From 0dd4a23770fb5af9b56e5124899fa491bb52818a Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 12 Apr 2019 09:36:30 -0400 Subject: [PATCH 1/7] Add Config for showing a system shutdown/restart option --- scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in index c6ec697f1..57bbc4aed 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in +++ b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in @@ -462,6 +462,15 @@ our @options = ( type => $types{string}, category => 'system', }, + { + name => 'ZM_SYSTEM_SHUTDOWN', + default => 'true', + description => 'Allow Admin users to power off or restart the system from the ZoneMinder UI.', + help => 'The system will need to have a polkit file installed to enable the apache user + to perform the shutdown or reboot', + type => $types{boolean}, + category => 'system', + }, { name => 'ZM_USE_DEEP_STORAGE', default => 'yes', From ec6d56fd7eab3285d2ba78b2c6867149b0441a09 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 12 Apr 2019 09:36:56 -0400 Subject: [PATCH 2/7] Add a translation for Shutdown --- web/lang/en_gb.php | 1 + 1 file changed, 1 insertion(+) diff --git a/web/lang/en_gb.php b/web/lang/en_gb.php index 4eb493630..3e7fcf3fd 100644 --- a/web/lang/en_gb.php +++ b/web/lang/en_gb.php @@ -689,6 +689,7 @@ $SLANG = array( 'Settings' => 'Settings', 'ShowFilterWindow' => 'Show Filter Window', 'ShowTimeline' => 'Show Timeline', + 'Shutdown' => 'Shutdown', 'SignalCheckColour' => 'Signal Check Colour', 'SignalCheckPoints' => 'Signal Check Points', 'Size' => 'Size', From d7747b3385223383c6eae95d0aacaac01b6adaab Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 12 Apr 2019 09:37:14 -0400 Subject: [PATCH 3/7] add a shutdown power button to the navbar --- web/skins/classic/includes/functions.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/web/skins/classic/includes/functions.php b/web/skins/classic/includes/functions.php index fa57411cd..cd97b9552 100644 --- a/web/skins/classic/includes/functions.php +++ b/web/skins/classic/includes/functions.php @@ -324,7 +324,9 @@ if (isset($_REQUEST['filter']['Query']['terms']['attr'])) { - + +power_settings_new' ) ?> + From 7b98dcbb9490e2650658d4b6666c5faf151ccb4f Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 12 Apr 2019 13:08:58 -0400 Subject: [PATCH 4/7] but the shutdown icon in a navbar-txt --- web/skins/classic/includes/functions.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/web/skins/classic/includes/functions.php b/web/skins/classic/includes/functions.php index cd97b9552..8de847f5b 100644 --- a/web/skins/classic/includes/functions.php +++ b/web/skins/classic/includes/functions.php @@ -321,12 +321,13 @@ if (isset($_REQUEST['filter']['Query']['terms']['attr'])) { - - -power_settings_new' ) ?> - + + + From 36336d67be91782345840491d2f5e5eec8646eae Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 12 Apr 2019 13:09:25 -0400 Subject: [PATCH 5/7] set width and height of shutdown window --- web/skins/classic/js/base.js | 1 + 1 file changed, 1 insertion(+) diff --git a/web/skins/classic/js/base.js b/web/skins/classic/js/base.js index b0a28dc96..5d044f229 100644 --- a/web/skins/classic/js/base.js +++ b/web/skins/classic/js/base.js @@ -60,6 +60,7 @@ var popupSizes = { 'preset': {'width': 300, 'height': 220}, 'server': {'width': 600, 'height': 405}, 'settings': {'width': 220, 'height': 235}, + 'shutdown': {'width': 400, 'height': 400}, 'state': {'width': 400, 'height': 170}, 'stats': {'width': 840, 'height': 200}, 'storage': {'width': 600, 'height': 405}, From 9421c0208d36cea58843738d65b00673fa1406fe Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 12 Apr 2019 14:48:47 -0400 Subject: [PATCH 6/7] Add instructions for enabling the web user to run shutdown --- scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in index 57bbc4aed..52dd2fb32 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in +++ b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in @@ -466,7 +466,10 @@ our @options = ( name => 'ZM_SYSTEM_SHUTDOWN', default => 'true', description => 'Allow Admin users to power off or restart the system from the ZoneMinder UI.', - help => 'The system will need to have a polkit file installed to enable the apache user + help => 'The system will need to have sudo installed and the following added to /etc/sudoers~~ + ~~ + @ZM_WEB_USER@ ALL=NOPASSWD: /sbin/shutdown~~ + ~~ to perform the shutdown or reboot', type => $types{boolean}, category => 'system', From 1a1c2db15f57536a5f1146831f96665c55320441 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 12 Apr 2019 14:55:56 -0400 Subject: [PATCH 7/7] add the shutdown view and actions --- web/includes/actions/shutdown.php | 44 ++++++++++++++++++ web/skins/classic/views/shutdown.php | 69 ++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 web/includes/actions/shutdown.php create mode 100644 web/skins/classic/views/shutdown.php diff --git a/web/includes/actions/shutdown.php b/web/includes/actions/shutdown.php new file mode 100644 index 000000000..f6d31b4f4 --- /dev/null +++ b/web/includes/actions/shutdown.php @@ -0,0 +1,44 @@ +&1", $output, $rc); + #exec('sudo -n /bin/systemctl poweroff -i 2>&1', $output, $rc); + ZM\Logger::Debug("Shutdown output $rc " . implode("\n",$output)); + #ZM\Logger::Debug("Shutdown output " . shell_exec('/bin/systemctl poweroff -i 2>&1')); + } else if ( $action == 'restart' ) { + $output = array(); + exec("sudo -n /sbin/shutdown -r $when 2>&1", $output); + #exec('sudo -n /bin/systemctl reboot -i 2>&1', $output); + ZM\Logger::Debug("Shutdown output " . implode("\n",$output)); + } else if ( $action == 'cancel' ) { + $output = array(); + exec('sudo /sbin/shutdown -c 2>&1', $output); + } +} # end if action +?> diff --git a/web/skins/classic/views/shutdown.php b/web/skins/classic/views/shutdown.php new file mode 100644 index 000000000..5e032cd1c --- /dev/null +++ b/web/skins/classic/views/shutdown.php @@ -0,0 +1,69 @@ + + +
+ +
+
+ +'.implode('
', $output).'

'; + } + if ( isset($_POST['when']) and ($_POST['when'] != 'NOW') and ($action != 'cancel') ) { + echo '

You may cancel this shutdown by clicking '.translate('Cancel').'

'; + } +?> +

Warning

+ This command will either shutdown or restart all ZoneMinder Servers
+

+

+ + +

+
+ + + + + + +
+
+
+
+ +