Merge branch 'master' of github.com:ZoneMinder/zoneminder

This commit is contained in:
Isaac Connor 2022-01-13 12:02:14 -05:00
commit 274ffd7da0
2 changed files with 44 additions and 42 deletions

View File

@ -273,6 +273,9 @@ sub zmDbDo {
if ( ! defined $rows ) { if ( ! defined $rows ) {
$sql =~ s/\?/'%s'/; $sql =~ s/\?/'%s'/;
Error(sprintf("Failed $sql :", @_).$dbh->errstr()); Error(sprintf("Failed $sql :", @_).$dbh->errstr());
} elsif ( ZoneMinder::Logger::logLevel() > INFO ) {
$sql =~ s/\?/'%s'/;
Debug(sprintf("Succeeded $sql : $rows rows affected", @_));
} }
return $rows; return $rows;
} }

View File

@ -2,7 +2,7 @@
# #
# ========================================================================== # ==========================================================================
# #
# ZoneMinder Update Script, $Date$, $Revision$ # ZoneMinder Update Script
# Copyright (C) 2001-2008 Philip Coombes # Copyright (C) 2001-2008 Philip Coombes
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
@ -31,29 +31,30 @@ zmupdate.pl -c,--check | -f,--freshen | -v<version>,--version=<version> [-u <dbu
=head1 DESCRIPTION =head1 DESCRIPTION
This script just checks what the most recent release of ZoneMinder is This script checks what the most recent release of ZoneMinder is
at the the moment. It will eventually be responsible for applying and at the the moment by downloading https://update.zoneminder.com/version.txt.
configuring upgrades etc, including on the fly upgrades. It can also apply and configure upgrades etc, including on the fly upgrades.
=head1 OPTIONS =head1 OPTIONS
-c, --check - Check for updated versions of ZoneMinder -c, --check - Check for updated versions of ZoneMinder.
-f, --freshen - Freshen the configuration in the database. Equivalent of old zmconfig.pl -noi If not interactive zmupdate.pl will stay running, checking every hour.
--migrate-events - Update database structures as per USE_DEEP_STORAGE setting. If interactive will try once, print out result and quit.
-v <version>, --version=<version> - Force upgrade to the current version from <version> -f, --freshen - Freshen the configuration in the database. Equivalent of old zmconfig.pl -noi
-u <dbuser>, --user=<dbuser> - Alternate DB user with privileges to alter DB --migrate-events - Update database structures as per USE_DEEP_STORAGE setting.
-p <dbpass>, --pass=<dbpass> - Password of alternate DB user with privileges to alter DB -v <version>, --version=<version> - Force upgrade to the current version from <version>
-s, --super - Use system maintenance account on debian based systems instead of unprivileged account -u <dbuser>, --user=<dbuser> - Alternate DB user with privileges to alter DB
-d <dir>, --dir=<dir> - Directory containing update files if not in default build location -p <dbpass>, --pass=<dbpass> - Password of alternate DB user with privileges to alter DB
-interactive - interact with the user -s, --super - Use system maintenance account on debian based systems instead of unprivileged account
-nointeractive - do not interact with the user -d <dir>, --dir=<dir> - Directory containing update files if not in default build location
-interactive - interact with the user
-nointeractive - do not interact with the user
=cut =cut
use strict; use strict;
use warnings;
use bytes; use bytes;
use version; use version;
use Crypt::Eksblowfish::Bcrypt;
use Data::Entropy::Algorithms qw(rand_bits);
# ========================================================================== # ==========================================================================
# #
@ -122,9 +123,8 @@ GetOptions(
) or pod2usage(-exitstatus => -1); ) or pod2usage(-exitstatus => -1);
my $dbh = zmDbConnect(undef, { mysql_multi_statements=>1 } ); my $dbh = zmDbConnect(undef, { mysql_multi_statements=>1 } );
if ( !$dbh ) { die "Unable to connect to db\n" if !$dbh;
die "Unable to connect to db\n";
}
$Config{ZM_DB_USER} = $dbUser; $Config{ZM_DB_USER} = $dbUser;
$Config{ZM_DB_PASS} = $dbPass; $Config{ZM_DB_PASS} = $dbPass;
# we escape dbpass with single quotes so that $ in the password has no effect, but dbpass could have a ' in it. # we escape dbpass with single quotes so that $ in the password has no effect, but dbpass could have a ' in it.
@ -144,8 +144,10 @@ if ( ($check + $freshen + $rename + $zoneFix + $migrateEvents + ($version?1:0))
pod2usage(-exitstatus => -1); pod2usage(-exitstatus => -1);
} }
if ( $check && $Config{ZM_CHECK_FOR_UPDATES} ) { if ($check and ($Config{ZM_CHECK_FOR_UPDATES} or $interactive) ) {
print('Update agent starting at '.strftime('%y/%m/%d %H:%M:%S', localtime() )."\n"); if (!$interactive) {
Info('Update agent starting at '.strftime('%y/%m/%d %H:%M:%S', localtime() )."\n");
}
my $currVersion = $Config{ZM_DYN_CURR_VERSION}; my $currVersion = $Config{ZM_DYN_CURR_VERSION};
my $lastVersion = $Config{ZM_DYN_LAST_VERSION}; my $lastVersion = $Config{ZM_DYN_LAST_VERSION};
@ -153,16 +155,14 @@ if ( $check && $Config{ZM_CHECK_FOR_UPDATES} ) {
if ( !$currVersion ) { if ( !$currVersion ) {
$currVersion = $Config{ZM_VERSION}; $currVersion = $Config{ZM_VERSION};
zmDbDo("UPDATE `Config` SET `Value` = ? WHERE `Name` = 'ZM_DYN_CURR_VERSION'", $currVersion);
my $sql = "update Config set Value = ? where Name = 'ZM_DYN_CURR_VERSION'";
my $sth = $dbh->prepare_cached($sql) or die("Can't prepare '$sql': ".$dbh->errstr());
my $res = $sth->execute($currVersion) or die("Can't execute: ".$sth->errstr());
$sth->finish();
} }
while ( 1 ) { while ( 1 ) {
my $now = time(); my $now = time();
if ( !$lastVersion || !$lastCheck || (($now-$lastCheck) > CHECK_INTERVAL) ) { if ( !$interactive and $lastVersion and $lastCheck and (($now-$lastCheck) <= CHECK_INTERVAL) ) {
Debug("Not checking for updates since we already have less than " . CHECK_INTERVAL . " seconds ago.");
} else {
Info('Checking for updates'); Info('Checking for updates');
use LWP::UserAgent; use LWP::UserAgent;
@ -175,21 +175,18 @@ if ( $check && $Config{ZM_CHECK_FOR_UPDATES} ) {
my $res = $ua->request($req); my $res = $ua->request($req);
if ( $res->is_success ) { if ( $res->is_success ) {
$lastVersion = $res->content; my $latestVersion = $res->content;
chomp($lastVersion); chomp($latestVersion);
$lastCheck = $now; $lastCheck = $now;
Info('Got version: '.$lastVersion); Info('Got version: '.$latestVersion);
my $lv_sql = 'UPDATE Config SET Value = ? WHERE Name = \'ZM_DYN_LAST_VERSION\''; zmDbDo('UPDATE Config SET Value = ? WHERE Name = \'ZM_DYN_LAST_VERSION\'', $latestVersion);
my $lv_sth = $dbh->prepare_cached($lv_sql) or die("Can't prepare '$lv_sql': ".$dbh->errstr()); zmDbDo('UPDATE Config SET Value = ? WHERE Name = \'ZM_DYN_LAST_CHECK\'', $lastCheck);
my $lv_res = $lv_sth->execute($lastVersion) or die("Can't execute: ".$lv_sth->errstr()); if ($interactive) {
$lv_sth->finish(); print("Last version $lastVersion, Latest version $latestVersion, our version " . ZM_VERSION."\n");
exit(0);
my $lc_sql = 'UPDATE Config SET Value = ? WHERE Name = \'ZM_DYN_LAST_CHECK\''; }
my $lc_sth = $dbh->prepare_cached($lc_sql) or die("Can't prepare '$lc_sql': ".$dbh->errstr());
my $lc_res = $lc_sth->execute($lastCheck) or die("Can't execute: ".$lc_sth->errstr());
$lc_sth->finish();
} else { } else {
Error('Error check failed: \''.$res->status_line().'\''); Error('Error check failed: \''.$res->status_line().'\'');
} }
@ -1044,14 +1041,16 @@ sub patchDB {
} # end sub patchDB } # end sub patchDB
sub migratePasswords { sub migratePasswords {
print ("Migratings passwords, if any...\n"); use Crypt::Eksblowfish::Bcrypt;
use Data::Entropy::Algorithms qw(rand_bits);
print("Migratings passwords, if any...\n");
my $sql = 'SELECT * FROM `Users`'; my $sql = 'SELECT * FROM `Users`';
my $sth = $dbh->prepare_cached($sql) or die( "Can't prepare '$sql': ".$dbh->errstr() ); my $sth = $dbh->prepare_cached($sql) or die( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute() or die("Can't execute: ".$sth->errstr()); my $res = $sth->execute() or die("Can't execute: ".$sth->errstr());
while( my $user = $sth->fetchrow_hashref() ) { while ( my $user = $sth->fetchrow_hashref() ) {
my $scheme = substr($user->{Password}, 0, 1); my $scheme = substr($user->{Password}, 0, 1);
if ($scheme eq '*') { if ($scheme eq '*') {
print ('-->'.$user->{Username}." password will be migrated\n"); print('-->'.$user->{Username}." password will be migrated\n");
my $salt = Crypt::Eksblowfish::Bcrypt::en_base64(rand_bits(16*8)); my $salt = Crypt::Eksblowfish::Bcrypt::en_base64(rand_bits(16*8));
my $settings = '$2a$10$'.$salt; my $settings = '$2a$10$'.$salt;
my $pass_hash = Crypt::Eksblowfish::Bcrypt::bcrypt($user->{Password},$settings); my $pass_hash = Crypt::Eksblowfish::Bcrypt::bcrypt($user->{Password},$settings);