summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2019-12-10 15:10:31 +0100
committerSimon Rettberg2019-12-10 15:10:31 +0100
commite7cc4e9d0e9a40274c8e337d0330e19dc450d929 (patch)
tree9b4e1721a3f383811d06ce7b1a26466d93548dd9
parent[minilinux] Remove debug output (diff)
downloadslx-admin-e7cc4e9d0e9a40274c8e337d0330e19dc450d929.tar.gz
slx-admin-e7cc4e9d0e9a40274c8e337d0330e19dc450d929.tar.xz
slx-admin-e7cc4e9d0e9a40274c8e337d0330e19dc450d929.zip
[serversetup-bwlp-ipxe/minilinux] Add comments, fix minor logic bug
Saving a boot entry didn't properly check the validity of a hook's ID, which was broken anyways, so the invalid check didn't uncover that the actual cheking code didn't work either.
-rw-r--r--modules-available/minilinux/inc/linuxbootentryhook.inc.php2
-rw-r--r--modules-available/serversetup-bwlp-ipxe/inc/bootentryhook.inc.php22
-rw-r--r--modules-available/serversetup-bwlp-ipxe/page.inc.php5
3 files changed, 24 insertions, 5 deletions
diff --git a/modules-available/minilinux/inc/linuxbootentryhook.inc.php b/modules-available/minilinux/inc/linuxbootentryhook.inc.php
index 41d70b17..324ffc7e 100644
--- a/modules-available/minilinux/inc/linuxbootentryhook.inc.php
+++ b/modules-available/minilinux/inc/linuxbootentryhook.inc.php
@@ -154,6 +154,8 @@ class LinuxBootEntryHook extends BootEntryHook
public function isValidId($id)
{
+ if ($id === 'default')
+ return true; // Meta-version that links to whatever the default is set to
$res = Database::queryFirst('SELECT installed FROM minilinux_version WHERE versionid = :id', ['id' => $id]);
return $res !== false && $res['installed'];
}
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/bootentryhook.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/bootentryhook.inc.php
index cf180006..73611b0a 100644
--- a/modules-available/serversetup-bwlp-ipxe/inc/bootentryhook.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/inc/bootentryhook.inc.php
@@ -26,6 +26,10 @@ abstract class BootEntryHook
*/
public abstract function extraFields();
+ /**
+ * @param string $id
+ * @return bool
+ */
public abstract function isValidId($id);
/**
@@ -63,16 +67,30 @@ abstract class BootEntryHook
return $this->getBootEntryInternal($data);
}
- public function setSelected($id)
+ /**
+ * @param string $mixed either the plain ID if the entry to be marked as selected, or the JSON string representing
+ * the entire entry, which must have a key called 'id' that will be used as the ID then.
+ */
+ public function setSelected($mixed)
{
- $json = @json_decode($id, true);
+ $json = @json_decode($mixed, true);
if (is_array($json)) {
$id = $json['id'];
$this->data = $json;
+ } else {
+ $id = $mixed;
}
$this->selectedId = $id;
}
+ /**
+ * @return string ID of entry that was marked as selected by setSelected()
+ */
+ public function getSelected()
+ {
+ return $this->selectedId;
+ }
+
public function renderExtraFields()
{
$list = $this->extraFields();
diff --git a/modules-available/serversetup-bwlp-ipxe/page.inc.php b/modules-available/serversetup-bwlp-ipxe/page.inc.php
index cc5fdbe5..a636665e 100644
--- a/modules-available/serversetup-bwlp-ipxe/page.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/page.inc.php
@@ -527,7 +527,7 @@ class Page_ServerSetup extends Page
if ($he->moduleId === $row['module']) {
$he->setSelected($row['data']);
$he->checked = 'checked';
- if ($he->getBootEntry($row['data']) === null) {
+ if (!$he->isValidId($he->getSelected())) {
Message::addError('invalid-custom-entry-id', $row['module'], $row['data']);
}
break;
@@ -848,8 +848,7 @@ class Page_ServerSetup extends Page
/** @var BootEntryHook $module */
$module = $hook->run();
$id = Request::post('selection-' . $type, false, 'string');
- $entry = $module->isValidId($id);
- if ($entry === null) {
+ if (!$module->isValidId($id)) {
Message::addError('invalid-custom-entry-id', $type, $id);
return;
}