From 7fcbd86ba0bd4c7c3b3e4efd27529dc3df274b48 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 29 Dec 2017 15:29:57 -0500 Subject: [PATCH 1/6] fix auditing Medium directory structures --- scripts/zmaudit.pl.in | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/zmaudit.pl.in b/scripts/zmaudit.pl.in index 2de067c3e..e1c97e448 100644 --- a/scripts/zmaudit.pl.in +++ b/scripts/zmaudit.pl.in @@ -238,8 +238,13 @@ MAIN: while( $loop ) { } elsif ( $$Storage{Scheme} eq 'Medium' ) { foreach my $event_dir ( glob("$monitor_dir/*/*") ) { next if ! -d $event_dir; - my $Event = $fs_events->{$event} = new ZoneMinder::Event(); - $$Event{Id} = $event; + my ( $date, $event_id ) = $event_dir =~ /^$monitor_dir\/(\d{4}\-\d{2}\-\d{2})\/(\d\+)$/; + if ( ! $event_id ) { + Debug("Unable to parse date/event_id from $event_dir"); + next; + } + my $Event = $fs_events->{$event_id} = new ZoneMinder::Event(); + $$Event{Id} = $event_id; $$Event{Path} = $event_dir; $Event->MonitorId( $monitor_dir ); $Event->StorageId( $Storage->Id() ); From a79017b16888b30d819a14936f02c379b2c06cfa Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 1 Jan 2018 12:43:47 -0500 Subject: [PATCH 2/6] add a KEY to Events for EndTime and DiskSpace, since we are constantly selecting on those. Insert the Update DiskSpace filter on db creation. --- db/zm_create.sql.in | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/db/zm_create.sql.in b/db/zm_create.sql.in index ef13ab924..b2d62d461 100644 --- a/db/zm_create.sql.in +++ b/db/zm_create.sql.in @@ -209,11 +209,12 @@ CREATE TABLE `Events` ( `StateId` int(10) unsigned NOT NULL, `Orientation` enum('0','90','180','270','hori','vert') NOT NULL default '0', `DiskSpace` bigint unsigned default NULL, - PRIMARY KEY (`Id`,`MonitorId`), + PRIMARY KEY (`Id`), KEY `MonitorId` (`MonitorId`), KEY `StartTime` (`StartTime`), KEY `Frames` (`Frames`), - KEY `Archived` (`Archived`) + KEY `Archived` (`Archived`), + KEY `EndTime_DiskSpace` (`EndTime`,`DiskSpace`) ) ENGINE=@ZM_MYSQL_ENGINE@; -- @@ -670,6 +671,7 @@ insert into Users VALUES (NULL,'admin',password('admin'),'',1,'View','Edit','Edi -- Add a sample filter to purge the oldest 100 events when the disk is 95% full -- insert into Filters values (NULL,'PurgeWhenFull','{"sort_field":"Id","terms":[{"val":0,"attr":"Archived","op":"="},{"cnj":"and","val":95,"attr":"DiskPercent","op":">="}],"limit":100,"sort_asc":1}',0,0,0,0,0,0,'',1,0,1,0); +insert into Filters values (NULL,'Update DiskSpace','{"terms":[{"attr":"DiskSpace","op":"IS","val":"NULL"}],"sort_field":"Id","sort_asc":"1","limit":"100"}',0,0,0,0,0,0,'',1,1,1,0); -- -- Add in some sample control protocol definitions From edd5bd8874f04b921f6a3847a48a4b5345bda305 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 1 Jan 2018 12:44:09 -0500 Subject: [PATCH 3/6] create the Update DIskSpace filter if it doesn't exist --- db/zm_update-1.31.18.sql | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/db/zm_update-1.31.18.sql b/db/zm_update-1.31.18.sql index 56e15dd3a..fd000bcfa 100644 --- a/db/zm_update-1.31.18.sql +++ b/db/zm_update-1.31.18.sql @@ -10,3 +10,14 @@ SET @s = (SELECT IF( PREPARE stmt FROM @s; EXECUTE stmt; + +SET @s = (SELECT IF( + (SELECT COUNT(*) FROM Filters WHERE Name = 'Update DiskSpace' + AND Query = '{"terms":[{"attr":"DiskSpace","op":"IS","val":"NULL"}],"sort_field":"Id","sort_asc":"1","limit":"100"}' + ) > 0, + "SELECT 'Update Disk Space Filter already exists.'", + "INSERT INTO Filters (Name,Query,UpdateDiskSpace,Background) values ('Update DiskSpace','{\"terms\":[{\"attr\":\"DiskSpace\",\"op\":\"IS\",\"val\":\"NULL\"}],\"sort_field\":\"Id\",\"sort_asc\":\"1\",\"limit\":\"100\"}',1,1)" + )); + +PREPARE stmt FROM @s; +EXECUTE stmt; From 1cd69c69b98b67ecb93c8d95f712589c8d3a7c1c Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 1 Jan 2018 13:10:39 -0500 Subject: [PATCH 4/6] add defining ZM_SERVER_ID after loading config --- web/api/app/Config/bootstrap.php.in | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/web/api/app/Config/bootstrap.php.in b/web/api/app/Config/bootstrap.php.in index cc096f233..d1cd7857d 100644 --- a/web/api/app/Config/bootstrap.php.in +++ b/web/api/app/Config/bootstrap.php.in @@ -142,6 +142,27 @@ foreach( $configvals as $key => $value) { Configure::write( $key, $value ); } +// For Human-readability, use ZM_SERVER_HOST or ZM_SERVER_NAME in zm.conf, and convert it here to a ZM_SERVER_ID +if ( ! defined('ZM_SERVER_ID') ) { + App::uses('ClassRegistry', 'Utility'); + $ServerModel = ClassRegistry::init('Server'); + if ( defined('ZM_SERVER_NAME') and ZM_SERVER_NAME ) { + $Server = $ServerModel->find( 'first', array( 'conditions'=>array('Name'=>ZM_SERVER_NAME) ) ); + if ( ! $Server ) { + Error('Invalid Multi-Server configration detected. ZM_SERVER_NAME set to ' . ZM_SERVER_NAME . ' in zm.conf, but no corresponding entry found in Servers table.'); + } else { + define( 'ZM_SERVER_ID', $Server['Server']['Id'] ); + } + } else if ( defined('ZM_SERVER_HOST') and ZM_SERVER_HOST ) { + $Server = $ServerModel->find( 'first', array( 'conditions'=>array('Name'=>ZM_SERVER_HOST) ) ); + if ( ! $Server ) { + Error('Invalid Multi-Server configration detected. ZM_SERVER_HOST set to ' . ZM_SERVER_HOST . ' in zm.conf, but no corresponding entry found in Servers table.'); + } else { + define( 'ZM_SERVER_ID', $Server['Server']['Id'] ); + } + } +} + function process_configfile($configFile) { if ( is_readable( $configFile ) ) { $configvals = array(); From 6c07347721065789470c570e151b44a6818a499f Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 1 Jan 2018 13:19:16 -0500 Subject: [PATCH 5/6] Fix Update DiskSpace Filter adding --- db/zm_create.sql.in | 21 +++++++++++++++++++-- db/zm_update-1.31.18.sql | 4 ++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/db/zm_create.sql.in b/db/zm_create.sql.in index b2d62d461..f9ac3b6d2 100644 --- a/db/zm_create.sql.in +++ b/db/zm_create.sql.in @@ -670,8 +670,25 @@ insert into Users VALUES (NULL,'admin',password('admin'),'',1,'View','Edit','Edi -- -- Add a sample filter to purge the oldest 100 events when the disk is 95% full -- -insert into Filters values (NULL,'PurgeWhenFull','{"sort_field":"Id","terms":[{"val":0,"attr":"Archived","op":"="},{"cnj":"and","val":95,"attr":"DiskPercent","op":">="}],"limit":100,"sort_asc":1}',0,0,0,0,0,0,'',1,0,1,0); -insert into Filters values (NULL,'Update DiskSpace','{"terms":[{"attr":"DiskSpace","op":"IS","val":"NULL"}],"sort_field":"Id","sort_asc":"1","limit":"100"}',0,0,0,0,0,0,'',1,1,1,0); + `Id` int(10) unsigned NOT NULL auto_increment, + `Name` varchar(64) NOT NULL default '', + `Query` text NOT NULL, + `AutoArchive` tinyint(3) unsigned NOT NULL default '0', + `AutoVideo` tinyint(3) unsigned NOT NULL default '0', + `AutoUpload` tinyint(3) unsigned NOT NULL default '0', + `AutoEmail` tinyint(3) unsigned NOT NULL default '0', + `AutoMessage` tinyint(3) unsigned NOT NULL default '0', + `AutoExecute` tinyint(3) unsigned NOT NULL default '0', + `AutoExecuteCmd` tinytext, + `AutoDelete` tinyint(3) unsigned NOT NULL default '0', + `AutoMove` tinyint(3) unsigned NOT NULL default '0', + `AutoMoveTo` smallint(5) unsigned NOT NULL default 0, + `UpdateDiskSpace` tinyint(3) unsigned NOT NULL default '0', + `Background` tinyint(1) unsigned NOT NULL default '0', + `Concurrent` tinyint(1) unsigned NOT NULL default '0', + +insert into Filters values (NULL,'PurgeWhenFull','{"sort_field":"Id","terms":[{"val":0,"attr":"Archived","op":"="},{"cnj":"and","val":95,"attr":"DiskPercent","op":">="}],"limit":100,"sort_asc":1}',0/*AutoArchive*/,0/*AutoVideo*/,0/*AutoUpload*/,0/*AutoEmail*/,0/*AutoMessage*/,0/*AutoExecute*/,'',1/*AutoDelete*/,0/*AutoMove*/,0/*MoveTo*/,0/*UpdateDiskSpace*/,1/*Background*/,0/*Concurrent*/); +insert into Filters values (NULL,'Update DiskSpace','{"terms":[{"attr":"DiskSpace","op":"IS","val":"NULL"}]}',0,0,0,0,0,0,'',0,0,0,1,1,0); -- -- Add in some sample control protocol definitions diff --git a/db/zm_update-1.31.18.sql b/db/zm_update-1.31.18.sql index fd000bcfa..5ba3b6caa 100644 --- a/db/zm_update-1.31.18.sql +++ b/db/zm_update-1.31.18.sql @@ -13,10 +13,10 @@ EXECUTE stmt; SET @s = (SELECT IF( (SELECT COUNT(*) FROM Filters WHERE Name = 'Update DiskSpace' - AND Query = '{"terms":[{"attr":"DiskSpace","op":"IS","val":"NULL"}],"sort_field":"Id","sort_asc":"1","limit":"100"}' + AND Query = '{"terms":[{"attr":"DiskSpace","op":"IS","val":"NULL"}]}' ) > 0, "SELECT 'Update Disk Space Filter already exists.'", - "INSERT INTO Filters (Name,Query,UpdateDiskSpace,Background) values ('Update DiskSpace','{\"terms\":[{\"attr\":\"DiskSpace\",\"op\":\"IS\",\"val\":\"NULL\"}],\"sort_field\":\"Id\",\"sort_asc\":\"1\",\"limit\":\"100\"}',1,1)" + "INSERT INTO Filters (Name,Query,UpdateDiskSpace,Background) values ('Update DiskSpace','{\"terms\":[{\"attr\":\"DiskSpace\",\"op\":\"IS\",\"val\":\"NULL\"}]}',1,1)" )); PREPARE stmt FROM @s; From b62343fb2c8adebc6d1f8a6a0182e023a8ddcbde Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 1 Jan 2018 13:19:30 -0500 Subject: [PATCH 6/6] bump to 1.31.18 --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index 874058d96..d1be1a9fa 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.31.17 +1.31.18