Introduction
Good day.
Having a home NAS that runs on Debian 8 (I used Ubuntu Server 12.04 and 14.04 earlier), the idea arose to assign to it, among other things, the role of a video surveillance server.
Zoneminder was selected as the server side. The algorithm of video surveillance should be as follows: round-the-clock recording is not needed, but if necessary, the ability to enable recording upon the occurrence of an event is required - triggering on motion, followed by sending an email to screenshots from the scene. This is necessary to provide control over the apartment when someone is not at home. And, of course, you need the ability to remotely connect and check - everything is in order.
On the developer’s site, I found a very detailed
Wiki dedicated specifically to installation on Debian 8 64-bit. Accordingly, I will take the installation instructions from there, explaining some points with my comments.
Installing Zoneminder
So, we have a server with Debian 8 64-bit installed in the minimum configuration (I used netinstall). First you need to edit sources.list, adding Jessie backports to it:
')
sudo nano /etc/apt/sources.list
At the end of the file, add:
deb http://http.debian.net/debian jessie-backports main
Either uncomment this line if it is already there, that is, delete # at the beginning of the line. Update package index:
sudo apt-get update
Now everything is ready to install Zoneminder, which we will do:
sudo apt-get install zoneminder
The installation process will also automatically install Apache, MySQL, PHP.
After the installation is complete, create the MySQL database:
sudo mysql -uroot -p < /usr/share/zoneminder/db/zm_create.sql
In the process of creating the database, you will be prompted to select the root password for the database. Then we execute the following commands sequentially (via sudo), entering the password in case of a request:
mysql -uroot -p -e "grant all on zm.* to 'zmuser'@localhost identified by 'zmpass';"
mysqladmin -uroot -p reload
chmod 740 /etc/zm/zm.conf
chown root:www-data /etc/zm/zm.conf
Enable autorun Zoneminder:
systemctl enable zoneminder.service
We add the user www-data to the sudo group, this is needed to access the local video cameras:
adduser www-data sudo
Start Zoneminder:
systemctl start zoneminder.service
Verify that Zoneminder is running:
systemctl status zoneminder.service
If everything is in order, the output of the command should be approximately as follows:
● zoneminder.service - ZoneMinder CCTV recording and surveillance system Loaded: loaded (/lib/systemd/system/zoneminder.service; enabled) Active: active (running) since 2016-07-10 18:48:30 IRKT; 5h 31min ago Process: 6413 ExecStop=/usr/bin/zmpkg.pl stop (code=exited, status=0/SUCCESS) Process: 6455 ExecStart=/usr/bin/zmpkg.pl start (code=exited, status=0/SUCCESS) Main PID: 6474 (zmdc.pl) CGroup: /system.slice/zoneminder.service ├─6474 /usr/bin/perl -wT /usr/bin/zmdc.pl startup ├─6507 /usr/bin/perl -wT /usr/bin/zmfilter.pl ├─6514 /usr/bin/perl -wT /usr/bin/zmaudit.pl -c └─6521 /usr/bin/perl -wT /usr/bin/zmwatch.pl
Configure Apache:
a2enmod cgi
a2enmod rewrite
a2enconf zoneminder
Add your time zone in PHP:
sudo nano /etc/php5/apache2/php.ini
We are looking for the [Date] section and change the date.timezone to the required one:
[Date] ; Defines the default timezone used by the date functions ; http://php.net/date.timezone date.timezone = Asia/Irkutsk
Save - Ctrl + O, exit - Ctrl + X.
Restart Apache:
service apache2 restart
To be able to manage Zoneminder via Internet Explorer, you need to install Cambozola:
cd /usr/src && wget http://www.andywilcock.com/code/cambozola/cambozola-latest.tar.gz
tar -xzvf cambozola-latest.tar.gz
replace 936 with cambozola version downloaded
cp cambozola-0.936/dist/cambozola.jar /usr/share/zoneminder
This completes the installation of Zoneminder. Now you need to configure the mail transport so that Zoneminder can notify about events via email.
Setting up mail transport
To send notifications, Zoneminder can use ssmtp, and install it:
sudo apt-get update
sudo apt-get install ssmtp
Install mailutils at the same time, if this package is not yet installed:
sudo apt-get install mailutils
Now we will configure the mail settings, on behalf of which notifications will be sent. Suppose the mailbox is on gmail.com. Open ssmtp.conf:
sudo nano /etc/ssmtp/ssmtp.conf
and bring to this form, indicating, respectively, your data:
root=mymail@gmail.com mailhub=smtp.gmail.com:587 hostname=localhost RewriteDomain=gmail.com UseSTARTTLS=YES UseTLS=YES AuthUser=mymail@gmail.com AuthPass=myverystrongpassword
Rule revaliases:
sudo nano /etc/ssmtp/revaliases
we lead to this form:
root:pp@gmail.com:smtp.gmail.com:587 www-data:pp@gmail.com:smtp.gmail.com:587
And we check the correctness of the settings by sending a test letter:
echo "Hello, World" | mail -s "My email check" mne@napochtu.ru
If the test was successful, go to the next step - installing MIME :: Lite and Net :: SMTP. Check if these components are installed:
perl -MMIME::Lite -e "print \"Module installed.\\n\";"
perl -MNet::SMTP -e "print \"Module installed.\\n\";"
Install by going to the perl shell:
sudo perl -MCPAN -e shell
install MIME::Lite install Net::SMTP
Now we need to make very important changes, without which the mail transport from Zoneminder will not work.
Please note that these changes need only be made if the version of the installed Zoneminder is 1.29 or lower. Starting with version 1.30, these actions are not necessary.Open the zmfilter.pl file in the editor:
sudo nano /usr/bin/zmfilter.pl
Turning to line 1179, we see the following:
Comment out the lines
MIME::Lite->send( "sendmail", $Config{ZM_EMAIL_HOST}, Timeout=>60 );
and
$mail->send();
and add a line under them
$mail->send('sendmail','/usr/sbin/ssmtp',$Config{ZM_EMAIL_ADDRESS});
As a result, starting from line 1179 (in my case, but not necessarily this line number), the code should look like this:
Save, exit. This completes the work with the terminal.
Zoneminder web interface
Management is available at
ip.adress.servera / zm , we go. The first thing to do is to go to Options -> Users, and set the password for the admin user:

