Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ZoneMinder/ZoneMinder
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Connor committed Jun 27, 2024
2 parents 6085782 + b1d0b57 commit f4e3005
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 9 deletions.
8 changes: 4 additions & 4 deletions db/zm_update-1.37.27.sql
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ PREPARE stmt FROM @s;
EXECUTE stmt;

REPLACE INTO Monitors_Permissions (UserId,Permission, MonitorId)
SELECT Id, 'Edit', SUBSTRING_INDEX(SUBSTRING_INDEX(t.MonitorIds, ',', n.n), ',', -1) value FROM Users t CROSS JOIN (
SELECT a.N + b.N * 10 + 1 n FROM (SELECT 0 AS N UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) a ,(SELECT 0 AS N UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) b ORDER BY n ) n WHERE t.Monitors='Edit' and t.MonitorIds != '' AND n.n <= 1 + (LENGTH(t.MonitorIds) - LENGTH(REPLACE(t.MonitorIds, ',', ''))) ORDER BY value;
SELECT Id, 'Edit', SUBSTRING_INDEX(SUBSTRING_INDEX(Users.MonitorIds, ',', n.n), ',', -1) value FROM Users CROSS JOIN (
SELECT a.N + b.N * 10 + 1 n FROM (SELECT 0 AS N UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) a ,(SELECT 0 AS N UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) b ORDER BY n ) n WHERE Users.Monitors='Edit' and Users.MonitorIds != '' AND n.n <= 1 + (LENGTH(Users.MonitorIds) - LENGTH(REPLACE(Users.MonitorIds, ',', ''))) ORDER BY value;

REPLACE INTO Monitors_Permissions (UserId,Permission, MonitorId)
SELECT Id, 'View', SUBSTRING_INDEX(SUBSTRING_INDEX(t.MonitorIds, ',', n.n), ',', -1) value FROM Users t CROSS JOIN (
SELECT a.N + b.N * 10 + 1 n FROM (SELECT 0 AS N UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) a ,(SELECT 0 AS N UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) b ORDER BY n ) n WHERE t.Monitors!='Edit' and t.MonitorIds != '' AND n.n <= 1 + (LENGTH(t.MonitorIds) - LENGTH(REPLACE(t.MonitorIds, ',', ''))) ORDER BY value;
SELECT Id, 'View', SUBSTRING_INDEX(SUBSTRING_INDEX(Users.MonitorIds, ',', n.n), ',', -1) value FROM Users CROSS JOIN (
SELECT a.N + b.N * 10 + 1 n FROM (SELECT 0 AS N UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) a ,(SELECT 0 AS N UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) b ORDER BY n ) n WHERE Users.Monitors!='Edit' and Users.MonitorIds != '' AND n.n <= 1 + (LENGTH(Users.MonitorIds) - LENGTH(REPLACE(Users.MonitorIds, ',', ''))) ORDER BY value;

DELETE FROM Monitors_Permissions WHERE MonitorID NOT IN (SELECT Id FROM Monitors);
ALTER TABLE Monitors_Permissions ADD CONSTRAINT Monitors_Permissions_ibfk_1 FOREIGN KEY (`MonitorId`) REFERENCES `Monitors` (`Id`) ON DELETE CASCADE;
79 changes: 79 additions & 0 deletions scripts/ZoneMinder/lib/ZoneMinder/Control.pm
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,92 @@ sub executeCommand {
&{$self->{$command}}($self, $params);
}

# Uses LWP get command and adds debugging
# if $$self{BaseURL} is defined then it will be prepended
sub get {
my $self = shift;
my $url = shift;
if (!$url) {
Error('No url specified in get');
return;
}
$url = $$self{BaseURL}.'/'.$url if $$self{BaseURL};
my $response = $self->{ua}->get($url);
Debug("Response from $url: ". $response->status_line . ' ' . $response->content);
return $response;
}

sub put {
my $self = shift;
my $url = shift;
if (!$url) {
Error('No url specified in put');
return;
}
$url = $$self{BaseURL}.'/'.$url if $$self{BaseURL};
my $req = HTTP::Request->new(PUT => $url);
my $content = shift;
if ( defined($content) ) {
$req->content_type('application/x-www-form-urlencoded; charset=UTF-8');
$req->content($content);
}
my $res = $self->{ua}->request($req);
if (!$res->is_success) {
Error($res->status_line);
} # end unless res->is_success
Debug('Response: '. $res->status_line . ' ' . $res->content);
return $res;
} # end sub put

