diff options
author | theCalcaholic <3knoeppl@informatik.un-hamburg.de> | 2018-02-10 03:11:24 +0300 |
---|---|---|
committer | nachoparker <nacho@ownyourbits.com> | 2018-02-18 22:14:00 +0300 |
commit | f1d41e38464697da8b7acd70e03a900061b477ba (patch) | |
tree | 59839d0ae3e23072892e6f989d77dc5d669015ae | |
parent | 26afda9281cfbafba87789d395783c3b72d745c2 (diff) |
Add dialog for shutdown.v0.46.17
-rw-r--r-- | changelog.md | 4 | ||||
-rw-r--r-- | ncp-web/index.php | 9 | ||||
-rw-r--r-- | ncp-web/ncp-launcher.php | 12 | ||||
-rw-r--r-- | ncp-web/ncp.css | 35 | ||||
-rw-r--r-- | ncp-web/ncp.js | 34 | ||||
-rw-r--r-- | nextcloudpi.sh | 2 | ||||
-rwxr-xr-x | update.sh | 4 |
7 files changed, 93 insertions, 7 deletions
diff --git a/changelog.md b/changelog.md index 1409e96f..4f602d60 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 238b73d3..8ec35bd6 100644 --- a/ncp-web/index.php +++ b/ncp-web/index.php @@ -61,7 +61,7 @@ { echo <<<HTML <div id="first-run-wizard"> - <div> + <div class='dialog'> <br> <h2 id="config-box-title">NextCloudPi First Run</h2> <p>Click to start the configuration wizard</p> @@ -169,6 +169,13 @@ HTML; </div> + <div id="poweroff-dialog" class='dialog primary hidden'> + <button id='poweroff-option_shutdown' class='primary'>shut down</button> + <button id='poweroff-option_reboot' class='primary'>reboot</button> + </div> + + <div id='overlay' class="hidden"></div> + <?php include ('csrf.php'); echo '<input type="hidden" id="csrf-token" name="csrf-token" value="' . getCSRFToken() . '"/>'; diff --git a/ncp-web/ncp-launcher.php b/ncp-web/ncp-launcher.php index 6a0a346a..318caa7a 100644 --- a/ncp-web/ncp-launcher.php +++ b/ncp-web/ncp-launcher.php @@ -107,13 +107,21 @@ else if ( $_POST['action'] == "launch" && $_POST['config'] ) 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 2ff5a793..c032a034 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 ba90ab3f..3937761a 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 7aebe4da..03b1227a 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 @@ -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 |