From 2024df43931754b5b2088f91074f98ac26b5c933 Mon Sep 17 00:00:00 2001
From: Isaac Connor
Date: Wed, 24 Oct 2018 09:49:56 -0400
Subject: [PATCH] use json_encode/decode instead of serialize/unserialize to
pass onvif probe results around. Also clean up some code/ add some missing
things. Fixes #2271 and #2272
---
web/lang/en_gb.php | 1 +
web/skins/classic/views/monitor.php | 2 +-
web/skins/classic/views/onvifprobe.php | 118 ++++++++++++-------------
3 files changed, 60 insertions(+), 61 deletions(-)
diff --git a/web/lang/en_gb.php b/web/lang/en_gb.php
index 0fca2f81d4..5412b94cd3 100644
--- a/web/lang/en_gb.php
+++ b/web/lang/en_gb.php
@@ -237,6 +237,7 @@
'Cause' => 'Cause',
'CheckMethod' => 'Alarm Check Method',
'ChooseDetectedCamera' => 'Choose Detected Camera',
+ 'ChooseDetectedProfile' => 'Choose Detected Profile',
'ChooseFilter' => 'Choose Filter',
'ChooseLogFormat' => 'Choose a log format',
'ChooseLogSelection' => 'Choose a log selection',
diff --git a/web/skins/classic/views/monitor.php b/web/skins/classic/views/monitor.php
index fa2ebd44f3..193b08d360 100644
--- a/web/skins/classic/views/monitor.php
+++ b/web/skins/classic/views/monitor.php
@@ -173,7 +173,7 @@ function fourcc( $a, $b, $c, $d ) {
}
}
if ( !empty($_REQUEST['probe']) ) {
- $probe = unserialize(base64_decode($_REQUEST['probe']));
+ $probe = json_decode(base64_decode($_REQUEST['probe']));
foreach ( $probe as $name=>$value ) {
if ( isset($value) ) {
# Does isset handle NULL's? I don't think this code is correct.
diff --git a/web/skins/classic/views/onvifprobe.php b/web/skins/classic/views/onvifprobe.php
index f9c7668464..ddbd895b65 100644
--- a/web/skins/classic/views/onvifprobe.php
+++ b/web/skins/classic/views/onvifprobe.php
@@ -18,7 +18,7 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
-if ( !canEdit( 'Monitors' ) ) {
+if ( !canEdit('Monitors') ) {
$view = 'error';
return;
}
@@ -73,26 +73,26 @@ function probeCameras( $localIp ) {
} elseif ( $tokens[1] == 'location' ) {
// $camera['location'] = $tokens[2];
} else {
- Logger::Debug('Unknown token ' . $tokens[1] );
+ Logger::Debug('Unknown token ' . $tokens[1]);
}
}
} // end foreach token
$cameras[] = $camera;
}
} // end foreach line
- }
- return( $cameras );
-}
+ } // end if results from execOnvif
+ return $cameras;
+} // end function probeCameras
function probeProfiles( $device_ep, $soapversion, $username, $password ) {
$profiles = array();
if ( $lines = @execONVIF( "profiles $device_ep $soapversion $username $password" ) ) {
foreach ( $lines as $line ) {
$line = rtrim( $line );
- if ( preg_match( '|^(.+),\s*(.+),\s*(.+),\s*(.+),\s*(.+),\s*(.+),\s*(.+)\s*$|', $line, $matches ) ) {
+ if ( preg_match('|^(.+),\s*(.+),\s*(.+),\s*(.+),\s*(.+),\s*(.+),\s*(.+)\s*$|', $line, $matches) ) {
$stream_uri = $matches[7];
// add user@pass to URI
- if ( preg_match( '|^(\S+://)(.+)$|', $stream_uri, $tokens ) ) {
+ if ( preg_match('|^(\S+://)(.+)$|', $stream_uri, $tokens) ) {
$stream_uri = $tokens[1].$username.':'.$password.'@'.$tokens[2];
}
@@ -106,17 +106,15 @@ function probeProfiles( $device_ep, $soapversion, $username, $password ) {
'Profile' => $matches[1],
'Name' => $matches[2],
'Encoding' => $matches[3],
-
);
$profiles[] = $profile;
} else {
Logger::Debug("Line did not match preg: $line");
}
- }
- }
- return( $profiles );
-}
-
+ } // end foreach line
+ } // end if results from execONVIF
+ return $profiles;
+} // end function probeProfiles
//==== STEP 1 ============================================================
@@ -124,20 +122,20 @@ function probeProfiles( $device_ep, $soapversion, $username, $password ) {
xhtmlHeaders(__FILE__, translate('MonitorProbe') );
-if( !isset($_REQUEST['step']) || ($_REQUEST['step'] == "1")) {
+if ( !isset($_REQUEST['step']) || ($_REQUEST['step'] == '1') ) {
$monitors = array();
- foreach ( dbFetchAll( "select Id, Name, Host from Monitors where Type = 'Remote' order by Host" ) as $monitor ) {
- if ( preg_match( '/^(.+)@(.+)$/', $monitor['Host'], $matches ) ) {
- //echo "1: ".$matches[2]." = ".gethostbyname($matches[2])."
";
- $monitors[gethostbyname($matches[2])] = $monitor;
- } else {
- //echo "2: ".$monitor['Host']." = ".gethostbyname($monitor['Host'])."
";
- $monitors[gethostbyname($monitor['Host'])] = $monitor;
- }
+ foreach ( dbFetchAll("SELECT Id, Name, Host FROM Monitors WHERE Type = 'Remote' ORDER BY Host") as $monitor ) {
+ if ( preg_match( '/^(.+)@(.+)$/', $monitor['Host'], $matches ) ) {
+ //echo "1: ".$matches[2]." = ".gethostbyname($matches[2])."
";
+ $monitors[gethostbyname($matches[2])] = $monitor;
+ } else {
+ //echo "2: ".$monitor['Host']." = ".gethostbyname($monitor['Host'])."
";
+ $monitors[gethostbyname($monitor['Host'])] = $monitor;
+ }
}
- $detcameras = probeCameras( '' );
+ $detcameras = probeCameras('');
foreach ( $detcameras as $camera ) {
if ( preg_match( '|([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)|', $camera['monitor']['Host'], $matches ) ) {
$ip = $matches[1];
@@ -157,13 +155,13 @@ function probeProfiles( $device_ep, $soapversion, $username, $password ) {
}
*/
// $sourceDesc = htmlspecialchars(serialize($camera['monitor']));
- $sourceDesc = base64_encode(serialize($camera['monitor']));
- $sourceString = $camera['model'].' @ '.$host . ' using version ' . $camera['monitor']['SOAP'] ;
- $cameras[$sourceDesc] = $sourceString;
+ $sourceDesc = base64_encode(json_encode($camera['monitor']));
+ $sourceString = $camera['model'].' @ '.$host . ' using version ' . $camera['monitor']['SOAP'] ;
+ $cameras[$sourceDesc] = $sourceString;
}
if ( count($cameras) <= 0 )
- $cameras[0] = translate('NoDetectedCameras');
+ $cameras[0] = translate('NoDetectedCameras');
?>
@@ -180,22 +178,23 @@ function probeProfiles( $device_ep, $soapversion, $username, $password ) {
-
+
+ 'configureButtons(this)')); ?>
-
+
-
+
-
+
@@ -205,44 +204,42 @@ function probeProfiles( $device_ep, $soapversion, $username, $password ) {
$value ) {
- if ( isset($value) ) {
- $monitor[$name] = $value;
- }
+ if ( isset($value) ) {
+ $monitor[$name] = $value;
+ }
}
$camera['monitor'] = $monitor;
//print $monitor['Host'].", ".$_REQUEST['username'].", ".$_REQUEST['password']."
";
- $detprofiles = probeProfiles( $monitor['Host'], $monitor['SOAP'], $_REQUEST['username'], $_REQUEST['password']);
+ $detprofiles = probeProfiles($monitor['Host'], $monitor['SOAP'], $_REQUEST['username'], $_REQUEST['password']);
foreach ( $detprofiles as $profile ) {
- $monitor = $camera['monitor'];
-
- $sourceString = "${profile['Name']} : ${profile['Encoding']}" .
- " (${profile['Width']}x${profile['Height']} @ ${profile['MaxFPS']}fps)";
- // copy technical details
- $monitor['Width'] = $profile['Width'];
- $monitor['Height'] = $profile['Height'];
-// The maxfps fields do not work for ip streams. Can re-enable if that is fixed.
-// $monitor['MaxFPS'] = $profile['MaxFPS'];
-// $monitor['AlarmMaxFPS'] = $profile['AlarmMaxFPS'];
- $monitor['Path'] = $profile['Path'];
-// $sourceDesc = htmlspecialchars(serialize($monitor));
- $sourceDesc = base64_encode(serialize($monitor));
- $profiles[$sourceDesc] = $sourceString;
+ $monitor = $camera['monitor'];
+
+ $sourceString = "${profile['Name']} : ${profile['Encoding']}" .
+ " (${profile['Width']}x${profile['Height']} @ ${profile['MaxFPS']}fps)";
+ // copy technical details
+ $monitor['Width'] = $profile['Width'];
+ $monitor['Height'] = $profile['Height'];
+ // The maxfps fields do not work for ip streams. Can re-enable if that is fixed.
+ // $monitor['MaxFPS'] = $profile['MaxFPS'];
+ // $monitor['AlarmMaxFPS'] = $profile['AlarmMaxFPS'];
+ $monitor['Path'] = $profile['Path'];
+ $sourceDesc = base64_encode(json_encode($monitor));
+ $profiles[$sourceDesc] = $sourceString;
}
if ( count($profiles) <= 0 )
- $profiles[0] = translate('NoDetectedProfiles');
+ $profiles[0] = translate('NoDetectedProfiles');
?>
@@ -254,17 +251,18 @@ function probeProfiles( $device_ep, $soapversion, $username, $password ) {
@@ -272,5 +270,5 @@ function probeProfiles( $device_ep, $soapversion, $username, $password ) {