'presetGoto3')), ' --preset=3 --command=presetGoto'); check('presetGoto with a numeric preset is accepted', command_for(array('control' => 'presetGoto', 'preset' => '12')), ' --preset=12 --command=presetGoto'); check('presetGoto with SQL in the preset is refused', command_for(array('control' => 'presetGoto', 'preset' => "0/**/UNION/**/SELECT/**/Value/**/FROM/**/Config")), ''); check('presetGoto with extra options in the preset is refused', command_for(array('control' => 'presetGoto', 'preset' => '1 --command=quit')), ''); check('plain movement command is accepted', command_for(array('control' => 'moveConUp')), ' --command=moveConUp'); check('qualified method name is refused', command_for(array('control' => 'ZoneMinder::General::executeShellCommand')), ''); check('control with spaces is refused', command_for(array('control' => 'wake --preset=1')), ''); check('missing control is refused', command_for(array()), ''); // ---- canView()/canEdit() with a monitor id --------------------------------- $source = file_get_contents(__DIR__.'/../../web/includes/auth.php'); foreach (array('canView', 'canEdit') as $fn) { if (!preg_match('/^function '.$fn.'\(.*?^}\n/ms', $source, $m)) { echo "FAIL - could not find $fn in auth.php\n"; exit(1); } eval($m[0]); } class StubUser { private $perms; public function __construct($perms) { $this->perms = $perms; } public function __call($area, $args) { return isset($this->perms[$area]) ? $this->perms[$area] : 'None'; } public function Role() { return null; } } $visible = array(); function visibleMonitor($mid) { global $visible; return in_array($mid, $visible); } function editableMonitor($mid) { global $visible; return in_array($mid, $visible); } $visible = array(1); $user = new StubUser(array('Monitors' => 'View', 'Control' => 'None')); check('Control=None viewer of the monitor cannot control it', canView('Control', 1), false); check('Control=None viewer can still view the monitor', canView('Monitors', 1), true); $user = new StubUser(array('Monitors' => 'View', 'Control' => 'View')); check('Control=View viewer of the monitor can control it', canView('Control', 1), true); check('Control=View user cannot control a monitor they cannot see', canView('Control', 2), false); check('Control=View user cannot edit Control on the monitor', canEdit('Control', 1), false); $user = new StubUser(array('Monitors' => 'Edit', 'Control' => 'Edit')); check('Control=Edit editor of the monitor can edit Control', canEdit('Control', 1), true); check('Monitors=Edit user can edit the monitor', canEdit('Monitors', 1), true); array_map('unlink', glob($stubdir.'/*')); @rmdir($stubdir); echo "\n$passes passed, $failures failed\n"; exit($failures ? 1 : 0);