Merge pull request #1412 from RaspAP/fix/sys-functions

Ajaxifies system reboot + shutdown
This commit is contained in:
Bill Zimmerman 2023-10-09 08:42:34 +02:00 committed by GitHub
commit c331ef9aaf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 80 additions and 11 deletions

View 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);
}

View file

@ -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(){ $(document).ready(function(){
$("#PanelManual").hide(); $("#PanelManual").hide();
}); });

View file

@ -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'])) { if (isset($_POST['RestartLighttpd'])) {

Binary file not shown.

View file

@ -752,6 +752,18 @@ msgstr "Reboot"
msgid "Shutdown" msgid "Shutdown"
msgstr "Shutdown" msgstr "Shutdown"
msgid "System reboot"
msgstr "System reboot"
msgid "System shutdown"
msgstr "System shutdown"
msgid "Reboot now? The system will be temporarily unavailable."
msgstr "Reboot now? The system will be temporarily unavailable."
msgid "Shutdown now? The system will be unavailable."
msgstr "Shutdown now? The system will be unavailable."
msgid "System Rebooting Now!" msgid "System Rebooting Now!"
msgstr "System Rebooting Now!" msgstr "System Rebooting Now!"

View file

@ -52,3 +52,39 @@
</div> </div>
</div> </div>
<!-- modal confirm-reboot-->
<div class="modal fade" id="system-confirm-reboot" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<div class="modal-title" id="ModalLabel"><i class="fas fa-sync mr-2"></i><?php echo _("System reboot"); ?></div>
</div>
<div class="modal-body">
<div class="col-md-12 mb-3 mt-1" id="system-reboot-message"><?php echo _("Reboot now? The system will be temporarily unavailable."); ?></div>
</div>
<div class="modal-footer">
<button type="button" data-message="<?php echo _("Close"); ?>" class="btn btn-outline-secondary" data-dismiss="modal"><?php echo _("Cancel"); ?></button>
<button type="button" id="js-sys-reboot" data-action="reboot" class="btn btn-outline-danger btn-delete"><?php echo _("Reboot"); ?></button>
</div>
</div>
</div>
</div>
<!-- modal confirm-shutdown-->
<div class="modal fade" id="system-confirm-shutdown" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<div class="modal-title" id="ModalLabel"><i class="fas fa-power-off mr-2"></i><?php echo _("System shutdown"); ?></div>
</div>
<div class="modal-body">
<div class="col-md-12 mb-3 mt-1" id="system-reboot-message"><?php echo _("Shutdown now? The system will be unavailable."); ?></div>
</div>
<div class="modal-footer">
<button type="button" data-message="<?php echo _("Close"); ?>" class="btn btn-outline-secondary" data-dismiss="modal"><?php echo _("Cancel"); ?></button>
<button type="button" id="js-sys-shutdown" data-action="shutdown" class="btn btn-outline-danger btn-delete"><?php echo _("Shutdown"); ?></button>
</div>
</div>
</div>
</div>

View file

@ -55,8 +55,8 @@ include('includes/sysstats.php');
<form action="system_info" method="POST"> <form action="system_info" method="POST">
<?php echo CSRFTokenFieldTag() ?> <?php echo CSRFTokenFieldTag() ?>
<?php if (!RASPI_MONITOR_ENABLED) : ?> <?php if (!RASPI_MONITOR_ENABLED) : ?>
<input type="submit" class="btn btn-warning" name="system_reboot" value="<?php echo _("Reboot"); ?>" /> <input type="button" class="btn btn-warning" data-toggle="modal" data-target="#system-confirm-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" data-toggle="modal" data-target="#system-confirm-shutdown" value="<?php echo _("Shutdown"); ?>" />
<?php endif ?> <?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> <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> </form>