Merge branch 'master' into storageareas

This commit is contained in:
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;
}
require_once('control_functions.php');
require_once('Monitor.php');
require_once('includes/control_functions.php');
require_once('includes/Monitor.php');
$mid = validInt($_REQUEST['mid']);
if ( $action == 'control' ) {
$monitor = new ZM\Monitor($mid);
$ctrlCommand = buildControlCommand($monitor);
sendControlCommand($monitor->Id(), $ctrlCommand);
$view = 'none';
}
?>

View File

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

View File

@ -252,7 +252,7 @@ function controlPresets( $monitor, $cmds ) {
global $SLANG;
// MAX_PRESETS IS PER LINE
define( "MAX_PRESETS", "12" );
define( 'MAX_PRESETS', '12' );
$sql = 'SELECT * FROM ControlPresets WHERE MonitorId = ?';
$labels = array();
@ -282,12 +282,12 @@ function controlPresets( $monitor, $cmds ) {
<?php
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
}
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
}
?>

View File

@ -267,8 +267,19 @@ function getNavBarHTML($reload = null) {
<?php
if ( ZM\logToDatabase() > ZM\Logger::NOLOG ) {
if ( ! ZM_RUN_AUDIT ) {
# zmaudit can clean the logs, but if we aren't running it, then we should clecan them regularly
dbQuery('DELETE FROM Logs WHERE TimeKey < unix_timestamp( NOW() - interval '.ZM_LOG_DATABASE_LIMIT.') LIMIT 100');
# zmaudit can clean the logs, but if we aren't running it, then we should clean them regularly
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>' );
}

View File

@ -49,7 +49,7 @@ xhtmlHeaders(__FILE__, translate('SetPreset') );
</div>
<div id="content">
<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="action" value="control"/>
<input type="hidden" name="control" value="presetSet"/>
@ -57,11 +57,11 @@ xhtmlHeaders(__FILE__, translate('SetPreset') );
<p><?php echo buildSelect('preset', $presets, 'updateLabel()' ) ?></p>
<p>
<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>
<div id="contentButtons">
<input type="submit" value="<?php echo translate('Save') ?>"/>
<input type="button" value="<?php echo translate('Cancel') ?>" data-on-click="closeWindow"/>
<button type="submit" value="Save"><?php echo translate('Save') ?></button>
<button type="button" data-on-click="closeWindow"><?php echo translate('Cancel') ?></button>
</div>
</form>
</div>