Skip to content

Commit a0cc82b

Browse files
Merge branch 'master' into ai_server
2 parents f6cd7f0 + f9d8ba5 commit a0cc82b

File tree

18 files changed

+172
-108
lines changed

18 files changed

+172
-108
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*.min.js
2+
eslint.config.js
23

34
# libraries
45
web/api/lib

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@
88
[submodule "dep/RtspServer"]
99
path = dep/RtspServer
1010
url = https://github.com/ZoneMinder/RtspServer
11+
[submodule "dep/CxxUrl"]
12+
path = dep/CxxUrl
13+
url = https://github.com/chmike/CxxUrl.git

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,9 @@ else()
404404
"ZoneMinder requires jpeg but it was not found on your system")
405405
endif()
406406

407+
list(APPEND ZM_BIN_LIBS chmike::CxxUrl)
408+
409+
407410
# libjwt
408411
if (${ZM_JWT_BACKEND} STREQUAL "libjwt")
409412
find_package(LibJWT REQUIRED COMPONENTS ${ZM_CRYPTO_BACKEND})

dep/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ add_subdirectory(jwt-cpp)
22
add_subdirectory(libbcrypt)
33
add_subdirectory(RtspServer)
44
add_subdirectory(span-lite)
5+
add_subdirectory(CxxUrl)

dep/CxxUrl

Submodule CxxUrl added at eaf46c0

docs/api.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,22 +385,22 @@ Return a list of events for a specific monitor within a specific date/time range
385385

386386
::
387387

388-
http://server/zm/api/events/index/MonitorId:5/StartTime >=:2015-05-15 18:43:56/EndTime <=:2015-05-16 18:43:56.json
388+
http://server/zm/api/events/index/MonitorId:5/StartDateTime >=:2015-05-15 18:43:56/EndDateTime <=:2015-05-16 18:43:56.json
389389

390390

391391
To try this in CuRL, you need to URL escape the spaces like so:
392392

393393
::
394394

395-
curl -XGET "http://server/zm/api/events/index/MonitorId:5/StartTime%20>=:2015-05-15%2018:43:56/EndTime%20<=:2015-05-16%2018:43:56.json"
395+
curl -XGET "http://server/zm/api/events/index/MonitorId:5/StartDateTime%20>=:2015-05-15%2018:43:56/EndDateTime%20<=:2015-05-16%2018:43:56.json"
396396

397397

398398
Return a list of events for all monitors within a specified date/time range
399399
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
400400

401401
::
402402

403-
curl -XGET "http://server/zm/api/events/index/StartTime%20>=:2015-05-15%2018:43:56/EndTime%20<=:208:43:56.json"
403+
curl -XGET "http://server/zm/api/events/index/StartDateTime%20>=:2015-05-15%2018:43:56/EndDateTime%20<=:208:43:56.json"
404404

405405

406406
Return event count based on times and conditions
@@ -430,7 +430,7 @@ This returns a list of events within a time range and also sorts it by descendin
430430

431431
::
432432

433-
curl -XGET "http://server/zm/api/events/index/StartTime%20>=:2015-05-15%2018:43:56/EndTime%20<=:208:43:56.json?sort=StartTime&direction=desc"
433+
curl -XGET "http://server/zm/api/events/index/StartDateTime%20>=:2015-05-15%2018:43:56/EndDateTime%20<=:208:43:56.json?sort=StartDateTime&direction=desc"
434434

435435

436436
Configuration Apis

