diff options
Diffstat (limited to 'modules-available/serversetup-bwlp-ipxe/api.inc.php')
-rw-r--r-- | modules-available/serversetup-bwlp-ipxe/api.inc.php | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/modules-available/serversetup-bwlp-ipxe/api.inc.php b/modules-available/serversetup-bwlp-ipxe/api.inc.php index dcfa7774..dc78f481 100644 --- a/modules-available/serversetup-bwlp-ipxe/api.inc.php +++ b/modules-available/serversetup-bwlp-ipxe/api.inc.php @@ -1,13 +1,27 @@ <?php (function() { - $type = Request::any('type'); + $type = Request::any('type', null, 'string'); + if ($type === null && isset($_SERVER['HTTP_USER_AGENT'])) { + if (preg_match('/^iPXE/', $_SERVER['HTTP_USER_AGENT'])) { + $type = 'ipxe'; + } elseif (preg_match('/^GRUB/', $_SERVER['HTTP_USER_AGENT'])) { + $type = 'grub'; + } elseif (preg_match('/wget|curl/i', $_SERVER['HTTP_USER_AGENT'])) { + $type = 'bash'; + } + } if ($type === 'bash') { $builder = new ScriptBuilderBash(); + } elseif ($type === 'grub') { + $builder = new ScriptBuilderGrub(); } else { $builder = new ScriptBuilderIpxe(); } - $bootEntryId = Util::cleanUtf8(Request::get('beid', false, 'string')); + $bootEntryId = Request::get('beid', false, 'string'); + if ($bootEntryId !== false) { + $bootEntryId = Util::cleanUtf8($bootEntryId); + } $entryId = Request::get('entryid', false, 'int'); if ($bootEntryId !== false) { $entry = BootEntry::fromDatabaseId($bootEntryId); @@ -16,10 +30,28 @@ $entry = MenuEntry::get($entryId); $data = $builder->getMenuEntry($entry); } else { + // Get bootstrap code if required... $data = $builder->bootstrapLive(); if ($data === false) { - $menu = IPxeMenu::forClient($builder->clientIp(), $builder->uuid()); - $data = $builder->getMenu($menu, true); + // ...otherwise, generate normal code + $menuId = Request::get('menuid', false, 'int'); + if ($menuId !== false) { + $menu = IPxeMenu::get($menuId, true); + } else { + $menu = IPxeMenu::forClient($builder->clientIp(), $builder->uuid()); + } + $data = null; + if ($menu->itemCount() === 1 && $menu->timeoutMs() === 0) { + // One entry, no timeout -- direct boot + $entry = $menu->defaultEntry(); + if ($entry !== null) { + $data = $builder->getMenuEntry($entry); + } + } + if ($data === null) { + // Show menu + $data = $builder->getMenu($menu, true); + } } } $builder->output($data); |