summaryrefslogtreecommitdiffstats
path: root/modules-available/serversetup-bwlp-ipxe
diff options
context:
space:
mode:
authorSimon Rettberg2023-11-14 14:47:55 +0100
committerSimon Rettberg2023-11-14 14:47:55 +0100
commit06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0 (patch)
tree7e5493b102074672d8cfd8fe1a61e49f080edbe8 /modules-available/serversetup-bwlp-ipxe
parentUpdate phpstorm config (diff)
downloadslx-admin-06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0.tar.gz
slx-admin-06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0.tar.xz
slx-admin-06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0.zip
Add function param/return types, fix a lot more phpstorm complaints
Diffstat (limited to 'modules-available/serversetup-bwlp-ipxe')
-rw-r--r--modules-available/serversetup-bwlp-ipxe/inc/bootentry.inc.php95
-rw-r--r--modules-available/serversetup-bwlp-ipxe/inc/bootentryhook.inc.php53
-rw-r--r--modules-available/serversetup-bwlp-ipxe/inc/execdata.inc.php7
-rw-r--r--modules-available/serversetup-bwlp-ipxe/inc/ipxe.inc.php146
-rw-r--r--modules-available/serversetup-bwlp-ipxe/inc/ipxebuilder.inc.php16
-rw-r--r--modules-available/serversetup-bwlp-ipxe/inc/ipxemenu.inc.php19
-rw-r--r--modules-available/serversetup-bwlp-ipxe/inc/localboot.inc.php3
-rw-r--r--modules-available/serversetup-bwlp-ipxe/inc/menuentry.inc.php49
-rw-r--r--modules-available/serversetup-bwlp-ipxe/inc/pxelinux.inc.php36
-rw-r--r--modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderbase.inc.php49
-rw-r--r--modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderbash.inc.php20
-rw-r--r--modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderipxe.inc.php45
-rw-r--r--modules-available/serversetup-bwlp-ipxe/page.inc.php73
13 files changed, 292 insertions, 319 deletions
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/bootentry.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/bootentry.inc.php
index 2abb5153..919861f0 100644
--- a/modules-available/serversetup-bwlp-ipxe/inc/bootentry.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/inc/bootentry.inc.php
@@ -22,17 +22,13 @@ abstract class BootEntry
$this->internalId = $internalId;
}
- public abstract function supportsMode($mode);
+ public abstract function supportsMode(string $mode): bool;
- /**
- * @param ScriptBuilderBase $builder
- * @return string
- */
- public abstract function toScript($builder);
+ public abstract function toScript(ScriptBuilderBase $builder): string;
- public abstract function toArray();
+ public abstract function toArray(): array;
- public abstract function addFormFields(&$array);
+ public abstract function addFormFields(array &$array): void;
public function internalId(): string
{
@@ -48,14 +44,14 @@ abstract class BootEntry
*
* @param string $module module this entry belongs to, or special values .script/.exec
* @param string $data serialized entry data
- * @return BootEntry|null instance representing boot entry, null on error
+ * @return ?BootEntry instance representing boot entry, null on error
*/
- public static function fromJson($module, $data)
+ public static function fromJson(string $module, string $data): ?BootEntry
{
if ($module[0] !== '.') {
// Hook from other module
$hook = Hook::loadSingle($module, 'ipxe-bootentry');
- if ($hook === false) {
+ if ($hook === null) {
error_log('Module ' . $module . ' doesnt have an ipxe-bootentry hook');
return null;
}
@@ -64,9 +60,9 @@ abstract class BootEntry
return null;
return $ret->getBootEntry($data);
}
- if (is_string($data)) {
- $data = json_decode($data, true);
- }
+ $data = json_decode($data, true);
+ if (!is_array($data))
+ return null;
if ($module === '.script') {
return new CustomBootEntry($data);
}
@@ -79,12 +75,12 @@ abstract class BootEntry
return null;
}
- public static function forMenu($menuId)
+ public static function forMenu(int $menuId): MenuBootEntry
{
return new MenuBootEntry($menuId);
}
- public static function newStandardBootEntry($initData, $efi = false, $arch = false, string $internalId = '')
+ public static function newStandardBootEntry($initData, $efi = false, $arch = false, string $internalId = ''): ?StandardBootEntry
{
$ret = new StandardBootEntry($initData, $efi, $arch, $internalId);
$list = [];
@@ -104,7 +100,7 @@ abstract class BootEntry
return $ret;
}
- public static function newCustomBootEntry($initData)
+ public static function newCustomBootEntry($initData): ?CustomBootEntry
{
if (!is_array($initData) || empty($initData))
return null;
@@ -114,15 +110,14 @@ abstract class BootEntry
/**
* Return a BootEntry instance from database with the given id.
*
- * @param string $id
- * @return BootEntry|null|false false == unknown id, null = unknown entry type, BootEntry instance on success
+ * @return ?BootEntry null = unknown entry type, BootEntry instance on success
*/
- public static function fromDatabaseId($id)
+ public static function fromDatabaseId(string $id): ?BootEntry
{
$row = Database::queryFirst("SELECT module, data FROM serversetup_bootentry
WHERE entryid = :id LIMIT 1", ['id' => $id]);
if ($row === false)
- return false;
+ return null;
return self::fromJson($row['module'], $row['data']);
}
@@ -132,7 +127,7 @@ abstract class BootEntry
*
* @return BootEntry[] all existing BootEntries
*/
- public static function getAll()
+ public static function getAll(): array
{
$res = Database::simpleQuery("SELECT entryid, module, data FROM serversetup_bootentry");
$ret = [];
@@ -158,13 +153,13 @@ class StandardBootEntry extends BootEntry
*/
protected $efi;
/**
- * @var string BootEntry Constants above
+ * @var ?string BootEntry Constants above
*/
protected $arch;
const KEYS = ['executable', 'initRd', 'commandLine', 'replace', 'imageFree', 'autoUnload', 'resetConsole', 'dhcpOptions'];
- public function __construct($data, $efi = false, $arch = false, string $internalId = '')
+ public function __construct($data, $efi = false, ?string $arch = null, string $internalId = '')
{
parent::__construct($internalId);
$this->pcbios = new ExecData();
@@ -239,10 +234,7 @@ class StandardBootEntry extends BootEntry
}
}
- /**
- * @param PxeSection $data
- */
- private function fromPxeMenu($data)
+ private function fromPxeMenu(PxeSection $data): void
{
$bios = $this->pcbios;
$bios->executable = $data->kernel;
@@ -266,12 +258,12 @@ class StandardBootEntry extends BootEntry
$bios->commandLine = trim(preg_replace('/\s+/', ' ', $bios->commandLine));
}
- public function arch()
+ public function arch(): ?string
{
return $this->arch;
}
- public function supportsMode($mode)
+ public function supportsMode(string $mode): bool
{
if ($mode === $this->arch || $this->arch === BootEntry::AGNOSTIC)
return true;
@@ -282,7 +274,7 @@ class StandardBootEntry extends BootEntry
return false;
}
- public function toScript($builder)
+ public function toScript(ScriptBuilderBase $builder): string
{
if ($this->arch === BootEntry::AGNOSTIC) // Same as below, could construct fall-through but this is more clear
return $builder->execDataToScript($this->pcbios, null, null);
@@ -291,7 +283,7 @@ class StandardBootEntry extends BootEntry
$this->supportsMode(BootEntry::EFI) ? $this->efi : null);
}
- public function addFormFields(&$array)
+ public function addFormFields(array &$array): void
{
$array[$this->arch . '_selected'] = 'selected';
$array['entries'][] = $this->pcbios->toFormFields(BootEntry::BIOS);
@@ -299,7 +291,10 @@ class StandardBootEntry extends BootEntry
$array['exec_checked'] = 'checked';
}
- public function toArray()
+ /**
+ * @return array{PCBIOS: array, EFI: array, arch: string}
+ */
+ public function toArray(): array
{
return [
BootEntry::BIOS => $this->pcbios->toArray(),
@@ -314,7 +309,7 @@ class CustomBootEntry extends BootEntry
/**
* @var string iPXE
*/
- protected $ipxe;
+ protected $ipxe = '';
protected $bash;
@@ -331,12 +326,12 @@ class CustomBootEntry extends BootEntry
}
}
- public function supportsMode($mode)
+ public function supportsMode(string $mode): bool
{
return true;
}
- public function toScript($builder)
+ public function toScript(ScriptBuilderBase $builder): string
{
if ($builder instanceof ScriptBuilderIpxe)
return $this->ipxe;
@@ -345,7 +340,7 @@ class CustomBootEntry extends BootEntry
return '';
}
- public function addFormFields(&$array)
+ public function addFormFields(array &$array): void
{
$array['entry'] = [
'script' => $this->ipxe,
@@ -353,7 +348,10 @@ class CustomBootEntry extends BootEntry
$array['script_checked'] = 'checked';
}
- public function toArray()
+ /**
+ * @return array{script: string}
+ */
+ public function toArray(): array
{
return ['script' => $this->ipxe];
}
@@ -361,31 +359,32 @@ class CustomBootEntry extends BootEntry
class MenuBootEntry extends BootEntry
{
+ /** @var int */
protected $menuId;
- public function __construct($menuId)
+ public function __construct(int $menuId)
{
parent::__construct('menu-' . $menuId);
$this->menuId = $menuId;
}
- public function supportsMode($mode)
+ public function supportsMode(string $mode): bool
{
return true;
}
- public function toScript($builder)
+ public function toScript(ScriptBuilderBase $builder): string
{
- $menu = IPxeMenu::get($this->menuId);
+ $menu = IPxeMenu::get($this->menuId, true);
return $builder->menuToScript($menu);
}
- public function toArray()
+ public function toArray(): array
{
return [];
}
- public function addFormFields(&$array)
+ public function addFormFields(array &$array): void
{
}
}
@@ -401,21 +400,21 @@ class SpecialBootEntry extends BootEntry
parent::__construct('special-' . $this->type);
}
- public function supportsMode($mode)
+ public function supportsMode(string $mode): bool
{
return true;
}
- public function toScript($builder)
+ public function toScript(ScriptBuilderBase $builder): string
{
return $builder->getSpecial($this->type);
}
- public function toArray()
+ public function toArray(): array
{
return [];
}
- public function addFormFields(&$array) { }
+ public function addFormFields(array &$array): void { }
} \ No newline at end of file
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/bootentryhook.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/bootentryhook.inc.php
index 060b3903..ab55c888 100644
--- a/modules-available/serversetup-bwlp-ipxe/inc/bootentryhook.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/inc/bootentryhook.inc.php
@@ -6,41 +6,37 @@ abstract class BootEntryHook
/**
* @var string -- set by ipxe, not module implementing hook
*/
- public $moduleId;
+ public $moduleId = '';
/**
* @var string -- set by ipxe, not module implementing hook
*/
- public $checked;
+ public $checked = '';
- private $selectedId;
+ private $selectedId = '';
private $data = [];
/**
* @return string
*/
- public abstract function name();
+ public abstract function name(): string;
/**
* @return HookExtraField[]
*/
- public abstract function extraFields();
+ public abstract function extraFields(): array;
- /**
- * @param string $id
- * @return bool
- */
- public abstract function isValidId($id);
+ public abstract function isValidId(string $id): bool;
/**
* @return HookEntryGroup[]
*/
- protected abstract function groupsInternal();
+ protected abstract function groupsInternal(): array;
/**
* @return HookEntryGroup[]
*/
- public final function groups()
+ public final function groups(): array
{
$groups = $this->groupsInternal();
foreach ($groups as $group) {
@@ -54,16 +50,13 @@ abstract class BootEntryHook
}
/**
- * @param $id
* @return BootEntry|null the actual boot entry instance for given entry, null if invalid id
*/
- public abstract function getBootEntryInternal($localData);
+ public abstract function getBootEntryInternal(array $localData): ?BootEntry;
- public final function getBootEntry($data)
+ public final function getBootEntry(string $jsonString): ?BootEntry
{
- if (!is_array($data)) {
- $data = json_decode($data, true);
- }
+ $data = json_decode($jsonString, true);
return $this->getBootEntryInternal($data);
}
@@ -71,7 +64,7 @@ abstract class BootEntryHook
* @param string $mixed either the plain ID if the entry to be marked as selected, or the JSON string representing
* the entire entry, which must have a key called 'id' that will be used as the ID then.
*/
- public function setSelected($mixed)
+ public function setSelected(string $mixed): void
{
$json = @json_decode($mixed, true);
if (is_array($json)) {
@@ -86,12 +79,15 @@ abstract class BootEntryHook
/**
* @return string ID of entry that was marked as selected by setSelected()
*/
- public function getSelected()
+ public function getSelected(): string
{
return $this->selectedId;
}
- public function renderExtraFields()
+ /**
+ * @return HookExtraField[]
+ */
+ public function renderExtraFields(): array
{
$list = $this->extraFields();
foreach ($list as $entry) {
@@ -144,14 +140,7 @@ class HookEntry
*/
public $selected;
- /**
- * HookEntry constructor.
- *
- * @param string $id
- * @param string $name
- * @param bool $valid
- */
- public function __construct($id, $name, $valid)
+ public function __construct(string $id, string $name, bool $valid)
{
$this->id = $id;
$this->name = $name;
@@ -182,7 +171,7 @@ class HookExtraField
*/
public $hook;
- public function __construct($name, $type, $default)
+ public function __construct(string $name, string $type, $default)
{
$this->name = $name;
$this->type = $type;
@@ -203,10 +192,10 @@ class HookExtraField
return $val;
}
- public function html()
+ public function html(): string
{
$fieldId = 'extra-' . $this->hook->moduleId . '-' . $this->name;
- $fieldText = htmlspecialchars(Dictionary::translateFileModule($this->hook->moduleId, 'module', 'ipxe-' . $this->name, true));
+ $fieldText = htmlspecialchars(Dictionary::translateFileModule($this->hook->moduleId, 'module', 'ipxe-' . $this->name));
if (is_array($this->type)) {
$out = '<label for="' . $fieldId . '">' . $fieldText . '</label><select class="form-control" name="' . $fieldId . '" id="' . $fieldId . '">';
foreach ($this->type as $entry) {
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/execdata.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/execdata.inc.php
index 1f6fa265..e4f7a1d7 100644
--- a/modules-available/serversetup-bwlp-ipxe/inc/execdata.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/inc/execdata.inc.php
@@ -108,7 +108,10 @@ class ExecData
$this->dhcpOptions = array_values($this->dhcpOptions);
}
- public function toArray()
+ /**
+ * @return array{executable: string, initRd: string[], commandLine: string, imageFree: bool, replace: bool, autoUnload: bool, resetConsole: bool, dhcpOptions: array}
+ */
+ public function toArray(): array
{
$this->sanitize();
return [
@@ -123,7 +126,7 @@ class ExecData
];
}
- public function toFormFields($arch)
+ public function toFormFields(string $arch): array
{
$this->sanitize();
$opts = [];
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/ipxe.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/ipxe.inc.php
index 8731bb7a..5e0531ab 100644
--- a/modules-available/serversetup-bwlp-ipxe/inc/ipxe.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/inc/ipxe.inc.php
@@ -12,9 +12,9 @@ class IPxe
* Import all IP-Range based pxe menus from the given directory.
*
* @param string $configPath The pxelinux.cfg path where to look for menu files in hexadecimal IP format.
- * @return Number of menus imported
+ * @return int Number of menus imported
*/
- public static function importSubnetPxeMenus($configPath)
+ public static function importSubnetPxeMenus(string $configPath): int
{
$res = Database::simpleQuery('SELECT menuid, entryid FROM serversetup_menuentry ORDER BY sortval ASC');
$menus = [];
@@ -52,6 +52,10 @@ class IPxe
$locations[] = $row;
}
$menu = PxeLinux::parsePxeLinux($content, true);
+ if ($menu === null) {
+ error_log("Skipping empty pxelinux menu file $file");
+ continue;
+ }
// Insert all entries first, so we can get the list of entry IDs
$entries = [];
self::importPxeMenuEntries($menu, $entries);
@@ -83,10 +87,10 @@ class IPxe
} else {
error_log('Imported menu ' . $menu->title . ' is NEW, using for ' . count($locations) . ' locations.');
// Insert new menu
- $menuId = self::insertMenu($menu, 'Auto Imported', false, 0, [], []);
- if ($menuId === false)
+ $menuId = self::insertMenu($menu, 'Auto Imported', null, 0, [], []);
+ if ($menuId === null)
continue;
- $menus[(int)$menuId] = $entries;
+ $menus[$menuId] = $entries;
$importCount++;
}
foreach ($locations as $loc) {
@@ -103,20 +107,20 @@ class IPxe
return $importCount;
}
- public static function importLegacyMenu($force = false)
+ public static function importLegacyMenu(bool $force = false): bool
{
// See if anything is there
if (!$force && false !== Database::queryFirst("SELECT menuentryid FROM serversetup_menuentry LIMIT 1"))
return false; // Already exists
// Now create the default entry
self::createDefaultEntries();
- $prepend = ['bwlp-default' => false, 'localboot' => false];
+ $prepend = ['bwlp-default' => null, 'localboot' => null];
$defaultLabel = 'bwlp-default';
$menuTitle = 'bwLehrpool Bootauswahl';
$pxeConfig = '';
$timeoutSecs = 60;
- // Try to import any customization
- $oldMenu = Property::getBootMenu();
+ // Try to import any customization of the legacy PXELinux menu (despite the property name hinting at iPXE)
+ $oldMenu = json_decode(Property::get('ipxe-menu'), true);
if (is_array($oldMenu)) {
//
if (isset($oldMenu['timeout'])) {
@@ -136,47 +140,45 @@ class IPxe
}
}
$append = [
- '',
- 'bwlp-default-dbg' => false,
- '',
- 'poweroff' => false,
+ new PxeSection(null),
+ 'bwlp-default-dbg' => null,
+ new PxeSection(null),
+ 'poweroff' => null,
];
- return self::insertMenu(PxeLinux::parsePxeLinux($pxeConfig, false), $menuTitle, $defaultLabel, $timeoutSecs, $prepend, $append);
+ self::insertMenu(PxeLinux::parsePxeLinux($pxeConfig, false), $menuTitle, $defaultLabel, $timeoutSecs, $prepend, $append);
+ return !empty($pxeConfig);
}
/**
- * @param PxeMenu $pxeMenu
- * @param string $menuTitle
- * @param string|false $defaultLabel Fallback for the default label, if PxeMenu doesn't set one
+ * @param ?string $defaultLabel Fallback for the default label, if PxeMenu doesn't set one
* @param int $defaultTimeoutSeconds Default timeout, if PxeMenu doesn't set one
- * @param array $prepend
- * @param array $append
- * @return int|false
+ * @param (?PxeSection)[] $prepend
+ * @param (?PxeSection)[] $append
+ * @return ?int ID of newly created menu, or null on error, e.g. if the menu is empty
*/
- public static function insertMenu($pxeMenu, $menuTitle, $defaultLabel, $defaultTimeoutSeconds, $prepend, $append)
+ public static function insertMenu(?PxeMenu $pxeMenu, string $menuTitle, ?string $defaultLabel, int $defaultTimeoutSeconds,
+ array $prepend, array $append): ?int
{
$timeoutMs = [];
$menuEntries = $prepend;
- settype($menuEntries, 'array');
- if (!empty($pxeMenu)) {
- $pxe =& $pxeMenu;
- if (!empty($pxe->title)) {
- $menuTitle = $pxe->title;
+ if ($pxeMenu !== null) {
+ if (!empty($pxeMenu->title)) {
+ $menuTitle = $pxeMenu->title;
}
- if ($pxe->timeoutLabel !== null && $pxe->hasLabel($pxe->timeoutLabel)) {
- $defaultLabel = $pxe->timeoutLabel;
- } elseif ($pxe->hasLabel($pxe->default)) {
- $defaultLabel = $pxe->default;
+ if ($pxeMenu->timeoutLabel !== null && $pxeMenu->hasLabel($pxeMenu->timeoutLabel)) {
+ $defaultLabel = $pxeMenu->timeoutLabel;
+ } elseif ($pxeMenu->hasLabel($pxeMenu->default)) {
+ $defaultLabel = $pxeMenu->default;
}
- $timeoutMs[] = $pxe->timeoutMs;
- $timeoutMs[] = $pxe->totalTimeoutMs;
- self::importPxeMenuEntries($pxe, $menuEntries);
+ $timeoutMs[] = $pxeMenu->timeoutMs;
+ $timeoutMs[] = $pxeMenu->totalTimeoutMs;
+ self::importPxeMenuEntries($pxeMenu, $menuEntries);
}
- if (is_array($append)) {
+ if (!empty($append)) {
$menuEntries += $append;
}
if (empty($menuEntries))
- return false;
+ return null;
// Make menu
$timeoutMs = array_filter($timeoutMs, function($x) { return is_int($x) && $x > 0; });
if (empty($timeoutMs)) {
@@ -195,25 +197,29 @@ class IPxe
// Figure out entryid for default label
// Fiddly diddly way of getting the mangled entryid for the wanted pxe menu label
$defaultEntryId = false;
+ $fallbackDefault = false;
foreach ($menuEntries as $entryId => $section) {
- if ($section instanceof PxeSection) {
- if ($section->isDefault) {
- $defaultEntryId = $entryId;
- break;
- }
- if ($section->label === $defaultLabel) {
- $defaultEntryId = $entryId;
- }
+ if ($section === null)
+ continue;
+ if ($section->isDefault) {
+ $defaultEntryId = $entryId;
+ break;
+ }
+ if ($section->label === $defaultLabel) {
+ $defaultEntryId = $entryId;
+ }
+ if ($fallbackDefault === false && !empty($entryId)) {
+ $fallbackDefault = $entryId;
}
}
if ($defaultEntryId === false) {
- $defaultEntryId = array_keys($menuEntries)[0];
+ $defaultEntryId = $fallbackDefault;
}
// Link boot entries to menu
$defaultMenuEntryId = null;
$order = 1000;
foreach ($menuEntries as $entryId => $entry) {
- if (is_string($entry)) {
+ if ($entry !== null && $entry->isTextOnly()) {
// Gap entry
Database::exec("INSERT INTO serversetup_menuentry
(menuid, entryid, hotkey, title, hidden, sortval, plainpass, md5pass)
@@ -221,7 +227,7 @@ class IPxe
'menuid' => $menuId,
'entryid' => null,
'hotkey' => '',
- 'title' => self::sanitizeIpxeString($entry),
+ 'title' => self::sanitizeIpxeString($entry->title),
'hidden' => 0,
'sortval' => $order += 100,
]);
@@ -232,7 +238,7 @@ class IPxe
continue;
$data['pass'] = '';
$data['hidden'] = 0;
- if ($entry instanceof PxeSection) {
+ if ($entry !== null) {
$data['hidden'] = (int)$entry->isHidden;
// Prefer explicit data from this imported menu over the defaults
$title = self::sanitizeIpxeString($entry->title);
@@ -243,7 +249,7 @@ class IPxe
$data['hotkey'] = $entry->hotkey;
}
if (!empty($entry->passwd)) {
- // Most likely it's a hash so we cannot recover; ask people to reset
+ // Most likely it's a hash, so we cannot recover; ask people to reset
$data['pass'] ='please_reset';
}
}
@@ -268,36 +274,28 @@ class IPxe
/**
* Import only the bootentries from the given PXELinux menu
- * @param PxeMenu $pxe
- * @param array $menuEntries Where to append the generated menu items to
+ *
+ * @param PxeSection[] $menuEntries Where to append the generated menu items to
*/
- public static function importPxeMenuEntries($pxe, &$menuEntries)
+ public static function importPxeMenuEntries(PxeMenu $pxe, array &$menuEntries): void
{
if (self::$allEntries === false) {
self::$allEntries = BootEntry::getAll();
}
foreach ($pxe->sections as $section) {
- if ($section->localBoot !== false || preg_match('/chain\.c32$/i', $section->kernel)) {
+ if ($section->isLocalboot()) {
$menuEntries['localboot'] = $section;
continue;
}
- if ($section->label === null) {
- if (!$section->isHidden && !empty($section->title)) {
- $menuEntries[] = $section->title;
- }
- continue;
- }
- if (empty($section->kernel)) {
- if (!$section->isHidden && !empty($section->title)) {
- $menuEntries[] = $section->title;
- }
+ if ($section->isTextOnly()) {
+ $menuEntries[] = $section;
continue;
}
$label = self::cleanLabelFixLocal($section);
$entry = self::pxe2BootEntry($section);
if ($entry === null)
continue; // Error? Ignore
- if ($label !== false || ($label = array_search($entry, self::$allEntries))) {
+ if ($label !== false || ($label = array_search($entry, self::$allEntries)) !== false) {
// Exact Duplicate, Do Nothing
error_log('Ignoring duplicate boot entry ' . $section->label . ' (' . $section->kernel . ')');
} else {
@@ -321,7 +319,7 @@ class IPxe
Database::exec('INSERT IGNORE INTO serversetup_bootentry (entryid, module, hotkey, title, builtin, data)
VALUES (:label, :module, :hotkey, :title, 0, :data)', [
'label' => $label,
- 'module' => ($entry instanceof \StandardBootEntry) ? '.exec' : '.script',
+ 'module' => ($entry instanceof StandardBootEntry) ? '.exec' : '.script',
'hotkey' => $hotkey,
'title' => $title,
'data' => json_encode($data),
@@ -408,10 +406,9 @@ class IPxe
* Also it patches the entry if it's referencing the local bwlp install
* but with different options.
*
- * @param PxeSection $section
* @return string|false existing label if match, false otherwise
*/
- private static function cleanLabelFixLocal($section)
+ private static function cleanLabelFixLocal(PxeSection $section)
{
$myip = Property::getServerIp();
// Detect our "old" entry types
@@ -434,10 +431,9 @@ class IPxe
}
/**
- * @param PxeSection $section
* @return BootEntry|null The according boot entry, null if it's unparsable
*/
- private static function pxe2BootEntry($section)
+ private static function pxe2BootEntry(PxeSection $section): ?BootEntry
{
if (preg_match('/(pxechain\.com|pxechn\.c32)$/i', $section->kernel)) {
// Chaining -- create script
@@ -496,11 +492,8 @@ class IPxe
/**
* Parse PXELINUX file notion. Basically, turn
* server::file into tftp://server/file.
- *
- * @param string $file
- * @return string
*/
- private static function parseFile($file)
+ private static function parseFile(string $file): string
{
if (preg_match(',^([^:/]+)::(.*)$,', $file, $out)) {
return 'tftp://' . $out[1] . '/' . $out[2];
@@ -508,12 +501,12 @@ class IPxe
return $file;
}
- public static function sanitizeIpxeString($string)
+ public static function sanitizeIpxeString(string $string): string
{
return str_replace(['&', '|', ';', '$', "\r", "\n"], ['+', '/', ':', 'S', ' ', ' '], $string);
}
- public static function makeMd5Pass($plainpass, $salt)
+ public static function makeMd5Pass(string $plainpass, string $salt): string
{
if (empty($plainpass))
return '';
@@ -528,11 +521,12 @@ class IPxe
* remove any occurrence of either "option" or "option=something". If the argument starts with a
* '+', it will be added to the command line after removing the '+'. If the argument starts with any
* other character, it will also be added to the command line.
+ *
* @param string $cmdLine command line to modify
- * @param string $modifier modification string of space separated arguments
+ * @param string $modifier modification string of space separated arguments
* @return string the modified command line
*/
- public static function modifyCommandLine($cmdLine, $modifier)
+ public static function modifyCommandLine(string $cmdLine, string $modifier): string
{
$items = preg_split('/\s+/', $modifier, -1, PREG_SPLIT_NO_EMPTY);
foreach ($items as $item) {
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/ipxebuilder.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/ipxebuilder.inc.php
index 3a82b4f7..a2b25f55 100644
--- a/modules-available/serversetup-bwlp-ipxe/inc/ipxebuilder.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/inc/ipxebuilder.inc.php
@@ -13,10 +13,9 @@ class IPxeBuilder
* Checkout given commit/ref of ipxe repo. Returns the according task-id, or null on error
*
* @param string $version version ref (commit, tag, ...)
- * @param string|null $parent parent task id
- * @return ?string
+ * @param ?string $parent parent task id, if any
*/
- public static function setIpxeVersion($version, $parent = null)
+ public static function setIpxeVersion(string $version, ?string $parent = null): ?string
{
$task = Taskmanager::submit('IpxeVersion', [
'action' => 'CHECKOUT',
@@ -30,10 +29,7 @@ class IPxeBuilder
return $task['id'];
}
- /**
- * @return array|false
- */
- public static function getVersionTaskResult()
+ public static function getVersionTaskResult(): ?array
{
$task = Taskmanager::status(IPxeBuilder::VERSION_LIST_TASK);
if (!Taskmanager::isTask($task) || Taskmanager::isFailed($task)) {
@@ -44,13 +40,13 @@ class IPxeBuilder
if (Taskmanager::isFinished($task) && !Taskmanager::isFailed($task)) {
return $task['data'];
}
- return false;
+ return null;
}
/**
* Callback when compile Taskmanager job finished
*/
- public static function compileCompleteCallback($task)
+ public static function compileCompleteCallback(array $task): void
{
if (!Taskmanager::isFinished($task) || Taskmanager::isFailed($task))
return;
@@ -75,7 +71,7 @@ class IPxeBuilder
Property::set(IPxeBuilder::PROP_IPXE_BUILDSTRING, $buildString);
}
- public static function setIPxeVersionCallback($task)
+ public static function setIPxeVersionCallback(array $task): void
{
if (!Taskmanager::isFinished($task) || Taskmanager::isFailed($task) || empty($task['data']['ref']))
return;
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/ipxemenu.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/ipxemenu.inc.php
index 7d15cd99..ddbce00d 100644
--- a/modules-available/serversetup-bwlp-ipxe/inc/ipxemenu.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/inc/ipxemenu.inc.php
@@ -24,10 +24,7 @@ class IPxeMenu
*/
public $items = [];
- /**
- * @param int $menuId
- */
- public static function get($menuId, $emptyFallback = false)
+ public static function get(int $menuId, bool $emptyFallback = false): ?IPxeMenu
{
$menu = Database::queryFirst("SELECT menuid, timeoutms, title, defaultentryid FROM serversetup_menu
WHERE menuid = :menuid LIMIT 1", ['menuid' => $menuId]);
@@ -43,7 +40,7 @@ class IPxeMenu
*
* @param array $menu array for according menu row
*/
- public function __construct($menu)
+ public function __construct(array $menu)
{
$this->menuid = (int)$menu['menuid'];
$this->timeoutMs = (int)$menu['timeoutms'];
@@ -86,7 +83,7 @@ class IPxeMenu
/**
* @return MenuEntry|null Return preselected menu entry
*/
- public function defaultEntry()
+ public function defaultEntry(): ?MenuEntry
{
foreach ($this->items as $item) {
if ($item->menuEntryId() === $this->defaultEntryId)
@@ -183,16 +180,18 @@ class IPxeMenu
return new IPxeMenu($menu);
}
- public static function forClient(string $ip, string $uuid): IPxeMenu
+ public static function forClient(string $ip, ?string $uuid): IPxeMenu
{
$locationId = 0;
if (Module::isAvailable('locations')) {
$locationId = Location::getFromIpAndUuid($ip, $uuid);
}
$menu = self::forLocation($locationId);
- // Super specialcase hackery: If this is a dedicated PVS, force the default to
- // be bwlp/"minilinux"
- $menu->maybeOverrideDefault($uuid);
+ if ($uuid !== null) {
+ // Super specialcase hackery: If this is a dedicated PVS, force the default to
+ // be bwlp/"minilinux"
+ $menu->maybeOverrideDefault($uuid);
+ }
return $menu;
}
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/localboot.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/localboot.inc.php
index 1261ee29..4d1a56c7 100644
--- a/modules-available/serversetup-bwlp-ipxe/inc/localboot.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/inc/localboot.inc.php
@@ -29,6 +29,9 @@ iseq ${i} 10 || goto blubber',
],
];
+ /**
+ * @return array{PCBIOS: string, EFI: string}
+ */
public static function getDefault(): array
{
$ret = explode(',', Property::get(self::PROPERTY_KEY, 'SANBOOT,GRUB'));
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/menuentry.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/menuentry.inc.php
index 3106291e..727c456a 100644
--- a/modules-available/serversetup-bwlp-ipxe/inc/menuentry.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/inc/menuentry.inc.php
@@ -35,11 +35,7 @@ class MenuEntry
public $md5pass = null;
- /**
- * @param int $menuEntryId
- * @return MenuEntry|null
- */
- public static function get($menuEntryId)
+ public static function get(int $menuEntryId): ?MenuEntry
{
$row = Database::queryFirst("SELECT e.menuentryid, e.entryid, e.refmenuid, e.hotkey, e.title,
e.hidden, e.sortval, e.plainpass, e.md5pass, b.module, b.data AS bootentry, b.title AS betitle
@@ -56,44 +52,42 @@ class MenuEntry
*
* @param array $row row from database
*/
- public function __construct($row)
+ public function __construct(array $row)
{
- if (is_array($row)) {
- if (empty($row['title']) && !empty($row['betitle'])) {
- $row['title'] = $row['betitle'];
- }
- foreach ($row as $key => $value) {
- if (property_exists($this, $key)) {
- $this->{$key} = $value;
- }
- }
- $this->hotkey = self::getKeyCode($row['hotkey'] ?? '');
- if (!empty($row['bootentry'])) {
- $this->bootEntry = BootEntry::fromJson($row['module'], $row['bootentry']);
- } elseif (isset($row['refmenuid'])) {
- $this->bootEntry = BootEntry::forMenu($row['refmenuid']);
+ if (empty($row['title']) && !empty($row['betitle'])) {
+ $row['title'] = $row['betitle'];
+ }
+ foreach ($row as $key => $value) {
+ if (property_exists($this, $key)) {
+ $this->{$key} = $value;
}
- $this->gap = (array_key_exists('entryid', $row) && $row['entryid'] === null && $row['refmenuid'] === null);
}
+ $this->hotkey = self::getKeyCode($row['hotkey'] ?? '');
+ if (!empty($row['bootentry'])) {
+ $this->bootEntry = BootEntry::fromJson($row['module'], $row['bootentry']);
+ } elseif (isset($row['refmenuid'])) {
+ $this->bootEntry = BootEntry::forMenu($row['refmenuid']);
+ }
+ $this->gap = (array_key_exists('entryid', $row) && $row['entryid'] === null && $row['refmenuid'] === null);
settype($this->hidden, 'bool');
settype($this->gap, 'bool');
settype($this->sortval, 'int');
settype($this->menuentryid, 'int');
}
- public function getBootEntryScript($builder)
+ public function getBootEntryScript(ScriptBuilderBase $builder): string
{
if ($this->bootEntry === null)
return '';
return $this->bootEntry->toScript($builder);
}
- public function menuEntryId()
+ public function menuEntryId(): int
{
return $this->menuentryid;
}
- public function title()
+ public function title(): string
{
return $this->title;
}
@@ -142,7 +136,7 @@ class MenuEntry
*
* @return string[] list of known key names
*/
- public static function getKeyList()
+ public static function getKeyList(): array
{
return array_keys(self::getKeyArray());
}
@@ -151,10 +145,9 @@ class MenuEntry
* Get the key code ipxe expects for the given named
* key. Returns false if the key name is unknown.
*
- * @param string $keyName
* @return false|string Key code as hex string, or false if not found
*/
- public static function getKeyCode($keyName)
+ public static function getKeyCode(string $keyName)
{
$data = self::getKeyArray();
if (isset($data[$keyName]))
@@ -166,7 +159,7 @@ class MenuEntry
* @param string $keyName desired key name
* @return string $keyName if it's known, empty string otherwise
*/
- public static function filterKeyName($keyName)
+ public static function filterKeyName(string $keyName): string
{
$data = self::getKeyArray();
if (isset($data[$keyName]))
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/pxelinux.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/pxelinux.inc.php
index cc4f9756..ba547468 100644
--- a/modules-available/serversetup-bwlp-ipxe/inc/pxelinux.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/inc/pxelinux.inc.php
@@ -7,11 +7,14 @@ class PxeLinux
/**
* Takes a (partial) pxelinux menu and parses it into
* a PxeMenu object.
+ *
* @param string $input The pxelinux menu to parse
- * @return PxeMenu the parsed menu
+ * @return ?PxeMenu the parsed menu, or null if input is not a PXELinux menu
*/
- public static function parsePxeLinux($input, $isCp437)
+ public static function parsePxeLinux(string $input, bool $isCp437): ?PxeMenu
{
+ if (empty($input))
+ return null;
if ($isCp437) {
$input = iconv('IBM437', 'UTF8//TRANSLIT//IGNORE', $input);
}
@@ -82,6 +85,8 @@ class PxeLinux
if ($section !== null) {
$menu->sections[] = $section;
}
+ if (empty($menu->sections))
+ return null; // Probably not a PXE menu but random text?
foreach ($menu->sections as $section) {
$section->mangle();
}
@@ -93,13 +98,14 @@ class PxeLinux
* to the given object. The map to look up the keyword has to be passed
* as well as the object to set the value in. Map and object should
* obviously match.
+ *
* @param string $key keyword of parsed line
* @param string $val raw value of currently parsed line (empty if not present)
* @param array $map Map in which $key is looked up as key
- * @param PxeMenu|PxeSection The object to set the parsed and sanitized value in
+ * @param PxeMenu|PxeSection $object The object to set the parsed and sanitized value in
* @return bool true if the value was found in the map (and set in the object), false otherwise
*/
- private static function handleKeyword($key, $val, $map, $object)
+ private static function handleKeyword(string $key, string $val, array $map, $object): bool
{
if (!isset($map[$key]))
return false;
@@ -169,7 +175,7 @@ class PxeMenu
/**
* Check if any of the sections has the given label.
*/
- public function hasLabel($label)
+ public function hasLabel(string $label): bool
{
foreach ($this->sections as $section) {
if ($section->label === $label)
@@ -190,7 +196,7 @@ class PxeSection
{
/**
- * @var string label used internally in PXEMENU definition to address this entry
+ * @var ?string label used internally in PXEMENU definition to address this entry
*/
public $label;
/**
@@ -248,7 +254,7 @@ class PxeSection
*/
public $hotkey;
- public function __construct($label) { $this->label = $label; }
+ public function __construct(?string $label) { $this->label = $label; }
public function mangle()
{
@@ -278,5 +284,21 @@ class PxeSection
}
}
+ /**
+ * Does this appear to be an entry that triggers localboot?
+ */
+ public function isLocalboot(): bool
+ {
+ return $this->localBoot !== false || preg_match('/chain\.c32$/i', $this->kernel);
+ }
+
+ /**
+ * Is this (most likely) a separating entry only that cannot be selected?
+ */
+ public function isTextOnly(): bool
+ {
+ return ($this->label === null || empty($this->kernel)) && !$this->isHidden && !empty($this->title);
+ }
+
}
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderbase.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderbase.inc.php
index 84cfd7db..9cd07388 100644
--- a/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderbase.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderbase.inc.php
@@ -9,8 +9,10 @@ abstract class ScriptBuilderBase
protected $platform = '';
+ /** @var string */
protected $clientIp;
+ /** @var ?string */
protected $uuid;
/**
@@ -18,57 +20,57 @@ abstract class ScriptBuilderBase
*/
protected $hasExtension = false;
- public function hasExtensions()
+ public function hasExtensions(): bool
{
return $this->hasExtension;
}
- public function platform()
+ public function platform(): string
{
return $this->platform;
}
- public function uuid()
+ public function uuid(): ?string
{
return $this->uuid;
}
- public function clientIp()
+ public function clientIp(): string
{
return $this->clientIp;
}
- public function getLabel()
+ public function getLabel(): string
{
return 'b' . mt_rand(100, 999) . 'x' . (++$this->lblId);
}
- public function __construct($platform = null, $serverIp = null, $slxExtensions = null)
+ public function __construct(?string $platform = null, ?string $serverIp = null, ?bool $slxExtensions = null)
{
- $this->clientIp = $_SERVER['REMOTE_ADDR'];
+ $this->clientIp = (string)$_SERVER['REMOTE_ADDR'];
if (substr($this->clientIp, 0, 7) === '::ffff:') {
$this->clientIp = substr($this->clientIp, 7);
}
$this->serverIp = $serverIp ?? $_SERVER['SERVER_ADDR'] ?? Property::getServerIp();
- $this->platform = $platform ?? Request::any('platform', false, 'string');
- if ($this->platform !== false) {
+ $this->platform = $platform ?? Request::any('platform', null, 'string');
+ if ($this->platform !== null) {
$this->platform = strtoupper($this->platform);
}
if ($this->platform !== 'EFI' && $this->platform !== 'PCBIOS') {
$this->platform = '';
}
$this->hasExtension = $slxExtensions ?? (bool)Request::any('slx-extensions', false, 'int');
- $this->uuid = Request::any('uuid', false, 'string');
- if (!preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i', $this->uuid)) {
- $this->uuid = false;
+ $uuid = Request::any('uuid', null, 'string');
+ if ($uuid !== null
+ && preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i', $uuid)) {
+ $this->uuid = (string)$uuid;
}
}
/**
* Output given string (script) to client, in a suitable encoding, headers, etc.
- * @param string $string
*/
- public abstract function output($string);
+ public abstract function output(string $string): void;
public abstract function bootstrapLive();
@@ -79,31 +81,22 @@ abstract class ScriptBuilderBase
* @param bool $honorPassword Whether we should generate a password dialog if protected, or skip
* @return string generated script/code/...
*/
- public abstract function getMenuEntry($menuEntry, $honorPassword = true);
+ public abstract function getMenuEntry(?MenuEntry $entry, bool $honorPassword = true): string;
/**
* @param BootEntry|null|false $bootEntry
- * @return string
*/
- public abstract function getBootEntry($bootEntry);
+ public abstract function getBootEntry(?BootEntry $entry): string;
- public abstract function getSpecial($special);
+ public abstract function getSpecial(string $special);
- /**
- * @param IPxeMenu|null $menu
- * @return string
- */
- public abstract function menuToScript($menu);
+ public abstract function menuToScript(IPxeMenu $menu): string;
/**
* Pass EITHER only $agnostic, OR $bios and/or $efi
* If $agnostic is given, it should be used unconditionally,
* and $bios/$efi should be ignored.
- * @param ExecData $agnostic
- * @param ExecData $bios
- * @param ExecData $efi
- * @return string
*/
- public abstract function execDataToScript($agnostic, $bios, $efi);
+ public abstract function execDataToScript(?ExecData $agnostic, ?ExecData $bios, ?ExecData $efi): string;
} \ No newline at end of file
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderbash.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderbash.inc.php
index 86b2931f..d6b542ec 100644
--- a/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderbash.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderbash.inc.php
@@ -3,39 +3,39 @@
class ScriptBuilderBash extends ScriptBuilderBase
{
- public function output($string)
+ public function output(string $string): void
{
echo $string;
}
- public function bootstrapLive() { return false; }
+ public function bootstrapLive(): bool { return false; }
- public function getMenu(IPxeMenu $menu, bool $bootstrap)
+ public function getMenu(IPxeMenu $menu, bool $bootstrap): string
{
return $this->menuToScript($menu);
}
- public function getBootEntry($entry)
+ public function getBootEntry(?BootEntry $entry): string
{
- if (!$entry) {
+ if ($entry === null) {
return "echo 'Invalid boot entry id'\nread -n1 -r _\n";
}
return $entry->toScript($this);
}
- public function getMenuEntry($entry, $honorPassword = true)
+ public function getMenuEntry(?MenuEntry $entry, bool $honorPassword = true): string
{
if ($entry === null)
return "echo 'Invalid menu entry id - press any key to continue'\nread -n1 -r _\n";
return $entry->getBootEntryScript($this);
}
- public function getSpecial($special)
+ public function getSpecial(string $special): string
{
return ''; // We can't really do localboot here I guess
}
- public function menuToScript($menu)
+ public function menuToScript(IPxeMenu $menu): string
{
$output = "declare -A items_name items_gap hotkey_item\ndeclare menu_default menu_timeout menu_title\n";
foreach ($menu->items as $entry) {
@@ -59,7 +59,7 @@ class ScriptBuilderBash extends ScriptBuilderBase
. "\nmenu_title=" . $this->bashString($menu->title) . "\n";
}
- public function execDataToScript($agnostic, $bios, $efi) : string
+ public function execDataToScript(?ExecData $agnostic, ?ExecData $bios, ?ExecData $efi): string
{
if ($agnostic !== null)
return $this->execDataToScriptInternal($agnostic);
@@ -86,7 +86,7 @@ class ScriptBuilderBash extends ScriptBuilderBase
return $script;
}
- private function bashString($string)
+ private function bashString(string $string): string
{
if (strpos($string, "'") === false) {
return "'$string'";
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderipxe.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderipxe.inc.php
index 3ca312aa..4896f598 100644
--- a/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderipxe.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderipxe.inc.php
@@ -3,7 +3,7 @@
class ScriptBuilderIpxe extends ScriptBuilderBase
{
- private function getUrlBase()
+ private function getUrlBase(): string
{
if (isset($_SERVER['REQUEST_URI'])) {
$url = parse_url($_SERVER['REQUEST_URI']);
@@ -23,7 +23,7 @@ class ScriptBuilderIpxe extends ScriptBuilderBase
}
- private function getUrlFull(&$hasExt, $key = null, $value = null)
+ private function getUrlFull(?bool &$hasExt = null, string $key = null, string $value = null): string
{
$url = parse_url($_SERVER['REQUEST_URI']);
$urlbase = $this->getUrlBase();
@@ -58,7 +58,7 @@ class ScriptBuilderIpxe extends ScriptBuilderBase
/**
* Redirect to same URL, but add our extended params
*/
- private function redirect($key = null, $value = null)
+ private function redirect(string $key = null, string $value = null): string
{
// Redirect to self with added parameters
$urlfull = $this->getUrlFull($hasExt, $key, $value);
@@ -102,27 +102,24 @@ HERE;
return false;
}
- public function getBootEntry($entry)
+ public function getBootEntry(?BootEntry $entry): string
{
- if (!$entry) {
+ if ($entry === null) {
return "#!ipxe\nprompt --timeout 5000 Invalid boot entry id\n";
}
return $entry->toScript($this);
}
- public function getMenu(IPxeMenu $menu, bool $bootstrap)
+ public function getMenu(IPxeMenu $menu, bool $bootstrap): string
{
if ($bootstrap) {
return "#!ipxe\nimgfree ||\n" . $this->menuToScript($menu);
}
- $base = $this->getUrlFull($he);
+ $base = $this->getUrlFull();
return "#!ipxe\nset self {$base} ||\n" . $this->menuToScript($menu);
}
- /**
- * @param IPxeMenu $menu
- */
- public function menuToScript($menu)
+ public function menuToScript(IPxeMenu $menu): string
{
if ($this->hasExtension) {
$slxConsoleUpdate = '--update';
@@ -186,12 +183,7 @@ HERE;
return $output;
}
- /**
- * @param $requestedDefaultId
- * @param MenuEntry $entry
- * @return string
- */
- private function getMenuItemScript($requestedDefaultId, $entry)
+ private function getMenuItemScript(int $requestedDefaultId, MenuEntry $entry): string
{
$str = 'item ';
if ($entry->gap) {
@@ -220,7 +212,7 @@ HERE;
return $str . " || prompt Could not create menu item for {$entry->menuentryid}\n";
}
- public function getSpecial($special)
+ public function getSpecial(string $special): string
{
if ($special === 'localboot') {
// Get preferred localboot method, depending on system model
@@ -269,11 +261,7 @@ HERE;
}
}
// Convert to actual ipxe code
- if (isset($BOOT_METHODS[$localboot])) {
- $localboot = $BOOT_METHODS[$localboot];
- } else {
- $localboot = 'prompt Localboot not possible';
- }
+ $localboot = $BOOT_METHODS[$localboot] ?? 'prompt Localboot not possible';
$output = <<<BLA
imgfree ||
console ||
@@ -287,7 +275,7 @@ BLA;
return $output;
}
- public function output($string)
+ public function output(string $string): void
{
// iPXE introduced UTF-8 support at some point in 2022, and now expects all text/script files to be
// encoded as such. Since we still offer to use older versions, we need to detect that here and handle
@@ -319,10 +307,7 @@ BLA;
const PROP_PW_SALT = 'ipxe.salt.';
- /**
- * @param MenuEntry $menuEntryId
- */
- private function passwordDialog($entry)
+ private function passwordDialog(MenuEntry $entry): string
{
if ($this->hasExtension) {
$salt = dechex(mt_rand(0x100000, 0xFFFFFF));
@@ -348,7 +333,7 @@ chain -a \${self}&entryid={$entry->menuentryid}##params || goto fail ||
HERE;
}
- public function getMenuEntry($entry, $honorPassword = true)
+ public function getMenuEntry(?MenuEntry $entry, bool $honorPassword = true): string
{
if ($entry === null)
return "#!ipxe\nprompt --timeout 10000 Invalid menu entry id\n";
@@ -402,7 +387,7 @@ HERE;
return $output;
}
- public function execDataToScript($agnostic, $bios, $efi) : string
+ public function execDataToScript(?ExecData $agnostic, ?ExecData $bios, ?ExecData $efi) : string
{
if ($agnostic !== null)
return $this->execDataToScriptInternal($agnostic) . "\ngoto fail\n";
diff --git a/modules-available/serversetup-bwlp-ipxe/page.inc.php b/modules-available/serversetup-bwlp-ipxe/page.inc.php
index 8d4a366f..c9260687 100644
--- a/modules-available/serversetup-bwlp-ipxe/page.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/page.inc.php
@@ -123,23 +123,23 @@ class Page_ServerSetup extends Page
$addr = false;
if (User::hasPermission('ipxe.menu.view')) {
- Dashboard::addSubmenu('?do=serversetup&show=menu', Dictionary::translate('submenu_menu', true));
+ Dashboard::addSubmenu('?do=serversetup&show=menu', Dictionary::translate('submenu_menu'));
}
if (User::hasPermission('ipxe.bootentry.view')) {
- Dashboard::addSubmenu('?do=serversetup&show=bootentry', Dictionary::translate('submenu_bootentry', true));
+ Dashboard::addSubmenu('?do=serversetup&show=bootentry', Dictionary::translate('submenu_bootentry'));
}
if (User::hasPermission('edit.address')) {
- Dashboard::addSubmenu('?do=serversetup&show=address', Dictionary::translate('submenu_address', true));
+ Dashboard::addSubmenu('?do=serversetup&show=address', Dictionary::translate('submenu_address'));
$addr = true;
}
if (User::hasPermission('download')) {
- Dashboard::addSubmenu('?do=serversetup&show=download', Dictionary::translate('submenu_download', true));
+ Dashboard::addSubmenu('?do=serversetup&show=download', Dictionary::translate('submenu_download'));
}
if (User::hasPermission('ipxe.localboot.*')) {
- Dashboard::addSubmenu('?do=serversetup&show=localboot', Dictionary::translate('submenu_localboot', true));
+ Dashboard::addSubmenu('?do=serversetup&show=localboot', Dictionary::translate('submenu_localboot'));
}
if (User::hasPermission('ipxe.bootentry.edit')) {
- Dashboard::addSubmenu('?do=serversetup&show=import', Dictionary::translate('submenu_import', true));
+ Dashboard::addSubmenu('?do=serversetup&show=import', Dictionary::translate('submenu_import'));
}
if (Request::get('show') === false) {
$subs = Dashboard::getSubmenus();
@@ -219,7 +219,6 @@ class Page_ServerSetup extends Page
break;
default:
Util::redirect('?do=serversetup');
- break;
}
}
@@ -231,17 +230,17 @@ class Page_ServerSetup extends Page
});
$files = [];
$strings = [
- 'efi' => [Dictionary::translate('dl-efi', true) => 50],
- 'pcbios' => [Dictionary::translate('dl-pcbios', true) => 51],
- 'usb' => [Dictionary::translate('dl-usb', true) => 80],
- 'hd' => [Dictionary::translate('dl-hd', true) => 81],
- 'lkrn' => [Dictionary::translate('dl-lkrn', true) => 82],
- 'i386' => [Dictionary::translate('dl-i386', true) => 10],
- 'x86_64' => [Dictionary::translate('dl-x86_64', true) => 11],
- 'ecm' => [Dictionary::translate('dl-usbnic', true) => 60],
- 'ncm' => [Dictionary::translate('dl-usbnic', true) => 61],
- 'ipxe' => [Dictionary::translate('dl-pcinic', true) => 62],
- 'snp' => [Dictionary::translate('dl-snp', true) => 63],
+ 'efi' => [Dictionary::translate('dl-efi') => 50],
+ 'pcbios' => [Dictionary::translate('dl-pcbios') => 51],
+ 'usb' => [Dictionary::translate('dl-usb') => 80],
+ 'hd' => [Dictionary::translate('dl-hd') => 81],
+ 'lkrn' => [Dictionary::translate('dl-lkrn') => 82],
+ 'i386' => [Dictionary::translate('dl-i386') => 10],
+ 'x86_64' => [Dictionary::translate('dl-x86_64') => 11],
+ 'ecm' => [Dictionary::translate('dl-usbnic') => 60],
+ 'ncm' => [Dictionary::translate('dl-usbnic') => 61],
+ 'ipxe' => [Dictionary::translate('dl-pcinic') => 62],
+ 'snp' => [Dictionary::translate('dl-snp') => 63],
];
foreach ($list as $file) {
if ($file[0] === '.')
@@ -267,7 +266,10 @@ class Page_ServerSetup extends Page
Render::addTemplate('download', ['files' => $files]);
}
- private function makeSelectArray($list, $defaults)
+ /**
+ * @return array{EFI: array, PCBIOS: array}
+ */
+ private function makeSelectArray(array $list, array $defaults): array
{
$ret = ['EFI' => [], 'PCBIOS' => []];
foreach (['PCBIOS', 'EFI'] as $m) {
@@ -326,7 +328,7 @@ class Page_ServerSetup extends Page
GROUP BY be.entryid, be.title");
if (empty($bootentryTable)) {
- if (Property::getServerIp() === false || Property::getServerIp() === 'invalid') {
+ if (Property::getServerIp() === 'invalid') {
Message::addError('no-ip-set');
Util::redirect('?do=serversetup&show=address');
}
@@ -379,7 +381,7 @@ class Page_ServerSetup extends Page
));
}
- private function hasMenuPermission($menuid, $permission)
+ private function hasMenuPermission(int $menuid, string $permission): bool
{
$allowedEditLocations = User::getAllowedLocations($permission);
$allowEdit = in_array(0, $allowedEditLocations);
@@ -466,7 +468,7 @@ class Page_ServerSetup extends Page
if ($k === 'id')
continue;
$bootentry['otherFields'][] = [
- 'key' => Dictionary::translateFileModule($bootentry['module'], 'module', 'ipxe-' . $k, true),
+ 'key' => Dictionary::translateFileModule($bootentry['module'], 'module', 'ipxe-' . $k),
'value' => is_bool($v) ? Util::boolToString($v) : $v,
];
}
@@ -483,16 +485,16 @@ class Page_ServerSetup extends Page
continue;
// Naming and agnostic
if ($bootentry['data']['arch'] === BootEntry::BIOS) {
- $bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_biosOnly', true);
+ $bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_biosOnly');
unset($bootentry['data']['EFI']);
} elseif ($bootentry['data']['arch'] === BootEntry::EFI) {
- $bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_efiOnly', true);
+ $bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_efiOnly');
unset($bootentry['data']['PCBIOS']);
} elseif ($bootentry['data']['arch'] === BootEntry::AGNOSTIC) {
- $bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_archAgnostic', true);
+ $bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_archAgnostic');
unset($bootentry['data']['EFI']);
} else {
- $bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_archBoth', true);
+ $bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_archBoth');
}
foreach ($bootentry['data'] as &$e) {
if (isset($e['initRd'])) {
@@ -537,12 +539,7 @@ class Page_ServerSetup extends Page
}
if ($row['module'][0] === '.') {
// either script or exec entry
- $json = json_decode($row['data'], true);
- if (!is_array($json)) {
- Message::addError('unknown-bootentry-type', $id);
- Util::redirect('?do=serversetup&show=bootentry');
- }
- $entry = BootEntry::fromJson($row['module'], $json);
+ $entry = BootEntry::fromJson($row['module'], $row['data']);
if ($entry === null) {
Message::addError('unknown-bootentry-type', $id);
Util::redirect('?do=serversetup&show=bootentry');
@@ -599,7 +596,7 @@ class Page_ServerSetup extends Page
{
$status = IPxeBuilder::getVersionTaskResult();
$versions = false;
- if ($status === false) {
+ if ($status === null) {
$error = 'Taskmanager down';
} elseif (!empty($status['versions'])) {
$versions = $status['versions'];
@@ -801,7 +798,7 @@ class Page_ServerSetup extends Page
|| $defaultEntryId === null)) { // if still null, use whatever as fallback, in case user didn't select any
$defaultEntryId = $newKey;
}
- $keepIds[] = (int)$newKey;
+ $keepIds[] = $newKey;
if (!empty($entry['plainpass'])) {
Database::exec('UPDATE serversetup_menuentry SET md5pass = :md5pass WHERE menuentryid = :id', [
'md5pass' => IPxe::makeMd5Pass($entry['plainpass'], $newKey),
@@ -894,7 +891,7 @@ class Page_ServerSetup extends Page
} else {
// Module hook
$hook = Hook::loadSingle($type, 'ipxe-bootentry');
- if ($hook === false) {
+ if ($hook === null) {
Message::addError('unknown-bootentry-type', $type);
return;
}
@@ -1073,7 +1070,7 @@ class Page_ServerSetup extends Page
Util::redirect('?do=serversetup&show=import');
}
$menu = PxeLinux::parsePxeLinux($content, false);
- if (empty($menu->sections)) {
+ if ($menu === null) {
Message::addWarning('import-no-entries');
Util::redirect('?do=serversetup&show=import');
}
@@ -1082,8 +1079,8 @@ class Page_ServerSetup extends Page
IPxe::importPxeMenuEntries($menu, $foo);
Util::redirect('?do=serversetup&show=bootentry');
} else {
- $id = IPxe::insertMenu($menu, 'Imported Menu', false, 0, [], []);
- if ($id === false) {
+ $id = IPxe::insertMenu($menu, 'Imported Menu', null, 0, [], []);
+ if ($id === null) {
Message::addError('import-error');
Util::redirect('?do=serversetup&show=import');
} else {