sub printMsg {
my $self = shift;
my $msg = shift;
my $msg_len = length($msg);

Debug($msg.'['.$msg_len.']');
}
sub get_realm {
my $self = shift;
my $url = shift;
my $response = $self->get($url);
return 1 if $response->is_success();

if ($response->status_line() eq '401 Unauthorized' and defined $$self{username}) {
my $headers = $response->headers();
foreach my $k ( keys %$headers ) {
Debug("Initial Header $k => $$headers{$k}");
}
if ( $$headers{'www-authenticate'} ) {
foreach my $auth_header ( ref $$headers{'www-authenticate'} eq 'ARRAY' ? @{$$headers{'www-authenticate'}} : ($$headers{'www-authenticate'})) {
my ( $auth, $tokens ) = $auth_header =~ /^(\w+)\s+(.*)$/;
my %tokens = map { /(\w+)="?([^"]+)"?/i } split(', ', $tokens );
if ( $tokens{realm} ) {
if ( $$self{realm} ne $tokens{realm} ) {
$$self{realm} = $tokens{realm};
Debug("Changing REALM to $$self{realm}, $$self{host}:$$self{port}, $$self{realm}, $$self{username}, $$self{password}");
$self->{ua}->credentials("$$self{host}:$$self{port}", $$self{realm}, $$self{username}, $$self{password});
$response = $self->get($url);
if ( !$response->is_success() ) {
Debug('Authentication still failed after updating REALM' . $response->status_line);
$headers = $response->headers();
foreach my $k ( keys %$headers ) {
Debug("Initial Header $k => $$headers{$k}\n");
} # end foreach
} else {
return 1;
}
} else {
Error('Authentication failed, not a REALM problem');
}
} else {
Debug('Failed to match realm in tokens');
} # end if
} # end foreach auth header
} else {
debug('No headers line');
} # end if headers
} # end if not authen
} # end sub get_realm

1;
__END__
Expand Down
8 changes: 5 additions & 3 deletions scripts/zmfilter.pl.in
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ sub substituteTags {
my $filter = shift;
my $Event = @_ ? shift : undef;
my $attachments_ref = shift if @_;
my $options = @_ ? shift : {};

# First we'd better check what we need to get
# We have a filter and an event, do we need any more
Expand All @@ -658,7 +659,7 @@ sub substituteTags {
my $Monitor = $Event->Monitor() if $Event and $need_monitor;
my $Summary = $Monitor->Event_Summary() if $Monitor and $need_summary;

my $html = ($text =~ /<html/ ? !undef : undef);
my $html = exists $$options{html} ? $$options{html} : (($text =~ /<html/ ? !undef : undef));
# Do we need the image information too?
my $need_images = $text =~ /%(?:EPI1|EPIM|EPISNAP|EI1|EIM|EI1A|EIMA|EISNAP|EIMOD|EIMODG)%/;
my $first_alarm_frame = '';
Expand Down Expand Up @@ -913,15 +914,16 @@ sub sendSummaryEmail {
my $subject = substituteTags($$filter{EmailSubject}, $filter);
return 0 if !$subject;

my $html = $$filter{EmailBody} =~ /<html/ ? !undef : undef;
my ($body_head, $summary_part, $body_tail) = split(/%SUMMARY%/m, $$filter{EmailBody});
if (!$summary_part) {
Error('Failed finding summary part of email body');
return 0;
}
my @attachments;
my $body = substituteTags($body_head, $filter, undef, \@attachments);
my $body = substituteTags($body_head, $filter, undef, \@attachments, {html=>$html});
foreach my $event (@events) {
$body .= substituteTags($summary_part, $filter, $event, \@attachments);
$body .= substituteTags($summary_part, $filter, $event, \@attachments, {html=>$html});
}
return 0 if !$body;
$body .= $body_tail;
Expand Down
2 changes: 1 addition & 1 deletion src/zm_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ void Event::Run() {

// The idea is to process the queue no matter what so that all packets get processed.
// We only break if the queue is empty
while (!terminate_) {
while (!terminate_ and !zm_terminate) {
ZMLockedPacket *packet_lock = packetqueue->get_packet(packetqueue_it);
if (packet_lock) {
std::shared_ptr<ZMPacket> packet = packet_lock->packet_;
Expand Down
3 changes: 2 additions & 1 deletion src/zm_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ bool Monitor::connect() {
Debug(1, "ONVIF Endpoint: %s", proxyEvent.soap_endpoint);
if (proxyEvent.CreatePullPointSubscription(&request, response) != SOAP_OK) {
const char *detail = soap_fault_detail(soap);
Error("ONVIF Couldn't create subscription! %s, %s", soap_fault_string(soap), detail ? detail : "null");
Error("ONVIF Couldn't create subscription! fault:%s, detail:%s", soap_fault_string(soap), detail ? detail : "null");
_wsnt__Unsubscribe wsnt__Unsubscribe;
_wsnt__UnsubscribeResponse wsnt__UnsubscribeResponse;
proxyEvent.Unsubscribe(response.SubscriptionReference.Address, NULL, &wsnt__Unsubscribe, wsnt__UnsubscribeResponse);
Expand Down Expand Up @@ -2780,6 +2780,7 @@ int Monitor::Capture() {
if (decoding == DECODING_NONE) {
shared_data->last_write_index = index;
shared_data->last_write_time = std::chrono::system_clock::to_time_t(packet->timestamp);
packet->decoded = true;
}
Debug(2, "Have packet stream_index:%d ?= videostream_id: %d q.vpktcount %d event? %d image_count %d",
packet->packet->stream_index, video_stream_id, packetqueue.packet_count(video_stream_id), ( event ? 1 : 0 ), shared_data->image_count);
Expand Down

0 comments on commit f4e3005

Please sign in to comment.