Skip to content

Commit

Permalink
Merge branch 'ZoneMinder:master' into patch-474778
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorA100 authored Jan 10, 2025
2 parents 779a578 + b5ee966 commit 0159850
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 20 deletions.
1 change: 1 addition & 0 deletions .well-known/funding-manifest-urls
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://zoneminder.com/funding.json
31 changes: 26 additions & 5 deletions db/zm_update-1.37.27.sql
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,34 @@ SET @s = (SELECT IF(
PREPARE stmt FROM @s;
EXECUTE stmt;

REPLACE INTO Monitors_Permissions (UserId,Permission, MonitorId)
SET @s = (SELECT IF(
(SELECT COUNT(*)
FROM INFORMATION_SCHEMA.STATISTICS
WHERE table_name = 'Users'
AND table_schema = DATABASE()
AND column_name = 'MonitorIds'
) > 0,
"REPLACE INTO Monitors_Permissions (UserId,Permission, MonitorId)
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;
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",
"SELECT 'No MonitorIds in Users'"
));
PREPARE stmt FROM @s;
EXECUTE stmt;

REPLACE INTO Monitors_Permissions (UserId,Permission, MonitorId)
SET @s = (SELECT IF(
(SELECT COUNT(*)
FROM INFORMATION_SCHEMA.STATISTICS
WHERE table_name = 'Users'
AND table_schema = DATABASE()
AND column_name = 'MonitorIds'
) > 0,
"REPLACE INTO Monitors_Permissions (UserId,Permission, MonitorId)
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;

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",
"SELECT 'No MonitorIds in Users'"
));
PREPARE stmt FROM @s;
EXECUTE stmt;
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;
70 changes: 70 additions & 0 deletions funding.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"version": "v1.0.0",
"entity": {
"type": "organisation",
"role": "owner",
"name": "ZoneMinder Inc",
"email": "[email protected]",
"phone": "16478835483",
"description": "A Canadian corporation to hold and maintain the assets relating to the ZoneMinder CCTV project.",
"webpageUrl": {
"url": "https://www.zoneminder.com",
"wellKnown": "https://www.zoneminder.com/.well-known/funding-manifest-urls"
}
},
"projects": [
{
"guid": "zoneminder",
"name": "ZoneMinder",
"description": "A full-featured, open source, state-of-the-art video surveillance software system.",
"webpageUrl": {
"url": "https://www.zoneminder.com",
"wellKnown": "https://www.zoneminder.com/.well-known/funding-manifest-urls"
},
"repositoryUrl": {
"url": "https://github.com/zoneminder/zoneminder",
"wellKnown": "https://github.com/zoneminder/zoneminder/blob/master/.well-known/funding-manifest-urls"
},
"licenses": [
"GPL-v2"
],
"tags": [
"video",
"security",
"cameras"
]
}
],
"funding": {
"channels": [
{
"guid": "bank",
"type": "bank",
"address": "Account: 5212751 Transit No: 29842 Institution: 004",
"description": ""
},
{
"guid": "paypal",
"type": "payment-provider",
"address": "[email protected]",
"description": ""
}
],
"plans": [
{
"guid": "myplan",
"status": "active",
"name": "Infrastructure costs, support, development",
"description": "Not really sure this plan part is about.",
"amount": 10000,
"currency": "USD",
"frequency": "yearly",
"channels": [
"bank",
"paypal"
]
}
],
"history": []
}
}
5 changes: 3 additions & 2 deletions scripts/ZoneMinder/lib/ZoneMinder/Control.pm
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ sub get_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});
$self->{ua}->credentials($$self{address}?$$self{address}:"$$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);
Expand All @@ -417,9 +417,10 @@ sub get_realm {
} # end if
} # end foreach auth header
} else {
debug('No headers line');
Debug('No headers line');
} # end if headers
} # end if not authen
return undef;
} # end sub get_realm

