summaryrefslogtreecommitdiffstats
path: root/modules-available/serversetup-bwlp/inc/ipxe.inc.php
blob: abeea74805c2b545b2862d68a5af5149b181d358 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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; }
}