mirror of
https://github.com/unraid/webgui.git
synced 2026-04-24 02:58:57 -05:00
Change state using socket call to emhttpd
This commit is contained in:
@@ -14,17 +14,22 @@
|
||||
$device = $_POST['device'];
|
||||
$name = $_POST['name'];
|
||||
$action = $_POST['action'];
|
||||
$var = parse_ini_file('state/var.ini');
|
||||
$csrf = $var['csrf_token'];
|
||||
|
||||
function emhttpd($cmd) {
|
||||
global $csrf;
|
||||
$ch = curl_init("http://127.0.0.1/update.htm?$cmd&csrf_token=$csrf");
|
||||
curl_setopt_array($ch, [CURLOPT_UNIX_SOCKET_PATH => '/var/run/emhttpd.socket', CURLOPT_RETURNTRANSFER => true]);
|
||||
curl_exec($ch);
|
||||
curl_close($ch);
|
||||
}
|
||||
|
||||
if ($device=='New') {
|
||||
$cmd = $action=='up' ? 'S0' : ($action=='down' ? 'y' : false);
|
||||
if ($cmd && $name) exec("/usr/sbin/hdparm -$cmd /dev/$name >/dev/null 2>&1");
|
||||
} else {
|
||||
$disks = parse_ini_file('state/disks.ini',true);
|
||||
if ($name) {
|
||||
exec("/usr/local/sbin/mdcmd spin$action {$disks[$name]['idx']} >/dev/null 2>&1");
|
||||
} else {
|
||||
foreach ($disks as $disk) exec("/usr/local/sbin/mdcmd spin$device {$disk['idx']} >/dev/null 2>&1");
|
||||
}
|
||||
if ($name) emhttpd("cmdSpin$action=$name"); else emhttpd("cmdSpin{$device}All=true");
|
||||
}
|
||||
sleep(3); // delay for completion
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user