blob: 6ebc839928272c05f461bab3beee17bf97056be7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
<?php
if (Request::any('action') === 'rebuild' && isLocalExecution()) {
if (Module::isAvailable('sysconfig')) {
SSHKey::getPrivateKey($regen);
if (!$regen) {
ConfigTgz::rebuildAllConfigs();
}
echo "OK";
}
exit(0);
}
/*
Needed POST-Parameters:
'token' -- for authentification
'action' -- which action should be performed (shutdown or reboot)
'clients' -- which are to reboot/shutdown (json encoded array!)
'timer' -- (optional) when to perform action in minutes (default value is 0)
*/
$ips = json_decode(Request::post('clients'));
$minutes = Request::post('timer', 0, 'int');
$clients = array();
foreach ($ips as $client) {
$clients[] = array("ip" => $client);
}
$apikey = Property::get("rebootcontrol_APIPOSTKEY", 'not-set');
if (!empty($apikey) && Request::post('token') === $apikey) {
if (Request::isPost()) {
if (Request::post('action') == 'shutdown') {
$shutdown = true;
$task = Taskmanager::submit("RemoteReboot", array("clients" => $clients, "shutdown" => $shutdown, "minutes" => $minutes));
echo $task["id"];
} else if (Request::post('action') == 'reboot') {
$shutdown = false;
$task = Taskmanager::submit("RemoteReboot", array("clients" => $clients, "shutdown" => $shutdown, "minutes" => $minutes));
echo $task["id"];
} else {
echo "Only action=shutdown and action=reboot available.";
}
} else {
echo "Only POST Method available.";
}
} else {
echo "Not authorized";
}
|