summaryrefslogtreecommitdiffstats
path: root/modules-available/serversetup-bwlp
diff options
context:
space:
mode:
authorSimon Rettberg2017-12-21 00:02:38 +0100
committerSimon Rettberg2017-12-21 00:02:38 +0100
commitf97f0c46019b192928282cdcaf2bd3a5c2e36add (patch)
tree81481e72fa25370b1180eebbbc919902a48e99d0 /modules-available/serversetup-bwlp
parent[sysconfig] Error checks + messages when rebuilding module (diff)
downloadslx-admin-f97f0c46019b192928282cdcaf2bd3a5c2e36add.tar.gz
slx-admin-f97f0c46019b192928282cdcaf2bd3a5c2e36add.tar.xz
slx-admin-f97f0c46019b192928282cdcaf2bd3a5c2e36add.zip
[serversetup] Start work on a pxemenu parser for later migration
Diffstat (limited to 'modules-available/serversetup-bwlp')
-rw-r--r--modules-available/serversetup-bwlp/inc/ipxe.inc.php102
1 files changed, 102 insertions, 0 deletions
diff --git a/modules-available/serversetup-bwlp/inc/ipxe.inc.php b/modules-available/serversetup-bwlp/inc/ipxe.inc.php
new file mode 100644
index 00000000..abeea748
--- /dev/null
+++ b/modules-available/serversetup-bwlp/inc/ipxe.inc.php
@@ -0,0 +1,102 @@
+<?php
+
+
+class Ipxe
+{
+
+ public static function parsePxeLinux($input)
+ {
+ /*
+ LABEL openslx-debug
+ MENU LABEL ^bwLehrpool-Umgebung starten (nosplash, debug)
+ KERNEL http://IPADDR/boot/default/kernel
+ INITRD http://IPADDR/boot/default/initramfs-stage31
+ APPEND slxbase=boot/default
+ IPAPPEND 3
+ */
+ $propMap = [
+ 'menu label' => ['string', 'title'],
+ 'menu default' => ['true', 'isDefault'],
+ 'menu hide' => ['true', 'isHidden'],
+ 'kernel' => ['string', 'kernel'],
+ 'initrd' => ['string', 'initrd'],
+ 'append' => ['string', 'append'],
+ 'ipappend' => ['int', 'ipAppend'],
+ 'localboot' => ['int', 'localBoot'],
+ ];
+ $sections = array();
+ $lines = preg_split('/[\r\n]+/', $input);
+ $section = null;
+ foreach ($lines as $line) {
+ if (!preg_match('/^\s*([^m\s]+|menu\s+\S+)\s+(.*?)\s*$/i', $line, $out))
+ continue;
+ $key = strtolower($out[1]);
+ $key = preg_replace('/\s+/', ' ', $key);
+ if ($key === 'label') {
+ if ($section !== null) {
+ $sections[] = $section;
+ }
+ $section = new PxeSection($out[2]);
+ } elseif ($section === null) {
+ continue;
+ } elseif (isset($propMap[$key])) {
+ $opt = $propMap[$key];
+ if ($opt[0] === 'true') {
+ $val = true;
+ } else {
+ $val = $out[2];
+ settype($val, $opt[0]);
+ }
+ $section->{$opt[1]} = $val;
+ }
+ }
+ if ($section !== null) {
+ $sections[] = $section;
+ }
+ return $sections;
+ }
+
+}
+
+class PxeMenu
+{
+ public $title;
+ public $timeoutMs;
+ public $totalTimeoutMs;
+ public $timeoutLabel;
+}
+
+class PxeSection
+{
+ /**
+ * @var string label used internally in PXEMENU definition to address this entry
+ */
+ public $label;
+ /**
+ * @var string MENU LABEL of PXEMENU - title of entry displayed to the user
+ */
+ public $title;
+ public $kernel;
+ public $initrd;
+ public $append;
+ /**
+ * @var int IPAPPEND from PXEMENU. Bitmask of valid options 1 and 2.
+ */
+ public $ipAppend;
+ public $passwd;
+ /**
+ * @var bool whether this section is marked as default (booted after timeout)
+ */
+ public $isDefault = false;
+ /**
+ * @var bool Menu entry is not visible (can only be triggered by timeout)
+ */
+ public $isHidden = false;
+ /**
+ * @var int Value of the LOCALBOOT field
+ */
+ public $localBoot;
+
+ public function __construct($label) { $this->label = $label; }
+}
+