Merge branch 'master' of github.com:ZoneMinder/ZoneMinder

pull/2522/head
Isaac Connor 2019-02-12 13:18:08 -05:00
commit 2f301cf5fe
3 changed files with 86 additions and 3 deletions

View File

@ -167,7 +167,7 @@ public $defaults = array(
} # end find_one()
public function delete() {
dbQuery('DELETE FROM Filters WHERE Id = ?', array($this->{'Id'}));
dbQuery('DELETE FROM Filters WHERE Id=?', array($this->{'Id'}));
} # end function delete()
public function set( $data ) {
@ -186,6 +186,60 @@ public $defaults = array(
}
}
} # end function set
public function control($command, $server_id=null) {
$Servers = $server_id ? Server::find(array('Id'=>$server_id)) : Server::find();
if ( !count($Servers) and !$server_id ) {
# This will be the non-multi-server case
$Servers = array(new Server());
}
foreach ( $Servers as $Server ) {
if ( !defined('ZM_SERVER_ID') or !$Server->Id() or ZM_SERVER_ID==$Server->Id() ) {
# Local
Logger::Debug("Controlling filter locally $command for server ".$Server->Id());
daemonControl($command, 'zmfilter.pl', '--filter_id='.$this->{'Id'});
} else {
# Remote case
$url = $Server->UrlToIndex();
if ( ZM_OPT_USE_AUTH ) {
if ( ZM_AUTH_RELAY == 'hashed' ) {
$url .= '?auth='.generateAuthHash(ZM_AUTH_HASH_IPS);
} else if ( ZM_AUTH_RELAY == 'plain' ) {
$url = '?user='.$_SESSION['username'];
$url = '?pass='.$_SESSION['password'];
} else if ( ZM_AUTH_RELAY == 'none' ) {
$url = '?user='.$_SESSION['username'];
}
}
$url .= '&view=filter&action=control&command='.$command.'&Id='.$this->Id().'&ServerId'.$Server->Id();
Logger::Debug("sending command to $url");
$data = array();
if ( defined('ZM_ENABLE_CSRF_MAGIC') )
$data['__csrf_magic'] = csrf_get_secret();
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
try {
$result = file_get_contents($url, false, $context);
if ( $result === FALSE ) { /* Handle error */
Error("Error restarting zmfilter.pl using $url");
}
} catch ( Exception $e ) {
Error("Except $e thrown trying to restart zmfilter");
}
} # end if local or remote
} # end foreach erver
} # end function control
} # end class Filter
?>

View File

@ -30,9 +30,23 @@ if ( isset($_REQUEST['object']) and ( $_REQUEST['object'] == 'filter' ) ) {
} elseif ( $action == 'delterm' ) {
$_REQUEST['filter'] = delFilterTerm($_REQUEST['filter'], $_REQUEST['line']);
} else if ( canEdit('Events') ) {
if ( empty($_REQUEST['Id']) ) {
Error("No filter id specified.");
return;
}
require_once('includes/Filter.php');
$filter = new Filter($_REQUEST['Id']);
if ( $action == 'delete' ) {
if ( !empty($_REQUEST['Id']) ) {
dbQuery('DELETE FROM Filters WHERE Id=?', array($_REQUEST['Id']));
if ( $filter->Background() ) {
$filter->control('stop');
}
$filter->delete();
} else {
Error("No filter id passed when deleting");
}
} else if ( ( $action == 'Save' ) or ( $action == 'SaveAs' ) or ( $action == 'execute' ) ) {
@ -66,15 +80,30 @@ if ( isset($_REQUEST['object']) and ( $_REQUEST['object'] == 'filter' ) ) {
if ( $_REQUEST['Id'] and ( $action == 'Save' ) ) {
dbQuery('UPDATE Filters SET '.$sql.' WHERE Id=?', array($_REQUEST['Id']));
if ( $filter->Background() )
$filter->control('stop');
} else {
dbQuery('INSERT INTO Filters SET'.$sql);
$_REQUEST['Id'] = dbInsertId();
$filter = new Filter($_REQUEST['Id']);
}
if ( !empty($_REQUEST['filter']['Background']) )
$filter->control('start');
if ( $action == 'execute' ) {
executeFilter($_REQUEST['Id']);
$view = 'events';
}
} else if ( $action == 'control' ) {
if ( $_REQUEST['command'] == 'start'
or $_REQUEST['command'] == 'stop'
or $_REQUEST['command'] == 'restart'
) {
$filter->control($_REQUEST['command'], $_REQUEST['ServerId']);
} else {
Error('Invalid command for filter ('.$_REQUEST['command'].')');
}
} // end if save or execute
} // end if canEdit(Events)
} // end if object == filter

View File

@ -219,7 +219,7 @@ function getBodyTopHTML() {
} // end function getBodyTopHTML
function getNavBarHTML($reload = null) {
# Provide a facility to turn off the headers if you put headers=0 into the url
# Provide a facility to turn off the headers if you put navbar=0 into the url
if ( isset($_REQUEST['navbar']) and $_REQUEST['navbar']=='0' )
return '';