mirror of
https://github.com/RaspAP/raspap-webgui.git
synced 2024-11-25 09:00:25 +00:00
Ajaxify system reboot/shutdown
This commit is contained in:
parent
2ac5f94594
commit
21f703b5a9
4 changed files with 32 additions and 11 deletions
21
ajax/system/sys_actions.php
Normal file
21
ajax/system/sys_actions.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
require '../../includes/csrf.php';
|
||||
|
||||
$action = escapeshellcmd($_POST['a']);
|
||||
|
||||
if (isset($action)) {
|
||||
|
||||
switch($action) {
|
||||
case "reboot":
|
||||
$response = shell_exec("sudo /sbin/reboot");
|
||||
break;
|
||||
case "shutdown":
|
||||
$response = shell_exec("sudo /sbin/shutdown -h now");
|
||||
break;
|
||||
default:
|
||||
$response = 'Unknown action: '.$action;
|
||||
}
|
||||
echo json_encode($response);
|
||||
}
|
||||
|
|
@ -354,6 +354,15 @@ $('#js-system-reset-confirm').on('click', function (e) {
|
|||
});
|
||||
});
|
||||
|
||||
$('#js-sys-reboot, #js-sys-shutdown').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
||||
var action = $(this).data('action');
|
||||
$.post('ajax/system/sys_actions.php?',{'a': action, 'csrf_token': csrfToken},function(data){
|
||||
var response = JSON.parse(data);
|
||||
});
|
||||
});
|
||||
|
||||
$(document).ready(function(){
|
||||
$("#PanelManual").hide();
|
||||
});
|
||||
|
|
|
@ -47,15 +47,6 @@ function DisplaySystem(&$extraFooterScripts)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['system_reboot'])) {
|
||||
$status->addMessage("System Rebooting Now!", "warning", false);
|
||||
$result = shell_exec("sudo /sbin/reboot");
|
||||
}
|
||||
if (isset($_POST['system_shutdown'])) {
|
||||
$status->addMessage("System Shutting Down Now!", "warning", false);
|
||||
$result = shell_exec("sudo /sbin/shutdown -h now");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['RestartLighttpd'])) {
|
||||
|
|
|
@ -55,8 +55,8 @@ include('includes/sysstats.php');
|
|||
<form action="system_info" method="POST">
|
||||
<?php echo CSRFTokenFieldTag() ?>
|
||||
<?php if (!RASPI_MONITOR_ENABLED) : ?>
|
||||
<input type="submit" class="btn btn-warning" name="system_reboot" value="<?php echo _("Reboot"); ?>" />
|
||||
<input type="submit" class="btn btn-warning" name="system_shutdown" value="<?php echo _("Shutdown"); ?>" />
|
||||
<input type="button" class="btn btn-warning" id="js-sys-reboot" data-action="reboot" value="<?php echo _("Reboot"); ?>" />
|
||||
<input type="button" class="btn btn-warning" id="js-sys-shutdown" data-action="shutdown" value="<?php echo _("Shutdown"); ?>" />
|
||||
<?php endif ?>
|
||||
<button type="button" onClick="window.location.reload();" class="btn btn-outline btn-primary"><i class="fas fa-sync-alt"></i> <?php echo _("Refresh") ?></a>
|
||||
</form>
|
||||
|
|
Loading…
Reference in a new issue