From 3fb99a5e8c229885602198bea4dce26bcf0fcc4f Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 10 Jun 2020 17:12:02 +0200 Subject: [serversetup-bwlp-ipxe] Start refactoring ipxe script generator This is WIP. Mostly restored all the old functionality. Boot entries are fetched when selected, not embedded in the main script, so password protection is a bit stronger. Hopefully allows for other script generators in the future. --- .../serversetup-bwlp-ipxe/api.inc.php | 277 +-------------------- 1 file changed, 8 insertions(+), 269 deletions(-) (limited to 'modules-available/serversetup-bwlp-ipxe/api.inc.php') diff --git a/modules-available/serversetup-bwlp-ipxe/api.inc.php b/modules-available/serversetup-bwlp-ipxe/api.inc.php index c3804a03..303f1560 100644 --- a/modules-available/serversetup-bwlp-ipxe/api.inc.php +++ b/modules-available/serversetup-bwlp-ipxe/api.inc.php @@ -1,273 +1,12 @@ getMenuEntry($entryId); } else { - $urlbase = 'http://' . $serverIp; - } - $urlbase .= $url['path']; - if (empty($url['query'])) { - $arr = []; - } else { - parse_str($url['query'], $arr); - foreach ($arr as &$v) { - $v = urlencode($v); - } - unset($v); - } - $arr['uuid'] = '${uuid}'; - $arr['mac'] = '${mac}'; - $arr['manuf'] = '${manufacturer:uristring}'; - $arr['product'] = '${product:uristring}'; - $arr['platform'] = '${platform:uristring}'; - $query = '?'; - foreach ($arr as $k => $v) { - $query .= $k . '=' . $v . '&'; - } - //$query = substr($query, 0, -1); - echo <<itemCount() === 1 && $menu->timeoutMs() === 0 && ($tmp = $menu->getDefaultScriptLabel()) !== false) { - $directBoot = "goto $tmp ||"; - $initLabel = 'init'; -} else { - $directBoot = ''; -} - -// Get preferred localboot method, depending on system model -$localboot = false; -$model = false; -if ($uuid !== false && Module::get('statistics') !== false) { - // If we have the machine table, we rather try to look up the system model from there, using the UUID - $row = Database::queryFirst('SELECT systemmodel FROM machine WHERE machineuuid = :uuid', ['uuid' => $uuid]); - if ($row !== false && !empty($row['systemmodel'])) { - $model = $row['systemmodel']; - } -} -if ($model === false) { - // Otherwise use what iPXE sent us - function modfilt($str) - { - if (empty($str) || preg_match('/product\s+name|be\s+filled|unknown|default\s+string|system\s+model|manufacturer/i', $str)) - return false; - return trim(preg_replace('/\s+/', ' ', $str)); - } - $manuf = modfilt($manuf); - $product = modfilt($product); - if (!empty($product)) { - $model = $product; - if (!empty($manuf)) { - $model .= " ($manuf)"; - } + $data = $builder->fallback(); } -} -// Query -if ($model !== false) { - $e = strtolower($platform); // We made sure $platform is either PCBIOS or EFI, so no injection possible - $row = Database::queryFirst("SELECT $e AS bootmethod FROM serversetup_localboot WHERE systemmodel = :model LIMIT 1", - ['model' => $model]); - if ($row !== false) { - $localboot = $row['bootmethod']; - } -} -if ($localboot === false || !isset($BOOT_METHODS[$localboot])) { - $localboot = Localboot::getDefault()[$platform]; - if (!isset($BOOT_METHODS[$localboot])) { - $localboot = array_keys($BOOT_METHODS)[0]; - } -} -// Convert to actual ipxe code -if (isset($BOOT_METHODS[$localboot])) { - $localboot = $BOOT_METHODS[$localboot]; -} else { - $localboot = 'prompt Localboot not possible'; -} - -if ($slxExtensions) { - $slxConsoleUpdate = '--update'; - $slxPasswordOnly = '--nouser'; -} else { - $slxConsoleUpdate = ''; - $slxPasswordOnly = ''; -} - -$output = <<getMenuDefinition('target', $platform, $slxExtensions); - -$output .= <<getItemsCode($platform); - -/* - -: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 - -*/ - -$output .= <<output($data); +})(); -- cgit v1.2.3-55-g7522