Return Debug to a regular function to match other logging functions. Since we switched to using namespaces we no longer clash with cake_php.

This commit is contained in:
Isaac Connor 2020-10-14 10:39:25 -04:00
parent ff14d11fef
commit 10c0a6617c
40 changed files with 144 additions and 143 deletions

View File

@ -19,11 +19,11 @@ function probe( &$url_bits ) {
$cam_list_html = file_get_contents('http://'.$url_bits['host'].':5000/monitoring/');
if ( $cam_list_html ) {
ZM\Logger::Debug("Have content at port 5000/monitoring");
ZM\Debug("Have content at port 5000/monitoring");
$matches_count = preg_match_all(
'/<a href="http:\/\/([.[:digit:]]+):([[:digit:]]+)\/\?action=stream" target="_blank">([^<]+)<\/a>/',
$cam_list_html, $cam_list );
ZM\Logger::Debug(print_r($cam_list,true));
ZM\Debug(print_r($cam_list,true));
}
if ( $matches_count ) {
for( $index = 0; $index < $matches_count; $index ++ ) {
@ -33,7 +33,7 @@ function probe( &$url_bits ) {
if ( ! isset($new_stream['scheme'] ) )
$new_stream['scheme'] = 'http';
$available_streams[] = $new_stream;
ZM\Logger::Debug("Have new stream " . print_r($new_stream,true) );
ZM\Debug("Have new stream " . print_r($new_stream,true) );
}
} else {
ZM\Info('No matches');

View File

@ -252,7 +252,7 @@ switch ( $_REQUEST['task'] ) {
ZM\Fatal('Can\'t create exports dir at \''.ZM_DIR_EXPORTS.'\'');
}
$exportPath = ZM_DIR_EXPORTS.'/zm-log-'.$exportKey.$exportExt;
ZM\Logger::Debug("Exporting to $exportPath");
ZM\Debug("Exporting to $exportPath");
if ( !($exportFP = fopen($exportPath, 'w')) )
ZM\Fatal("Unable to open log export file $exportPath");
$logs = array();
@ -261,7 +261,7 @@ switch ( $_REQUEST['task'] ) {
$log['Server'] = ( $log['ServerId'] and isset($servers_by_Id[$log['ServerId']]) ) ? $servers_by_Id[$log['ServerId']]->Name() : '';
$logs[] = $log;
}
ZM\Logger::Debug(count($logs).' lines being exported by '.$sql.implode(',', $values));
ZM\Debug(count($logs).' lines being exported by '.$sql.implode(',', $values));
switch( $format ) {
case 'text' :

View File

@ -8,7 +8,7 @@ if ( empty($_REQUEST['modal']) ) {
$modal = validJsStr($_REQUEST['modal']);
$data = array();
ZM\Logger::Debug("Including modals/$modal.php");
ZM\Debug("Including modals/$modal.php");
# Shouldn't be necessary but at the moment we have last .conf file contents
ob_start();
@$result = include('modals/'.$modal.'.php');

View File

@ -60,7 +60,7 @@ if ( isset($_SESSION['montageReviewFilter']) and !$eids ) {
#unset($_SESSION['montageReviewFilter']);
#session_write_close();
#} else {
#Logger::Debug("NO montageReviewFilter");
#Debug("NO montageReviewFilter");
}
$exportFormat = '';

View File

@ -69,7 +69,7 @@ while ( $row = $result->fetch(PDO::FETCH_ASSOC) ) {
} else {
$user = ZM\User::find_one(array('Username'=>$_SESSION['username']));
if ( ! $user ) {
ZM\Logger::Debug('User not found for ' . $_SESSION['username']);
ZM\Debug('User not found for ' . $_SESSION['username']);
continue;
}
$user_cache[$_SESSION['username']] = $user;

View File

@ -336,7 +336,7 @@ function collectData() {
}
}
}
#ZM\Logger::Debug(print_r($data, true));
#ZM\Debug(print_r($data, true));
return $data;
}

View File

@ -31,19 +31,19 @@ if ( sem_acquire($semaphore,1) !== false ) {
switch ( $_REQUEST['command'] ) {
case CMD_VARPLAY :
ZM\Logger::Debug('Varplaying to '.$_REQUEST['rate']);
ZM\Debug('Varplaying to '.$_REQUEST['rate']);
$msg = pack('lcn', MSG_CMD, $_REQUEST['command'], $_REQUEST['rate']+32768);
break;
case CMD_ZOOMIN :
ZM\Logger::Debug('Zooming to '.$_REQUEST['x'].','.$_REQUEST['y']);
ZM\Debug('Zooming to '.$_REQUEST['x'].','.$_REQUEST['y']);
$msg = pack('lcnn', MSG_CMD, $_REQUEST['command'], $_REQUEST['x'], $_REQUEST['y']);
break;
case CMD_PAN :
ZM\Logger::Debug('Panning to '.$_REQUEST['x'].','.$_REQUEST['y']);
ZM\Debug('Panning to '.$_REQUEST['x'].','.$_REQUEST['y']);
$msg = pack('lcnn', MSG_CMD, $_REQUEST['command'], $_REQUEST['x'], $_REQUEST['y']);
break;
case CMD_SCALE :
ZM\Logger::Debug('Scaling to '.$_REQUEST['scale']);
ZM\Debug('Scaling to '.$_REQUEST['scale']);
$msg = pack('lcn', MSG_CMD, $_REQUEST['command'], $_REQUEST['scale']);
break;
case CMD_SEEK :
@ -53,7 +53,7 @@ if ( sem_acquire($semaphore,1) !== false ) {
1000000*( $_REQUEST['offset']-intval($_REQUEST['offset'])));
break;
default :
ZM\Logger::Debug('Sending command ' . $_REQUEST['command']);
ZM\Debug('Sending command ' . $_REQUEST['command']);
$msg = pack('lc', MSG_CMD, $_REQUEST['command']);
break;
}
@ -67,7 +67,7 @@ if ( sem_acquire($semaphore,1) !== false ) {
// WHY? We will just send another one...
// ANSWER: Because otherwise we get a log of errors logged
//ZM\Logger::Debug("$remSockFile does not exist, waiting, current " . (time() - $start_time) . ' seconds' );
//ZM\Debug("$remSockFile does not exist, waiting, current " . (time() - $start_time) . ' seconds' );
usleep(1000);
}
@ -126,16 +126,16 @@ if ( sem_acquire($semaphore,1) !== false ) {
$auth_hash = generateAuthHash(ZM_AUTH_HASH_IPS);
if ( isset($_REQUEST['auth']) and ($_REQUEST['auth'] != $auth_hash) ) {
$data['auth'] = $auth_hash;
ZM\Logger::Debug("including nw auth hash " . $data['auth']);
ZM\Debug("including nw auth hash " . $data['auth']);
} else {
ZM\Logger::Debug('Not including nw auth hash becase it hashn\'t changed '.$auth_hash);
ZM\Debug('Not including nw auth hash becase it hashn\'t changed '.$auth_hash);
}
}
ajaxResponse(array('status'=>$data));
break;
case MSG_DATA_EVENT :
if ( version_compare( phpversion(), '5.6.0', '<') ) {
ZM\Logger::Debug('Using old unpack methods to handle 64bit event id');
ZM\Debug('Using old unpack methods to handle 64bit event id');
$data = unpack('ltype/ieventlow/ieventhigh/dduration/dprogress/irate/izoom/Cpaused', $msg);
$data['event'] = $data['eventhigh'] << 32 | $data['eventlow'];
} else {
@ -156,7 +156,7 @@ if ( sem_acquire($semaphore,1) !== false ) {
}
sem_release($semaphore);
} else {
ZM\Logger::Debug('Couldn\'t get semaphore');
ZM\Debug('Couldn\'t get semaphore');
ajaxResponse(array());
}

View File

@ -105,7 +105,7 @@ class AppController extends Controller {
if ( ! is_session_started() )
zm_session_start();
ZM\Logger::Debug(print_r($_SESSION, true));
ZM\Debug(print_r($_SESSION, true));
$user = userFromSession();
session_write_close();
}

View File

@ -50,10 +50,10 @@ class HostController extends AppController {
$cred_depr = [];
if ( $username && $password ) {
ZM\Logger::Debug('Username and password provided, generating access and refresh tokens');
ZM\Debug('Username and password provided, generating access and refresh tokens');
$cred = $this->_getCredentials(true, '', $username); // generate refresh
} else {
ZM\Logger::Debug('Only generating access token');
ZM\Debug('Only generating access token');
$cred = $this->_getCredentials(false, $token); // don't generate refresh
}
@ -72,7 +72,7 @@ class HostController extends AppController {
$login_array['credentials'] = $cred_depr[0];
$login_array['append_password'] = $cred_depr[1];
} else {
ZM\Logger::Debug('Legacy Auth is disabled, not generating auth= credentials');
ZM\Debug('Legacy Auth is disabled, not generating auth= credentials');
}
$login_array['version'] = $ver[0];
@ -203,7 +203,7 @@ class HostController extends AppController {
if ( $mid ) {
// Get disk usage for $mid
ZM\Logger::Debug("Executing du -s0 $zm_dir_events/$mid | awk '{print $1}'");
ZM\Debug("Executing du -s0 $zm_dir_events/$mid | awk '{print $1}'");
$usage = shell_exec("du -s0 $zm_dir_events/$mid | awk '{print $1}'");
} else {
$monitors = $this->Monitor->find('all', array(

View File

@ -178,7 +178,7 @@ class MonitorsController extends AppController {
)
) {
if ( !defined('ZM_SERVER_ID')) {
ZM\Logger::Debug("Not defined ZM_SERVER_ID");
ZM\Debug("Not defined ZM_SERVER_ID");
}
$this->daemonControl($this->Monitor->id, 'start');
}
@ -386,7 +386,7 @@ class MonitorsController extends AppController {
}
$shellcmd = escapeshellcmd("$zm_path_bin/zmdc.pl $command $daemon $args");
ZM\Logger::Debug("Command $shellcmd");
ZM\Debug("Command $shellcmd");
$status = exec($shellcmd);
$status_text .= $status."\n";
}

View File

@ -133,10 +133,10 @@ class Event extends AppModel {
if ( file_exists($this->Path().'/'.$event['DefaultVideo']) ) {
return 1;
} else {
ZM\Logger::Debug('File does not exist at ' . $this->Path().'/'.$event['DefaultVideo'] );
ZM\Debug('File does not exist at ' . $this->Path().'/'.$event['DefaultVideo'] );
}
} else {
ZM\Logger::Debug('No DefaultVideo in Event' . $this->Event);
ZM\Debug('No DefaultVideo in Event' . $this->Event);
return 0;
}
} // end function fileExists($event)

View File

@ -291,7 +291,7 @@ class Event extends ZM_Object {
# The idea here is that we don't really want to use the analysis jpeg as the thumbnail.
# The snapshot image will be generated during capturing
if ( file_exists($this->Path().'/snapshot.jpg') ) {
Logger::Debug("snapshot exists");
Debug("snapshot exists");
$frame = null;
} else {
# Load the frame with the highest score to use as a thumbnail
@ -396,14 +396,14 @@ class Event extends ZM_Object {
if ( $frame and !is_array($frame) ) {
# Must be an Id
Logger::Debug("Assuming that $frame is an Id");
Debug("Assuming that $frame is an Id");
$frame = array('FrameId'=>$frame, 'Type'=>'', 'Delta'=>0);
}
if ( ( !$frame ) and file_exists($eventPath.'/snapshot.jpg') ) {
# No frame specified, so look for a snapshot to use
$captImage = 'snapshot.jpg';
Logger::Debug('Frame not specified, using snapshot');
Debug('Frame not specified, using snapshot');
$frame = array('FrameId'=>'snapshot', 'Type'=>'', 'Delta'=>0);
} else {
$captImage = sprintf('%0'.ZM_EVENT_IMAGE_DIGITS.'d-analyze.jpg', $frame['FrameId']);
@ -421,11 +421,11 @@ class Event extends ZM_Object {
#$command ='ffmpeg -v 0 -i '.$videoPath.' -vf "select=gte(n\\,'.$frame['FrameId'].'),setpts=PTS-STARTPTS" '.$eventPath.'/'.$captImage;
$command ='ffmpeg -ss '. $frame['Delta'] .' -i '.$videoPath.' -frames:v 1 '.$eventPath.'/'.$captImage;
Logger::Debug('Running '.$command);
Debug('Running '.$command);
$output = array();
$retval = 0;
exec($command, $output, $retval);
Logger::Debug("Retval: $retval, output: " . implode("\n", $output));
Debug("Retval: $retval, output: " . implode("\n", $output));
} else {
Error('Can\'t create frame images from video because there is no video file for event '.$Event->Id().' at ' .$Event->Path());
}
@ -529,7 +529,7 @@ class Event extends ZM_Object {
return;
}
}
Logger::Debug("sending command to $url");
Debug("sending command to $url");
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
@ -545,7 +545,7 @@ class Event extends ZM_Object {
Error("Error restarting zmc using $url");
}
$event_data = json_decode($result,true);
Logger::Debug(print_r($event_data['event']['Event'],1));
Debug(print_r($event_data['event']['Event'],1));
return $event_data['event']['Event']['fileExists'];
} catch ( Exception $e ) {
Error("Except $e thrown trying to get event data");
@ -577,7 +577,7 @@ class Event extends ZM_Object {
return;
}
}
Logger::Debug("sending command to $url");
Debug("sending command to $url");
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
@ -593,7 +593,7 @@ class Event extends ZM_Object {
Error("Error restarting zmc using $url");
}
$event_data = json_decode($result,true);
Logger::Debug(print_r($event_data['event']['Event'], 1));
Debug(print_r($event_data['event']['Event'], 1));
return $event_data['event']['Event']['fileSize'];
} catch ( Exception $e ) {
Error("Except $e thrown trying to get event data");

View File

@ -230,7 +230,7 @@ class Filter extends ZM_Object {
if ( (!defined('ZM_SERVER_ID')) or (!$Server->Id()) or (ZM_SERVER_ID==$Server->Id()) ) {
# Local
Logger::Debug("Controlling filter locally $command for server ".$Server->Id());
Debug("Controlling filter locally $command for server ".$Server->Id());
daemonControl($command, 'zmfilter.pl', '--filter_id='.$this->{'Id'}.' --daemon');
} else {
# Remote case
@ -247,7 +247,7 @@ class Filter extends ZM_Object {
}
}
$url .= '&view=filter&object=filter&action=control&command='.$command.'&Id='.$this->Id().'&ServerId='.$Server->Id();
Logger::Debug("sending command to $url");
Debug("sending command to $url");
$data = array();
if ( defined('ZM_ENABLE_CSRF_MAGIC') ) {
require_once( 'includes/csrf/csrf-magic.php' );
@ -278,7 +278,7 @@ class Filter extends ZM_Object {
public function execute() {
$command = ZM_PATH_BIN.'/zmfilter.pl --filter_id='.escapeshellarg($this->Id());
$result = exec($command, $output, $status);
Logger::Debug("$command status:$status output:".implode("\n", $output));
Debug("$command status:$status output:".implode("\n", $output));
return $status;
}

View File

@ -329,14 +329,14 @@ class FilterTerm {
public function test($event=null) {
if ( !isset($event) ) {
# Is a Pre Condition
Logger::Debug("Testing " . $this->attr);
Debug("Testing " . $this->attr);
if ( $this->attr == 'DiskPercent' ) {
# The logic on this is really ugly. We are going to treat it as an OR
foreach ( $this->filter->get_StorageAreas() as $storage ) {
$string_to_eval = 'return $storage->disk_usage_percent() '.$this->op.' '.$this->val.';';
try {
$ret = eval($string_to_eval);
Logger::Debug("Evalled $string_to_eval = $ret");
Debug("Evalled $string_to_eval = $ret");
if ( $ret )
return true;
} catch ( Throwable $t ) {
@ -348,7 +348,7 @@ class FilterTerm {
$string_to_eval = 'return getLoad() '.$this->op.' '.$this->val.';';
try {
$ret = eval($string_to_eval);
Logger::Debug("Evaled $string_to_eval = $ret");
Debug("Evaled $string_to_eval = $ret");
if ( $ret )
return true;
} catch ( Throwable $t ) {
@ -374,7 +374,7 @@ class FilterTerm {
$string_to_eval = 'return $event->Storage()->disk_usage_percent() '.$this->op.' '.$this->val.';';
try {
$ret = eval($string_to_eval);
Logger::Debug("Evalled $string_to_eval = $ret");
Debug("Evalled $string_to_eval = $ret");
if ( $ret )
return true;
} catch ( Throwable $t ) {
@ -385,7 +385,7 @@ class FilterTerm {
$string_to_eval = 'return $event->Storage()->disk_usage_blocks() '.$this->op.' '.$this->val.';';
try {
$ret = eval($string_to_eval);
Logger::Debug("Evalled $string_to_eval = $ret");
Debug("Evalled $string_to_eval = $ret");
if ( $ret )
return true;
} catch ( Throwable $t ) {

View File

@ -329,7 +329,7 @@ class Monitor extends ZM_Object {
return;
}
}
Logger::Debug('sending command to '.$url);
Debug('sending command to '.$url);
$context = stream_context_create();
try {
@ -389,7 +389,7 @@ class Monitor extends ZM_Object {
return;
}
}
Logger::Debug("sending command to $url");
Debug("sending command to $url");
$context = stream_context_create();
try {
@ -538,7 +538,7 @@ class Monitor extends ZM_Object {
if ( $command == 'quit' or $command == 'start' or $command == 'stop' ) {
# These are special as we now run zmcontrol as a daemon through zmdc.
$status = daemonStatus('zmcontrol.pl', array('--id', $this->{'Id'}));
Logger::Debug("Current status $status");
Debug("Current status $status");
if ( $status or ( (!defined('ZM_SERVER_ID')) or ( property_exists($this, 'ServerId') and (ZM_SERVER_ID==$this->{'ServerId'}) ) ) ) {
daemonControl($command, 'zmcontrol.pl', '--id '.$this->{'Id'});
return;
@ -552,10 +552,10 @@ class Monitor extends ZM_Object {
if ( (!defined('ZM_SERVER_ID')) or ( property_exists($this, 'ServerId') and (ZM_SERVER_ID==$this->{'ServerId'}) ) ) {
# Local
Logger::Debug('Trying to send options ' . print_r($options, true));
Debug('Trying to send options ' . print_r($options, true));
$optionString = jsonEncode($options);
Logger::Debug("Trying to send options $optionString");
Debug("Trying to send options $optionString");
// Either connects to running zmcontrol.pl or runs zmcontrol.pl to send the command.
$socket = socket_create(AF_UNIX, SOCK_STREAM, 0);
if ( $socket < 0 ) {
@ -589,7 +589,7 @@ class Monitor extends ZM_Object {
$url .= '?user='.$_SESSION['username'];
}
}
Logger::Debug("sending command to $url");
Debug("sending command to $url");
$context = stream_context_create();
try {

View File

@ -94,7 +94,7 @@ class Storage extends ZM_Object {
}
$used = $this->disk_used_space();
$usage = round(($used / $total) * 100);
//Logger::Debug("Used $usage = round( ( $used / $total ) * 100 )");
//Debug("Used $usage = round( ( $used / $total ) * 100 )");
return $usage;
}

View File

@ -32,7 +32,7 @@ if ( !canEdit('Events') ) {
if ( $action == 'archive' ) {
$dbConn->beginTransaction();
$eids = getAffectedIds('eids');
ZM\Logger::Debug("E IDS" . print_r($eids, true));
ZM\Debug("E IDS" . print_r($eids, true));
foreach ( $eids as $markEid ) {
dbQuery('UPDATE Events SET Archived=? WHERE Id=?', array(1, $markEid));
}
@ -41,7 +41,7 @@ if ( $action == 'archive' ) {
} else if ( $action == 'unarchive' ) {
$dbConn->beginTransaction();
$eids = getAffectedIds('eids');
ZM\Logger::Debug("E IDS" . print_r($eids, true));
ZM\Debug("E IDS" . print_r($eids, true));
foreach ( $eids as $markEid ) {
dbQuery('UPDATE Events SET Archived=? WHERE Id=?', array(0, $markEid));
}

View File

@ -64,7 +64,7 @@ if ( isset($_REQUEST['object']) and ( $_REQUEST['object'] == 'filter' ) ) {
$_REQUEST['filter']['Background'] = empty($_REQUEST['filter']['Background']) ? 0 : 1;
$_REQUEST['filter']['Concurrent'] = empty($_REQUEST['filter']['Concurrent']) ? 0 : 1;
$changes = $filter->changes($_REQUEST['filter']);
ZM\Logger::Debug('Changes: ' . print_r($changes,true));
ZM\Debug('Changes: ' . print_r($changes,true));
if ( $_REQUEST['Id'] and ( $action == 'Save' ) ) {
if ( $filter->Background() )

View File

@ -52,7 +52,7 @@ if ( $action == 'function' ) {
$monitor->zmaControl('start');
}
} else {
ZM\Logger::Debug('No change to function, not doing anything.');
ZM\Debug('No change to function, not doing anything.');
}
} // end if action
$redirect = '?view=console';

View File

@ -75,10 +75,10 @@ if ( $action == 'save' ) {
if ( $_REQUEST['newMonitor']['ServerId'] == 'auto' ) {
$_REQUEST['newMonitor']['ServerId'] = dbFetchOne(
'SELECT Id FROM Servers WHERE Status=\'Running\' ORDER BY FreeMem DESC, CpuLoad ASC LIMIT 1', 'Id');
ZM\Logger::Debug('Auto selecting server: Got ' . $_REQUEST['newMonitor']['ServerId']);
ZM\Debug('Auto selecting server: Got ' . $_REQUEST['newMonitor']['ServerId']);
if ( ( !$_REQUEST['newMonitor'] ) and defined('ZM_SERVER_ID') ) {
$_REQUEST['newMonitor']['ServerId'] = ZM_SERVER_ID;
ZM\Logger::Debug('Auto selecting server to ' . ZM_SERVER_ID);
ZM\Debug('Auto selecting server to ' . ZM_SERVER_ID);
}
}
@ -235,7 +235,7 @@ if ( $action == 'save' ) {
$restart = true;
} else {
ZM\Logger::Debug('No action due to no changes to Monitor');
ZM\Debug('No action due to no changes to Monitor');
} # end if count(changes)
if ( !$mid ) {

View File

@ -29,13 +29,13 @@ if ( $action ) {
$rc = 0;
exec('sudo -n '.ZM_PATH_SHUTDOWN." -P $when 2>&1", $output, $rc);
#exec('sudo -n /bin/systemctl poweroff -i 2>&1', $output, $rc);
ZM\Logger::Debug("Shutdown output $rc " . implode("\n",$output));
#ZM\Logger::Debug("Shutdown output " . shell_exec('/bin/systemctl poweroff -i 2>&1'));
ZM\Debug("Shutdown output $rc " . implode("\n",$output));
#ZM\Debug("Shutdown output " . shell_exec('/bin/systemctl poweroff -i 2>&1'));
} else if ( $action == 'restart' ) {
$output = array();
exec('sudo -n '.ZM_PATH_SHUTDOWN." -r $when 2>&1", $output);
#exec('sudo -n /bin/systemctl reboot -i 2>&1', $output);
ZM\Logger::Debug("Shutdown output " . implode("\n",$output));
ZM\Debug("Shutdown output " . implode("\n",$output));
} else if ( $action == 'cancel' ) {
$output = array();
exec('sudo '.ZM_PATH_SHUTDOWN.' -c 2>&1', $output);

View File

@ -72,12 +72,12 @@ function validateUser($username='', $password='') {
// We assume we don't need to support mysql < 4.1
// Starting MY SQL 4.1, mysql concats a '*' in front of its password hash
// https://blog.pythian.com/hashing-algorithm-in-mysql-password-2/
ZM\Logger::Debug('Saved password is using MYSQL password function');
ZM\Debug('Saved password is using MYSQL password function');
$input_password_hash = '*'.strtoupper(sha1(sha1($password, true)));
$password_correct = ($user['Password'] == $input_password_hash);
break;
case 'bcrypt' :
ZM\Logger::Debug('bcrypt signature found, assumed bcrypt password');
ZM\Debug('bcrypt signature found, assumed bcrypt password');
$password_correct = password_verify($password, $user['Password']);
break;
case 'mysql+bcrypt' :
@ -85,10 +85,10 @@ function validateUser($username='', $password='') {
// this is done so that we don't spend cycles doing two bcrypt password_verify calls
// for every wrong password entered. This will only be invoked for passwords zmupdate.pl has
// overlay hashed
ZM\Logger::Debug("Detected bcrypt overlay hashing for $username");
ZM\Debug("Detected bcrypt overlay hashing for $username");
$bcrypt_hash = substr($user['Password'], 4);
$mysql_encoded_password = '*'.strtoupper(sha1(sha1($password, true)));
ZM\Logger::Debug("Comparing password $mysql_encoded_password to bcrypt hash: $bcrypt_hash");
ZM\Debug("Comparing password $mysql_encoded_password to bcrypt hash: $bcrypt_hash");
$password_correct = password_verify($mysql_encoded_password, $bcrypt_hash);
break;
default:
@ -130,7 +130,7 @@ function validateToken($token, $allowed_token_type='access') {
return array(false, 'Incorrect token type');
}
} else {
ZM\Logger::Debug('Not comparing token types as [any] was passed');
ZM\Debug('Not comparing token types as [any] was passed');
}
$username = $jwt_payload['user'];
@ -210,7 +210,7 @@ function generateAuthHash($useRemoteAddr, $force=false) {
} else {
$authKey = ZM_AUTH_HASH_SECRET.$user['Username'].$user['Password'].$local_time[2].$local_time[3].$local_time[4].$local_time[5];
}
#ZM\Logger::Debug("Generated using hour:".$local_time[2] . ' mday:' . $local_time[3] . ' month:'.$local_time[4] . ' year: ' . $local_time[5] );
#ZM\Debug("Generated using hour:".$local_time[2] . ' mday:' . $local_time[3] . ' month:'.$local_time[4] . ' year: ' . $local_time[5] );
$auth = md5($authKey);
$_SESSION['AuthHash'.$_SESSION['remoteAddr']] = $auth;
$_SESSION['AuthHashGeneratedAt'] = $time;
@ -248,14 +248,14 @@ function userFromSession() {
if ( isset($_SESSION['AuthHash'.$_SESSION['remoteAddr']]) )
$user = getAuthUser($_SESSION['AuthHash'.$_SESSION['remoteAddr']]);
else
ZM\Logger::Debug("No auth hash in session, there should have been");
ZM\Debug("No auth hash in session, there should have been");
} else {
# Need to refresh permissions and validate that the user still exists
$sql = 'SELECT * FROM Users WHERE Enabled=1 AND Username=?';
$user = dbFetchOne($sql, NULL, array($_SESSION['username']));
}
} else {
ZM\Logger::Debug('No username in session');
ZM\Debug('No username in session');
}
return $user;
}

View File

@ -193,21 +193,21 @@ function csrf_check($fatal = true) {
$tokens = '';
do {
if (!isset($_POST[$name])) {
#Logger::Debug("POST[$name] is not set");
#Debug("POST[$name] is not set");
break;
#} else {
#Logger::Debug("POST[$name] is set as " . $_POST[$name] );
#Debug("POST[$name] is set as " . $_POST[$name] );
}
// we don't regenerate a token and check it because some token creation
// schemes are volatile.
$tokens = $_POST[$name];
if (!csrf_check_tokens($tokens)) {
#Logger::Debug("Failed checking tokens");
#Debug("Failed checking tokens");
break;
#} else {
#Logger::Debug("Token passed");
#Debug("Token passed");
}
$ok = true;
} while (false);
@ -296,7 +296,7 @@ function csrf_callback($tokens) {
// Don't make it too easy for users to inflict a CSRF attack on themselves.
echo "<p><strong>Only try again if you weren't sent to this page by someone as this is potentially a sign of an attack.</strong></p>";
echo "<form method='post' action=''>$data<input type='submit' value='Try again' /></form>";
ZM\Logger::Debug("Failed csrf check");
ZM\Debug("Failed csrf check");
}
echo "<p>Debug: $tokens</p></body></html>
";
@ -318,27 +318,27 @@ function csrf_check_tokens($tokens) {
* Checks if a token is valid.
*/
function csrf_check_token($token) {
#Logger::Debug("Checking CSRF token $token");
#Debug("Checking CSRF token $token");
if (strpos($token, ':') === false) {
#Logger::Debug("Checking CSRF token $token bad because no :");
#Debug("Checking CSRF token $token bad because no :");
return false;
}
list($type, $value) = explode(':', $token, 2);
if (strpos($value, ',') === false) {
#Logger::Debug("Checking CSRF token $token bad because no ,");
#Debug("Checking CSRF token $token bad because no ,");
return false;
}
list($x, $time) = explode(',', $token, 2);
if ($GLOBALS['csrf']['expires']) {
if (time() > $time + $GLOBALS['csrf']['expires']) {
#Logger::Debug("Checking CSRF token $token bad because expired");
#Debug("Checking CSRF token $token bad because expired");
return false;
}
}
switch ($type) {
case 'sid':
{
#Logger::Debug("Checking sid: $value === " . csrf_hash(session_id(), $time) );
#Debug("Checking sid: $value === " . csrf_hash(session_id(), $time) );
return $value === csrf_hash(session_id(), $time);
}
case 'cookie':
@ -348,10 +348,10 @@ return false;
return $value === csrf_hash($_COOKIE[$n], $time);
case 'key':
if (!$GLOBALS['csrf']['key']) {
Logger::Debug("Checking key: no key set" );
Debug("Checking key: no key set" );
return false;
}
#Logger::Debug("Checking sid: $value === " . csrf_hash($GLOBALS['csrf']['key'], $time) );
#Debug("Checking sid: $value === " . csrf_hash($GLOBALS['csrf']['key'], $time) );
return $value === csrf_hash($GLOBALS['csrf']['key'], $time);
// We could disable these 'weaker' checks if 'key' was set, but
// that doesn't make me feel good then about the cookie-based

View File

@ -105,7 +105,7 @@ function dbLog($sql, $update=false) {
global $dbLogLevel;
$noExecute = $update && ($dbLogLevel >= DB_LOG_DEBUG);
if ( $dbLogLevel > DB_LOG_OFF )
ZM\Logger::Debug( "SQL-LOG: $sql".($noExecute?' (not executed)':'') );
ZM\Debug( "SQL-LOG: $sql".($noExecute?' (not executed)':'') );
return( $noExecute );
}
@ -146,7 +146,7 @@ function dbQuery($sql, $params=NULL) {
}
} else {
if ( defined('ZM_DB_DEBUG') ) {
ZM\Logger::Debug("SQL: $sql values:" . ($params?implode(',',$params):''));
ZM\Debug("SQL: $sql values:" . ($params?implode(',',$params):''));
}
$result = $dbConn->query($sql);
if ( ! $result ) {
@ -155,7 +155,7 @@ function dbQuery($sql, $params=NULL) {
}
}
if ( defined('ZM_DB_DEBUG') ) {
ZM\Logger::Debug('SQL: '.$sql.' '.($params?implode(',',$params):'').' rows: '.$result->rowCount());
ZM\Debug('SQL: '.$sql.' '.($params?implode(',',$params):'').' rows: '.$result->rowCount());
}
} catch(PDOException $e) {
ZM\Error("SQL-ERR '".$e->getMessage()."', statement was '".$sql."' params:" . ($params?implode(',',$params):''));

View File

@ -104,7 +104,7 @@ function CORSHeaders() {
# Only need CORSHeaders in the event that there are multiple servers in use.
# ICON: Might not be true. multi-port?
if ( ZM_MIN_STREAMING_PORT ) {
ZM\Logger::Debug('Setting default Access-Control-Allow-Origin from ' . $_SERVER['HTTP_ORIGIN']);
ZM\Debug('Setting default Access-Control-Allow-Origin from ' . $_SERVER['HTTP_ORIGIN']);
header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
header('Access-Control-Allow-Headers: x-requested-with,x-request');
}
@ -117,7 +117,7 @@ function CORSHeaders() {
preg_match('/^(https?:\/\/)?'.preg_quote($Server->Name(),'/').'/i', $_SERVER['HTTP_ORIGIN'])
) {
$valid = true;
ZM\Logger::Debug('Setting Access-Control-Allow-Origin from '.$_SERVER['HTTP_ORIGIN']);
ZM\Debug('Setting Access-Control-Allow-Origin from '.$_SERVER['HTTP_ORIGIN']);
header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
header('Access-Control-Allow-Headers: x-requested-with,x-request');
break;
@ -392,7 +392,7 @@ function getEventDefaultVideoPath($event) {
}
function deletePath( $path ) {
ZM\Logger::Debug('Deleting '.$path);
ZM\Debug('Deleting '.$path);
if ( is_dir($path) ) {
system(escapeshellcmd('rm -rf '.$path));
} else if ( file_exists($path) ) {
@ -791,7 +791,7 @@ function daemonControl($command, $daemon=false, $args=false) {
}
$string = escapeshellcmd($string);
#$string .= ' 2>/dev/null >&- <&- >/dev/null';
ZM\Logger::Debug('daemonControl '.$string);
ZM\Debug('daemonControl '.$string);
exec($string);
}
@ -932,7 +932,7 @@ function createVideo($event, $format, $rate, $scale, $overwrite=false) {
$command .= ' -o';
$command = escapeshellcmd($command);
$result = exec($command, $output, $status);
ZM\Logger::Debug("generating Video $command: result($result outptu:(".implode("\n", $output )." status($status");
ZM\Debug("generating Video $command: result($result outptu:(".implode("\n", $output )." status($status");
return $status ? '' : rtrim($result);
}
@ -1635,17 +1635,17 @@ function coordsToPoints($coords) {
function limitPoints(&$points, $min_x, $min_y, $max_x, $max_y) {
foreach ( $points as &$point ) {
if ( $point['x'] < $min_x ) {
ZM\Logger::Debug('Limiting point x'.$point['x'].' to min_x '.$min_x);
ZM\Debug('Limiting point x'.$point['x'].' to min_x '.$min_x);
$point['x'] = $min_x;
} else if ( $point['x'] > $max_x ) {
ZM\Logger::Debug('Limiting point x'.$point['x'].' to max_x '.$max_x);
ZM\Debug('Limiting point x'.$point['x'].' to max_x '.$max_x);
$point['x'] = $max_x;
}
if ( $point['y'] < $min_y ) {
ZM\Logger::Debug('Limiting point y'.$point['y'].' to min_y '.$min_y);
ZM\Debug('Limiting point y'.$point['y'].' to min_y '.$min_y);
$point['y'] = $min_y;
} else if ( $point['y'] > $max_y ) {
ZM\Logger::Debug('Limiting point y'.$point['y'].' to max_y '.$max_y);
ZM\Debug('Limiting point y'.$point['y'].' to max_y '.$max_y);
$point['y'] = $max_y;
}
} // end foreach point
@ -2170,7 +2170,7 @@ function check_timezone() {
'TIME_FORMAT(TIMEDIFF(NOW(), UTC_TIMESTAMP),\'%H%i\')'
));
#Logger::Debug("System timezone offset determine to be: $sys_tzoffset,\x20
#Debug("System timezone offset determine to be: $sys_tzoffset,\x20
#PHP timezone offset determine to be: $php_tzoffset,\x20
#Mysql timezone offset determine to be: $mysql_tzoffset
#");

View File

@ -158,7 +158,7 @@ class Logger {
$this->initialised = true;
//Logger::Debug( "LogOpts: level=".self::$codes[$this->level]."/".self::$codes[$this->effectiveLevel].", screen=".self::$codes[$this->termLevel].", database=".self::$codes[$this->databaseLevel].", logfile=".self::$codes[$this->fileLevel]."->".$this->logFile.", weblog=".self::$codes[$this->weblogLevel].", syslog=".self::$codes[$this->syslogLevel] );
//Debug( "LogOpts: level=".self::$codes[$this->level]."/".self::$codes[$this->effectiveLevel].", screen=".self::$codes[$this->termLevel].", database=".self::$codes[$this->databaseLevel].", logfile=".self::$codes[$this->fileLevel]."->".$this->logFile.", weblog=".self::$codes[$this->weblogLevel].", syslog=".self::$codes[$this->syslogLevel] );
}
private function terminate() {
@ -199,9 +199,6 @@ class Logger {
return self::$instance;
}
public static function Debug( $string ) {
Logger::fetch()->logPrint( Logger::DEBUG, $string );
}
public function id( $id=NULL ) {
if ( isset($id) && $this->id != $id ) {
@ -459,6 +456,10 @@ function Dump( &$var, $label='VAR' ) {
Logger::fetch()->logPrint( Logger::DEBUG, ob_get_clean() );
}
function Debug( $string ) {
Logger::fetch()->logPrint( Logger::DEBUG, $string );
}
function Info( $string ) {
Logger::fetch()->logPrint( Logger::INFO, $string );
}

View File

@ -25,7 +25,7 @@ function zm_session_start() {
}
ini_set('session.name', 'ZMSESSID');
ZM\Logger::Debug('Setting cookie parameters to '.print_r($currentCookieParams, true));
ZM\Debug('Setting cookie parameters to '.print_r($currentCookieParams, true));
}
session_start();
$_SESSION['remoteAddr'] = $_SERVER['REMOTE_ADDR']; // To help prevent session hijacking
@ -37,7 +37,7 @@ function zm_session_start() {
session_start();
} else if ( !empty($_SESSION['generated_at']) ) {
if ( $_SESSION['generated_at']<($now-(ZM_COOKIE_LIFETIME/2)) ) {
ZM\Logger::Debug('Regenerating session because generated_at ' . $_SESSION['generated_at'] . ' < ' . $now . '-'.ZM_COOKIE_LIFETIME.'/2 = '.($now-ZM_COOKIE_LIFETIME/2));
ZM\Debug('Regenerating session because generated_at ' . $_SESSION['generated_at'] . ' < ' . $now . '-'.ZM_COOKIE_LIFETIME.'/2 = '.($now-ZM_COOKIE_LIFETIME/2));
zm_session_regenerate_id();
}
}

View File

@ -56,7 +56,7 @@ require_once('includes/Monitor.php');
if ( 0 and ZM\Logger::fetch()->debugOn() ) {
ob_start();
phpinfo(INFO_VARIABLES);
ZM\Logger::Debug(ob_get_contents());
ZM\Debug(ob_get_contents());
ob_end_clean();
}
@ -82,7 +82,7 @@ define('ZM_BASE_URL', '');
require_once('includes/functions.php');
if ( $_SERVER['REQUEST_METHOD'] == 'OPTIONS' ) {
ZM\Logger::Debug('OPTIONS Method, only doing CORS');
ZM\Debug('OPTIONS Method, only doing CORS');
# Add Cross domain access headers
CORSHeaders();
return;
@ -221,7 +221,7 @@ if ( (!$view and !$request) or ($view == 'console') ) {
check_timezone();
}
ZM\Logger::Debug("View: $view Request: $request Action: $action User: " . ( isset($user) ? $user['Username'] : 'none' ));
ZM\Debug("View: $view Request: $request Action: $action User: " . ( isset($user) ? $user['Username'] : 'none' ));
if (
ZM_ENABLE_CSRF_MAGIC &&
( $action != 'login' ) &&
@ -232,14 +232,14 @@ if (
( $view != 'archive' ) // returns data
) {
require_once('includes/csrf/csrf-magic.php');
#ZM\Logger::Debug("Calling csrf_check with the following values: \$request = \"$request\", \$view = \"$view\", \$action = \"$action\"");
#ZM\Debug("Calling csrf_check with the following values: \$request = \"$request\", \$view = \"$view\", \$action = \"$action\"");
csrf_check();
}
# Need to include actions because it does auth
if ( $action and !$request ) {
if ( file_exists('includes/actions/'.$view.'.php') ) {
ZM\Logger::Debug("Including includes/actions/$view.php");
ZM\Debug("Including includes/actions/$view.php");
require_once('includes/actions/'.$view.'.php');
} else {
ZM\Warning("No includes/actions/$view.php for action $action");
@ -254,7 +254,7 @@ if ( ZM_OPT_USE_AUTH and (!isset($user)) and ($view != 'login') and ($view != 'n
header('HTTP/1.1 401 Unauthorized');
exit;
}
ZM\Logger::Debug('Redirecting to login');
ZM\Debug('Redirecting to login');
$view = 'none';
$redirect = ZM_BASE_URL.$_SERVER['PHP_SELF'].'?view=login';
if ( ! $request ) {
@ -271,7 +271,7 @@ if ( ZM_OPT_USE_AUTH and (!isset($user)) and ($view != 'login') and ($view != 'n
if ( $redirect ) {
ZM\Logger::Debug("Redirecting to $redirect");
ZM\Debug("Redirecting to $redirect");
header('Location: '.$redirect);
return;
}

View File

@ -897,7 +897,7 @@ function exportEvents(
ZM\Error("Can't create exports dir at '$export_dir'");
return false;
}
ZM\Logger::Debug("Successfully created dir '$export_dir'");
ZM\Debug("Successfully created dir '$export_dir'");
chmod($export_dir, 0700);
if ( !chdir($export_dir) ) {
ZM\Error("Can't chdir to $export_dir");
@ -925,7 +925,7 @@ function exportEvents(
#continue;
$cmd = 'cp -as '.$event->Path().'/'.$file.' '.$export_dir.'/'.$event->Id().'/'.$file. ' 2>&1';
exec($cmd, $output, $return);
ZM\Logger::Debug($cmd.' return code: '.$return.' output: '.print_r($output,true));
ZM\Debug($cmd.' return code: '.$return.' output: '.print_r($output,true));
} # end foreach event_exportFile
} # end foreach event

View File

@ -122,7 +122,7 @@ if ( isset($_COOKIE['zmCycleHeight']) and $_COOKIE['zmCycleHeight'] ) {
session_write_close();
ZM\Logger::Debug(print_r($options,true));
ZM\Debug(print_r($options,true));
noCacheHeaders();
xhtmlHeaders(__FILE__, translate('CycleWatch'));

View File

@ -42,7 +42,7 @@ if ( isset($_REQUEST['filter'])) {
parseSort();
$filterQuery = $filter->querystring();
ZM\Logger::Debug('Filter '.print_r($filter, true));
ZM\Debug('Filter '.print_r($filter, true));
if ( $filter->sql() ) {
$eventsSql .= ' AND ('.$filter->sql().')';
@ -58,14 +58,14 @@ $limit = isset($_REQUEST['limit']) ? validInt($_REQUEST['limit']) : $filter['lim
if ( $_POST ) {
// I think this is basically so that a refresh doesn't repost
ZM\Logger::Debug('Redirecting to ' . $_SERVER['REQUEST_URI']);
ZM\Debug('Redirecting to ' . $_SERVER['REQUEST_URI']);
header('Location: ?view=' . $view.htmlspecialchars_decode($filterQuery).htmlspecialchars_decode($sortQuery).$limitQuery.'&page='.$page);
exit();
}
$failed = !$filter->test_pre_sql_conditions();
if ( $failed ) {
ZM\Logger::Debug('Pre conditions failed, not doing sql');
ZM\Debug('Pre conditions failed, not doing sql');
}
$results = $failed ? null : dbQuery($eventsSql);
@ -75,13 +75,13 @@ if ( ! $results ) {
global $error_message;
$error_message = dbError($eventsSql);
}
ZM\Logger::Debug("Pre conditions succeeded sql return $nEvents events");
ZM\Debug("Pre conditions succeeded sql return $nEvents events");
if ( !empty($limit) && ($nEvents > $limit) ) {
$nEvents = $limit;
}
$pages = (int)ceil($nEvents/ZM_WEB_EVENTS_PER_PAGE);
#Logger::Debug("Page $page Limit $limit #vents: $nEvents pages: $pages ");
#Debug("Page $page Limit $limit #vents: $nEvents pages: $pages ");
if ( !empty($page) ) {
if ( $page < 0 )
$page = 1;
@ -212,7 +212,7 @@ if ( $results ) {
if ( $limit and (count($events) >= $limit) ) {
break;
}
ZM\Logger::Debug("Have " . count($events) . " events, limit $limit");
ZM\Debug("Have " . count($events) . " events, limit $limit");
}
foreach ( $events as $event ) {

View File

@ -61,7 +61,7 @@ if ( !$filter ) {
$filter->set($_REQUEST['filter']);
}
} else {
ZM\Logger::Debug('filter: ' . print_r($filter,true));
ZM\Debug('filter: ' . print_r($filter,true));
}
$conjunctionTypes = ZM\getFilterQueryConjunctionTypes();

View File

@ -79,7 +79,7 @@ if ( $layout_id and is_numeric($layout_id) and isset($layoutsById[$layout_id]) )
$Layout = $layoutsById[$layout_id];
$Positions = json_decode($Layout->Positions(), true);
} else {
ZM\Logger::Debug('Layout not found');
ZM\Debug('Layout not found');
}
if ( $Layout and ( $Layout->Name() != 'Freeform' ) ) {
// Use layout instead of other options

View File

@ -42,7 +42,7 @@ function execONVIF($cmd) {
$shell_command"
);
} else {
ZM\Logger::Debug('Results from probe: '.implode('<br/>', $output));
ZM\Debug('Results from probe: '.implode('<br/>', $output));
}
return $output;
@ -80,7 +80,7 @@ function probeCameras($localIp) {
$camera['monitor']['Notes'] .= $tokens[1].'='.$tokens[2]."\n";
// $camera['location'] = $tokens[2];
} else {
ZM\Logger::Debug('Unknown token '.$tokens[1].' = '.$tokens[2]);
ZM\Debug('Unknown token '.$tokens[1].' = '.$tokens[2]);
}
}
} // end foreach token
@ -119,7 +119,7 @@ function probeProfiles($device_ep, $soapversion, $username, $password) {
);
$profiles[] = $profile;
} else {
ZM\Logger::Debug("Line did not match preg: $line");
ZM\Debug("Line did not match preg: $line");
}
} // end foreach line
} // end if results from execONVIF
@ -187,7 +187,7 @@ if ( !isset($_REQUEST['step']) || ($_REQUEST['step'] == '1') ) {
if ( $matches[1] != 'lo' ) {
$interfaces[$matches[1]] = $matches[1];
} else {
ZM\Logger::Debug("No match for $line");
ZM\Debug("No match for $line");
}
}
}
@ -247,7 +247,7 @@ if ( !isset($_REQUEST['step']) || ($_REQUEST['step'] == '1') ) {
#empty($_REQUEST['password']) )
$probe = json_decode(base64_decode($_REQUEST['probe']));
ZM\Logger::Debug(print_r($probe, true));
ZM\Debug(print_r($probe, true));
foreach ( $probe as $name=>$value ) {
if ( isset($value) ) {
$monitor[$name] = $value;

View File

@ -156,7 +156,7 @@ foreach ( array_map('basename', glob('skins/'.$skin.'/css/*', GLOB_ONLYDIR)) as
$userMonitors[] = $monitors[$monitorId]['Name'];
}
}
ZM\Logger::Debug("monitors: ".$user_row['Username'] . ' ' . $user_row['MonitorIds']. ' :' . print_r($userMonitors, true));
ZM\Debug("monitors: ".$user_row['Username'] . ' ' . $user_row['MonitorIds']. ' :' . print_r($userMonitors, true));
?>
<tr>
<td class="colUsername"><?php echo makeLink('?view=user&amp;uid='.$user_row['Id'], validHtmlStr($user_row['Username']).($user['Username']==$user_row['Username']?'*':''), $canEdit) ?></td>

View File

@ -62,7 +62,7 @@ if ( count($selected_monitor_ids) ) {
}
parseFilter($filter);
$filterQuery = $filter['query'];
ZM\Logger::Debug($filterQuery);
ZM\Debug($filterQuery);
$eventsSql = 'SELECT *,
UNIX_TIMESTAMP(E.StartTime) AS StartTimeSecs,
@ -94,7 +94,7 @@ while ( $event = $result->fetch(PDO::FETCH_ASSOC) ) {
if ( count($EventsByMonitor[$event['MonitorId']]['Events']) ) {
$last_event = end($EventsByMonitor[$event['MonitorId']]['Events']);
#Logger::Debug(print_r($last_event,true));
#Debug(print_r($last_event,true));
$gap = $last_event->EndTimeSecs() - $event['StartTimeSecs'];
if ( $gap < $EventsByMonitor[$event['MonitorId']]['MinGap'] )

View File

@ -500,7 +500,7 @@ for ( $i = 0; $i < $chart['graph']['width']; $i++ ) {
} # end foreach MonitorId
} # end foreach x
//ZM\Logger::Debug(print_r( $monEventSlots,true ));
//ZM\Debug(print_r( $monEventSlots,true ));
//print_r( $monFrameSlots );
//print_r( $chart );

View File

@ -55,7 +55,7 @@ if ( !$mimetype ) {
$connkey = isset($_REQUEST['connkey'])?$_REQUEST['connkey']:'';
$filename = "zmExport_$connkey.$file_ext";
$filename_path = ZM_DIR_EXPORTS.'/'.$filename;
ZM\Logger::Debug("downloading archive from $filename_path");
ZM\Debug("downloading archive from $filename_path");
if ( is_readable($filename_path) ) {
while (ob_get_level()) {
ob_end_clean();

View File

@ -87,11 +87,11 @@ if ( empty($_REQUEST['path']) ) {
if (file_exists($path_anim_gif)) {
// we found the animation gif file
$media_type = 'image/gif';
ZM\Logger::Debug("Animation file found at $path");
ZM\Debug("Animation file found at $path");
$path = $path_anim_gif;
} else if (file_exists($path_image)) {
// animation not found, but image found
ZM\Logger::Debug("Image file found at $path");
ZM\Debug("Image file found at $path");
$path = $path_image;
} else {
// neither animation nor image found
@ -206,14 +206,14 @@ if ( empty($_REQUEST['path']) ) {
$percentage = ($Frame->FrameId() - $previousBulkFrame['FrameId']) / ($nextBulkFrame['FrameId'] - $previousBulkFrame['FrameId']);
$Frame->Delta($previousBulkFrame['Delta'] + floor( 100* ( $nextBulkFrame['Delta'] - $previousBulkFrame['Delta'] ) * $percentage )/100);
ZM\Logger::Debug("Got virtual frame from Bulk Frames previous delta: " . $previousBulkFrame['Delta'] . " + nextdelta:" . $nextBulkFrame['Delta'] . ' - ' . $previousBulkFrame['Delta'] . ' * ' . $percentage );
ZM\Debug("Got virtual frame from Bulk Frames previous delta: " . $previousBulkFrame['Delta'] . " + nextdelta:" . $nextBulkFrame['Delta'] . ' - ' . $previousBulkFrame['Delta'] . ' * ' . $percentage );
} else {
ZM\Fatal('No Frame found for event('.$_REQUEST['eid'].') and frame id('.$_REQUEST['fid'].')');
}
}
// Frame can be non-existent. We have Bulk frames. So now we should try to load the bulk frame
$path = $Event->Path().'/'.sprintf('%0'.ZM_EVENT_IMAGE_DIGITS.'d',$Frame->FrameId()).'-'.$show.'.jpg';
ZM\Logger::Debug("Path: $path");
ZM\Debug("Path: $path");
}
} else {
@ -235,7 +235,7 @@ if ( empty($_REQUEST['path']) ) {
} # end if have eid
if ( !file_exists($path) ) {
ZM\Logger::Debug("$path does not exist");
ZM\Debug("$path does not exist");
# Generate the frame JPG
if ( ($show == 'capture') and $Event->DefaultVideo() ) {
if ( !file_exists($Event->Path().'/'.$Event->DefaultVideo()) ) {
@ -245,11 +245,11 @@ if ( empty($_REQUEST['path']) ) {
$command = ZM_PATH_FFMPEG.' -ss '. $Frame->Delta() .' -i '.$Event->Path().'/'.$Event->DefaultVideo().' -frames:v 1 '.$path;
#$command ='ffmpeg -ss '. $Frame->Delta() .' -i '.$Event->Path().'/'.$Event->DefaultVideo().' -vf "select=gte(n\\,'.$Frame->FrameId().'),setpts=PTS-STARTPTS" '.$path;
#$command ='ffmpeg -v 0 -i '.$Storage->Path().'/'.$Event->Path().'/'.$Event->DefaultVideo().' -vf "select=gte(n\\,'.$Frame->FrameId().'),setpts=PTS-STARTPTS" '.$path;
ZM\Logger::Debug("Running $command");
ZM\Debug("Running $command");
$output = array();
$retval = 0;
exec( $command, $output, $retval );
ZM\Logger::Debug("Command: $command, retval: $retval, output: " . implode("\n", $output));
ZM\Debug("Command: $command, retval: $retval, output: " . implode("\n", $output));
if ( ! file_exists( $path ) ) {
header('HTTP/1.0 404 Not Found');
ZM\Fatal('Can\'t create frame images from video for this event '.$Event->DefaultVideo() );
@ -334,7 +334,7 @@ if ( $errorText ) {
ZM\Error('No bytes read from '. $path);
}
} else {
ZM\Logger::Debug("Doing a scaled image: scale($scale) width($width) height($height)");
ZM\Debug("Doing a scaled image: scale($scale) width($width) height($height)");
$i = 0;
if ( ! ( $width && $height ) ) {
$i = imagecreatefromjpeg($path);
@ -347,7 +347,7 @@ if ( $errorText ) {
$width = ($height * $oldWidth) / $oldHeight;
} elseif ( $width != 0 && $height == 0 ) {
$height = ($width * $oldHeight) / $oldWidth;
ZM\Logger::Debug("Figuring out height using width: $height = ($width * $oldHeight) / $oldWidth");
ZM\Debug("Figuring out height using width: $height = ($width * $oldHeight) / $oldWidth");
}
if ( $width == $oldWidth && $height == $oldHeight ) {
ZM\Warning('No change to width despite scaling.');
@ -361,7 +361,7 @@ ZM\Logger::Debug("Figuring out height using width: $height = ($width * $oldHeigh
header('Content-Disposition: inline; filename="' . $filename . '"');
}
if ( !( file_exists($scaled_path) and readfile($scaled_path) ) ) {
ZM\Logger::Debug("Cached scaled image does not exist at $scaled_path or is no good.. Creating it");
ZM\Debug("Cached scaled image does not exist at $scaled_path or is no good.. Creating it");
ob_start();
if ( !$i )
$i = imagecreatefromjpeg($path);
@ -373,12 +373,12 @@ ZM\Logger::Debug("Figuring out height using width: $height = ($width * $oldHeigh
file_put_contents($scaled_path, $scaled_jpeg_data);
echo $scaled_jpeg_data;
} else {
ZM\Logger::Debug("Sending $scaled_path");
ZM\Debug("Sending $scaled_path");
$bytes = readfile($scaled_path);
if ( !$bytes ) {
ZM\Error('No bytes read from '. $scaled_path);
} else {
ZM\Logger::Debug("$bytes sent");
ZM\Debug("$bytes sent");
}
}
}

View File

@ -66,14 +66,14 @@ $end = $size-1;
$length = $size;
if ( isset($_SERVER['HTTP_RANGE']) ) {
ZM\Logger::Debug('Using Range '.$_SERVER['HTTP_RANGE']);
ZM\Debug('Using Range '.$_SERVER['HTTP_RANGE']);
if ( preg_match('/bytes=\h*(\d+)-(\d*)[\D.*]?/i', $_SERVER['HTTP_RANGE'], $matches) ) {
$begin = intval($matches[1]);
if ( !empty($matches[2]) ) {
$end = intval($matches[2]);
}
$length = $end - $begin + 1;
ZM\Logger::Debug("Using Range $begin $end size: $size, length: $length");
ZM\Debug("Using Range $begin $end size: $size, length: $length");
}
} # end if HTTP_RANGE