From 77d5885827f123745a0d304019bb6bd0952b45cd Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 15 Feb 2018 15:06:40 +0100 Subject: [serversetup-bwlp] Make use of new permission helpers --- .../serversetup-bwlp/templates/ipaddress.html | 7 +++++-- modules-available/serversetup-bwlp/templates/ipxe.html | 18 +++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) (limited to 'modules-available/serversetup-bwlp/templates') diff --git a/modules-available/serversetup-bwlp/templates/ipaddress.html b/modules-available/serversetup-bwlp/templates/ipaddress.html index e82253f5..8d73dfac 100644 --- a/modules-available/serversetup-bwlp/templates/ipaddress.html +++ b/modules-available/serversetup-bwlp/templates/ipaddress.html @@ -1,4 +1,4 @@ -
+
{{lang_bootAddress}}
@@ -20,7 +20,10 @@ {{/default}} {{^default}} - + {{/default}} diff --git a/modules-available/serversetup-bwlp/templates/ipxe.html b/modules-available/serversetup-bwlp/templates/ipxe.html index e0dc53e5..f4b0b4d3 100644 --- a/modules-available/serversetup-bwlp/templates/ipxe.html +++ b/modules-available/serversetup-bwlp/templates/ipxe.html @@ -3,7 +3,7 @@ -
+
{{lang_bootMenu}}
@@ -16,15 +16,15 @@
{{lang_bootBehavior}}
- +
- +
- +
@@ -32,7 +32,7 @@
{{lang_menuDisplayTime}}
- + {{lang_seconds}}
@@ -40,22 +40,22 @@
{{lang_masterPassword}}
- +
{{lang_masterPasswordHelp}}
{{lang_menuCustom}} - +
@@ -27,6 +27,9 @@ if (task.data.pxeDone) $('#built-pxe').removeClass('invisible'); if (task.data.usbDone) $('#built-usb').removeClass('invisible'); } + if (task.statusCode === 'TASK_ERROR' || task.statusCode === 'TASK_FINISHED') { + $('#tm-compile-div').find('pre').hide(); + } if (task.statusCode === 'TASK_ERROR') { var $gf = $('#genfailed'); if (task.data && task.data.errors) { -- cgit v1.2.3-55-g7522 From 2f3f7ba4844ca4acff33569f3fa46ccf6301c92f Mon Sep 17 00:00:00 2001 From: Udo Walter Date: Thu, 4 Oct 2018 03:19:44 +0200 Subject: [serversetup-bwlp] bootmenu-edit UI improvements - add cancel button - add checkbox to hide menu entries - add button to remove menu entries - hide input fields not relevant for spacers - add modal to select an entry that shows some information about the selected entry --- modules-available/serversetup-bwlp/page.inc.php | 6 +- .../serversetup-bwlp/templates/menu-edit.html | 269 ++++++++++++++------- 2 files changed, 189 insertions(+), 86 deletions(-) (limited to 'modules-available/serversetup-bwlp/templates') diff --git a/modules-available/serversetup-bwlp/page.inc.php b/modules-available/serversetup-bwlp/page.inc.php index 4ebb7530..615bac64 100644 --- a/modules-available/serversetup-bwlp/page.inc.php +++ b/modules-available/serversetup-bwlp/page.inc.php @@ -261,7 +261,11 @@ class Page_ServerSetup extends Page $menu['entries'] = Database::queryAll("SELECT menuentryid, entryid, hotkey, title, hidden, sortval, plainpass FROM serversetup_menuentry WHERE menuid = :id ORDER BY sortval ASC", compact('id')); $menu['keys'] = array_map(function ($item) { return ['key' => $item]; }, MenuEntry::getKeyList()); - $menu['entrylist'] = Database::queryAll("SELECT entryid, title, hotkey FROM serversetup_bootentry ORDER BY title ASC"); + $menu['entrylist'] = Database::queryAll("SELECT entryid, title, hotkey, data FROM serversetup_bootentry ORDER BY title ASC"); + foreach ($menu['entrylist'] as &$bootentry) { + $bootentry['json'] = $bootentry['data']; + $bootentry['data'] = json_decode($bootentry['data']); + } foreach ($menu['entries'] as &$entry) { $entry['isdefault'] = ($entry['menuentryid'] == $menu['defaultentryid']); // TODO: plainpass only when permissions diff --git a/modules-available/serversetup-bwlp/templates/menu-edit.html b/modules-available/serversetup-bwlp/templates/menu-edit.html index c0a353b4..e695ef20 100644 --- a/modules-available/serversetup-bwlp/templates/menu-edit.html +++ b/modules-available/serversetup-bwlp/templates/menu-edit.html @@ -7,7 +7,7 @@
{{title}} {{^title}} - {{lang_newMenu}} + {{lang_newMenu}} {{/title}}
@@ -50,86 +50,151 @@ - - - + + + - - + + + + {{#entries}} - - - - - - + + + + - + + - - {{#entryid}} - - {{/entryid}} - - - + + + + + + + + + + {{/entries}}
{{lang_entryId}}{{lang_entryId}} {{lang_title}}{{lang_hotkey}}{{lang_password}}{{lang_hotkey}}{{lang_password}}
- - -
- - -
-
+ + + +
+ + +
+
+ + - - - - - -
+ + + + + + +
+ + +
+
+ +
-
+
+
+
+ {{lang_cancel}}
+ +
- @@ -141,38 +206,52 @@ -
+ - + + - - + + + +
+ + +
+ + + \ No newline at end of file -- cgit v1.2.3-55-g7522 From 093d16682743eb1502819bb6c127afeac65d4ede Mon Sep 17 00:00:00 2001 From: Udo Walter Date: Fri, 9 Nov 2018 02:46:50 +0100 Subject: [serversetup-bwlp] add location selection to menu edit + ui improvements - add multiselect to select the locations - add architecture information to the bootentry select modal - add glyphicon to the hide entry column header - default menu is now selected in the menu list - fixed error when creating a menu (isdefault has no default value) and when creating a menu without bootentries --- modules-available/serversetup-bwlp/config.json | 3 +- modules-available/serversetup-bwlp/page.inc.php | 221 ++++++++++++++------- .../serversetup-bwlp/templates/menu-edit.html | 124 +++++++++--- .../serversetup-bwlp/templates/menu-list.html | 11 +- 4 files changed, 261 insertions(+), 98 deletions(-) (limited to 'modules-available/serversetup-bwlp/templates') diff --git a/modules-available/serversetup-bwlp/config.json b/modules-available/serversetup-bwlp/config.json index ff485760..8b3ce2a3 100644 --- a/modules-available/serversetup-bwlp/config.json +++ b/modules-available/serversetup-bwlp/config.json @@ -2,6 +2,7 @@ "category": "main.settings-server", "dependencies" : [ "locations", - "js_jqueryui" + "js_jqueryui", + "bootstrap_multiselect" ] } \ No newline at end of file diff --git a/modules-available/serversetup-bwlp/page.inc.php b/modules-available/serversetup-bwlp/page.inc.php index 615bac64..87c57dea 100644 --- a/modules-available/serversetup-bwlp/page.inc.php +++ b/modules-available/serversetup-bwlp/page.inc.php @@ -87,6 +87,11 @@ class Page_ServerSetup extends Page $this->deleteMenu(); } + if ($action === 'setDefaultMenu') { + User::assertPermission('ipxe.menu.edit', 0); + $this->setDefaultMenu(); + } + if (Request::isPost()) { Util::redirect('?do=serversetup'); } @@ -213,7 +218,8 @@ class Page_ServerSetup extends Page Render::addTemplate('menu-list', array( 'menuTable' => $menuTable, - 'allowAddMenu' => $allowAddMenu + 'allowAddMenu' => $allowAddMenu, + 'showSetDefault' => User::hasPermission('ipxe.menu.edit', 0) )); } @@ -252,11 +258,15 @@ class Page_ServerSetup extends Page Message::addError('invalid-menu-id', $id); Util::redirect('?do=serversetup&show=menu'); } - if (!$this->hasMenuPermission($id, 'ipxe.menu.edit')) { + if ($id !== 0 && !$this->hasMenuPermission($id, 'ipxe.menu.edit')) { $menu['readonly'] = 'readonly'; $menu['disabled'] = 'disabled'; $menu['plainpass'] = ''; } + if (!User::hasPermission('ipxe.menu.edit', 0)) { + $menu['globalMenuWarning'] = true; + } + $menu['timeout'] = round($menu['timeoutms'] / 1000); $menu['entries'] = Database::queryAll("SELECT menuentryid, entryid, hotkey, title, hidden, sortval, plainpass FROM serversetup_menuentry WHERE menuid = :id ORDER BY sortval ASC", compact('id')); @@ -264,13 +274,50 @@ class Page_ServerSetup extends Page $menu['entrylist'] = Database::queryAll("SELECT entryid, title, hotkey, data FROM serversetup_bootentry ORDER BY title ASC"); foreach ($menu['entrylist'] as &$bootentry) { $bootentry['json'] = $bootentry['data']; - $bootentry['data'] = json_decode($bootentry['data']); + $bootentry['data'] = json_decode($bootentry['data'], true); + 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') { + $bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_biosOnly', true); + unset($bootentry['data']['EFI']); + } else if ($bootentry['data']['arch'] === 'EFI') { + $bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_efiOnly', true); + unset($bootentry['data']['PCBIOS']); + } else { + $bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_archBoth', true); + } + + } else { + $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 ($menu['entries'] as &$entry) { $entry['isdefault'] = ($entry['menuentryid'] == $menu['defaultentryid']); // TODO: plainpass only when permissions } // TODO: Make assigned locations editable + + $currentLocations = Database::queryColumnArray('SELECT locationid FROM serversetup_menu_location + WHERE menuid = :menuid', array('menuid' => $id)); + $menu['locations'] = Location::getLocations($currentLocations); + + // if user has no permission to edit for this location, disable the location in the select + $allowedEditLocations = User::getAllowedLocations('ipxe.menu.edit'); + foreach ($menu['locations'] as &$loc) { + if (!in_array($loc["locationid"], $allowedEditLocations)) { + $loc["disabled"] = "disabled"; + } + } + Permission::addGlobalTags($menu['perms'], 0, ['ipxe.menu.edit']); Render::addTemplate('menu-edit', $menu); } @@ -300,6 +347,7 @@ class Page_ServerSetup extends Page $params['oldentryid'] = $params['entryid'] = $row['entryid']; $params['builtin'] = $row['builtin']; } + Render::addTemplate('ipxe-new-boot-entry', $params); } @@ -361,6 +409,17 @@ class Page_ServerSetup extends Page Message::addSuccess('bootentry-deleted'); } + private function setDefaultMenu() + { + $id = Request::post('menuid', false, 'int'); + if ($id === false) { + Message::addError('main.parameter-missing', 'menuid'); + return; + } + Database::exec('UPDATE serversetup_menu SET isdefault = (menuid = :menuid)', ['menuid' => $id]); + Message::addSuccess('menu-set-default'); + } + private function deleteMenu() { $id = Request::post('deleteid', false, 'int'); @@ -374,7 +433,6 @@ class Page_ServerSetup extends Page } Database::exec("DELETE FROM serversetup_menu WHERE menuid = :menuid", array("menuid" => $id)); Message::addSuccess('menu-deleted'); - } private function saveMenu() @@ -384,13 +442,30 @@ class Page_ServerSetup extends Page Message::addError('main.parameter-missing', 'menuid'); return; } - // TODO: Validate new locations to be saved (and actually save them) + + $locationids = Request::post('locations', [], "ARRAY"); + // check if the user is allowed to edit the menu on the affected locations + $allowedEditLocations = User::getAllowedLocations('ipxe.menu.edit'); + $currentLocations = Database::queryColumnArray('SELECT locationid FROM serversetup_menu_location + WHERE menuid = :menuid', array('menuid' => $id)); + // permission denied if the user tries to assign or remove a menu to/from locations he has no edit rights for + // or if the user tries to save a menu without locations but does not have the permission for the root location (0) + if (!in_array(0, $allowedEditLocations) + && ( + (!empty(array_diff($locationids, $allowedEditLocations)) && !empty(array_diff($currentLocations, $allowedEditLocations))) + || empty($locationids) + ) + ) { + Message::addError('main.no-permission'); + Util::redirect('?do=serversetup'); + } + $insertParams = [ 'title' => IPxe::sanitizeIpxeString(Request::post('title', '', 'string')), 'timeoutms' => abs(Request::post('timeout', 0, 'int') * 1000), ]; if ($id === 0) { - Database::exec("INSERT INTO serversetup_menu (title, timeoutms) VALUES (:title, :timeoutms)", $insertParams); + Database::exec("INSERT INTO serversetup_menu (title, timeoutms, isdefault) VALUES (:title, :timeoutms, 0)", $insertParams); $menu['menuid'] = $id = Database::lastInsertId(); } else { $menu = Database::queryFirst("SELECT m.menuid, GROUP_CONCAT(l.locationid) AS locations @@ -410,88 +485,98 @@ class Page_ServerSetup extends Page WHERE menuid = :menuid', $insertParams); } - if (User::hasPermission('ipxe.menu.edit', 0) - && Request::post('defmenu', false, 'boolean')) { - Database::exec('UPDATE serversetup_menu SET isdefault = (menuid = :menuid)', ['menuid' => $id]); - } - $keepIds = []; $entries = Request::post('entry', false, 'array'); $wantedDefaultEntryId = Request::post('defaultentry', null, 'string'); $defaultEntryId = null; - foreach ($entries as $key => $entry) { - if (!isset($entry['sortval'])) { - error_log(print_r($entry, true)); - continue; - } - // Fallback defaults - $entry += [ - 'entryid' => null, - 'title' => '', - 'hidden' => 0, - 'plainpass' => '', - ]; - $params = [ - 'title' => IPxe::sanitizeIpxeString($entry['title']), - 'sortval' => (int)$entry['sortval'], - 'menuid' => $menu['menuid'], - ]; - if (empty($entry['entryid'])) { - // Spacer - $params += [ + if ($entries) { + foreach ($entries as $key => $entry) { + if (!isset($entry['sortval'])) { + error_log(print_r($entry, true)); + continue; + } + // Fallback defaults + $entry += [ 'entryid' => null, - 'hotkey' => '', - 'hidden' => 0, // Doesn't make any sense - 'plainpass' => '', // Doesn't make any sense + 'title' => '', + 'hidden' => 0, + 'plainpass' => '', ]; - } else { - $params += [ - 'entryid' => $entry['entryid'], // TODO validate? - 'hotkey' => MenuEntry::filterKeyName($entry['hotkey']), - 'hidden' => (int)$entry['hidden'], // TODO (needs hotkey to make sense) - 'plainpass' => $entry['plainpass'], + $params = [ + 'title' => IPxe::sanitizeIpxeString($entry['title']), + 'sortval' => (int)$entry['sortval'], + 'menuid' => $menu['menuid'], ]; - } - if (is_numeric($key)) { - if ((string)$key === $wantedDefaultEntryId) { // Check now that we have generated our key - $defaultEntryId = $key; + if (empty($entry['entryid'])) { + // Spacer + $params += [ + 'entryid' => null, + 'hotkey' => '', + 'hidden' => 0, // Doesn't make any sense + 'plainpass' => '', // Doesn't make any sense + ]; + } else { + $params += [ + 'entryid' => $entry['entryid'], // TODO validate? + 'hotkey' => MenuEntry::filterKeyName($entry['hotkey']), + 'hidden' => (int)$entry['hidden'], // TODO (needs hotkey to make sense) + 'plainpass' => $entry['plainpass'], + ]; } - $keepIds[] = $key; - $params['menuentryid'] = $key; - $params['md5pass'] = IPxe::makeMd5Pass($entry['plainpass'], $key); - $ret = Database::exec('UPDATE serversetup_menuentry + if (is_numeric($key)) { + if ((string)$key === $wantedDefaultEntryId) { // Check now that we have generated our key + $defaultEntryId = $key; + } + $keepIds[] = $key; + $params['menuentryid'] = $key; + $params['md5pass'] = IPxe::makeMd5Pass($entry['plainpass'], $key); + $ret = Database::exec('UPDATE serversetup_menuentry SET entryid = :entryid, hotkey = :hotkey, title = :title, hidden = :hidden, sortval = :sortval, plainpass = :plainpass, md5pass = :md5pass WHERE menuid = :menuid AND menuentryid = :menuentryid', $params, true); - } else { - $ret = Database::exec("INSERT INTO serversetup_menuentry + } else { + $ret = Database::exec("INSERT INTO serversetup_menuentry (menuid, entryid, hotkey, title, hidden, sortval, plainpass, md5pass) VALUES (:menuid, :entryid, :hotkey, :title, :hidden, :sortval, :plainpass, '')", $params, true); - if ($ret) { - $newKey = Database::lastInsertId(); - if ((string)$key === $wantedDefaultEntryId) { // Check now that we have generated our key - $defaultEntryId = $newKey; - } - $keepIds[] = (int)$newKey; - if (!empty($entry['plainpass'])) { - Database::exec('UPDATE serversetup_menuentry SET md5pass = :md5pass WHERE menuentryid = :id', [ - 'md5pass' => IPxe::makeMd5Pass($entry['plainpass'], $newKey), - 'id' => $newKey, - ]); + if ($ret) { + $newKey = Database::lastInsertId(); + if ((string)$key === $wantedDefaultEntryId) { // Check now that we have generated our key + $defaultEntryId = $newKey; + } + $keepIds[] = (int)$newKey; + if (!empty($entry['plainpass'])) { + Database::exec('UPDATE serversetup_menuentry SET md5pass = :md5pass WHERE menuentryid = :id', [ + 'md5pass' => IPxe::makeMd5Pass($entry['plainpass'], $newKey), + 'id' => $newKey, + ]); + } } } + + if ($ret === false) { + Message::addWarning('error-saving-entry', $entry['title'], Database::lastError()); + } } + Database::exec('DELETE FROM serversetup_menuentry WHERE menuid = :menuid AND menuentryid NOT IN (:keep)', + ['menuid' => $menu['menuid'], 'keep' => $keepIds]); + // Set default entry + Database::exec('UPDATE serversetup_menu SET defaultentryid = :default WHERE menuid = :menuid', + ['menuid' => $menu['menuid'], 'default' => $defaultEntryId]); + } else { + Database::exec('DELETE FROM serversetup_menuentry WHERE menuid = :menuid', ['menuid' => $menu['menuid']]); + Database::exec('UPDATE serversetup_menu SET defaultentryid = NULL WHERE menuid = :menuid', ['menuid' => $menu['menuid']]); + } - if ($ret === false) { - Message::addWarning('error-saving-entry', $entry['title'], Database::lastError()); + Database::exec('DELETE FROM serversetup_menu_location WHERE menuid = :menuid', ['menuid' => $menu['menuid']]); + if (!empty($locationids)) { + Database::exec('DELETE FROM serversetup_menu_location WHERE locationid IN (:locationids)', ['locationids' => $locationids]); + foreach ($locationids as $locationid) { + Database::exec('INSERT INTO serversetup_menu_location (menuid, locationid) VALUES (:menuid, :locationid)', + ['menuid' => $menu['menuid'], 'locationid' => $locationid]); } } - Database::exec('DELETE FROM serversetup_menuentry WHERE menuid = :menuid AND menuentryid NOT IN (:keep)', - ['menuid' => $menu['menuid'], 'keep' => $keepIds]); - // Set default entry - Database::exec('UPDATE serversetup_menu SET defaultentryid = :default WHERE menuid = :menuid', - ['menuid' => $menu['menuid'], 'default' => $defaultEntryId]); + Message::addSuccess('menu-saved'); } diff --git a/modules-available/serversetup-bwlp/templates/menu-edit.html b/modules-available/serversetup-bwlp/templates/menu-edit.html index e695ef20..09814da9 100644 --- a/modules-available/serversetup-bwlp/templates/menu-edit.html +++ b/modules-available/serversetup-bwlp/templates/menu-edit.html @@ -38,12 +38,17 @@
+
-
- - -
+ + {{#globalMenuWarning}} + + {{/globalMenuWarning}}
@@ -56,7 +61,7 @@ {{lang_title}} {{lang_hotkey}} {{lang_password}} - + @@ -124,7 +129,7 @@
{{lang_cancel}} - @@ -154,29 +159,69 @@
{{#data}} {{#script}} -
- -
{{.}}
-
+
+ +
{{.}}
+
+ {{/script}} + {{^script}} +
+ +
{{arch}}
+
+ {{#archAgnostic}} +
+ +
{{executable}}
+
+
+ +
{{initRd}}
+
+
+ +
{{commandLine}}
+
+ {{/archAgnostic}} + {{#PCBIOS}} +
+
PCBIOS
+
+
+ +
{{executable}}
+
+
+ +
{{initRd}}
+
+
+ +
{{commandLine}}
+
+
+
+ {{/PCBIOS}} + {{#EFI}} +
+
EFI
+
+
+ +
{{executable}}
+
+
+ +
{{initRd}}
+
+
+ +
{{commandLine}}
+
+
+
+ {{/EFI}} {{/script}} - {{#executable}} -
- -
{{.}}
-
- {{/executable}} - {{#initRd}} -
- -
{{.}}
-
- {{/initRd}} - {{#commandLine}} -
- -
{{.}}
-
- {{/commandLine}} {{/data}}
{{/entrylist}} @@ -244,6 +289,29 @@ var spacerText = "{{lang_spacer}}"; document.addEventListener("DOMContentLoaded", function() { + var locationSelect = $('#panel-locations'); + locationSelect.multiselect({numberDisplayed: 1}); + var globalMenuWarning = $('#global-menu-warning'); + if (globalMenuWarning.length) { + var saveButton = $('#save-button'); + if (locationSelect.val() !== null) { + saveButton.prop('disabled', false); + globalMenuWarning.hide(); + } else { + saveButton.prop('disabled', true); + globalMenuWarning.show(); + } + locationSelect.change(function () { + if ($(this).val() !== null) { + saveButton.prop('disabled', false); + globalMenuWarning.hide(); + } else { + saveButton.prop('disabled', true); + globalMenuWarning.show(); + } + }); + } + function reassignSortValues() { var startValue = 1; $('.sort-val').each(function(index, element) { diff --git a/modules-available/serversetup-bwlp/templates/menu-list.html b/modules-available/serversetup-bwlp/templates/menu-list.html index 1f190bb7..5d8ee184 100644 --- a/modules-available/serversetup-bwlp/templates/menu-list.html +++ b/modules-available/serversetup-bwlp/templates/menu-list.html @@ -20,13 +20,22 @@ {{locationCount}} + {{^isdefault}} +
+ + + +
+ {{/isdefault}} {{#isdefault}} {{/isdefault}} {{#allowEdit}} - + {{/allowEdit}} -- cgit v1.2.3-55-g7522 From 6812e85e11718116f097f493419c489c41660c77 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 21 Nov 2018 14:53:14 +0100 Subject: [serversetup-bwlp] Compilation front-end --- modules-available/serversetup-bwlp/page.inc.php | 8 ++++- .../serversetup-bwlp/templates/ipxe_update.html | 37 +++++++++++++++------- 2 files changed, 32 insertions(+), 13 deletions(-) (limited to 'modules-available/serversetup-bwlp/templates') diff --git a/modules-available/serversetup-bwlp/page.inc.php b/modules-available/serversetup-bwlp/page.inc.php index 87c57dea..5f927173 100644 --- a/modules-available/serversetup-bwlp/page.inc.php +++ b/modules-available/serversetup-bwlp/page.inc.php @@ -124,7 +124,13 @@ class Page_ServerSetup extends Page $task = $this->getCompileTask(); if ($task !== false) { - Render::addTemplate('ipxe_update', array('taskid' => $task['id'])); + $files = []; + if ($task['data'] && $task['data']['files']) { + foreach ($task['data']['files'] as $k => $v) { + $files[] = ['name' => $k, 'namehyphen' => str_replace(['/', '.'], '-', $k)]; + } + } + Render::addTemplate('ipxe_update', array('taskid' => $task['id'], 'files' => $files)); } switch (Request::get('show')) { diff --git a/modules-available/serversetup-bwlp/templates/ipxe_update.html b/modules-available/serversetup-bwlp/templates/ipxe_update.html index 71611085..344d3905 100644 --- a/modules-available/serversetup-bwlp/templates/ipxe_update.html +++ b/modules-available/serversetup-bwlp/templates/ipxe_update.html @@ -1,13 +1,13 @@
{{lang_menuGeneration}}
- -
diff --git a/modules-available/serversetup-bwlp/templates/menu-list.html b/modules-available/serversetup-bwlp/templates/menu-list.html index 5d8ee184..67365a33 100644 --- a/modules-available/serversetup-bwlp/templates/menu-list.html +++ b/modules-available/serversetup-bwlp/templates/menu-list.html @@ -21,13 +21,15 @@ {{^isdefault}} -
+ {{#showSetDefault}} +
+ {{/showSetDefault}} {{/isdefault}} {{#isdefault}} -- cgit v1.2.3-55-g7522 From 1729bd0ec9137697a7688c5f556163717abfb54b Mon Sep 17 00:00:00 2001 From: Udo Walter Date: Fri, 23 Nov 2018 16:02:17 +0100 Subject: [serversetup-bwlp] Fix new menu entries not using the preset titles --- .../serversetup-bwlp/templates/menu-edit.html | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'modules-available/serversetup-bwlp/templates') diff --git a/modules-available/serversetup-bwlp/templates/menu-edit.html b/modules-available/serversetup-bwlp/templates/menu-edit.html index 6059333e..2141103f 100644 --- a/modules-available/serversetup-bwlp/templates/menu-edit.html +++ b/modules-available/serversetup-bwlp/templates/menu-edit.html @@ -84,7 +84,7 @@ -
- -- cgit v1.2.3-55-g7522 From 63aa220d849dca2384773bf755358557a1d711c5 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 18 Jan 2019 16:37:17 +0100 Subject: [serversetup-bwlp] Make localboot method configurable --- modules-available/serversetup-bwlp/api.inc.php | 23 ++----- .../serversetup-bwlp/inc/localboot.inc.php | 17 +++++ .../serversetup-bwlp/lang/de/messages.json | 2 + .../serversetup-bwlp/lang/de/module.json | 1 + .../serversetup-bwlp/lang/de/template-tags.json | 6 ++ modules-available/serversetup-bwlp/page.inc.php | 78 ++++++++++++++++++++++ .../serversetup-bwlp/templates/localboot.html | 59 ++++++++++++++++ 7 files changed, 169 insertions(+), 17 deletions(-) create mode 100644 modules-available/serversetup-bwlp/inc/localboot.inc.php create mode 100644 modules-available/serversetup-bwlp/templates/localboot.html (limited to 'modules-available/serversetup-bwlp/templates') diff --git a/modules-available/serversetup-bwlp/api.inc.php b/modules-available/serversetup-bwlp/api.inc.php index 4ed316a7..d089584e 100644 --- a/modules-available/serversetup-bwlp/api.inc.php +++ b/modules-available/serversetup-bwlp/api.inc.php @@ -13,10 +13,9 @@ $product = Request::any('product', false, 'string'); $slxExtensions = Request::any('slx-extensions', false, 'int'); if ($platform === false || ($uuid === false && $product === false) || $slxExtensions === false) { - error_log(print_r($_SERVER, true)); - sleep(1); + // Redirect to self with added parameters $url = parse_url($_SERVER['REQUEST_URI']); - if (isset($_SERVER['SCRIPT_URI']) && preg_match('#(\w+://[^/]+)#', $_SERVER['SCRIPT_URI'], $out)) { + if (isset($_SERVER['SCRIPT_URI']) && preg_match('#^(\w+://[^/]+)#', $_SERVER['SCRIPT_URI'], $out)) { $urlbase = $out[1]; } elseif (isset($_SERVER['REQUEST_SCHEME']) && isset($_SERVER['SERVER_NAME'])) { $urlbase = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME']; @@ -62,11 +61,7 @@ HERE; } $platform = strtoupper($platform); -$BOOT_METHODS = [ - 'EXIT' => 'exit 1', - 'COMBOOT' => 'chain /tftp/chain.c32 hd0', - 'SANBOOT' => 'sanboot --no-describe', -]; +$BOOT_METHODS = Localboot::BOOT_METHODS; $ip = $_SERVER['REMOTE_ADDR']; if (substr($ip, 0, 7) === '::ffff:') { @@ -111,15 +106,9 @@ if ($model !== false) { } } if ($localboot === false || !isset($BOOT_METHODS[$localboot])) { - $localboot = Property::get('serversetup.localboot', false); - if ($localboot === false) { - if ($platform === 'EFI') { - // It seems most (all) EFI platforms won't enumerate any drives in ipxe. - // No idea if this can be fixed in ipxe code in the future. - $localboot = 'EXIT'; - } else { - $localboot = 'SANBOOT'; - } + $localboot = Property::get('serversetup.localboot', 'AUTO'); + if (!isset($BOOT_METHODS[$localboot])) { + $localboot = 'AUTO'; } } if (isset($BOOT_METHODS[$localboot])) { diff --git a/modules-available/serversetup-bwlp/inc/localboot.inc.php b/modules-available/serversetup-bwlp/inc/localboot.inc.php new file mode 100644 index 00000000..a91d0547 --- /dev/null +++ b/modules-available/serversetup-bwlp/inc/localboot.inc.php @@ -0,0 +1,17 @@ + 'iseq EFI ${platform} && exit 1 || sanboot --no-describe', + 'EXIT' => 'exit 1', + 'COMBOOT' => 'chain /tftp/chain.c32 hd0', + 'SANBOOT' => 'sanboot --no-describe', + ]; + + + +} \ No newline at end of file diff --git a/modules-available/serversetup-bwlp/lang/de/messages.json b/modules-available/serversetup-bwlp/lang/de/messages.json index 2bcaa391..de48ef0b 100644 --- a/modules-available/serversetup-bwlp/lang/de/messages.json +++ b/modules-available/serversetup-bwlp/lang/de/messages.json @@ -7,6 +7,8 @@ "invalid-boot-entry": "Ung\u00fcltiger Booteintrag: {{0}}", "invalid-ip": "Kein Interface ist auf die Adresse {{0}} konfiguriert", "invalid-menu-id": "Ung\u00fcltige Men\u00fc-ID: {{0}}", + "localboot-invalid-method": "Ung\u00fcltige localboot-Methode: {{0}}", + "localboot-saved": "Einstellungen gespeichert", "location-menu-assigned": "{{0}} wurde ein Men\u00fc zugewiesen", "location-use-default": "{{0}} verwendet jetzt das Standardmen\u00fc", "menu-deleted": "Men\u00fc gel\u00f6scht", diff --git a/modules-available/serversetup-bwlp/lang/de/module.json b/modules-available/serversetup-bwlp/lang/de/module.json index e4c1ff4e..31d563f0 100644 --- a/modules-available/serversetup-bwlp/lang/de/module.json +++ b/modules-available/serversetup-bwlp/lang/de/module.json @@ -14,5 +14,6 @@ "submenu_address": "Server-Adresse", "submenu_bootentry": "Booteintr\u00e4ge verwalten", "submenu_download": "Downloads", + "submenu_localboot": "HDD-Boot", "submenu_menu": "Men\u00fcs verwalten" } \ No newline at end of file diff --git a/modules-available/serversetup-bwlp/lang/de/template-tags.json b/modules-available/serversetup-bwlp/lang/de/template-tags.json index 9d64ebd9..2b68b3fb 100644 --- a/modules-available/serversetup-bwlp/lang/de/template-tags.json +++ b/modules-available/serversetup-bwlp/lang/de/template-tags.json @@ -19,6 +19,7 @@ "lang_bootentryTitle": "Booteintrag", "lang_chooseIP": "Bitte w\u00e4hlen Sie die IP-Adresse, \u00fcber die der Server von den Clients zum Booten angesprochen werden soll.", "lang_commandLine": "Command line", + "lang_count": "Anzahl", "lang_customEntry": "Eigener Eintrag", "lang_downloadBootImage": "Boot-Image herunterladen", "lang_downloadRufus": "Rufus herunterladen", @@ -41,6 +42,10 @@ "lang_initRd": "Zu ladendes initramfs", "lang_isDefault": "Standard", "lang_listOfMenus": "Men\u00fcliste", + "lang_localBootDefault": "Standardm\u00e4\u00dfig verwendete Methode, um von Festplatte zu booten", + "lang_localBootExceptions": "Ausnahmen, pro Rechnermodell definierbar", + "lang_localBootHead": "Boot von Festplatte", + "lang_localBootIntro": "Aus dem iPXE Bootmen\u00fc kann auf verschiedene Arten ein Boot von der prim\u00e4ren Festplatte ausgel\u00f6st werden. In den allermeisten F\u00e4llen ist die Einstellung \"AUTO\" ausreichend, bei bestimmten Rechnermodellen kann es allerdings erforderlich sein, eine der alternativen Methoden zu erzwingen. Falls Sie einem solchen Modell begegnen, k\u00f6nnen Sie im unteren Teil dieser Seite eine solche Ausnahme festlegen. In einigen F\u00e4llen l\u00e4sst sich das Problem auch durch ein BIOS-Update auf den entsprechenden Ger\u00e4ten beheben.", "lang_localHDD": "Lokale HDD", "lang_locationCount": "Anzahl Orte", "lang_masterPassword": "Master-Passwort", @@ -60,6 +65,7 @@ "lang_newBootEntryHead": "Neuer Booteintrag", "lang_newMenu": "Neues Men\u00fc", "lang_none": "(keine)", + "lang_override": "\u00dcberschreiben", "lang_pxeBuilt": "PXE-Binary gebaut", "lang_recompileHint": "iPXE-Binaries jetzt neu kompilieren. Normalerweise wird dieser Vorgang bei \u00c4nderungen automatisch ausgef\u00fchrt. Sollten Bootprobleme auftreten, k\u00f6nnen Sie hier den Vorgang manuell ansto\u00dfen.", "lang_scriptContent": "Script", diff --git a/modules-available/serversetup-bwlp/page.inc.php b/modules-available/serversetup-bwlp/page.inc.php index a71e56ef..7766050b 100644 --- a/modules-available/serversetup-bwlp/page.inc.php +++ b/modules-available/serversetup-bwlp/page.inc.php @@ -88,6 +88,11 @@ class Page_ServerSetup extends Page Util::redirect('?do=locations'); } + if ($action === 'savelocalboot') { + User::assertPermission('ipxe.localboot.edit'); + $this->saveLocalboot(); + } + if ($action === 'deleteMenu') { // Permcheck in function $this->deleteMenu(); @@ -114,6 +119,9 @@ class Page_ServerSetup extends Page if (User::hasPermission('download')) { Dashboard::addSubmenu('?do=serversetup&show=download', Dictionary::translate('submenu_download', true)); } + if (User::hasPermission('ipxe.localboot.*')) { + Dashboard::addSubmenu('?do=serversetup&show=localboot', Dictionary::translate('submenu_localboot', true)); + } if (Request::get('show') === false) { $subs = Dashboard::getSubmenus(); if (empty($subs)) { @@ -168,6 +176,10 @@ class Page_ServerSetup extends Page // Permcheck in function $this->showEditLocation(); break; + case 'localboot': + User::assertPermission('ipxe.localboot.*'); + $this->showLocalbootConfig(); + break; default: Util::redirect('?do=serversetup'); break; @@ -218,6 +230,49 @@ class Page_ServerSetup extends Page Render::addTemplate('download', ['files' => $files]); } + private function makeSelectArray($list, $default) + { + $ret = []; + foreach (array_keys($list) as $k) { + $ret[] = [ + 'key' => $k, + 'selected' => ($k === $default ? 'selected' : ''), + ]; + } + return $ret; + } + + private function showLocalbootConfig() + { + // Default setting + $default = Property::get('serversetup.localboot', false); + if (!array_key_exists($default, Localboot::BOOT_METHODS)) { + $default = 'AUTO'; + } + $optionList = $this->makeSelectArray(Localboot::BOOT_METHODS, $default); + // Exceptions + $cutoff = strtotime('-90 days'); + $models = []; + $res = Database::simpleQuery('SELECT m.systemmodel, cnt, sl.bootmethod FROM ( + SELECT m2.systemmodel, Count(*) AS cnt FROM machine m2 + WHERE m2.lastseen > :cutoff + GROUP BY systemmodel + ) m + LEFT JOIN serversetup_localboot sl USING (systemmodel) + ORDER BY systemmodel', ['cutoff' => $cutoff]); + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + $row['options'] = $this->makeSelectArray(Localboot::BOOT_METHODS, $row['bootmethod']); + $models[] = $row; + } + // Output + $data = [ + 'default' => $default, + 'options' => $optionList, + 'exceptions' => $models, + ]; + Render::addTemplate('localboot', $data); + } + private function showBootentryList() { $allowEdit = User::hasPermission('ipxe.bootentry.edit'); @@ -734,4 +789,27 @@ class Page_ServerSetup extends Page Message::addSuccess('location-menu-assigned', $loc['locationname']); } + private function saveLocalboot() + { + $default = Request::post('default', 'AUTO', 'string'); + if (!array_key_exists($default, Localboot::BOOT_METHODS)) { + Message::addError('localboot-invalid-method', $default); + return; + } + $overrides = Request::post('override', [], 'array'); + Database::exec('TRUNCATE TABLE serversetup_localboot'); + foreach ($overrides as $model => $mode) { + if (empty($mode)) // No override + continue; + if (!array_key_exists($mode, Localboot::BOOT_METHODS)) { + Message::addWarning('localboot-invalid-method', $mode); + continue; + } + Database::exec('INSERT INTO serversetup_localboot (systemmodel, bootmethod) + VALUES (:model, :mode)', compact('model', 'mode')); + } + Message::addSuccess('localboot-saved'); + Util::redirect('?do=serversetup&show=localboot'); + } + } diff --git a/modules-available/serversetup-bwlp/templates/localboot.html b/modules-available/serversetup-bwlp/templates/localboot.html new file mode 100644 index 00000000..7000be37 --- /dev/null +++ b/modules-available/serversetup-bwlp/templates/localboot.html @@ -0,0 +1,59 @@ +

{{lang_localBootHead}}

+ +

{{lang_localBootIntro}}

+ +
+ + + + +
+
+ + +
+ +
+

+ {{lang_localBootExceptions}} +

+ + + + + + + {{#exceptions}} + + + + + + {{/exceptions}} +
{{lang_name}}{{lang_count}}{{lang_override}}
{{systemmodel}}{{cnt}} + +
+ +
+ + +
+ +
-- cgit v1.2.3-55-g7522 From b0e0eddcfeb0f7d7cdde6caad21e3a0485797890 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 18 Jan 2019 16:49:46 +0100 Subject: [serversetup-bwlp] Link systemmodel to machine list --- modules-available/serversetup-bwlp/templates/localboot.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules-available/serversetup-bwlp/templates') diff --git a/modules-available/serversetup-bwlp/templates/localboot.html b/modules-available/serversetup-bwlp/templates/localboot.html index 7000be37..960f463d 100644 --- a/modules-available/serversetup-bwlp/templates/localboot.html +++ b/modules-available/serversetup-bwlp/templates/localboot.html @@ -31,7 +31,7 @@ {{#exceptions}} - {{systemmodel}} + {{systemmodel}} {{cnt}} - +
@@ -121,6 +121,13 @@
{{/builtin}} +

{{lang_referencingMenus}}:

+ +