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