spaces, quotes extra braces

This commit is contained in:
Isaac Connor 2019-09-25 10:13:32 -04:00
parent 80710e6551
commit afd10e49d6
1 changed files with 189 additions and 191 deletions

View File

@ -10,193 +10,193 @@ if ($_REQUEST['entity'] == 'navBar') {
} }
$statusData = array( $statusData = array(
'system' => array( 'system' => array(
'permission' => 'System', 'permission' => 'System',
'table' => 'Monitors', 'table' => 'Monitors',
'limit' => 1, 'limit' => 1,
'elements' => array( 'elements' => array(
'MonitorCount' => array( 'sql' => 'count(*)' ), 'MonitorCount' => array( 'sql' => 'count(*)' ),
'ActiveMonitorCount' => array( 'sql' => "count(if(Function != 'None',1,NULL))" ), 'ActiveMonitorCount' => array( 'sql' => "count(if(Function != 'None',1,NULL))" ),
'State' => array( 'func' => 'daemonCheck()?'.translate('Running').':'.translate('Stopped') ), 'State' => array( 'func' => 'daemonCheck()?'.translate('Running').':'.translate('Stopped') ),
'Load' => array( 'func' => 'getLoad()' ), 'Load' => array( 'func' => 'getLoad()' ),
'Disk' => array( 'func' => 'getDiskPercent()' ), 'Disk' => array( 'func' => 'getDiskPercent()' ),
), ),
), ),
'monitor' => array( 'monitor' => array(
'permission' => 'Monitors', 'permission' => 'Monitors',
'table' => 'Monitors', 'table' => 'Monitors',
'limit' => 1, 'limit' => 1,
'selector' => 'Monitors.Id', 'selector' => 'Monitors.Id',
'elements' => array( 'elements' => array(
'Id' => array( 'sql' => 'Monitors.Id' ), 'Id' => array( 'sql' => 'Monitors.Id' ),
'Name' => array( 'sql' => 'Monitors.Name' ), 'Name' => array( 'sql' => 'Monitors.Name' ),
'Type' => true, 'Type' => true,
'Function' => true, 'Function' => true,
'Enabled' => true, 'Enabled' => true,
'LinkedMonitors' => true, 'LinkedMonitors' => true,
'Triggers' => true, 'Triggers' => true,
'Device' => true, 'Device' => true,
'Channel' => true, 'Channel' => true,
'Format' => true, 'Format' => true,
'Host' => true, 'Host' => true,
'Port' => true, 'Port' => true,
'Path' => true, 'Path' => true,
'Width' => array( 'sql' => 'Monitors.Width' ), 'Width' => array( 'sql' => 'Monitors.Width' ),
'Height' => array( 'sql' => 'Monitors.Height' ), 'Height' => array( 'sql' => 'Monitors.Height' ),
'Palette' => true, 'Palette' => true,
'Orientation' => true, 'Orientation' => true,
'Brightness' => true, 'Brightness' => true,
'Contrast' => true, 'Contrast' => true,
'Hue' => true, 'Hue' => true,
'Colour' => true, 'Colour' => true,
'EventPrefix' => true, 'EventPrefix' => true,
'LabelFormat' => true, 'LabelFormat' => true,
'LabelX' => true, 'LabelX' => true,
'LabelY' => true, 'LabelY' => true,
'LabelSize' => true, 'LabelSize' => true,
'ImageBufferCount' => true, 'ImageBufferCount' => true,
'WarmupCount' => true, 'WarmupCount' => true,
'PreEventCount' => true, 'PreEventCount' => true,
'PostEventCount' => true, 'PostEventCount' => true,
'AlarmFrameCount' => true, 'AlarmFrameCount' => true,
'SectionLength' => true, 'SectionLength' => true,
'FrameSkip' => true, 'FrameSkip' => true,
'MotionFrameSkip' => true, 'MotionFrameSkip' => true,
'MaxFPS' => true, 'MaxFPS' => true,
'AlarmMaxFPS' => true, 'AlarmMaxFPS' => true,
'FPSReportInterval' => true, 'FPSReportInterval' => true,
'RefBlendPerc' => true, 'RefBlendPerc' => true,
'Controllable' => true, 'Controllable' => true,
'ControlId' => true, 'ControlId' => true,
'ControlDevice' => true, 'ControlDevice' => true,
'ControlAddress' => true, 'ControlAddress' => true,
'AutoStopTimeout' => true, 'AutoStopTimeout' => true,
'TrackMotion' => true, 'TrackMotion' => true,
'TrackDelay' => true, 'TrackDelay' => true,
'ReturnLocation' => true, 'ReturnLocation' => true,
'ReturnDelay' => true, 'ReturnDelay' => true,
'DefaultView' => true, 'DefaultView' => true,
'DefaultRate' => true, 'DefaultRate' => true,
'DefaultScale' => true, 'DefaultScale' => true,
'WebColour' => true, 'WebColour' => true,
'Sequence' => true, 'Sequence' => true,
'MinEventId' => array( 'sql' => '(SELECT min(Events.Id) FROM Events WHERE Events.MonitorId = Monitors.Id' ), 'MinEventId' => array( 'sql' => '(SELECT min(Events.Id) FROM Events WHERE Events.MonitorId = Monitors.Id' ),
'MaxEventId' => array( 'sql' => '(SELECT max(Events.Id) FROM Events WHERE Events.MonitorId = Monitors.Id' ), 'MaxEventId' => array( 'sql' => '(SELECT max(Events.Id) FROM Events WHERE Events.MonitorId = Monitors.Id' ),
'TotalEvents' => array( 'sql' => '(SELECT count(Events.Id) FROM Events WHERE Events.MonitorId = Monitors.Id' ), 'TotalEvents' => array( 'sql' => '(SELECT count(Events.Id) FROM Events WHERE Events.MonitorId = Monitors.Id' ),
'Status' => array( 'zmu' => '-m '.escapeshellarg($_REQUEST['id'][0]).' -s' ), 'Status' => array( 'zmu' => '-m '.escapeshellarg($_REQUEST['id'][0]).' -s' ),
'FrameRate' => array( 'zmu' => '-m '.escapeshellarg($_REQUEST['id'][0]).' -f' ), 'FrameRate' => array( 'zmu' => '-m '.escapeshellarg($_REQUEST['id'][0]).' -f' ),
), ),
), ),
'events' => array( 'events' => array(
'permission' => 'Events', 'permission' => 'Events',
'table' => 'Events', 'table' => 'Events',
'selector' => 'Events.MonitorId', 'selector' => 'Events.MonitorId',
'elements' => array( 'elements' => array(
'Id' => true, 'Id' => true,
'Name' => true, 'Name' => true,
'Cause' => true, 'Cause' => true,
'Notes' => true, 'Notes' => true,
'StartTime' => true, 'StartTime' => true,
'StartTimeShort' => array( 'sql' => "date_format( StartTime, '".MYSQL_FMT_DATETIME_SHORT."' )" ), 'StartTimeShort' => array( 'sql' => "date_format( StartTime, '".MYSQL_FMT_DATETIME_SHORT."' )" ),
'EndTime' => true, 'EndTime' => true,
'Width' => true, 'Width' => true,
'Height' => true, 'Height' => true,
'Length' => true, 'Length' => true,
'Frames' => true, 'Frames' => true,
'AlarmFrames' => true, 'AlarmFrames' => true,
'TotScore' => true, 'TotScore' => true,
'AvgScore' => true, 'AvgScore' => true,
'MaxScore' => true, 'MaxScore' => true,
), ),
), ),
'event' => array( 'event' => array(
'permission' => 'Events', 'permission' => 'Events',
'table' => 'Events', 'table' => 'Events',
'limit' => 1, 'limit' => 1,
'selector' => 'Events.Id', 'selector' => 'Events.Id',
'elements' => array( 'elements' => array(
'Id' => array( 'sql' => 'Events.Id' ), 'Id' => array( 'sql' => 'Events.Id' ),
'MonitorId' => true, 'MonitorId' => true,
'MonitorName' => array('sql' => '(SELECT Monitors.Name FROM Monitors WHERE Monitors.Id = Events.MonitorId)'), 'MonitorName' => array('sql' => '(SELECT Monitors.Name FROM Monitors WHERE Monitors.Id = Events.MonitorId)'),
'Name' => true, 'Name' => true,
'Cause' => true, 'Cause' => true,
'StartTime' => true, 'StartTime' => true,
'StartTimeShort' => array( 'sql' => "date_format( StartTime, '".MYSQL_FMT_DATETIME_SHORT."' )" ), 'StartTimeShort' => array( 'sql' => "date_format( StartTime, '".MYSQL_FMT_DATETIME_SHORT."' )" ),
'EndTime' => true, 'EndTime' => true,
'Width' => true, 'Width' => true,
'Height' => true, 'Height' => true,
'Length' => true, 'Length' => true,
'Frames' => true, 'Frames' => true,
'DefaultVideo' => true, 'DefaultVideo' => true,
'AlarmFrames' => true, 'AlarmFrames' => true,
'TotScore' => true, 'TotScore' => true,
'AvgScore' => true, 'AvgScore' => true,
'MaxScore' => true, 'MaxScore' => true,
'Archived' => true, 'Archived' => true,
'Videoed' => true, 'Videoed' => true,
'Uploaded' => true, 'Uploaded' => true,
'Emailed' => true, 'Emailed' => true,
'Messaged' => true, 'Messaged' => true,
'Executed' => true, 'Executed' => true,
'Notes' => true, 'Notes' => true,
'MinFrameId' => array( 'sql' => '(SELECT min(Frames.FrameId) FROM Frames WHERE EventId=Events.Id)' ), 'MinFrameId' => array( 'sql' => '(SELECT min(Frames.FrameId) FROM Frames WHERE EventId=Events.Id)' ),
'MaxFrameId' => array( 'sql' => '(SELECT max(Frames.FrameId) FROM Frames WHERE Events.Id = Frames.EventId)' ), 'MaxFrameId' => array( 'sql' => '(SELECT max(Frames.FrameId) FROM Frames WHERE Events.Id = Frames.EventId)' ),
'MinFrameDelta' => array( 'sql' => '(SELECT min(Frames.Delta) FROM Frames WHERE Events.Id = Frames.EventId)' ), 'MinFrameDelta' => array( 'sql' => '(SELECT min(Frames.Delta) FROM Frames WHERE Events.Id = Frames.EventId)' ),
'MaxFrameDelta' => array( 'sql' => '(SELECT max(Frames.Delta) FROM Frames WHERE Events.Id = Frames.EventId)' ), 'MaxFrameDelta' => array( 'sql' => '(SELECT max(Frames.Delta) FROM Frames WHERE Events.Id = Frames.EventId)' ),
), ),
), ),
'frames' => array( 'frames' => array(
'permission' => 'Events', 'permission' => 'Events',
'table' => 'Frames', 'table' => 'Frames',
'selector' => 'EventId', 'selector' => 'EventId',
'elements' => array( 'elements' => array(
'EventId' => true, 'EventId' => true,
'FrameId' => true, 'FrameId' => true,
'Type' => true, 'Type' => true,
'Delta' => true, 'Delta' => true,
), ),
), ),
'frame' => array( 'frame' => array(
'permission' => 'Events', 'permission' => 'Events',
'table' => 'Frames', 'table' => 'Frames',
'limit' => 1, 'limit' => 1,
'selector' => array( array( 'table' => 'Events', 'join' => 'Events.Id = Frames.EventId', 'selector'=>'Events.Id' ), 'Frames.FrameId' ), 'selector' => array( array( 'table' => 'Events', 'join' => 'Events.Id = Frames.EventId', 'selector'=>'Events.Id' ), 'Frames.FrameId' ),
'elements' => array( 'elements' => array(
//'Id' => array( 'sql' => 'Frames.FrameId' ), //'Id' => array( 'sql' => 'Frames.FrameId' ),
'FrameId' => true, 'FrameId' => true,
'EventId' => true, 'EventId' => true,
'Type' => true, 'Type' => true,
'TimeStamp' => true, 'TimeStamp' => true,
'TimeStampShort' => array( 'sql' => "date_format( StartTime, '".MYSQL_FMT_DATETIME_SHORT."' )" ), 'TimeStampShort' => array( 'sql' => "date_format( StartTime, '".MYSQL_FMT_DATETIME_SHORT."' )" ),
'Delta' => true, 'Delta' => true,
'Score' => true, 'Score' => true,
//'Image' => array( 'postFunc' => 'getFrameImage' ), //'Image' => array( 'postFunc' => 'getFrameImage' ),
), ),
), ),
'frameimage' => array( 'frameimage' => array(
'permission' => 'Events', 'permission' => 'Events',
'func' => 'getFrameImage()' 'func' => 'getFrameImage()'
), ),
'nearframe' => array( 'nearframe' => array(
'permission' => 'Events', 'permission' => 'Events',
'func' => 'getNearFrame()' 'func' => 'getNearFrame()'
), ),
'nearevents' => array( 'nearevents' => array(
'permission' => 'Events', 'permission' => 'Events',
'func' => 'getNearEvents()' 'func' => 'getNearEvents()'
) )
); );
function collectData() { function collectData() {
global $statusData; global $statusData;
$entitySpec = &$statusData[strtolower(validJsStr($_REQUEST['entity']))]; $entitySpec = &$statusData[strtolower(validJsStr($_REQUEST['entity']))];
#print_r( $entitySpec ); #print_r( $entitySpec );
if ( !canView( $entitySpec['permission'] ) ) if ( !canView($entitySpec['permission']) )
ajaxError('Unrecognised action or insufficient permissions'); ajaxError('Unrecognised action or insufficient permissions');
if ( !empty($entitySpec['func']) ) { if ( !empty($entitySpec['func']) ) {
$data = eval( 'return( '.$entitySpec['func']." );" ); $data = eval('return('.$entitySpec['func'].');');
} else { } else {
$data = array(); $data = array();
$postFuncs = array(); $postFuncs = array();
@ -249,12 +249,12 @@ function collectData() {
$groupSql[] = $elementData['group']; $groupSql[] = $elementData['group'];
} }
} }
} } # end foreach element
if ( count($fieldSql) ) { if ( count($fieldSql) ) {
$sql = 'select '.join( ', ', $fieldSql ).' from '.$entitySpec['table']; $sql = 'SELECT '.join(', ', $fieldSql).' FROM '.$entitySpec['table'];
if ( $joinSql ) if ( $joinSql )
$sql .= ' '.join( ' ', array_unique( $joinSql ) ); $sql .= ' '.join(' ', array_unique($joinSql));
if ( $id && !empty($entitySpec['selector']) ) { if ( $id && !empty($entitySpec['selector']) ) {
$index = 0; $index = 0;
$where = array(); $where = array();
@ -270,10 +270,10 @@ function collectData() {
} }
$index++; $index++;
} }
$sql .= ' WHERE '.join( ' AND ', $where ); $sql .= ' WHERE '.join(' AND ', $where);
} }
if ( $groupSql ) if ( $groupSql )
$sql .= ' GROUP BY '.join( ',', array_unique( $groupSql ) ); $sql .= ' GROUP BY '.join(',', array_unique($groupSql));
if ( !empty($_REQUEST['sort']) ) { if ( !empty($_REQUEST['sort']) ) {
$sql .= ' ORDER BY '; $sql .= ' ORDER BY ';
$sort_fields = explode(',',$_REQUEST['sort']); $sort_fields = explode(',',$_REQUEST['sort']);
@ -335,31 +335,29 @@ if ( !isset($_REQUEST['layout']) ) {
switch( $_REQUEST['layout'] ) { switch( $_REQUEST['layout'] ) {
case 'xml NOT CURRENTLY SUPPORTED' : case 'xml NOT CURRENTLY SUPPORTED' :
{ header('Content-type: application/xml');
header("Content-type: application/xml" ); echo('<?xml version="1.0" encoding="iso-8859-1"?>'."\n");
echo( '<?xml version="1.0" encoding="iso-8859-1"?>'."\n" );
echo '<'.strtolower($_REQUEST['entity']).">\n"; echo '<'.strtolower($_REQUEST['entity']).">\n";
foreach ( $data as $key=>$value ) { foreach ( $data as $key=>$value ) {
$key = strtolower( $key ); $key = strtolower($key);
echo "<$key>".htmlentities($value)."</$key>\n"; echo "<$key>".htmlentities($value)."</$key>\n";
} }
echo '</'.strtolower($_REQUEST['entity']).">\n"; echo '</'.strtolower($_REQUEST['entity']).">\n";
break; break;
}
case 'json' : case 'json' :
{ {
$response = array( strtolower(validJsStr($_REQUEST['entity'])) => $data ); $response = array( strtolower(validJsStr($_REQUEST['entity'])) => $data );
if ( isset($_REQUEST['loopback']) ) if ( isset($_REQUEST['loopback']) )
$response['loopback'] = validJsStr($_REQUEST['loopback']); $response['loopback'] = validJsStr($_REQUEST['loopback']);
ajaxResponse( $response ); ajaxResponse($response);
break; break;
} }
case 'text' : case 'text' :
{
header('Content-type: text/plain' ); header('Content-type: text/plain' );
echo join( ' ', array_values( $data ) ); echo join( ' ', array_values( $data ) );
break; break;
} default:
ZM\Error('Unsupported layout: '. $_REQUEST['layout']);
} }
function getFrameImage() { function getFrameImage() {