diff options
Diffstat (limited to 'modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderbase.inc.php')
-rw-r--r-- | modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderbase.inc.php | 65 |
1 files changed, 42 insertions, 23 deletions
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderbase.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderbase.inc.php index c6adc953..9cd07388 100644 --- a/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderbase.inc.php +++ b/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderbase.inc.php @@ -9,75 +9,94 @@ abstract class ScriptBuilderBase protected $platform = ''; + /** @var string */ protected $clientIp; + /** @var ?string */ + protected $uuid; + /** * @var bool Running iPXE has slx-extensions */ 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 getLabel() + public function uuid(): ?string + { + return $this->uuid; + } + + public function clientIp(): string + { + return $this->clientIp; + } + + 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); } - Header('X-Popo: ' . $this->platform); if ($this->platform !== 'EFI' && $this->platform !== 'PCBIOS') { $this->platform = ''; } $this->hasExtension = $slxExtensions ?? (bool)Request::any('slx-extensions', false, 'int'); + $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 getMenu($menuId); + public abstract function output(string $string): void; - public abstract function getMenuEntry($menuEntryId); + public abstract function bootstrapLive(); - public abstract function getSpecial($special); + public abstract function getMenu(IPxeMenu $menu, bool $bootstrap); - public abstract function fallback(); + /** + * @param MenuEntry|null $menuEntry The according menu entry, or null if invalid. + * @param bool $honorPassword Whether we should generate a password dialog if protected, or skip + * @return string generated script/code/... + */ + public abstract function getMenuEntry(?MenuEntry $entry, bool $honorPassword = true): string; /** - * @param IPxeMenu|null $menu - * @return string + * @param BootEntry|null|false $bootEntry */ - public abstract function menuToScript($menu); + public abstract function getBootEntry(?BootEntry $entry): string; + + public abstract function getSpecial(string $special); + + 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 |