summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Hofmaier2018-07-24 12:41:51 +0200
committerChristian Hofmaier2018-07-24 12:41:51 +0200
commit43c02c0eb26a5253663db244346ec1f2a5b62eb2 (patch)
tree064ce46330fafb3ab92902abba465d92a568e5c5
parent[serversetup-bwlp] Delete menu entries missing from POST data (diff)
downloadslx-admin-43c02c0eb26a5253663db244346ec1f2a5b62eb2.tar.gz
slx-admin-43c02c0eb26a5253663db244346ec1f2a5b62eb2.tar.xz
slx-admin-43c02c0eb26a5253663db244346ec1f2a5b62eb2.zip
[ipxe] added add-menu-button, added delete-menu-buttons, fixed bug that timeoutms didn't save, fixed bug that last edited menu gets the isDefault value, some table styling + language tags
-rw-r--r--modules-available/serversetup-bwlp/lang/de/template-tags.json6
-rw-r--r--modules-available/serversetup-bwlp/lang/en/template-tags.json6
-rw-r--r--modules-available/serversetup-bwlp/page.inc.php75
-rw-r--r--modules-available/serversetup-bwlp/permissions/permissions.json6
-rw-r--r--modules-available/serversetup-bwlp/templates/menu-list.html54
5 files changed, 131 insertions, 16 deletions
diff --git a/modules-available/serversetup-bwlp/lang/de/template-tags.json b/modules-available/serversetup-bwlp/lang/de/template-tags.json
index 8d612ab0..14f1c134 100644
--- a/modules-available/serversetup-bwlp/lang/de/template-tags.json
+++ b/modules-available/serversetup-bwlp/lang/de/template-tags.json
@@ -1,5 +1,6 @@
{
"lang_active": "Aktiv",
+ "lang_addMenu": "Menü hinzufügen",
"lang_bootAddress": "Boot-Adresse des Servers",
"lang_bootBehavior": "Standard-Bootverhalten",
"lang_bootHint": "Das Bootmen\u00fc muss nach einer \u00c4nderung der IP-Adresse neu generiert werden. In der Regel geschieht dies automatisch, der Vorgang kann in der Sektion Bootmen\u00fc allerdings auch manuell ausgel\u00f6st werden.",
@@ -8,11 +9,15 @@
"lang_bootMenuCreate": "Bootmen\u00fc erzeugen",
"lang_chooseIP": "Bitte w\u00e4hlen Sie die IP-Adresse, \u00fcber die der Server von den Clients zum Booten angesprochen werden soll.",
"lang_customEntry": "Eigener Eintrag",
+ "lang_menuDeleteConfirm": "Sind Sie sicher, dass Sie dieses Menü löschen wollen?",
"lang_downloadImage": "USB-Image herunterladen",
"lang_downloadRufus": "Rufus herunterladen",
"lang_example": "Beispiel",
"lang_generationFailed": "Erzeugen des Bootmen\u00fcs fehlgeschlagen. Der Netzwerkboot von bwLehrpool wird wahrscheinlich nicht funktionieren. Wenn Sie den Fehler nicht selbst beheben k\u00f6nnen, melden Sie bitte die Logausgabe an das bwLehrpool-Projekt.",
+ "lang_isDefault": "Standard",
+ "lang_listOfMenus": "Menüliste",
"lang_localHDD": "Lokale HDD",
+ "lang_locationCount": "Anzahl Orte",
"lang_masterPassword": "Master-Passwort",
"lang_masterPasswordHelp": "Das Master-Passwort wird ben\u00f6tigt, um einen Booteintrag direkt am Client tempor\u00e4r durch Dr\u00fccken der Tab-Taste zu editieren. Da dies f\u00fcr Manipulation am Client genutzt werden kann, sollte diese Funktion unbedingt mit einem Passwort gesch\u00fctzt werden.",
"lang_menuCustom": "Benutzerdefinierter Men\u00fczusatz",
@@ -21,6 +26,7 @@
"lang_menuCustomHint3": "und w\u00e4hlen Sie als Standard-Bootverhalten ebenfalls custom.",
"lang_menuDisplayTime": "Anzeigedauer des Men\u00fcs",
"lang_menuGeneration": "Erzeugen des Bootmen\u00fcs",
+ "lang_menuTitle": "Menü",
"lang_moduleHeading": "iPXE \/ Boot Menu",
"lang_pxeBuilt": "PXE-Binary gebaut",
"lang_seconds": "Sekunden",
diff --git a/modules-available/serversetup-bwlp/lang/en/template-tags.json b/modules-available/serversetup-bwlp/lang/en/template-tags.json
index 9bb55f93..d70159e2 100644
--- a/modules-available/serversetup-bwlp/lang/en/template-tags.json
+++ b/modules-available/serversetup-bwlp/lang/en/template-tags.json
@@ -1,5 +1,6 @@
{
"lang_active": "Active",
+ "lang_addMenu": "Add Menu",
"lang_bootAddress": "Boot Address of the Server",
"lang_bootBehavior": "Default Boot Behavior",
"lang_bootHint": "The Boot menu must be recreated after changing the IP address. Usually this is done automatically, but the process can also be triggered manually in the section of the boot menu.",
@@ -8,11 +9,15 @@
"lang_bootMenuCreate": "Create Boot Menu",
"lang_chooseIP": "Please select the IP address that the client server will use to boot.",
"lang_customEntry": "Custom entry",
+ "lang_menuDeleteConfirm": "Are you sure you want to delete this menu?",
"lang_downloadImage": "Download USB Image",
"lang_downloadRufus": "Download Rufus",
"lang_example": "Example",
"lang_generationFailed": "Could not generate boot menu. The bwLehrpool-System might not work properly. If you can't fix the problem, please report the error log below to the bwLehrpool project.",
+ "lang_isDefault": "Default",
+ "lang_listOfMenus": "Menulist",
"lang_localHDD": "Local HDD",
+ "lang_locationCount": "Number of Locations",
"lang_masterPassword": "Master Password",
"lang_masterPasswordHelp": "The master password is required to edit a boot menu entry. This should be set for security reasons.",
"lang_menuCustom": "Custom Extra Menu",
@@ -21,6 +26,7 @@
"lang_menuCustomHint3": "and select as the default boot behavior custom as well.",
"lang_menuDisplayTime": "Menu Display Time",
"lang_menuGeneration": "Generating boot menu...",
+ "lang_menuTitle": "Menu",
"lang_moduleHeading": "iPXE \/ Boot Menu",
"lang_pxeBuilt": "Built PXE binary",
"lang_seconds": "Seconds",
diff --git a/modules-available/serversetup-bwlp/page.inc.php b/modules-available/serversetup-bwlp/page.inc.php
index dc53070b..6df4c49c 100644
--- a/modules-available/serversetup-bwlp/page.inc.php
+++ b/modules-available/serversetup-bwlp/page.inc.php
@@ -60,6 +60,11 @@ class Page_ServerSetup extends Page
$this->saveMenu();
}
+ if ($action === 'deleteMenu') {
+ User::assertPermission('ipxe.menu.delete');
+ $this->deleteMenu();
+ }
+
if (Request::isPost()) {
Util::redirect('?do=serversetup');
}
@@ -132,26 +137,35 @@ class Page_ServerSetup extends Page
private function showMenuList()
{
$allowedEdit = User::getAllowedLocations('ipxe.menu.edit');
+ $allowedDelete = User::getAllowedLocations('ipxe.menu.delete');
// TODO Permission::addGlobalTags($perms, null, ['edit.menu', 'edit.address', 'download']);
$res = Database::simpleQuery("SELECT m.menuid, m.title, m.isdefault, GROUP_CONCAT(l.locationid) AS locations
FROM serversetup_menu m LEFT JOIN serversetup_menu_location l USING (menuid) GROUP BY menuid ORDER BY title");
- $table = [];
+ $menuTable = [];
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
if (empty($row['locations'])) {
$locations = [];
$row['allowEdit'] = in_array(0, $allowedEdit);
+ $row['allowDelete'] = in_array(0, $allowedDelete);
} else {
$locations = explode(',', $row['locations']);
$row['allowEdit'] = empty(array_diff($locations, $allowedEdit));
+ $row['allowDelete'] = empty(array_diff($locations, $allowedDelete));
}
$row['locationCount'] = empty($locations) ? '' : count($locations);
- $table[] = $row;
+ $menuTable[] = $row;
+ }
+
+ $allowAddMenu = 'disabled';
+ if (User::hasPermission('ipxe.menu.add')) {
+ $allowAddMenu = '';
}
Render::addTemplate('menu-list', array(
- 'table' => $table,
+ 'menuTable' => $menuTable,
+ 'allowAddMenu' => $allowAddMenu
));
}
@@ -173,8 +187,19 @@ class Page_ServerSetup extends Page
private function showEditMenu()
{
$id = Request::get('id', false, 'int');
- $menu = Database::queryFirst("SELECT menuid, timeoutms, title, defaultentryid, isdefault
+ // if = edit, else = add new
+ if ($id != 0) {
+ $menu = Database::queryFirst("SELECT menuid, timeoutms, title, defaultentryid, isdefault
FROM serversetup_menu WHERE menuid = :id", compact('id'));
+ } else {
+ $menu = [];
+ $menu['menuid'] = 0;
+ $menu['timeoutms'] = 0;
+ $menu['title'] = '';
+ $menu['defaultentryid'] = null;
+ $menu['isdefault'] = false;
+ }
+
if ($menu === false) {
Message::addError('invalid-menu-id', $id);
Util::redirect('?do=serversetup&show=menu');
@@ -263,6 +288,22 @@ class Page_ServerSetup extends Page
return true;
}
+ private function deleteMenu()
+ {
+ $id = Request::post('deleteid', false, 'int');
+ if ($id === false) {
+ Message::addError('main.parameter-missing', 'menuid');
+ return;
+ }
+ if (!$this->hasMenuPermission($id, 'ipxe.menu.delete')) {
+ Message::addError('locations.no-permission-location', 'TODO');
+ return;
+ }
+ Database::exec("DELETE FROM serversetup_menu WHERE menuid = :menuid", array("menuid" => $id));
+ Message::addSuccess('menu-deleted');
+
+ }
+
private function saveMenu()
{
$id = Request::post('menuid', false, 'int');
@@ -284,15 +325,27 @@ class Page_ServerSetup extends Page
}
// TODO: Validate new locations to be saved (and actually save them)
- Database::exec('UPDATE serversetup_menu SET title = :title, timeoutms = :timeoutms, defaultentryid = :defaultentryid
+ if ($id == 0) {
+ Database::exec("INSERT IGNORE INTO serversetup_menu (title, timeoutms, defaultentryid) VALUES (:title, :timeoutms, :defaultentryid)", [
+ 'title' => IPxe::sanitizeIpxeString(Request::post('title', '', 'string')),
+ 'timeoutms' => abs(Request::post('timeout', 0, 'int') * 1000),
+ 'defaultentryid' => Request::post('defaultentry', null, 'int')
+ ]);
+ } else {
+ Database::exec('UPDATE serversetup_menu SET title = :title, timeoutms = :timeoutms, defaultentryid = :defaultentryid
WHERE menuid = :menuid', [
- 'menuid' => $id,
- 'title' => IPxe::sanitizeIpxeString(Request::post('title', '', 'string')),
- 'timeoutms' => abs(Request::post('timeoutms', 0, 'int') * 1000),
- 'defaultentryid' => Request::post('defaultentry', null, 'int'),
- ]);
+ 'menuid' => $id,
+ 'title' => IPxe::sanitizeIpxeString(Request::post('title', '', 'string')),
+ 'timeoutms' => abs(Request::post('timeout', 0, 'int') * 1000),
+ 'defaultentryid' => Request::post('defaultentry', null, 'int'),
+ ]);
+ }
+
+ $defmenu = Request::post('defmenu', false, 'boolean');
if (User::hasPermission('ipxe.menu.edit', 0)) {
- Database::exec('UPDATE serversetup_menu SET isdefault = (menuid = :menuid)', ['menuid' => $id]);
+ if ($defmenu) {
+ Database::exec('UPDATE serversetup_menu SET isdefault = (menuid = :menuid)', ['menuid' => $id]);
+ }
}
$keepIds = [];
diff --git a/modules-available/serversetup-bwlp/permissions/permissions.json b/modules-available/serversetup-bwlp/permissions/permissions.json
index aa2aa001..e05b9f6c 100644
--- a/modules-available/serversetup-bwlp/permissions/permissions.json
+++ b/modules-available/serversetup-bwlp/permissions/permissions.json
@@ -20,6 +20,12 @@
"ipxe.menu.edit": {
"location-aware": true
},
+ "ipxe.menu.add": {
+ "location-aware": false
+ },
+ "ipxe.menu.delete": {
+ "location-aware": true
+ },
"ipxe.localboot.edit": {
"location-aware": false
}
diff --git a/modules-available/serversetup-bwlp/templates/menu-list.html b/modules-available/serversetup-bwlp/templates/menu-list.html
index a862cff2..1f190bb7 100644
--- a/modules-available/serversetup-bwlp/templates/menu-list.html
+++ b/modules-available/serversetup-bwlp/templates/menu-list.html
@@ -7,10 +7,11 @@
<th class="slx-smallcol">{{lang_locationCount}}</th>
<th class="slx-smallcol">{{lang_isDefault}}</th>
<th class="slx-smallcol">{{lang_edit}}</th>
+ <th class="slx-smallcol">{{lang_delete}}</th>
</tr>
</thead>
<tbody>
- {{#table}}
+ {{#menuTable}}
<tr>
<td>
{{title}}
@@ -18,19 +19,62 @@
<td class="text-right">
{{locationCount}}
</td>
- <td>
+ <td align="center">
{{#isdefault}}
<span class="glyphicon glyphicon-ok"></span>
{{/isdefault}}
</td>
- <td>
+ <td align="center">
{{#allowEdit}}
<a href="?do=serversetup&amp;show=editmenu&amp;id={{menuid}}" class="btn btn-xs btn-default">
<span class="glyphicon glyphicon-edit"></span>
</a>
{{/allowEdit}}
</td>
+ <td align="center">
+ {{#allowDelete}}
+ <button type="button" class="btn btn-xs btn-danger" data-toggle="modal" data-target="#deleteModal" onclick="deleteMenu('{{menuid}}')">
+ <span class="glyphicon glyphicon-trash"></span>
+ </button>
+ {{/allowDelete}}
+ </td>
</tr>
- {{/table}}
+ {{/menuTable}}
</tbody>
-</table> \ No newline at end of file
+</table>
+<div class="pull-right">
+ <a href="?do=serversetup&amp;show=editmenu&amp;id=0" class="btn btn-success {{allowAddMenu}}">
+ <span class="glyphicon glyphicon-plus"></span>
+ {{lang_addMenu}}
+ </a>
+</div>
+
+
+<!-- Modals -->
+<form method="post" action="?do=serversetup">
+ <input type="hidden" name="token" value="{{token}}">
+ <div class ="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
+ <div class="modal-dialog" role="document">
+ <div class="modal-content">
+ <div class="modal-header">
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
+ <h4 class="modal-title" id="myModalLabel">{{lang_delete}}</h4>
+ </div>
+ <div class="modal-body">
+ <p>{{lang_menuDeleteConfirm}}</p>
+ </div>
+ <div class="modal-footer">
+ <input type="hidden" id="delete-menu-id" name="deleteid" value="">
+ <button type="button" class="btn btn-default" data-dismiss="modal">{{lang_cancel}}</button>
+ <button type="submit" name="action" value="deleteMenu" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span> {{lang_delete}}</button>
+ </div>
+ </div>
+ </div>
+ </div>
+</form>
+
+<script>
+ function deleteMenu(menuid) {
+ $("#delete-menu-id").val(menuid);
+ }
+</script> \ No newline at end of file