1;
Expand Down
20 changes: 8 additions & 12 deletions scripts/ZoneMinder/lib/ZoneMinder/Control/Amcrest_HTTP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ sub open {

if ($self->{Monitor}->{ControlAddress}
and
$self->{Monitor}{ControlAddress} ne 'user:pass@ip'
$self->{Monitor}->{ControlAddress} ne 'user:pass@ip'
and
$self->{Monitor}{ControlAddress} ne 'user:port@ip'
$self->{Monitor}->{ControlAddress} ne 'user:port@ip'
) {

if ( $self->{Monitor}->{ControlAddress} !~ /^\w+:\/\// ) {
Expand All @@ -70,7 +70,7 @@ sub open {
}
my $uri = URI->new($self->{Monitor}->{ControlAddress});

$$self{realm} = 'Login to ' . $self->{Monitor}->{ControlDevice};
$$self{realm} = 'Login to ' . $self->{Monitor}->{ControlDevice} if $self->{Monitor}->{ControlDevice};
if ($self->{Monitor}->{ControlAddress}) {
if ( $uri->userinfo()) {
@$self{'username', 'password'} = $uri->userinfo() =~ /^(.*):(.*)$/;
Expand All @@ -85,8 +85,8 @@ sub open {
$$self{base_url} = $uri->canonical();
Debug('Using initial credentials for '.$uri->host_port().join(',', '', @$self{'realm', 'username', 'password'}).", base_url: $$self{base_url} auth:".$uri->authority());
}
} elsif ( $self->{Monitor}{Path}) {
my $uri = URI->new($self->{Monitor}{Path});
} elsif ( $self->{Monitor}->{Path}) {
my $uri = URI->new($self->{Monitor}->{Path});
Debug("Using Path for credentials: $self->{Monitor}{Path} " . $uri->userinfo());
if ( $uri->userinfo()) {
@$self{'username', 'password'} = $uri->userinfo() =~ /^(.*):(.*)$/;
Expand All @@ -102,7 +102,7 @@ sub open {
$$self{base_url} = $uri->canonical();
$$self{address} = $uri->host_port();
Debug("User auth $$self{username} $$self{password} " . $uri->authority() . ' ' . $uri->host_port());
$self->{ua}->credentials($uri->host_port(), @$self{'realm', 'username', 'password');
$self->{ua}->credentials($uri->host_port(), @$self{'realm', 'username', 'password'});
chomp $$self{base_url};
Debug("Base_url is ".$$self{base_url});
} else {
Expand All @@ -111,14 +111,10 @@ sub open {

my $url = $$self{base_url}.'cgi-bin/magicBox.cgi?action=getDeviceType';
# Detect REALM, has to be /cgi-bin/ptz.cgi because just / accepts no auth
my $res = $self->get_realm($url);

if ( $res->is_success ) {
if ($self->get_realm($url)) {
$self->{state} = 'open';
return !undef;
} else {
Error("Failed to get $url ".$res->status_line());
} # end if $res->status_line() eq '401 Unauthorized'
}

$self->{state} = 'closed';
return undef;
Expand Down
4 changes: 4 additions & 0 deletions src/zm_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1855,10 +1855,14 @@ void Monitor::UpdateFPS() {
last_camera_bytes = new_camera_bytes;
last_fps_time = now;

FPSeconds db_elapsed = now - last_status_time;
if (db_elapsed > Seconds(10)) {
std::string sql = stringtf(
"UPDATE LOW_PRIORITY Monitor_Status SET Status='Connected', CaptureFPS = %.2lf, CaptureBandwidth=%u, AnalysisFPS = %.2lf, UpdatedOn=NOW() WHERE MonitorId=%u",
new_capture_fps, new_capture_bandwidth, new_analysis_fps, id);
dbQueue.push(std::move(sql));
last_status_time = now;
}
} // now != last_fps_time
} // void Monitor::UpdateFPS()

Expand Down
1 change: 1 addition & 0 deletions src/zm_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ class Monitor : public std::enable_shared_from_this<Monitor> {
State state;
SystemTimePoint start_time;
SystemTimePoint last_fps_time;
SystemTimePoint last_status_time;
SystemTimePoint last_analysis_fps_time;
SystemTimePoint auto_resume_time;
unsigned int last_motion_score;
Expand Down
2 changes: 1 addition & 1 deletion src/zm_videostore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ bool VideoStore::open() {
video_out_stream->avg_frame_rate = video_in_stream->avg_frame_rate;
// Only set orientation if doing passthrough, otherwise the frame image will be rotated
Monitor::Orientation orientation = monitor->getOrientation();
if (orientation) {
if (orientation > 1) { // 1 is ROTATE_0
#if LIBAVCODEC_VERSION_CHECK(59, 37, 100, 37, 100)
int32_t* displaymatrix = static_cast<int32_t*>(av_malloc(sizeof(int32_t)*9));
Debug(3, "Have orientation %d", orientation);
Expand Down

0 comments on commit 0159850

Please sign in to comment.