r4073 minor change in UI for recent change: VST form commit on ENTER and hints on...
[racktables] / upgrade.php
1 <?php
2
3 $relnotes = array
4 (
5 '0.17.0' => <<<ENDOFTEXT
6 LDAP options have been moved to LDAP_options array. This means, that if you were
7 using LDAP authentication for users in version 0.16.x, it will break right after
8 upgrade to 0.17.0. To get things working again, adjust existing secret.php file
9 according to secret-sample.php file provided with 0.17.0 release.
10
11 This release is the first to take advantage of the foreign key support
12 provided by the InnoDB storage engine in MySQL. The installer and
13 upgrader scripts check for InnoDB support and cannot complete without it.
14 If you have trouble, the first step is to make sure the 'skip-innodb'
15 option in my.cnf is commented out.
16
17 Another change is the addition of support for file uploads. Files are stored
18 in the database. There are several settings in php.ini which you may need to modify:
19 file_uploads - needs to be On
20 upload_max_filesize - max size for uploaded files
21 post_max_size - max size of all form data submitted via POST (including files)
22
23 User accounts used to have 'enabled' flag, which allowed individual blocking and
24 unblocking of each. This flag was dropped in favor of existing mean of access
25 setup (RackCode). An unconditional denying rule is automatically added into RackCode
26 for such blocked account, so the effective security policy remains the same.
27 ENDOFTEXT
28 ,
29 '0.18.2' => <<<ENDOFTEXT
30 RackTables from its version 0.18.0 and later is not compatible with
31 RHEL/CentOS (at least with versions up to 5.5) Linux distributions
32 in their default installation. There are yet options to work around that:
33 1. Install RackTables on a server with a different distribution/OS.
34 2. Request Linux distribution vendor to fix the bug with PCRE.
35 3. Repair your RHEL/CentOS installation yourself by fixing its PCRE
36 RPM as explained here: http://bugs.centos.org/view.php?id=3252
37 ENDOFTEXT
38 ,
39 );
40
41 // At the moment we assume, that for any two releases we can
42 // sequentally execute all batches, that separate them, and
43 // nothing will break. If this changes one day, the function
44 // below will have to generate smarter upgrade paths, while
45 // the upper layer will remain the same.
46 // Returning an empty array means that no upgrade is necessary.
47 // Returning NULL indicates an error.
48 function getDBUpgradePath ($v1, $v2)
49 {
50 $versionhistory = array
51 (
52 '0.16.4',
53 '0.16.5',
54 '0.16.6',
55 '0.17.0',
56 '0.17.1',
57 '0.17.2',
58 '0.17.3',
59 '0.17.4',
60 '0.17.5',
61 '0.17.6',
62 '0.17.7',
63 '0.17.8',
64 '0.17.9',
65 '0.17.10',
66 '0.17.11',
67 '0.18.0',
68 '0.18.1',
69 '0.18.2',
70 '0.18.3',
71 '0.18.4',
72 '0.18.5',
73 '0.19.0',
74 );
75 if (!in_array ($v1, $versionhistory) or !in_array ($v2, $versionhistory))
76 return NULL;
77 $skip = TRUE;
78 $path = NULL;
79 // Now collect all versions > $v1 and <= $v2
80 foreach ($versionhistory as $v)
81 {
82 if ($skip and $v == $v1)
83 {
84 $skip = FALSE;
85 $path = array();
86 continue;
87 }
88 if ($skip)
89 continue;
90 $path[] = $v;
91 if ($v == $v2)
92 break;
93 }
94 return $path;
95 }
96
97 // Upgrade batches are named exactly as the release where they first appear.
98 // That is simple, but seems sufficient for beginning.
99 function executeUpgradeBatch ($batchid)
100 {
101 $query = array();
102 global $dbxlink;
103 switch ($batchid)
104 {
105 case '0.16.5':
106 $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')";
107 $query[] = "update Config set varvalue = '0.16.5' where varname = 'DB_VERSION'";
108 break;
109 case '0.16.6':
110 $query[] = "update Config set varvalue = '0.16.6' where varname = 'DB_VERSION'";
111 break;
112 case '0.17.0':
113 // create tables for storing files (requires InnoDB support)
114 if (!isInnoDBSupported ())
115 {
116 showFailure ("Cannot upgrade because InnoDB tables are not supported by your MySQL server. See the README for details.", __FILE__);
117 die;
118 }
119
120 $query[] = "alter table Chapter change chapter_no id int(10) unsigned NOT NULL auto_increment";
121 $query[] = "alter table Chapter change chapter_name name char(128) NOT NULL";
122 $query[] = "alter table Chapter drop key chapter_name";
123 $query[] = "alter table Chapter add UNIQUE KEY name (name)";
124 $query[] = "alter table Attribute change attr_id id int(10) unsigned NOT NULL auto_increment";
125 $query[] = "alter table Attribute change attr_type type enum('string','uint','float','dict') default NULL";
126 $query[] = "alter table Attribute change attr_name name char(64) default NULL";
127 $query[] = "alter table Attribute drop key attr_name";
128 $query[] = "alter table Attribute add UNIQUE KEY name (name)";
129 $query[] = "alter table AttributeMap change chapter_no chapter_id int(10) unsigned NOT NULL";
130 $query[] = "alter table Dictionary change chapter_no chapter_id int(10) unsigned NOT NULL";
131 // Only after the above call it is Ok to use reloadDictionary()
132 $query = array_merge ($query, reloadDictionary ($batchid));
133 // schema changes for file management
134 $query[] = "
135 CREATE TABLE `File` (
136 `id` int(10) unsigned NOT NULL auto_increment,
137 `name` char(255) NOT NULL,
138 `type` char(255) NOT NULL,
139 `size` int(10) unsigned NOT NULL,
140 `ctime` datetime NOT NULL,
141 `mtime` datetime NOT NULL,
142 `atime` datetime NOT NULL,
143 `contents` longblob NOT NULL,
144 `comment` text,
145 PRIMARY KEY (`id`),
146 UNIQUE KEY `name` (`name`)
147 ) ENGINE=InnoDB";
148 $query[] = "
149 CREATE TABLE `FileLink` (
150 `id` int(10) unsigned NOT NULL auto_increment,
151 `file_id` int(10) unsigned NOT NULL,
152 `entity_type` enum('ipv4net','ipv4rspool','ipv4vs','object','rack','user') NOT NULL default 'object',
153 `entity_id` int(10) NOT NULL,
154 PRIMARY KEY (`id`),
155 UNIQUE KEY `FileLink-unique` (`file_id`,`entity_type`,`entity_id`),
156 KEY `FileLink-file_id` (`file_id`),
157 CONSTRAINT `FileLink-File_fkey` FOREIGN KEY (`file_id`) REFERENCES `File` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
158 ) ENGINE=InnoDB";
159 $query[] = "ALTER TABLE TagStorage MODIFY COLUMN target_realm enum('file','ipv4net','ipv4rspool','ipv4vs','object','rack','user') NOT NULL default 'object'";
160
161 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (24,'no','network security models')";
162 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (25,'no','wireless models')";
163 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,1,0)";
164 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,2,24)";
165 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,3,0)";
166 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,5,0)";
167 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,14,0)";
168 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,16,0)";
169 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,17,0)";
170 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,18,0)";
171 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,20,0)";
172 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,21,0)";
173 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,22,0)";
174 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,24,0)";
175 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (965,1,0)";
176 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (965,3,0)";
177 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (965,2,25)";
178 $query[] = 'alter table IPBonds rename to IPv4Allocation';
179 $query[] = 'alter table PortForwarding rename to IPv4NAT';
180 $query[] = 'alter table IPRanges rename to IPv4Network';
181 $query[] = 'alter table IPAddress rename to IPv4Address';
182 $query[] = 'alter table IPLoadBalancer rename to IPv4LB';
183 $query[] = 'alter table IPRSPool rename to IPv4RSPool';
184 $query[] = 'alter table IPRealServer rename to IPv4RS';
185 $query[] = 'alter table IPVirtualService rename to IPv4VS';
186 $query[] = "alter table TagStorage change column target_realm entity_realm enum('file','ipv4net','ipv4vs','ipv4rspool','object','rack','user') NOT NULL default 'object'";
187 $query[] = 'alter table TagStorage change column target_id entity_id int(10) unsigned NOT NULL';
188 $query[] = 'alter table TagStorage drop key entity_tag';
189 $query[] = 'alter table TagStorage drop key target_id';
190 $query[] = 'alter table TagStorage add UNIQUE KEY `entity_tag` (`entity_realm`,`entity_id`,`tag_id`)';
191 $query[] = 'alter table TagStorage add KEY `entity_id` (`entity_id`)';
192 $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')";
193 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('PREVIEW_TEXT_ROWS','25','uint','yes','no','Rows for text file preview')";
194 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('PREVIEW_TEXT_COLS','80','uint','yes','no','Columns for text file preview')";
195 $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')";
196 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('VENDOR_SIEVE','','string','yes','no','Vendor sieve configuration')";
197 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('IPV4LB_LISTSRC','{\$typeid_4}','string','yes','no','List source: IPv4 load balancers')";
198 $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')";
199 $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')";
200 $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')";
201 $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')";
202 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('RACKS_PER_ROW','12','unit','yes','no','Racks per row')";
203 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('FILTER_PREDICATE_SIEVE','','string','yes','no','Predicate sieve regex(7)')";
204 $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)')";
205 $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')";
206 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('FILTER_SUGGEST_TAGS','yes','string','no','no','Suggest tags in list filter')";
207 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('FILTER_SUGGEST_PREDICATES','yes','string','no','no','Suggest predicates in list filter')";
208 $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')";
209 $query[] = "delete from Config where varname = 'USER_AUTH_SRC'";
210 $query[] = "delete from Config where varname = 'COOKIE_TTL'";
211 $query[] = "delete from Config where varname = 'rtwidth_0'";
212 $query[] = "delete from Config where varname = 'rtwidth_1'";
213 $query[] = "delete from Config where varname = 'rtwidth_2'";
214 $query[] = "delete from Config where varname = 'NAMEFUL_OBJTYPES'";
215 $query[] = "delete from Config where varname = 'REQUIRE_ASSET_TAG_FOR'";
216 $query[] = "delete from Config where varname = 'IPV4_PERFORMERS'";
217 $query[] = "delete from Config where varname = 'NATV4_PERFORMERS'";
218 $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";
219 $result = $dbxlink->query ("select user_id, user_name, user_realname from UserAccount where user_enabled = 'no'");
220 while ($row = $result->fetch (PDO::FETCH_ASSOC))
221 $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'";
222 $query[] = "update Script set script_text = NULL where script_name = 'RackCodeCache'";
223 unset ($result);
224 $query[] = "alter table UserAccount drop column user_enabled";
225
226 $query[] = "CREATE TABLE RackRow ( id int(10) unsigned NOT NULL auto_increment, name char(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM";
227
228 $result = $dbxlink->query ("select dict_key, dict_value from Dictionary where chapter_no = 3");
229 while($row = $result->fetch(PDO::FETCH_NUM))
230 $query[] = "insert into RackRow set id=${row[0]}, name='${row[1]}'";
231 unset ($result);
232 $query[] = "delete from Dictionary where chapter_id = 3";
233 $query[] = "delete from Chapter where id = 3";
234 $query[] = "
235 CREATE TABLE `LDAPCache` (
236 `presented_username` char(64) NOT NULL,
237 `successful_hash` char(40) NOT NULL,
238 `first_success` timestamp NOT NULL default CURRENT_TIMESTAMP,
239 `last_retry` timestamp NOT NULL default '0000-00-00 00:00:00',
240 `displayed_name` char(128) default NULL,
241 `memberof` text,
242 UNIQUE KEY `presented_username` (`presented_username`),
243 KEY `scanidx` (`presented_username`,`successful_hash`)
244 ) ENGINE=InnoDB;";
245 $query[] = "alter table UserAccount modify column user_password_hash char(40) NULL";
246 $query[] = 'ALTER TABLE Rack DROP COLUMN deleted';
247 $query[] = 'ALTER TABLE RackHistory DROP COLUMN deleted';
248 $query[] = 'ALTER TABLE RackObject DROP COLUMN deleted';
249 $query[] = 'ALTER TABLE RackObjectHistory DROP COLUMN deleted';
250 // Can't be added straight due to many duplicates, even in "dictbase" data.
251 $result = $dbxlink->query ('SELECT type1, type2, count(*) - 1 as excess FROM PortCompat GROUP BY type1, type2 HAVING excess > 0');
252 while ($row = $result->fetch (PDO::FETCH_ASSOC))
253 $query[] = "DELETE FROM PortCompat WHERE type1 = ${row['type1']} AND type2 = ${row['type2']} limit ${row['excess']}";
254 unset ($result);
255 $query[] = 'ALTER TABLE PortCompat DROP KEY type1';
256 $query[] = 'ALTER TABLE PortCompat ADD UNIQUE `type1_2` (type1, type2)';
257 $query[] = "UPDATE Config SET varvalue = '0.17.0' WHERE varname = 'DB_VERSION'";
258
259 break;
260 case '0.17.1':
261 $query[] = "ALTER TABLE Dictionary DROP KEY `chap_to_key`";
262 $query = array_merge ($query, reloadDictionary ($batchid));
263 // Token set has changed, so the cache isn't valid any more.
264 $query[] = "UPDATE Script SET script_text = NULL WHERE script_name = 'RackCodeCache'";
265 $query[] = "UPDATE Config SET varvalue = '0.17.1' WHERE varname = 'DB_VERSION'";
266 break;
267 case '0.17.2':
268 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (26,'no','fibre channel switch models')";
269 $query = array_merge ($query, reloadDictionary ($batchid));
270 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1055,2,26)";
271 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('DEFAULT_SNMP_COMMUNITY','public','string','no','no','Default SNMP Community string')";
272 // wipe irrelevant records (ticket:250)
273 $query[] = "DELETE FROM TagStorage WHERE entity_realm = 'file' AND entity_id NOT IN (SELECT id FROM File)";
274 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('IPV4_ENABLE_KNIGHT','yes','string','no','no','Enable IPv4 knight feature')";
275 $query[] = "ALTER TABLE IPv4Network ADD COLUMN comment text AFTER name";
276 $query[] = "ALTER TABLE Port ADD INDEX comment (reservation_comment)";
277 $query[] = "ALTER TABLE Port DROP KEY l2address"; // UNIQUE
278 $query[] = "ALTER TABLE Port ADD KEY (l2address)"; // not UNIQUE
279 $query[] = "ALTER TABLE Port DROP KEY object_id";
280 $query[] = "ALTER TABLE Port ADD UNIQUE KEY per_object (object_id, name, type)";
281 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (20,1083)";
282 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (21,1083)";
283 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (1077,1077)";
284 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (1083,20)";
285 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (1083,21)";
286 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (1083,1083)";
287 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (1087,1087)";
288 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (27,'no','PDU models')";
289 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (2,2,27)";
290 $query[] = "UPDATE Config SET varvalue = '0.17.2' WHERE varname = 'DB_VERSION'";
291 break;
292 case '0.17.3':
293 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('TAGS_TOPLIST_SIZE','50','uint','yes','no','Tags top list size')";
294 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('TAGS_QUICKLIST_SIZE','20','uint','no','no','Tags quick list size')";
295 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('TAGS_QUICKLIST_THRESHOLD','50','uint','yes','no','Tags quick list threshold')";
296 $query[] = "ALTER TABLE AttributeMap MODIFY COLUMN chapter_id int(10) unsigned NULL";
297 $query[] = "UPDATE AttributeMap SET chapter_id = NULL WHERE attr_id IN (SELECT id FROM Attribute WHERE type != 'dict')";
298 // ticket:239
299 $query[] = 'UPDATE AttributeValue SET uint_value = 1018 WHERE uint_value = 731 AND attr_id IN (SELECT attr_id FROM AttributeMap WHERE chapter_id = 12)';
300 $query[] = 'DELETE FROM Dictionary WHERE dict_key = 731';
301 $query = array_merge ($query, reloadDictionary ($batchid));
302 $query[] = "UPDATE Config SET vartype='uint' WHERE varname='RACKS_PER_ROW'";
303 $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')";
304 $query[] = "UPDATE Config SET varvalue = '0.17.3' WHERE varname = 'DB_VERSION'";
305 break;
306 case '0.17.4':
307 $query[] = "ALTER TABLE Link ENGINE=InnoDB";
308 $query[] = "ALTER TABLE Port ENGINE=InnoDB";
309 $query[] = "ALTER TABLE IPv4RS ENGINE=InnoDB";
310 $query[] = "ALTER TABLE IPv4RSPool ENGINE=InnoDB";
311 $query[] = "ALTER TABLE AttributeValue ENGINE=InnoDB";
312 $query[] = "ALTER TABLE RackObject ENGINE=InnoDB";
313 $query[] = "ALTER TABLE IPv4NAT ENGINE=InnoDB";
314 $query[] = "ALTER TABLE IPv4LB ENGINE=InnoDB";
315 $query[] = "ALTER TABLE IPv4VS ENGINE=InnoDB";
316 $query[] = "DELETE FROM IPv4RS WHERE rspool_id NOT IN (SELECT id FROM IPv4RSPool)";
317 $query[] = "ALTER TABLE Link ADD CONSTRAINT `Link-FK-b` FOREIGN KEY (portb) REFERENCES Port (id)";
318 $query[] = "ALTER TABLE Link ADD CONSTRAINT `Link-FK-a` FOREIGN KEY (porta) REFERENCES Port (id)";
319 $query[] = "ALTER TABLE IPv4RS ADD CONSTRAINT `IPv4RS-FK` FOREIGN KEY (rspool_id) REFERENCES IPv4RSPool (id) ON DELETE CASCADE";
320 $query[] = "ALTER TABLE AttributeValue ADD CONSTRAINT `AttributeValue-FK-object_id` FOREIGN KEY (object_id) REFERENCES RackObject (id)";
321 $query[] = "ALTER TABLE IPv4NAT ADD CONSTRAINT `IPv4NAT-FK-object_id` FOREIGN KEY (object_id) REFERENCES RackObject (id)";
322 $query[] = "ALTER TABLE Port ADD CONSTRAINT `Port-FK-object_id` FOREIGN KEY (object_id) REFERENCES RackObject (id)";
323 $query[] = "ALTER TABLE IPv4LB ADD CONSTRAINT `IPv4LB-FK-rspool_id` FOREIGN KEY (rspool_id) REFERENCES IPv4RSPool (id)";
324 $query[] = "ALTER TABLE IPv4LB ADD CONSTRAINT `IPv4LB-FK-object_id` FOREIGN KEY (object_id) REFERENCES RackObject (id)";
325 $query[] = "ALTER TABLE IPv4LB ADD CONSTRAINT `IPv4LB-FK-vs_id` FOREIGN KEY (vs_id) REFERENCES IPv4VS (id)";
326 $query = array_merge ($query, reloadDictionary ($batchid));
327 $query[] = "UPDATE Config SET varvalue = '0.17.4' WHERE varname = 'DB_VERSION'";
328 break;
329 case '0.17.5':
330 $query[] = "ALTER TABLE TagTree ENGINE=InnoDB";
331 $query[] = "ALTER TABLE TagStorage ENGINE=InnoDB";
332 $query[] = "ALTER TABLE TagStorage ADD CONSTRAINT `TagStorage-FK-tag_id` FOREIGN KEY (tag_id) REFERENCES TagTree (id)";
333 $query[] = "ALTER TABLE TagTree ADD CONSTRAINT `TagTree-K-parent_id` FOREIGN KEY (parent_id) REFERENCES TagTree (id)";
334 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (21,1195)';
335 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (22,1196)';
336 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (23,1196)';
337 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (20,1195)';
338 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (25,1202)';
339 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (26,1202)';
340 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (27,1204)';
341 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (28,1204)';
342 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1083,1195)';
343 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1084,1084)';
344 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1195,20)';
345 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1195,21)';
346 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1195,1083)';
347 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1195,1195)';
348 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1196,22)';
349 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1196,23)';
350 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1196,1196)';
351 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1197,1197)';
352 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1198,1199)';
353 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1199,1198)';
354 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1200,1200)';
355 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1201,1201)';
356 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1202,25)';
357 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1202,26)';
358 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1202,1202)';
359 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1203,1203)';
360 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1204,27)';
361 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1204,28)';
362 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1204,1204)';
363 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1205,1205)';
364 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1206,1207)';
365 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1207,1206)';
366 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1316,1316)';
367 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (16, 1322)';
368 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1322, 16)';
369 $query[] = 'DELETE FROM PortCompat WHERE type1 = 16 AND type2 = 16';
370 for ($i = 1209; $i <= 1300; $i++)
371 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (${i}, ${i})";
372 $query[] = "
373 CREATE TABLE `PortInnerInterface` (
374 `id` int(10) unsigned NOT NULL,
375 `iif_name` char(16) NOT NULL,
376 PRIMARY KEY (`id`),
377 UNIQUE KEY `iif_name` (`iif_name`)
378 ) ENGINE=InnoDB";
379 $query[] = "INSERT INTO `PortInnerInterface` VALUES (1,'hardwired')";
380 $query[] = "INSERT INTO `PortInnerInterface` VALUES (2,'SFP-100')";
381 $query[] = "INSERT INTO `PortInnerInterface` VALUES (3,'GBIC')";
382 $query[] = "INSERT INTO `PortInnerInterface` VALUES (4,'SFP-1000')";
383 $query[] = "INSERT INTO `PortInnerInterface` VALUES (5,'XENPAK')";
384 $query[] = "INSERT INTO `PortInnerInterface` VALUES (6,'X2')";
385 $query[] = "INSERT INTO `PortInnerInterface` VALUES (7,'XPAK')";
386 $query[] = "INSERT INTO `PortInnerInterface` VALUES (8,'XFP')";
387 $query[] = "INSERT INTO `PortInnerInterface` VALUES (9,'SFP+')";
388 $query[] = "
389 CREATE TABLE `PortInterfaceCompat` (
390 `iif_id` int(10) unsigned NOT NULL,
391 `oif_id` int(10) unsigned NOT NULL,
392 UNIQUE KEY `pair` (`iif_id`,`oif_id`),
393 CONSTRAINT `PortInterfaceCompat-FK-iif_id` FOREIGN KEY (`iif_id`) REFERENCES `PortInnerInterface` (`id`)
394 ) ENGINE=InnoDB";
395 $query[] = "ALTER TABLE Port ADD COLUMN iif_id int unsigned NOT NULL AFTER name"; // will set iif_id to 0
396 $query[] = "UPDATE Port SET iif_id = 2 WHERE type = 1208";
397 $query[] = "UPDATE Port SET iif_id = 3 WHERE type = 1078";
398 $query[] = "UPDATE Port SET iif_id = 4 WHERE type = 1077";
399 $query[] = "UPDATE Port SET iif_id = 5 WHERE type = 1079";
400 $query[] = "UPDATE Port SET iif_id = 6 WHERE type = 1080";
401 $query[] = "UPDATE Port SET iif_id = 7 WHERE type = 1081";
402 $query[] = "UPDATE Port SET iif_id = 8 WHERE type = 1082";
403 $query[] = "UPDATE Port SET iif_id = 9 WHERE type = 1084";
404 $query[] = "UPDATE Port SET iif_id = 1 WHERE iif_id = 0";
405 $query[] = 'ALTER TABLE Port ADD UNIQUE `object_iif_oif_name` (object_id, iif_id, type, name)';
406 $query[] = 'ALTER TABLE Port DROP KEY `per_object`';
407 $base1000 = array (24, 34, 1202, 1203, 1204, 1205, 1206, 1207);
408 $base10000 = array (30, 35, 36, 37, 38, 39, 40);
409 $PICdata = array
410 (
411 1 => array (16, 19, 24, 29, 31, 33, 446, 681, 682, 1322),
412 2 => array (1208, 1195, 1196, 1197, 1198, 1199, 1200, 1201),
413 3 => array_merge (array (1078), $base1000),
414 4 => array_merge (array (1077), $base1000),
415 5 => array_merge (array (1079), $base10000),
416 6 => array_merge (array (1080), $base10000),
417 7 => array_merge (array (1081), $base10000),
418 8 => array_merge (array (1082), $base10000),
419 9 => array_merge (array (1084), $base10000),
420 );
421 // make sure all IIF/OIF pairs referenced from Port exist in PortInterfaceCompat before enabling FK
422 // iif_id doesn't exist at this point
423 $result = $dbxlink->query ('SELECT DISTINCT type FROM Port WHERE type NOT IN (1208, 1078, 1077, 1079, 1080, 1081, 1082, 1084)');
424 while ($row = $result->fetch (PDO::FETCH_ASSOC))
425 if (FALSE === array_search ($row['type'], $PICdata[1]))
426 array_push ($PICdata[1], $row['type']);
427 unset ($result);
428 foreach ($PICdata as $iif_id => $oif_ids)
429 foreach ($oif_ids as $oif_id)
430 $query[] = "INSERT INTO PortInterfaceCompat (iif_id, oif_id) VALUES (${iif_id}, ${oif_id})";
431 $query[] = "ALTER TABLE Port ADD CONSTRAINT `Port-FK-iif-oif` FOREIGN KEY (`iif_id`, `type`) REFERENCES `PortInterfaceCompat` (`iif_id`, `oif_id`)";
432 $query[] = 'UPDATE Port SET type = 1322 WHERE type = 16 AND (SELECT objtype_id FROM RackObject WHERE id = object_id) IN (2, 12)';
433 $query = array_merge ($query, reloadDictionary ($batchid));
434 $query[] = "DELETE FROM Config WHERE varname = 'default_port_type'";
435 $query[] = "INSERT INTO Config VALUES ('DEFAULT_PORT_IIF_ID','1','uint','no','no','Default port inner interface ID')";
436 $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')";
437 $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')";
438 $query[] = "UPDATE Chapter SET name = 'PortOuterInterface' WHERE id = 2";
439 // remap refs to duplicate records, which will be discarded (ticket:286)
440 $query[] = 'UPDATE AttributeValue SET uint_value = 147 WHERE uint_value = 1020 AND attr_id = 2';
441 $query[] = 'UPDATE AttributeValue SET uint_value = 377 WHERE uint_value = 1021 AND attr_id = 2';
442 $query[] = 'INSERT INTO AttributeMap (objtype_id, attr_id) VALUES (2, 1), (2, 3), (2, 5)';
443 $query[] = "UPDATE Config SET varvalue = '0.17.5' WHERE varname = 'DB_VERSION'";
444 break;
445 case '0.17.6':
446 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (28,'no','Voice/video hardware')";
447 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1323,1,NULL)";
448 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1323,2,28)";
449 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1323,3,NULL)";
450 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1323,5,NULL)";
451 $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)')";
452 $query = array_merge ($query, reloadDictionary ($batchid));
453 $query[] = "UPDATE Config SET varvalue = '0.17.6' WHERE varname = 'DB_VERSION'";
454 break;
455 case '0.17.7':
456 $query[] = "UPDATE Config SET varvalue = '0.17.7' WHERE varname = 'DB_VERSION'";
457 break;
458 case '0.17.8':
459 $query = array_merge ($query, reloadDictionary ($batchid));
460 $query[] = "ALTER TABLE TagTree DROP COLUMN valid_realm";
461 $query[] = "UPDATE Config SET varvalue = '0.17.8' WHERE varname = 'DB_VERSION'";
462 break;
463 case '0.17.9':
464 $query[] = "ALTER table Config add `is_userdefined` enum('yes','no') NOT NULL default 'no' AFTER `is_hidden`";
465 $query[] = "
466 CREATE TABLE `UserConfig` (
467 `varname` char(32) NOT NULL,
468 `varvalue` char(255) NOT NULL,
469 `user` char(64) NOT NULL,
470 UNIQUE KEY `user_varname` (`user`,`varname`)
471 ) TYPE=InnoDB";
472 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname IN
473 (
474 'MASSCOUNT',
475 'MAXSELSIZE',
476 'ROW_SCALE',
477 'PORTS_PER_ROW',
478 'IPV4_ADDRS_PER_PAGE',
479 'DEFAULT_RACK_HEIGHT',
480 'DEFAULT_SLB_VS_PORT',
481 'DEFAULT_SLB_RS_PORT',
482 'DETECT_URLS',
483 'RACK_PRESELECT_THRESHOLD',
484 'DEFAULT_IPV4_RS_INSERVICE',
485 'DEFAULT_OBJECT_TYPE',
486 'SHOW_EXPLICIT_TAGS',
487 'SHOW_IMPLICIT_TAGS',
488 'SHOW_AUTOMATIC_TAGS',
489 'IPV4_AUTO_RELEASE',
490 'SHOW_LAST_TAB',
491 'EXT_IPV4_VIEW',
492 'TREE_THRESHOLD',
493 'ADDNEW_AT_TOP',
494 'IPV4_TREE_SHOW_USAGE',
495 'PREVIEW_TEXT_MAXCHARS',
496 'PREVIEW_TEXT_ROWS',
497 'PREVIEW_TEXT_COLS',
498 'PREVIEW_IMAGE_MAXPXS',
499 'VENDOR_SIEVE',
500 'RACKS_PER_ROW'
501 )";
502 $query[] = "UPDATE Config SET varvalue = '0.17.9' WHERE varname = 'DB_VERSION'";
503 break;
504 case '0.17.10':
505 $query = array_merge ($query, reloadDictionary ($batchid));
506 $query[] = "ALTER TABLE MountOperation ADD KEY (object_id)";
507 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('STATIC_FILTER','yes','string','no','no','yes','Enable Filter Caching');";
508 $query[] = "UPDATE Config SET varvalue = '0.17.10' WHERE varname = 'DB_VERSION'";
509 break;
510 case '0.17.11':
511 $query = array_merge ($query, reloadDictionary ($batchid));
512 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('ENABLE_BULKPORT_FORM','yes','string','no','no','yes','Enable \"Bulk Port\" form');";
513 $query[] = "DELETE AttributeValue FROM AttributeValue JOIN Attribute where AttributeValue.attr_id = Attribute.id AND Attribute.type = 'dict' AND AttributeValue.uint_value = 0";
514 $query[] = "UPDATE Config SET varvalue = '0.17.11' WHERE varname = 'DB_VERSION'";
515 break;
516 case '0.18.0':
517 $query = array_merge ($query, reloadDictionary ($batchid));
518 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('VLANSWITCH_LISTSRC', '', 'string', 'yes', 'no', 'yes', 'List of VLAN running switches')";
519 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('VLANIPV4NET_LISTSRC', '', 'string', 'yes', 'no', 'yes', 'List of VLAN-based IPv4 networks')";
520 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('DEFAULT_VDOM_ID','','uint','yes','no','yes','Default VLAN domain ID')";
521 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('DEFAULT_VST_ID','','uint','yes','no','yes','Default VLAN switch template ID')";
522 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('8021Q_DEPLOY_MINAGE','300','uint','no','no','no','802.1Q deploy minimum age')";
523 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('8021Q_DEPLOY_MAXAGE','3600','uint','no','no','no','802.1Q deploy maximum age')";
524 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('8021Q_DEPLOY_RETRY','10800','uint','no','no','no','802.1Q deploy retry timer')";
525 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('8021Q_WRI_AFTER_CONFT','no','string','no','no','no','802.1Q: save device configuration after deploy')";
526 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('8021Q_INSTANT_DEPLOY','no','string','no','no','yes','802.1Q: instant deploy')";
527 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('IPV4_TREE_SHOW_VLAN','yes','string','no','no','yes','Show VLAN for each network in IPv4 tree')";
528 $query[] = "ALTER TABLE IPv4Network ENGINE=InnoDB";
529 $query[] = "SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0";
530 $query[] = "
531 CREATE TABLE `CachedPAV` (
532 `object_id` int(10) unsigned NOT NULL,
533 `port_name` char(255) NOT NULL,
534 `vlan_id` int(10) unsigned NOT NULL default '0',
535 PRIMARY KEY (`object_id`,`port_name`,`vlan_id`),
536 KEY `vlan_id` (`vlan_id`),
537 CONSTRAINT `CachedPAV-FK-object-port` FOREIGN KEY (`object_id`, `port_name`) REFERENCES `CachedPVM` (`object_id`, `port_name`) ON DELETE CASCADE,
538 CONSTRAINT `CachedPAV-FK-vlan_id` FOREIGN KEY (`vlan_id`) REFERENCES `VLANValidID` (`vlan_id`)
539 ) ENGINE=InnoDB
540 ";
541 $query[] = "
542 CREATE TABLE `CachedPNV` (
543 `object_id` int(10) unsigned NOT NULL,
544 `port_name` char(255) NOT NULL,
545 `vlan_id` int(10) unsigned NOT NULL default '0',
546 PRIMARY KEY (`object_id`,`port_name`,`vlan_id`),
547 UNIQUE KEY `port_id` (`object_id`,`port_name`),
548 CONSTRAINT `CachedPNV-FK-compound` FOREIGN KEY (`object_id`, `port_name`, `vlan_id`) REFERENCES `CachedPAV` (`object_id`, `port_name`, `vlan_id`) ON DELETE CASCADE
549 ) ENGINE=InnoDB
550 ";
551 $query[] = "
552 CREATE TABLE `CachedPVM` (
553 `object_id` int(10) unsigned NOT NULL,
554 `port_name` char(255) NOT NULL,
555 `vlan_mode` enum('access','trunk') NOT NULL default 'access',
556 PRIMARY KEY (`object_id`,`port_name`),
557 CONSTRAINT `CachedPVM-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `RackObject` (`id`) ON DELETE CASCADE
558 ) ENGINE=InnoDB
559 ";
560 $query[] = "
561 CREATE TABLE `PortAllowedVLAN` (
562 `object_id` int(10) unsigned NOT NULL,
563 `port_name` char(255) NOT NULL,
564 `vlan_id` int(10) unsigned NOT NULL default '0',
565 PRIMARY KEY (`object_id`,`port_name`,`vlan_id`),
566 KEY `vlan_id` (`vlan_id`),
567 CONSTRAINT `PortAllowedVLAN-FK-object-port` FOREIGN KEY (`object_id`, `port_name`) REFERENCES `PortVLANMode` (`object_id`, `port_name`) ON DELETE CASCADE,
568 CONSTRAINT `PortAllowedVLAN-FK-vlan_id` FOREIGN KEY (`vlan_id`) REFERENCES `VLANValidID` (`vlan_id`)
569 ) ENGINE=InnoDB
570 ";
571 $query[] = "
572 CREATE TABLE `PortNativeVLAN` (
573 `object_id` int(10) unsigned NOT NULL,
574 `port_name` char(255) NOT NULL,
575 `vlan_id` int(10) unsigned NOT NULL default '0',
576 PRIMARY KEY (`object_id`,`port_name`,`vlan_id`),
577 UNIQUE KEY `port_id` (`object_id`,`port_name`),
578 CONSTRAINT `PortNativeVLAN-FK-compound` FOREIGN KEY (`object_id`, `port_name`, `vlan_id`) REFERENCES `PortAllowedVLAN` (`object_id`, `port_name`, `vlan_id`) ON DELETE CASCADE
579 ) ENGINE=InnoDB
580 ";
581 $query[] = "
582 CREATE TABLE `PortVLANMode` (
583 `object_id` int(10) unsigned NOT NULL,
584 `port_name` char(255) NOT NULL,
585 `vlan_mode` enum('access','trunk') NOT NULL default 'access',
586 PRIMARY KEY (`object_id`,`port_name`),
587 CONSTRAINT `PortVLANMode-FK-object-port` FOREIGN KEY (`object_id`, `port_name`) REFERENCES `CachedPVM` (`object_id`, `port_name`)
588 ) ENGINE=InnoDB
589 ";
590 $query[] = "
591 CREATE TABLE `VLANDescription` (
592 `domain_id` int(10) unsigned NOT NULL,
593 `vlan_id` int(10) unsigned NOT NULL default '0',
594 `vlan_type` enum('ondemand','compulsory','alien') NOT NULL default 'ondemand',
595 `vlan_descr` char(255) default NULL,
596 PRIMARY KEY (`domain_id`,`vlan_id`),
597 KEY `vlan_id` (`vlan_id`),
598 CONSTRAINT `VLANDescription-FK-domain_id` FOREIGN KEY (`domain_id`) REFERENCES `VLANDomain` (`id`) ON DELETE CASCADE,
599 CONSTRAINT `VLANDescription-FK-vlan_id` FOREIGN KEY (`vlan_id`) REFERENCES `VLANValidID` (`vlan_id`)
600 ) ENGINE=InnoDB
601 ";
602 $query[] = "
603 CREATE TABLE `VLANDomain` (
604 `id` int(10) unsigned NOT NULL auto_increment,
605 `description` char(255) default NULL,
606 PRIMARY KEY (`id`),
607 UNIQUE KEY `description` (`description`)
608 ) ENGINE=InnoDB
609 ";
610 $query[] = "
611 CREATE TABLE `VLANIPv4` (
612 `domain_id` int(10) unsigned NOT NULL,
613 `vlan_id` int(10) unsigned NOT NULL,
614 `ipv4net_id` int(10) unsigned NOT NULL,
615 UNIQUE KEY `network-domain` (`ipv4net_id`,`domain_id`),
616 KEY `VLANIPv4-FK-compound` (`domain_id`,`vlan_id`),
617 CONSTRAINT `VLANIPv4-FK-compound` FOREIGN KEY (`domain_id`, `vlan_id`) REFERENCES `VLANDescription` (`domain_id`, `vlan_id`) ON DELETE CASCADE,
618 CONSTRAINT `VLANIPv4-FK-ipv4net_id` FOREIGN KEY (`ipv4net_id`) REFERENCES `IPv4Network` (`id`) ON DELETE CASCADE
619 ) ENGINE=InnoDB
620 ";
621 $query[] = "
622 CREATE TABLE `VLANSTRule` (
623 `vst_id` int(10) unsigned NOT NULL,
624 `rule_no` int(10) unsigned NOT NULL,
625 `port_pcre` char(255) NOT NULL,
626 `port_role` enum('access','trunk','uplink','downlink','none') NOT NULL default 'none',
627 `wrt_vlans` char(255) default NULL,
628 `description` char(255) default NULL,
629 UNIQUE KEY `vst-rule` (`vst_id`,`rule_no`),
630 CONSTRAINT `VLANSTRule-FK-vst_id` FOREIGN KEY (`vst_id`) REFERENCES `VLANSwitchTemplate` (`id`) ON DELETE CASCADE
631 ) ENGINE=InnoDB
632 ";
633 $query[] = "
634 CREATE TABLE `VLANSwitch` (
635 `object_id` int(10) unsigned NOT NULL,
636 `domain_id` int(10) unsigned NOT NULL,
637 `template_id` int(10) unsigned NOT NULL,
638 `mutex_rev` int(10) unsigned NOT NULL default '0',
639 `out_of_sync` enum('yes','no') NOT NULL default 'yes',
640 `last_errno` int(10) unsigned NOT NULL default '0',
641 `last_change` timestamp NOT NULL default '0000-00-00 00:00:00',
642 `last_push_started` timestamp NOT NULL default '0000-00-00 00:00:00',
643 `last_push_finished` timestamp NOT NULL default '0000-00-00 00:00:00',
644 `last_error_ts` timestamp NOT NULL default '0000-00-00 00:00:00',
645 UNIQUE KEY `object_id` (`object_id`),
646 KEY `domain_id` (`domain_id`),
647 KEY `template_id` (`template_id`),
648 KEY `out_of_sync` (`out_of_sync`),
649 KEY `last_errno` (`last_errno`),
650 CONSTRAINT `VLANSwitch-FK-domain_id` FOREIGN KEY (`domain_id`) REFERENCES `VLANDomain` (`id`),
651 CONSTRAINT `VLANSwitch-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `RackObject` (`id`),
652 CONSTRAINT `VLANSwitch-FK-template_id` FOREIGN KEY (`template_id`) REFERENCES `VLANSwitchTemplate` (`id`)
653 ) ENGINE=InnoDB
654 ";
655 $query[] = "
656 CREATE TABLE `VLANSwitchTemplate` (
657 `id` int(10) unsigned NOT NULL auto_increment,
658 `max_local_vlans` int(10) unsigned default NULL,
659 `description` char(255) default NULL,
660 PRIMARY KEY (`id`),
661 UNIQUE KEY `description` (`description`)
662 ) ENGINE=InnoDB
663 ";
664 $query[] = "
665 CREATE TABLE `VLANValidID` (
666 `vlan_id` int(10) unsigned NOT NULL default '1',
667 PRIMARY KEY (`vlan_id`)
668 ) ENGINE=InnoDB
669 ";
670 $query[] = "SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS";
671 for ($i = 1; $i <= 4094; $i++)
672 $query[] = "INSERT INTO VLANValidID (vlan_id) VALUES (${i})";
673 $query[] = "UPDATE Config SET varvalue = '0.18.0' WHERE varname = 'DB_VERSION'";
674 break;
675 case '0.18.1':
676 $query = array_merge ($query, reloadDictionary ($batchid));
677 $query[] = "ALTER TABLE Atom ENGINE=InnoDB";
678 $query[] = "ALTER TABLE AttributeMap ENGINE=InnoDB";
679 $query[] = "ALTER TABLE Config ENGINE=InnoDB";
680 $query[] = "ALTER TABLE IPv4Address ENGINE=InnoDB";
681 $query[] = "ALTER TABLE IPv4Allocation ENGINE=InnoDB";
682 $query[] = "ALTER TABLE Molecule ENGINE=InnoDB";
683 $query[] = "ALTER TABLE MountOperation ENGINE=InnoDB";
684 $query[] = "ALTER TABLE PortCompat ENGINE=InnoDB";
685 $query[] = "ALTER TABLE Rack ENGINE=InnoDB";
686 $query[] = "ALTER TABLE RackHistory ENGINE=InnoDB";
687 $query[] = "ALTER TABLE RackObjectHistory ENGINE=InnoDB";
688 $query[] = "ALTER TABLE RackRow ENGINE=InnoDB";
689 $query[] = "ALTER TABLE RackSpace ENGINE=InnoDB";
690 $query[] = "ALTER TABLE Script ENGINE=InnoDB";
691 $query[] = "ALTER TABLE AttributeValue DROP FOREIGN KEY `AttributeValue-FK-object_id`";
692 $query[] = "ALTER TABLE AttributeValue ADD CONSTRAINT `AttributeValue-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `RackObject` (`id`) ON DELETE CASCADE";
693 $query[] = "ALTER TABLE RackObjectHistory ADD KEY (id)";
694 $query[] = "ALTER TABLE RackObjectHistory ADD CONSTRAINT `RackObjectHistory-FK-object_id` FOREIGN KEY (id) REFERENCES `RackObject` (`id`) ON DELETE CASCADE";
695 $query[] = "ALTER TABLE MountOperation ADD CONSTRAINT `MountOperation-FK-object_id` FOREIGN KEY (object_id) REFERENCES RackObject (id) ON DELETE CASCADE";
696 $query[] = "ALTER TABLE RackSpace ADD CONSTRAINT `RackSpace-FK-object_id` FOREIGN KEY (object_id) REFERENCES RackObject (id) ON DELETE CASCADE";
697 $query[] = "ALTER TABLE Link DROP FOREIGN KEY `Link-FK-a`";
698 $query[] = "ALTER TABLE Link ADD CONSTRAINT `Link-FK-a` FOREIGN KEY (`porta`) REFERENCES `Port` (`id`) ON DELETE CASCADE";
699 $query[] = "ALTER TABLE Link DROP FOREIGN KEY `Link-FK-b`";
700 $query[] = "ALTER TABLE Link ADD CONSTRAINT `Link-FK-b` FOREIGN KEY (`portb`) REFERENCES `Port` (`id`) ON DELETE CASCADE";
701 $query[] = "ALTER TABLE Port DROP FOREIGN KEY `Port-FK-object_id`";
702 $query[] = "ALTER TABLE Port ADD CONSTRAINT `Port-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `RackObject` (`id`) ON DELETE CASCADE";
703 $query[] = "ALTER TABLE AttributeMap MODIFY `chapter_id` int(10) unsigned default NULL";
704 $query[] = "ALTER TABLE IPv4Address MODIFY `ip` int(10) unsigned NOT NULL default '0'";
705 $query[] = "ALTER TABLE IPv4Address MODIFY `name` char(255) NOT NULL default ''";
706 $query[] = "ALTER TABLE IPv4Allocation MODIFY `object_id` int(10) unsigned NOT NULL default '0'";
707 $query[] = "ALTER TABLE IPv4Allocation MODIFY `ip` int(10) unsigned NOT NULL default '0'";
708 $query[] = "ALTER TABLE IPv4Allocation MODIFY `name` char(255) NOT NULL default ''";
709 $query[] = "ALTER TABLE IPv4NAT MODIFY `object_id` int(10) unsigned NOT NULL default '0'";
710 $query[] = "ALTER TABLE IPv4NAT MODIFY `proto` enum('TCP','UDP') NOT NULL default 'TCP'";
711 $query[] = "ALTER TABLE IPv4NAT MODIFY `localip` int(10) unsigned NOT NULL default '0'";
712 $query[] = "ALTER TABLE IPv4NAT MODIFY `localport` smallint(5) unsigned NOT NULL default '0'";
713 $query[] = "ALTER TABLE IPv4NAT MODIFY `remoteip` int(10) unsigned NOT NULL default '0'";
714 $query[] = "ALTER TABLE IPv4NAT MODIFY `remoteport` smallint(5) unsigned NOT NULL default '0'";
715 $query[] = "ALTER TABLE IPv4Network MODIFY `ip` int(10) unsigned NOT NULL default '0'";
716 $query[] = "ALTER TABLE IPv4Network MODIFY `mask` int(10) unsigned NOT NULL default '0'";
717 $query[] = "ALTER TABLE Link MODIFY `porta` int(10) unsigned NOT NULL default '0'";
718 $query[] = "ALTER TABLE Link MODIFY `portb` int(10) unsigned NOT NULL default '0'";
719 $query[] = "ALTER TABLE MountOperation MODIFY `object_id` int(10) unsigned NOT NULL default '0'";
720 $query[] = "ALTER TABLE MountOperation MODIFY `ctime` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP";
721 $query[] = "ALTER TABLE Port MODIFY `object_id` int(10) unsigned NOT NULL default '0'";
722 $query[] = "ALTER TABLE Port MODIFY `name` char(255) NOT NULL default ''";
723 $query[] = "ALTER TABLE Port MODIFY `type` int(10) unsigned NOT NULL default '0'";
724 $query[] = "ALTER TABLE PortCompat MODIFY `type1` int(10) unsigned NOT NULL default '0'";
725 $query[] = "ALTER TABLE PortCompat MODIFY `type2` int(10) unsigned NOT NULL default '0'";
726 $query[] = "ALTER TABLE RackHistory MODIFY `ctime` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP";
727 $query[] = "ALTER TABLE RackObjectHistory MODIFY `ctime` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP";
728 $query[] = "ALTER TABLE TagStorage MODIFY `tag_id` int(10) unsigned NOT NULL default '0'";
729 $query[] = "ALTER TABLE UserAccount MODIFY `user_name` char(64) NOT NULL default ''";
730 $query[] = "UPDATE Config SET varvalue = '0.18.1' WHERE varname = 'DB_VERSION'";
731 break;
732 case '0.18.2':
733 $query = array_merge ($query, reloadDictionary ($batchid));
734 $query[] = "ALTER TABLE Rack ADD CONSTRAINT `Rack-FK-row_id` FOREIGN KEY (row_id) REFERENCES RackRow (id)";
735 $query[] = "ALTER TABLE RackRow ADD UNIQUE KEY `name` (name)";
736 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('CDP_RUNNERS_LISTSRC', '', 'string', 'yes', 'no', 'no', 'List of devices running CDP')";
737 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('LLDP_RUNNERS_LISTSRC', '', 'string', 'yes', 'no', 'no', 'List of devices running LLDP')";
738 $query[] = "UPDATE Config SET varvalue = '0.18.2' WHERE varname = 'DB_VERSION'";
739 break;
740 case '0.18.3':
741 $query = array_merge ($query, reloadDictionary ($batchid));
742 $query[] = "UPDATE Config SET varname='8021Q_WRI_AFTER_CONFT_LISTSRC', varvalue='false', description='802.1Q: save device configuration after deploy (RackCode)' WHERE varname='8021Q_WRI_AFTER_CONFT'";
743 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('HNDP_RUNNERS_LISTSRC', '', 'string', 'yes', 'no', 'no', 'List of devices running HNDP (RackCode)')";
744 $query[] = "UPDATE Config SET varvalue = '0.18.3' WHERE varname = 'DB_VERSION'";
745 break;
746 case '0.18.4':
747 $query = array_merge ($query, reloadDictionary ($batchid));
748 $query[] = "ALTER TABLE VLANSTRule MODIFY port_role enum('access','trunk','anymode','uplink','downlink','none') NOT NULL default 'none'";
749 $query[] = "UPDATE Config SET varvalue = '0.18.4' WHERE varname = 'DB_VERSION'";
750 break;
751 case '0.18.5':
752 $query = array_merge ($query, reloadDictionary ($batchid));
753 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('SHRINK_TAG_TREE_ON_CLICK','yes','string','no','no','yes','Dynamically hide useless tags in tagtree')";
754 $query[] = "ALTER TABLE `IPv4LB` ADD COLUMN `prio` int(10) unsigned DEFAULT NULL AFTER `vs_id`";
755 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('MAX_UNFILTERED_ENTITIES','0','uint','no','no','yes','Max item count to display on unfiltered result page')";
756 $query[] = "UPDATE Config SET varvalue = '0.18.5' WHERE varname = 'DB_VERSION'";
757 break;
758 case '0.19.0':
759 if (!isInnoDBSupported ())
760 {
761 showFailure ("Cannot upgrade because triggers are not supported by your MySQL server.", __FILE__);
762 die;
763 }
764
765 // search for invalid Links
766 $result = $dbxlink->query ("SELECT * FROM Link WHERE porta=portb OR porta IN (SELECT portb FROM Link) OR portb IN (SELECT porta FROM Link);");
767 $rows = $result->fetchAll (PDO::FETCH_ASSOC);
768 if (count($rows) > 0)
769 {
770 foreach ($rows as $row)
771 $invalid_msg .= sprintf("porta: %s, portb: %s\n", $row['porta'], $row['portb']);
772 showFailure("Cannot upgrade because one or more invalid port links exist:\n{$invalid_msg}", __FILE__);
773 die;
774 }
775
776 $query[] = 'ALTER TABLE `File` ADD `thumbnail` LONGBLOB NULL AFTER `atime`';
777 $query[] = "
778 CREATE TABLE `IPv6Address` (
779 `ip` binary(16) NOT NULL,
780 `name` char(255) NOT NULL default '',
781 `reserved` enum('yes','no') default NULL,
782 PRIMARY KEY (`ip`)
783 ) ENGINE=InnoDB
784 ";
785 $query[] = "
786 CREATE TABLE `IPv6Allocation` (
787 `object_id` int(10) unsigned NOT NULL default '0',
788 `ip` binary(16) NOT NULL,
789 `name` char(255) NOT NULL default '',
790 `type` enum('regular','shared','virtual','router') default NULL,
791 PRIMARY KEY (`object_id`,`ip`),
792 CONSTRAINT `IPv6Allocation-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `RackObject` (`id`) ON DELETE CASCADE
793 ) ENGINE=InnoDB
794 ";
795 $query[] = "
796 CREATE TABLE `IPv6Network` (
797 `id` int(10) unsigned NOT NULL auto_increment,
798 `ip` binary(16) NOT NULL,
799 `mask` int(10) unsigned NOT NULL,
800 `last_ip` binary(16) NOT NULL,
801 `name` char(255) default NULL,
802 `comment` text,
803 PRIMARY KEY (`id`),
804 UNIQUE KEY `ip` (`ip`,`mask`)
805 ) ENGINE=InnoDB
806 ";
807 $query[] = "
808 CREATE TABLE `VLANIPv6` (
809 `domain_id` int(10) unsigned NOT NULL,
810 `vlan_id` int(10) unsigned NOT NULL,
811 `ipv6net_id` int(10) unsigned NOT NULL,
812 UNIQUE KEY `network-domain` (`ipv6net_id`,`domain_id`),
813 KEY `VLANIPv6-FK-compound` (`domain_id`,`vlan_id`),
814 CONSTRAINT `VLANIPv6-FK-compound` FOREIGN KEY (`domain_id`, `vlan_id`) REFERENCES `VLANDescription` (`domain_id`, `vlan_id`) ON DELETE CASCADE,
815 CONSTRAINT `VLANIPv6-FK-ipv6net_id` FOREIGN KEY (`ipv6net_id`) REFERENCES `IPv6Network` (`id`) ON DELETE CASCADE
816 ) ENGINE=InnoDB
817 ";
818 $query[] = "
819 CREATE TABLE `ObjectLog` (
820 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
821 `object_id` int(10) unsigned NOT NULL,
822 `user` char(64) NOT NULL,
823 `date` datetime NOT NULL,
824 `content` text NOT NULL,
825 PRIMARY KEY (`id`),
826 KEY `object_id` (`object_id`),
827 KEY `date` (`date`),
828 CONSTRAINT `ObjectLog-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `RackObject` (`id`) ON DELETE CASCADE
829 ) ENGINE=InnoDB
830 ";
831 $query[] = "
832 CREATE TRIGGER `checkForDuplicateLinksBeforeInsert` BEFORE INSERT ON `Link`
833 FOR EACH ROW
834 BEGIN
835 DECLARE count INTEGER;
836
837 IF NEW.porta = NEW.portb THEN
838 SET NEW.porta = NULL;
839 END IF;
840
841 SELECT COUNT(*) INTO count FROM Link WHERE porta IN (NEW.porta,NEW.portb) OR portb IN (NEW.porta,NEW.portb);
842
843 IF count > 0 THEN
844 SET NEW.porta = NULL;
845 END IF;
846 END;
847 ";
848 $query[] = "
849 CREATE TRIGGER `checkForDuplicateLinksBeforeUpdate` BEFORE UPDATE ON `Link`
850 FOR EACH ROW
851 BEGIN
852 DECLARE count INTEGER;
853
854 IF NEW.porta = NEW.portb THEN
855 SET NEW.porta = NULL;
856 END IF;
857
858 SELECT COUNT(*) INTO count FROM Link WHERE
859 (NEW.porta IN (porta,portb) AND NEW.porta != porta) OR
860 (NEW.portb IN (porta,portb) AND NEW.portb != portb);
861
862 IF count > 0 THEN
863 SET NEW.porta = NULL;
864 END IF;
865 END;
866 ";
867 $query[] = "ALTER TABLE `TagStorage` CHANGE COLUMN `entity_realm` `entity_realm` ENUM('file','ipv4net','ipv4vs','ipv4rspool','object','rack','user','ipv6net') NOT NULL DEFAULT 'object' FIRST";
868 $query[] = "ALTER TABLE `FileLink` CHANGE COLUMN `entity_type` `entity_type` ENUM('ipv4net','ipv4rspool','ipv4vs','object','rack','user','ipv6net') NOT NULL DEFAULT 'object' AFTER `file_id`";
869 $query[] = 'ALTER TABLE Link ADD COLUMN cable char(64) NULL AFTER portb';
870 $query[] = 'ALTER TABLE RackSpace ADD CONSTRAINT `RackSpace-FK-rack_id` FOREIGN KEY (rack_id) REFERENCES Rack (id)';
871 $query[] = "ALTER TABLE `IPv4Allocation` ADD CONSTRAINT `IPv4Allocation-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `RackObject` (`id`) ON DELETE CASCADE";
872 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('SYNCDOMAIN_MAX_PROCESSES','0','uint','yes','no', 'How many worker proceses syncdomain cron script should create')";
873 $query[] = "ALTER TABLE `VLANSwitchTemplate` ADD COLUMN `mutex_rev` int(10) NOT NULL AFTER `max_local_vlans`";
874 $query[] = "ALTER TABLE `VLANSwitchTemplate` ADD COLUMN `saved_by` char(64) NOT NULL AFTER `description`";
875 $query[] = "UPDATE Config SET varvalue = '0.19.0' WHERE varname = 'DB_VERSION'";
876 break;
877 default:
878 showFailure ("executeUpgradeBatch () failed, because batch '${batchid}' isn't defined", __FILE__);
879 die;
880 break;
881 }
882 $failures = array();
883 echo "<tr><th>Executing batch '${batchid}'</th><td>";
884 foreach ($query as $q)
885 {
886 $result = $dbxlink->query ($q);
887 if ($result == NULL)
888 {
889 $errorInfo = $dbxlink->errorInfo();
890 $failures[] = array ($q, $errorInfo[2]);
891 }
892 }
893 if (!count ($failures))
894 echo "<strong><font color=green>done</font></strong>";
895 else
896 {
897 echo "<strong><font color=red>The following queries failed:</font></strong><br><pre>";
898 foreach ($failures as $f)
899 {
900 list ($q, $i) = $f;
901 echo "${q} -- ${i}\n";
902 }
903 echo "</pre>";
904 }
905 echo '</td></tr>';
906 }
907
908 // ******************************************************************
909 //
910 // Execution starts here
911 //
912 // ******************************************************************
913
914 // a clone of showError() to drop dependency on interface.php
915 function showFailure ($info = '', $location = 'N/A')
916 {
917 if (preg_match ('/\.php$/', $location))
918 $location = basename ($location);
919 elseif ($location != 'N/A')
920 $location = $location . '()';
921 echo "<div class=msg_error>An error has occured in [${location}]. ";
922 if (empty ($info))
923 echo 'No additional information is available.';
924 else
925 echo "Additional information:<br><p>\n<pre>\n${info}\n</pre></p>";
926 echo "This failure is most probably fatal.<br></div>\n";
927 }
928
929 require_once 'inc/config.php'; // for CODE_VERSION
930 require_once 'inc/database.php'; // for getDatabaseVersion()
931 require_once 'inc/dictionary.php';
932 // Enforce default value for now, releases prior to 0.17.0 didn't support 'httpd' auth source.
933 $user_auth_src = 'database';
934
935 if (file_exists ('inc/secret.php'))
936 require_once 'inc/secret.php';
937 else
938 die ('<center>There is no working RackTables instance here, <a href="install.php">install</a>?</center>');
939
940 try
941 {
942 $dbxlink = new PDO ($pdo_dsn, $db_username, $db_password);
943 }
944 catch (PDOException $e)
945 {
946 die ("Database connection failed:\n\n" . $e->getMessage());
947 }
948
949 // Now we need to be sure that the current user is the administrator.
950 // The rest doesn't matter within this context.
951
952 function authenticate_admin ($username, $password)
953 {
954 global $dbxlink;
955 $prepared = $dbxlink->prepare ('SELECT COUNT(*) FROM UserAccount WHERE user_id=1 AND user_name=? AND user_password_hash=?');
956 if (!$prepared->execute (array ($username, sha1 ($password))))
957 die ('SQL query failed in ' . __FUNCTION__);
958 $rows = $prepared->fetchAll (PDO::FETCH_NUM);
959 return $rows[0][0] == 1;
960 }
961
962 switch ($user_auth_src)
963 {
964 case 'database':
965 case 'ldap': // authenticate against DB as well
966 if
967 (
968 !isset ($_SERVER['PHP_AUTH_USER']) or
969 !strlen ($_SERVER['PHP_AUTH_USER']) or
970 !isset ($_SERVER['PHP_AUTH_PW']) or
971 !strlen ($_SERVER['PHP_AUTH_PW']) or
972 !authenticate_admin ($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])
973 )
974 {
975 header ('WWW-Authenticate: Basic realm="RackTables upgrade"');
976 header ('HTTP/1.0 401 Unauthorized');
977 showFailure ('You must be authenticated as an administrator to complete the upgrade.', __FILE__);
978 die;
979 }
980 break; // cleared
981 case 'httpd':
982 if
983 (
984 !isset ($_SERVER['REMOTE_USER']) or
985 !strlen ($_SERVER['REMOTE_USER'])
986 )
987 {
988 showFailure ('System misconfiguration. The web-server didn\'t authenticate the user, although ought to do.');
989 die;
990 }
991 break; // cleared
992 default:
993 showFailure ('authentication source misconfiguration', __FILE__);
994 die;
995 }
996
997 ?>
998 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
999 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
1000 <head><title>RackTables upgrade script</title>
1001 <link rel=stylesheet type='text/css' href='pi.css' />
1002 </head>
1003 <body>
1004 <h1>Platform check status</h1>
1005 <?php
1006
1007 if (!platform_is_ok())
1008 die ('</body></html>');
1009
1010 echo '<h1>Upgrade status</h1>';
1011 $dbver = getDatabaseVersion();
1012 echo '<table border=1 cellpadding=5>';
1013 echo "<tr><th>Current status</th><td>Data version: ${dbver}<br>Code version: " . CODE_VERSION . "</td></tr>\n";
1014
1015 $path = getDBUpgradePath ($dbver, CODE_VERSION);
1016 if ($path === NULL)
1017 {
1018 echo "<tr><th>Upgrade path</th><td><font color=red>not found</font></td></tr>\n";
1019 echo "<tr><th>Summary</th><td>Check README for more information. RackTables releases prior to 0.16.4 ";
1020 echo "must be upgraded to 0.16.4 first.</td></tr>\n";
1021 }
1022 else
1023 {
1024 if (!count ($path))
1025 echo "<tr><th>Summary</th><td>Come back later.</td></tr>\n";
1026 else
1027 {
1028 echo "<tr><th>Upgrade path</th><td>${dbver} &rarr; " . implode (' &rarr; ', $path) . "</td></tr>\n";
1029 foreach ($path as $batchid)
1030 {
1031 executeUpgradeBatch ($batchid);
1032 if (isset ($relnotes[$batchid]))
1033 echo "<tr><th>Release notes for ${batchid}</th><td><pre>" . $relnotes[$batchid] . "</pre></td></tr>\n";
1034 }
1035 echo "<tr><th>Summary</th><td>Upgrade complete, it is Ok to <a href='index.php'>enter</a> the system.</td></tr>\n";
1036 }
1037 }
1038 echo '</table>';
1039 echo '</body></html>';
1040
1041 ?>