Update
This commit is contained in:
@@ -31,9 +31,15 @@ class RaspberryDisplayController extends mfBaseController {
|
||||
case "reboot":
|
||||
$return = $this->restartRaspberryPi($this->request->displayID);
|
||||
break;
|
||||
case "rebootAll":
|
||||
$return = $this->restartAllRaspberryPis();
|
||||
break;
|
||||
case "getConfig":
|
||||
$return = $this->getConfig();
|
||||
break;
|
||||
case "displayPower":
|
||||
$return = $this->displayPower();
|
||||
break;
|
||||
default:
|
||||
$return = false;
|
||||
break;
|
||||
@@ -95,6 +101,21 @@ class RaspberryDisplayController extends mfBaseController {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function restartAllRaspberryPis() {
|
||||
$displays = RaspberryDisplayModel::getAll();
|
||||
$ipAddresses = [];
|
||||
foreach ($displays as $display) {
|
||||
if (in_array($display->ip_address, $ipAddresses)) {
|
||||
continue;
|
||||
}
|
||||
$ipAddresses[] = $display->ip_address;
|
||||
$ssh = new SSH2($display->ip_address, $this->port);
|
||||
$ssh->login($this->username, $this->password);
|
||||
$ssh->exec('sudo reboot now');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function getConfig() {
|
||||
$hostname = $this->request->hostname;
|
||||
|
||||
@@ -129,5 +150,26 @@ class RaspberryDisplayController extends mfBaseController {
|
||||
$this->layout()->setTemplate("VueViews/Vue");
|
||||
}
|
||||
|
||||
private function displayPower(): bool
|
||||
{
|
||||
$state = $this->request->state;
|
||||
$displays = RaspberryDisplayModel::getAll();
|
||||
$ipAddresses = [];
|
||||
foreach ($displays as $display) {
|
||||
if (in_array($display->ip_address, $ipAddresses)) {
|
||||
continue;
|
||||
}
|
||||
$ipAddresses[] = $display->ip_address;
|
||||
$ssh = new SSH2($display->ip_address, $this->port);
|
||||
$ssh->login($this->username, $this->password);
|
||||
if ($state === "on") {
|
||||
$ssh->exec('sudo bash /root/on.sh');
|
||||
} else {
|
||||
$ssh->exec('sudo bash /root/off.sh');
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user