From 91686f2aec69d9d32849d78bdabde170cc9e57cb Mon Sep 17 00:00:00 2001
From: theCalcaholic <3knoeppl@informatik.un-hamburg.de>
Date: Sat, 10 Feb 2018 01:11:24 +0100
Subject: [PATCH] Add dialog for shutdown.
---
changelog.md | 4 +++-
ncp-web/index.php | 9 ++++++++-
ncp-web/ncp-launcher.php | 12 ++++++++++--
ncp-web/ncp.css | 35 ++++++++++++++++++++++++++++++++++-
ncp-web/ncp.js | 34 +++++++++++++++++++++++++++++++++-
nextcloudpi.sh | 2 +-
update.sh | 4 ++++
7 files changed, 93 insertions(+), 7 deletions(-)
diff --git a/changelog.md b/changelog.md
index 1409e96ff..4f602d60c 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,5 +1,7 @@
-[v0.46.16](https://github.com/nextcloud/nextcloudpi/commit/93d58f2) (2018-02-16) remove redundant configuration from unattended upgrades
+[v0.46.17](https://github.com/nextcloud/nextcloudpi/commit/fbe639a) (2018-02-10) Add dialog for shutdown.
+
+[v0.46.16](https://github.com/nextcloud/nextcloudpi/commit/2d3fc6f) (2018-02-16) remove redundant configuration from unattended upgrades
[v0.46.15](https://github.com/nextcloud/nextcloudpi/commit/45c5608) (2018-02-16) lamp: enhance SSL security (chacha cypher), and OCSP stapling
diff --git a/ncp-web/index.php b/ncp-web/index.php
index 238b73d32..8ec35bd64 100644
--- a/ncp-web/index.php
+++ b/ncp-web/index.php
@@ -61,7 +61,7 @@
{
echo <<
-
+
NextCloudPi First Run
Click to start the configuration wizard
@@ -169,6 +169,13 @@
+
+
+
+
+
+
+
';
diff --git a/ncp-web/ncp-launcher.php b/ncp-web/ncp-launcher.php
index 6a0a346a2..318caa7af 100644
--- a/ncp-web/ncp-launcher.php
+++ b/ncp-web/ncp-launcher.php
@@ -107,13 +107,21 @@
echo '"' . $ret . '" }';
}
-else if ( $_POST['action'] == "poweroff" )
+else
{
// CSRF check
$token = isset($_POST['csrf_token']) ? $_POST['csrf_token'] : '';
if ( empty($token) || !validateCSRFToken($token) )
exit( '{ "output": "Unauthorized request. Try reloading the page" }' );
- shell_exec( 'bash -c "( sleep 2 && sudo halt ) 2>/dev/null >/dev/null &"' );
+
+ if ( $_POST['action'] == "poweroff" )
+ {
+ shell_exec( 'bash -c "( sleep 2 && sudo halt ) 2>/dev/null >/dev/null &"' );
+ }
+ else if ( $_POST['action'] == "reboot" )
+ {
+ shell_exec('bash -c "( sleep 2 && sudo reboot ) 2>/dev/null >/dev/null &"');
+ }
}
// License
diff --git a/ncp-web/ncp.css b/ncp-web/ncp.css
index 2ff5a793e..c032a0347 100644
--- a/ncp-web/ncp.css
+++ b/ncp-web/ncp.css
@@ -1172,7 +1172,7 @@ a#versionlink{
cursor:pointer;
}
-#first-run-wizard div {
+.dialog {
display:block;
background: white;
position:relative;
@@ -1197,3 +1197,36 @@ a#versionlink{
#wizard-btn {
cursor: pointer;
}
+
+#poweroff-dialog {
+ display: flex;
+ flex-direction: row;
+ flex-wrap: nowrap;
+ justify-content: space-around;
+ align-items: center;
+ width: 300px;
+ height: 60px;
+ background-color: white;
+ position: fixed;
+ top: 50%;
+ left: 50%;
+ transform: translate(-50%, -50%);
+ text-align: center;
+ z-index: 1;
+ line-height: 60px;
+}
+
+#poweroff-dialog button {
+ font-size: 2em;
+}
+
+#overlay {
+ display: block;
+ background-color: rgba(0, 0, 0, 0.5);
+ position: fixed;
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 100%;
+ z-index: 0;
+}
diff --git a/ncp-web/ncp.js b/ncp-web/ncp.js
index ba90ab3f8..3937761ab 100644
--- a/ncp-web/ncp.js
+++ b/ncp-web/ncp.js
@@ -37,7 +37,10 @@ $(function()
if (!!window.EventSource)
var source = new EventSource('ncp-output.php');
else
- $('#config-box-title').fill( "Browser not supported" );
+ $('#config-box-title').fill( "Browser not supported" );
+
+ $('#poweroff-dialog').hide();
+ $('#overlay').hide();
source.addEventListener('message', function(e)
{
@@ -158,6 +161,21 @@ $(function()
// Power-off button
$( '#poweroff' ).on('click', function(e)
{
+ //e.preventBubble = true;
+ $('#overlay').show();
+ $('#poweroff-dialog').show();
+ $('#overlay').on('click', function(ev)
+ {
+ $('#poweroff-dialog').hide();
+ $('#overlay').hide();
+ $('#overlay').off('click');
+ });
+ });
+
+ $( '#poweroff-option_shutdown' ).on('click', function(e)
+ {
+ $('#poweroff-dialog').hide();
+ $('#overlay').hide();
// request
$.request('post', 'ncp-launcher.php', { action:'poweroff',
csrf_token: $( '#csrf-token' ).get( '.value' ) }).then(
@@ -168,6 +186,20 @@ $(function()
}).error( errorMsg );
} );
+ $( '#poweroff-option_reboot' ).on('click', function(e)
+ {
+ $('#poweroff-dialog').hide();
+ $('#overlay').hide();
+ // request
+ $.request('post', 'ncp-launcher.php', { action:'reboot',
+ csrf_token: $( '#csrf-token' ).get( '.value' ) }).then(
+ function success( result )
+ {
+ $('#config-box-wrapper').hide();
+ $('#config-box-title').fill( "Rebooting..." );
+ }).error( errorMsg );
+ } );
+
// Wizard button
$( '.wizard-btn' ).on('click', function(e)
{
diff --git a/nextcloudpi.sh b/nextcloudpi.sh
index 7aebe4da1..03b1227aa 100644
--- a/nextcloudpi.sh
+++ b/nextcloudpi.sh
@@ -110,7 +110,7 @@ cd $DIR
launch_script $1
EOF
chmod 700 /home/www/ncp-launcher.sh
- echo "www-data ALL = NOPASSWD: /home/www/ncp-launcher.sh , /sbin/halt" >> /etc/sudoers
+ echo "www-data ALL = NOPASSWD: /home/www/ncp-launcher.sh , /sbin/halt, /sbin/reboot" >> /etc/sudoers
# NEXTCLOUDPI AUTO TRUSTED DOMAIN
mkdir -p /usr/lib/systemd/system
diff --git a/update.sh b/update.sh
index 007c42a67..e69deb89e 100755
--- a/update.sh
+++ b/update.sh
@@ -264,6 +264,10 @@ launch_script $1
EOF
chmod 700 /home/www/ncp-launcher.sh
+ # update sudoers permissions for the reboot command
+ grep -q reboot /etc/sudoers || \
+ sed -i 's|www-data.*|www-data ALL = NOPASSWD: /home/www/ncp-launcher.sh , /sbin/halt, /sbin/reboot|' /etc/sudoers
+
} # end - only live updates
exit 0