// GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // if (!canEdit('Monitors')) { $view = "error"; return; } $cameras = array(); $cameras[0] = translate('ChooseDetectedCamera'); if (ZM_HAS_V4L2) { // Probe Local Cameras // $command = getZmuCommand(" --query --device"); if (!empty($_REQUEST['device'])) { $command .= "=" . escapeshellarg($_REQUEST['device']); } $result = exec(escapeshellcmd($command), $output, $status); if ($status) { Fatal("Unable to probe local cameras, status is '{$status}'"); } $monitors = array(); foreach (dbFetchAll("select Id, Name, Device,Channel from Monitors where Type = 'Local' order by Device, Channel") as $monitor) { $monitors[$monitor['Device'] . ':' . $monitor['Channel']] = $monitor; } $devices = array(); $preferredStandards = array('PAL', 'NTSC'); $preferredFormats = array('BGR3', 'RGB3', 'YUYV', 'UYVY', 'JPEG', 'MJPG', '422P', 'YU12', 'GREY'); foreach ($output as $line) {
} // Monitor control actions, require a monitor id and control view permissions for that monitor if (!empty($_REQUEST['mid']) && canView('Control', $_REQUEST['mid'])) { require_once 'control_functions.php'; $mid = validInt($_REQUEST['mid']); if ($action == "control") { $monitor = dbFetchOne("select C.*,M.* from Monitors as M inner join Controls as C on (M.ControlId = C.Id) where M.Id = ?", NULL, array($mid)); $ctrlCommand = buildControlCommand($monitor); sendControlCommand($monitor['Id'], $ctrlCommand); } elseif ($action == "settings") { $args = " -m " . escapeshellarg($mid); $args .= " -B" . escapeshellarg($_REQUEST['newBrightness']); $args .= " -C" . escapeshellarg($_REQUEST['newContrast']); $args .= " -H" . escapeshellarg($_REQUEST['newHue']); $args .= " -O" . escapeshellarg($_REQUEST['newColour']); $zmuCommand = getZmuCommand($args); $zmuOutput = exec($zmuCommand); list($brightness, $contrast, $hue, $colour) = explode(' ', $zmuOutput); dbQuery("update Monitors set Brightness = ?, Contrast = ?, Hue = ?, Colour = ? where Id = ?", array($brightness, $contrast, $hue, $colour, $mid)); } } // Control capability actions, require control edit permissions if (canEdit('Control')) { if ($action == "controlcap") { if (!empty($_REQUEST['cid'])) { $control = dbFetchOne("select * from Controls where Id = ?", NULL, array($_REQUEST['cid'])); } else { $control = array(); } // Define a field type for anything that's not simple text equivalent $types = array();
function collectData() { global $statusData; if (isset($_REQUEST['MainFrameID']) && $_REQUEST['MainFrameID'] == "1") { $statusData["event"]["elements"]["MainFrameID"] = array("sql" => "(select FrameID from Frames where EventId=Events.id order by Score desc,FrameId limit 1)"); $statusData["events"]["elements"]["MainFrameID"] = array("sql" => "(select FrameID from Frames where EventId=Events.id order by Score desc,FrameId limit 1)"); } $entitySpec =& $statusData[strtolower(validJsStr($_REQUEST['entity']))]; #print_r( $entitySpec ); if (!canView($entitySpec['permission'])) { ajaxError('Unrecognised action or insufficient permissions'); } if (!empty($entitySpec['func'])) { $data = eval("return( " . $entitySpec['func'] . " );"); } else { $data = array(); $postFuncs = array(); $fieldSql = array(); $joinSql = array(); $groupSql = array(); $elements =& $entitySpec['elements']; $lc_elements = array_change_key_case($elements); $id = false; if (isset($_REQUEST['id'])) { if (!is_array($_REQUEST['id'])) { $id = array(validJsStr($_REQUEST['id'])); } else { $id = array_values($_REQUEST['id']); } } if (!isset($_REQUEST['element'])) { $_REQUEST['element'] = array_keys($elements); } else { if (!is_array($_REQUEST['element'])) { $_REQUEST['element'] = array(validJsStr($_REQUEST['element'])); } } if (isset($entitySpec['selector'])) { if (!is_array($entitySpec['selector'])) { $entitySpec['selector'] = array($entitySpec['selector']); } foreach ($entitySpec['selector'] as $selector) { if (is_array($selector) && isset($selector['table']) && isset($selector['join'])) { $joinSql[] = "left join " . $selector['table'] . " on " . $selector['join']; } } } foreach ($_REQUEST['element'] as $element) { if (!($elementData = $lc_elements[strtolower($element)])) { ajaxError("Bad " . validJsStr($_REQUEST['entity']) . " element " . $element); } if (isset($elementData['func'])) { $data[$element] = eval("return( " . $elementData['func'] . " );"); } else { if (isset($elementData['postFunc'])) { $postFuncs[$element] = $elementData['postFunc']; } else { if (isset($elementData['zmu'])) { $data[$element] = exec(escapeshellcmd(getZmuCommand(" " . $elementData['zmu']))); } else { if (isset($elementData['sql'])) { $fieldSql[] = $elementData['sql'] . " as " . $element; } else { $fieldSql[] = $element; } if (isset($elementData['table']) && isset($elementData['join'])) { $joinSql[] = "left join " . $elementData['table'] . " on " . $elementData['join']; } if (isset($elementData['group'])) { $groupSql[] = $elementData['group']; } } } } } if (count($fieldSql)) { $sql = "select " . join(", ", $fieldSql) . " from " . $entitySpec['table']; if ($joinSql) { $sql .= " " . join(" ", array_unique($joinSql)); } if ($id && !empty($entitySpec['selector'])) { $index = 0; $where = array(); $values = array(); foreach ($entitySpec['selector'] as $selector) { if (is_array($selector)) { $where[] = $selector['selector'] . ' = ?'; $values[] = validInt($id[$index]); } else { $where[] = $selector . ' = ?'; $values[] = validInt($id[$index]); } $index++; } $sql .= " where " . join(" and ", $where); } if ($groupSql) { $sql .= " group by " . join(",", array_unique($groupSql)); } if (!empty($_REQUEST['sort'])) { $arr = explode(' ', $_REQUEST['sort']); $col = validCol($arr[0]); $dir = ""; if (count($arr) == 2) { if ($arr[1] == "desc") { $dir = $arr[1]; } } $sql .= " order by {$col} {$dir}"; } if (!empty($entitySpec['limit'])) { $limit = $entitySpec['limit']; } elseif (!empty($_REQUEST['count'])) { $limit = validInt($_REQUEST['count']); } $limit_offset = ""; if (!empty($_REQUEST['offset'])) { $limit_offset = validInt($_REQUEST['offset']) . ", "; } if (!empty($limit)) { $sql .= " limit " . $limit_offset . $limit; } if (isset($limit) && $limit == 1) { if ($sqlData = dbFetchOne($sql, NULL, $values)) { foreach ($postFuncs as $element => $func) { $sqlData[$element] = eval('return( ' . $func . '( $sqlData ) );'); } $data = array_merge($data, $sqlData); } } else { $count = 0; foreach (dbFetchAll($sql, NULL, $values) as $sqlData) { foreach ($postFuncs as $element => $func) { $sqlData[$element] = eval('return( ' . $func . '( $sqlData ) );'); } $data[] = $sqlData; if (isset($limi) && ++$count >= $limit) { break; } } } } } #print_r( $data ); return $data; }
// but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // if (!canView('Stream')) { $_REQUEST['view'] = "error"; return; } $sql = 'select C.*, M.* from Monitors as M left join Controls as C on (M.ControlId = C.Id ) where M.Id = ?'; $monitor = dbFetchOne($sql, NULL, array($_REQUEST['mid'])); $showPtzControls = ZM_OPT_CONTROL && $monitor['Controllable'] && canView('Control'); $zmuCommand = getZmuCommand(" -m " . $_REQUEST['mid'] . " -s -f"); $zmuOutput = exec(escapeshellcmd($zmuCommand)); list($status, $fps) = explode(' ', $zmuOutput); $statusString = translate('Unknown'); $fpsString = "--.--"; $class = "infoText"; if ($status <= STATE_PREALARM) { $statusString = translate('Idle'); } elseif ($status == STATE_ALARM) { $statusString = translate('Alarm'); $class = "errorText"; } elseif ($status == STATE_ALERT) { $statusString = translate('Alert'); $class = "warnText"; } elseif ($status == STATE_TAPE) { $statusString = translate('Record');
// of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // if (!canView('System')) { $view = "error"; return; } $zmuCommand = getZmuCommand(" --list"); $result = exec(escapeshellcmd($zmuCommand), $output); $refresh = ZM_WEB_REFRESH_STATUS; $url = '?view=' . $view; noCacheHeaders(); xhtmlHeaders(__FILE__, $SLANG['Status']); ?> <body> <div id="page"> <div id="header"> <h2><?php echo $SLANG['Status']; ?> </h2> </div> <div id="content">
$zone = array('Name' => translate('New'), 'Id' => 0, 'MonitorId' => $monitor['Id'], 'NumCoords' => 4, 'Coords' => sprintf("%d,%d %d,%d, %d,%d %d,%d", $minX, $minY, $maxX, $minY, $maxX, $maxY, $minX, $maxY), 'Area' => $monitor['Width'] * $monitor['Height'], 'AlarmRGB' => 0xff0000, 'CheckMethod' => 'Blobs', 'MinPixelThreshold' => '', 'MaxPixelThreshold' => '', 'MinAlarmPixels' => '', 'MaxAlarmPixels' => '', 'FilterX' => '', 'FilterY' => '', 'MinFilterPixels' => '', 'MaxFilterPixels' => '', 'MinBlobPixels' => '', 'MaxBlobPixels' => '', 'MinBlobs' => '', 'MaxBlobs' => '', 'OverloadFrames' => '', 'ExtendAlarmFrames' => ''); } $zone['Points'] = coordsToPoints($zone['Coords']); $newZone = $zone; } //if ( !$points ) //{ //$points = $zone['Points']; //} ksort($newZone['Points'], SORT_NUMERIC); $newZone['Coords'] = pointsToCoords($newZone['Points']); $newZone['Area'] = getPolyArea($newZone['Points']); $selfIntersecting = isSelfIntersecting($newZone['Points']); $wd = getcwd(); chdir(ZM_DIR_IMAGES); $command = getZmuCommand(" -m " . $mid . " -z"); $command .= '"' . $zid . ' ' . $hicolor . ' ' . $newZone['Coords'] . '"'; $status = exec(escapeshellcmd($command)); chdir($wd); $zoneImage = ZM_DIR_IMAGES . '/Zones' . $monitor['Id'] . '.jpg?' . time(); $focusWindow = true; xhtmlHeaders(__FILE__, translate('Zone')); ?> <body> <div id="page"> <div id="header"> <h2><?php echo translate('Monitor'); ?> <?php echo $monitor['Name'];
// but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // if (!canView('Monitors')) { $view = "error"; return; } $mid = validInt($_REQUEST['mid']); $wd = getcwd(); chdir(ZM_DIR_IMAGES); $status = exec(escapeshellcmd(getZmuCommand(" -m " . $mid . " -z"))); chdir($wd); $monitor = dbFetchMonitor($mid); $sql = "select * from Zones where MonitorId = '" . $mid . "' order by Area desc"; $zones = array(); foreach (dbFetchAll($sql) as $row) { if ($row['Points'] = coordsToPoints($row['Coords'])) { $row['AreaCoords'] = preg_replace('/\\s+/', ',', $row['Coords']); $zones[] = $row; } } $image = 'Zones' . $monitor['Id'] . '.jpg'; xhtmlHeaders(__FILE__, $SLANG['Zones']); ?> <body> <div id="page">
<?php if (empty($_REQUEST['mid'])) { ajaxError('No monitor id supplied'); } elseif (!isset($_REQUEST['zid'])) { ajaxError('No zone id(s) supplied'); } if (canView('Monitors')) { switch ($_REQUEST['action']) { case "zoneImage": $wd = getcwd(); chdir(ZM_DIR_IMAGES); $hiColor = '0x00ff00'; $command = getZmuCommand(" -m " . $_REQUEST['mid'] . " -z"); if (!isset($_REQUEST['zid'])) { $_REQUEST['zid'] = 0; } $command .= "'" . $_REQUEST['zid'] . ' ' . $hiColor . ' ' . $_REQUEST['coords'] . "'"; $status = exec(escapeshellcmd($command)); chdir($wd); $monitor = dbFetchOne('SELECT * FROM Monitors WHERE Id = ?', NULL, array($_REQUEST['mid'])); $points = coordsToPoints($_REQUEST['coords']); ajaxResponse(array('zoneImage' => ZM_DIR_IMAGES . '/Zones' . $monitor['Id'] . '.jpg?' . time(), 'selfIntersecting' => isSelfIntersecting($points), 'area' => getPolyArea($points))); break; } } ajaxError('Unrecognised action or insufficient permissions');
function collectData() { global $statusData; $entitySpec =& $statusData[strtolower(validJsStr($_REQUEST['entity']))]; #print_r( $entitySpec ); if (!canView($entitySpec['permission'])) { ajaxError('Unrecognised action or insufficient permissions'); } if (!empty($entitySpec['func'])) { $data = eval("return( " . $entitySpec['func'] . " );"); } else { $data = array(); $postFuncs = array(); $fieldSql = array(); $joinSql = array(); $groupSql = array(); $elements =& $entitySpec['elements']; $lc_elements = array_change_key_case($elements); $id = false; if (isset($_REQUEST['id'])) { if (!is_array($_REQUEST['id'])) { $id = array(validJsStr($_REQUEST['id'])); } else { $id = array_values($_REQUEST['id']); } } if (!isset($_REQUEST['element'])) { $_REQUEST['element'] = array_keys($elements); } else { if (!is_array($_REQUEST['element'])) { $_REQUEST['element'] = array(validJsStr($_REQUEST['element'])); } } if (isset($entitySpec['selector'])) { if (!is_array($entitySpec['selector'])) { $entitySpec['selector'] = array($entitySpec['selector']); } foreach ($entitySpec['selector'] as $selector) { if (is_array($selector) && isset($selector['table']) && isset($selector['join'])) { $joinSql[] = "left join " . $selector['table'] . " on " . $selector['join']; } } } foreach ($_REQUEST['element'] as $element) { if (!($elementData = $lc_elements[strtolower($element)])) { ajaxError("Bad " . validJsStr($_REQUEST['entity']) . " element " . $element); } if (isset($elementData['func'])) { $data[$element] = eval("return( " . $elementData['func'] . " );"); } else { if (isset($elementData['postFunc'])) { $postFuncs[$element] = $elementData['postFunc']; } else { if (isset($elementData['zmu'])) { $data[$element] = exec(escapeshellcmd(getZmuCommand(" " . $elementData['zmu']))); } else { if (isset($elementData['sql'])) { $fieldSql[] = $elementData['sql'] . " as " . $element; } else { $fieldSql[] = $element; } if (isset($elementData['table']) && isset($elementData['join'])) { $joinSql[] = "left join " . $elementData['table'] . " on " . $elementData['join']; } if (isset($elementData['group'])) { $groupSql[] = $elementData['group']; } } } } } if (count($fieldSql)) { $sql = "select " . join(", ", $fieldSql) . " from " . $entitySpec['table']; if ($joinSql) { $sql .= " " . join(" ", array_unique($joinSql)); } if ($id && !empty($entitySpec['selector'])) { $index = 0; $where = array(); foreach ($entitySpec['selector'] as $selector) { if (is_array($selector)) { $where[] = $selector['selector'] . " = " . dbEscape($id[$index]); } else { $where[] = $selector . " = " . dbEscape($id[$index]); } $index++; } $sql .= " where " . join(" and ", $where); } if ($groupSql) { $sql .= " group by " . join(",", array_unique($groupSql)); } if (!empty($_REQUEST['sort'])) { $sql .= " order by " . dbEscape($_REQUEST['sort']); } if (!empty($entitySpec['limit'])) { $limit = $entitySpec['limit']; } elseif (!empty($_REQUEST['count'])) { $limit = dbEscape($_REQUEST['count']); } if (!empty($limit)) { $sql .= " limit " . $limit; } if (isset($limit) && $limit == 1) { if ($sqlData = dbFetchOne($sql)) { foreach ($postFuncs as $element => $func) { $sqlData[$element] = eval('return( ' . $func . '( $sqlData ) );'); } $data = array_merge($data, $sqlData); } } else { $count = 0; foreach (dbFetchAll($sql) as $sqlData) { foreach ($postFuncs as $element => $func) { $sqlData[$element] = eval('return( ' . $func . '( $sqlData ) );'); } $data[] = $sqlData; if (isset($limi) && ++$count >= $limit) { break; } } } } } #print_r( $data ); return $data; }
// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // if (!canView('Control')) { $view = "error"; return; } $monitor = dbFetchMonitor($_REQUEST['mid']); $zmuCommand = getZmuCommand(" -m " . escapeshellarg($_REQUEST['mid']) . " -B -C -H -O"); $zmuOutput = exec($zmuCommand); list($brightness, $contrast, $hue, $colour) = explode(' ', $zmuOutput); $monitor['Brightness'] = $brightness; $monitor['Contrast'] = $contrast; $monitor['Hue'] = $hue; $monitor['Colour'] = $colour; $focusWindow = true; xhtmlHeaders(__FILE__, validHtmlStr($monitor['Name']) . " - " . $SLANG['Settings']); ?> <body> <div id="page"> <div id="header"> <h2><?php echo validHtmlStr($monitor['Name']); ?>
$options[$matches[1]] = $matches[2] ? $matches[2] : 1; } } $optionString = jsonEncode($options); if (!socket_write($socket, $optionString)) { Fatal("Can't write to control socket: " . socket_strerror(socket_last_error($socket))); } socket_close($socket); } else { $ctrlCommand .= " --id=" . $monitor['Id']; // Can't connect so use script $ctrlOutput = exec(escapeshellcmd($ctrlCommand)); } } } elseif ($action == "settings") { $zmuCommand = getZmuCommand(" -m " . $mid . " -B" . $_REQUEST['newBrightness'] . " -C" . $_REQUEST['newContrast'] . " -H" . $_REQUEST['newHue'] . " -O" . $_REQUEST['newColour']); $zmuOutput = exec(escapeshellcmd($zmuCommand)); list($brightness, $contrast, $hue, $colour) = explode(' ', $zmuOutput); dbQuery("update Monitors set Brightness = '" . $brightness . "', Contrast = '" . $contrast . "', Hue = '" . $hue . "', Colour = '" . $colour . "' where Id = '" . $mid . "'"); } } // Control capability actions, require control edit permissions if (canEdit('Control')) { if ($action == "controlcap") { if (!empty($_REQUEST['cid'])) { $control = dbFetchOne("select * from Controls where Id = '" . dbEscape($_REQUEST['cid']) . "'"); } else { $control = array(); } // Define a field type for anything that's not simple text equivalent $types = array();
<?php define("MSG_TIMEOUT", 2.0); define("MSG_DATA_SIZE", 4 + 256); if (canEdit('Monitors')) { $zmuCommand = getZmuCommand(" -m " . validInt($_REQUEST['id'])); switch (validJsStr($_REQUEST['command'])) { case "disableAlarms": $zmuCommand .= " -n"; break; case "enableAlarms": $zmuCommand .= " -c"; break; case "forceAlarm": $zmuCommand .= " -a"; break; case "cancelForcedAlarm": $zmuCommand .= " -c"; break; default: ajaxError("Unexpected command '" . validJsStr($_REQUEST['command']) . "'"); } ajaxResponse(exec(escapeshellcmd($zmuCommand))); } ajaxError('Unrecognised action or insufficient permissions');