summaryrefslogtreecommitdiffstats
path: root/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderbase.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderbase.inc.php')
-rw-r--r--modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderbase.inc.php83
1 files changed, 83 insertions, 0 deletions
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderbase.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderbase.inc.php
new file mode 100644
index 00000000..c6adc953
--- /dev/null
+++ b/modules-available/serversetup-bwlp-ipxe/inc/scriptbuilderbase.inc.php
@@ -0,0 +1,83 @@
+<?php
+
+abstract class ScriptBuilderBase
+{
+
+ private $lblId = 0;
+
+ protected $serverIp;
+
+ protected $platform = '';
+
+ protected $clientIp;
+
+ /**
+ * @var bool Running iPXE has slx-extensions
+ */
+ protected $hasExtension = false;
+
+ public function hasExtensions()
+ {
+ return $this->hasExtension;
+ }
+
+ public function platform()
+ {
+ return $this->platform;
+ }
+
+ public function getLabel()
+ {
+ return 'b' . mt_rand(100, 999) . 'x' . (++$this->lblId);
+ }
+
+ public function __construct($platform = null, $serverIp = null, $slxExtensions = null)
+ {
+ $this->clientIp = $_SERVER['REMOTE_ADDR'];
+ if (substr($this->clientIp, 0, 7) === '::ffff:') {
+ $this->clientIp = substr($this->clientIp, 7);
+ }
+ $this->serverIp = $serverIp ?? $_SERVER['SERVER_ADDR'] ?? Property::getServerIp();
+ $this->platform = $platform ?? Request::any('platform', false, 'string');
+ if ($this->platform !== false) {
+ $this->platform = strtoupper($this->platform);
+ }
+ Header('X-Popo: ' . $this->platform);
+ if ($this->platform !== 'EFI' && $this->platform !== 'PCBIOS') {
+ $this->platform = '';
+ }
+ $this->hasExtension = $slxExtensions ?? (bool)Request::any('slx-extensions', false, 'int');
+ }
+
+ /**
+ * Output given string (script) to client, in a suitable encoding, headers, etc.
+ * @param string $string
+ */
+ public abstract function output($string);
+
+ public abstract function getMenu($menuId);
+
+ public abstract function getMenuEntry($menuEntryId);
+
+ public abstract function getSpecial($special);
+
+ public abstract function fallback();
+
+ /**
+ * @param IPxeMenu|null $menu
+ * @return string
+ */
+ public abstract function menuToScript($menu);
+
+ /**
+ * Pass EITHER only $agnostic, OR $bios and/or $efi
+ * If $agnostic is given, it should be used unconditionally,
+ * and $bios/$efi should be ignored.
+ * @param ExecData $agnostic
+ * @param ExecData $bios
+ * @param ExecData $efi
+ * @return string
+ */
+ public abstract function execDataToScript($agnostic, $bios, $efi);
+
+} \ No newline at end of file