This commit is contained in:
2024-06-03 07:51:44 +02:00
parent 97ee7d43b8
commit 90318bde75
3 changed files with 86 additions and 10 deletions

View File

@@ -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;
}
}