Merge branch 'master' into storageareas

pull/2562/head
Isaac Connor 2019-03-01 14:03:49 -05:00
commit 466c379e94
5 changed files with 43 additions and 31 deletions

View File

@ -28,13 +28,14 @@ if ( ! canView('Control', $_REQUEST['mid']) ) {
return; return;
} }
require_once('control_functions.php'); require_once('includes/control_functions.php');
require_once('Monitor.php'); require_once('includes/Monitor.php');
$mid = validInt($_REQUEST['mid']); $mid = validInt($_REQUEST['mid']);
if ( $action == 'control' ) { if ( $action == 'control' ) {
$monitor = new ZM\Monitor($mid); $monitor = new ZM\Monitor($mid);
$ctrlCommand = buildControlCommand($monitor); $ctrlCommand = buildControlCommand($monitor);
sendControlCommand($monitor->Id(), $ctrlCommand); sendControlCommand($monitor->Id(), $ctrlCommand);
$view = 'none';
} }
?> ?>

View File

@ -16,9 +16,9 @@ class Logger {
private $initialised = false; private $initialised = false;
private $id = "web"; private $id = 'web';
private $idRoot = "web"; private $idRoot = 'web';
private $idArgs = ""; private $idArgs = '';
private $useErrorLog = true; private $useErrorLog = true;
private $level = self::INFO; private $level = self::INFO;
@ -32,17 +32,17 @@ class Logger {
private $hasTerm = false; private $hasTerm = false;
private $logPath = ZM_PATH_LOGS; private $logPath = ZM_PATH_LOGS;
private $logFile = ""; private $logFile = '';
private $logFd = NULL; private $logFd = NULL;
public static $codes = array( public static $codes = array(
self::DEBUG => "DBG", self::DEBUG => 'DBG',
self::INFO => "INF", self::INFO => 'INF',
self::WARNING => "WAR", self::WARNING => 'WAR',
self::ERROR => "ERR", self::ERROR => 'ERR',
self::FATAL => "FAT", self::FATAL => 'FAT',
self::PANIC => "PNC", self::PANIC => 'PNC',
self::NOLOG => "OFF", self::NOLOG => 'OFF',
); );
private static $syslogPriorities = array( private static $syslogPriorities = array(
self::DEBUG => LOG_DEBUG, self::DEBUG => LOG_DEBUG,
@ -63,7 +63,7 @@ class Logger {
private function __construct() { private function __construct() {
$this->hasTerm = (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])); $this->hasTerm = (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']));
$this->logFile = $this->logPath."/".$this->id.".log"; $this->logFile = $this->logPath.'/'.$this->id.'.log';
} }
public function __destruct() { public function __destruct() {
@ -78,12 +78,12 @@ class Logger {
//$this->useErrorLog = $options['useErrorLog']; //$this->useErrorLog = $options['useErrorLog'];
if ( isset($options['logPath']) ) { if ( isset($options['logPath']) ) {
$this->logPath = $options['logPath']; $this->logPath = $options['logPath'];
$tempLogFile = $this->logPath."/".$this->id.".log"; $tempLogFile = $this->logPath.'/'.$this->id.'.log';
} }
if ( isset($options['logFile']) ) if ( isset($options['logFile']) )
$tempLogFile = $options['logFile']; $tempLogFile = $options['logFile'];
else else
$tempLogFile = $this->logPath."/".$this->id.".log"; $tempLogFile = $this->logPath.'/'.$this->id.'.log';
if ( !is_null($logFile = $this->getTargettedEnv('LOG_FILE')) ) if ( !is_null($logFile = $this->getTargettedEnv('LOG_FILE')) )
$tempLogFile = $logFile; $tempLogFile = $logFile;
@ -177,10 +177,10 @@ class Logger {
} }
private function getTargettedEnv( $name ) { private function getTargettedEnv( $name ) {
$envName = $name."_".$this->id; $envName = $name.'_'.$this->id;
$value = getenv( $envName ); $value = getenv( $envName );
if ( $value === false && $this->id != $this->idRoot ) if ( $value === false && $this->id != $this->idRoot )
$value = getenv( $name."_".$this->idRoot ); $value = getenv( $name.'_'.$this->idRoot );
if ( $value === false ) if ( $value === false )
$value = getenv( $name ); $value = getenv( $name );
return( $value !== false ? $value : NULL ); return( $value !== false ? $value : NULL );
@ -269,7 +269,7 @@ class Logger {
if ( $this->databaseLevel > self::NOLOG ) { if ( $this->databaseLevel > self::NOLOG ) {
if ( (include_once 'database.php') === FALSE ) { if ( (include_once 'database.php') === FALSE ) {
$this->databaseLevel = self::NOLOG; $this->databaseLevel = self::NOLOG;
Warning( "Unable to write log entries to DB, database.php not found" ); Warning( 'Unable to write log entries to DB, database.php not found' );
} }
} }
} }
@ -424,7 +424,7 @@ class Logger {
function logInit( $options=array() ) { function logInit( $options=array() ) {
$logger = Logger::fetch(); $logger = Logger::fetch();
$logger->initialise( $options ); $logger->initialise( $options );
set_error_handler( 'ErrorHandler' ); set_error_handler( 'ZM\ErrorHandler' );
} }
function logToDatabase( $level=NULL ) { function logToDatabase( $level=NULL ) {
@ -487,7 +487,7 @@ function Panic( $string ) {
function ErrorHandler( $error, $string, $file, $line ) { function ErrorHandler( $error, $string, $file, $line ) {
if ( ! (error_reporting() & $error) ) { if ( ! (error_reporting() & $error) ) {
// This error code is not included in error_reporting // This error code is not included in error_reporting
return( false ); return false;
} }
switch ( $error ) { switch ( $error ) {
@ -507,7 +507,7 @@ function ErrorHandler( $error, $string, $file, $line ) {
Panic( "Unknown error type: [$error] $string" ); Panic( "Unknown error type: [$error] $string" );
break; break;
} }
return( true ); return true;
} }
?> ?>

View File

@ -252,7 +252,7 @@ function controlPresets( $monitor, $cmds ) {
global $SLANG; global $SLANG;
// MAX_PRESETS IS PER LINE // MAX_PRESETS IS PER LINE
define( "MAX_PRESETS", "12" ); define( 'MAX_PRESETS', '12' );
$sql = 'SELECT * FROM ControlPresets WHERE MonitorId = ?'; $sql = 'SELECT * FROM ControlPresets WHERE MonitorId = ?';
$labels = array(); $labels = array();
@ -282,12 +282,12 @@ function controlPresets( $monitor, $cmds ) {
<?php <?php
if ( $monitor->HasHomePreset() ) { if ( $monitor->HasHomePreset() ) {
?> ?>
<button type="button" class="ptzTextBtn" value="<?php echo translate('Home') ?>" onclick="controlCmd('<?php echo $cmds['PresetHome'] ?>');"/> <button type="button" class="ptzTextBtn" value="Home" onclick="controlCmd('<?php echo $cmds['PresetHome'] ?>');"><?php echo translate('Home') ?></button>
<?php <?php
} }
if ( canEdit('Monitors') && $monitor->CanSetPresets() ) { if ( canEdit('Monitors') && $monitor->CanSetPresets() ) {
?> ?>
<button type="button" class="ptzTextBtn popup-link" value="<?php echo translate('Set') ?>" data-url="?view=controlpreset&amp;mid=<?php echo $monitor->Id() ?>" data-window-name="zmPreset" data-window-tag="preset"/> <button type="button" class="ptzTextBtn popup-link" value="Set" data-url="?view=controlpreset&amp;mid=<?php echo $monitor->Id() ?>" data-window-name="zmPreset" data-window-tag="preset"><?php echo translate('Set') ?></button>
<?php <?php
} }
?> ?>

View File

@ -267,8 +267,19 @@ function getNavBarHTML($reload = null) {
<?php <?php
if ( ZM\logToDatabase() > ZM\Logger::NOLOG ) { if ( ZM\logToDatabase() > ZM\Logger::NOLOG ) {
if ( ! ZM_RUN_AUDIT ) { if ( ! ZM_RUN_AUDIT ) {
# zmaudit can clean the logs, but if we aren't running it, then we should clecan them regularly # zmaudit can clean the logs, but if we aren't running it, then we should clean them regularly
dbQuery('DELETE FROM Logs WHERE TimeKey < unix_timestamp( NOW() - interval '.ZM_LOG_DATABASE_LIMIT.') LIMIT 100'); if ( preg_match('/^\d+$/', ZM_LOG_DATABASE_LIMIT) ) {
# Number of lines, instead of an interval
$rows = dbFetchOne('SELECT Count(*) AS Rows FROM Logs', 'Rows' );
if ( $rows > ZM_LOG_DATABASE_LIMIT ) {
dbQuery('DELETE low_priority FROM Logs ORDER BY TimeKey ASC LIMIT ?', array($rows - ZM_LOG_DATABASE_LIMIT));
}
} else if ( preg_match('/^\d\s*(hour|minute|day|week|month|year)$/', ZM_LOG_DATABASE_LIMIT, $matches) ) {
ZM\Logger::Debug("have interval ".$matches[1]);
dbQuery('DELETE FROM Logs WHERE TimeKey < unix_timestamp( NOW() - interval '.ZM_LOG_DATABASE_LIMIT.') LIMIT 100');
} else {
ZM\Error('Potentially invalid value for ZM_LOG_DATABASE_LIMIT: ' . ZM_LOG_DATABASE_LIMIT);
}
} }
echo makePopupLink( '?view=log', 'zmLog', 'log', '<span class="'.logState().'">'.translate('Log').'</span>' ); echo makePopupLink( '?view=log', 'zmLog', 'log', '<span class="'.logState().'">'.translate('Log').'</span>' );
} }

View File

@ -49,7 +49,7 @@ xhtmlHeaders(__FILE__, translate('SetPreset') );
</div> </div>
<div id="content"> <div id="content">
<form name="contentForm" id="contentForm" method="post" action="?"> <form name="contentForm" id="contentForm" method="post" action="?">
<input type="hidden" name="view" value="none"/> <input type="hidden" name="view" value="control"/>
<input type="hidden" name="mid" value="<?php echo $monitor['Id'] ?>"/> <input type="hidden" name="mid" value="<?php echo $monitor['Id'] ?>"/>
<input type="hidden" name="action" value="control"/> <input type="hidden" name="action" value="control"/>
<input type="hidden" name="control" value="presetSet"/> <input type="hidden" name="control" value="presetSet"/>
@ -57,11 +57,11 @@ xhtmlHeaders(__FILE__, translate('SetPreset') );
<p><?php echo buildSelect('preset', $presets, 'updateLabel()' ) ?></p> <p><?php echo buildSelect('preset', $presets, 'updateLabel()' ) ?></p>
<p> <p>
<label for="newLabel"><?php echo translate('NewLabel') ?></label> <label for="newLabel"><?php echo translate('NewLabel') ?></label>
<input type="text" name="newLabel" id="newLabel" value="" size="16"/> <input type="text" name="newLabel" id="newLabel" value=""/>
</p> </p>
<div id="contentButtons"> <div id="contentButtons">
<input type="submit" value="<?php echo translate('Save') ?>"/> <button type="submit" value="Save"><?php echo translate('Save') ?></button>
<input type="button" value="<?php echo translate('Cancel') ?>" data-on-click="closeWindow"/> <button type="button" data-on-click="closeWindow"><?php echo translate('Cancel') ?></button>
</div> </div>
</form> </form>
</div> </div>