summaryrefslogtreecommitdiffstats
path: root/modules-available/serversetup-bwlp-ipxe/install.inc.php
blob: 983988bb0716e136e8093776cd9b7d7c3b8ae4a0 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php

$result = array();

$result[] = tableCreate('serversetup_bootentry', "
  `entryid` varchar(16) CHARACTER SET ascii NOT NULL,
  `hotkey` varchar(8) CHARACTER SET ascii NOT NULL,
  `title` varchar(100) NOT NULL,
  `builtin` tinyint(1) NOT NULL,
  `module` varchar(30) DEFAULT NULL,
  `data` blob NOT NULL,
  PRIMARY KEY (`entryid`)
");

$result[] = tableCreate('serversetup_menu', "
  `menuid` int(11) NOT NULL AUTO_INCREMENT,
  `timeoutms` int(10) unsigned NOT NULL,
  `title` varchar(100) NOT NULL COMMENT 'Escaped/Sanitized for iPXE!',
  `defaultentryid` int(11) DEFAULT NULL,
  `isdefault` tinyint(1) NOT NULL,
  PRIMARY KEY (`menuid`),
  KEY `defaultentryid` (`defaultentryid`),
  KEY `isdefault` (`isdefault`)
");

$result[] = tableCreate('serversetup_menuentry', "
  `menuentryid` int(11) NOT NULL AUTO_INCREMENT,
  `menuid` int(11) NOT NULL,
  `entryid` varchar(16) CHARACTER SET ascii NULL COMMENT 'If NULL, entry is gap or another menu',
  `refmenuid` int(11) DEFAULT NULL COMMENT 'If entryid is NULL this can be a ref to another menu',
  `hotkey` varchar(8) CHARACTER SET ascii NOT NULL,
  `title` varchar(100) NOT NULL COMMENT 'Sanitize this before insert',
  `hidden` tinyint(1) NOT NULL,
  `sortval` int(11) NOT NULL,
  `plainpass` varchar(80) NOT NULL,
  `md5pass` char(32) CHARACTER SET ascii NOT NULL,
  PRIMARY KEY (`menuentryid`),
  KEY `menuid` (`menuid`,`sortval`),
  KEY `entryid` (`entryid`)
");

$result[] = tableCreate('serversetup_menu_location', '
  `menuid` int(11) NOT NULL,
  `locationid` int(11) NOT NULL,
  `defaultentryid` int(11) DEFAULT NULL,
  PRIMARY KEY (`menuid`,`locationid`),
  UNIQUE `locationid` (`locationid`),
  KEY `defaultentryid` (`defaultentryid`)
');

$result[] = tableCreate('serversetup_localboot', "
  `systemmodel` varchar(120) NOT NULL,
  `pcbios` varchar(16) CHARACTER SET ascii DEFAULT NULL,
  `efi` varchar(16) CHARACTER SET ascii DEFAULT NULL,
  PRIMARY KEY (`systemmodel`)
");

// Add defaultentry override column
if (!tableHasColumn('serversetup_menu_location', 'defaultentryid')) {
	if (Database::exec('ALTER TABLE serversetup_menu_location ADD COLUMN `defaultentryid` int(11) DEFAULT NULL,
		ADD KEY `defaultentryid` (`defaultentryid`)') !== false) {
		$result[] = UPDATE_DONE;
	} else {
		$result[] = UPDATE_FAILED;
	}
}

$result[] = tableAddConstraint('serversetup_menu', 'defaultentryid', 'serversetup_menuentry', 'menuentryid',
	'ON DELETE SET NULL');

$result[] = tableAddConstraint('serversetup_menuentry', 'entryid', 'serversetup_bootentry', 'entryid',
	'ON UPDATE CASCADE ON DELETE CASCADE');

$result[] = tableAddConstraint('serversetup_menuentry', 'menuid', 'serversetup_menu', 'menuid',
	'ON UPDATE CASCADE ON DELETE CASCADE');

$result[] = tableAddConstraint('serversetup_menu_location', 'menuid', 'serversetup_menu', 'menuid',
	'ON UPDATE CASCADE ON DELETE CASCADE');

$result[] = tableAddConstraint('serversetup_menu_location', 'defaultentryid', 'serversetup_menuentry', 'menuentryid',
	'ON UPDATE CASCADE ON DELETE SET NULL');

// 2019-03-19 Add refmenuid to have cascaded menus
if (!tableHasColumn('serversetup_menuentry', 'refmenuid')) {
	if (Database::exec("ALTER TABLE serversetup_menuentry ADD COLUMN `refmenuid` int(11) DEFAULT NULL COMMENT 'If entryid is NULL this can be a ref to another menu'") !== false) {
		$result[] = UPDATE_DONE;
	} else {
		$result[] = UPDATE_FAILED;
	}
}

// 2019-03-26 Make localboot config distinct for efi and bios
if (!tableHasColumn('serversetup_localboot', 'pcbios')) {
	if (Database::exec("ALTER TABLE serversetup_localboot DROP COLUMN `bootmethod`,
	ADD COLUMN `pcbios` varchar(16) CHARACTER SET ascii DEFAULT NULL, ADD COLUMN `efi` varchar(16) CHARACTER SET ascii DEFAULT NULL") !== false) {
		$result[] = UPDATE_DONE;
	} else {
		$result[] = UPDATE_FAILED;
	}
}

$result[] = tableAddConstraint('serversetup_menuentry', 'refmenuid', 'serversetup_menu', 'menuid',
	'ON UPDATE CASCADE ON DELETE SET NULL');

if (Module::get('location') !== false) {
	if (!tableExists('location')) {
		$result[] = UPDATE_RETRY;
	} else {
		$result[] = tableAddConstraint('serversetup_menu_location', 'locationid', 'location', 'locationid',
			'ON UPDATE CASCADE ON DELETE CASCADE');
	}
}

// 2019-09-21 Add module column to bootentry
if (!tableHasColumn('serversetup_bootentry', 'module')) {
	if (Database::exec("ALTER TABLE serversetup_bootentry
	ADD COLUMN `module` varchar(30) CHARACTER SET ascii DEFAULT NULL AFTER `builtin`") !== false) {
		$result[] = UPDATE_DONE;
		$res = Database::simpleQuery('SELECT entryid, data FROM serversetup_bootentry WHERE module IS NULL');
		while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
			$json = json_decode($row['data'], true);
			if (isset($json['script'])) {
				Database::exec("UPDATE serversetup_bootentry SET module = '.script' WHERE entryid = :id", ['id' => $row['entryid']]);
			} else {
				Database::exec("UPDATE serversetup_bootentry SET module = '.exec' WHERE entryid = :id", ['id' => $row['entryid']]);
			}
		}
	} else {
		$result[] = UPDATE_FAILED;
	}
}

if (Module::isAvailable('serversetup')) {
	IPxe::createDefaultEntries();
}

responseFromArray($result);