From 8cdccaeb71a167c6a16b715e65967da3be8a040a Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 10 Jul 2020 16:40:06 +0200 Subject: [serversetup-bwlp-ipxe] Progress on new structure (+bash) --- .../inc/scriptbuilderipxe.inc.php | 50 +++++++++++++--------- 1 file changed, 30 insertions(+), 20 deletions(-) (limited to 'modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderipxe.inc.php') diff --git a/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderipxe.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderipxe.inc.php index 23c4bd70..1b33a1ac 100644 --- a/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderipxe.inc.php +++ b/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderipxe.inc.php @@ -86,32 +86,39 @@ HERE; return $output; } - public function fallback() + /** + * Called when we handle a real client request, and don't just generate static data + * for whatever use-case that might have. In the latter case, it wouldn't make much sense + * to generate a redirect code snippet. + * @return string + */ + public function bootstrapLive() { // Check if required arguments are given; if not, spit out according script and chain to self - $uuid = Request::any('uuid', false, 'string'); - error_log("Got UUID='$uuid' PLATF='" . $this->platform . "'"); - if ($uuid === false || $this->platform === '') { + if ($this->uuid === false || $this->platform === '') { // REQUIRED so we can hide incompatible entries return $this->redirect(); } + return false; + } - $menu = IPxeMenu::forClient($this->clientIp, $uuid); - $out = $this->menuCheckAutostart($menu); - if (!empty($out)) - return "#!ipxe\nimgfree ||\n" . $out; - - return "#!ipxe\nimgfree ||\n" . $this->menuToScript($menu); + public function getBootEntry($entry) + { + if (!$entry) { + return "#!ipxe\nprompt --timeout 5000 Invalid boot entry id\n"; + } + return $entry->toScript($this); } - public function getMenu($menuId) + public function getMenu(IPxeMenu $menu, bool $bootstrap) { - $menu = IPxeMenu::get($menuId, true); + if ($bootstrap) { + return "#!ipxe\nimgfree ||\n" . $this->menuToScript($menu); + } $base = $this->getUrlFull($he); return "#!ipxe\nset self {$base} ||\n" . $this->menuToScript($menu); } - /** * @param IPxeMenu $menu */ @@ -144,7 +151,7 @@ cpair --foreground 7 --background 9 0 console --left 55 --top 88 --right 63 --bottom 64 $slxConsoleUpdate --keep --picture bg-menu || -menu -- {$menu->title} || prompt Error creating menu || +menu -- {$menu->title} || prompt --timeout 5000 Error creating menu || HERE; foreach ($menu->items as $item) { @@ -306,7 +313,6 @@ console || $localboot || goto fail BLA; - // } else { $output = "prompt --timeout 5000 Unknown special command '$special' ||\nchain -ar \${self}\n"; @@ -381,12 +387,12 @@ chain -a \${self}&entryid={$entry->menuentryid}##params || goto fail || HERE; } - public function getMenuEntry($menuEntryId) + public function getMenuEntry($entry, $honorPassword = true) { - $entry = MenuEntry::get($menuEntryId); if ($entry === null) - return "#!ipxe\nprompt --timeout 10000 Invalid menu entry id: $menuEntryId\n"; + return "#!ipxe\nprompt --timeout 10000 Invalid menu entry id\n"; $base = $this->getUrlBase(); + $meid = $entry->menuEntryId(); // Make sure legacy variables are set; they might get used $output = <<serverIp} || iseq \${idx} \${} && set idx:string X || iseq \${self} \${} && set self {$base}? || +set menuentryid $meid || HERE; // Check for password - if (!empty($entry->md5pass)) { // TODO: This should be split out so we can unconditionally get entry code + if ($honorPassword && !empty($entry->md5pass)) { $pwh = Request::post('pwhash', false, 'string'); $pwp = Request::post('pwplain', false, 'string'); if ($pwh === false && $pwp === false) { @@ -459,6 +466,9 @@ HERE; return $output . "goto fail\n"; } // static, we know in advance + if ($efi !== null && $this->platform === BootEntry::EFI) + return $this->execDataToScriptInternal($efi) . "\ngoto fail\n"; + // Should be BIOS at this point return $this->execDataToScriptInternal($bios ?? $efi ?? new ExecData()) . "\ngoto fail\n"; } @@ -510,7 +520,7 @@ HERE; } } if (!empty($entry->commandLine)) { - $script .= ' ' . $entry->commandLine; + $script .= ' ' . $entry->commandLine . ' slx.ipxe.id=${menuentryid}'; } $script .= " || goto fail\n"; if ($entry->resetConsole) { -- cgit v1.2.3-55-g7522