Skip to content

Commit

Permalink
Merge pull request #1412 from RaspAP/fix/sys-functions
Browse files Browse the repository at this point in the history
Ajaxifies system reboot + shutdown
  • Loading branch information
billz authored Oct 9, 2023
2 parents 03118b9 + c208ad9 commit c331ef9
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 11 deletions.
21 changes: 21 additions & 0 deletions ajax/system/sys_actions.php
Original file line number Diff line number Diff line change
@@ -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);
}

9 changes: 9 additions & 0 deletions app/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
9 changes: 0 additions & 9 deletions includes/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down
Binary file modified locale/en_US/LC_MESSAGES/messages.mo
Binary file not shown.
12 changes: 12 additions & 0 deletions locale/en_US/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,18 @@ msgstr "Reboot"
msgid "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!"
msgstr "System Rebooting Now!"

Expand Down
36 changes: 36 additions & 0 deletions templates/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,39 @@
</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>

4 changes: 2 additions & 2 deletions templates/system/basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
<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" data-toggle="modal" data-target="#system-confirm-reboot" value="<?php echo _("Reboot"); ?>" />
<input type="button" class="btn btn-warning" data-toggle="modal" data-target="#system-confirm-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>
Expand Down

0 comments on commit c331ef9

Please sign in to comment.