diff options
Diffstat (limited to 'modules-available/serversetup-bwlp-ipxe/inc/pxelinux.inc.php')
-rw-r--r-- | modules-available/serversetup-bwlp-ipxe/inc/pxelinux.inc.php | 36 |
1 files changed, 29 insertions, 7 deletions
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); + } + } |