diff options
author | Simon Rettberg | 2020-06-10 17:12:02 +0200 |
---|---|---|
committer | Simon Rettberg | 2020-06-10 17:12:02 +0200 |
commit | 3fb99a5e8c229885602198bea4dce26bcf0fcc4f (patch) | |
tree | 775501f868c5afe913ef6485dabb89feefea7fb0 /modules-available/serversetup-bwlp-ipxe/inc/menuentry.inc.php | |
parent | [statistics] Fix querying location 0 (no location) (diff) | |
download | slx-admin-3fb99a5e8c229885602198bea4dce26bcf0fcc4f.tar.gz slx-admin-3fb99a5e8c229885602198bea4dce26bcf0fcc4f.tar.xz slx-admin-3fb99a5e8c229885602198bea4dce26bcf0fcc4f.zip |
[serversetup-bwlp-ipxe] Start refactoring ipxe script generator
This is WIP. Mostly restored all the old functionality.
Boot entries are fetched when selected, not embedded in the main script,
so password protection is a bit stronger.
Hopefully allows for other script generators in the future.
Diffstat (limited to 'modules-available/serversetup-bwlp-ipxe/inc/menuentry.inc.php')
-rw-r--r-- | modules-available/serversetup-bwlp-ipxe/inc/menuentry.inc.php | 82 |
1 files changed, 31 insertions, 51 deletions
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/menuentry.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/menuentry.inc.php index a65e9f98..1e567448 100644 --- a/modules-available/serversetup-bwlp-ipxe/inc/menuentry.inc.php +++ b/modules-available/serversetup-bwlp-ipxe/inc/menuentry.inc.php @@ -5,33 +5,51 @@ class MenuEntry /** * @var int id of entry, used for pw */ - private $menuentryid; + public $menuentryid; /** * @var false|string key code as expected by iPXE */ - private $hotkey; + public $hotkey; /** * @var string */ - private $title; + public $title; /** * @var bool */ - private $hidden; + public $hidden; /** * @var bool */ - private $gap; + public $gap; /** * @var int */ - private $sortval; + public $sortval; /** * @var BootEntry */ - private $bootEntry = null; + public $bootEntry = null; - private $md5pass = null; + public $plainpass = null; + + public $md5pass = null; + + /** + * @param int $menuEntryId + * @return MenuEntry|null + */ + public static function get($menuEntryId) + { + $row = Database::queryFirst("SELECT e.menuentryid, e.entryid, e.refmenuid, e.hotkey, e.title, e.hidden, e.sortval, e.plainpass, e.md5pass, + b.module, b.data AS bootentry + FROM serversetup_menuentry e + LEFT JOIN serversetup_bootentry b USING (entryid) + WHERE e.menuentryid = :id", ['id' => $menuEntryId]); + if ($row === false) + return null; + return new MenuEntry($row); + } /** * MenuEntry constructor. @@ -46,10 +64,10 @@ class MenuEntry $this->{$key} = $value; } } - $this->hotkey = self::getKeyCode($row['hotkey']); + $this->hotkey = self::getKeyCode($row['hotkey'] ?? ''); if (!empty($row['bootentry'])) { $this->bootEntry = BootEntry::fromJson($row['module'], $row['bootentry']); - } elseif ($row['refmenuid'] !== null) { + } elseif (isset($row['refmenuid'])) { $this->bootEntry = BootEntry::forMenu($row['refmenuid']); } $this->gap = (array_key_exists('entryid', $row) && $row['entryid'] === null && $row['refmenuid'] === null); @@ -60,49 +78,11 @@ class MenuEntry settype($this->menuentryid, 'int'); } - public function getMenuItemScript($lblPrefix, $requestedDefaultId, $mode, $slxExtensions) - { - if ($this->bootEntry !== null && !$this->bootEntry->supportsMode($mode)) - return ''; - $str = 'item '; - if ($this->gap) { - $str .= '--gap -- '; - } else { - if ($this->hidden && $slxExtensions) { - if ($this->hotkey === false) - return ''; // Hidden entries without hotkey are illegal - $str .= '--hidden '; - } - if ($this->hotkey !== false) { - $str .= '--key ' . $this->hotkey . ' '; - } - if ($this->menuentryid == $requestedDefaultId) { - $str .= '--default '; - } - $str .= "-- {$lblPrefix}_{$this->menuentryid} "; - } - if (empty($this->title)) { - $str .= '${}'; - } else { - $str .= $this->title; - } - return $str . " || prompt Could not create menu item for {$lblPrefix}_{$this->menuentryid}\n"; - } - - public function getBootEntryScript($lblPrefix, $failLabel, $mode) + public function getBootEntryScript($builder) { - if ($this->bootEntry === null || !$this->bootEntry->supportsMode($mode)) + if ($this->bootEntry === null) return ''; - $str = ":{$lblPrefix}_{$this->menuentryid}\n"; - if (!empty($this->md5pass)) { - $str .= "set slx_hash {$this->md5pass} || goto $failLabel\n" - . "set slx_salt {$this->menuentryid} || goto $failLabel\n" - . "set slx_pw_ok {$lblPrefix}_ok || goto $failLabel\n" - . "set slx_pw_fail slx_menu || goto $failLabel\n" - . "goto slx_pass_check || goto $failLabel\n" - . ":{$lblPrefix}_ok\n"; - } - return $str . $this->bootEntry->toScript($failLabel, $mode); + return $this->bootEntry->toScript($builder); } public function menuEntryId() |