summaryrefslogtreecommitdiffstats
path: root/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderipxe.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderipxe.inc.php')
-rw-r--r--modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderipxe.inc.php137
1 files changed, 43 insertions, 94 deletions
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderipxe.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderipxe.inc.php
index 385cd15f..9421684f 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';
@@ -136,13 +133,13 @@ HERE;
imgstat bg-menu || imgfetch --name bg-menu /tftp/pxe-menu.png ||
console --left 55 --top 88 --right 63 --bottom 64 --keep --picture bg-menu ||
-colour --rgb 0xffffff 7
-colour --rgb 0xcccccc 5
-colour --rgb 0x000000 0
-colour --rgb 0xdddddd 6
-cpair --foreground 0 --background 4 1
-cpair --foreground 0 --background 5 2
-cpair --foreground 7 --background 9 0
+colour --rgb 0xffffff 7 ||
+colour --rgb 0xcccccc 5 ||
+colour --rgb 0x000000 0 ||
+colour --rgb 0xdddddd 6 ||
+cpair --foreground 0 --background 4 1 ||
+cpair --foreground 0 --background 5 2 ||
+cpair --foreground 7 --background 9 0 ||
:slx_menu
@@ -166,7 +163,11 @@ HERE;
$output .= " selection || goto default || goto fail\n";
$output .= <<<HERE
console --left 60 --top 130 --right 67 --bottom 86 $slxConsoleUpdate ||
+set slx_exit \${} ||
chain -a \${self}&entryid=\${selection} ||
+iseq \${slx_exit} \${} || console ||
+iseq \${slx_exit} \${} || echo Exiting with code \${slx_exit} ||
+iseq \${slx_exit} \${} || exit \${slx_exit}
goto fail || goto start
goto \${target} ||
echo Could not find menu entry in script.
@@ -179,49 +180,10 @@ prompt Boot failed. Press any key to start.
goto start
HERE;
-
- /*
-
- :i5
- chain -a /tftp/memtest.0 passes=1 onepass || goto membad
- prompt Memory OK. Press a key.
- goto init
-
- :i8
- set x:int32 0
- :again
- console --left 60 --top 130 --right 67 --bottom 96 --picture bg-load --keep ||
- console --left 55 --top 88 --right 63 --bottom 64 --picture bg-menu --keep ||
- inc x
- iseq \${x} 20 || goto again
- prompt DONE. Press dein Knie.
- goto slx_menu
-
- :membad
- iseq \${errno} 0x1 || goto memaborted
- params
- param scrot \${vram}
- imgfetch -a http://132.230.8.113/screen.php##params ||
- prompt Memory is bad. Press a key.
- goto init
-
- :memaborted
- params
- param scrot \${vram}
- imgfetch -a http://132.230.8.113/screen.php##params ||
- prompt Memory test aborted. Press a key.
- goto init
-
- */
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) {
@@ -250,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
@@ -299,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 ||
@@ -317,17 +275,27 @@ BLA;
return $output;
}
- public function output($string)
+ public function output(string $string): void
{
- setlocale(LC_ALL, 'de_DE.UTF-8', 'de_DE.utf-8', 'de_DE.utf8', 'de_DE', 'de', 'German', 'ge', 'en_US.UTF-8', 'en_US.utf-8');
- if ($this->platform === 'EFI') {
- $cs = 'ASCII';
+ // 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
+ // all non-ASCII chars differently.
+ // Use 'ipxe.compile-time' instead of const from IpxeBuilder to avoid pulling in another include
+ if (!preg_match('/Version: (\d{4})-\d{2}-\d{2}\b/', Property::get('ipxe.compile-time'), $out)
+ || (int)$out[1] >= 2022) {
+ Header('Content-Type: text/plain; charset=UTF-8');
+ echo $string;
} else {
- $cs = 'IBM437';
- }
- Header('Content-Type: text/plain; charset=' . $cs);
+ if ($this->platform === 'EFI') {
+ $cs = 'ASCII';
+ } else {
+ $cs = 'IBM437';
+ }
+ Header('Content-Type: text/plain; charset=' . $cs);
- echo iconv('UTF-8', $cs . '//TRANSLIT//IGNORE', $string);
+ setlocale(LC_ALL, 'de_DE.UTF-8', 'de_DE.utf-8', 'de_DE.utf8', 'de_DE', 'de', 'German', 'ge', 'en_US.UTF-8', 'en_US.utf-8');
+ echo iconv('UTF-8', $cs . '//TRANSLIT//IGNORE', $string);
+ }
}
public function modfilt($str)
@@ -337,28 +305,9 @@ BLA;
return trim(preg_replace('/\s+/', ' ', $str));
}
- /**
- * @param IPxeMenu $menu
- */
- private function menuCheckAutostart($menu)
- {
- // If this is a menu with a single item, treat a timeout of 0 as "boot immediately" instead of "infinite"
- if ($menu->itemCount() === 1 && $menu->timeoutMs() === 0 && ($tmp = $menu->getDefaultEntryId()) !== null) {
- if (empty($menu->items[0]->md5pass)) {
- return $menu->items[0]->getBootEntryScript($this);
- } else {
- return $this->passwordDialog($menu->items[0]);
- }
- }
- return '';
- }
-
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));
@@ -384,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";
@@ -438,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";