summaryrefslogtreecommitdiffstats
path: root/modules-available/serversetup-bwlp-ipxe/page.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2019-03-08 16:13:49 +0100
committerSimon Rettberg2019-03-08 16:13:49 +0100
commitf535295c86bc029da86582fe6a1ba3f96d64a1da (patch)
tree3d3f56a522595b965b1608baa1b70f5ccbec5eed /modules-available/serversetup-bwlp-ipxe/page.inc.php
parent[serversetup-bwlp-ipxe] Improve legacy PXELinux import (diff)
downloadslx-admin-f535295c86bc029da86582fe6a1ba3f96d64a1da.tar.gz
slx-admin-f535295c86bc029da86582fe6a1ba3f96d64a1da.tar.xz
slx-admin-f535295c86bc029da86582fe6a1ba3f96d64a1da.zip
[serversetup-bwlp-ipxe] Fix bugs, add import feature
Diffstat (limited to 'modules-available/serversetup-bwlp-ipxe/page.inc.php')
-rw-r--r--modules-available/serversetup-bwlp-ipxe/page.inc.php90
1 files changed, 74 insertions, 16 deletions
diff --git a/modules-available/serversetup-bwlp-ipxe/page.inc.php b/modules-available/serversetup-bwlp-ipxe/page.inc.php
index 07683df3..95ebb69f 100644
--- a/modules-available/serversetup-bwlp-ipxe/page.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/page.inc.php
@@ -87,6 +87,11 @@ class Page_ServerSetup extends Page
$this->saveLocalboot();
}
+ if ($action === 'import') {
+ User::assertPermission('ipxe.bootentry.edit');
+ $this->execImportPxeMenu();
+ }
+
if ($action === 'deleteMenu') {
// Permcheck in function
$this->deleteMenu();
@@ -116,6 +121,9 @@ class Page_ServerSetup extends Page
if (User::hasPermission('ipxe.localboot.*')) {
Dashboard::addSubmenu('?do=serversetup&show=localboot', Dictionary::translate('submenu_localboot', true));
}
+ if (User::hasPermission('ipxe.bootentry.*')) {
+ Dashboard::addSubmenu('?do=serversetup&show=import', Dictionary::translate('submenu_import', true));
+ }
if (Request::get('show') === false) {
$subs = Dashboard::getSubmenus();
if (empty($subs)) {
@@ -174,6 +182,10 @@ class Page_ServerSetup extends Page
User::assertPermission('ipxe.localboot.*');
$this->showLocalbootConfig();
break;
+ case 'import':
+ User::assertPermission('ipxe.bootentry.edit');
+ $this->showImportMenu();
+ break;
default:
Util::redirect('?do=serversetup');
break;
@@ -267,6 +279,11 @@ class Page_ServerSetup extends Page
Render::addTemplate('localboot', $data);
}
+ private function showImportMenu()
+ {
+ Render::addTemplate('page-import');
+ }
+
private function showBootentryList()
{
$allowEdit = User::hasPermission('ipxe.bootentry.edit');
@@ -375,32 +392,45 @@ class Page_ServerSetup extends Page
}
$menu['keys'] = array_map(function ($item) { return ['key' => $item]; }, MenuEntry::getKeyList());
$menu['entrylist'] = Database::queryAll("SELECT entryid, title, hotkey, data FROM serversetup_bootentry ORDER BY title ASC");
+ class_exists('BootEntry'); // Leave this here for StandardBootEntry
foreach ($menu['entrylist'] as &$bootentry) {
- //$bootentry['json'] = $bootentry['data'];
$bootentry['data'] = json_decode($bootentry['data'], true);
+ // Transform stuff suitable for mustache
if (array_key_exists('arch', $bootentry['data'])) {
- $bootentry['data']['PCBIOS'] = array('executable' => $bootentry['data']['executable']['PCBIOS'],
- 'initRd' => $bootentry['data']['initRd']['PCBIOS'],
- 'commandLine' => $bootentry['data']['commandLine']['PCBIOS']);
- $bootentry['data']['EFI'] = array('executable' => $bootentry['data']['executable']['EFI'],
- 'initRd' => $bootentry['data']['initRd']['EFI'],
- 'commandLine' => $bootentry['data']['commandLine']['EFI']);
-
- if ($bootentry['data']['arch'] === 'PCBIOS') {
+ // BIOS/EFI or both
+ if ($bootentry['data']['arch'] === StandardBootEntry::BIOS
+ || $bootentry['data']['arch'] === StandardBootEntry::BOTH) {
+ $bootentry['data']['PCBIOS'] = array('executable' => $bootentry['data']['executable']['PCBIOS'],
+ 'initRd' => $bootentry['data']['initRd']['PCBIOS'],
+ 'commandLine' => $bootentry['data']['commandLine']['PCBIOS']);
+ }
+ if ($bootentry['data']['arch'] === StandardBootEntry::EFI
+ || $bootentry['data']['arch'] === StandardBootEntry::BOTH) {
+ $bootentry['data']['EFI'] = array('executable' => $bootentry['data']['executable']['EFI'],
+ 'initRd' => $bootentry['data']['initRd']['EFI'],
+ 'commandLine' => $bootentry['data']['commandLine']['EFI']);
+ }
+ // Naming and agnostic
+ if ($bootentry['data']['arch'] === StandardBootEntry::BIOS) {
$bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_biosOnly', true);
unset($bootentry['data']['EFI']);
- } else if ($bootentry['data']['arch'] === 'EFI') {
+ } elseif ($bootentry['data']['arch'] === StandardBootEntry::EFI) {
$bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_efiOnly', true);
unset($bootentry['data']['PCBIOS']);
+ } elseif ($bootentry['data']['arch'] === StandardBootEntry::AGNOSTIC) {
+ $bootentry['data']['archAgnostic'] = array('executable' => $bootentry['data']['executable']['PCBIOS'],
+ 'initRd' => $bootentry['data']['initRd']['PCBIOS'],
+ 'commandLine' => $bootentry['data']['commandLine']['PCBIOS']);
+ $bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_archAgnostic', true);
+ unset($bootentry['data']['EFI']);
} else {
$bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_archBoth', true);
}
-
- } elseif (!array_key_exists('script', $bootentry['data'])) {
- $bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_archAgnostic', true);
- $bootentry['data']['archAgnostic'] = array('executable' => $bootentry['data']['executable'],
- 'initRd' => $bootentry['data']['initRd'],
- 'commandLine' => $bootentry['data']['commandLine']);
+ foreach ($bootentry['data'] as &$e) {
+ if (isset($e['initRd']) && is_array($e['initRd'])) {
+ $e['initRd'] = implode(',', $e['initRd']);
+ }
+ }
}
}
foreach ($menu['entries'] as &$entry) {
@@ -827,4 +857,32 @@ class Page_ServerSetup extends Page
Util::redirect('?do=serversetup&show=localboot');
}
+ private function execImportPxeMenu()
+ {
+ $content = Request::post('pxemenu', false, 'string');
+ if (empty($content)) {
+ Message::addError('main.parameter-empty', 'pxemenu');
+ Util::redirect('?do=serversetup&show=import');
+ }
+ $menu = PxeLinux::parsePxeLinux($content, false);
+ if (empty($menu->sections)) {
+ Message::addWarning('import-no-entries');
+ Util::redirect('?do=serversetup&show=import');
+ }
+ if (Request::post('entries-only', 0, 'int') !== 0) {
+ $foo = [];
+ $bar = false;
+ IPxe::importPxeMenuEntries($menu, $foo, $bar);
+ Util::redirect('?do=serversetup&show=bootentry');
+ } else {
+ $id = IPxe::insertMenu($menu, 'Imported Menu', false, 0, [], []);
+ if ($id === false) {
+ Message::addError('import-error');
+ Util::redirect('?do=serversetup&show=import');
+ } else {
+ Util::redirect('?do=serversetup&show=editmenu&id=' . $id);
+ }
+ }
+ }
+
}