From f97f0c46019b192928282cdcaf2bd3a5c2e36add Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 21 Dec 2017 00:02:38 +0100 Subject: [serversetup] Start work on a pxemenu parser for later migration --- .../serversetup-bwlp/inc/ipxe.inc.php | 102 +++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 modules-available/serversetup-bwlp/inc/ipxe.inc.php (limited to 'modules-available') 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 @@ + ['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; } +} + -- cgit v1.2.3-55-g7522