From 471c78c544d816eba9850bb4894757156f6c4a9d Mon Sep 17 00:00:00 2001 From: stan Date: Mon, 23 Oct 2006 15:32:22 +0000 Subject: [PATCH] Bug 246 - Manually execute filters with actions. git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@2027 e3e1d417-86f3-4887-817a-d78f3d33393f --- scripts/zmfilter.pl | 52 +++++++++++++--- web/zm_actions.php | 8 ++- web/zm_config.php.in | 2 +- web/zm_funcs.php | 10 +++ web/zm_html_config.php | 2 +- web/zm_html_view_events.php | 7 ++- web/zm_html_view_filter.php | 106 ++++++++++++++++++++++++-------- web/zm_html_view_filtersave.php | 51 +-------------- web/zm_lang_en_gb.php | 12 ++-- 9 files changed, 153 insertions(+), 97 deletions(-) diff --git a/scripts/zmfilter.pl b/scripts/zmfilter.pl index 7d3c79cab..fe99bb882 100644 --- a/scripts/zmfilter.pl +++ b/scripts/zmfilter.pl @@ -35,7 +35,7 @@ use bytes; # ========================================================================== 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 DBG_LEVEL => 1; # 0 is errors, warnings and info only, > 0 for debug use constant START_DELAY => 5; # How long to wait before starting @@ -109,13 +109,14 @@ 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 [-d ,--delay=] +Usage: zmfilter.pl [-f ,--filter=] Parameters are :- --d, --delay= - How long to delay between each check, default ".ZM_FILTER_EXECUTE_INTERVAL." +-f, --filter= - The name of a specific filter to run "); exit( -1 ); } @@ -152,7 +153,7 @@ sub DateTimeToSQL return( strftime( "%Y-%m-%d %H:%M:%S", localtime( $dt_val ) ) ); } -if ( !GetOptions( 'delay=i'=>\$delay ) ) +if ( !GetOptions( 'filter=s'=>\$filter_parm ) ) { Usage(); } @@ -161,11 +162,21 @@ chdir( EVENT_PATH ); my $dbh = DBI->connect( "DBI:mysql:database=".ZM_DB_NAME.";host=".ZM_DB_HOST, ZM_DB_USER, ZM_DB_PASS ); -Info( "Scanning for events\n" ); +if ( $filter_parm ) +{ + Info( "Scanning for events using filter '$filter_parm'\n" ); +} +else +{ + Info( "Scanning for events\n" ); +} -sleep( START_DELAY ); +if ( !$filter_parm ) +{ + sleep( START_DELAY ); +} -my $filters = getFilters(); +my $filters; my $last_action = 0; while( 1 ) @@ -174,7 +185,7 @@ while( 1 ) { Debug( "Reloading filters\n" ); $last_action = time(); - $filters = getFilters(); + $filters = getFilters( $filter_parm ); } foreach my $filter ( @$filters ) @@ -182,6 +193,8 @@ while( 1 ) checkFilter( $filter ); } + last if ( $filter_parm ); + Debug( "Sleeping for $delay seconds\n" ); sleep( $delay ); } @@ -212,10 +225,29 @@ sub getDiskBlocks sub getFilters { + my $filter_name = shift; + my @filters; - my $sql = "select * from Filters where (AutoArchive = 1 or AutoVideo = 1 or AutoUpload = 1 or AutoEmail = 1 or AutoMessage = 1 or AutoExecute = 1 or AutoDelete = 1) order by Name"; + 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 = $sth->execute() or Fatal( "Can't execute '$sql': ".$sth->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 $filter_data = $sth->fetchrow_hashref() ) { Debug( "Found filter '$filter_data->{Name}'\n" ); diff --git a/web/zm_actions.php b/web/zm_actions.php index 11d7f45fb..5215639c1 100644 --- a/web/zm_actions.php +++ b/web/zm_actions.php @@ -169,9 +169,15 @@ if ( !empty($action) ) } elseif ( $action == "filter" ) { + if ( $execute ) + { + $temp_filter_name = "_TempFilter".time(); + } if ( $filter_name || $new_filter_name ) { - if ( $new_filter_name ) + if ( $temp_filter_name ) + $filter_name = $temp_filter_name; + elseif ( $new_filter_name ) $filter_name = $new_filter_name; $filter_query = array(); $filter_query['trms'] = $trms; diff --git a/web/zm_config.php.in b/web/zm_config.php.in index 105856a24..80ec70976 100644 --- a/web/zm_config.php.in +++ b/web/zm_config.php.in @@ -195,7 +195,7 @@ $jws = array( 'eventdetail' => array( 'w'=>400, 'h'=>220 ), 'events' => array( 'w'=>720, 'h'=>480 ), 'export' => array( 'w'=>400, 'h'=>340 ), - 'filter' => array( 'w'=>620, 'h'=>250 ), + 'filter' => array( 'w'=>620, 'h'=>360 ), 'filtersave' => array( 'w'=>560, 'h'=>220 ), 'frames' => array( 'w'=>500, 'h'=>300 ), 'function' => array( 'w'=>248, 'h'=>92 ), diff --git a/web/zm_funcs.php b/web/zm_funcs.php index 41c241e3b..0068bce68 100644 --- a/web/zm_funcs.php +++ b/web/zm_funcs.php @@ -1052,6 +1052,16 @@ function createImage( $monitor, $scale ) return( $status ); } +function executeFilter( $filter ) +{ + $command = ZM_PATH_BIN."/zmfilter.pl --filter ".$filter; + $result = exec( $command, $output, $status ); + $result = mysql_query( "delete from Filters where Name like '_TempFilter%'" ); + if ( !$result ) + die( mysql_error() ); + return( $status ); +} + function reScale( $dimension, $dummy ) { for ( $i = 1; $i < func_num_args(); $i++ ) diff --git a/web/zm_html_config.php b/web/zm_html_config.php index bc287ebaa..286f15532 100644 --- a/web/zm_html_config.php +++ b/web/zm_html_config.php @@ -117,7 +117,7 @@ $jws = array( 'eventdetail' => array( 'w'=>400, 'h'=>220 ), 'events' => array( 'w'=>720, 'h'=>480 ), 'export' => array( 'w'=>400, 'h'=>340 ), - 'filter' => array( 'w'=>620, 'h'=>250 ), + 'filter' => array( 'w'=>620, 'h'=>360 ), 'filtersave' => array( 'w'=>560, 'h'=>220 ), 'frames' => array( 'w'=>500, 'h'=>300 ), 'function' => array( 'w'=>248, 'h'=>92 ), diff --git a/web/zm_html_view_events.php b/web/zm_html_view_events.php index 1bdc94729..0664356c2 100644 --- a/web/zm_html_view_events.php +++ b/web/zm_html_view_events.php @@ -18,12 +18,17 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // -if ( !canView( 'Events' ) ) +if ( !canView( 'Events' ) || ($execute && !canEdit('Events')) ) { $view = "error"; return; } +if ( $execute ) +{ + executeFilter( $temp_filter_name ); +} + $count_sql = "select count(E.Id) as EventCount from Monitors as M inner join Events as E on (M.Id = E.MonitorId) where"; $events_sql = "select E.Id,E.MonitorId,M.Name As MonitorName,M.Width,M.Height,M.DefaultScale,E.Name,E.Cause,E.StartTime,E.Length,E.Frames,E.AlarmFrames,E.TotScore,E.AvgScore,E.MaxScore,E.Archived,E.LearnState from Monitors as M inner join Events as E on (M.Id = E.MonitorId) where"; if ( $user['MonitorIds'] ) diff --git a/web/zm_html_view_filter.php b/web/zm_html_view_filter.php index 5acbe61f0..63b31e496 100644 --- a/web/zm_html_view_filter.php +++ b/web/zm_html_view_filter.php @@ -31,6 +31,8 @@ if ( !$result ) while ( $row = mysql_fetch_assoc( $result ) ) { $filter_names[$row['Name']] = $row['Name']; + if ( $row['Background'] ) + $filter_names[$row['Name']] .= "*"; if ( !empty($reload) && isset($filter_name) && $filter_name == $row['Name'] ) { $filter_data = $row; @@ -38,28 +40,11 @@ while ( $row = mysql_fetch_assoc( $result ) ) } mysql_free_result( $result ); -$auto_str = ""; +$background_str = ""; if ( isset($filter_data) ) { - $auto_text = array(); - if ( $filter_data['AutoArchive'] ) - $auto_text[] = $zmSlangAutoArchiveAbbr; - if ( $filter_data['AutoVideo'] ) - $auto_text[] = $zmSlangAutoVideoAbbr; - if ( $filter_data['AutoUpload'] ) - $auto_text[] = $zmSlangAutoUploadAbbr; - if ( $filter_data['AutoEmail'] ) - $auto_text[] = $zmSlangAutoEmailAbbr; - if ( $filter_data['AutoMessage'] ) - $auto_text[] = $zmSlangAutoMessageAbbr; - if ( $filter_data['AutoExecute'] ) - $auto_text[] = $zmSlangAutoExecuteAbbr; - if ( $filter_data['AutoDelete'] ) - $auto_text[] = $zmSlangAutoDeleteAbbr; - if ( count($auto_text) ) - { - $auto_str = '['.join( ',', $auto_text ).']'; - } + if ( $filter_data['Background'] ) + $background_str = '['.strtolower($zmSlangBackground).']'; foreach( split( '&', $filter_data['Query'] ) as $filter_parm ) { @@ -211,14 +196,22 @@ function submitToFilter( form, reload ) } function submitToEvents( form ) { - var Url = ''; var Name = 'zmEvents'; - var Width = ; - var Height = ; - var Options = 'resizable,scrollbars,width='+Width+',height='+Height; form.target = Name; form.view.value = 'events'; + form.action.value = ''; + form.execute.value = 0; + form.submit(); +} +function executeFilter( form ) +{ + var Name = 'zmEvents'; + + form.target = Name; + form.view.value = 'events'; + form.action.value = 'filter'; + form.execute.value = 1; form.submit(); } function saveFilter( form ) @@ -266,6 +259,7 @@ function delTerm( form, line ) + @@ -274,7 +268,7 @@ function delTerm( form, line ) - + @@ -352,7 +346,67 @@ else - + + + + + +
1 ) { echo buildSelect( $select_name, $filter_names, "submitToFilter( document.filter_form, 1 );" ); } else { ?>   1 ) { echo buildSelect( $select_name, $filter_names, "submitToFilter( document.filter_form, 1 );" ); } else { ?>  
   + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
class="form-noborder">
class="form-noborder">
class="form-noborder">
class="form-noborder">
class="form-noborder">
class="form-noborder">
class="form-noborder">

+   +   + +
diff --git a/web/zm_html_view_filtersave.php b/web/zm_html_view_filtersave.php index bdf108e8c..b088ae75f 100644 --- a/web/zm_html_view_filtersave.php +++ b/web/zm_html_view_filtersave.php @@ -100,55 +100,8 @@ mysql_free_result( $result );   -:  - class="form-noborder"> - - - -:  - class="form-noborder"> - - - -:  - class="form-noborder"> - - - -:  - class="form-noborder"> - - - -:  - class="form-noborder"> - - - -:  - class="form-noborder"> - - - -:  - class="form-noborder"> +:  + class="form-noborder">   diff --git a/web/zm_lang_en_gb.php b/web/zm_lang_en_gb.php index 59210205b..fa1a2e0cf 100644 --- a/web/zm_lang_en_gb.php +++ b/web/zm_lang_en_gb.php @@ -115,23 +115,18 @@ $zmSlangAttrNotes = 'Notes'; $zmSlangAttrTime = 'Time'; $zmSlangAttrTotalScore = 'Total Score'; $zmSlangAttrWeekday = 'Weekday'; -$zmSlangAutoArchiveAbbr = 'Archive'; -$zmSlangAutoArchiveEvents = 'Automatically archive all matches'; $zmSlangAuto = 'Auto'; -$zmSlangAutoDeleteAbbr = 'Delete'; +$zmSlangAutoArchiveEvents = 'Automatically archive all matches'; $zmSlangAutoDeleteEvents = 'Automatically delete all matches'; -$zmSlangAutoEmailAbbr = 'Email'; $zmSlangAutoEmailEvents = 'Automatically email details of all matches'; -$zmSlangAutoExecuteAbbr = 'Execute'; $zmSlangAutoExecuteEvents = 'Automatically execute command on all matches'; -$zmSlangAutoMessageAbbr = 'Message'; $zmSlangAutoMessageEvents = 'Automatically message details of all matches'; $zmSlangAutoStopTimeout = 'Auto Stop Timeout'; -$zmSlangAutoUploadAbbr = 'Upload'; $zmSlangAutoUploadEvents = 'Automatically upload all matches'; -$zmSlangAutoVideoAbbr = 'Video'; $zmSlangAutoVideoEvents = 'Automatically create video for all matches'; $zmSlangAvgBrScore = 'Avg.
Score'; +$zmSlangBackground = 'Background'; +$zmSlangBackgroundFilter = 'Run filter in background'; $zmSlangBadAlarmFrameCount = 'Alarm frame count must be an integer of one or more'; $zmSlangBadAlarmMaxFPS = 'Alarm Maximum FPS must be a positive integer or floating point value'; $zmSlangBadChannel = 'Channel must be set to an integer of zero or more'; @@ -273,6 +268,7 @@ $zmSlangEventName = 'Event Name'; $zmSlangEventPrefix = 'Event Prefix'; $zmSlangEvents = 'Events'; $zmSlangExclude = 'Exclude'; +$zmSlangExecute = 'Execute'; $zmSlangExportDetails = 'Export Event Details'; $zmSlangExport = 'Export'; $zmSlangExportFailed = 'Export Failed';