Skip to content

Commit 570477c

Browse files
committed
Fix: Infinite restart loop when server restart is invoked from the UI
1 parent 9490fc9 commit 570477c

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

web/restart/system/index.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,29 @@
1111
exit();
1212
}
1313

14-
if ($_SESSION['user'] == 'admin') {
15-
if (!empty($_GET['hostname'])) {
16-
exec (HESTIA_CMD."v-restart-system yes", $output, $return_var);
17-
$_SESSION['error_msg'] = 'The system is going down for reboot NOW!';
14+
// If the session has the same reset token as the current request prevent restarting again.
15+
// This happens when the server is restarted, the admin panel goes down and the browser reloads
16+
// the /restart/index.php page once the server goes online causing restart loop.
17+
$reset_token_dir = '/var/tmp/';
18+
if (isset($_GET['system_reset_token']) && is_numeric($_GET['system_reset_token'])) {
19+
clearstatcache();
20+
$reset_token_file = $reset_token_dir . 'hst_reset_' . $_GET['system_reset_token'];
21+
if (file_exists($reset_token_file)) {
22+
unlink($reset_token_file);
23+
sleep(5);
24+
header('location: /list/server/');
25+
exit();
26+
}
27+
if ($_SESSION['user'] == 'admin') {
28+
if (!empty($_GET['hostname'])) {
29+
touch($reset_token_file);
30+
$_SESSION['error_msg'] = 'The system is going down for reboot NOW!';
31+
touch($reset_token_file . '_persistent');
32+
exec(HESTIA_CMD . "v-restart-system yes", $output, $return_var);
33+
}
34+
unset($output);
1835
}
19-
unset($output);
2036
}
2137

2238
header("Location: /list/server/");
23-
exit;
39+
exit();

web/templates/admin/list_services.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<a class="data-controls do_servicerestart ui-button danger cancel" title="<?=__('Restart')?>">
1111
<i class="do_servicerestart fas fa-undo status-icon red"></i>
1212
<?=__('Restart')?>
13-
<input type="hidden" name="servicerestart_url" value="/restart/system/?hostname=<?php echo $sys['sysinfo']['HOSTNAME'] ?>&token=<?=$_SESSION['token']?>" />
13+
<input type="hidden" name="servicerestart_url" value="/restart/system/?hostname=<?php echo $sys['sysinfo']['HOSTNAME'] ?>&token=<?=$_SESSION['token']?>&system_reset_token=<?php echo time(); ?>" />
1414
<div class="confirmation-text-servicerestart hidden" title="<?=__('Confirmation')?>">
1515
<p class="confirmation"><?=__('RESTART_CONFIRMATION', 'Server')?></p>
1616
</div>

0 commit comments

Comments
 (0)