Add guarded reboot control

This commit is contained in:
seo
2026-06-07 13:59:12 +09:00
parent d6b1322a8f
commit 4a02f7f354
6 changed files with 244 additions and 10 deletions
+45
View File
@@ -1751,6 +1751,51 @@ function control_api_dispatch(): void
]);
}
if ($action === 'reboot') {
$phrase = trim((string)($_POST['phrase'] ?? ''));
$password = (string)($_POST['password'] ?? '');
if ($phrase !== '재부팅') {
json_out([
'ok' => false,
'error' => 'bad_reboot_phrase',
'message' => '재부팅 확인 단어가 올바르지 않습니다.',
], 400);
}
if (!hash_equals(APP_PASSWORD, $password)) {
json_out([
'ok' => false,
'error' => 'bad_reboot_password',
'message' => '관리자 암호가 올바르지 않습니다.',
], 403);
}
add_fan_action(
'system_reboot',
null,
null,
'web reboot requested',
true
);
$result = sh(['/usr/sbin/reboot'], true, 5);
if ($result['code'] !== 0) {
json_out([
'ok' => false,
'error' => 'reboot_failed',
'message' => trim($result['out']) !== '' ? trim($result['out']) : 'reboot command failed',
], 500);
}
json_out([
'ok' => true,
'data' => [
'message' => 'reboot_requested',
],
]);
}
if ($action === 'wifi') {
$verb = (string)($_POST['verb'] ?? '');
$unit = (string)($_POST['unit'] ?? '');