mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-11-30 04:04:03 -05:00
fix: console footer event links match no events when no monitor is listed instead of every event (#8517)
This commit is contained in:
1 parent
2f9f658a9a
commit
c69b5a5e4e
2 files changed
+123
-11
No files matched your search
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
// The console footer's event totals link to the events view for the monitors the console is
|
||||
// listing. When a search or filter leaves no monitor, the Monitor term had no value and dropped
|
||||
// out, so the "0 events" link opened every event of every monitor. It now names monitor 0, which
|
||||
// no event has. With monitors listed the link is unchanged.
|
||||
//
|
||||
// Run as: php tests/php/test_console_footer_no_monitors.php [root] [case] (root defaults to the repo)
|
||||
// The case is picked by the driver, since console.php defines functions at file scope.
|
||||
|
||||
$root = isset($argv[1]) ? $argv[1] : realpath(__DIR__.'/../..');
|
||||
|
||||
if ($argc < 3) {
|
||||
$failures = 0;
|
||||
foreach (array('none', 'one', 'two') as $case) {
|
||||
$out = array();
|
||||
$rc = 0;
|
||||
exec(escapeshellarg(PHP_BINARY).' '.escapeshellarg(__FILE__).' '.escapeshellarg($root).' '.escapeshellarg($case).' 2>&1', $out, $rc);
|
||||
echo implode("\n", $out)."\n";
|
||||
if ($rc !== 0) $failures++;
|
||||
}
|
||||
echo $failures ? "\n$failures case(s) FAILED\n" : "\nall cases passed\n";
|
||||
exit($failures ? 1 : 0);
|
||||
}
|
||||
$case = $argv[2];
|
||||
|
||||
namespace_stubs();
|
||||
function namespace_stubs() {
|
||||
eval('namespace ZM {
|
||||
function Error($m) {} function Warning($m) {} function Debug($m) {}
|
||||
class Monitor { private $r; function __construct($r = null) { $this->r = $r; } function __call($n, $a) { return $n == "Id" ? $this->r["Id"] : 0; } }
|
||||
class Storage { static function find() { return array(); } }
|
||||
class Group_Monitor { static function find($a = null) { return array(); } }
|
||||
}');
|
||||
}
|
||||
|
||||
$stub = sys_get_temp_dir().'/zm_console_footer_'.getmypid();
|
||||
mkdir($stub, 0777, true);
|
||||
file_put_contents($stub.'/_monitor_filters.php', '<?php
|
||||
function getFilterSelection($n) { return ""; }
|
||||
function getFilterText($n) { return ""; }
|
||||
function monitorNameRegexp($f) { return "/x/"; }
|
||||
function monitorStatusFilterSql($s, &$v, $e) { return "1"; }');
|
||||
foreach (array('Monitor', 'Group', 'Group_Monitor') as $f) {
|
||||
@mkdir($stub.'/includes');
|
||||
file_put_contents($stub.'/includes/'.$f.'.php', '<?php');
|
||||
}
|
||||
set_include_path($stub.PATH_SEPARATOR.get_include_path());
|
||||
register_shutdown_function(function() use ($stub) { system('rm -rf '.escapeshellarg($stub)); });
|
||||
|
||||
function getSkinFile($f) { global $stub; return $stub.'/_monitor_filters.php'; }
|
||||
function canView($a, $id = null) { return false; }
|
||||
function visibleMonitor($id) { return true; }
|
||||
function human_filesize($b) { return (string)$b; }
|
||||
function validHtmlStr($s) { return htmlspecialchars((string)$s); }
|
||||
define('ZM_WEB_LIST_THUMBS', false);
|
||||
// The filter helpers the footer builds its links with; querystring is the terms, readable.
|
||||
$fn = file_get_contents($root.'/web/includes/functions.php');
|
||||
preg_match('/^function addFilterTerm\(.*?\n\}/ms', $fn, $m);
|
||||
eval($m[0]);
|
||||
function parseFilter(&$filter) { $filter['querystring'] = json_encode($filter['Query']['terms']); return $filter; }
|
||||
|
||||
$rows = array();
|
||||
function mon($id) {
|
||||
return array('Id' => $id, 'Name' => "M$id", 'Function' => 'Monitor', 'Enabled' => 1, 'Sequence' => $id, 'Deleted' => 0,
|
||||
'Status' => 'Running', 'Type' => 'Ffmpeg', 'ServerId' => 0, 'StorageId' => 0, 'Capturing' => 'Always',
|
||||
'Analysing' => 'None', 'Decoding' => 'None', 'Recording' => 'None', 'ZoneCount' => 0, 'Manufacturer' => null, 'Model' => null,
|
||||
'Width' => 1, 'Height' => 1, 'TotalEvents' => 2, 'HourEvents' => 0, 'DayEvents' => 0, 'WeekEvents' => 0, 'MonthEvents' => 0, 'ArchivedEvents' => 0);
|
||||
}
|
||||
if ($case == 'one') $rows = array(mon(5));
|
||||
if ($case == 'two') $rows = array(mon(5), mon(7));
|
||||
function dbFetchAll($sql, $col = null, $params = null) { return $GLOBALS['rows']; }
|
||||
|
||||
$Servers = array();
|
||||
$user = new stdClass();
|
||||
$_REQUEST = array();
|
||||
$_COOKIE = array();
|
||||
function ajaxResponse($d = array()) { $GLOBALS['data'] = $d; }
|
||||
function ajaxError($m) {}
|
||||
$_REQUEST = array('task' => 'query');
|
||||
|
||||
require $root.'/web/ajax/console.php';
|
||||
$data = $GLOBALS['data'];
|
||||
|
||||
$failures = 0;
|
||||
function check($label, $got, $want) {
|
||||
global $failures;
|
||||
if ($got === $want) { echo "ok - $label\n"; return; }
|
||||
$failures++;
|
||||
echo "FAIL - $label\n got: ".var_export($got, true)."\n want: ".var_export($want, true)."\n";
|
||||
}
|
||||
function monitorTerm($querystring) {
|
||||
foreach (json_decode($querystring, true) as $t) {
|
||||
if ($t['attr'] == 'Monitor') return $t;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (array('Total', 'Hour', 'Day', 'Week', 'Month', 'Archived') as $period) {
|
||||
$t = monitorTerm($data['footer'][$period.'FilterQuery']);
|
||||
if ($case == 'none') {
|
||||
check("$period footer link is limited to a monitor no event has", $t ? $t['val'] : null, '0');
|
||||
} else if ($case == 'one') {
|
||||
check("$period footer link is limited to the listed monitor", $t ? $t['val'] : null, '5');
|
||||
} else {
|
||||
check("$period footer link is limited to the listed monitors", $t ? $t['val'] : null, '5,7');
|
||||
}
|
||||
}
|
||||
if ($case == 'none') check('the footer still counts no monitors', $data['footer']['monitor_count'], 0);
|
||||
exit($failures ? 1 : 0);
|
||||
+14
-11
@@ -684,22 +684,25 @@ function queryRequest() {
|
||||
$data['footer'][$period.'Events'] = $footer_totals['event_totals'][$period]['events'];
|
||||
$data['footer'][$period.'EventDiskSpace'] = human_filesize($footer_totals['event_totals'][$period]['diskspace']);
|
||||
|
||||
// Generate filter querystring for footer (include monitor filter if monitors are filtered)
|
||||
$filter = $eventCountsFooter[$period]['filter'];
|
||||
if (count($all_filtered_monitors) > 0) {
|
||||
$filter = addFilterTerm(
|
||||
$filter,
|
||||
count($filter['Query']['terms']),
|
||||
array('cnj' => 'and', 'attr' => 'Monitor', 'op' => 'IN', 'val' => implode(',', array_column($all_filtered_monitors, 'Id')))
|
||||
);
|
||||
}
|
||||
parseFilter($filter);
|
||||
$data['footer'][$period.'FilterQuery'] = $filter['querystring'];
|
||||
$data['footer'][$period.'FilterQuery'] = consoleFooterFilterQuery($eventCountsFooter[$period]['filter'], $all_filtered_monitors);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
// The querystring a footer event total links to: the period's filter limited to the monitors
|
||||
// the console is listing. With none listed the term would have no value and drop out, and the
|
||||
// link would show every event, so it names monitor 0, which no event has.
|
||||
function consoleFooterFilterQuery($filter, $monitors) {
|
||||
$filter = addFilterTerm(
|
||||
$filter,
|
||||
count($filter['Query']['terms']),
|
||||
array('cnj' => 'and', 'attr' => 'Monitor', 'op' => 'IN', 'val' => count($monitors) ? implode(',', array_column($monitors, 'Id')) : '0')
|
||||
);
|
||||
parseFilter($filter);
|
||||
return $filter['querystring'];
|
||||
}
|
||||
|
||||
// Remove camera credentials from an exported monitor for users who cannot edit it.
|
||||
function exportStripCredentials(array $data) {
|
||||
unset($data['User'], $data['Pass'], $data['ONVIF_Username'], $data['ONVIF_Password']);
|
||||
|
||||
Reference in new issue
Block a user