mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-11-30 12:14:36 -05:00
79 lines
2.3 KiB
PHP
79 lines
2.3 KiB
PHP
<?php
|
|
if ($argc < 2 || (isset($argv[1]) && is_dir($argv[1]))) {
|
|
$root = (isset($argv[1]) && is_dir($argv[1])) ? $argv[1] : __DIR__.'/../..';
|
|
$failures = 0;
|
|
foreach (array('aud', 'inf', 'err') as $case) {
|
|
$out = array();
|
|
$rc = 0;
|
|
exec(escapeshellarg(PHP_BINARY).' '.escapeshellarg(__FILE__).' '.escapeshellarg($case).' '.escapeshellarg($root).' 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);
|
|
}
|
|
|
|
// web/ajax/log.php create accepted level AUD, so anyone allowed to inject
|
|
// logs could forge audit-level rows.
|
|
$case = $argv[1];
|
|
$root = $argv[2];
|
|
$GLOBALS['logged'] = array();
|
|
|
|
function canEdit($area) {
|
|
return true;
|
|
}
|
|
function validHtmlStr($s) {
|
|
return htmlspecialchars($s, ENT_QUOTES);
|
|
}
|
|
function ajaxError($message) {
|
|
}
|
|
function ajaxResponse($data = array()) {
|
|
}
|
|
class FakeUser {
|
|
public function Username() {
|
|
return 'tester';
|
|
}
|
|
}
|
|
$user = new FakeUser();
|
|
eval('namespace ZM;
|
|
class Logger {
|
|
public static $codes = array(-6=>"OFF", -5=>"AUD", -3=>"FAT", -2=>"ERR", 0=>"INF", 1=>"DBG");
|
|
public static function fetch() {
|
|
return new Logger();
|
|
}
|
|
public function logPrint($level, $message, $file = null, $line = null) {
|
|
$GLOBALS["logged"][] = $level;
|
|
}
|
|
}
|
|
function logInit($options = array()) {}
|
|
function Error($m) {}
|
|
function Warning($m) {}');
|
|
|
|
$levels = array('aud' => 'AUD', 'inf' => 'INF', 'err' => 'ERR');
|
|
$_REQUEST = array('task' => 'create');
|
|
$_POST = array('level' => $levels[$case], 'message' => 'boom', 'file' => 'x.js', 'line' => '3');
|
|
|
|
require($root.'/web/ajax/log.php');
|
|
|
|
$failures = 0;
|
|
function check($label, $got, $want) {
|
|
global $failures;
|
|
$ok = ($got === $want);
|
|
if (!$ok) $failures++;
|
|
printf("[%s] %s\n", $ok ? 'PASS' : 'FAIL', $label);
|
|
if (!$ok) printf(" got: %s\n want: %s\n", var_export($got, true), var_export($want, true));
|
|
}
|
|
|
|
switch ($case) {
|
|
case 'aud':
|
|
check('a request cannot log at AUDIT; it is logged as an error', $GLOBALS['logged'], array(-2));
|
|
break;
|
|
case 'inf':
|
|
check('INF is logged as itself', $GLOBALS['logged'], array(0));
|
|
break;
|
|
case 'err':
|
|
check('ERR is logged as itself', $GLOBALS['logged'], array(-2));
|
|
break;
|
|
}
|
|
exit($failures ? 1 : 0);
|