Merge ../ZoneMinder.connortechnology into storageareas

This commit is contained in:
Isaac Connor 2016-10-07 11:39:32 -04:00
commit 346975fd1d
13 changed files with 413 additions and 549 deletions

View File

@ -77,6 +77,8 @@ my %soap_version_of :ATTR(:default<('1.1')>);
sub service
{
my ($self, $serviceName, $attr) = @_;
#print "service: " . $services_of{${$self}}{$serviceName}{$attr} . "\n";
# Please note that the Std::Class::Fast docs say not to use ident.
$services_of{ident $self}{$serviceName}{$attr};
}
@ -113,18 +115,14 @@ sub set_soap_version
delete $serializer_of{ ident $self };
}
sub get_service_urls
{
sub get_service_urls {
my ($self) = @_;
my $result = $self->service('device', 'ep')->GetServices( {
IncludeCapability => 'true', # boolean
},,
);
die $result if not $result;
# print $result . "\n";
if ( $result ) {
foreach my $svc ( @{ $result->get_Service() } ) {
my $short_name = $namespace_map{$svc->get_Namespace()};
my $url_svc = $svc->get_XAddr()->get_value();
@ -133,7 +131,43 @@ sub get_service_urls
$self->set_service($short_name, 'url', $url_svc);
}
}
}
# } else {
#print "No results from GetServices: $result\n";
}
# Some devices do not support getServices, so we have to try getCapabilities
$result = $self->service('device', 'ep')->GetCapabilities( {}, , );
if ( ! $result ) {
print "No results from GetCapabilities: $result\n";
return;
}
# Result is a GetCapabilitiesResponse
foreach my $capabilities ( @{ $result->get_Capabilities() } ) {
foreach my $capability ( 'PTZ', 'Media', 'Imaging', 'Events', 'Device' ) {
if ( my $function = $capabilities->can( "get_$capability" ) ) {
my $Services = $function->( $capabilities );
if ( ! $Services ) {
print "Nothing returned ffrom get_$capability\n";
} else {
foreach my $svc ( @{ $Services } ) {
# The capability versions don't have a namespace, so just lowercase them.
my $short_name = lc $capability;
my $url_svc = $svc->get_XAddr()->get_value();
if( defined $url_svc) {
# print "Got $short_name service\n";
$self->set_service($short_name, 'url', $url_svc);
}
} # end foreach svr
}
} else {
print "No $capability function\n";
} # end if has a get_ function
} # end foreach capability
} # end foreach capabilities
} # end sub get_service_urls
sub http_digest {
my ($service, $username, $password) = @_;

View File

@ -272,7 +272,11 @@ sub _initialize {
#
$_method =~s{\.}{__}xg;
$_method =~s{\-}{_}xg;
if ( $list->[-1]->can( $_method ) ) {
$list->[-1]->$_method( $current );
} else {
print ( "ERror " . $list->[-1] . " cannot $_method\n" );
}
$current = pop @$list; # step up in object hierarchy

View File

@ -120,8 +120,8 @@ sub send_receive {
my ($address,$port) = ($endpoint =~ /([^:\/]+):([0-9]+)/);
# warn "address = ${address}";
# warn "port = ${port}";
#warn "address = ${address}";
#warn "port = ${port}";
$self->send_multi($address, $port, $envelope);

View File

@ -15,6 +15,7 @@ __PACKAGE__->__set_ref();
use base qw(
SOAP::WSDL::XSD::Typelib::Element
WSDiscovery10::Types::ProbeType
WSDiscovery10::Types::ProbeMatchesType
);
}

View File

@ -1,4 +1,5 @@
#!/usr/bin/perl -w
use strict;
#
# ==========================================================================
#
@ -41,6 +42,7 @@ require WSDiscovery::TransportUDP;
# Globals
my $verbose = 0;
my $soap_version = undef;
my $client;
# =========================================================================
@ -172,6 +174,8 @@ sub discover
my $uuid_gen = Data::UUID->new();
if ( ( ! $soap_version ) or ( $soap_version eq '1.1' ) ) {
if($verbose) {
print "Probing for SOAP 1.1\n"
}
@ -193,28 +197,30 @@ sub discover
To => { value => 'urn:schemas-xmlsoap-org:ws:2005:04:discovery' },
})
);
# print $result . "\n";
print $result . "\n" if $verbose;
interpret_messages($svc_discover, \%services, @responses);
@responses = ();
} # end if doing soap 1.1
if ( ( ! $soap_version ) or ( $soap_version eq '1.2' ) ) {
if($verbose) {
print "Probing for SOAP 1.2\n"
}
$svc_discover = WSDiscovery10::Interfaces::WSDiscovery::WSDiscoveryPort->new({
my $svc_discover = WSDiscovery10::Interfaces::WSDiscovery::WSDiscoveryPort->new({
# no_dispatch => '1',
});
$svc_discover->set_soap_version('1.2');
# copies of the same Probe message must have the same MessageID.
# This is not a copy. So we generate a new uuid.
$uuid = $uuid_gen->create_str();
# copies of the same Probe message must have the same MessageID.
# This is not a copy. So we generate a new uuid.
my $uuid = $uuid_gen->create_str();
$result = $svc_discover->ProbeOp(
# Everyone else, like the nodejs onvif code and odm only ask for NetworkVideoTransmitter
my $result = $svc_discover->ProbeOp(
{ # WSDiscovery::Types::ProbeType
xmlattr => { 'xmlns:dn' => 'http://www.onvif.org/ver10/network/wsdl',
'xmlns:tds' => 'http://www.onvif.org/ver10/device/wsdl', },
Types => 'dn:NetworkVideoTransmitter tds:Device', # QNameListType
xmlattr => { 'xmlns:dn' => 'http://www.onvif.org/ver10/network/wsdl', },
Types => 'dn:NetworkVideoTransmitter', # QNameListType
Scopes => { value => '' },
},
WSDiscovery10::Elements::Header->new({
@ -223,9 +229,10 @@ sub discover
To => { value => 'urn:schemas-xmlsoap-org:ws:2005:04:discovery' },
})
);
# print $result . "\n";
print $result . "\n" if $verbose;
interpret_messages($svc_discover, \%services, @responses);
} # end if doing soap 1.2
}
@ -321,7 +328,7 @@ my $OPTIONS = "v";
sub HELP_MESSAGE
{
my ($fh, $pkg, $ver, $opts) = @_;
print $fh "Usage: " . __FILE__ . " [-v] probe \n";
print $fh "Usage: " . __FILE__ . " [-v] probe <soap version>\n";
print $fh " " . __FILE__ . " [-v] <command> <device URI> <soap version> <user> <password>\n";
print $fh <<EOF
Commands are:
@ -359,14 +366,15 @@ if(!defined $action) {
}
if($action eq "probe") {
$soap_version = shift;
discover();
}
else {
# all other actions need URI and credentials
my $url_svc_device = shift;
my $soap_version = shift;
my $username = shift;
my $password = shift;
my $url_svc_device = shift @ARGV;
$soap_version = shift @ARGV;
my $username = @ARGV ? shift @ARGV : '';
my $password = @ARGV ? shift @ARGV: '';
$client = ONVIF::Client->new( {
'url_svc_device' => $url_svc_device,

View File

@ -152,11 +152,13 @@ Image::Image( const Image &p_image )
strncpy( text, p_image.text, sizeof(text) );
}
Image::~Image()
{
Image::~Image() {
DumpImgBuffer();
if ( initialised )
{
}
/* Should be called as part of program shutdown to free everything */
void Image::Deinitialise() {
if ( initialised ) {
/*
delete[] y_table;
delete[] uv_table;
@ -166,9 +168,7 @@ Image::~Image()
delete[] b_u_table;
*/
initialised = false;
}
if ( readjpg_dcinfo )
{
if ( readjpg_dcinfo ) {
jpeg_destroy_decompress( readjpg_dcinfo );
delete readjpg_dcinfo;
readjpg_dcinfo = 0;
@ -179,17 +179,14 @@ Image::~Image()
delete decodejpg_dcinfo;
decodejpg_dcinfo = 0;
}
#if 0
+// This creates a memleak because it isn't de-allocating the structures and it's doing it on every Image construct/destruct.
+// We need to refactor this code big time.
for ( unsigned int quality=0; quality <= 100; quality += 1 ) {
if ( writejpg_ccinfo[quality] ) {
jpeg_destroy_compress( writejpg_ccinfo[quality] );
delete writejpg_ccinfo[quality];
writejpg_ccinfo[quality] = NULL;
}
} // end foreach quality
#endif
}
}
void Image::Initialise()

View File

@ -137,7 +137,6 @@ protected:
static jpeg_decompress_struct *decodejpg_dcinfo;
static struct zm_error_mgr jpg_err;
protected:
unsigned int width;
unsigned int height;
unsigned int pixels;
@ -150,8 +149,6 @@ protected:
int holdbuffer; /* Hold the buffer instead of replacing it with new one */
char text[1024];
protected:
static void Initialise();
public:
Image();
@ -159,6 +156,8 @@ public:
Image( int p_width, int p_height, int p_colours, int p_subpixelorder, uint8_t *p_buffer=0);
Image( const Image &p_image );
~Image();
static void Initialise();
static void Deinitialise();
inline unsigned int Width() const { return( width ); }
inline unsigned int Height() const { return( height ); }

View File

@ -198,6 +198,7 @@ int main( int argc, char *argv[] )
{
fprintf( stderr, "Can't find monitor with id of %d\n", id );
}
Image::Deinitialise();
logTerm();
zmDbClose();
return( 0 );

View File

@ -358,6 +358,7 @@ int main( int argc, char *argv[] )
delete [] next_delays;
delete [] last_capture_times;
Image::Deinitialise();
logTerm();
zmDbClose();

File diff suppressed because it is too large Load Diff

View File

@ -141,13 +141,12 @@ function getAuthUser( $auth ) {
}
function generateAuthHash( $useRemoteAddr ) {
if ( ZM_OPT_USE_AUTH && ZM_AUTH_RELAY == 'hashed' ) {
if ( ZM_OPT_USE_AUTH and ZM_AUTH_RELAY == 'hashed' and $_SESSION['username'] and $_SESSION['passwordHash'] ) {
# regenerate a hash at half the liftetime of a hash, an hour is 3600 so half is 1800
if ( ( $_SESSION['AuthHashGeneratedAt'] < time() - ( ZM_AUTH_HASH_TTL * 1800 ) ) or ! isset($_SESSION['AuthHash']) ) {
if ( ! ( $_SESSION['username'] and $_SESSION['passwordHash'] ) ) {
Warning("Can't generate auth hash until we are logged in");
} else {
# Don't both regenerating Auth Hash if an hour hasn't gone by yet
$time = localtime();
$authKey = '';
if ( $useRemoteAddr ) {
$authKey = ZM_AUTH_HASH_SECRET.$_SESSION['username'].$_SESSION['passwordHash'].$_SESSION['remoteAddr'].$time[2].$time[3].$time[4].$time[5];
} else {
@ -159,14 +158,13 @@ function generateAuthHash( $useRemoteAddr ) {
}
$_SESSION['AuthHash'] = $auth;
$_SESSION['AuthHashGeneratedAt'] = time();
Debug("Generating new auth $auth at " . $_SESSION['AuthHashGeneratedAt']. " using $authKey" );
}
Debug("Generated new auth $auth at " . $_SESSION['AuthHashGeneratedAt']. " using $authKey" );
} else {
Debug("Using auth " . $_SESSION['AuthHash'] );
Debug( "Using cached auth " . $_SESSION['AuthHash'] );
} # end if AuthHash is not cached
return $_SESSION['AuthHash'];
} else {
$auth = "";
$auth = '';
}
return( $auth );
}

View File

@ -520,6 +520,7 @@ $SLANG = array(
'NewUser' => 'New User',
'Next' => 'Next',
'NoDetectedCameras' => 'No Detected Cameras',
'NoDetectedProfiles' => 'No Detected Profiles',
'NoFramesRecorded' => 'There are no frames recorded for this event',
'NoGroup' => 'No Group',
'NoneAvailable' => 'None available',

View File

@ -18,41 +18,40 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
if ( !canEdit( 'Monitors' ) )
{
$view = "error";
if ( !canEdit( 'Monitors' ) ) {
$view = 'error';
return;
}
$cameras = array();
$cameras[0] = translate('ChooseDetectedCamera');
$profiles = array();
$profiles[0] = translate('ChooseDetectedProfile');
function execONVIF( $cmd )
{
exec( escapeshellcmd(ZM_PATH_BIN . "/zmonvif-probe.pl $cmd"), $output, $status );
function execONVIF( $cmd ) {
$shell_command = escapeshellcmd(ZM_PATH_BIN . "/zmonvif-probe.pl $cmd");
if ( $status )
exec( $shell_command, $output, $status );
if ( $status ) {
$html_output = implode( '<br/>', $output );
Fatal( "Unable to probe network cameras, status is '$status'. Output was:<br/><br/>
$html_output<br/><br/>
Please the following command from a command line for more information:<br/><br/>".
ZM_PATH_BIN . "/zmonvif-probe.pl $cmd" );
Please the following command from a command line for more information:<br/><br/>$shell_command"
);
}
return $output;
}
function probeCameras( $localIp )
{
function probeCameras( $localIp ) {
$cameras = array();
$count = 0;
if ( $lines = @execONVIF( "probe" ) )
{
foreach ( $lines as $line )
{
if ( $lines = @execONVIF( 'probe' ) ) {
foreach ( $lines as $line ) {
$line = rtrim( $line );
if ( preg_match( '|^(.+),(.+),\s\((.*)\)$|', $line, $matches ) )
{
if ( preg_match( '|^(.+),(.+),\s\((.*)\)$|', $line, $matches ) ) {
$device_ep = $matches[1];
$soapversion = $matches[2];
$camera = array(
@ -65,15 +64,12 @@ function probeCameras( $localIp )
),
);
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") {
$camera['model'] = $tokens[2];
}
elseif($tokens[1] == "name") {
} elseif($tokens[1] == "name") {
$camera['monitor']['Name'] = $tokens[2];
}
elseif($tokens[1] == "location") {
} elseif($tokens[1] == "location") {
// $camera['location'] = $tokens[2];
}
@ -86,21 +82,16 @@ function probeCameras( $localIp )
return( $cameras );
}
function probeProfiles( $device_ep, $soapversion, $username, $password )
{
function probeProfiles( $device_ep, $soapversion, $username, $password ) {
$profiles = array();
$count = 0;
if ( $lines = @execONVIF( "profiles $device_ep $soapversion $username $password" ) )
{
foreach ( $lines as $line )
{
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];
}
@ -133,25 +124,19 @@ xhtmlHeaders(__FILE__, translate('MonitorProbe') );
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 ) )
{
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])."<br/>";
$monitors[gethostbyname($matches[2])] = $monitor;
}
else
{
} else {
//echo "2: ".$monitor['Host']." = ".gethostbyname($monitor['Host'])."<br/>";
$monitors[gethostbyname($monitor['Host'])] = $monitor;
}
}
$detcameras = probeCameras( '' );
foreach ( $detcameras as $camera )
{
if ( preg_match( '|([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)|', $camera['monitor']['Host'], $matches ) )
{
foreach ( $detcameras as $camera ) {
if ( preg_match( '|([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)|', $camera['monitor']['Host'], $matches ) ) {
$ip = $matches[1];
}
$host = $ip;
@ -220,15 +205,14 @@ if( !isset($_REQUEST['step']) || ($_REQUEST['step'] == "1")) {
}
else if($_REQUEST['step'] == "2")
{
if ( empty($_REQUEST['probe']) || empty($_REQUEST['username']) ||
empty($_REQUEST['password']) )
Fatal("Internal error. Please re-open this page.");
if ( empty($_REQUEST['probe']) )
Fatal("No probe passed in request. Please go back and try again.");
#|| empty($_REQUEST['username']) ||
#empty($_REQUEST['password']) )
$probe = unserialize(base64_decode($_REQUEST['probe']));
foreach ( $probe as $name=>$value )
{
if ( isset($value) )
{
foreach ( $probe as $name=>$value ) {
if ( isset($value) ) {
$monitor[$name] = $value;
}
}
@ -237,8 +221,7 @@ else if($_REQUEST['step'] == "2")
//print $monitor['Host'].", ".$_REQUEST['username'].", ".$_REQUEST['password']."<br/>";
$detprofiles = probeProfiles( $monitor['Host'], $monitor['SOAP'], $_REQUEST['username'], $_REQUEST['password']);
foreach ( $detprofiles as $profile )
{
foreach ( $detprofiles as $profile ) {
$monitor = $camera['monitor'];
$sourceString = "${profile['Name']} : ${profile['Encoding']}" .
@ -252,11 +235,11 @@ else if($_REQUEST['step'] == "2")
$monitor['Path'] = $profile['Path'];
// $sourceDesc = htmlspecialchars(serialize($monitor));
$sourceDesc = base64_encode(serialize($monitor));
$cameras[$sourceDesc] = $sourceString;
$profiles[$sourceDesc] = $sourceString;
}
if ( count($cameras) <= 0 )
$cameras[0] = translate('NoDetectedCameras');
if ( count($profiles) <= 0 )
$profiles[0] = translate('NoDetectedProfiles');
?>
<body>
@ -273,7 +256,7 @@ else if($_REQUEST['step'] == "2")
<?php echo translate('ProfileProbeIntro') ?>
</p>
<p>
<label for="probe"><?php echo translate('DetectedProfiles') ?></label><?php echo buildSelect( "probe", $cameras, 'configureButtons( this )' ); ?>
<label for="probe"><?php echo translate('DetectedProfiles') ?></label><?php echo buildSelect( 'probe', $profiles, 'configureButtons( this )' ); ?>
</p>
<div id="contentButtons">
<input type="button" name="prevBtn" value="<?php echo translate('Prev') ?>" onclick="gotoStep1( this )"/>