Then go to Options -> System, and put a tick in front of OPT_USE_AUTH:

If you do not do this, then Zoneminder allows you to log in to the web interface or connect through a client application without asking for a username / password, which, of course, is not safe. It is strange that this very necessary tick is not checked by default.
Now let's set up email sending. Go to Optons -> Email and set up by analogy:

In the EMAIL_BODY field, you can customize the format of notifications exactly as you need. For example, if you add% EI1% in the field, then the first screenshot from the moment the motion sensor is triggered is attached to the message. A full list of options for notifications is available
here .
Adding cameras
Zoneminder can work with both usb and IP cameras. At the moment, my cameras are still on the way, so as a test-tuning-temporary version of the camera, I use my old Android-smartphone Alcatel Pop C2, on which the
IP Webcam application is installed, which turns the smartphone into a Wi-Fi IP-camera. After installing and running the application (I recommend to set the resolution of the video stream in the application settings, I set 800x480), the smartphone displays the IP and the port that you can use to access the web interface and see what is interesting here:

There are a lot of settings in general, but we are interested in the address to which the video stream is sent. And we see that there is information to configure Zoneminder, which is good news. Namely, the Remote host path is specified, the path that will need to be specified in the settings of Zoneminder - after the IP camera you need to add / video:

Returning to the web interface of Zoneminder, to add a camera, select Add New Monitor:

In the Name field, write the desired name, Source type -> Remote:

In the Source tab, we fill in the fields: Remote Host Name -> IP of the smartphone, Remote Host Port -> port on which the IP Webcam is running, Remote Host Path -> the path we saw in the IP Webcam settings, and also specify the resolution of the video stream, which should match with the one we chose earlier in the IP webcam settings:

Save the settings -> Save, and in the main menu of Zoneminder we see the camera we added:

When clicking on the name of which, we see the image:

Cameras can operate in several modes, which is determined by the Function parameter in the main menu:

The mode in which the recording is made only when there is motion in the frame is called Modect, and we will select it. Now the system will not record the video stream constantly, but only if there are compelling reasons. But we still need to be notified of movement in the frame. For this you need to configure the filter. Open Filters in the main menu of Zoneminder, set up according to the screenshot, save under any name:

And do not forget to put a tick in front of the Run filter in background:

Thus, if motion is detected in a frame, the system will record a video and send an e-mail notification.
Client applications
If there is a permanent IP, nothing prevents you from forwarding ports in the router and connecting from your smartphone from the outside via a web interface, especially since you can select the mobile version of the interface in the Zoneminder settings, but in addition, I decided to look for some mobile application for this goals Searching on Google Play for the keyword "zoneminder", I stopped at
zmNinja , because The rating is quite high and the screenshots are liked. The application is a paid, trial version for a preliminary assessment, alas, no. The functionality is more than enough - viewing the video stream in real time, viewing the archive, recorded events, switching camera modes, etc.





There are also
desktop versions of zmNinja for Linux, Windows, Mac OS X - they are distributed free of charge. This is the Linux version running on my Mint 18:

In general, the interface is uniform for all systems.
That's all, thank you for your attention.