System is Ubuntu 14.04 server w/GUI and ZM 1.28.1
1) Setting up a filter to run a command when there is a new alarm
There are many suggestions I found but the only one I could get to work was to use event archiving. I wish there was another way as this method eliminates the use of archiving to save important events (unless you have unlimited storage).
- Create a new filter. I named mine TurnDisplayOn
- Add triggers
-- Alarm Frames, Greater than or equal to, 5 (adjust as needed for your system)
-- and, Archive Status equal to Unarchived Only
- Sort by, Date/Time, Desc, Limit to first 10 (adjust as needed) results only
- Archive all matches, check
- Execute command on all matches:
Code: Select all
/bin/sh /home/www-data/zmDOA-ssh.sh
2) Getting zmDOA-ssh.sh to execute
This was a challenge. I could never get the www-data to have enough permission to get the display to turn on (lots of visudo experiments). In the end I found leaving the browser running for extended times on the montage view resulted in browser freezes, so needed more permission to close/restart the browsers anyway. Solution was creating a script which will kick off commands (via ssh) as another Ubuntu user.
I am sure there is a much more elegant solution. I also believe there is a significant security exposure with this method, however in my case the system use is local only with no internet access. So intrusion requires physical access at which point the hacker owns the system anyway. No data of value on this system anyway. They'd just take the hardware for the hardware value.
The ZoneMinder user on Ubuntu is www-data. This is not a full user, so getting commands to execute is challenging.
a) Create the www-data user directory, open a terminal
Code: Select all
$ sudo mkdir /home/www-data
Code: Select all
sudo nano /home/www-data/zmDOA-ssh.sh
Code: Select all
#!/bin/sh
/usr/bin/ssh yourUbuntuUser@localhost /bin/sh /home/yourUbuntuUser/zmDispOnAlarm.sh
Code: Select all
$ sudo chown -R www-data:www-data /home/www-data
This is where the security exposure comes in. There must be a secure way to do this, but I really did not need to find one.
- As your ubuntu default user ssh into your system.
Code: Select all
$ ssh localhost
Code: Select all
$ exit
Code: Select all
$ sudo cp /home/yourUbuntuUser/.ssh /var/www
Code: Select all
$ sudo chown -R www-data:www-data /var/www/.ssh
Code: Select all
$ nano /home/yourUbuntuUser/.bash_profile
- Paste in and save
# Let re-use ssh-agent and/or gpg-agent between logins
/usr/bin/keychain $HOME/.ssh/id_rsa
source $HOME/.keychain/$HOSTNAME-sh
### End-Keychain ###
[/code]
3) Install some tools which will be needed.
Code: Select all
$ sudo apt-get install xdotool
$ sudo apt-get install wmctrl
Code: Select all
$ cd ~
$ nano zmDispOnAlarm.sh
Code: Select all
#!/bin/sh
# Check if firefox is already running (could be due to a recent alarm) if not start firefox
if ps ax |grep -v grep | grep firefox > /dev/null
then
echo firefox already running > /dev/null
else
env DISPLAY=:0 firefox &
fi
# Wake the display. I have found that the export command will wake the display all by itself in some cases.
export DISPLAY=:0
# To make sure the display is awake, move the mouse a pixel and back
/usr/bin/xdotool mousemove_relative 1 1
sleep 1
#/usr/bin/xdotool mousemove 0 480
/usr/bin/xdotool mousemove_relative -1 -1
# Uncomment items below if you wish to log when this sript is called
#TIMESTAMP=`/bin/date "+%Y-%m-%d %H:%M:%S"`
#MONITOR=`/usr/bin/xset -display :0 -q|grep "Monitor is"`
#echo "$TIMESTAMP: $MONITOR" >> /~/zmDispOnAlarm.log
Code: Select all
$ cd ~
$ nano ff_to.sh
Code: Select all
#!/bin/sh
#grab the current display status
MONITOR=`/usr/bin/xset -display :0 -q|grep "Monitor is"`
#If display is off close firefox
case $MONITOR in *Off*)
if ps ax |grep -v grep | grep firefox > /dev/null
then
env DISPLAY=:0 wmctrl -c firefox
fi
esac
Code: Select all
$ crontab -e
Code: Select all
0,5,10,15,20,25,30,35,40,45,50,55 * * * * sh /home/yourUbuntuUser/ff_to.sh
- In preferences set show my homepage when firefox starts
- Use the following as your homepage replacing zmuser and zmpassw0rd as appropriate
Code: Select all
http://localhost/zm/?action=login&view=montage&group=0&username=zmuser&password=zmpassw0rd