summaryrefslogtreecommitdiffstats
path: root/modules-available/serversetup-bwlp-ipxe/inc/menuentry.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/serversetup-bwlp-ipxe/inc/menuentry.inc.php')
-rw-r--r--modules-available/serversetup-bwlp-ipxe/inc/menuentry.inc.php119
1 files changed, 51 insertions, 68 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..da94a16b 100644
--- a/modules-available/serversetup-bwlp-ipxe/inc/menuentry.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/inc/menuentry.inc.php
@@ -5,114 +5,98 @@ 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
+ * @var ?BootEntry
*/
- private $bootEntry = null;
+ public $bootEntry = null;
- private $md5pass = null;
+ public $plainpass = null;
+
+ public $md5pass = null;
+
+ public static function get(int $menuEntryId): ?MenuEntry
+ {
+ $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, b.title AS betitle
+ 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.
*
* @param array $row row from database
*/
- public function __construct($row)
+ public function __construct(array $row)
{
- if (is_array($row)) {
- foreach ($row as $key => $value) {
- if (property_exists($this, $key)) {
- $this->{$key} = $value;
- }
- }
- $this->hotkey = self::getKeyCode($row['hotkey']);
- if (!empty($row['bootentry'])) {
- $this->bootEntry = BootEntry::fromJson($row['module'], $row['bootentry']);
- } elseif ($row['refmenuid'] !== null) {
- $this->bootEntry = BootEntry::forMenu($row['refmenuid']);
+ if (empty($row['title']) && !empty($row['betitle'])) {
+ $row['title'] = $row['betitle'];
+ }
+ foreach ($row as $key => $value) {
+ if (property_exists($this, $key)) {
+ $this->{$key} = $value;
}
- $this->gap = (array_key_exists('entryid', $row) && $row['entryid'] === null && $row['refmenuid'] === null);
}
+ $this->hotkey = self::getKeyCode($row['hotkey'] ?? '');
+ if (!empty($row['bootentry'])) {
+ $this->bootEntry = BootEntry::fromJson($row['module'], $row['bootentry']);
+ } elseif (isset($row['refmenuid'])) {
+ $this->bootEntry = BootEntry::forMenu($row['refmenuid']);
+ }
+ $this->gap = (array_key_exists('entryid', $row) && $row['entryid'] === null && $row['refmenuid'] === null);
settype($this->hidden, 'bool');
settype($this->gap, 'bool');
settype($this->sortval, 'int');
settype($this->menuentryid, 'int');
}
- public function getMenuItemScript($lblPrefix, $requestedDefaultId, $mode, $slxExtensions)
+ public function getBootEntryScript(ScriptBuilderBase $builder): string
{
- if ($this->bootEntry !== null && !$this->bootEntry->supportsMode($mode))
+ if ($this->bootEntry === null)
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";
+ return $this->bootEntry->toScript($builder);
}
- public function getBootEntryScript($lblPrefix, $failLabel, $mode)
+ public function menuEntryId(): int
{
- if ($this->bootEntry === null || !$this->bootEntry->supportsMode($mode))
- 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->menuentryid;
}
- public function menuEntryId()
+ public function title(): string
{
- return $this->menuentryid;
+ return $this->title;
}
- public function title()
+ public function internalId(): string
{
- return $this->title;
+ if ($this->bootEntry === null)
+ return '';
+ return $this->bootEntry->internalId();
}
/*
@@ -154,7 +138,7 @@ class MenuEntry
*
* @return string[] list of known key names
*/
- public static function getKeyList()
+ public static function getKeyList(): array
{
return array_keys(self::getKeyArray());
}
@@ -163,10 +147,9 @@ class MenuEntry
* Get the key code ipxe expects for the given named
* key. Returns false if the key name is unknown.
*
- * @param string $keyName
* @return false|string Key code as hex string, or false if not found
*/
- public static function getKeyCode($keyName)
+ public static function getKeyCode(string $keyName)
{
$data = self::getKeyArray();
if (isset($data[$keyName]))
@@ -178,7 +161,7 @@ class MenuEntry
* @param string $keyName desired key name
* @return string $keyName if it's known, empty string otherwise
*/
- public static function filterKeyName($keyName)
+ public static function filterKeyName(string $keyName): string
{
$data = self::getKeyArray();
if (isset($data[$keyName]))