From 4349106270b9599c8c46a2e9145d70b4233192ef Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 17 May 2022 12:26:33 -0400 Subject: [PATCH] Rough in zmeventtool with command deleteanalysisjpegs --- scripts/CMakeLists.txt | 2 + scripts/zmeventtool.pl.in | 116 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 scripts/zmeventtool.pl.in diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index 79df1f03a..4fa99eddd 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -19,6 +19,7 @@ configure_file(zmvideo.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmvideo.pl" @ONLY) configure_file(zmwatch.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmwatch.pl" @ONLY) configure_file(zmstats.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmstats.pl" @ONLY) configure_file(zmcamtool.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmcamtool.pl" @ONLY) +configure_file(zmeventtool.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmeventtool.pl" @ONLY) configure_file(zmsystemctl.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmsystemctl.pl" @ONLY) configure_file(zmtelemetry.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmtelemetry.pl" @ONLY) if(NOT ZM_NO_X10) @@ -54,6 +55,7 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/zmvideo.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmwatch.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmcamtool.pl" + "${CMAKE_CURRENT_BINARY_DIR}/zmeventtool.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmtelemetry.pl" "${CMAKE_CURRENT_BINARY_DIR}/zmstats.pl" DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}" PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) diff --git a/scripts/zmeventtool.pl.in b/scripts/zmeventtool.pl.in new file mode 100644 index 000000000..9c786fd44 --- /dev/null +++ b/scripts/zmeventtool.pl.in @@ -0,0 +1,116 @@ +#!@PERL_EXECUTABLE@ -wT +# +# ========================================================================== +# +# ZoneMinder Event Tool +# Copyright (C) 2022 ZoneMinder Inc +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# ========================================================================== + +=head1 NAME + +zmeventtool.pl - ZoneMinder tool to perform various actions on events + +=head1 SYNOPSIS + + zmeventtool.pl [--user= --pass=] command [list of event ids] + +=head1 DESCRIPTION + +This script performs various actions on an event. It is primarily meant to +be run from a filter but could be run manually. + +=head1 OPTIONS + + deletejpegs - Deletes all jpegs from the event directory + deleteanalysisjpegs - Deletes the analysis jpegs from the event directory + + --help - Print usage information. + --user= - Alternate dB user with privileges to alter dB. + --pass= - Password of alternate dB user with privileges to alter dB. + --version - Print version. + +=cut +use strict; +use bytes; + +@EXTRA_PERL_LIB@ +use ZoneMinder::Config qw(:all); +use ZoneMinder::Logger qw(:all); +use ZoneMinder::Database qw(:all); +use ZoneMinder::Event; +use DBI; +use Getopt::Long; +use autouse 'Pod::Usage'=>qw(pod2usage); + +$ENV{PATH} = '/bin:/usr/bin:/usr/local/bin'; +$ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL}; +delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; + +my $web_uid = (getpwnam( $Config{ZM_WEB_USER} ))[2]; +my $use_log = (($> == 0) || ($> == $web_uid)); + +logInit( toFile=>$use_log?DEBUG:NOLOG ); +logSetSignal(); + +my $help = 0; +my $dbUser = $Config{ZM_DB_USER}; +my $dbPass = $Config{ZM_DB_PASS}; +my $version = 0; + +GetOptions( + 'help' =>\$help, + 'user:s' =>\$dbUser, + 'pass:s' =>\$dbPass, + 'version' =>\$version +) or pod2usage(-exitstatus => -1); + +$Config{ZM_DB_USER} = $dbUser; +$Config{ZM_DB_PASS} = $dbPass; + +if ( $version ) { + print( ZoneMinder::Base::ZM_VERSION . "\n"); + exit(0); +} + +# Call the appropriate subroutine based on the params given on the commandline +if ($help or (@ARGV < 2) ) { + pod2usage(-exitstatus => -1); +} + +my $dbh = zmDbConnect(); + +my $command = shift @ARGV; +foreach my $event_id (@ARGV) { + if ( $event_id =~ /\D/ ) { + # Assume path to event, strip it + $event_id =~ s/.*\/(\d+)/$1/; + } + if ($command eq 'deleteanalysisjpegs') { + my $Event = ZoneMinder::Event->find_one(Id=>$event_id); + if ($Event) { + $Event->delete_analysis_jpegs(); + } else { + Warning("Event not found for $event_id"); + } + } +} + +zmDbDisconnect(); + +1; +__END__