Add guarded reboot control
This commit is contained in:
@@ -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'] ?? '');
|
||||
|
||||
Reference in New Issue
Block a user