21 lines
550 B
PHP
21 lines
550 B
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
|
|
$body = json_decode(file_get_contents('php://input'), true) ?? [];
|
|
$action = $body['action'] ?? '';
|
|
|
|
$allowed = ['stop', 'shutdown', 'restart'];
|
|
if (!in_array($action, $allowed, true)) {
|
|
echo json_encode(['ok' => false, 'error' => 'invalid action']);
|
|
exit;
|
|
}
|
|
|
|
$cmd = match($action) {
|
|
'stop' => '/usr/local/sbin/mdcmd stop',
|
|
'shutdown' => '/sbin/shutdown -h now',
|
|
'restart' => '/sbin/shutdown -r now',
|
|
};
|
|
|
|
exec($cmd . ' > /dev/null 2>&1 &');
|
|
echo json_encode(['ok' => true]);
|