summaryrefslogtreecommitdiffstats
path: root/modules-available/serversetup-bwlp-ipxe/inc/ipxemenu.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2022-05-02 13:09:08 +0200
committerSimon Rettberg2022-05-02 13:09:08 +0200
commit672ead2f9d19a1651f5a87e11c1c04db5edacd08 (patch)
treeea1ab2f5e0300d90c80a295b589445007b149ee5 /modules-available/serversetup-bwlp-ipxe/inc/ipxemenu.inc.php
parent[locations/remoteaccess] Add option to veto remoteaccess mode (diff)
downloadslx-admin-672ead2f9d19a1651f5a87e11c1c04db5edacd08.tar.gz
slx-admin-672ead2f9d19a1651f5a87e11c1c04db5edacd08.tar.xz
slx-admin-672ead2f9d19a1651f5a87e11c1c04db5edacd08.zip
[serversetup-bwlp-ipxe] Force default boot entry to MiniLinux for dedicated PVSmgr
Diffstat (limited to 'modules-available/serversetup-bwlp-ipxe/inc/ipxemenu.inc.php')
-rw-r--r--modules-available/serversetup-bwlp-ipxe/inc/ipxemenu.inc.php73
1 files changed, 66 insertions, 7 deletions
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/ipxemenu.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/ipxemenu.inc.php
index 587d9200..deaa2fdb 100644
--- a/modules-available/serversetup-bwlp-ipxe/inc/ipxemenu.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/inc/ipxemenu.inc.php
@@ -3,8 +3,17 @@
class IPxeMenu
{
+ /**
+ * @var int ID of this menu, from DB
+ */
protected $menuid;
+ /**
+ * @var int 0 = disabled, otherwise, launch default option after timeout
+ */
public $timeoutMs;
+ /**
+ * @var string title to display above menu
+ */
public $title;
public $defaultEntryId;
/**
@@ -35,7 +44,7 @@ class IPxeMenu
{
$this->menuid = (int)$menu['menuid'];
$this->timeoutMs = (int)$menu['timeoutms'];
- $this->title = $menu['title'];
+ $this->title = (string)$menu['title'];
$this->defaultEntryId = $menu['defaultentryid'];
$res = Database::simpleQuery("SELECT e.menuentryid, e.entryid, e.refmenuid, e.hotkey, e.title,
e.hidden, e.sortval, e.md5pass, b.module, b.data AS bootentry, b.title AS betitle
@@ -52,12 +61,12 @@ class IPxeMenu
}
}
- public function title()
+ public function title(): string
{
return $this->title;
}
- public function timeoutMs()
+ public function timeoutMs(): int
{
return $this->timeoutMs;
}
@@ -65,7 +74,7 @@ class IPxeMenu
/**
* @return int Number of items in this menu
*/
- public function itemCount()
+ public function itemCount(): int
{
return count($this->items);
}
@@ -90,11 +99,57 @@ class IPxeMenu
return null;
}
+ private function maybeOverrideDefault(string $uuid)
+ {
+ $e = $this->defaultEntry();
+ // Shortcut - is already bwlp and timeout is reasonable (1-15s), do nothing
+ $defIsMl = $e !== null && substr($e->internalId(), 0, 3) === 'ml-';
+ $timeoutOk = $this->timeoutMs > 0 && $this->timeoutMs <= 15000;
+ if ($timeoutOk && $defIsMl)
+ return;
+ // No runmode module anyways
+ if (!Module::isAvailable('runmode'))
+ return;
+ $rm = RunMode::getRunMode($uuid);
+ // No runmode for this client, cannot be PVSmgr
+ if ($rm === false)
+ return;
+ // Is not pvsmgr
+ if ($rm['modeid'] !== 'roomplanner')
+ return;
+ // See if it's a dedicated station, if so make sure it boots into bwLehrpool
+ $data = json_decode($rm['modedata'], true);
+ if ($data['dedicatedmgr'] ?? false) {
+ if (!$defIsMl) {
+ $this->overrideDefaultToMinilinux();
+ }
+ if (!$timeoutOk) {
+ $this->timeoutMs = 5000;
+ }
+ }
+ }
+
+ /**
+ * Patch the menu to make sure bwLehrpool/"MiniLinux" is the default
+ * boot option, and set timeout to something reasonable. This is used
+ * for dedicated PVS managers, as they might not have a keyboard
+ * connected.
+ */
+ private function overrideDefaultToMinilinux()
+ {
+ foreach ($this->items as $item) {
+ if (substr($item->internalId(), 0, 3) === 'ml-') {
+ $this->defaultEntryId = $item->menuEntryId();
+ return;
+ }
+ }
+ }
+
/*
*
*/
- public static function forLocation($locationId) : IPxeMenu
+ public static function forLocation(int $locationId): IPxeMenu
{
$chain = null;
if (Module::isAvailable('locations')) {
@@ -132,13 +187,17 @@ class IPxeMenu
return new IPxeMenu($menu);
}
- public static function forClient($ip, $uuid) : IPxeMenu
+ public static function forClient(string $ip, string $uuid): IPxeMenu
{
$locationId = 0;
if (Module::isAvailable('locations')) {
$locationId = Location::getFromIpAndUuid($ip, $uuid);
}
- return self::forLocation($locationId);
+ $menu = self::forLocation($locationId);
+ // Super specialcase hackery: If this is a dedicated PVS, force the default to
+ // be bwlp/"minilinux"
+ $menu->maybeOverrideDefault($uuid);
+ return $menu;
}
}