Skip to content

Commit

Permalink
ncp-web: poweroff button
Browse files Browse the repository at this point in the history
  • Loading branch information
nachoparker committed Aug 17, 2017
1 parent ba95342 commit 3d80632
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 4 deletions.
7 changes: 6 additions & 1 deletion ncp-web/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@
<h1 class="hidden-visually">NextCloudPi</h1>
</div>
</a>
<?php echo file_get_contents( "/usr/local/etc/ncp-version" ) . "&nbsp;&nbsp;"; ?>
</div>
<div id="header-right">
<?php echo file_get_contents( "/usr/local/etc/ncp-version" ) . "&nbsp;&nbsp;"; ?>
<div id="poweroff">
<div id="expand">
<div id="expandDisplayName" class="icon-power-white"></div>
</div>
</div>
</div>
</header>

Expand Down
Binary file modified ncp-web/loading-small.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 13 additions & 2 deletions ncp-web/ncp-launcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

session_start();

if ( !$_POST['ref'] ) exit( '{ "output": "Invalid request" }' );

if ( $_POST['action'] == "cfgreq" )
{
if ( !$_POST['ref'] ) exit( '{ "output": "Invalid request" }' );

//CSFR check
$token = isset($_POST['csrf_token']) ? $_POST['csrf_token'] : '';
if ( empty($token) || !validateCSRFToken($token) )
Expand Down Expand Up @@ -64,6 +64,8 @@

else if ( $_POST['action'] == "launch" && $_POST['config'] )
{
if ( !$_POST['ref'] ) exit( '{ "output": "Invalid request" }' );

// CSRF check
$token = isset($_POST['csrf_token']) ? $_POST['csrf_token'] : '';
if ( empty($token) || !validateCSRFToken($token) )
Expand Down Expand Up @@ -100,6 +102,15 @@
echo json_encode( shell_exec( 'bash -c "sudo /home/www/ncp-launcher.sh ' . $file . '"' ) ) . ' }';
}

else if ( $_POST['action'] == "poweroff" )
{
// 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 &"' );
}

// License
//
// This script is free software; you can redistribute it and/or modify it
Expand Down
33 changes: 33 additions & 0 deletions ncp-web/ncp.css
Original file line number Diff line number Diff line change
Expand Up @@ -1084,3 +1084,36 @@ select {
.icon-close {
background-image:url('close.svg')
}

#power {
display: inline-block;
color: rgba(255, 255, 255, 0.7);
cursor: pointer;
flex: 0 0 auto;
}

#expand {
position: relative;
display: flex;
align-items: center;
padding: 7px 20px 6px 10px;
cursor: pointer;
}

#expand * {
cursor: pointer;
}

#expand:hover img,#expand:focus img,#expand:active img,#expand:hover #expandDisplayName,#expand:focus #expandDisplayName,#expand:active #expandDisplayName {
-ms-filter:'progid:DXImageTransform.Microsoft.Alpha(Opacity=100)';
opacity:1
}

.icon-power-white {
background-image: url('poweroff.svg');
}

#expand #expandDisplayName {
padding: 8px;
opacity: 0.6;
}
12 changes: 12 additions & 0 deletions ncp-web/ncp.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ $(function()
confLock = false;
}).error( errorMsg );
});

// Power-off button
$( '#poweroff' ).on('click', function(e)
{
// request
$.request('post', 'ncp-launcher.php', { action:'poweroff',
csrf_token: $( '#csrf-token' ).get( '.value' ) }).then(
function success( result )
{
$('#config-box-title').fill( "Shutting down..." );
}).error( errorMsg );
} );
});

// License
Expand Down
85 changes: 85 additions & 0 deletions ncp-web/poweroff.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion nextcloudpi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ cd $DIR
launch_script $1
EOF
chmod 700 /home/www/ncp-launcher.sh
echo "www-data ALL = NOPASSWD: /home/www/ncp-launcher.sh" >> /etc/sudoers
echo "www-data ALL = NOPASSWD: /home/www/ncp-launcher.sh , /sbin/halt" >> /etc/sudoers

# NEXTCLOUDPI MOTD
##########################################
Expand Down
3 changes: 3 additions & 0 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ cat $LATEST > $NOTIFIED
EOF
chmod +x /usr/local/bin/ncp-notify-update

# fix permissions for ncp-web: shutdown button
sed -i 's|www-data.*|www-data ALL = NOPASSWD: /home/www/ncp-launcher.sh , /sbin/halt|' /etc/sudoers

# License
#
# This script is free software; you can redistribute it and/or modify it
Expand Down

0 comments on commit 3d80632

Please sign in to comment.