2014-08-10 21:47:11 +08:00
|
|
|
#!/usr/bin/pkexec /usr/bin/perl
|
|
|
|
#
|
|
|
|
# ==========================================================================
|
|
|
|
#
|
2015-04-16 12:37:49 +08:00
|
|
|
# ZoneMinder systemctl wrapper, $Date$, $Revision$
|
2014-08-10 21:47:11 +08:00
|
|
|
# Copyright (C) 2001-2008 Philip Coombes
|
|
|
|
#
|
|
|
|
# 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
|
2016-12-26 23:23:16 +08:00
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2014-08-10 21:47:11 +08:00
|
|
|
#
|
|
|
|
# ==========================================================================
|
2015-04-16 12:37:49 +08:00
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
zmsystemctl.pl - ZoneMinder systemctl wrapper
|
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
|
|
|
zmsystemctl.pl {start|stop|restart|version}
|
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
2015-06-21 05:13:40 +08:00
|
|
|
This script allows an unpriveledged user to start, stop, or restart the
|
|
|
|
zoneminder service on a system running systemd. It does this by redirecting
|
|
|
|
commands through pkexec, which checks the available polkit policy files. The
|
|
|
|
default policy file grants the system web account user permission. This can be
|
|
|
|
changed or expanded by modifying the policy file. See man polkit for details.
|
|
|
|
|
|
|
|
=head1 SEE ALSO
|
|
|
|
|
|
|
|
polkit(8), pkexec(1)
|
2015-04-16 12:37:49 +08:00
|
|
|
|
|
|
|
=cut
|
2014-08-10 21:47:11 +08:00
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
use bytes;
|
2015-04-16 12:37:49 +08:00
|
|
|
use autouse 'Pod::Usage'=>qw(pod2usage);
|
2014-08-20 06:19:44 +08:00
|
|
|
|
|
|
|
@EXTRA_PERL_LIB@
|
2016-05-20 00:08:25 +08:00
|
|
|
use ZoneMinder;
|
2014-08-10 21:47:11 +08:00
|
|
|
|
|
|
|
my $command = $ARGV[0];
|
|
|
|
|
2015-04-16 12:37:49 +08:00
|
|
|
if ( (scalar(@ARGV) == 1)
|
|
|
|
&& ($command =~ /^(start|stop|restart|version)$/ )
|
|
|
|
){
|
|
|
|
$command = $1;
|
2014-08-10 21:47:11 +08:00
|
|
|
} else {
|
2015-04-16 12:37:49 +08:00
|
|
|
pod2usage(-exitstatus => -1);
|
2014-08-10 21:47:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
my $path = qx(which systemctl);
|
|
|
|
chomp($path);
|
|
|
|
|
|
|
|
my $status = $? >> 8;
|
|
|
|
if ( !$path || $status ) {
|
2015-04-16 12:37:49 +08:00
|
|
|
Fatal( "Unable to determine systemctl executable. Is systemd in use?" );
|
2014-08-10 21:47:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Info( "Redirecting command through systemctl\n" );
|
|
|
|
exec("$path $command zoneminder");
|
|
|
|
|