Skip to content

Commit

Permalink
Add dialog for shutdown.
Browse files Browse the repository at this point in the history
  • Loading branch information
theCalcaholic authored and nacho committed Feb 18, 2018
1 parent 4bdbf93 commit 91686f2
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 7 deletions.
4 changes: 3 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
9 changes: 8 additions & 1 deletion ncp-web/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -169,6 +169,13 @@

</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() . '"/>';
Expand Down
12 changes: 10 additions & 2 deletions ncp-web/ncp-launcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 34 additions & 1 deletion ncp-web/ncp.css
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ a#versionlink{
cursor:pointer;
}

#first-run-wizard div {
.dialog {
display:block;
background: white;
position:relative;
Expand All @@ -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;
}
34 changes: 33 additions & 1 deletion ncp-web/ncp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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(
Expand All @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion nextcloudpi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 91686f2

Please sign in to comment.