r3256 initial checkin of VLAN management work
[racktables] / upgrade.php
CommitLineData
6dc745d2 1<?php
fbbb74fb 2
90b96ff6
DO
3$relnotes = array
4(
2c9fde3a
DO
5 '0.17.0' => "LDAP options have been moved to LDAP_options array. This means, that if you were<br>" .
6 "using LDAP authentication for users in version 0.16.x, it will break right after<br>" .
aca5a846 7 "upgrade to 0.17.0. To get things working again, adjust existing secret.php file<br>" .
2c9fde3a 8 "according to secret-sample.php file provided with 0.17.0 release.<br><br>" .
204284ba 9 "Another change is the addition of support for file uploads. Files are stored<br>" .
90b96ff6 10 "in the database. There are several settings in php.ini which you may need to modify:<br>" .
4114697d
DO
11 "<ul><li>file_uploads - needs to be On</li>" .
12 "<li>upload_max_filesize - max size for uploaded files</li>" .
a476909e 13 "<li>post_max_size - max size of all form data submitted via POST (including files)</li></ul><br>" .
b82cce3f 14 "Local user accounts used to have 'enabled' flag, which allowed individual blocking and<br>" .
a476909e
DO
15 "unblocking of each. This flag was dropped in favor of existing mean of access<br>" .
16 "setup (RackCode). An unconditional denying rule is automatically added into RackCode<br>" .
17 "for such blocked account, so the effective security policy remains the same.<br>",
90b96ff6
DO
18);
19
fbbb74fb
DO
20// At the moment we assume, that for any two releases we can
21// sequentally execute all batches, that separate them, and
22// nothing will break. If this changes one day, the function
23// below will have to generate smarter upgrade paths, while
24// the upper layer will remain the same.
25// Returning an empty array means that no upgrade is necessary.
4114697d 26// Returning NULL indicates an error.
fbbb74fb
DO
27function getDBUpgradePath ($v1, $v2)
28{
a6f83a72
DO
29 $versionhistory = array
30 (
b3f866fc 31 '0.16.4',
64347dcf 32 '0.16.5',
90b96ff6 33 '0.16.6',
30d0a2a3 34 '0.17.0',
4563cecb 35 '0.17.1',
7b1a3a72 36 '0.17.2',
9e51318b 37 '0.17.3',
958ac06d 38 '0.17.4',
9f572fb5 39 '0.17.5',
63811a09 40 '0.17.6',
026a79ee 41 '0.17.7',
3540d15c 42 '0.17.8',
a6f83a72 43 );
120e9ddd
DO
44 if (!in_array ($v1, $versionhistory) or !in_array ($v2, $versionhistory))
45 return NULL;
fbbb74fb 46 $skip = TRUE;
4114697d 47 $path = NULL;
fbbb74fb
DO
48 // Now collect all versions > $v1 and <= $v2
49 foreach ($versionhistory as $v)
50 {
4114697d 51 if ($skip and $v == $v1)
fbbb74fb
DO
52 {
53 $skip = FALSE;
4114697d 54 $path = array();
fbbb74fb
DO
55 continue;
56 }
57 if ($skip)
58 continue;
59 $path[] = $v;
60 if ($v == $v2)
61 break;
62 }
63 return $path;
64}
65
90b96ff6
DO
66// Upgrade batches are named exactly as the release where they first appear.
67// That is simple, but seems sufficient for beginning.
fbbb74fb
DO
68function executeUpgradeBatch ($batchid)
69{
70 $query = array();
ca3d68bd 71 global $dbxlink;
fbbb74fb
DO
72 switch ($batchid)
73 {
64347dcf
DO
74 case '0.16.5':
75 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('IPV4_TREE_SHOW_USAGE','yes','string','no','no','Show address usage in IPv4 tree')";
76 $query[] = "update Config set varvalue = '0.16.5' where varname = 'DB_VERSION'";
77 break;
90b96ff6
DO
78 case '0.16.6':
79 $query[] = "update Config set varvalue = '0.16.6' where varname = 'DB_VERSION'";
80 break;
30d0a2a3 81 case '0.17.0':
e1ae3fb4
AD
82 // create tables for storing files (requires InnoDB support)
83 if (!isInnoDBSupported ())
84 {
5d168fde 85 showFailure ("Cannot upgrade because InnoDB tables are not supported by your MySQL server. See the README for details.", __FILE__);
f3c50166 86 die;
e1ae3fb4 87 }
f76c4197
DY
88
89 $query[] = "alter table Chapter change chapter_no id int(10) unsigned NOT NULL auto_increment";
90 $query[] = "alter table Chapter change chapter_name name char(128) NOT NULL";
91 $query[] = "alter table Chapter drop key chapter_name";
92 $query[] = "alter table Chapter add UNIQUE KEY name (name)";
93 $query[] = "alter table Attribute change attr_id id int(10) unsigned NOT NULL auto_increment";
94 $query[] = "alter table Attribute change attr_type type enum('string','uint','float','dict') default NULL";
95 $query[] = "alter table Attribute change attr_name name char(64) default NULL";
96 $query[] = "alter table Attribute drop key attr_name";
97 $query[] = "alter table Attribute add UNIQUE KEY name (name)";
98 $query[] = "alter table AttributeMap change chapter_no chapter_id int(10) unsigned NOT NULL";
99 $query[] = "alter table Dictionary change chapter_no chapter_id int(10) unsigned NOT NULL";
3fb336f6 100 // Only after the above call it is Ok to use reloadDictionary()
ca3d68bd 101 $query = array_merge ($query, reloadDictionary ($batchid));
f3c50166 102 // schema changes for file management
e1ae3fb4
AD
103 $query[] = "
104CREATE TABLE `File` (
105 `id` int(10) unsigned NOT NULL auto_increment,
106 `name` char(255) NOT NULL,
107 `type` char(255) NOT NULL,
108 `size` int(10) unsigned NOT NULL,
109 `ctime` datetime NOT NULL,
110 `mtime` datetime NOT NULL,
111 `atime` datetime NOT NULL,
112 `contents` longblob NOT NULL,
113 `comment` text,
13edfa1c
AD
114 PRIMARY KEY (`id`),
115 UNIQUE KEY `name` (`name`)
e1ae3fb4
AD
116) ENGINE=InnoDB";
117 $query[] = "
118CREATE TABLE `FileLink` (
119 `id` int(10) unsigned NOT NULL auto_increment,
120 `file_id` int(10) unsigned NOT NULL,
121 `entity_type` enum('ipv4net','ipv4rspool','ipv4vs','object','rack','user') NOT NULL default 'object',
122 `entity_id` int(10) NOT NULL,
123 PRIMARY KEY (`id`),
af721881 124 UNIQUE KEY `FileLink-unique` (`file_id`,`entity_type`,`entity_id`),
e1ae3fb4
AD
125 KEY `FileLink-file_id` (`file_id`),
126 CONSTRAINT `FileLink-File_fkey` FOREIGN KEY (`file_id`) REFERENCES `File` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
127) ENGINE=InnoDB";
128 $query[] = "ALTER TABLE TagStorage MODIFY COLUMN target_realm enum('file','ipv4net','ipv4rspool','ipv4vs','object','rack','user') NOT NULL default 'object'";
f3c50166 129
f76c4197 130 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (24,'no','network security models')";
9730d09f 131 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (25,'no','wireless models')";
f76c4197
DY
132 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,1,0)";
133 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,2,24)";
134 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,3,0)";
135 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,5,0)";
136 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,14,0)";
137 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,16,0)";
138 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,17,0)";
139 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,18,0)";
140 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,20,0)";
141 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,21,0)";
142 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,22,0)";
143 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,24,0)";
9730d09f
DO
144 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (965,1,0)";
145 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (965,3,0)";
146 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (965,2,25)";
706ce117
DO
147 $query[] = 'alter table IPBonds rename to IPv4Allocation';
148 $query[] = 'alter table PortForwarding rename to IPv4NAT';
149 $query[] = 'alter table IPRanges rename to IPv4Network';
150 $query[] = 'alter table IPAddress rename to IPv4Address';
151 $query[] = 'alter table IPLoadBalancer rename to IPv4LB';
4114697d 152 $query[] = 'alter table IPRSPool rename to IPv4RSPool';
706ce117 153 $query[] = 'alter table IPRealServer rename to IPv4RS';
4114697d 154 $query[] = 'alter table IPVirtualService rename to IPv4VS';
120e9ddd
DO
155 $query[] = "alter table TagStorage change column target_realm entity_realm enum('file','ipv4net','ipv4vs','ipv4rspool','object','rack','user') NOT NULL default 'object'";
156 $query[] = 'alter table TagStorage change column target_id entity_id int(10) unsigned NOT NULL';
157 $query[] = 'alter table TagStorage drop key entity_tag';
158 $query[] = 'alter table TagStorage drop key target_id';
159 $query[] = 'alter table TagStorage add UNIQUE KEY `entity_tag` (`entity_realm`,`entity_id`,`tag_id`)';
160 $query[] = 'alter table TagStorage add KEY `entity_id` (`entity_id`)';
37e59768
DO
161 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('PREVIEW_TEXT_MAXCHARS','10240','uint','yes','no','Max chars for text file preview')";
162 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('PREVIEW_TEXT_ROWS','25','uint','yes','no','Rows for text file preview')";
163 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('PREVIEW_TEXT_COLS','80','uint','yes','no','Columns for text file preview')";
164 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('PREVIEW_IMAGE_MAXPXS','320','uint','yes','no','Max pixels per axis for image file preview')";
f3d274bf 165 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('VENDOR_SIEVE','','string','yes','no','Vendor sieve configuration')";
073ed463
DO
166 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('IPV4LB_LISTSRC','{\$typeid_4}','string','yes','no','List source: IPv4 load balancers')";
167 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('IPV4OBJ_LISTSRC','{\$typeid_4} or {\$typeid_7} or {\$typeid_8} or {\$typeid_12} or {\$typeid_445} or {\$typeid_447}','string','yes','no','List source: IPv4-enabled objects')";
168 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('IPV4NAT_LISTSRC','{\$typeid_4} or {\$typeid_7} or {\$typeid_8}','string','yes','no','List source: IPv4 NAT performers')";
169 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('ASSETWARN_LISTSRC','{\$typeid_4} or {\$typeid_7} or {\$typeid_8}','string','yes','no','List source: object, for which asset tag should be set')";
170 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('NAMEWARN_LISTSRC','{\$typeid_4} or {\$typeid_7} or {\$typeid_8}','string','yes','no','List source: object, for which common name should be set')";
f5883ec1 171 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('RACKS_PER_ROW','12','unit','yes','no','Racks per row')";
590e1281 172 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('FILTER_PREDICATE_SIEVE','','string','yes','no','Predicate sieve regex(7)')";
5496c89f
DO
173 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('FILTER_DEFAULT_ANDOR','or','string','no','no','Default list filter boolean operation (or/and)')";
174 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('FILTER_SUGGEST_ANDOR','yes','string','no','no','Suggest and/or selector in list filter')";
175 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('FILTER_SUGGEST_TAGS','yes','string','no','no','Suggest tags in list filter')";
176 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('FILTER_SUGGEST_PREDICATES','yes','string','no','no','Suggest predicates in list filter')";
177 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('FILTER_SUGGEST_EXTRA','no','string','no','no','Suggest extra expression in list filter')";
529eac25
DO
178 $query[] = "delete from Config where varname = 'USER_AUTH_SRC'";
179 $query[] = "delete from Config where varname = 'COOKIE_TTL'";
180 $query[] = "delete from Config where varname = 'rtwidth_0'";
181 $query[] = "delete from Config where varname = 'rtwidth_1'";
182 $query[] = "delete from Config where varname = 'rtwidth_2'";
c6bc0ac5
DO
183 $query[] = "delete from Config where varname = 'NAMEFUL_OBJTYPES'";
184 $query[] = "delete from Config where varname = 'REQUIRE_ASSET_TAG_FOR'";
185 $query[] = "delete from Config where varname = 'IPV4_PERFORMERS'";
186 $query[] = "delete from Config where varname = 'NATV4_PERFORMERS'";
dbb33805 187 $query[] = "alter table TagTree add column valid_realm set('file','ipv4net','ipv4vs','ipv4rspool','object','rack','user') not null default 'file,ipv4net,ipv4vs,ipv4rspool,object,rack,user' after parent_id";
a476909e
DO
188 $result = $dbxlink->query ("select user_id, user_name, user_realname from UserAccount where user_enabled = 'no'");
189 while ($row = $result->fetch (PDO::FETCH_ASSOC))
190 $query[] = "update Script set script_text = concat('deny {\$userid_${row['user_id']}} # ${row['user_name']} (${row['user_realname']})\n', script_text) where script_name = 'RackCode'";
191 $query[] = "update Script set script_text = NULL where script_name = 'RackCodeCache'";
192 unset ($result);
79b8ad1e 193 $query[] = "alter table UserAccount drop column user_enabled";
f76c4197 194
10bac82a
DY
195 $query[] = "CREATE TABLE RackRow ( id int(10) unsigned NOT NULL auto_increment, name char(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM";
196
9f14a7ef
DY
197 $result = $dbxlink->query ("select dict_key, dict_value from Dictionary where chapter_no = 3");
198 while($row = $result->fetch(PDO::FETCH_NUM))
10bac82a 199 $query[] = "insert into RackRow set id=${row[0]}, name='${row[1]}'";
ee286837 200 unset ($result);
f76c4197 201 $query[] = "delete from Dictionary where chapter_id = 3";
c4d0dc30 202 $query[] = "delete from Chapter where id = 3";
9133d2c5
DO
203 $query[] = "
204CREATE TABLE `LDAPCache` (
205 `presented_username` char(64) NOT NULL,
206 `successful_hash` char(40) NOT NULL,
207 `first_success` timestamp NOT NULL default CURRENT_TIMESTAMP,
208 `last_retry` timestamp NOT NULL default '0000-00-00 00:00:00',
209 `displayed_name` char(128) default NULL,
210 `memberof` text,
211 UNIQUE KEY `presented_username` (`presented_username`),
212 KEY `scanidx` (`presented_username`,`successful_hash`)
213) ENGINE=InnoDB;";
3827da34 214 $query[] = "alter table UserAccount modify column user_password_hash char(40) NULL";
aa9a0fb4
DO
215 $query[] = 'ALTER TABLE Rack DROP COLUMN deleted';
216 $query[] = 'ALTER TABLE RackHistory DROP COLUMN deleted';
217 $query[] = 'ALTER TABLE RackObject DROP COLUMN deleted';
218 $query[] = 'ALTER TABLE RackObjectHistory DROP COLUMN deleted';
2fb9d280
DO
219 // Can't be added straight due to many duplicates, even in "dictbase" data.
220 $result = $dbxlink->query ('SELECT type1, type2, count(*) - 1 as excess FROM PortCompat GROUP BY type1, type2 HAVING excess > 0');
221 while ($row = $result->fetch (PDO::FETCH_ASSOC))
222 $query[] = "DELETE FROM PortCompat WHERE type1 = ${row['type1']} AND type2 = ${row['type2']} limit ${row['excess']}";
223 unset ($result);
224 $query[] = 'ALTER TABLE PortCompat DROP KEY type1';
67d8a969 225 $query[] = 'ALTER TABLE PortCompat ADD UNIQUE `type1_2` (type1, type2)';
f76c4197
DY
226 $query[] = "UPDATE Config SET varvalue = '0.17.0' WHERE varname = 'DB_VERSION'";
227
b3f866fc 228 break;
4563cecb 229 case '0.17.1':
8b200a9c 230 $query[] = "ALTER TABLE Dictionary DROP KEY `chap_to_key`";
ca3d68bd 231 $query = array_merge ($query, reloadDictionary ($batchid));
4563cecb
DO
232 // Token set has changed, so the cache isn't valid any more.
233 $query[] = "UPDATE Script SET script_text = NULL WHERE script_name = 'RackCodeCache'";
234 $query[] = "UPDATE Config SET varvalue = '0.17.1' WHERE varname = 'DB_VERSION'";
7d4ea62b 235 break;
7b1a3a72 236 case '0.17.2':
7b1a3a72 237 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (26,'no','fibre channel switch models')";
ca3d68bd 238 $query = array_merge ($query, reloadDictionary ($batchid));
7c537f33 239 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1055,2,26)";
49b605d9 240 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('DEFAULT_SNMP_COMMUNITY','public','string','no','no','Default SNMP Community string')";
29c3a4d8
DO
241 // wipe irrelevant records (ticket:250)
242 $query[] = "DELETE FROM TagStorage WHERE entity_realm = 'file' AND entity_id NOT IN (SELECT id FROM File)";
f06fe423 243 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('IPV4_ENABLE_KNIGHT','yes','string','no','no','Enable IPv4 knight feature')";
99ab184f 244 $query[] = "ALTER TABLE IPv4Network ADD COLUMN comment text AFTER name";
5163cd3a 245 $query[] = "ALTER TABLE Port ADD INDEX comment (reservation_comment)";
029a14bc
DO
246 $query[] = "ALTER TABLE Port DROP KEY l2address"; // UNIQUE
247 $query[] = "ALTER TABLE Port ADD KEY (l2address)"; // not UNIQUE
948666cc
DO
248 $query[] = "ALTER TABLE Port DROP KEY object_id";
249 $query[] = "ALTER TABLE Port ADD UNIQUE KEY per_object (object_id, name, type)";
74aee2dc
DO
250 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (20,1083)";
251 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (21,1083)";
252 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (1077,1077)";
253 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (1083,20)";
254 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (1083,21)";
255 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (1083,1083)";
1c4830dc 256 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (1087,1087)";
50e02490
DO
257 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (27,'no','PDU models')";
258 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (2,2,27)";
7b1a3a72
AD
259 $query[] = "UPDATE Config SET varvalue = '0.17.2' WHERE varname = 'DB_VERSION'";
260 break;
9e51318b
DO
261 case '0.17.3':
262 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('TAGS_TOPLIST_SIZE','50','uint','yes','no','Tags top list size')";
263 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('TAGS_QUICKLIST_SIZE','20','uint','no','no','Tags quick list size')";
264 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('TAGS_QUICKLIST_THRESHOLD','50','uint','yes','no','Tags quick list threshold')";
87601bbc 265 $query[] = "ALTER TABLE AttributeMap MODIFY COLUMN chapter_id int(10) unsigned NULL";
7028a42c 266 $query[] = "UPDATE AttributeMap SET chapter_id = NULL WHERE attr_id IN (SELECT id FROM Attribute WHERE type != 'dict')";
a013838b
DO
267 // ticket:239
268 $query[] = 'UPDATE AttributeValue SET uint_value = 1018 WHERE uint_value = 731 AND attr_id IN (SELECT attr_id FROM AttributeMap WHERE chapter_id = 12)';
269 $query[] = 'DELETE FROM Dictionary WHERE dict_key = 731';
084aca6c
DO
270 $query = array_merge ($query, reloadDictionary ($batchid));
271 $query[] = "UPDATE Config SET vartype='uint' WHERE varname='RACKS_PER_ROW'";
f44fdef9 272 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('ENABLE_MULTIPORT_FORM','no','string','no','no','Enable \"Add/update multiple ports\" form')";
9e51318b
DO
273 $query[] = "UPDATE Config SET varvalue = '0.17.3' WHERE varname = 'DB_VERSION'";
274 break;
958ac06d
DO
275 case '0.17.4':
276 $query[] = "ALTER TABLE Link ENGINE=InnoDB";
277 $query[] = "ALTER TABLE Port ENGINE=InnoDB";
4d87feaf
DO
278 $query[] = "ALTER TABLE IPv4RS ENGINE=InnoDB";
279 $query[] = "ALTER TABLE IPv4RSPool ENGINE=InnoDB";
cafd4cf3
DO
280 $query[] = "ALTER TABLE AttributeValue ENGINE=InnoDB";
281 $query[] = "ALTER TABLE RackObject ENGINE=InnoDB";
282 $query[] = "ALTER TABLE IPv4NAT ENGINE=InnoDB";
283 $query[] = "ALTER TABLE IPv4LB ENGINE=InnoDB";
284 $query[] = "ALTER TABLE IPv4VS ENGINE=InnoDB";
4d87feaf 285 $query[] = "DELETE FROM IPv4RS WHERE rspool_id NOT IN (SELECT id FROM IPv4RSPool)";
958ac06d 286 $query[] = "ALTER TABLE Link ADD CONSTRAINT `Link-FK-b` FOREIGN KEY (portb) REFERENCES Port (id)";
cafd4cf3 287 $query[] = "ALTER TABLE Link ADD CONSTRAINT `Link-FK-a` FOREIGN KEY (porta) REFERENCES Port (id)";
4d87feaf 288 $query[] = "ALTER TABLE IPv4RS ADD CONSTRAINT `IPv4RS-FK` FOREIGN KEY (rspool_id) REFERENCES IPv4RSPool (id) ON DELETE CASCADE";
cafd4cf3
DO
289 $query[] = "ALTER TABLE AttributeValue ADD CONSTRAINT `AttributeValue-FK-object_id` FOREIGN KEY (object_id) REFERENCES RackObject (id)";
290 $query[] = "ALTER TABLE IPv4NAT ADD CONSTRAINT `IPv4NAT-FK-object_id` FOREIGN KEY (object_id) REFERENCES RackObject (id)";
291 $query[] = "ALTER TABLE Port ADD CONSTRAINT `Port-FK-object_id` FOREIGN KEY (object_id) REFERENCES RackObject (id)";
292 $query[] = "ALTER TABLE IPv4LB ADD CONSTRAINT `IPv4LB-FK-rspool_id` FOREIGN KEY (rspool_id) REFERENCES IPv4RSPool (id)";
293 $query[] = "ALTER TABLE IPv4LB ADD CONSTRAINT `IPv4LB-FK-object_id` FOREIGN KEY (object_id) REFERENCES RackObject (id)";
294 $query[] = "ALTER TABLE IPv4LB ADD CONSTRAINT `IPv4LB-FK-vs_id` FOREIGN KEY (vs_id) REFERENCES IPv4VS (id)";
e49d8a77 295 $query = array_merge ($query, reloadDictionary ($batchid));
958ac06d
DO
296 $query[] = "UPDATE Config SET varvalue = '0.17.4' WHERE varname = 'DB_VERSION'";
297 break;
9f572fb5
DO
298 case '0.17.5':
299 $query[] = "ALTER TABLE TagTree ENGINE=InnoDB";
300 $query[] = "ALTER TABLE TagStorage ENGINE=InnoDB";
301 $query[] = "ALTER TABLE TagStorage ADD CONSTRAINT `TagStorage-FK-tag_id` FOREIGN KEY (tag_id) REFERENCES TagTree (id)";
302 $query[] = "ALTER TABLE TagTree ADD CONSTRAINT `TagTree-K-parent_id` FOREIGN KEY (parent_id) REFERENCES TagTree (id)";
2400d7ec
DO
303 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (21,1195)';
304 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (22,1196)';
305 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (23,1196)';
306 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (20,1195)';
307 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (25,1202)';
308 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (26,1202)';
309 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (27,1204)';
310 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (28,1204)';
311 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1083,1195)';
312 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1084,1084)';
313 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1195,20)';
314 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1195,21)';
315 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1195,1083)';
316 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1195,1195)';
317 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1196,22)';
318 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1196,23)';
319 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1196,1196)';
320 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1197,1197)';
321 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1198,1199)';
322 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1199,1198)';
323 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1200,1200)';
324 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1201,1201)';
325 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1202,25)';
326 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1202,26)';
327 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1202,1202)';
328 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1203,1203)';
329 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1204,27)';
330 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1204,28)';
331 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1204,1204)';
332 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1205,1205)';
333 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1206,1207)';
334 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1207,1206)';
93a83f51 335 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1316,1316)';
bdc91a5c
DO
336 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (16, 1322)';
337 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1322, 16)';
338 $query[] = 'DELETE FROM PortCompat WHERE type1 = 16 AND type2 = 16';
2400d7ec
DO
339 for ($i = 1209; $i <= 1300; $i++)
340 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (${i}, ${i})";
d9b88ea0 341 $query[] = "
09d6afa4 342CREATE TABLE `PortInnerInterface` (
9173281a 343 `id` int(10) unsigned NOT NULL,
d9b88ea0
DO
344 `iif_name` char(16) NOT NULL,
345 PRIMARY KEY (`id`),
9173281a 346 UNIQUE KEY `iif_name` (`iif_name`)
d9b88ea0 347) ENGINE=InnoDB";
2400d7ec
DO
348 $query[] = "INSERT INTO `PortInnerInterface` VALUES (1,'hardwired')";
349 $query[] = "INSERT INTO `PortInnerInterface` VALUES (2,'SFP-100')";
350 $query[] = "INSERT INTO `PortInnerInterface` VALUES (3,'GBIC')";
351 $query[] = "INSERT INTO `PortInnerInterface` VALUES (4,'SFP-1000')";
352 $query[] = "INSERT INTO `PortInnerInterface` VALUES (5,'XENPAK')";
353 $query[] = "INSERT INTO `PortInnerInterface` VALUES (6,'X2')";
354 $query[] = "INSERT INTO `PortInnerInterface` VALUES (7,'XPAK')";
355 $query[] = "INSERT INTO `PortInnerInterface` VALUES (8,'XFP')";
356 $query[] = "INSERT INTO `PortInnerInterface` VALUES (9,'SFP+')";
d9b88ea0 357 $query[] = "
09d6afa4 358CREATE TABLE `PortInterfaceCompat` (
d9b88ea0
DO
359 `iif_id` int(10) unsigned NOT NULL,
360 `oif_id` int(10) unsigned NOT NULL,
361 UNIQUE KEY `pair` (`iif_id`,`oif_id`),
2400d7ec 362 CONSTRAINT `PortInterfaceCompat-FK-iif_id` FOREIGN KEY (`iif_id`) REFERENCES `PortInnerInterface` (`id`)
d9b88ea0 363) ENGINE=InnoDB";
c76cfa0d
DO
364 $query[] = "ALTER TABLE Port ADD COLUMN iif_id int unsigned NOT NULL AFTER name"; // will set iif_id to 0
365 $query[] = "UPDATE Port SET iif_id = 2 WHERE type = 1208";
366 $query[] = "UPDATE Port SET iif_id = 3 WHERE type = 1078";
367 $query[] = "UPDATE Port SET iif_id = 4 WHERE type = 1077";
368 $query[] = "UPDATE Port SET iif_id = 5 WHERE type = 1079";
369 $query[] = "UPDATE Port SET iif_id = 6 WHERE type = 1080";
370 $query[] = "UPDATE Port SET iif_id = 7 WHERE type = 1081";
371 $query[] = "UPDATE Port SET iif_id = 8 WHERE type = 1082";
372 $query[] = "UPDATE Port SET iif_id = 9 WHERE type = 1084";
373 $query[] = "UPDATE Port SET iif_id = 1 WHERE iif_id = 0";
08aa3467
DO
374 $query[] = 'ALTER TABLE Port ADD UNIQUE `object_iif_oif_name` (object_id, iif_id, type, name)';
375 $query[] = 'ALTER TABLE Port DROP KEY `per_object`';
2400d7ec
DO
376 $base1000 = array (24, 34, 1202, 1203, 1204, 1205, 1206, 1207);
377 $base10000 = array (30, 35, 36, 37, 38, 39, 40);
378 $PICdata = array
379 (
bdc91a5c 380 1 => array (16, 19, 24, 29, 31, 33, 446, 681, 682, 1322),
2400d7ec
DO
381 2 => array (1208, 1195, 1196, 1197, 1198, 1199, 1200, 1201),
382 3 => array_merge (array (1078), $base1000),
383 4 => array_merge (array (1077), $base1000),
384 5 => array_merge (array (1079), $base10000),
385 6 => array_merge (array (1080), $base10000),
386 7 => array_merge (array (1081), $base10000),
387 8 => array_merge (array (1082), $base10000),
388 9 => array_merge (array (1084), $base10000),
389 );
390 // make sure all IIF/OIF pairs referenced from Port exist in PortInterfaceCompat before enabling FK
391 // iif_id doesn't exist at this point
392 $result = $dbxlink->query ('SELECT DISTINCT type FROM Port WHERE type NOT IN (1208, 1078, 1077, 1079, 1080, 1081, 1082, 1084)');
393 while ($row = $result->fetch (PDO::FETCH_ASSOC))
394 if (FALSE === array_search ($row['type'], $PICdata[1]))
395 array_push ($PICdata[1], $row['type']);
396 unset ($result);
397 foreach ($PICdata as $iif_id => $oif_ids)
398 foreach ($oif_ids as $oif_id)
399 $query[] = "INSERT INTO PortInterfaceCompat (iif_id, oif_id) VALUES (${iif_id}, ${oif_id})";
c76cfa0d 400 $query[] = "ALTER TABLE Port ADD CONSTRAINT `Port-FK-iif-oif` FOREIGN KEY (`iif_id`, `type`) REFERENCES `PortInterfaceCompat` (`iif_id`, `oif_id`)";
bdc91a5c 401 $query[] = 'UPDATE Port SET type = 1322 WHERE type = 16 AND (SELECT objtype_id FROM RackObject WHERE id = object_id) IN (2, 12)';
2400d7ec
DO
402 $query = array_merge ($query, reloadDictionary ($batchid));
403 $query[] = "DELETE FROM Config WHERE varname = 'default_port_type'";
404 $query[] = "INSERT INTO Config VALUES ('DEFAULT_PORT_IIF_ID','1','uint','no','no','Default port inner interface ID')";
405 $query[] = "INSERT INTO Config VALUES ('DEFAULT_PORT_OIF_IDS','1=24; 3=1078; 4=1077; 5=1079; 6=1080; 8=1082; 9=1084','string','no','no','Default port outer interface IDs')";
4a47d34b 406 $query[] = "INSERT INTO Config VALUES ('IPV4_TREE_RTR_AS_CELL','yes','string','no','no','Show full router info for each network in IPv4 tree view')";
93a83f51 407 $query[] = "UPDATE Chapter SET name = 'PortOuterInterface' WHERE id = 2";
fbcbb4ee
DO
408 // remap refs to duplicate records, which will be discarded (ticket:286)
409 $query[] = 'UPDATE AttributeValue SET uint_value = 147 WHERE uint_value = 1020 AND attr_id = 2';
410 $query[] = 'UPDATE AttributeValue SET uint_value = 377 WHERE uint_value = 1021 AND attr_id = 2';
e8ab58e8 411 $query[] = 'INSERT INTO AttributeMap (objtype_id, attr_id) VALUES (2, 1), (2, 3), (2, 5)';
9f572fb5
DO
412 $query[] = "UPDATE Config SET varvalue = '0.17.5' WHERE varname = 'DB_VERSION'";
413 break;
63811a09
DO
414 case '0.17.6':
415 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (28,'no','Voice/video hardware')";
416 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1323,1,NULL)";
417 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1323,2,28)";
418 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1323,3,NULL)";
419 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1323,5,NULL)";
cd3775e9 420 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('PROXIMITY_RANGE','0','uint','yes','no','Proximity range (0 is current rack only)')";
5c3bc8de 421 $query = array_merge ($query, reloadDictionary ($batchid));
63811a09
DO
422 $query[] = "UPDATE Config SET varvalue = '0.17.6' WHERE varname = 'DB_VERSION'";
423 break;
026a79ee
DO
424 case '0.17.7':
425 $query[] = "UPDATE Config SET varvalue = '0.17.7' WHERE varname = 'DB_VERSION'";
426 break;
3540d15c 427 case '0.17.8':
45833307 428 $query[] = "ALTER table Config add `is_userdefined` enum('yes','no') NOT NULL default 'no' AFTER `is_hidden`";
3540d15c
DY
429 $query[] = "
430CREATE TABLE `UserConfig` (
431 `varname` char(32) NOT NULL,
432 `varvalue` char(255) NOT NULL,
433 `user` char(64) NOT NULL,
434 UNIQUE KEY `user_varname` (`user`,`varname`)
435) TYPE=InnoDB";
436 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='MASSCOUNT'";
437 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='MAXSELSIZE'";
438 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='ROW_SCALE'";
439 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='PORTS_PER_ROW'";
440 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='IPV4_ADDRS_PER_PAGE'";
441 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='DEFAULT_RACK_HEIGHT'";
442 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='DEFAULT_SLB_VS_PORT'";
443 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='DEFAULT_SLB_RS_PORT'";
444 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='DETECT_URLS'";
445 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='RACK_PRESELECT_THRESHOLD'";
446 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='DEFAULT_IPV4_RS_INSERVICE'";
447 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='DEFAULT_OBJECT_TYPE'";
448 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='SHOW_EXPLICIT_TAGS'";
449 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='SHOW_IMPLICIT_TAGS'";
450 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='SHOW_AUTOMATIC_TAGS'";
451 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='IPV4_AUTO_RELEASE'";
452 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='SHOW_LAST_TAB'";
453 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='EXT_IPV4_VIEW'";
454 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='TREE_THRESHOLD'";
455 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='ADDNEW_AT_TOP'";
456 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='IPV4_TREE_SHOW_USAGE'";
457 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='PREVIEW_TEXT_MAXCHARS'";
458 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='PREVIEW_TEXT_ROWS'";
459 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='PREVIEW_TEXT_COLS'";
460 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='PREVIEW_IMAGE_MAXPXS'";
461 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='VENDOR_SIEVE'";
462 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname='RACKS_PER_ROW'";
ad9da675 463 $query = array_merge ($query, reloadDictionary ($batchid));
8a6efd17 464 $query[] = "ALTER TABLE TagTree DROP COLUMN valid_realm";
3540d15c
DY
465 $query[] = "UPDATE Config SET varvalue = '0.17.8' WHERE varname = 'DB_VERSION'";
466 break;
8198f2c6
DO
467 case '0.17.9':
468 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('VLAN_LISTSRC', '', 'string', 'yes', 'no', 'List of VLAN running switches')";
469 $query[] = "UPDATE Config SET varvalue = '0.17.9' WHERE varname = 'DB_VERSION'";
470 break;
fbbb74fb 471 default:
5d168fde 472 showFailure ("executeUpgradeBatch () failed, because batch '${batchid}' isn't defined", __FILE__);
fbbb74fb
DO
473 die;
474 break;
475 }
fbbb74fb 476 $failures = array();
4114697d 477 echo "<tr><th>Executing batch '${batchid}'</th><td>";
fbbb74fb
DO
478 foreach ($query as $q)
479 {
480 $result = $dbxlink->query ($q);
4114697d 481 if ($result == NULL)
758fe24c 482 {
758fe24c
DO
483 $errorInfo = $dbxlink->errorInfo();
484 $failures[] = array ($q, $errorInfo[2]);
485 }
fbbb74fb 486 }
fbbb74fb 487 if (!count ($failures))
4114697d 488 echo "<strong><font color=green>done</font></strong>";
fbbb74fb
DO
489 else
490 {
4114697d 491 echo "<strong><font color=red>The following queries failed:</font></strong><br><pre>";
fbbb74fb
DO
492 foreach ($failures as $f)
493 {
494 list ($q, $i) = $f;
4114697d 495 echo "${q} -- ${i}\n";
fbbb74fb 496 }
4114697d 497 echo "</pre>";
fbbb74fb 498 }
4114697d 499 echo '</td></tr>';
fbbb74fb
DO
500}
501
502// ******************************************************************
503//
504// Execution starts here
505//
506// ******************************************************************
507
5d168fde
DO
508// a clone of showError() to drop dependency on interface.php
509function showFailure ($info = '', $location = 'N/A')
510{
5d168fde
DO
511 if (preg_match ('/\.php$/', $location))
512 $location = basename ($location);
513 elseif ($location != 'N/A')
514 $location = $location . '()';
515 echo "<div class=msg_error>An error has occured in [${location}]. ";
516 if (empty ($info))
517 echo 'No additional information is available.';
518 else
519 echo "Additional information:<br><p>\n<pre>\n${info}\n</pre></p>";
520 echo "This failure is most probably fatal.<br></div>\n";
521}
522
523require_once 'inc/config.php'; // for CODE_VERSION
524require_once 'inc/database.php'; // for getDatabaseVersion()
3fb336f6 525require_once 'inc/dictionary.php';
5d168fde
DO
526// Enforce default value for now, releases prior to 0.17.0 didn't support 'httpd' auth source.
527$user_auth_src = 'database';
fbbb74fb 528
80138748
DO
529if (file_exists ('inc/secret.php'))
530 require_once 'inc/secret.php';
fbbb74fb 531else
80138748
DO
532 die ("Database connection parameters are read from inc/secret.php file, " .
533 "which cannot be found.\nCopy provided inc/secret-sample.php to " .
534 "inc/secret.php and modify to your setup.\n\nThen reload the page.");
fbbb74fb
DO
535
536try
537{
538 $dbxlink = new PDO ($pdo_dsn, $db_username, $db_password);
539}
540catch (PDOException $e)
541{
542 die ("Database connection failed:\n\n" . $e->getMessage());
543}
544
fbbb74fb
DO
545// Now we need to be sure that the current user is the administrator.
546// The rest doesn't matter within this context.
fbbb74fb 547
120e9ddd 548function authenticate_admin ($username, $password)
a1f3710a 549{
43c7895d 550 global $dbxlink;
93bdb7ba 551 $hash = sha1 ($password);
120e9ddd 552 $query = "select count(*) from UserAccount where user_id = 1 and user_name = '${username}' and user_password_hash = '${hash}'";
a1f3710a
DO
553 if (($result = $dbxlink->query ($query)) == NULL)
554 die ('SQL query failed in ' . __FUNCTION__);
120e9ddd 555 $rows = $result->fetchAll (PDO::FETCH_NUM);
43c7895d 556 return $rows[0][0] == 1;
a1f3710a
DO
557}
558
204284ba 559switch ($user_auth_src)
99ee5479 560{
120e9ddd
DO
561 case 'database':
562 case 'ldap': // authenticate against DB as well
563 if
564 (
565 !isset ($_SERVER['PHP_AUTH_USER']) or
566 !strlen ($_SERVER['PHP_AUTH_USER']) or
567 !isset ($_SERVER['PHP_AUTH_PW']) or
568 !strlen ($_SERVER['PHP_AUTH_PW']) or
569 !authenticate_admin (escapeString ($_SERVER['PHP_AUTH_USER']), escapeString ($_SERVER['PHP_AUTH_PW']))
570 )
571 {
572 header ('WWW-Authenticate: Basic realm="RackTables upgrade"');
573 header ('HTTP/1.0 401 Unauthorized');
33bbd712 574 showFailure ('You must be authenticated as an administrator to complete the upgrade.', __FILE__);
120e9ddd
DO
575 die;
576 }
577 break; // cleared
578 case 'httpd':
579 if
580 (
581 !isset ($_SERVER['REMOTE_USER']) or
582 !strlen ($_SERVER['REMOTE_USER'])
583 )
584 {
33bbd712 585 showFailure ('System misconfiguration. The web-server didn\'t authenticate the user, although ought to do.');
120e9ddd
DO
586 die;
587 }
588 break; // cleared
589 default:
33bbd712 590 showFailure ('authentication source misconfiguration', __FILE__);
120e9ddd 591 die;
99ee5479 592}
fbbb74fb
DO
593
594$dbver = getDatabaseVersion();
4114697d
DO
595echo '<table border=1>';
596echo "<tr><th>Current status</th><td>Data version: ${dbver}<br>Code version: " . CODE_VERSION . "</td></tr>\n";
597
598$path = getDBUpgradePath ($dbver, CODE_VERSION);
599if ($path === NULL)
758fe24c 600{
4114697d 601 echo "<tr><th>Upgrade path</th><td><font color=red>not found</font></td></tr>\n";
d74ae24c
DO
602 echo "<tr><th>Summary</th><td>Check README for more information. RackTables releases prior to 0.16.4 ";
603 echo "must be upgraded to 0.16.4 first.</td></tr>\n";
758fe24c 604}
4114697d 605else
5f4027b8 606{
4114697d
DO
607 if (!count ($path))
608 echo "<tr><th>Summary</th><td>Come back later.</td></tr>\n";
609 else
610 {
611 echo "<tr><th>Upgrade path</th><td>${dbver} &rarr; " . implode (' &rarr; ', $path) . "</td></tr>\n";
612 foreach ($path as $batchid)
613 {
614 executeUpgradeBatch ($batchid);
615 if (isset ($relnotes[$batchid]))
616 echo "<tr><th>Release notes for ${batchid}</th><td>" . $relnotes[$batchid] . "</td></tr>\n";
617 }
790a60e8 618 echo "<tr><th>Summary</th><td>Upgrade complete, it is Ok to <a href='index.php'>enter</a> the system.</td></tr>\n";
4114697d 619 }
5f4027b8 620}
4114697d 621echo '</table>';
fbbb74fb
DO
622
623?>