Merge pull request #2704 from connortechnology/fix_2702

general clean of onvif probe view.  Use buttons instead of inputs and…
This commit is contained in:
Isaac Connor 2019-09-11 09:18:27 -04:00 committed by GitHub
commit 94f2dccae5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 47 deletions

View File

@ -22,14 +22,14 @@ function gotoStep2( element ) {
form.submit(); form.submit();
} }
function configureButtons( element ) { function configureButtons(element) {
var form = element.form; var form = element.form;
if (form.elements.namedItem("nextBtn")) { if (form.elements.namedItem('nextBtn')) {
form.nextBtn.disabled = (form.probe.selectedIndex==0) || form.nextBtn.disabled = (form.probe.selectedIndex==0) ||
(form.username == "") || (form.username == null) || (form.Username == '') || (form.Username == null) ||
(form.password == "") || (form.password == null); (form.Password == '') || (form.Password == null);
} }
if (form.elements.namedItem("saveBtn")) { if (form.elements.namedItem('saveBtn')) {
form.saveBtn.disabled = (form.probe.selectedIndex==0); form.saveBtn.disabled = (form.probe.selectedIndex==0);
} }
} }

View File

@ -41,18 +41,18 @@ function execONVIF( $cmd ) {
Please the following command from a command line for more information:<br/><br/>$shell_command" Please the following command from a command line for more information:<br/><br/>$shell_command"
); );
} else { } else {
ZM\Logger::Debug( "Results from probe: " . implode( '<br/>', $output ) ); ZM\Logger::Debug('Results from probe: '.implode('<br/>', $output));
} }
return $output; return $output;
} }
function probeCameras( $localIp ) { function probeCameras($localIp) {
$cameras = array(); $cameras = array();
if ( $lines = @execONVIF( 'probe' ) ) { if ( $lines = @execONVIF('probe') ) {
foreach ( $lines as $line ) { foreach ( $lines as $line ) {
$line = rtrim( $line ); $line = rtrim($line);
if ( preg_match( '|^(.+),(.+),\s\((.*)\)$|', $line, $matches ) ) { if ( preg_match('|^(.+),(.+),\s\((.*)\)$|', $line, $matches) ) {
$device_ep = $matches[1]; $device_ep = $matches[1];
$soapversion = $matches[2]; $soapversion = $matches[2];
$camera = array( $camera = array(
@ -65,7 +65,7 @@ function probeCameras( $localIp ) {
), ),
); );
foreach ( preg_split('|,\s*|', $matches[3]) as $attr_val ) { foreach ( preg_split('|,\s*|', $matches[3]) as $attr_val ) {
if ( preg_match( '|(.+)=\'(.*)\'|', $attr_val, $tokens ) ) { if ( preg_match('|(.+)=\'(.*)\'|', $attr_val, $tokens) ) {
if ( $tokens[1] == 'hardware' ) { if ( $tokens[1] == 'hardware' ) {
$camera['model'] = $tokens[2]; $camera['model'] = $tokens[2];
} elseif ( $tokens[1] == 'name' ) { } elseif ( $tokens[1] == 'name' ) {
@ -84,7 +84,7 @@ function probeCameras( $localIp ) {
return $cameras; return $cameras;
} // end function probeCameras } // end function probeCameras
function probeProfiles( $device_ep, $soapversion, $username, $password ) { function probeProfiles($device_ep, $soapversion, $username, $password) {
$profiles = array(); $profiles = array();
if ( $lines = @execONVIF("profiles $device_ep $soapversion $username $password") ) { if ( $lines = @execONVIF("profiles $device_ep $soapversion $username $password") ) {
foreach ( $lines as $line ) { foreach ( $lines as $line ) {
@ -125,8 +125,8 @@ xhtmlHeaders(__FILE__, translate('MonitorProbe') );
if ( !isset($_REQUEST['step']) || ($_REQUEST['step'] == '1') ) { if ( !isset($_REQUEST['step']) || ($_REQUEST['step'] == '1') ) {
$monitors = array(); $monitors = array();
foreach ( dbFetchAll("SELECT Id, Name, Host FROM Monitors WHERE Type = 'Remote' ORDER BY Host") as $monitor ) { foreach ( dbFetchAll("SELECT Id, Name, Host FROM Monitors WHERE Type='Remote' ORDER BY Host") as $monitor ) {
if ( preg_match( '/^(.+)@(.+)$/', $monitor['Host'], $matches ) ) { if ( preg_match('/^(.+)@(.+)$/', $monitor['Host'], $matches) ) {
//echo "1: ".$matches[2]." = ".gethostbyname($matches[2])."<br/>"; //echo "1: ".$matches[2]." = ".gethostbyname($matches[2])."<br/>";
$monitors[gethostbyname($matches[2])] = $monitor; $monitors[gethostbyname($matches[2])] = $monitor;
} else { } else {
@ -137,26 +137,12 @@ if ( !isset($_REQUEST['step']) || ($_REQUEST['step'] == '1') ) {
$detcameras = probeCameras(''); $detcameras = probeCameras('');
foreach ( $detcameras as $camera ) { foreach ( $detcameras as $camera ) {
if ( preg_match( '|([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)|', $camera['monitor']['Host'], $matches ) ) { if ( preg_match('|([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)|', $camera['monitor']['Host'], $matches) ) {
$ip = $matches[1]; $ip = $matches[1];
} }
$host = $ip; $host = $ip;
/*
if ( isset($monitors[$ip]) )
{
$monitor = $monitors[$ip];
$sourceString .= " (".$monitor['Name'].")";
}
else
{
$sourceString .= " - ".translate('Available');
}
$cameras[$sourceDesc] = $sourceString;
}
*/
// $sourceDesc = htmlspecialchars(serialize($camera['monitor']));
$sourceDesc = base64_encode(json_encode($camera['monitor'])); $sourceDesc = base64_encode(json_encode($camera['monitor']));
$sourceString = $camera['model'].' @ '.$host . ' using version ' . $camera['monitor']['SOAP'] ; $sourceString = $camera['model'].' @ '.$host.' using version '.$camera['monitor']['SOAP'];
$cameras[$sourceDesc] = $sourceString; $cameras[$sourceDesc] = $sourceString;
} }
@ -179,39 +165,38 @@ if ( !isset($_REQUEST['step']) || ($_REQUEST['step'] == '1') ) {
</p> </p>
<p> <p>
<label for="probe"><?php echo translate('DetectedCameras') ?></label> <label for="probe"><?php echo translate('DetectedCameras') ?></label>
<?php echo htmlSelect('probe', $cameras, null, array('onchange'=>'configureButtons(this)')); ?> <?php echo htmlSelect('probe', $cameras, null, array('data-on-change-this'=>'configureButtons')); ?>
</p> </p>
<p> <p>
<?php echo translate('OnvifCredentialsIntro') ?> <?php echo translate('OnvifCredentialsIntro') ?>
</p> </p>
<p> <p>
<label for="username"><?php echo translate('Username') ?></label> <label for="Username"><?php echo translate('Username') ?></label>
<input type="text" name="username" value="" onChange="configureButtons(this)"/> <input type="text" name="Username" data-on-change-this="configureButtons"/>
</p> </p>
<p> <p>
<label for="password"><?php echo translate('Password') ?></label> <label for="Password"><?php echo translate('Password') ?></label>
<input type="password" name="password" value="" onChange="configureButtons(this)"/> <input type="password" name="Password" data-on-change-this="configureButtons"/>
</p> </p>
<div id="contentButtons"> <div id="contentButtons">
<input type="button" value="<?php echo translate('Cancel') ?>" data-on-click="closeWindow"/> <button type="button" data-on-click="closeWindow"><?php echo translate('Cancel') ?></button>
<input type="submit" name="nextBtn" value="<?php echo translate('Next') ?>" data-on-click-this="gotoStep2" disabled="disabled"/> <button type="button" name="nextBtn" data-on-click-this="gotoStep2" disabled="disabled"><?php echo translate('Next') ?></button>
</div> </div>
</form> </form>
</div> </div>
</div> </div>
</body> </body>
</html>
<?php <?php
//==== STEP 2 ============================================================ //==== STEP 2 ============================================================
} else if($_REQUEST['step'] == '2') { } else if ( $_REQUEST['step'] == '2' ) {
if ( empty($_REQUEST['probe']) ) if ( empty($_REQUEST['probe']) )
ZM\Fatal('No probe passed in request. Please go back and try again.'); ZM\Fatal('No probe passed in request. Please go back and try again.');
#|| empty($_REQUEST['username']) || #|| empty($_REQUEST['username']) ||
#empty($_REQUEST['password']) ) #empty($_REQUEST['password']) )
$probe = json_decode(base64_decode($_REQUEST['probe'])); $probe = json_decode(base64_decode($_REQUEST['probe']));
ZM\Logger::Debug(print_r($probe,true)); ZM\Logger::Debug(print_r($probe, true));
foreach ( $probe as $name=>$value ) { foreach ( $probe as $name=>$value ) {
if ( isset($value) ) { if ( isset($value) ) {
$monitor[$name] = $value; $monitor[$name] = $value;
@ -221,7 +206,7 @@ if ( !isset($_REQUEST['step']) || ($_REQUEST['step'] == '1') ) {
//print $monitor['Host'].", ".$_REQUEST['username'].", ".$_REQUEST['password']."<br/>"; //print $monitor['Host'].", ".$_REQUEST['username'].", ".$_REQUEST['password']."<br/>";
$detprofiles = probeProfiles($monitor['Host'], $monitor['SOAP'], $_REQUEST['username'], $_REQUEST['password']); $detprofiles = probeProfiles($monitor['Host'], $monitor['SOAP'], $_REQUEST['Username'], $_REQUEST['Password']);
foreach ( $detprofiles as $profile ) { foreach ( $detprofiles as $profile ) {
$monitor = $camera['monitor']; $monitor = $camera['monitor'];
@ -258,18 +243,18 @@ if ( !isset($_REQUEST['step']) || ($_REQUEST['step'] == '1') ) {
</p> </p>
<p> <p>
<label for="probe"><?php echo translate('DetectedProfiles') ?></label> <label for="probe"><?php echo translate('DetectedProfiles') ?></label>
<?php echo htmlSelect('probe', $profiles, null, array('onchange'=>'configureButtons(this)')); ?> <?php echo htmlSelect('probe', $profiles, null, array('data-on-change-this'=>'configureButtons')); ?>
</p> </p>
<div id="contentButtons"> <div id="contentButtons">
<input type="button" name="prevBtn" value="<?php echo translate('Prev') ?>" data-on-click-this="gotoStep1"/> <button type="button" name="prevBtn" data-on-click-this="gotoStep1"><?php echo translate('Prev') ?></button>
<input type="button" value="<?php echo translate('Cancel') ?>" data-on-click="closeWindow"/> <button type="button" data-on-click="closeWindow"><?php echo translate('Cancel') ?></button>
<input type="submit" name="saveBtn" value="<?php echo translate('Save') ?>" data-on-click-this="submitCamera" disabled="disabled"/> <button type="button" name="saveBtn" data-on-click-this="submitCamera" disabled="disabled"><?php echo translate('Save') ?></button>
</div> </div>
</form> </form>
</div> </div>
</div> </div>
</body> </body>
</html>
<?php <?php
} // end if step 1 or 2 } // end if step 1 or 2
?> ?>
</html>