summaryrefslogtreecommitdiffstats
path: root/modules-available/serversetup-bwlp-ipxe
diff options
context:
space:
mode:
authorSimon Rettberg2019-10-16 18:12:17 +0200
committerSimon Rettberg2019-10-16 18:12:17 +0200
commit36e47dcdfb7d19d4c8982a77b4dd3b87d8c4ca31 (patch)
tree1326851106dd111dc1bcd32d0622dda094f1dcae /modules-available/serversetup-bwlp-ipxe
parent[dozmod] Increase sat DB's launch counter on cache hit (diff)
downloadslx-admin-36e47dcdfb7d19d4c8982a77b4dd3b87d8c4ca31.tar.gz
slx-admin-36e47dcdfb7d19d4c8982a77b4dd3b87d8c4ca31.tar.xz
slx-admin-36e47dcdfb7d19d4c8982a77b4dd3b87d8c4ca31.zip
[serversetup-bwlp-ipxe/minilinux] Implement minilinux hook for ipxe
Diffstat (limited to 'modules-available/serversetup-bwlp-ipxe')
-rw-r--r--modules-available/serversetup-bwlp-ipxe/inc/bootentry.inc.php1
-rw-r--r--modules-available/serversetup-bwlp-ipxe/inc/bootentryhook.inc.php134
-rw-r--r--modules-available/serversetup-bwlp-ipxe/inc/execdata.inc.php2
-rw-r--r--modules-available/serversetup-bwlp-ipxe/lang/de/template-tags.json2
-rw-r--r--modules-available/serversetup-bwlp-ipxe/page.inc.php43
-rw-r--r--modules-available/serversetup-bwlp-ipxe/templates/ipxe-new-boot-entry.html14
6 files changed, 170 insertions, 26 deletions
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/bootentry.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/bootentry.inc.php
index e97d1389..174f4459 100644
--- a/modules-available/serversetup-bwlp-ipxe/inc/bootentry.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/inc/bootentry.inc.php
@@ -260,6 +260,7 @@ class StandardBootEntry extends BootEntry
} else {
$entry = $this->efi;
}
+ $entry->sanitize();
$script = '';
if ($entry->resetConsole) {
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/bootentryhook.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/bootentryhook.inc.php
index 2e2e5009..f89031a3 100644
--- a/modules-available/serversetup-bwlp-ipxe/inc/bootentryhook.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/inc/bootentryhook.inc.php
@@ -14,18 +14,24 @@ abstract class BootEntryHook
private $selectedId;
+ private $data = [];
+
+ /**
+ * @return string
+ */
public abstract function name();
/**
- * @return HookEntryGroup[]
+ * @return HookExtraField[]
*/
- protected abstract function groupsInternal();
+ public abstract function extraFields();
+
+ public abstract function isValidId($id);
/**
- * @param $id
- * @return BootEntry|null the actual boot entry instance for given entry, null if invalid id
+ * @return HookEntryGroup[]
*/
- public abstract function getBootEntry($id);
+ protected abstract function groupsInternal();
/**
* @return HookEntryGroup[]
@@ -43,11 +49,40 @@ abstract class BootEntryHook
return $groups;
}
+ /**
+ * @param $id
+ * @return BootEntry|null the actual boot entry instance for given entry, null if invalid id
+ */
+ public abstract function getBootEntryInternal($data);
+
+ public final function getBootEntry($data)
+ {
+ if (!is_array($data)) {
+ $data = json_decode($data, true);
+ }
+ return $this->getBootEntryInternal($data);
+ }
+
public function setSelected($id)
{
+ $json = @json_decode($id, true);
+ if (is_array($json)) {
+ $id = $json['id'];
+ $this->data = $json;
+ }
$this->selectedId = $id;
}
+ public function renderExtraFields()
+ {
+ $list = $this->extraFields();
+ foreach ($list as &$entry) {
+ $entry->currentValue = isset($this->data[$entry->name]) ? $this->data[$entry->name] : $entry->default;
+ $entry->hook = $this;
+ }
+ return $list;
+ }
+
}
class HookEntryGroup
@@ -79,13 +114,100 @@ class HookEntry
*/
public $name;
/**
+ * @var bool
+ */
+ public $valid;
+ /**
+ * @var string if !valid, this will be the string 'disabled', empty otherwise
+ */
+ public $disabled;
+ /**
* @var string internal - to be set by ipxe module
*/
public $selected;
- public function __construct($id, $name)
+ /**
+ * HookEntry constructor.
+ *
+ * @param string $id
+ * @param string $name
+ * @param bool $valid
+ */
+ public function __construct($id, $name, $valid)
{
$this->id = $id;
$this->name = $name;
+ $this->valid = $valid;
+ $this->disabled = $valid ? '' : 'disabled';
}
+}
+
+class HookExtraField
+{
+ /**
+ * @var string ID of extra field, [a-z0-9\-] please. Must not be 'id'
+ */
+ public $name;
+ /**
+ * @var string type of field, use string, bool, or an array of predefined options
+ */
+ public $type;
+ /**
+ * @var mixed default value
+ */
+ public $default;
+
+ public $currentValue;
+
+ /**
+ * @var BootEntryHook
+ */
+ public $hook;
+
+ public function __construct($name, $type, $default)
+ {
+ $this->name = $name;
+ $this->type = $type;
+ $this->default = $default;
+ }
+
+ public function fromPost($typePrefix)
+ {
+ if (is_array($this->type)) {
+ $val = Request::post('extra-' . $typePrefix . '-' . $this->name, '', 'array');
+ if (!in_array($val, $this->type)) {
+ $val = $this->default;
+ }
+ } else {
+ $val = Request::post('extra-' . $typePrefix . '-' . $this->name, '', $this->type);
+ settype($val, $this->type);
+ }
+ return $val;
+ }
+
+ public function html()
+ {
+ $fieldId = 'extra-' . $this->hook->moduleId . '-' . $this->name;
+ $fieldText = htmlspecialchars(Dictionary::translateFileModule($this->hook->moduleId, 'module', 'ipxe-' . $this->name, true));
+ if (is_array($this->type)) {
+ $out = '<label for="' . $fieldId . '">' . $fieldText . '</label><select class="form-control" name="' . $fieldId . '" id="' . $fieldId . '">';
+ foreach ($this->type as $entry) {
+ $selected = ($entry === $this->currentValue) ? 'selected' : '';
+ $out .= '<option ' . $selected . '>' . htmlspecialchars($entry) . '</option>';
+ }
+ $out .= '</select>';
+ return $out;
+ }
+ if ($this->type === 'bool') {
+ $checked = $this->currentValue ? 'checked' : '';
+ return '<div class="checkbox"><input type="checkbox" id="' . $fieldId
+ . '" name="' . $fieldId . '" ' . $checked . '><label for="' . $fieldId . '">'
+ . $fieldText . '</label></div>';
+ }
+ // Default
+ return '<label for="' . $fieldId . '">' . $fieldText . '</label>'
+ . '<input class="form-control" type="text" id="' . $fieldId
+ . '" name="' . $fieldId . '" value="' . htmlspecialchars($this->currentValue) . '">';
+ }
+
} \ No newline at end of file
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/execdata.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/execdata.inc.php
index b82ce2e7..97f98b94 100644
--- a/modules-available/serversetup-bwlp-ipxe/inc/execdata.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/inc/execdata.inc.php
@@ -73,7 +73,7 @@ class ExecData
],
];
- private function sanitize()
+ public function sanitize()
{
settype($this->executable, 'string');
settype($this->initRd, 'array');
diff --git a/modules-available/serversetup-bwlp-ipxe/lang/de/template-tags.json b/modules-available/serversetup-bwlp-ipxe/lang/de/template-tags.json
index 07cf8fa3..f7a62091 100644
--- a/modules-available/serversetup-bwlp-ipxe/lang/de/template-tags.json
+++ b/modules-available/serversetup-bwlp-ipxe/lang/de/template-tags.json
@@ -11,6 +11,7 @@
"lang_biosOnly": "Nur BIOS",
"lang_bootAddress": "Boot-Adresse des Servers",
"lang_bootEntryData": "Daten des Men\u00fceintrags",
+ "lang_bootEntryDetailsHeading": "Typspezifische Konfiguration",
"lang_bootentryDeleteConfirm": "Sind Sie sicher, dass Sie diesen Men\u00fceintrag l\u00f6schen wollen?",
"lang_bootentryHead": "Men\u00fceintr\u00e4ge",
"lang_bootentryIntro": "Hier k\u00f6nnen Sie Men\u00fceintr\u00e4ge definieren, die sich sp\u00e4ter einem Men\u00fc zuweisen lassen. Ein Men\u00fceintrag besteht entweder aus einem zu ladenden Kernel\/Image plus optional initrd, oder aus einem iPXE-Skript.",
@@ -38,6 +39,7 @@
"lang_forceRecompile": "Jetzt neu kompilieren",
"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_hex": "Hex",
+ "lang_hookExtraOptionHeading": "Weitere Angaben",
"lang_hotkey": "Hotkey",
"lang_idFormatHint": "(Max. 16 Zeichen, nur a-z 0-9 - _)",
"lang_imageToLoad": "Zu ladendes Image (z.B. Kernel)",
diff --git a/modules-available/serversetup-bwlp-ipxe/page.inc.php b/modules-available/serversetup-bwlp-ipxe/page.inc.php
index 40b75dd2..f14c1e57 100644
--- a/modules-available/serversetup-bwlp-ipxe/page.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/page.inc.php
@@ -519,25 +519,25 @@ class Page_ServerSetup extends Page
$params['oldentryid'] = $params['entryid'] = $row['entryid'];
$params['builtin'] = $row['builtin'];
}
- if (!is_array($params['entries'])) {
- $params['entries'] = [];
- }
- $f = [];
- foreach ($params['entries'] as $e) {
- if (isset($e['mode'])) {
- $f[] = $e['mode'];
- }
- }
- if (!in_array('PCBIOS', $f)) {
- $params['entries'][] = ['mode' => 'PCBIOS'];
- }
- if (!in_array('EFI', $f)) {
- $params['entries'][] = ['mode' => 'EFI'];
- }
$params['menus'] = Database::queryAll('SELECT m.menuid, m.title FROM serversetup_menu m
INNER JOIN serversetup_menuentry me ON (me.menuid = m.menuid)
WHERE me.entryid = :entryid', ['entryid' => $row['entryid']]);
}
+ if (!isset($params['entries']) || !is_array($params['entries'])) {
+ $params['entries'] = [];
+ }
+ $f = [];
+ foreach ($params['entries'] as $e) {
+ if (isset($e['mode'])) {
+ $f[] = $e['mode'];
+ }
+ }
+ if (!in_array('PCBIOS', $f)) {
+ $params['entries'][] = ['mode' => 'PCBIOS'];
+ }
+ if (!in_array('EFI', $f)) {
+ $params['entries'][] = ['mode' => 'EFI'];
+ }
$params['disabled'] = User::hasPermission('ipxe.bootentry.edit') ? '' : 'disabled';
Render::addTemplate('ipxe-new-boot-entry', $params);
@@ -823,12 +823,19 @@ class Page_ServerSetup extends Page
}
/** @var BootEntryHook $module */
$module = $hook->run();
- $entryData = Request::post('selection-' . $type, false, 'string');
- $entry = $module->getBootEntry($entryData);
+ $id = Request::post('selection-' . $type, false, 'string');
+ $entry = $module->isValidId($id);
if ($entry === null) {
- Message::addError('invalid-custom-entry-id', $type, $entryData);
+ Message::addError('invalid-custom-entry-id', $type, $id);
return;
}
+ $entryData = ['id' => $id];
+ foreach ($module->extraFields() as $field) {
+ if ($field->name === 'id')
+ continue;
+ $entryData[$field->name] = $field->fromPost($type);
+ }
+ $entryData = json_encode($entryData);
}
$params = [
'entryid' => $newId,
diff --git a/modules-available/serversetup-bwlp-ipxe/templates/ipxe-new-boot-entry.html b/modules-available/serversetup-bwlp-ipxe/templates/ipxe-new-boot-entry.html
index fd76c1d5..5b7e3134 100644
--- a/modules-available/serversetup-bwlp-ipxe/templates/ipxe-new-boot-entry.html
+++ b/modules-available/serversetup-bwlp-ipxe/templates/ipxe-new-boot-entry.html
@@ -52,6 +52,8 @@
<input id="input-title" class="form-control" name="title" value="{{title}}" maxlength="100" {{disabled}}>
</div>
+ <h4>{{lang_bootEntryDetailsHeading}}</h4>
+
<div class="type-form" id="form-exec">
<div class="form-group">
<label for="arch-selector">
@@ -170,12 +172,20 @@
{{#groups}}
<optgroup label="{{groupName}}">
{{#entries}}
- <option value="{{id}}" {{selected}}>{{name}}</option>
+ <option value="{{id}}" {{selected}} {{disabled}}>{{name}}</option>
{{/entries}}
</optgroup>
{{/groups}}
</select>
</div>
+ <div class="form-group">
+ {{#renderExtraFields.0}}
+ <h4>{{lang_hookExtraOptionHeading}}</h4>
+ {{/renderExtraFields.0}}
+ {{#renderExtraFields}}
+ {{{html}}}
+ {{/renderExtraFields}}
+ </div>
</div>
{{/hooks}}
@@ -185,6 +195,8 @@
</div>
{{/builtin}}
+ <hr>
+
<p class="slx-bold">{{lang_referencingMenus}}:</p>
<ul>
{{#menus}}