From c125d22d4d6677ecfdbbaaed0f1f7cf0f6aae9d0 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 18 May 2017 12:49:59 -0400 Subject: [PATCH] Fix Debug to Logger::Debug --- web/includes/Event.php | 4 ++-- web/includes/csrf/csrf-magic.php | 22 +++++++++++----------- web/includes/database.php | 2 +- web/includes/functions.php | 20 ++++++++++---------- web/views/image.php | 29 +++++++++++++++-------------- web/views/view_video.php | 5 +++-- 6 files changed, 42 insertions(+), 40 deletions(-) diff --git a/web/includes/Event.php b/web/includes/Event.php index 96d511f81..0e072fb33 100644 --- a/web/includes/Event.php +++ b/web/includes/Event.php @@ -221,11 +221,11 @@ class Event { #$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; - Debug( "Running $command" ); + Logger::Debug( "Running $command" ); $output = array(); $retval = 0; exec( $command, $output, $retval ); - Debug("Retval: $retval, output: " . implode("\n", $output)); + Logger::Debug("Retval: $retval, output: " . implode("\n", $output)); } else { Error("Can't create frame images from video becuase there is no video file for this event (".$Event->DefaultVideo() ); } diff --git a/web/includes/csrf/csrf-magic.php b/web/includes/csrf/csrf-magic.php index c4d1b7f8e..afdfd7bd6 100644 --- a/web/includes/csrf/csrf-magic.php +++ b/web/includes/csrf/csrf-magic.php @@ -189,21 +189,21 @@ function csrf_check($fatal = true) { $tokens = ''; do { if (!isset($_POST[$name])) { -Debug("POST[$name] is not set"); +Logger::Debug("POST[$name] is not set"); break; } else { -Debug("POST[$name] is set as " . $_POST[$name] ); +Logger::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)) { -Debug("Failed checking tokens"); +Logger::Debug("Failed checking tokens"); break; } else { -Debug("Token passed"); +Logger::Debug("Token passed"); } $ok = true; } while (false); @@ -308,27 +308,27 @@ function csrf_check_tokens($tokens) { * Checks if a token is valid. */ function csrf_check_token($token) { -Debug("Checking CSRF token $token"); +Logger::Debug("Checking CSRF token $token"); if (strpos($token, ':') === false) { -Debug("Checking CSRF token $token bad because no :"); +Logger::Debug("Checking CSRF token $token bad because no :"); return false; } list($type, $value) = explode(':', $token, 2); if (strpos($value, ',') === false) { -Debug("Checking CSRF token $token bad because no ,"); +Logger::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']) { -Debug("Checking CSRF token $token bad because expired"); +Logger::Debug("Checking CSRF token $token bad because expired"); return false; } } switch ($type) { case 'sid': { - Debug("Checking sid: $value === " . csrf_hash(session_id(), $time) ); + Logger::Debug("Checking sid: $value === " . csrf_hash(session_id(), $time) ); return $value === csrf_hash(session_id(), $time); } case 'cookie': @@ -338,10 +338,10 @@ return false; return $value === csrf_hash($_COOKIE[$n], $time); case 'key': if (!$GLOBALS['csrf']['key']) { - Debug("Checking key: no key set" ); + Logger::Debug("Checking key: no key set" ); return false; } - Debug("Checking sid: $value === " . csrf_hash($GLOBALS['csrf']['key'], $time) ); + Logger::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 diff --git a/web/includes/database.php b/web/includes/database.php index 40cd8950b..dea9e4b8c 100644 --- a/web/includes/database.php +++ b/web/includes/database.php @@ -81,7 +81,7 @@ function dbLog( $sql, $update=false ) { global $dbLogLevel; $noExecute = $update && ($dbLogLevel >= DB_LOG_DEBUG); if ( $dbLogLevel > DB_LOG_OFF ) - Debug( "SQL-LOG: $sql".($noExecute?" (not executed)":"") ); + Logger::Debug( "SQL-LOG: $sql".($noExecute?" (not executed)":"") ); return( $noExecute ); } diff --git a/web/includes/functions.php b/web/includes/functions.php index 732da9bdb..8791c2dc5 100644 --- a/web/includes/functions.php +++ b/web/includes/functions.php @@ -161,9 +161,9 @@ function generateAuthHash( $useRemoteAddr ) { } $_SESSION['AuthHash'] = $auth; $_SESSION['AuthHashGeneratedAt'] = time(); - Debug("Generated new auth $auth at " . $_SESSION['AuthHashGeneratedAt']. " using $authKey" ); + Logger::Debug("Generated new auth $auth at " . $_SESSION['AuthHashGeneratedAt']. " using $authKey" ); } else { - Debug( "Using cached auth " . $_SESSION['AuthHash'] ); + Logger::Debug( "Using cached auth " . $_SESSION['AuthHash'] ); } # end if AuthHash is not cached return $_SESSION['AuthHash']; } else { @@ -472,10 +472,10 @@ function getEventDefaultVideoPath( $event ) { function deletePath( $path ) { if ( is_dir( $path ) ) { -Debug("deletePath rm -rf $path"); +Logger::Debug("deletePath rm -rf $path"); system( escapeshellcmd( "rm -rf ".$path ) ); } else { -Debug("deletePath unlink $path"); +Logger::Debug("deletePath unlink $path"); unlink( $path ); } } @@ -491,7 +491,7 @@ function deleteEvent( $event ) { # $event could be an eid, so turn it into an event hash $event = new Event( $event ); } else { -Debug("Event type: " . gettype($event)); +Logger::Debug("Event type: " . gettype($event)); } global $user; @@ -1036,7 +1036,7 @@ function createVideo( $event, $format, $rate, $scale, $overwrite=false ) { $command .= " -o"; $command = escapeshellcmd( $command ); $result = exec( $command, $output, $status ); -Debug("generating Video $command: result($result outptu:(".implode("\n", $output )." status($status"); +Logger::Debug("generating Video $command: result($result outptu:(".implode("\n", $output )." status($status"); return( $status?"":rtrim($result) ); } @@ -1751,17 +1751,17 @@ function coordsToPoints( $coords ) { function limitPoints( &$points, $min_x, $min_y, $max_x, $max_y ) { foreach ( $points as &$point ) { if ( $point['x'] < $min_x ) { - Debug('Limiting point x'.$point['x'].' to min_x ' . $min_x ); + Logger::Debug('Limiting point x'.$point['x'].' to min_x ' . $min_x ); $point['x'] = $min_x; } else if ( $point['x'] > $max_x ) { - Debug('Limiting point x'.$point['x'].' to max_x ' . $max_x ); + Logger::Debug('Limiting point x'.$point['x'].' to max_x ' . $max_x ); $point['x'] = $max_x; } if ( $point['y'] < $min_y ) { - Debug('Limiting point y'.$point['y'].' to min_y ' . $min_y ); + Logger::Debug('Limiting point y'.$point['y'].' to min_y ' . $min_y ); $point['y'] = $min_y; } else if ( $point['y'] > $max_y ) { - Debug('Limiting point y'.$point['y'].' to max_y ' . $max_y ); + Logger::Debug('Limiting point y'.$point['y'].' to max_y ' . $max_y ); $point['y'] = $max_y; } } // end foreach point diff --git a/web/views/image.php b/web/views/image.php index 7bc40a1c1..300f3a9bc 100644 --- a/web/views/image.php +++ b/web/views/image.php @@ -33,8 +33,8 @@ // if ( !canView( 'Events' ) ) { - $view = 'error'; - return; + $view = 'error'; + return; } require_once('includes/Event.php'); require_once('includes/Frame.php'); @@ -82,36 +82,37 @@ if ( empty($_REQUEST['path']) ) { } if ( ! file_exists( $path ) ) { -Debug( "$path does not exist"); + Logger::Debug( "$path does not exist"); # Generate the frame JPG if ( $show == 'capture' and $Event->DefaultVideo() ) { $command ='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; - Debug( "Running $command" ); + Logger::Debug( "Running $command" ); $output = array(); $retval = 0; exec( $command, $output, $retval ); - Debug("Retval: $retval, output: " . implode("\n", $output)); + Logger::Debug("Retval: $retval, output: " . implode("\n", $output)); if ( ! file_exists( $path ) ) { - header("HTTP/1.0 404 Not Found"); + header('HTTP/1.0 404 Not Found'); Fatal("Can't create frame images from video for this event (".$Event->DefaultVideo() ); } } else { - header("HTTP/1.0 404 Not Found"); + header('HTTP/1.0 404 Not Found'); Fatal("Can't create frame images from video becuase there is no video file for this event (".$Event->DefaultVideo() ); } } } else { + Warning('Loading images by path is deprecated'); $dir_events = realpath(ZM_DIR_EVENTS); $path = realpath($dir_events . '/' . $_REQUEST['path']); $pos = strpos($path, $dir_events); - if($pos == 0 && $pos !== false) { - if ( !empty($user['MonitorIds']) ) { + if ( $pos == 0 && $pos !== false ) { + if ( ! empty( $user['MonitorIds'] ) ) { $imageOk = false; - $pathMonId = substr( $path, 0, strspn( $path, "1234567890" ) ); + $pathMonId = substr( $path, 0, strspn( $path, '1234567890' ) ); foreach ( preg_split( '/["\'\s]*,["\'\s]*/', $user['MonitorIds'] ) as $monId ) { if ( $pathMonId == $monId ) { $imageOk = true; @@ -119,10 +120,10 @@ Debug( "$path does not exist"); } } if ( !$imageOk ) - $errorText = "No image permissions"; + $errorText = 'No image permissions'; } } else { - $errorText = "Invalid image path"; + $errorText = 'Invalid image path'; } if ( ! file_exists( $path ) ) { header('HTTP/1.0 404 Not Found'); @@ -174,7 +175,7 @@ if ( $errorText ) { Error("No bytes read from ". $path ); } } else { - Debug("Doing a scaled image: scale($scale) width($width) height($height)"); + Logger::Debug("Doing a scaled image: scale($scale) width($width) height($height)"); $i = 0; if ( ! ( $width && $height ) ) { $i = imagecreatefromjpeg( $path ); @@ -196,7 +197,7 @@ if ( $errorText ) { # Slight optimisation, thumbnails always specify width and height, so we can cache them. $scaled_path = preg_replace('/\.jpg$/', "-${width}x${height}.jpg", $path ); if ( ! file_exists( $scaled_path ) or ! readfile( $scaled_path ) ) { - Debug( "Cached scaled image does not exist at $scaled_path or is no good.. Creating it"); + Logger::Debug( "Cached scaled image does not exist at $scaled_path or is no good.. Creating it"); ob_start(); if ( ! $i ) $i = imagecreatefromjpeg( $path ); diff --git a/web/views/view_video.php b/web/views/view_video.php index 64c75928e..f468a42f9 100644 --- a/web/views/view_video.php +++ b/web/views/view_video.php @@ -82,7 +82,7 @@ header('Content-Length: '.$length); if ( $Event ) { header('Content-Disposition: inline; filename="' . $Event->DefaultVideo() . '"'); } else { - header("Content-Disposition: inline;"); + header('Content-Disposition: inline;'); } if ( $begin > 0 || $end < $size-1 ) { header('HTTP/1.0 206 Partial Content'); @@ -105,7 +105,8 @@ while( $length && ( ! feof( $fh ) ) && ( connection_status() == 0 ) ) { print fread( $fh, $amount ); $length -= $amount; - usleep(100); + # Why introduce a speed limit? + #usleep(100); flush(); }