scripts/ZoneMinder/lib/ZoneMinder/Control.pm

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ sub guess_credentials {
405405
my $self = shift;
406406

407407
require URI;
408+
my $uri;
408409

409410
# Extract the username/password host/port from ControlAddress
410411
if ($self->{Monitor}{ControlAddress}
@@ -414,7 +415,7 @@ sub guess_credentials {
414415
$self->{Monitor}{ControlAddress} ne 'user:port@ip'
415416
) {
416417
Debug("Using ControlAddress for credentials: $self->{Monitor}{ControlAddress}");
417-
my $uri = URI->new($self->{Monitor}->{ControlAddress});
418+
$uri = URI->new($self->{Monitor}->{ControlAddress});
418419
$uri = URI->new('http://'.$self->{Monitor}->{ControlAddress}) if ref($uri) eq 'URI::_foreign';
419420
$$self{host} = $uri->host();
420421
if ( $uri->userinfo()) {
@@ -443,7 +444,7 @@ sub guess_credentials {
443444
$$self{username}= $self->{Monitor}->{User} if $self->{Monitor}->{User} and !$$self{username};
444445
$$self{password} = $self->{Monitor}->{Pass} if $self->{Monitor}->{Pass} and !$$self{password};
445446
}
446-
my $uri = URI->new($self->{Monitor}->{Path});
447+
$uri = URI->new($self->{Monitor}->{Path});
447448
$uri->scheme('http');
448449
$uri->port(80);
449450
$uri->path('');
@@ -452,6 +453,7 @@ sub guess_credentials {
452453
} else {
453454
Debug('Unable to guess credentials');
454455
}
456+
return $uri;
455457
}
456458

457459
sub get_realm {
@@ -501,7 +503,10 @@ sub get_realm {
501503
sub ping {
502504
my $self = shift;
503505
my $ip = @_ ? shift : $$self{host};
504-
return undef if ! $ip;
506+
if (!$ip) {
507+
Warning("No ip to ping. Please either pass ip or populate self{host}");
508+
return undef;
509+
}
505510

506511
require Net::Ping;
507512
Debug("Pinging $ip");

scripts/ZoneMinder/lib/ZoneMinder/Control/AxisV2.pm

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,35 +53,20 @@ sub open {
5353

5454
$self->loadMonitor();
5555

56-
if ($self->{Monitor}->{ControlAddress} and ($self->{Monitor}->{ControlAddress} ne 'user:pass@ip')) {
57-
Debug("Getting connection details from Control Address " . $self->{Monitor}->{ControlAddress});
58-
if ( $self->{Monitor}->{ControlAddress} !~ /^\w+:\/\// ) {
59-
# Has no scheme at the beginning, so won't parse as a URI
60-
$self->{Monitor}->{ControlAddress} = 'http://'.$self->{Monitor}->{ControlAddress};
61-
}
62-
$uri = URI->new($self->{Monitor}->{ControlAddress});
63-
} elsif ($self->{Monitor}->{Path}) {
64-
Debug("Getting connection details from Path " . $self->{Monitor}->{Path});
65-
$uri = URI->new($self->{Monitor}->{Path});
66-
$uri->scheme('http');
67-
$uri->port(80);
68-
$uri->path('');
69-
}
56+
my $uri = $self->guess_credentials();
57+
$uri = new URI() if ! $uri;;
58+
# For parent get
59+
$$self{BaseURL} = $uri->canonical();
7060

7161
use LWP::UserAgent;
7262
$self->{ua} = LWP::UserAgent->new;
7363
$self->{ua}->cookie_jar( {} );
7464
$self->{ua}->agent('ZoneMinder Control Agent/'.ZoneMinder::Base::ZM_VERSION);
7565
$self->{state} = 'closed';
7666

77-
my ( $username, $password, $host ) = ( $uri->authority() =~ /^([^:]+):([^@]*)@(.+)$/ );
78-
Debug("Have username: $username password: $password host: $host from authority:" . $uri->authority());
79-
80-
$uri->userinfo(undef);
81-
8267
my $realm = $self->{Monitor}->{ControlDevice};
8368

84-
$self->{ua}->credentials($uri->host_port(), $realm, $username, $password);
69+
$self->{ua}->credentials($uri->host_port(), $realm, $$self{username}, $$self{password});
8570
my $url = '/axis-cgi/param.cgi?action=list&group=Properties.PTZ.PTZ';
8671

8772
# test auth
@@ -92,7 +77,7 @@ sub open {
9277
Warning('Response suggests that camera doesn\'t support PTZ. Content:('.$res->content().')');
9378
}
9479
$self->{state} = 'open';
95-
return;
80+
return !undef;
9681
}
9782
if ($res->status_line() eq '404 Not Found') {
9883
#older style
@@ -113,12 +98,12 @@ sub open {
11398
if ( $tokens =~ /\w+="([^"]+)"/i ) {
11499
if ( $realm ne $1 ) {
115100
$realm = $1;
116-
$self->{ua}->credentials($uri->host_port(), $realm, $username, $password);
101+
$self->{ua}->credentials($uri->host_port(), $realm, $$self{username}, $$self{password});
117102
$res = $self->{ua}->get($uri->canonical().$url);
118103
if ( $res->is_success() ) {
119104
Info("Auth succeeded after setting realm to $realm. You can set this value in the Control Device field to speed up connections and remove these log entries.");
120105
$self->{state} = 'open';
121-
return;
106+
return !undef;
122107
}
123108
Error('Authentication still failed after updating REALM status: '.$res->status_line);
124109
} else {
@@ -131,11 +116,10 @@ sub open {
131116
} else {
132117
Debug('No headers line');
133118
} # end if headers
134-
# For parent get
135-
$$self{BaseURL} = $uri->canonical();
136119
} else {
137120
Debug('Failed to open '.$uri->canonical().$url.' status: '.$res->status_line());
138121
} # end if $res->status_line() eq '401 Unauthorized'
122+
return undef;
139123
} # end sub open
140124

141125
sub sendCmd {
@@ -352,13 +336,10 @@ sub moveStop {
352336
my $speed = 0;
353337
Debug('Move Stop');
354338
# we have to stop both pans and zooms
355-
my $cmd = "/axis-cgi/com/ptz.cgi?continuouspantiltmove=$speed,$speed";
356-
$self->sendCmd($cmd);
357-
my $cmd = "/axis-cgi/com/ptz.cgi?continuouszoommove=$speed";
358-
$self->sendCmd($cmd);
339+
$self->sendCmd("/axis-cgi/com/ptz.cgi?continuouspantiltmove=$speed,$speed");
340+
$self->sendCmd("/axis-cgi/com/ptz.cgi?continuouszoommove=$speed");
359341
}
360342

361-
362343
sub zoomRelTele {
363344
my $self = shift;
364345
my $params = shift;

src/zm_monitor.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,11 +423,15 @@ class Monitor : public std::enable_shared_from_this<Monitor> {
423423
Monitor *parent;
424424
bool alarmed;
425425
bool healthy;
426-
std::string amcrest_response;
426+
std::string last_topic;
427+
std::string last_value;
428+
429+
std::string response;
427430
CURLM *curl_multi = nullptr;
428431
CURL *Amcrest_handle = nullptr;
429-
static size_t WriteCallback(void *contents, size_t size, size_t nmemb,
430-
void *userp);
432+
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp);
433+
std::mutex alarms_mutex;
434+
std::mutex response_mutex;
431435

432436
public:
433437
explicit AmcrestAPI(Monitor *parent_);

0 commit comments

Comments
 (0)