From e851f51157ac00aa3de03f4bb9743c6a7d91bea8 Mon Sep 17 00:00:00 2001 From: James Meyer Date: Thu, 1 Nov 2012 15:57:51 -0500 Subject: zoneminder 1.25: made it easier for end users to get this product up and running. It will not integrate itself with lighttpd and install the database. runit-scripts holds the run file. All that should be needed for this package to work is add_service zoneminder Then access the console at http://localhost/zm Unfortunatly only mythzoneminder on the backend will be able to use zoneminder. This is a shortcoming of the integration with myth and zoneminder. --- abs/core/zoneminder/Controls_Orbit.sql | 3 - abs/core/zoneminder/Makefile.patch | 11 - abs/core/zoneminder/PKGBUILD | 281 +++++-- abs/core/zoneminder/__changelog | 15 + abs/core/zoneminder/customdb | 31 - abs/core/zoneminder/httpd-zm.conf | 18 - abs/core/zoneminder/httpd-zoneminder.conf | 20 + abs/core/zoneminder/patch-ffmpeg-0.11.patch | 60 ++ abs/core/zoneminder/run | 21 - abs/core/zoneminder/zm.include | 4 + abs/core/zoneminder/zm.rc.d | 172 ---- abs/core/zoneminder/zm.sysctrl.conf | 2 + abs/core/zoneminder/zmeventbackup | 48 -- abs/core/zoneminder/zmfilter.pl | 1119 --------------------------- abs/core/zoneminder/zminit.arch | 143 ---- abs/core/zoneminder/zoneminder | 63 ++ abs/core/zoneminder/zoneminder.install | 139 ++-- abs/core/zoneminder/zoneminder.service | 13 + 18 files changed, 475 insertions(+), 1688 deletions(-) delete mode 100755 abs/core/zoneminder/Controls_Orbit.sql delete mode 100755 abs/core/zoneminder/Makefile.patch mode change 100755 => 100644 abs/core/zoneminder/PKGBUILD create mode 100644 abs/core/zoneminder/__changelog delete mode 100755 abs/core/zoneminder/customdb delete mode 100755 abs/core/zoneminder/httpd-zm.conf create mode 100644 abs/core/zoneminder/httpd-zoneminder.conf create mode 100644 abs/core/zoneminder/patch-ffmpeg-0.11.patch delete mode 100755 abs/core/zoneminder/run create mode 100644 abs/core/zoneminder/zm.include delete mode 100755 abs/core/zoneminder/zm.rc.d create mode 100644 abs/core/zoneminder/zm.sysctrl.conf delete mode 100755 abs/core/zoneminder/zmeventbackup delete mode 100755 abs/core/zoneminder/zmfilter.pl delete mode 100755 abs/core/zoneminder/zminit.arch create mode 100644 abs/core/zoneminder/zoneminder mode change 100755 => 100644 abs/core/zoneminder/zoneminder.install create mode 100644 abs/core/zoneminder/zoneminder.service diff --git a/abs/core/zoneminder/Controls_Orbit.sql b/abs/core/zoneminder/Controls_Orbit.sql deleted file mode 100755 index 23224e4..0000000 --- a/abs/core/zoneminder/Controls_Orbit.sql +++ /dev/null @@ -1,3 +0,0 @@ - -INSERT INTO `Controls` VALUES (7,'Orbit','Remote','mjpgStreamer',0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,1,-7000,7000,200,200,1,100,100,0,0,1,-2000,2000,10,100,1,200,200,0,0,0,0); - diff --git a/abs/core/zoneminder/Makefile.patch b/abs/core/zoneminder/Makefile.patch deleted file mode 100755 index efafc48..0000000 --- a/abs/core/zoneminder/Makefile.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- ZoneMinder-1.24.0.orig/Makefile 2008-03-13 17:41:47.000000000 -0700 -+++ ZoneMinder-1.24.0/Makefile 2008-03-15 06:21:22.000000000 -0700 -@@ -815,7 +815,7 @@ - # Yes, you are correct. This is a HACK! - install-data-hook: - ( cd $(DESTDIR)$(sysconfdir); chown $(webuser):$(webgroup) $(sysconf_DATA); chmod 600 $(sysconf_DATA) ) -- ( if ! test -e $(ZM_RUNDIR); then mkdir -p $(ZM_RUNDIR); fi; if test "$(ZM_RUNDIR)" != "/var/run"; then chown $(webuser):$(webgroup) $(ZM_RUNDIR); chmod u+w $(ZM_RUNDIR); fi ) -+ ( if ! test -e $(DESTDIR)$(ZM_RUNDIR); then mkdir -p $(DESTDIR)$(ZM_RUNDIR); fi; if test "$(DESTDIR)$(ZM_RUNDIR)" != "/var/run"; then chown $(webuser):$(webgroup) $(DESTDIR)$(ZM_RUNDIR); chmod u+w $(DESTDIR)$(ZM_RUNDIR); fi ) - ( if ! test -e $(ZM_TMPDIR); then mkdir -m 700 -p $(ZM_TMPDIR); fi; if test "$(ZM_TMPDIR)" != "/tmp"; then chown $(webuser):$(webgroup) $(ZM_TMPDIR); chmod u+w $(ZM_TMPDIR); fi ) - ( if ! test -e $(ZM_LOGDIR); then mkdir -p $(ZM_LOGDIR); fi; if test "$(ZM_LOGDIR)" != "/var/log"; then chown $(webuser):$(webgroup) $(ZM_LOGDIR); chmod u+w $(ZM_LOGDIR); fi ) - diff --git a/abs/core/zoneminder/PKGBUILD b/abs/core/zoneminder/PKGBUILD old mode 100755 new mode 100644 index 6b5c6c8..4dc5c63 --- a/abs/core/zoneminder/PKGBUILD +++ b/abs/core/zoneminder/PKGBUILD @@ -1,84 +1,213 @@ -# This is a ZoneMinder PKGBUILD file. -# Contributor: Ross melin +# Maintainer: Vojtech Aschenbrenner +# Contributor: Jason Gardner +# Contributor: Ross melin +# Maintainer (Parabola): Márcio Silva +# Contributor (Parabola): André Silva + +# based of debian squeeze package pkgname=zoneminder pkgver=1.25.0 -pkgrel=2 -pkgdesc="Capture, analyse, record and monitor video security cameras." -arch=('i686' 'x86_64') -url="http://www.zoneminder.com" -license=('GPL') -depends=('cambozola' 'apache' 'php' 'mysql' 'pcre' 'openssl' 'ffmpeg' 'perl-php-serialization' 'perl-libwww' 'perl-date-manip' 'perl-unicode-map' 'perl-dbi' 'perl-dbd-mysql' 'perl-io-stringy' 'perl-mime-lite' 'perl-timedate' 'perl-x10' 'perl-time-modules' 'perl-net-smtp-ssl' 'perl-sys-mmap' 'sudo' 'libv4l') -makedepends=() -install=zoneminder.install -source=("http://www2.zoneminder.com/downloads/ZoneMinder-${pkgver}.tar.gz" -zm.rc.d -Controls_Orbit.sql -zminit.arch -customdb -httpd-zm.conf -zmfilter.pl -zmeventbackup -Makefile.patch -run) +pkgrel=22 +pkgdesc='Capture, analyse, record and monitor video security cameras' +arch=( + i686 + x86_64 + mips64el +) +backup=( + etc/zm.conf +) +url="http://www.$pkgname.com" +license=( + GPL +) +depends=( + #apache + lighttpd + cambozola + #ffmpeg-static + ffmpeg + gnutls + mysql + perl-archive-zip + perl-date-manip + perl-dbd-mysql + perl-dbi + perl-expect + perl-libwww + perl-mime-lite + perl-mime-tools + perl-php-serialization + perl-net-sftp-foreign + perl-sys-mmap + perl-time-modules + perl-x10 + php + #php-apache + php-gd + php-mcrypt +) +makedepends=( + netpbm +) +optdepends=( + netpbm +) +install=$pkgname.install +source=( + http://www.$pkgname.com/downloads/ZoneMinder-$pkgver.tar.gz + httpd-$pkgname.conf + $pkgname + $pkgname.service + patch-ffmpeg-0.11.patch + zm.include + zm.sysctrl.conf +) + build() { - cd "$srcdir/ZoneMinder-$pkgver" - - cat ../Controls_Orbit.sql >> db/zm_create.sql.in - ./configure --prefix=/usr \ - --sysconfdir=/etc \ - --with-webuser=http \ - --with-webgroup=http \ - --with-mysql=/usr \ - --with-webdir=/srv/zoneminder/www \ - --with-cgidir=/srv/zoneminder/cgi-bin \ - --bindir=/srv/zoneminder/bin \ - ZM_SSL_LIB=openssl \ - CPPFLAGS=-D__STDC_CONSTANT_MACROS - # goddamn chown line just mucks everything up, we'll chown it in the install - # script. - sed -i '/chown/d' Makefile - make || return 1 - make DESTDIR="$pkgdir" install || return 1 - - install -D -m 700 $startdir/src/zminit.arch $startdir/pkg/usr/lib/zm/bin/zminit - install -D -m 700 $startdir/src/zm.rc.d $startdir/pkg/etc/rc.d/zm - install -D -m 700 scripts/zmdbbackup $startdir/pkg/usr/lib/zm/bin/zmdbbackup - install -D -m 700 scripts/zmdbrestore $startdir/pkg/usr/lib/zm/bin/zmdbrestore - install -D -m 700 scripts/zmeventdump $startdir/pkg/usr/lib/zm/bin/zmeventdump - install -D -m 700 scripts/zmlogrotate.conf $startdir/pkg/etc/logrotate.d/zm - install -D -m 700 $startdir/src/zmeventbackup $startdir/pkg/etc/cron.hourly/zmeventbackup - install -D -m 755 scripts/zmfilter.pl $startdir/pkg/usr/lib/zm/bin/zmfilter.pl - install -D -m 755 scripts/zmupdate.pl $startdir/pkg/usr/lib/zm/bin/zmupdate.pl - - mkdir -p $startdir/pkg/etc/httpd/conf/extra/ - install -m 644 $startdir/src/httpd-zm.conf $startdir/pkg/etc/httpd/conf/extra/httpd-zm.conf - - install -D -m 700 $startdir/src/customdb $startdir/pkg/usr/lib/zm/upgrade/customdb - install -D db/zm*.sql $startdir/pkg/usr/lib/zm/upgrade/ - - mkdir -p $startdir/pkg/var/run/zm - mkdir -p $startdir/pkg/var/lib/zm - - #install runit files - mkdir -p $pkgdir/etc/sv/zm - install -D -m 755 $srcdir/run $pkgdir/etc/sv/zm - - ### remove special files - find $startdir/pkg/ -name "perllocal.pod" \ - -o -name ".packlist" \ - -o -name "*.bs" \ - |xargs -i rm -f {} + cd $srcdir/ZoneMinder-$pkgver + + # ZM_RUNDIR need change to run dir + export CPPFLAGS=-D__STDC_CONSTANT_MACROS\ + ZM_LOGDIR=/var/log/$pkgname\ + ZM_RUNDIR=/tmp/$pkgname\ + ZM_SSL_LIB=gnutls\ + ZM_TMPDIR=/tmp/$pkgname + + # Patch for GCC 4.7.x + sed -i -e 's/^#include /#include \n#include /'\ + src/zm_logger.cpp || read + sed -i -e 's/^#include /#include \n#include /'\ + src/zm_thread.h || read + + # Patch for automake 1.12 + sed -i -e '/am__api_version=/ s/1.11/1.12/'\ + configure || read + + # Patch for disable ZM_CHECK_FOR_UPDATES + sed -i -e '/ZM_CHECK_FOR_UPDATES/,+1 s/yes/no/'\ + scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in || read + + # Patch for support html5 video and flv + sed -i -e '/ZM_MPEG_LIVE_FORMAT/,+1 s/swf/webm/;/ZM_MPEG_REPLAY_FORMAT/,+1 s/swf/webm/; + /ZM_FFMPEG_FORMATS/,+1 s/mpg mpeg wmv asf avi\* mov swf 3gp\*\*/mpg mpeg wmv asf avi\* mov flv swf 3gp\*\* webm ogg h254/'\ + scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in || read + + # Patch for change path run dir + sed -i -e '/ZM_PATH_SOCKS/,+1 s/TMP/RUN/'\ + scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in || read + + # Patch for change ZM name to ZoneMinder + sed -i -e '/ZM_WEB_TITLE_PREFIX/,+1 s/"ZM"/"ZoneMinder"/'\ + scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in || read + + # Patch for v4l1 compat support + sed -i -e "s/$ENV{SHELL} = \'\/bin\/sh\' if exists $ENV{SHELL};/$ENV{SHELL} = \'\/bin\/sh\' if exists $ENV{SHELL};\n$ENV{LD_PRELOAD} = \'\/usr\/lib\/libv4l\/v4l1compat.so\' ;/"\ + scripts/zmdc.pl.in || read + + # Patch for add more socket tries + sed -i -e '/$max_socket_tries/ s/3/15/'\ + web/ajax/stream.php || read + + # Patch for wrong "suppported" + sed -i -e 's/suppported/supported/'\ + src/zm_local_camera.cpp || read + + # Patch for type cast in linux-libre kernel 3.5 + sed -i -e 's/enum v4l2_buf_type type = v4l2_data.fmt.type;/enum v4l2_buf_type type = (v4l2_buf_type)v4l2_data.fmt.type;/'\ + src/zm_local_camera.cpp || read + + # Patch for drop custom perl install paths + sed -i -e '/# Slight hack for non-standard perl install paths/,+10 d; + s/^AC_SUBST(ZM_CONFIG,"$SYSCONFDIR\/zm.conf")/AC_SUBST(ZM_CONFIG,"$SYSCONFDIR\/zm.conf")\n\nEXTRA_PERL_LIB="# Include from system perl paths only"\nPERL_MM_PARMS="INSTALLDIRS=vendor"/'\ + configure.ac + + # Patch for support new ffmpeg + patch -p1 < $srcdir/patch-ffmpeg-0.11.patch +# sed -i -e 's/if ( av_open_input_file( \&mFormatContext, mPath.c_str(), NULL, 0, NULL ) !=0 )/if ( avformat_open_input( \&mFormatContext, mPath.c_str(), NULL, NULL ) !=0 )/; +# s/if ( avcodec_open( mCodecContext, mCodec ) < 0 )/if ( avcodec_open2( mCodecContext, mCodec, NULL ) < 0 )/'\ +# src/zm_ffmpeg_camera.cpp +# sed -i -e 's/if ( av_set_parameters(ofc, NULL) < 0 )/\/\*\n \* Removed in last ffmpeg\n \* if ( av_set_parameters(ofc, NULL) < 0 )/; +# /Panic( "Invalid output format parameters" );/,+1 s/}/}\*/; +# /if ( avio_open(&ofc->pb, filename, URL_WRONLY) < 0 )/ s/URL_WRONLY/AVIO_FLAG_WRITE/; +# s/av_write_header(ofc);/avformat_write_header(ofc, NULL);/'\ +# src/zm_mpeg.cpp + sed -i -e 's/avcodec_init/avcodec_open/'\ + configure{,.ac} + + # Patch for support ffmpeg with and C library + sed -i -e 's/^extern "C" {/extern "C" {\n#ifdef _STDINT_H\n#undef _STDINT_H\n#endif\n#include / + s/^#include /#include \n#include /'\ + src/zm_ffmpeg.h + sed -i -e 's/^AM_CONFIG_HEADER(config.h)/AM_CONFIG_HEADER(config.h)\n\nAC_SUBST([AM_CXXFLAGS], [-D__STDC_CONSTANT_MACROS])/; + s/^AC_CHECK_HEADERS(mysql\/mysql.h,,AC_MSG_ERROR(zm requires MySQL headers - check that MySQL development packages are installed),)/AC_CHECK_HEADERS(mysql\/mysql.h,,AC_MSG_ERROR(zm requires MySQL headers - check that MySQL development packages are installed),)\nAC_LANG_PUSH([C])/; + s/^AC_CHECK_HEADERS(libswscale\/swscale.h,,,)/AC_CHECK_HEADERS(libswscale\/swscale.h,,,)\nAC_LANG_POP([C])/'\ + configure.ac + + # Patch for wrong install run, tmp and log dir + sed -i -e '/ install-data-hook/d;/install-data-hook:/d;/# Yes, you are correct. This is a HACK!/d; + / ( cd $(DESTDIR)$(sysconfdir); chown $(webuser):$(webgroup) $(sysconf_DATA); chmod 600 $(sysconf_DATA) )/d; + / ( if ! test -e $(ZM_RUNDIR); then mkdir -p $(ZM_RUNDIR); fi; if test "$(ZM_RUNDIR)" != "\/var\/run"; then chown $(webuser):$(webgroup) $(ZM_RUNDIR); chmod u+w $(ZM_RUNDIR); fi )/d; + / ( if ! test -e $(ZM_TMPDIR); then mkdir -m 700 -p $(ZM_TMPDIR); fi; if test "$(ZM_TMPDIR)" != "\/tmp"; then chown $(webuser):$(webgroup) $(ZM_TMPDIR); chmod u+w $(ZM_TMPDIR); fi )/d; + / ( if ! test -e $(ZM_LOGDIR); then mkdir -p $(ZM_LOGDIR); fi; if test "$(ZM_LOGDIR)" != "\/var\/log"; then chown $(webuser):$(webgroup) $(ZM_LOGDIR); chmod u+w $(ZM_LOGDIR); fi )/,+1 d'\ + Makefile.{am,in} + + ./configure --prefix=/usr\ + --enable-crashtrace=no\ + --enable-debug=no\ + --enable-mmap=yes\ + --sysconfdir=/etc\ + --with-cgidir=/data/srv/httpd/cgi-bin\ + --with-extralibs='-L/usr/lib -L/usr/lib/mysql'\ + --with-ffmpeg=/usr\ + --with-libarch=lib\ + --with-mysql=/usr\ + --with-webdir=/data/srv/httpd/$pkgname\ + --with-webgroup=http\ + --with-webhost=localhost\ + --with-webuser=http + + make V=0 +} + +package() { + cd $srcdir/ZoneMinder-$pkgver + + make DESTDIR=$pkgdir install + + mkdir -p $pkgdir/{etc/{httpd/conf/extra,rc.d},data/srv/httpd/{cgi-bin,$pkgname},usr/{lib/systemd/system,share/{license/$pkgname,$pkgname/db}},var/{cache/$pkgname,log/$pkgname}} + + chown -R http.http $pkgdir/{etc/zm.conf,var/{cache/$pkgname,log/$pkgname}} + chmod 0700 $pkgdir/etc/zm.conf + + for i in events images temp; do + mv $pkgdir/data/srv/httpd/$pkgname/$i $pkgdir/var/cache/$pkgname/$i + ln -s /var/cache/$pkgname/$i $pkgdir/data/srv/httpd/$pkgname/$i + chown -h http.http $pkgdir/data/srv/httpd/$pkgname/$i + done + + ln -s /data/srv/httpd/cgi-bin $pkgdir/data/srv/httpd/$pkgname + chown -h http.http $pkgdir/data/srv/httpd/{cgi-bin,$pkgname,$pkgname/cgi-bin} + + ln -s /usr/share/cambozola/cambozola.jar $pkgdir/data/srv/httpd/$pkgname + mkdir -p $pkgdir/etc/lighttpd + install -D -m 644 $srcdir/zm.include $pkgdir/etc/lighttpd/ + #sysctrl conf + install -o root -g root -D -m 0755 $srcdir/zm.sysctrl.conf $startdir/pkg/etc/sysctl.d/zm.conf + + install -D -m 644 $srcdir/httpd-$pkgname.conf $pkgdir/etc/httpd/conf/extra + install -D -m 644 $srcdir/$pkgname $pkgdir/etc/rc.d + install -D -m 644 $srcdir/$pkgname.service $pkgdir/usr/lib/systemd/system + install -D -m 644 COPYING $pkgdir/usr/share/license/$pkgname + install -D -m 644 db/zm*.sql $pkgdir/usr/share/$pkgname/db } md5sums=('eaefa14befd482154970541252aa1a39' - 'b20fb25b187eb6abb21321e153a7fb25' - '5033bc098bf497c8aed1fc1b3c9c5f9c' - 'f9720872736f26d17bc49d8725b75ae4' - '4ace13d1e20934abe192ef7372c75988' - '00201eba9c0a5d1ed14b10cc55410698' - '80c52cc3575073a7462ff6a54886a345' - '8b40137b6ff54f2fb26104b70edd22e9' - 'bb308c2393e947a224d56862c85a3ad9' - '0c7024c355ce36828627bed10d965202') + '72380d8793a784ec24cb6809aea4a739' + '034b61cda8849fc3001849e76ef26041' + 'ca3fe00739707b9f92eaaa9034d4da2b' + '81c8be870260142e2633eedf73c72040' + '9d93f9b7b0a1384df533efde19ed3021' + '9a60f8b9af050220e1cb86da438952b3') diff --git a/abs/core/zoneminder/__changelog b/abs/core/zoneminder/__changelog new file mode 100644 index 0000000..e7181bc --- /dev/null +++ b/abs/core/zoneminder/__changelog @@ -0,0 +1,15 @@ +Change cgidir and webdir: + /data/srv/ +-- +added zm.include for lighttpd +added zm.sysctrl.conf to set the shared mem +-- +run file + +-- + +Install file +Removed modifications of php.ini +Added remove/add of zm.include in post install/remove +added install_db +add http to video group diff --git a/abs/core/zoneminder/customdb b/abs/core/zoneminder/customdb deleted file mode 100755 index 82dfc48..0000000 --- a/abs/core/zoneminder/customdb +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh -DBHOST=$1 -DBNAME=$2 -USERNAME=$3 -PASSWORD=$4 - -ZM_PATH_ZMS=/cgi-zm/nph-zms -ZM_PATH_SOCKS=/var/lib/zm/socks -ZM_PATH_LOGS=/var/log/zm -ZM_WEB_LIST_THUMBS=1 -ZM_WEB_MONTAGE_WIDTH=320 -ZM_WEB_MONTAGE_HEIGHT=240 -ZM_OPT_CAMBOZOLA=1 -ZM_OPT_MPEG=ffmpeg -ZM_PATH_FFMPEG=/usr/bin/ffmpeg -ZM_OPT_NETPBM=1 -ZM_EXTRA_DEBUG_LOG=/var/log/zm/zm_debug.log -ZM_OPT_USE_AUTH=0 - -sql=/tmp/$$ -echo "" >$sql -for n in ZM_PATH_ZMS ZM_PATH_SOCKS ZM_PATH_LOGS ZM_WEB_LIST_THUMBS ZM_WEB_MONTAGE_WIDTH ZM_WEB_MONTAGE_HEIGHT ZM_OPT_CAMBOZOLA ZM_OPT_MPEG ZM_PATH_FFMPEG ZM_OPT_NETPBM ZM_EXTRA_DEBUG_LOG ZM_OPT_USE_AUTH; do - eval "val=\$$n" - echo "UPDATE Config SET Value='$val' WHERE Name='$n';" >>$sql -done - -cat $sql | mysql --user=$USERNAME --password=$PASSWORD --host=$DBHOST $DBNAME -rm -f $sql - - -exit 0 diff --git a/abs/core/zoneminder/httpd-zm.conf b/abs/core/zoneminder/httpd-zm.conf deleted file mode 100755 index bdd29d7..0000000 --- a/abs/core/zoneminder/httpd-zm.conf +++ /dev/null @@ -1,18 +0,0 @@ -# /etc/httpd/conf/extra/httpd-zm.conf -# Config for zoneminder web app - -Alias /zm "/var/lib/zm/www" - - Options -Indexes MultiViews FollowSymLinks - AllowOverride All - Order allow,deny - Allow from all - - -ScriptAlias /cgi-zm "/var/lib/zm/cgi-bin" - - AllowOverride All - Options ExecCGI - Order allow,deny - Allow from all - diff --git a/abs/core/zoneminder/httpd-zoneminder.conf b/abs/core/zoneminder/httpd-zoneminder.conf new file mode 100644 index 0000000..aeb089b --- /dev/null +++ b/abs/core/zoneminder/httpd-zoneminder.conf @@ -0,0 +1,20 @@ +# /etc/httpd/conf/extra/httpd-zm.conf +# Config for zoneminder web app + +Alias /zm "/srv/http/zoneminder" + + Options -Indexes MultiViews FollowSymLinks + AllowOverride None + Order allow,deny + Allow from all + # The code unfortunately uses short tags in many places + php_value short_open_tag On + + +ScriptAlias /cgi-bin "/srv/http/cgi-bin" + + AllowOverride None + Options ExecCGI FollowSymLinks + Order allow,deny + Allow from all + diff --git a/abs/core/zoneminder/patch-ffmpeg-0.11.patch b/abs/core/zoneminder/patch-ffmpeg-0.11.patch new file mode 100644 index 0000000..ac56e4c --- /dev/null +++ b/abs/core/zoneminder/patch-ffmpeg-0.11.patch @@ -0,0 +1,60 @@ +diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp +index 42927f6..61df606 100644 +--- a/src/zm_ffmpeg_camera.cpp ++++ b/src/zm_ffmpeg_camera.cpp +@@ -91,7 +91,7 @@ int FfmpegCamera::PrimeCapture() + Info( "Priming capture from %s", mPath.c_str() ); + + // Open the input, not necessarily a file +- if ( av_open_input_file( &mFormatContext, mPath.c_str(), NULL, 0, NULL ) !=0 ) ++ if ( avformat_open_input( &mFormatContext, mPath.c_str(), NULL, NULL ) !=0 ) + Fatal( "Unable to open input %s due to: %s", mPath.c_str(), strerror(errno) ); + + // Locate stream info from input +@@ -122,7 +122,7 @@ int FfmpegCamera::PrimeCapture() + Fatal( "Can't find codec for video stream from %s", mPath.c_str() ); + + // Open the codec +- if ( avcodec_open( mCodecContext, mCodec ) < 0 ) ++ if ( avcodec_open2( mCodecContext, mCodec, NULL ) < 0 ) + Fatal( "Unable to open codec for video stream from %s", mPath.c_str() ); + + // Allocate space for the native video frame + +diff --git a/src/zm_mpeg.cpp b/src/zm_mpeg.cpp +index f5de2a4..d614346 100644 +--- a/src/zm_mpeg.cpp ++++ b/src/zm_mpeg.cpp +@@ -130,10 +130,12 @@ void VideoStream::SetParameters() + { + /* set the output parameters (must be done even if no + parameters). */ +- if ( av_set_parameters(ofc, NULL) < 0 ) ++ /* ++ * Removed in last ffmpeg ++ * if ( av_set_parameters(ofc, NULL) < 0 ) + { + Panic( "Invalid output format parameters" ); +- } ++ }*/ + //dump_format(ofc, 0, filename, 1); + } + +@@ -222,7 +224,7 @@ void VideoStream::OpenStream() + if ( !(of->flags & AVFMT_NOFILE) ) + { + #if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,2,1) +- if ( avio_open(&ofc->pb, filename, URL_WRONLY) < 0 ) ++ if ( avio_open(&ofc->pb, filename, AVIO_FLAG_WRITE) < 0 ) + #else + if ( url_fopen(&ofc->pb, filename, URL_WRONLY) < 0 ) + #endif +@@ -241,7 +243,7 @@ void VideoStream::OpenStream() + } + + /* write the stream header, if any */ +- av_write_header(ofc); ++ avformat_write_header(ofc, NULL); + } + + VideoStream::VideoStream( const char *filename, const char *format, int bitrate, double frame_rate, int colours, int subpixelorder, int width, int height ) diff --git a/abs/core/zoneminder/run b/abs/core/zoneminder/run deleted file mode 100755 index ce61c24..0000000 --- a/abs/core/zoneminder/run +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -export TERM=linux -. /etc/rc.conf -. /etc/rc.d/functions - -while true ; do - PID=`pidof -x zmdc.pl` - if test -n "$PID" ; then - sleep 60 - continue - fi - stat_runit "Starting ZoneMinder" - /etc/rc.d/zm start - if test $? -ne 0 ; then - stat_fail - else - add_daemon zm - stat_done - fi - sleep 30 -done diff --git a/abs/core/zoneminder/zm.include b/abs/core/zoneminder/zm.include new file mode 100644 index 0000000..63ffc50 --- /dev/null +++ b/abs/core/zoneminder/zm.include @@ -0,0 +1,4 @@ +alias.url += ( + "/zm" => "/data/srv/httpd/zoneminder/" +) + diff --git a/abs/core/zoneminder/zm.rc.d b/abs/core/zoneminder/zm.rc.d deleted file mode 100755 index 60f684b..0000000 --- a/abs/core/zoneminder/zm.rc.d +++ /dev/null @@ -1,172 +0,0 @@ -#!/bin/bash - -# Source function library. -. /etc/rc.conf -. /etc/rc.d/functions - -prog=ZoneMinder -ZM_VERSION="1.24.0" -ZM_PATH_BIN="/usr/lib/zm/bin" -ZM_CONFIG="/etc/zm.conf" -command="$ZM_PATH_BIN/zmpkg.pl" - -loadconf() -{ - if [ -f $ZM_CONFIG ]; then - . $ZM_CONFIG - else - echo "ERROR: $ZM_CONFIG not found. -" - return 1 - fi -} - -# Check for old config and update if needed -checkcfg() -{ - # Check config - if [ "$ZM_DB_HOST" = "" -o "$ZM_DB_NAME" = "" -o "$ZM_DB_USER" = "" -o "$ZM_DB_PASS" = "" ]; then - echo "In $ZM_CONFIG there should not be null values. -" - return 1 - loadconf - fi -} - -checkdb() -{ - # Check database exisits and version - GetVer="select Value from Config where Name='ZM_DYN_DB_VERSION'" - OLD_VERSION=`echo $GetVer | mysql -B -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS $ZM_DB_NAME | grep -v '^Value'` - if [ "$OLD_VERSION" = "" ]; then - GetVer="select Value from Config where Name='ZM_DYN_CURR_VERSION'" - OLD_VERSION=`echo $GetVer | mysql -B -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS $ZM_DB_NAME | grep -v '^Value'` - if [ "$OLD_VERSION" = "" ]; then - echo "You must run $ZM_PATH_BIN/zminit manually -" - return 1 - fi - fi - RETVAL=$? - - if [ $RETVAL != 0 ]; then - tbls=`mysql -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS -s -e 'show tables' $ZM_DB_NAME` - RETVAL=$? - if [ $RETVAL = 0 ]; then - echo "Initialize $prog database: -" - echo tbls | grep Config >/dev/null 2>&1 - RETVAL=$? - if [ $RETVAL != 0 ]; then - mysql -B -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS $ZM_DB_NAME < $ZM_PATH_UPDATE/zm_create.sql - RETVAL=$? - [ $RETVAL = 0 ] && stat_done - [ $RETVAL != 0 ] && stat_fail - echo - return $RETVAL - fi - ( cd $ZM_PATH_UPDATE; perl $ZM_PATH_BIN/zmupdate.pl -f ) - RETVAL=$? - [ $RETVAL = 0 ] && stat_done - [ $RETVAL != 0 ] && stat_fail - echo - return $RETVAL - else - echo "No access to ZoneMinder database. -Run $ZM_PATH_BIN/zminit manually. -" - return $RETVAL - fi - else - [ "$ZM_VERSION" = "$OLD_VERSION" ] && return 0 - echo "Upgrade %s database: " "$prog" - $ZM_PATH_BIN/zmupdate.pl --version=$OLD_VERSION --noi && ( cd $ZM_PATH_UPDATE; perl $ZM_PATH_BIN/zmupdate.pl -f ) - RETVAL=$? - [ $RETVAL = 0 ] && stat_done - [ $RETVAL != 0 ] && stat_fail - echo - return $RETVAL - fi -} - -start() -{ - loadconf || return $? - checkcfg || return $? - checkdb || return $? - stat_busy "Starting $prog" - [ -d /var/run/zm ] || mkdir -m 774 /var/run/zm - chown -R $ZM_WEB_USER:$ZM_WEB_GROUP /var/run/zm - GetPath="select Value from Config where Name='ZM_PATH_SOCKS'" - ZM_PATH_SOCK=`echo $GetPath | mysql -B -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS $ZM_DB_NAME | grep -v '^Value'` - [ -d $ZM_PATH_SOCK ] || mkdir -m 774 -p $ZM_PATH_SOCK - sudo -u $ZM_WEB_USER test -O $ZM_PATH_SOCK \ - || chown -R $ZM_WEB_USER:$ZM_WEB_GROUP $ZM_PATH_SOCK - # Setup the log dir - [ -d /var/log/zm ] || mkdir /var/log/zm - for logs in zmaudit.log zmdc.log zmfilter.log zmpkg.log zmupdate.log zmwatch.log; do - touch /var/log/zm/$logs - done - chown -R $ZM_WEB_USER:$ZM_WEB_GROUP /var/log/zm - $command start - RETVAL=$? - [ $RETVAL = 0 ] && stat_done - [ $RETVAL != 0 ] && stat_fail - #[ $RETVAL = 0 ] && touch /var/lock/subsys/zm - return $RETVAL -} - -stop() -{ - stat_busy "Stopping $prog" - $command stop - RETVAL=$? - [ $RETVAL = 0 ] && stat_done - [ $RETVAL != 0 ] && stat_fail - #[ $RETVAL = 0 ] && rm -f /var/lock/subsys/zm -} - -status() -{ - result=`$command status` - if [ "$result" = "running" ]; then - echo "ZoneMinder is running -" - RETVAL=0 - else - echo "ZoneMinder is stopped -" - RETVAL=1 - fi -} - -case "$1" in - 'start') - start - ;; - 'stop') - stop - ;; - 'restart') - stop - start - ;; - 'condrestart') - loadconf - checkcfg - result=`$ZM_PATH_BIN/zmdc.pl check` - if [ "$result" = "running" ]; then - $ZM_PATH_BIN/zmdc.pl shutdown > /dev/null - start - fi - ;; - 'status') - status - ;; - *) - echo "Usage: zm { start | stop | restart | condrestart | status } -" - RETVAL=1 - ;; -esac -exit $RETVAL diff --git a/abs/core/zoneminder/zm.sysctrl.conf b/abs/core/zoneminder/zm.sysctrl.conf new file mode 100644 index 0000000..4f62a37 --- /dev/null +++ b/abs/core/zoneminder/zm.sysctrl.conf @@ -0,0 +1,2 @@ +kernel.shmall = 2097152 +kernel.shmmax = 4294967296 diff --git a/abs/core/zoneminder/zmeventbackup b/abs/core/zoneminder/zmeventbackup deleted file mode 100755 index 71c9538..0000000 --- a/abs/core/zoneminder/zmeventbackup +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash -#=============================================================================== -# -# FILE: eventdump.sh -# -# USAGE: ./eventdump.sh -# -# DESCRIPTION: Uses mysqldump to create a .sql file for individual zm -# events to make Event table recovery possible by doing a -# 'find' search in ZoneMinder the events directory -# -# OPTIONS: --- -# REQUIREMENTS: --- mysqldump -# BUGS: --- -# NOTES: --- -# AUTHOR: Ross Melin -# COMPANY: -# VERSION: 1.0 -# CREATED: 03/06/2008 11:51:19 AM PST -# REVISION: --- -#=============================================================================== - -# Edit these to suit your configuration -ZM_CONFIG=/etc/zm.conf -MYSQLDUMP=/usr/bin/mysqldump -EVENTSDIR=/var/lib/zm/www/events - -# The rest should not need editing - -# Get the mysql user and password -source $ZM_CONFIG -MYDUMPOPTS="--user=$ZM_DB_USER --password=$ZM_DB_PASS --skip-opt --compact --quick --no-create-info" - - -for tag in $(find $EVENTSDIR -amin -65 -name ".[0-9]*") - do - EVENT_PATH=$(echo $tag |cut -f 1 -d .) - EVENT_ID=$(echo $tag |cut -f 2 -d .) - # Dump the sql statements needed to reload the Events, Frames and Stats tables - - echo "-- ZM_DB_VERSION=$ZM_VERSION -" > $EVENT_PATH.sql - - $MYSQLDUMP $MYDUMPOPTS --where="Id=$EVENT_ID" zm Events >> $EVENT_PATH.sql - $MYSQLDUMP $MYDUMPOPTS --where="Eventid=$EVENT_ID" zm Frames >> $EVENT_PATH.sql - $MYSQLDUMP $MYDUMPOPTS --where="Eventid=$EVENT_ID" zm Stats >> $EVENT_PATH.sql - -done diff --git a/abs/core/zoneminder/zmfilter.pl b/abs/core/zoneminder/zmfilter.pl deleted file mode 100755 index 7875937..0000000 --- a/abs/core/zoneminder/zmfilter.pl +++ /dev/null @@ -1,1119 +0,0 @@ -#!/usr/bin/perl -wT -# -# ========================================================================== -# -# ZoneMinder Event Filter Script, $Date: 2008-10-09 10:17:07 +0100 (Thu, 09 Oct 2008) $, $Revision: 2659 $ -# Copyright (C) 2001-2008 Philip Coombes -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -# ========================================================================== -# -# This script continuously monitors the recorded events for the given -# monitor and applies any filters which would delete and/or upload -# matching events -# -use strict; -use bytes; - -# ========================================================================== -# -# These are the elements you can edit to suit your installation -# -# ========================================================================== - -use constant DBG_ID => "zmfilter"; # Tag that appears in debug to identify source -use constant DBG_LEVEL => 0; # 0 is errors, warnings and info only, > 0 for debug - -use constant START_DELAY => 5; # How long to wait before starting - -# ========================================================================== -# -# You shouldn't need to change anything from here downwards -# -# ========================================================================== - -use ZoneMinder; -use DBI; -use POSIX; -use Time::HiRes qw/gettimeofday/; -use Date::Manip; -use Getopt::Long; -use PHP::Serialization qw(serialize unserialize); -use Data::Dumper; - -use constant EVENT_PATH => ZM_PATH_WEB.'/'.ZM_DIR_EVENTS; - -zmDbgInit( DBG_ID, level=>DBG_LEVEL ); -zmDbgSetSignal(); - -if ( ZM_OPT_UPLOAD ) -{ - # Comment these out if you don't have them and don't want to upload - # or don't want to use that format - if ( ZM_UPLOAD_ARCH_FORMAT eq "zip" ) - { - require Archive::Zip; - import Archive::Zip qw( :ERROR_CODES :CONSTANTS ); - } - else - { - require Archive::Tar; - } - require Net::FTP; -} - -if ( ZM_OPT_EMAIL ) -{ - if ( ZM_NEW_MAIL_MODULES ) - { - require MIME::Lite; - require Net::SMTP; - } - else - { - require MIME::Entity; - } -} - -if ( ZM_OPT_MESSAGE ) -{ - if ( ZM_NEW_MAIL_MODULES ) - { - require MIME::Lite; - require Net::SMTP; - } - else - { - require MIME::Entity; - } -} - - -$| = 1; - -$ENV{PATH} = '/bin:/usr/bin'; -$ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL}; -delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; - -my $delay = ZM_FILTER_EXECUTE_INTERVAL; -my $event_id = 0; -my $filter_parm = ""; - -sub Usage -{ - print( " -Usage: zmfilter.pl [-f ,--filter=] -Parameters are :- --f, --filter= - The name of a specific filter to run -"); - exit( -1 ); -} - -# -# More or less replicates the equivalent PHP function -# -sub strtotime -{ - my $dt_str = shift; - return( UnixDate( $dt_str, '%s' ) ); -} - -# -# More or less replicates the equivalent PHP function -# -sub str_repeat -{ - my $string = shift; - my $count = shift; - return( ${string}x${count} ); -} - -# Formats a date into MySQL format -sub DateTimeToSQL -{ - my $dt_str = shift; - my $dt_val = strtotime( $dt_str ); - if ( !$dt_val ) - { - Error( "Unable to parse date string '$dt_str'\n" ); - return( undef ); - } - return( strftime( "%Y-%m-%d %H:%M:%S", localtime( $dt_val ) ) ); -} - -if ( !GetOptions( 'filter=s'=>\$filter_parm ) ) -{ - Usage(); -} - -chdir( EVENT_PATH ); - -my $dbh = zmDbConnect(); - -if ( $filter_parm ) -{ - Info( "Scanning for events using filter '$filter_parm'\n" ); -} -else -{ - Info( "Scanning for events\n" ); -} - -if ( !$filter_parm ) -{ - sleep( START_DELAY ); -} - -my $filters; -my $last_action = 0; - -while( 1 ) -{ - if ( (time() - $last_action) > ZM_FILTER_RELOAD_DELAY ) - { - Debug( "Reloading filters\n" ); - $last_action = time(); - $filters = getFilters( $filter_parm ); - } - - foreach my $filter ( @$filters ) - { - checkFilter( $filter ); - } - - last if ( $filter_parm ); - - Debug( "Sleeping for $delay seconds\n" ); - sleep( $delay ); -} - -sub getDiskPercent -{ - my $command = "df ."; - my $df = qx( $command ); - my $space = -1; - if ( $df =~ /\s(\d+)%/ms ) - { - $space = $1; - } - return( $space ); -} - -sub getDiskBlocks -{ - my $command = "df ."; - my $df = qx( $command ); - my $space = -1; - if ( $df =~ /\s(\d+)\s+\d+\s+\d+%/ms ) - { - $space = $1; - } - return( $space ); -} - -sub getLoad -{ - my $command = "uptime ."; - my $uptime = qx( $command ); - my $load = -1; - if ( $uptime =~ /load average:\s+([\d.]+)/ms ) - { - $load = $1; - Info( "Load: $load" ); - } - return( $load ); -} - -sub getFilters -{ - my $filter_name = shift; - - my @filters; - my $sql = "select * from Filters where"; - if ( $filter_name ) - { - $sql .= " Name = ? and"; - } - else - { - $sql .= " Background = 1 and"; - } - $sql .= " (AutoArchive = 1 or AutoVideo = 1 or AutoUpload = 1 or AutoEmail = 1 or AutoMessage = 1 or AutoExecute = 1 or AutoDelete = 1) order by Name"; - my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); - my $res; - if ( $filter_name ) - { - $res = $sth->execute( $filter_name ) or Fatal( "Can't execute '$sql': ".$sth->errstr() ); - } - else - { - $res = $sth->execute() or Fatal( "Can't execute '$sql': ".$sth->errstr() ); - } - FILTER: while( my $db_filter = $sth->fetchrow_hashref() ) - { - Debug( "Found filter '$db_filter->{Name}'\n" ); - my $filter_expr = unserialize( $db_filter->{Query} ); - my $sql = "select E.Id,E.MonitorId,M.Name as MonitorName,M.DefaultRate,M.DefaultScale,E.Name,E.Cause,E.Notes,E.StartTime,unix_timestamp(E.StartTime) as Time,E.Length,E.Frames,E.AlarmFrames,E.TotScore,E.AvgScore,E.MaxScore,E.Archived,E.Videoed,E.Uploaded,E.Emailed,E.Messaged,E.Executed from Events as E inner join Monitors as M on M.Id = E.MonitorId where not isnull(E.EndTime)"; - $db_filter->{Sql} = ''; - - if ( @{$filter_expr->{terms}} ) - { - for ( my $i = 0; $i < @{$filter_expr->{terms}}; $i++ ) - { - if ( exists($filter_expr->{terms}[$i]->{cnj}) ) - { - $db_filter->{Sql} .= " ".$filter_expr->{terms}[$i]->{cnj}." "; - } - if ( exists($filter_expr->{terms}[$i]->{obr}) ) - { - $db_filter->{Sql} .= " ".str_repeat( "(", $filter_expr->{terms}[$i]->{obr} )." "; - } - my $value = $filter_expr->{terms}[$i]->{val}; - my @value_list; - if ( $filter_expr->{terms}[$i]->{attr} ) - { - if ( $filter_expr->{terms}[$i]->{attr} =~ /^Monitor/ ) - { - my ( $temp_attr_name ) = $filter_expr->{terms}[$i]->{attr} =~ /^Monitor(.+)$/; - $db_filter->{Sql} .= "M.".$temp_attr_name; - } - elsif ( $filter_expr->{terms}[$i]->{attr} eq 'DateTime' ) - { - $db_filter->{Sql} .= "E.StartTime"; - } - elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Date' ) - { - $db_filter->{Sql} .= "to_days( E.StartTime )"; - } - elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Time' ) - { - $db_filter->{Sql} .= "extract( hour_second from E.StartTime )"; - } - elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Weekday' ) - { - $db_filter->{Sql} .= "weekday( E.StartTime )"; - } - elsif ( $filter_expr->{terms}[$i]->{attr} eq 'DiskPercent' ) - { - $db_filter->{Sql} .= "zmDiskPercent"; - $db_filter->{HasDiskPercent} = !undef; - } - elsif ( $filter_expr->{terms}[$i]->{attr} eq 'DiskBlocks' ) - { - $db_filter->{Sql} .= "zmDiskBlocks"; - $db_filter->{HasDiskBlocks} = !undef; - } - elsif ( $filter_expr->{terms}[$i]->{attr} eq 'SystemLoad' ) - { - $db_filter->{Sql} .= "zmSystemLoad"; - $db_filter->{HasSystemLoad} = !undef; - } - else - { - $db_filter->{Sql} .= "E.".$filter_expr->{terms}[$i]->{attr}; - } - - ( my $stripped_value = $value ) =~ s/^["\']+?(.+)["\']+?$/$1/; - foreach my $temp_value ( split( '/["\'\s]*?,["\'\s]*?/', $stripped_value ) ) - { - if ( $filter_expr->{terms}[$i]->{attr} =~ /^Monitor/ ) - { - $value = "'$temp_value'"; - } - elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Name' || $filter_expr->{terms}[$i]->{attr} eq 'Cause' || $filter_expr->{terms}[$i]->{attr} eq 'Notes' ) - { - $value = "'$temp_value'"; - } - elsif ( $filter_expr->{terms}[$i]->{attr} eq 'DateTime' ) - { - $value = DateTimeToSQL( $temp_value ); - if ( !$value ) - { - Error( "Error parsing date/time '$temp_value', skipping filter '$db_filter->{Name}'\n" ); - next FILTER; - } - $value = "'$value'"; - } - elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Date' ) - { - $value = DateTimeToSQL( $temp_value ); - if ( !$value ) - { - Error( "Error parsing date/time '$temp_value', skipping filter '$db_filter->{Name}'\n" ); - next FILTER; - } - $value = "to_days( '$value' )"; - } - elsif ( $filter_expr->{terms}[$i]->{attr} eq 'Time' ) - { - $value = DateTimeToSQL( $temp_value ); - if ( !$value ) - { - Error( "Error parsing date/time '$temp_value', skipping filter '$db_filter->{Name}'\n" ); - next FILTER; - } - $value = "extract( hour_second from '$value' )"; - } - else - { - $value = $temp_value; - } - push( @value_list, $value ); - } - } - if ( $filter_expr->{terms}[$i]->{op} ) - { - if ( $filter_expr->{terms}[$i]->{op} eq '=~' ) - { - $db_filter->{Sql} .= " regexp $value"; - } - elsif ( $filter_expr->{terms}[$i]->{op} eq '!~' ) - { - $db_filter->{Sql} .= " not regexp $value"; - } - elsif ( $filter_expr->{terms}[$i]->{op} eq '=[]' ) - { - $db_filter->{Sql} .= " in (".join( ",", @value_list ).")"; - } - elsif ( $filter_expr->{terms}[$i]->{op} eq '!~' ) - { - $db_filter->{Sql} .= " not in (".join( ",", @value_list ).")"; - } - else - { - $db_filter->{Sql} .= " ".$filter_expr->{terms}[$i]->{op}." $value"; - } - } - if ( exists($filter_expr->{terms}[$i]->{cbr}) ) - { - $db_filter->{Sql} .= " ".str_repeat( ")", $filter_expr->{terms}[$i]->{cbr} )." "; - } - } - } - if ( $db_filter->{Sql} ) - { - $sql .= " and ( ".$db_filter->{Sql}." )"; - } - my @auto_terms; - if ( $db_filter->{AutoArchive} ) - { - push( @auto_terms, "E.Archived = 0" ) - } - if ( $db_filter->{AutoVideo} ) - { - push( @auto_terms, "E.Videoed = 0" ) - } - if ( $db_filter->{AutoUpload} ) - { - push( @auto_terms, "E.Uploaded = 0" ) - } - if ( $db_filter->{AutoEmail} ) - { - push( @auto_terms, "E.Emailed = 0" ) - } - if ( $db_filter->{AutoMessage} ) - { - push( @auto_terms, "E.Messaged = 0" ) - } - if ( $db_filter->{AutoExecute} ) - { - push( @auto_terms, "E.Executed = 0" ) - } - if ( @auto_terms ) - { - $sql .= " and ( ".join( " or ", @auto_terms )." )"; - } - if ( !$filter_expr->{sort_field} ) - { - $filter_expr->{sort_field} = 'StartTime'; - $filter_expr->{sort_asc} = 0; - } - my $sort_column = ''; - if ( $filter_expr->{sort_field} eq 'Id' ) - { - $sort_column = "E.Id"; - } - elsif ( $filter_expr->{sort_field} eq 'MonitorName' ) - { - $sort_column = "M.Name"; - } - elsif ( $filter_expr->{sort_field} eq 'Name' ) - { - $sort_column = "E.Name"; - } - elsif ( $filter_expr->{sort_field} eq 'StartTime' ) - { - $sort_column = "E.StartTime"; - } - elsif ( $filter_expr->{sort_field} eq 'Secs' ) - { - $sort_column = "E.Length"; - } - elsif ( $filter_expr->{sort_field} eq 'Frames' ) - { - $sort_column = "E.Frames"; - } - elsif ( $filter_expr->{sort_field} eq 'AlarmFrames' ) - { - $sort_column = "E.AlarmFrames"; - } - elsif ( $filter_expr->{sort_field} eq 'TotScore' ) - { - $sort_column = "E.TotScore"; - } - elsif ( $filter_expr->{sort_field} eq 'AvgScore' ) - { - $sort_column = "E.AvgScore"; - } - elsif ( $filter_expr->{sort_field} eq 'MaxScore' ) - { - $sort_column = "E.MaxScore"; - } - else - { - $sort_column = "E.StartTime"; - } - my $sort_order = $filter_expr->{sort_asc}?"asc":"desc"; - $sql .= " order by ".$sort_column." ".$sort_order; - if ( $filter_expr->{limit} ) - { - $sql .= " limit 0,".$filter_expr->{limit}; - } - Debug( "SQL:$sql\n" ); - $db_filter->{Sql} = $sql; - if ( $db_filter->{AutoExecute} ) - { - my $script = $db_filter->{AutoExecuteCmd}; - $script =~ s/\s.*$//; - if ( !-e $script ) - { - Error( "Auto execute script '$script' not found, skipping filter '$db_filter->{Name}'\n" ); - next FILTER; - - } - elsif ( !-x $script ) - { - Error( "Auto execute script '$script' not executable, skipping filter '$db_filter->{Name}'\n" ); - next FILTER; - } - } - push( @filters, $db_filter ); - } - $sth->finish(); - - return( \@filters ); -} - -sub checkFilter -{ - my $filter = shift; - - Debug( "Checking filter '$filter->{Name}'". - ($filter->{AutoDelete}?", delete":""). - ($filter->{AutoArchive}?", archive":""). - ($filter->{AutoVideo}?", video":""). - ($filter->{AutoUpload}?", upload":""). - ($filter->{AutoEmail}?", email":""). - ($filter->{AutoMessage}?", message":""). - ($filter->{AutoExecute}?", execute":""). - "\n" - ); - my $sql = $filter->{Sql}; - - if ( $filter->{HasDiskPercent} ) - { - my $disk_percent = getDiskPercent(); - $sql =~ s/zmDiskPercent/$disk_percent/g; - } - if ( $filter->{HasDiskBlocks} ) - { - my $disk_blocks = getDiskBlocks(); - $sql =~ s/zmDiskBlocks/$disk_blocks/g; - } - if ( $filter->{HasSystemLoad} ) - { - my $load = getLoad(); - $sql =~ s/zmSystemLoad/$load/g; - } - - my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); - my $res = $sth->execute(); - if ( !$res ) - { - Error( "Can't execute filter '$sql', ignoring: ".$sth->errstr() ); - return; - } - - while( my $event = $sth->fetchrow_hashref() ) - { - Debug( "Checking event $event->{Id}\n" ); - my $delete_ok = !undef; - if ( $filter->{AutoArchive} ) - { - Info( "Archiving event $event->{Id}\n" ); - # Do it individually to avoid locking up the table for new events - my $sql = "update Events set Archived = 1 where Id = ?"; - my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); - my $res = $sth->execute( $event->{Id} ) or Fatal( "Can't execute '$sql': ".$sth->errstr() ); - } - if ( ZM_OPT_FFMPEG && $filter->{AutoVideo} ) - { - if ( !$event->{Videoed} ) - { - $delete_ok = undef if ( !generateVideo( $filter, $event ) ); - } - } - if ( ZM_OPT_EMAIL && $filter->{AutoEmail} ) - { - if ( !$event->{Emailed} ) - { - $delete_ok = undef if ( !sendEmail( $filter, $event ) ); - } - } - if ( ZM_OPT_MESSAGE && $filter->{AutoMessage} ) - { - if ( !$event->{Messaged} ) - { - $delete_ok = undef if ( !sendMessage( $filter, $event ) ); - } - } - if ( ZM_OPT_UPLOAD && $filter->{AutoUpload} ) - { - if ( !$event->{Uploaded} ) - { - $delete_ok = undef if ( !uploadArchFile( $filter, $event ) ); - } - } - if ( $filter->{AutoExecute} ) - { - if ( !$event->{Execute} ) - { - $delete_ok = undef if ( !executeCommand( $filter, $event ) ); - } - } - if ( $filter->{AutoDelete} ) - { - if ( $delete_ok ) - { - Info( "Deleting event $event->{Id}\n" ); - # Do it individually to avoid locking up the table for new events - my $sql = "delete from Events where Id = ?"; - my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); - my $res = $sth->execute( $event->{Id} ) or Fatal( "Can't execute '$sql': ".$sth->errstr() ); - - if ( !ZM_OPT_FAST_DELETE ) - { - my $sql = "delete from Frames where EventId = ?"; - my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); - my $res = $sth->execute( $event->{Id} ) or Fatal( "Can't execute '$sql': ".$sth->errstr() ); - - $sql = "delete from Stats where EventId = ?"; - $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); - $res = $sth->execute( $event->{Id} ) or Fatal( "Can't execute '$sql': ".$sth->errstr() ); - - deleteEventFiles( $event->{Id}, $event->{MonitorId} ); - } - } - else - { - Error( "Unable to delete event $event->{Id} as previous operations failed\n" ); - } - } - } - $sth->finish(); -} - -sub generateVideo -{ - my $filter = shift; - my $event = shift; - my $phone = shift; - - my $rate = $event->{DefaultRate}/100; - my $scale = $event->{DefaultScale}/100; - my $format; - - my @ffmpeg_formats = split( /\s+/, ZM_FFMPEG_FORMATS ); - my $default_video_format; - my $default_phone_format; - foreach my $ffmpeg_format( @ffmpeg_formats ) - { - if ( $ffmpeg_format =~ /^(.+)\*\*$/ ) - { - $default_phone_format = $1; - } - elsif ( $ffmpeg_format =~ /^(.+)\*$/ ) - { - $default_video_format = $1; - } - } - - if ( $phone && $default_phone_format ) - { - $format = $default_phone_format; - } - elsif ( $default_video_format ) - { - $format = $default_video_format; - } - else - { - $format = $ffmpeg_formats[0]; - } - - my $command = ZM_PATH_BIN."/zmvideo.pl -e ".$event->{Id}." -r ".$rate." -s ".$scale." -f ".$format; - my $output = qx($command); - chomp( $output ); - my $status = $? >> 8; - if ( $status || DBG_LEVEL > 0 ) - { - Debug( "Output: $output\n" ); - } - if ( $status ) - { - Error( "Video generation '$command' failed with status: $status\n" ); - if ( wantarray() ) - { - return( undef, undef ); - } - return( 0 ); - } - else - { - my $sql = "update Events set Videoed = 1 where Id = ?"; - my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); - my $res = $sth->execute( $event->{Id} ) or Fatal( "Can't execute '$sql': ".$sth->errstr() ); - if ( wantarray() ) - { - return( $format, sprintf( "%s/%s", getEventPath( $event ), $output ) ); - } - } - return( 1 ); -} - -sub uploadArchFile -{ - my $filter = shift; - my $event = shift; - if ( !ZM_UPLOAD_FTP_HOST ) - { - Error( "Cannot upload archive as no FTP host defined" ); - return( 0 ); - } - - my $arch_file = ZM_UPLOAD_FTP_LOC_DIR.'/'.$event->{MonitorName}.'-'.$event->{Id}; - my $arch_image_path = getEventPath( $event )."/".((ZM_UPLOAD_ARCH_ANALYSE)?'{*analyse,*capture}':'*capture').".jpg"; - my @arch_image_files = glob($arch_image_path); - - my $arch_error; - if ( ZM_UPLOAD_ARCH_FORMAT eq "zip" ) - { - $arch_file .= '.zip'; - my $zip = Archive::Zip->new(); - Info( "Creating upload file '$arch_file', ".int(@arch_image_files)." files\n" ); - - my $status = &AZ_OK; - foreach my $image_file ( @arch_image_files ) - { - Info( "Adding $image_file\n" ); - my $member = $zip->addFile( $image_file ); - last unless ( $member ); - $member->desiredCompressionMethod( (ZM_UPLOAD_ARCH_COMPRESS)?&COMPRESSION_DEFLATED:&COMPRESSION_STORED ); - } - $status = $zip->writeToFileNamed( $arch_file ); - - if ( $arch_error = ($status != &AZ_OK) ) - { - Error( "Zip error: $status\n " ); - } - } - elsif ( ZM_UPLOAD_ARCH_FORMAT eq "tar" ) - { - if ( ZM_UPLOAD_ARCH_COMPRESS ) - { - $arch_file .= '.tar.gz'; - } - else - { - $arch_file .= '.tar'; - } - Info( "Creating upload file '$arch_file', ".int(@arch_image_files)." files\n" ); - - if ( $arch_error = !Archive::Tar->create_archive( $arch_file, ZM_UPLOAD_ARCH_COMPRESS, @arch_image_files ) ) - { - Error( "Tar error: ".Archive::Tar->error()."\n " ); - } - } - - if ( $arch_error ) - { - return( 0 ); - } - else - { - Info( "Uploading to ".ZM_UPLOAD_FTP_HOST."\n" ); - my $ftp = Net::FTP->new( ZM_UPLOAD_FTP_HOST, Timeout=>ZM_UPLOAD_FTP_TIMEOUT, Passive=>ZM_UPLOAD_FTP_PASSIVE, Debug=>ZM_UPLOAD_FTP_DEBUG ); - if ( !$ftp ) - { - warn( "Can't create ftp connection: $@" ); - return( 0 ); - } - - $ftp->login( ZM_UPLOAD_FTP_USER, ZM_UPLOAD_FTP_PASS ) or warn( "FTP - Can't login" ); - $ftp->binary() or warn( "FTP - Can't go binary" ); - $ftp->cwd( ZM_UPLOAD_FTP_REM_DIR ) or warn( "FTP - Can't cwd" ); - $ftp->put( $arch_file ) or warn( "FTP - Can't upload '$arch_file'" ); - $ftp->quit() or warn( "FTP - Can't quit" ); - unlink( $arch_file ); - my $sql = "update Events set Uploaded = 1 where Id = ?"; - my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); - my $res = $sth->execute( $event->{Id} ) or Fatal( "Can't execute '$sql': ".$sth->errstr() ); - } - return( 1 ); -} - -sub substituteTags -{ - my $text = shift; - my $filter = shift; - my $event = shift; - my $attachments_ref = shift; - - # First we'd better check what we need to get - # We have a filter and an event, do we need any more - # monitor information? - my $need_monitor = $text =~ /%(?:MET|MEH|MED|MEW|MEN|MEA)%/; - - my $monitor = {}; - if ( $need_monitor ) - { - my $db_now = strftime( "%Y-%m-%d %H:%M:%S", localtime() ); - my $sql = "select M.Id, count(E.Id) as EventCount, count(if(E.Archived,1,NULL)) as ArchEventCount, count(if(E.StartTime>'$db_now' - INTERVAL 1 HOUR && E.Archived = 0,1,NULL)) as HourEventCount, count(if(E.StartTime>'$db_now' - INTERVAL 1 DAY && E.Archived = 0,1,NULL)) as DayEventCount, count(if(E.StartTime>'$db_now' - INTERVAL 7 DAY && E.Archived = 0,1,NULL)) as WeekEventCount, count(if(E.StartTime>'$db_now' - INTERVAL 1 MONTH && E.Archived = 0,1,NULL)) as MonthEventCount from Monitors as M left join Events as E on E.MonitorId = M.Id where MonitorId = ? group by E.MonitorId order by Id"; - my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); - my $res = $sth->execute( $event->{MonitorId} ) or Fatal( "Can't execute '$sql': ".$sth->errstr() ); - $monitor = $sth->fetchrow_hashref(); - $sth->finish(); - return() if ( !$monitor ); - } - - # Do we need the image information too? - my $need_images = $text =~ /%(?:EPI1|EPIM|EI1|EIM)%/; - my $first_alarm_frame; - my $max_alarm_frame; - my $max_alarm_score = 0; - if ( $need_images ) - { - my $sql = "select * from Frames where EventId = ? and Type = 'Alarm' order by FrameId"; - my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); - my $res = $sth->execute( $event->{Id} ) or Fatal( "Can't execute '$sql': ".$sth->errstr() ); - while( my $frame = $sth->fetchrow_hashref() ) - { - if ( !$first_alarm_frame ) - { - $first_alarm_frame = $frame; - } - if ( $frame->{Score} > $max_alarm_score ) - { - $max_alarm_frame = $frame; - $max_alarm_score = $frame->{Score}; - } - } - $sth->finish(); - } - - my $url = ZM_URL; - $text =~ s/%ZP%/$url/g; - $text =~ s/%MN%/$event->{MonitorName}/g; - $text =~ s/%MET%/$monitor->{EventCount}/g; - $text =~ s/%MEH%/$monitor->{HourEventCount}/g; - $text =~ s/%MED%/$monitor->{DayEventCount}/g; - $text =~ s/%MEW%/$monitor->{WeekEventCount}/g; - $text =~ s/%MEM%/$monitor->{MonthEventCount}/g; - $text =~ s/%MEA%/$monitor->{ArchEventCount}/g; - $text =~ s/%MP%/$url?view=watch&mid=$event->{MonitorId}/g; - $text =~ s/%MPS%/$url?view=watchfeed&mid=$event->{MonitorId}&mode=stream/g; - $text =~ s/%MPI%/$url?view=watchfeed&mid=$event->{MonitorId}&mode=still/g; - $text =~ s/%EP%/$url?view=event&mid=$event->{MonitorId}&eid=$event->{Id}/g; - $text =~ s/%EPS%/$url?view=event&mode=stream&mid=$event->{MonitorId}&eid=$event->{Id}/g; - $text =~ s/%EPI%/$url?view=event&mode=still&mid=$event->{MonitorId}&eid=$event->{Id}/g; - $text =~ s/%EI%/$event->{Id}/g; - $text =~ s/%EN%/$event->{Name}/g; - $text =~ s/%EC%/$event->{Cause}/g; - $text =~ s/%ED%/$event->{Notes}/g; - $text =~ s/%ET%/$event->{StartTime}/g; - $text =~ s/%EL%/$event->{Length}/g; - $text =~ s/%EF%/$event->{Frames}/g; - $text =~ s/%EFA%/$event->{AlarmFrames}/g; - $text =~ s/%EST%/$event->{TotScore}/g; - $text =~ s/%ESA%/$event->{AvgScore}/g; - $text =~ s/%ESM%/$event->{MaxScore}/g; - if ( $first_alarm_frame ) - { - $text =~ s/%EPI1%/$url?view=frame&mid=$event->{MonitorId}&eid=$event->{Id}&fid=$first_alarm_frame->{FrameId}/g; - $text =~ s/%EPIM%/$url?view=frame&mid=$event->{MonitorId}&eid=$event->{Id}&fid=$max_alarm_frame->{FrameId}/g; - if ( $attachments_ref && $text =~ s/%EI1%//g ) - { - push( @$attachments_ref, { type=>"image/jpeg", path=>sprintf( "%s/%0".ZM_EVENT_IMAGE_DIGITS."d-capture.jpg", getEventPath( $event ), $first_alarm_frame->{FrameId} ) } ); - } - if ( $attachments_ref && $text =~ s/%EIM%//g ) - { - # Don't attach the same image twice - if ( !@$attachments_ref || ($first_alarm_frame->{FrameId} != $max_alarm_frame->{FrameId} ) ) - { - push( @$attachments_ref, { type=>"image/jpeg", path=>sprintf( "%s/%0".ZM_EVENT_IMAGE_DIGITS."d-capture.jpg", getEventPath( $event ), $max_alarm_frame->{FrameId} ) } ); - } - } - } - if ( $attachments_ref && ZM_OPT_FFMPEG ) - { - if ( $text =~ s/%EV%//g ) - { - my ( $format, $path ) = generateVideo( $filter, $event ); - if ( !$format ) - { - return( undef ); - } - push( @$attachments_ref, { type=>"video/$format", path=>$path } ); - } - if ( $text =~ s/%EVM%//g ) - { - my ( $format, $path ) = generateVideo( $filter, $event, 1 ); - if ( !$format ) - { - return( undef ); - } - push( @$attachments_ref, { type=>"video/$format", path=>$path } ); - } - } - $text =~ s/%FN%/$filter->{Name}/g; - ( my $filter_name = $filter->{Name} ) =~ s/ /+/g; - $text =~ s/%FP%/$url?view=filter&mid=$event->{MonitorId}&filter_name=$filter_name/g; - - return( $text ); -} - -sub sendEmail -{ - my $filter = shift; - my $event = shift; - - if ( !ZM_FROM_EMAIL ) - { - warn( "No 'from' email address defined, not sending email" ); - return( 0 ); - } - if ( !ZM_EMAIL_ADDRESS ) - { - warn( "No email address defined, not sending email" ); - return( 0 ); - } - - Info( "Creating notification email\n" ); - - my $subject = substituteTags( ZM_EMAIL_SUBJECT, $filter, $event ); - return( 0 ) if ( !$subject ); - my @attachments; - my $body = substituteTags( ZM_EMAIL_BODY, $filter, $event, \@attachments ); - return( 0 ) if ( !$body ); - - Info( "Sending notification email '$subject'\n" ); - - eval - { - if ( ZM_NEW_MAIL_MODULES ) - { - ### Create the multipart container - my $mail = MIME::Lite->new ( - From => ZM_FROM_EMAIL, - To => ZM_EMAIL_ADDRESS, - Subject => $subject, - Type => "multipart/mixed" - ); - ### Add the text message part - $mail->attach ( - Type => "TEXT", - Data => $body - ); - ### Add the attachments - foreach my $attachment ( @attachments ) - { - Info( "Attaching '$attachment->{path}\n" ); - $mail->attach( - Path => $attachment->{path}, - Type => $attachment->{type}, - Disposition => "attachment" - ); - } - ### Send the Message - MIME::Lite->send( "smtp", ZM_EMAIL_HOST, Timeout=>60 ); - $mail->send(); - } - else - { - my $from_email = substituteTags( ZM_FROM_EMAIL ); - my $email_address = substituteTags( ZM_EMAIL_ADDRESS ); - my @attachpaths ; - foreach my $attachment ( @attachments ) - { - push(@attachpaths, $attachment->{path} ); - } - my $attachstring ; - if ( @attachpaths ) - { - $attachstring = join(" -a "," ", @attachpaths); - } - Info( "Executing /usr/bin/email -s \" $subject\" $attachstring -f $from_email $email_address \n" ); - my $mail = `/usr/bin/email -s \"$subject\" $attachstring -f $from_email $email_address << EOF $body `; - } - }; - if ( $@ ) - { - warn( "Can't send email: $@" ); - return( 0 ); - } - else - { - Info( "Notification email sent\n" ); - } - my $sql = "update Events set Emailed = 1 where Id = ?"; - my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); - my $res = $sth->execute( $event->{Id} ) or Fatal( "Can't execute '$sql': ".$sth->errstr() ); - - return( 1 ); -} - -sub sendMessage -{ - my $filter = shift; - my $event = shift; - - if ( !ZM_FROM_EMAIL ) - { - warn( "No 'from' email address defined, not sending message" ); - return( 0 ); - } - if ( !ZM_MESSAGE_ADDRESS ) - { - warn( "No message address defined, not sending message" ); - return( 0 ); - } - - Info( "Creating notification message\n" ); - - my $subject = substituteTags( ZM_MESSAGE_SUBJECT, $filter, $event ); - return( 0 ) if ( !$subject ); - my @attachments; - my $body = substituteTags( ZM_MESSAGE_BODY, $filter, $event, \@attachments ); - return( 0 ) if ( !$body ); - - Info( "Sending notification message '$subject'\n" ); - - eval - { - if ( ZM_NEW_MAIL_MODULES ) - { - ### Create the multipart container - my $mail = MIME::Lite->new ( - From => ZM_FROM_EMAIL, - To => ZM_MESSAGE_ADDRESS, - Subject => $subject, - Type => "multipart/mixed" - ); - ### Add the text message part - $mail->attach ( - Type => "TEXT", - Data => $body - ); - ### Add the attachments - foreach my $attachment ( @attachments ) - { - Info( "Attaching '$attachment->{path}\n" ); - $mail->attach( - Path => $attachment->{path}, - Type => $attachment->{type}, - Disposition => "attachment" - ); - } - ### Send the Message - MIME::Lite->send( "smtp", ZM_EMAIL_HOST, Timeout=>60 ); - $mail->send(); - } - else - { - my $from_email = substituteTags( ZM_FROM_EMAIL ); - my $email_address = substituteTags( ZM_EMAIL_ADDRESS ); - my @attachpaths ; - foreach my $attachment ( @attachments ) - { - push(@attachpaths, $attachment->{path} ); - } - my $attachstring ; - if ( @attachpaths ) - { - $attachstring = join(" -a "," ", @attachpaths); - } - Info( "Executing /usr/bin/email -s \" $subject\" $attachstring -f $from_email $email_address \n" ); - my $mail = `/usr/bin/email -s \"$subject\" $attachstring -f $from_email $email_address << EOF $body `; - } - }; - if ( $@ ) - { - warn( "Can't send email: $@" ); - return( 0 ); - } - else - { - Info( "Notification message sent\n" ); - } - my $sql = "update Events set Messaged = 1 where Id = ?"; - my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); - my $res = $sth->execute( $event->{Id} ) or Fatal( "Can't execute '$sql': ".$sth->errstr() ); - - return( 1 ); -} - -sub executeCommand -{ - my $filter = shift; - my $event = shift; - - my $event_path = getEventPath( $event ); - - my $command = $filter->{AutoExecuteCmd}; - $command .= " $event_path"; - - Info( "Executing '$command'\n" ); - my $output = qx($command); - my $status = $? >> 8; - if ( $status || DBG_LEVEL > 0 ) - { - chomp( $output ); - Debug( "Output: $output\n" ); - } - if ( $status ) - { - Error( "Command '$command' exited with status: $status\n" ); - return( 0 ); - } - else - { - my $sql = "update Events set Executed = 1 where Id = ?"; - my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); - my $res = $sth->execute( $event->{Id} ) or Fatal( "Can't execute '$sql': ".$sth->errstr() ); - } - return( 1 ); -} - diff --git a/abs/core/zoneminder/zminit.arch b/abs/core/zoneminder/zminit.arch deleted file mode 100755 index 01b6658..0000000 --- a/abs/core/zoneminder/zminit.arch +++ /dev/null @@ -1,143 +0,0 @@ -#!/bin/sh - - -ZM_CONFIG=/etc/zm.conf - - - -loadcfg() { - if [ -f $ZM_CONFIG ]; then - . $ZM_CONFIG - else - echo "ERROR: $ZM_CONFIG not found." - exit 1 - fi - } -chkmysql(){ - #FIXME - /etc/rc.d/mysqld restart || (echo "mysql is not availible" && exit 1 ) - } - -getmylogin(){ - echo "Enter MySQL Administrator username" - echo "(Default: root and password is blank)" - echo -n "MySQL Admin: " - read MYADMIN - echo -n "Password: " - read MYPASS - if [ "X$MYPASS" != "X" ]; then MYPASS="-p$MYPASS"; fi - echo "\q" |mysql -u $MYADMIN $MYPASS || exit 0 - - } - -checkdb() -{ - # Check database exisits and version - exists=$(echo "show databases" |mysql -u $MYADMIN "$MYPASS" |grep zm) - if [ "$exists" = "zm" ]; then - OLD_VERSION=$(echo "select Value from Config where Name = 'ZM_DYN_DB_VERSION';" | mysql -u $MYADMIN $MYPASS zm |grep -v '^Value') - - case $OLD_VERSION in - "") - echo "A zm database exists, but the version is unknown" - echo "Updating is unlikely to succeed" - ;; - "$ZM_VERSION") - echo "The zm database appears to be up to date" - echo "If this is incorrect, edit $ZM_CONFIG to reflect the current version" - ;; - *) - echo "A database fron zm-$OLD_VERSION exists already" - ;; - esac - - while [ true ] - do - echo "Choose one of the following options:" - echo "[U]pdate the database" - echo "[D]rop the old database and reinitialize" - echo "[E]xit and do nothing" - read OPTION - case $OPTION in - "U"|"u") - /etc/rc.d/zm restart - exit 0 - ;; - "D"|"d") - echo "drop database zm;"|mysql -u $MYADMIN $MYPASS - return - ;; - "E"|"e") - exit 0 - ;; - esac - done - fi -} - -checkcfg(){ -for n in ZM_DB_HOST ZM_DB_NAME ZM_DB_USER ZM_DB_PASS; do - eval "val=\$$n" - if [ "$val" = "" ]; then - echo "ERROR($ZM_CONFIG): $n should not be empty." - echo "Enter a $n for ZM to use the Database." - if [ "$n" = "ZM_DB_PASS" ]; then - echo -n "Will not echo on screen $n : " - stty -echo # Turns off screen echo. - read newval - stty echo # Restores screen echo. - echo "" - ### The following can be used to generate a random password - # randstr newval 16 - else - echo -n "$n : " - read newval - fi - cp $ZM_CONFIG /tmp/$$ && - sed 's/^'$n='.*$/'$n=$newval'/g' /tmp/$$ >$ZM_CONFIG - - fi -done - -if [ "$ZM_DB_HOST" = "localhost" ]; then - ClientHost=localhost -else - ClientHost=`hostname` -fi -} - -reloadcfg(){ -loadcfg -} - -initdb(){ -sql=/tmp/zm.crdb.sql -echo "" >$sql -chmod 600 $sql - -echo "CREATE DATABASE $ZM_DB_NAME;" >>$sql -echo "USE $ZM_DB_NAME;" >>$sql - -echo "GRANT all on $ZM_DB_NAME.* TO '$ZM_DB_USER'@'$ClientHost' IDENTIFIED BY '$ZM_DB_PASS';" >>$sql - -cat $sql | mysql -B -h $ZM_DB_HOST -u $MYADMIN $MYPASS -rm -f $sql - -cat $ZM_PATH_UPDATE/zm_create.sql | mysql -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS $ZM_DB_NAME -( cd $ZM_PATH_UPDATE; perl $ZM_PATH_BIN/zmupdate.pl -f ) - - $ZM_PATH_UPDATE/customdb $ZM_DB_HOST $ZM_DB_NAME $ZM_DB_USER $ZM_DB_PASS -} - - - -loadcfg -getmylogin -checkdb -checkcfg -reloadcfg -initdb - - - - diff --git a/abs/core/zoneminder/zoneminder b/abs/core/zoneminder/zoneminder new file mode 100644 index 0000000..c4cbf4d --- /dev/null +++ b/abs/core/zoneminder/zoneminder @@ -0,0 +1,63 @@ +#!/bin/bash + +daemon_name=zm + +. /etc/rc.conf +. /etc/rc.d/functions + +case "$1" in + start) + stat_busy "Starting Zoneminder" + /usr/bin/zmfix -a + if /usr/bin/zmpkg.pl start >/dev/null ; then + add_daemon $daemon_name + stat_done + else + stat_fail + exit 1 + fi + ;; + + stop) + stat_busy "Stopping Zoneminder" + if /usr/bin/zmpkg.pl stop >/dev/null ; then + rm_daemon $daemon_name + stat_done + else + stat_fail + exit 1 + fi + ;; + + reload) + stat_busy "Reloading Zoneminder" + if /usr/bin/zmpkg.pl graceful >/dev/null ; then + add_daemon $daemon_name + stat_done + else + stat_fail + exit 1 + fi + ;; + + restart) + stat_busy "Restarting Zoneminder" + if /usr/bin/zmpkg.pl restart >/dev/null ; then + add_daemon $daemon_name + stat_done + else + stat_fail + exit 1 + fi + ;; + + status) + stat_busy "Checking Zoneminder status"; + ck_status $daemon_name + ;; + + *) + echo "usage: $0 {start|stop|reload|restart|status}" +esac + +exit 0 diff --git a/abs/core/zoneminder/zoneminder.install b/abs/core/zoneminder/zoneminder.install old mode 100755 new mode 100644 index 250749f..c2e1cb8 --- a/abs/core/zoneminder/zoneminder.install +++ b/abs/core/zoneminder/zoneminder.install @@ -1,55 +1,102 @@ -# zoneminder.install -## arg 1: the new package version -post_install() { - ln -s /usr/share/cambozola/cambozola.jar /srv/zoneminder/www/ - chown -R http.http /srv/zoneminder - chown http.http /etc/zm.conf - cat << EOF -Note: -==> To initialize the ZoneMinder database run (as root) -==> /usr/lib/zm/bin/zminit -EOF +install_db() { + . /etc/systemconfig + if [ $SystemType = Master_backend -o $SystemType = Standalone ] + then + mysql -e "use zm" > /dev/null + rc=$? + if [ $rc = 1 ] + then + echo "Installing zoneminder database zm" + cat /usr/share/zoneminder/db/zm_create.sql | mysql + echo 'grant lock tables, alter,select,insert,update,delete on zm.* to 'zmuser'@localhost identified by "zmpass";' | mysql + fi + else + echo "Will only init the database for StandAlone or Master_backend LinHES systems" + fi + } -cat << EOF -==> Check /etc/php/php.ini and make sure these are uncommented -==> extension=gd.so -==> extension=gettext.so -==> extension=mcrypt.so -==> extension=mysql.so -==> extension=mysqli.so -==> extension=session.so -==> extension=sockets.so +pre_install() { + set -e + abort=false + if [ -L /srv/http/zoneminder/events ]; then + l=$(readlink /srv/http/zoneminder/events) + if [ $l != /var/cache/zoneminder/events ]; then + abort=true + fi + fi + if [ -L /srv/http/zoneminder/images ]; then + l=$(readlink /srv/http/zoneminder/images) + if [ $l != /var/cache/zoneminder/images ]; then + abort=true + fi + fi + if [ $abort = true ]; then + cat >&2 << EOF +Aborting installation of zoneminder due to non-default symlinks in +/srv/http/zoneminder for the images and/or events directory, which could +result in loss of data. Please move your data in each of these directories to +/var/cache/zoneminder before installing zoneminder from the package. EOF -cat << EOF -==> Check /etc/php/php.ini and make sure short_open_tag = On -EOF - + exit 1 + fi + exit 0 +} -cat /etc/php/php.ini |grep "^open_basedir.*/etc/" | \ -grep "/var/lib/zm/www">/dev/null || cat << EOF -==> You must edit /etc/php/php.ini and add to open_basedir "/etc/" and -==> "/var/lib/zm/" like so -==> open_basedir = /home/:/tmp/:/usr/share/pear/:/etc/:/var/lib/zm/ -==> Otherwise ZoneMinder will be unable to read /etc/zm.conf -==> or display its own web directory -EOF +post_install() { + if [[ -d /var/log/zoneminder ]]; then + chmod 0755 /var/log/zoneminder + chown http.http /var/log/zoneminder + else + mkdir -m 0755 /var/log/zoneminder + chown http.http /var/log/zoneminder + fi + if [[ -d /tmp/zoneminder ]]; then + chmod 0700 /tmp/zoneminder + chown http.http /tmp/zoneminder + else + mkdir -m 0700 /tmp/zoneminder + chown http.http /tmp/zoneminder + fi +#--- + usermod -G video http + COUNT=`grep -c "zm.include" /etc/lighttpd/conf.include` + if [ $COUNT == 0 ] + then + echo "==> Adding zm.include to conf.include" + echo "include \"/etc/lighttpd/zm.include\"" >> /etc/lighttpd/conf.include + fi + echo + echo "==> Forcing a re-read of lighttpd's configuration file." + echo "" + /sbin/sv hup /service/lighttpd -cat << EOF -Note: -==> You must edit /etc/httpd/conf/httpd.conf and uncomment/add the line -==> LoadModule php5_module modules/libphp5.so -==> You must also add these lines: -==> Include conf/extra/php5_module.conf -==> Include /etc/httpd/conf/extra/httpd-zm.conf -EOF -touch /var/lib/zm/zm_backup.sql + install_db +#--- +} +post_upgrade() { + post_install + /usr/bin/zmupdate.pl -f >/dev/null } +post_remove() { + if [[ -d /tmp/zoneminder ]]; then + rm -vr /tmp/zoneminder + fi + +#-- + COUNT=`grep -c "zm.include" /etc/lighttpd/conf.include` + if [ $COUNT -gt 0 ] + then + echo "==> Removing zm.include from conf.include" + sed -i 's#include \"/etc/lighttpd/zm.include\"##' -i /etc/lighttpd/conf.include + fi + + + echo + echo "==> Forcing a re-read of lighttpd's configuration file." + echo "" + /sbin/sv hup /service/lighttpd +#-- -## arg 1: the new package version -## arg 2: the old package version -post_upgrade() { -/usr/lib/zm/bin/zmupdate.pl -f >/dev/null } -# vim:set ts=2 sw=2 et: diff --git a/abs/core/zoneminder/zoneminder.service b/abs/core/zoneminder/zoneminder.service new file mode 100644 index 0000000..05cae6f --- /dev/null +++ b/abs/core/zoneminder/zoneminder.service @@ -0,0 +1,13 @@ +[Unit] +Description=Capture, analyse, record and monitor video security cameras +After=network.target remote-fs.target +Required=mysqld.service + +[Service] +Type=forking +ExecStart=/usr/bin/zmpkg.pl start +ExecRestart=/usr/bin/zmpkg.pl restart +ExecStop=/usr/bin/zmpkg.pl stop + +[Install] +WantedBy=multi-user.target -- cgit v0.12