r5036 weed broken links out from the dictionary
[racktables] / wwwroot / inc / upgrade.php
CommitLineData
6dc745d2 1<?php
fbbb74fb 2
cddbb9fd
DO
3# This file is a part of RackTables, a datacenter and server room management
4# framework. See accompanying file "COPYING" for the full copyright and
5# licensing information.
6
90b96ff6
DO
7$relnotes = array
8(
5ae6d365
DO
9 '0.17.0' => <<<ENDOFTEXT
10LDAP options have been moved to LDAP_options array. This means, that if you were
11using LDAP authentication for users in version 0.16.x, it will break right after
12upgrade to 0.17.0. To get things working again, adjust existing secret.php file
13according to secret-sample.php file provided with 0.17.0 release.
14
15This release is the first to take advantage of the foreign key support
16provided by the InnoDB storage engine in MySQL. The installer and
17upgrader scripts check for InnoDB support and cannot complete without it.
18If you have trouble, the first step is to make sure the 'skip-innodb'
19option in my.cnf is commented out.
20
21Another change is the addition of support for file uploads. Files are stored
22in the database. There are several settings in php.ini which you may need to modify:
23 file_uploads - needs to be On
24 upload_max_filesize - max size for uploaded files
25 post_max_size - max size of all form data submitted via POST (including files)
26
27User accounts used to have 'enabled' flag, which allowed individual blocking and
28unblocking of each. This flag was dropped in favor of existing mean of access
29setup (RackCode). An unconditional denying rule is automatically added into RackCode
30for such blocked account, so the effective security policy remains the same.
31ENDOFTEXT
32,
1679ddbd
DO
33 '0.18.2' => <<<ENDOFTEXT
34RackTables from its version 0.18.0 and later is not compatible with
35RHEL/CentOS (at least with versions up to 5.5) Linux distributions
36in their default installation. There are yet options to work around that:
371. Install RackTables on a server with a different distribution/OS.
382. Request Linux distribution vendor to fix the bug with PCRE.
393. Repair your RHEL/CentOS installation yourself by fixing its PCRE
40RPM as explained here: http://bugs.centos.org/view.php?id=3252
41ENDOFTEXT
9fb6900d
DO
42,
43 '0.19.0' => <<<ENDOFTEXT
841a5b54
DO
44The files, which are intended for the httpd (web-server) directory, are
45now in the "wwwroot" directory of the tar.gz archive. Files outside of
46that directory are not directly intended for httpd environment and should
47not be copied to the server.
9fb6900d 48
8489d2af
DO
49This release incorporates ObjectLog functionality, which used to be
50available as a separate plugin. For the best results it is advised to
51disable (through local.php) external ObjectLog plugin permanently before
52the new version is installed. All previously accumulated ObjectLog records
53will be available through the updated standard interface.
54
841a5b54
DO
55RackTables is now using PHP JSON extension which is included in the PHP
56core since 5.2.0.
57
58The barcode attribute was removed. The upgrade script attempts to
59preserve the data by moving it to either the 'OEM S/N 1' attribute or to
60a Log entry. You should backup your database beforehand anyway.
9fb6900d 61ENDOFTEXT
36efe434
DO
62,
63 '0.19.2' => <<<ENDOFTEXT
64This release is different in filesystem layout. The "gateways" directory
4f5aea8a
AA
65has been moved from "wwwroot" directory. This improves security a bit.
66You can also separate your local settings and add-ons from the core RackTables code.
67To do that, put a single index.php file into the DocumentRoot of your http server:
36efe434 68
4f5aea8a
AA
69<?php
70\$racktables_confdir='/directory/where/your/secret.php/and/local.php/files/are/stored';
71require '/directory_where_you_extracted_racktables_distro/wwwroot/index.php';
72?>
73
74No more files are needed to be available directly over the HTTP.
75Full list of filesystem paths which could be specified in custom index.php or secret.php:
76 \$racktables_gwdir: path to the gateways directory;
77 \$racktables_staticdir: path to the directory containing 'pix', 'js', 'css' dirs;
78 \$racktables_confdir: path where secret.php and local.php are located. It is not
79 recommended to define it in secret.php, cause only the path to
80 local.php will be affected;
81 \$path_to_secret_php: Ignore \$racktables_confdir when locating secret.php and use
82 the specified path;
83 \$path_to_local_php: idem for local.php.
36efe434 84ENDOFTEXT
5ae6d365 85,
90b96ff6
DO
86);
87
fbbb74fb
DO
88// At the moment we assume, that for any two releases we can
89// sequentally execute all batches, that separate them, and
90// nothing will break. If this changes one day, the function
91// below will have to generate smarter upgrade paths, while
92// the upper layer will remain the same.
93// Returning an empty array means that no upgrade is necessary.
4114697d 94// Returning NULL indicates an error.
fbbb74fb
DO
95function getDBUpgradePath ($v1, $v2)
96{
a6f83a72
DO
97 $versionhistory = array
98 (
b3f866fc 99 '0.16.4',
64347dcf 100 '0.16.5',
90b96ff6 101 '0.16.6',
30d0a2a3 102 '0.17.0',
4563cecb 103 '0.17.1',
7b1a3a72 104 '0.17.2',
9e51318b 105 '0.17.3',
958ac06d 106 '0.17.4',
9f572fb5 107 '0.17.5',
63811a09 108 '0.17.6',
026a79ee 109 '0.17.7',
3540d15c 110 '0.17.8',
1e81ad97 111 '0.17.9',
f32167d2 112 '0.17.10',
4a4a5440 113 '0.17.11',
9013f05b 114 '0.18.0',
425fd829 115 '0.18.1',
298d2375 116 '0.18.2',
f6d1a7cc 117 '0.18.3',
1c5b7c84 118 '0.18.4',
92ee2b01 119 '0.18.5',
2f5e4db9 120 '0.18.6',
9fb6900d 121 '0.18.7',
16825cc8 122 '0.19.0',
1d5dd3a1 123 '0.19.1',
0abae5fb 124 '0.19.2',
03d86c03 125 '0.19.3',
1f02e311 126 '0.19.4',
2a3a1a6d
AA
127 '0.19.5',
128 '0.19.6',
86eaaa67 129 '0.19.7',
f7494e3c 130 '0.19.8',
5c0bd7de 131 '0.19.9',
f7494e3c 132 '0.19.10',
ea24fb69 133 '0.19.11',
28537080 134 '0.19.12',
f7494e3c 135 '0.20.0',
a6f83a72 136 );
120e9ddd
DO
137 if (!in_array ($v1, $versionhistory) or !in_array ($v2, $versionhistory))
138 return NULL;
fbbb74fb 139 $skip = TRUE;
4114697d 140 $path = NULL;
154a42e5
DO
141 // foreach() below cannot handle this specific case
142 if ($v1 == $v2)
143 return array();
fbbb74fb
DO
144 // Now collect all versions > $v1 and <= $v2
145 foreach ($versionhistory as $v)
146 {
4114697d 147 if ($skip and $v == $v1)
fbbb74fb
DO
148 {
149 $skip = FALSE;
4114697d 150 $path = array();
fbbb74fb
DO
151 continue;
152 }
153 if ($skip)
154 continue;
155 $path[] = $v;
156 if ($v == $v2)
157 break;
158 }
159 return $path;
160}
161
90b96ff6
DO
162// Upgrade batches are named exactly as the release where they first appear.
163// That is simple, but seems sufficient for beginning.
fbbb74fb
DO
164function executeUpgradeBatch ($batchid)
165{
166 $query = array();
ca3d68bd 167 global $dbxlink;
fbbb74fb
DO
168 switch ($batchid)
169 {
64347dcf
DO
170 case '0.16.5':
171 $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')";
172 $query[] = "update Config set varvalue = '0.16.5' where varname = 'DB_VERSION'";
173 break;
90b96ff6
DO
174 case '0.16.6':
175 $query[] = "update Config set varvalue = '0.16.6' where varname = 'DB_VERSION'";
176 break;
30d0a2a3 177 case '0.17.0':
e1ae3fb4
AD
178 // create tables for storing files (requires InnoDB support)
179 if (!isInnoDBSupported ())
180 {
964b0388 181 showError ("Cannot upgrade because InnoDB tables are not supported by your MySQL server. See the README for details.", __FUNCTION__);
f3c50166 182 die;
e1ae3fb4 183 }
f76c4197
DY
184
185 $query[] = "alter table Chapter change chapter_no id int(10) unsigned NOT NULL auto_increment";
186 $query[] = "alter table Chapter change chapter_name name char(128) NOT NULL";
187 $query[] = "alter table Chapter drop key chapter_name";
188 $query[] = "alter table Chapter add UNIQUE KEY name (name)";
189 $query[] = "alter table Attribute change attr_id id int(10) unsigned NOT NULL auto_increment";
190 $query[] = "alter table Attribute change attr_type type enum('string','uint','float','dict') default NULL";
191 $query[] = "alter table Attribute change attr_name name char(64) default NULL";
192 $query[] = "alter table Attribute drop key attr_name";
193 $query[] = "alter table Attribute add UNIQUE KEY name (name)";
194 $query[] = "alter table AttributeMap change chapter_no chapter_id int(10) unsigned NOT NULL";
195 $query[] = "alter table Dictionary change chapter_no chapter_id int(10) unsigned NOT NULL";
f3c50166 196 // schema changes for file management
e1ae3fb4
AD
197 $query[] = "
198CREATE TABLE `File` (
199 `id` int(10) unsigned NOT NULL auto_increment,
200 `name` char(255) NOT NULL,
201 `type` char(255) NOT NULL,
202 `size` int(10) unsigned NOT NULL,
203 `ctime` datetime NOT NULL,
204 `mtime` datetime NOT NULL,
205 `atime` datetime NOT NULL,
206 `contents` longblob NOT NULL,
207 `comment` text,
13edfa1c
AD
208 PRIMARY KEY (`id`),
209 UNIQUE KEY `name` (`name`)
e1ae3fb4
AD
210) ENGINE=InnoDB";
211 $query[] = "
212CREATE TABLE `FileLink` (
213 `id` int(10) unsigned NOT NULL auto_increment,
214 `file_id` int(10) unsigned NOT NULL,
215 `entity_type` enum('ipv4net','ipv4rspool','ipv4vs','object','rack','user') NOT NULL default 'object',
216 `entity_id` int(10) NOT NULL,
217 PRIMARY KEY (`id`),
af721881 218 UNIQUE KEY `FileLink-unique` (`file_id`,`entity_type`,`entity_id`),
e1ae3fb4
AD
219 KEY `FileLink-file_id` (`file_id`),
220 CONSTRAINT `FileLink-File_fkey` FOREIGN KEY (`file_id`) REFERENCES `File` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
221) ENGINE=InnoDB";
222 $query[] = "ALTER TABLE TagStorage MODIFY COLUMN target_realm enum('file','ipv4net','ipv4rspool','ipv4vs','object','rack','user') NOT NULL default 'object'";
f3c50166 223
f76c4197 224 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (24,'no','network security models')";
9730d09f 225 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (25,'no','wireless models')";
f76c4197
DY
226 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,1,0)";
227 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,2,24)";
228 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,3,0)";
229 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,5,0)";
230 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,14,0)";
231 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,16,0)";
232 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,17,0)";
233 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,18,0)";
234 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,20,0)";
235 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,21,0)";
236 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,22,0)";
237 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (798,24,0)";
9730d09f
DO
238 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (965,1,0)";
239 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (965,3,0)";
240 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (965,2,25)";
706ce117
DO
241 $query[] = 'alter table IPBonds rename to IPv4Allocation';
242 $query[] = 'alter table PortForwarding rename to IPv4NAT';
243 $query[] = 'alter table IPRanges rename to IPv4Network';
244 $query[] = 'alter table IPAddress rename to IPv4Address';
245 $query[] = 'alter table IPLoadBalancer rename to IPv4LB';
4114697d 246 $query[] = 'alter table IPRSPool rename to IPv4RSPool';
706ce117 247 $query[] = 'alter table IPRealServer rename to IPv4RS';
4114697d 248 $query[] = 'alter table IPVirtualService rename to IPv4VS';
120e9ddd
DO
249 $query[] = "alter table TagStorage change column target_realm entity_realm enum('file','ipv4net','ipv4vs','ipv4rspool','object','rack','user') NOT NULL default 'object'";
250 $query[] = 'alter table TagStorage change column target_id entity_id int(10) unsigned NOT NULL';
251 $query[] = 'alter table TagStorage drop key entity_tag';
252 $query[] = 'alter table TagStorage drop key target_id';
253 $query[] = 'alter table TagStorage add UNIQUE KEY `entity_tag` (`entity_realm`,`entity_id`,`tag_id`)';
254 $query[] = 'alter table TagStorage add KEY `entity_id` (`entity_id`)';
37e59768
DO
255 $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')";
256 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('PREVIEW_TEXT_ROWS','25','uint','yes','no','Rows for text file preview')";
257 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('PREVIEW_TEXT_COLS','80','uint','yes','no','Columns for text file preview')";
258 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('PREVIEW_IMAGE_MAXPXS','320','uint','yes','no','Max pixels per axis for image file preview')";
f3d274bf 259 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('VENDOR_SIEVE','','string','yes','no','Vendor sieve configuration')";
073ed463
DO
260 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('IPV4LB_LISTSRC','{\$typeid_4}','string','yes','no','List source: IPv4 load balancers')";
261 $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')";
262 $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')";
263 $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')";
264 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('NAMEWARN_LISTSRC','{\$typeid_4} or {\$typeid_7} or {\$typeid_8}','string','yes','no','List source: object, for which common name should be set')";
f5883ec1 265 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('RACKS_PER_ROW','12','unit','yes','no','Racks per row')";
590e1281 266 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('FILTER_PREDICATE_SIEVE','','string','yes','no','Predicate sieve regex(7)')";
5496c89f
DO
267 $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)')";
268 $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')";
269 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('FILTER_SUGGEST_TAGS','yes','string','no','no','Suggest tags in list filter')";
270 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('FILTER_SUGGEST_PREDICATES','yes','string','no','no','Suggest predicates in list filter')";
271 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('FILTER_SUGGEST_EXTRA','no','string','no','no','Suggest extra expression in list filter')";
529eac25
DO
272 $query[] = "delete from Config where varname = 'USER_AUTH_SRC'";
273 $query[] = "delete from Config where varname = 'COOKIE_TTL'";
274 $query[] = "delete from Config where varname = 'rtwidth_0'";
275 $query[] = "delete from Config where varname = 'rtwidth_1'";
276 $query[] = "delete from Config where varname = 'rtwidth_2'";
c6bc0ac5
DO
277 $query[] = "delete from Config where varname = 'NAMEFUL_OBJTYPES'";
278 $query[] = "delete from Config where varname = 'REQUIRE_ASSET_TAG_FOR'";
279 $query[] = "delete from Config where varname = 'IPV4_PERFORMERS'";
280 $query[] = "delete from Config where varname = 'NATV4_PERFORMERS'";
dbb33805 281 $query[] = "alter table TagTree add column valid_realm set('file','ipv4net','ipv4vs','ipv4rspool','object','rack','user') not null default 'file,ipv4net,ipv4vs,ipv4rspool,object,rack,user' after parent_id";
a476909e
DO
282 $result = $dbxlink->query ("select user_id, user_name, user_realname from UserAccount where user_enabled = 'no'");
283 while ($row = $result->fetch (PDO::FETCH_ASSOC))
284 $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'";
285 $query[] = "update Script set script_text = NULL where script_name = 'RackCodeCache'";
286 unset ($result);
79b8ad1e 287 $query[] = "alter table UserAccount drop column user_enabled";
f76c4197 288
10bac82a
DY
289 $query[] = "CREATE TABLE RackRow ( id int(10) unsigned NOT NULL auto_increment, name char(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM";
290
9f14a7ef
DY
291 $result = $dbxlink->query ("select dict_key, dict_value from Dictionary where chapter_no = 3");
292 while($row = $result->fetch(PDO::FETCH_NUM))
10bac82a 293 $query[] = "insert into RackRow set id=${row[0]}, name='${row[1]}'";
ee286837 294 unset ($result);
f76c4197 295 $query[] = "delete from Dictionary where chapter_id = 3";
c4d0dc30 296 $query[] = "delete from Chapter where id = 3";
9133d2c5
DO
297 $query[] = "
298CREATE TABLE `LDAPCache` (
299 `presented_username` char(64) NOT NULL,
300 `successful_hash` char(40) NOT NULL,
301 `first_success` timestamp NOT NULL default CURRENT_TIMESTAMP,
302 `last_retry` timestamp NOT NULL default '0000-00-00 00:00:00',
303 `displayed_name` char(128) default NULL,
304 `memberof` text,
305 UNIQUE KEY `presented_username` (`presented_username`),
306 KEY `scanidx` (`presented_username`,`successful_hash`)
307) ENGINE=InnoDB;";
3827da34 308 $query[] = "alter table UserAccount modify column user_password_hash char(40) NULL";
aa9a0fb4
DO
309 $query[] = 'ALTER TABLE Rack DROP COLUMN deleted';
310 $query[] = 'ALTER TABLE RackHistory DROP COLUMN deleted';
311 $query[] = 'ALTER TABLE RackObject DROP COLUMN deleted';
312 $query[] = 'ALTER TABLE RackObjectHistory DROP COLUMN deleted';
2fb9d280
DO
313 // Can't be added straight due to many duplicates, even in "dictbase" data.
314 $result = $dbxlink->query ('SELECT type1, type2, count(*) - 1 as excess FROM PortCompat GROUP BY type1, type2 HAVING excess > 0');
315 while ($row = $result->fetch (PDO::FETCH_ASSOC))
316 $query[] = "DELETE FROM PortCompat WHERE type1 = ${row['type1']} AND type2 = ${row['type2']} limit ${row['excess']}";
317 unset ($result);
318 $query[] = 'ALTER TABLE PortCompat DROP KEY type1';
67d8a969 319 $query[] = 'ALTER TABLE PortCompat ADD UNIQUE `type1_2` (type1, type2)';
f76c4197
DY
320 $query[] = "UPDATE Config SET varvalue = '0.17.0' WHERE varname = 'DB_VERSION'";
321
b3f866fc 322 break;
4563cecb 323 case '0.17.1':
8b200a9c 324 $query[] = "ALTER TABLE Dictionary DROP KEY `chap_to_key`";
4563cecb
DO
325 // Token set has changed, so the cache isn't valid any more.
326 $query[] = "UPDATE Script SET script_text = NULL WHERE script_name = 'RackCodeCache'";
327 $query[] = "UPDATE Config SET varvalue = '0.17.1' WHERE varname = 'DB_VERSION'";
7d4ea62b 328 break;
7b1a3a72 329 case '0.17.2':
7b1a3a72 330 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (26,'no','fibre channel switch models')";
7c537f33 331 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1055,2,26)";
49b605d9 332 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('DEFAULT_SNMP_COMMUNITY','public','string','no','no','Default SNMP Community string')";
29c3a4d8
DO
333 // wipe irrelevant records (ticket:250)
334 $query[] = "DELETE FROM TagStorage WHERE entity_realm = 'file' AND entity_id NOT IN (SELECT id FROM File)";
f06fe423 335 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('IPV4_ENABLE_KNIGHT','yes','string','no','no','Enable IPv4 knight feature')";
99ab184f 336 $query[] = "ALTER TABLE IPv4Network ADD COLUMN comment text AFTER name";
5163cd3a 337 $query[] = "ALTER TABLE Port ADD INDEX comment (reservation_comment)";
029a14bc
DO
338 $query[] = "ALTER TABLE Port DROP KEY l2address"; // UNIQUE
339 $query[] = "ALTER TABLE Port ADD KEY (l2address)"; // not UNIQUE
948666cc
DO
340 $query[] = "ALTER TABLE Port DROP KEY object_id";
341 $query[] = "ALTER TABLE Port ADD UNIQUE KEY per_object (object_id, name, type)";
74aee2dc
DO
342 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (20,1083)";
343 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (21,1083)";
344 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (1077,1077)";
345 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (1083,20)";
346 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (1083,21)";
347 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (1083,1083)";
1c4830dc 348 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (1087,1087)";
50e02490
DO
349 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (27,'no','PDU models')";
350 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (2,2,27)";
7b1a3a72
AD
351 $query[] = "UPDATE Config SET varvalue = '0.17.2' WHERE varname = 'DB_VERSION'";
352 break;
9e51318b
DO
353 case '0.17.3':
354 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('TAGS_TOPLIST_SIZE','50','uint','yes','no','Tags top list size')";
355 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('TAGS_QUICKLIST_SIZE','20','uint','no','no','Tags quick list size')";
356 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('TAGS_QUICKLIST_THRESHOLD','50','uint','yes','no','Tags quick list threshold')";
87601bbc 357 $query[] = "ALTER TABLE AttributeMap MODIFY COLUMN chapter_id int(10) unsigned NULL";
7028a42c 358 $query[] = "UPDATE AttributeMap SET chapter_id = NULL WHERE attr_id IN (SELECT id FROM Attribute WHERE type != 'dict')";
a013838b
DO
359 // ticket:239
360 $query[] = 'UPDATE AttributeValue SET uint_value = 1018 WHERE uint_value = 731 AND attr_id IN (SELECT attr_id FROM AttributeMap WHERE chapter_id = 12)';
361 $query[] = 'DELETE FROM Dictionary WHERE dict_key = 731';
084aca6c 362 $query[] = "UPDATE Config SET vartype='uint' WHERE varname='RACKS_PER_ROW'";
f44fdef9 363 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('ENABLE_MULTIPORT_FORM','no','string','no','no','Enable \"Add/update multiple ports\" form')";
9e51318b
DO
364 $query[] = "UPDATE Config SET varvalue = '0.17.3' WHERE varname = 'DB_VERSION'";
365 break;
958ac06d
DO
366 case '0.17.4':
367 $query[] = "ALTER TABLE Link ENGINE=InnoDB";
368 $query[] = "ALTER TABLE Port ENGINE=InnoDB";
4d87feaf
DO
369 $query[] = "ALTER TABLE IPv4RS ENGINE=InnoDB";
370 $query[] = "ALTER TABLE IPv4RSPool ENGINE=InnoDB";
cafd4cf3
DO
371 $query[] = "ALTER TABLE AttributeValue ENGINE=InnoDB";
372 $query[] = "ALTER TABLE RackObject ENGINE=InnoDB";
373 $query[] = "ALTER TABLE IPv4NAT ENGINE=InnoDB";
374 $query[] = "ALTER TABLE IPv4LB ENGINE=InnoDB";
375 $query[] = "ALTER TABLE IPv4VS ENGINE=InnoDB";
4d87feaf 376 $query[] = "DELETE FROM IPv4RS WHERE rspool_id NOT IN (SELECT id FROM IPv4RSPool)";
958ac06d 377 $query[] = "ALTER TABLE Link ADD CONSTRAINT `Link-FK-b` FOREIGN KEY (portb) REFERENCES Port (id)";
cafd4cf3 378 $query[] = "ALTER TABLE Link ADD CONSTRAINT `Link-FK-a` FOREIGN KEY (porta) REFERENCES Port (id)";
4d87feaf 379 $query[] = "ALTER TABLE IPv4RS ADD CONSTRAINT `IPv4RS-FK` FOREIGN KEY (rspool_id) REFERENCES IPv4RSPool (id) ON DELETE CASCADE";
cafd4cf3
DO
380 $query[] = "ALTER TABLE AttributeValue ADD CONSTRAINT `AttributeValue-FK-object_id` FOREIGN KEY (object_id) REFERENCES RackObject (id)";
381 $query[] = "ALTER TABLE IPv4NAT ADD CONSTRAINT `IPv4NAT-FK-object_id` FOREIGN KEY (object_id) REFERENCES RackObject (id)";
382 $query[] = "ALTER TABLE Port ADD CONSTRAINT `Port-FK-object_id` FOREIGN KEY (object_id) REFERENCES RackObject (id)";
383 $query[] = "ALTER TABLE IPv4LB ADD CONSTRAINT `IPv4LB-FK-rspool_id` FOREIGN KEY (rspool_id) REFERENCES IPv4RSPool (id)";
384 $query[] = "ALTER TABLE IPv4LB ADD CONSTRAINT `IPv4LB-FK-object_id` FOREIGN KEY (object_id) REFERENCES RackObject (id)";
385 $query[] = "ALTER TABLE IPv4LB ADD CONSTRAINT `IPv4LB-FK-vs_id` FOREIGN KEY (vs_id) REFERENCES IPv4VS (id)";
958ac06d
DO
386 $query[] = "UPDATE Config SET varvalue = '0.17.4' WHERE varname = 'DB_VERSION'";
387 break;
9f572fb5
DO
388 case '0.17.5':
389 $query[] = "ALTER TABLE TagTree ENGINE=InnoDB";
390 $query[] = "ALTER TABLE TagStorage ENGINE=InnoDB";
391 $query[] = "ALTER TABLE TagStorage ADD CONSTRAINT `TagStorage-FK-tag_id` FOREIGN KEY (tag_id) REFERENCES TagTree (id)";
392 $query[] = "ALTER TABLE TagTree ADD CONSTRAINT `TagTree-K-parent_id` FOREIGN KEY (parent_id) REFERENCES TagTree (id)";
2400d7ec
DO
393 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (21,1195)';
394 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (22,1196)';
395 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (23,1196)';
396 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (20,1195)';
397 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (25,1202)';
398 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (26,1202)';
399 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (27,1204)';
400 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (28,1204)';
401 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1083,1195)';
402 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1084,1084)';
403 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1195,20)';
404 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1195,21)';
405 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1195,1083)';
406 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1195,1195)';
407 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1196,22)';
408 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1196,23)';
409 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1196,1196)';
410 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1197,1197)';
411 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1198,1199)';
412 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1199,1198)';
413 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1200,1200)';
414 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1201,1201)';
415 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1202,25)';
416 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1202,26)';
417 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1202,1202)';
418 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1203,1203)';
419 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1204,27)';
420 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1204,28)';
421 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1204,1204)';
422 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1205,1205)';
423 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1206,1207)';
424 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1207,1206)';
93a83f51 425 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1316,1316)';
bdc91a5c
DO
426 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (16, 1322)';
427 $query[] = 'INSERT INTO PortCompat (type1, type2) VALUES (1322, 16)';
428 $query[] = 'DELETE FROM PortCompat WHERE type1 = 16 AND type2 = 16';
2400d7ec
DO
429 for ($i = 1209; $i <= 1300; $i++)
430 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (${i}, ${i})";
d9b88ea0 431 $query[] = "
09d6afa4 432CREATE TABLE `PortInnerInterface` (
9173281a 433 `id` int(10) unsigned NOT NULL,
d9b88ea0
DO
434 `iif_name` char(16) NOT NULL,
435 PRIMARY KEY (`id`),
9173281a 436 UNIQUE KEY `iif_name` (`iif_name`)
d9b88ea0 437) ENGINE=InnoDB";
2400d7ec
DO
438 $query[] = "INSERT INTO `PortInnerInterface` VALUES (1,'hardwired')";
439 $query[] = "INSERT INTO `PortInnerInterface` VALUES (2,'SFP-100')";
440 $query[] = "INSERT INTO `PortInnerInterface` VALUES (3,'GBIC')";
441 $query[] = "INSERT INTO `PortInnerInterface` VALUES (4,'SFP-1000')";
442 $query[] = "INSERT INTO `PortInnerInterface` VALUES (5,'XENPAK')";
443 $query[] = "INSERT INTO `PortInnerInterface` VALUES (6,'X2')";
444 $query[] = "INSERT INTO `PortInnerInterface` VALUES (7,'XPAK')";
445 $query[] = "INSERT INTO `PortInnerInterface` VALUES (8,'XFP')";
446 $query[] = "INSERT INTO `PortInnerInterface` VALUES (9,'SFP+')";
d9b88ea0 447 $query[] = "
09d6afa4 448CREATE TABLE `PortInterfaceCompat` (
d9b88ea0
DO
449 `iif_id` int(10) unsigned NOT NULL,
450 `oif_id` int(10) unsigned NOT NULL,
451 UNIQUE KEY `pair` (`iif_id`,`oif_id`),
2400d7ec 452 CONSTRAINT `PortInterfaceCompat-FK-iif_id` FOREIGN KEY (`iif_id`) REFERENCES `PortInnerInterface` (`id`)
d9b88ea0 453) ENGINE=InnoDB";
c76cfa0d
DO
454 $query[] = "ALTER TABLE Port ADD COLUMN iif_id int unsigned NOT NULL AFTER name"; // will set iif_id to 0
455 $query[] = "UPDATE Port SET iif_id = 2 WHERE type = 1208";
456 $query[] = "UPDATE Port SET iif_id = 3 WHERE type = 1078";
457 $query[] = "UPDATE Port SET iif_id = 4 WHERE type = 1077";
458 $query[] = "UPDATE Port SET iif_id = 5 WHERE type = 1079";
459 $query[] = "UPDATE Port SET iif_id = 6 WHERE type = 1080";
460 $query[] = "UPDATE Port SET iif_id = 7 WHERE type = 1081";
461 $query[] = "UPDATE Port SET iif_id = 8 WHERE type = 1082";
462 $query[] = "UPDATE Port SET iif_id = 9 WHERE type = 1084";
463 $query[] = "UPDATE Port SET iif_id = 1 WHERE iif_id = 0";
08aa3467
DO
464 $query[] = 'ALTER TABLE Port ADD UNIQUE `object_iif_oif_name` (object_id, iif_id, type, name)';
465 $query[] = 'ALTER TABLE Port DROP KEY `per_object`';
2400d7ec
DO
466 $base1000 = array (24, 34, 1202, 1203, 1204, 1205, 1206, 1207);
467 $base10000 = array (30, 35, 36, 37, 38, 39, 40);
468 $PICdata = array
469 (
bdc91a5c 470 1 => array (16, 19, 24, 29, 31, 33, 446, 681, 682, 1322),
2400d7ec
DO
471 2 => array (1208, 1195, 1196, 1197, 1198, 1199, 1200, 1201),
472 3 => array_merge (array (1078), $base1000),
473 4 => array_merge (array (1077), $base1000),
474 5 => array_merge (array (1079), $base10000),
475 6 => array_merge (array (1080), $base10000),
476 7 => array_merge (array (1081), $base10000),
477 8 => array_merge (array (1082), $base10000),
478 9 => array_merge (array (1084), $base10000),
479 );
480 // make sure all IIF/OIF pairs referenced from Port exist in PortInterfaceCompat before enabling FK
481 // iif_id doesn't exist at this point
482 $result = $dbxlink->query ('SELECT DISTINCT type FROM Port WHERE type NOT IN (1208, 1078, 1077, 1079, 1080, 1081, 1082, 1084)');
483 while ($row = $result->fetch (PDO::FETCH_ASSOC))
484 if (FALSE === array_search ($row['type'], $PICdata[1]))
485 array_push ($PICdata[1], $row['type']);
486 unset ($result);
487 foreach ($PICdata as $iif_id => $oif_ids)
488 foreach ($oif_ids as $oif_id)
489 $query[] = "INSERT INTO PortInterfaceCompat (iif_id, oif_id) VALUES (${iif_id}, ${oif_id})";
c76cfa0d 490 $query[] = "ALTER TABLE Port ADD CONSTRAINT `Port-FK-iif-oif` FOREIGN KEY (`iif_id`, `type`) REFERENCES `PortInterfaceCompat` (`iif_id`, `oif_id`)";
bdc91a5c 491 $query[] = 'UPDATE Port SET type = 1322 WHERE type = 16 AND (SELECT objtype_id FROM RackObject WHERE id = object_id) IN (2, 12)';
2400d7ec
DO
492 $query[] = "DELETE FROM Config WHERE varname = 'default_port_type'";
493 $query[] = "INSERT INTO Config VALUES ('DEFAULT_PORT_IIF_ID','1','uint','no','no','Default port inner interface ID')";
494 $query[] = "INSERT INTO Config VALUES ('DEFAULT_PORT_OIF_IDS','1=24; 3=1078; 4=1077; 5=1079; 6=1080; 8=1082; 9=1084','string','no','no','Default port outer interface IDs')";
4a47d34b 495 $query[] = "INSERT INTO Config VALUES ('IPV4_TREE_RTR_AS_CELL','yes','string','no','no','Show full router info for each network in IPv4 tree view')";
93a83f51 496 $query[] = "UPDATE Chapter SET name = 'PortOuterInterface' WHERE id = 2";
fbcbb4ee
DO
497 // remap refs to duplicate records, which will be discarded (ticket:286)
498 $query[] = 'UPDATE AttributeValue SET uint_value = 147 WHERE uint_value = 1020 AND attr_id = 2';
499 $query[] = 'UPDATE AttributeValue SET uint_value = 377 WHERE uint_value = 1021 AND attr_id = 2';
e8ab58e8 500 $query[] = 'INSERT INTO AttributeMap (objtype_id, attr_id) VALUES (2, 1), (2, 3), (2, 5)';
9f572fb5
DO
501 $query[] = "UPDATE Config SET varvalue = '0.17.5' WHERE varname = 'DB_VERSION'";
502 break;
63811a09
DO
503 case '0.17.6':
504 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (28,'no','Voice/video hardware')";
505 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1323,1,NULL)";
506 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1323,2,28)";
507 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1323,3,NULL)";
508 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1323,5,NULL)";
cd3775e9 509 $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)')";
63811a09
DO
510 $query[] = "UPDATE Config SET varvalue = '0.17.6' WHERE varname = 'DB_VERSION'";
511 break;
026a79ee
DO
512 case '0.17.7':
513 $query[] = "UPDATE Config SET varvalue = '0.17.7' WHERE varname = 'DB_VERSION'";
514 break;
3540d15c 515 case '0.17.8':
1e81ad97
DO
516 $query[] = "ALTER TABLE TagTree DROP COLUMN valid_realm";
517 $query[] = "UPDATE Config SET varvalue = '0.17.8' WHERE varname = 'DB_VERSION'";
518 break;
519 case '0.17.9':
45833307 520 $query[] = "ALTER table Config add `is_userdefined` enum('yes','no') NOT NULL default 'no' AFTER `is_hidden`";
3540d15c
DY
521 $query[] = "
522CREATE TABLE `UserConfig` (
523 `varname` char(32) NOT NULL,
524 `varvalue` char(255) NOT NULL,
525 `user` char(64) NOT NULL,
526 UNIQUE KEY `user_varname` (`user`,`varname`)
527) TYPE=InnoDB";
1e81ad97
DO
528 $query[] = "UPDATE Config SET is_userdefined = 'yes' WHERE varname IN
529(
530'MASSCOUNT',
531'MAXSELSIZE',
532'ROW_SCALE',
533'PORTS_PER_ROW',
534'IPV4_ADDRS_PER_PAGE',
535'DEFAULT_RACK_HEIGHT',
536'DEFAULT_SLB_VS_PORT',
537'DEFAULT_SLB_RS_PORT',
538'DETECT_URLS',
539'RACK_PRESELECT_THRESHOLD',
540'DEFAULT_IPV4_RS_INSERVICE',
541'DEFAULT_OBJECT_TYPE',
542'SHOW_EXPLICIT_TAGS',
543'SHOW_IMPLICIT_TAGS',
544'SHOW_AUTOMATIC_TAGS',
545'IPV4_AUTO_RELEASE',
546'SHOW_LAST_TAB',
547'EXT_IPV4_VIEW',
548'TREE_THRESHOLD',
549'ADDNEW_AT_TOP',
550'IPV4_TREE_SHOW_USAGE',
551'PREVIEW_TEXT_MAXCHARS',
552'PREVIEW_TEXT_ROWS',
553'PREVIEW_TEXT_COLS',
554'PREVIEW_IMAGE_MAXPXS',
555'VENDOR_SIEVE',
556'RACKS_PER_ROW'
557)";
9013f05b
DO
558 $query[] = "UPDATE Config SET varvalue = '0.17.9' WHERE varname = 'DB_VERSION'";
559 break;
f32167d2 560 case '0.17.10':
4368cc45 561 $query[] = "ALTER TABLE MountOperation ADD KEY (object_id)";
2926b1cb 562 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('STATIC_FILTER','yes','string','no','no','yes','Enable Filter Caching');";
f32167d2 563 $query[] = "UPDATE Config SET varvalue = '0.17.10' WHERE varname = 'DB_VERSION'";
d80036ba 564 break;
a1fc539a 565 case '0.17.11':
a1fc539a 566 $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');";
0f353a95 567 $query[] = "DELETE AttributeValue FROM AttributeValue JOIN Attribute where AttributeValue.attr_id = Attribute.id AND Attribute.type = 'dict' AND AttributeValue.uint_value = 0";
a1fc539a 568 $query[] = "UPDATE Config SET varvalue = '0.17.11' WHERE varname = 'DB_VERSION'";
59e0658a 569 break;
9013f05b 570 case '0.18.0':
8bb69a06
DO
571 $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')";
572 $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')";
573 $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')";
574 $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')";
37cb9e18
DO
575 $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')";
576 $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')";
577 $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')";
407ed7bb 578 $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')";
4492050b 579 $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')";
97c0a54e 580 $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')";
1768cc35 581 $query[] = "ALTER TABLE IPv4Network ENGINE=InnoDB";
22fdebff
DO
582 $query[] = "SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0";
583 $query[] = "
584CREATE TABLE `CachedPAV` (
585 `object_id` int(10) unsigned NOT NULL,
586 `port_name` char(255) NOT NULL,
587 `vlan_id` int(10) unsigned NOT NULL default '0',
588 PRIMARY KEY (`object_id`,`port_name`,`vlan_id`),
589 KEY `vlan_id` (`vlan_id`),
590 CONSTRAINT `CachedPAV-FK-object-port` FOREIGN KEY (`object_id`, `port_name`) REFERENCES `CachedPVM` (`object_id`, `port_name`) ON DELETE CASCADE,
591 CONSTRAINT `CachedPAV-FK-vlan_id` FOREIGN KEY (`vlan_id`) REFERENCES `VLANValidID` (`vlan_id`)
592) ENGINE=InnoDB
593";
594 $query[] = "
595CREATE TABLE `CachedPNV` (
596 `object_id` int(10) unsigned NOT NULL,
597 `port_name` char(255) NOT NULL,
598 `vlan_id` int(10) unsigned NOT NULL default '0',
599 PRIMARY KEY (`object_id`,`port_name`,`vlan_id`),
600 UNIQUE KEY `port_id` (`object_id`,`port_name`),
601 CONSTRAINT `CachedPNV-FK-compound` FOREIGN KEY (`object_id`, `port_name`, `vlan_id`) REFERENCES `CachedPAV` (`object_id`, `port_name`, `vlan_id`) ON DELETE CASCADE
602) ENGINE=InnoDB
603";
604 $query[] = "
605CREATE TABLE `CachedPVM` (
606 `object_id` int(10) unsigned NOT NULL,
607 `port_name` char(255) NOT NULL,
608 `vlan_mode` enum('access','trunk') NOT NULL default 'access',
609 PRIMARY KEY (`object_id`,`port_name`),
610 CONSTRAINT `CachedPVM-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `RackObject` (`id`) ON DELETE CASCADE
611) ENGINE=InnoDB
612";
613 $query[] = "
614CREATE TABLE `PortAllowedVLAN` (
615 `object_id` int(10) unsigned NOT NULL,
616 `port_name` char(255) NOT NULL,
617 `vlan_id` int(10) unsigned NOT NULL default '0',
618 PRIMARY KEY (`object_id`,`port_name`,`vlan_id`),
619 KEY `vlan_id` (`vlan_id`),
620 CONSTRAINT `PortAllowedVLAN-FK-object-port` FOREIGN KEY (`object_id`, `port_name`) REFERENCES `PortVLANMode` (`object_id`, `port_name`) ON DELETE CASCADE,
621 CONSTRAINT `PortAllowedVLAN-FK-vlan_id` FOREIGN KEY (`vlan_id`) REFERENCES `VLANValidID` (`vlan_id`)
622) ENGINE=InnoDB
623";
624 $query[] = "
625CREATE TABLE `PortNativeVLAN` (
626 `object_id` int(10) unsigned NOT NULL,
627 `port_name` char(255) NOT NULL,
628 `vlan_id` int(10) unsigned NOT NULL default '0',
629 PRIMARY KEY (`object_id`,`port_name`,`vlan_id`),
630 UNIQUE KEY `port_id` (`object_id`,`port_name`),
631 CONSTRAINT `PortNativeVLAN-FK-compound` FOREIGN KEY (`object_id`, `port_name`, `vlan_id`) REFERENCES `PortAllowedVLAN` (`object_id`, `port_name`, `vlan_id`) ON DELETE CASCADE
632) ENGINE=InnoDB
633";
634 $query[] = "
635CREATE TABLE `PortVLANMode` (
636 `object_id` int(10) unsigned NOT NULL,
637 `port_name` char(255) NOT NULL,
638 `vlan_mode` enum('access','trunk') NOT NULL default 'access',
639 PRIMARY KEY (`object_id`,`port_name`),
640 CONSTRAINT `PortVLANMode-FK-object-port` FOREIGN KEY (`object_id`, `port_name`) REFERENCES `CachedPVM` (`object_id`, `port_name`)
641) ENGINE=InnoDB
642";
643 $query[] = "
644CREATE TABLE `VLANDescription` (
645 `domain_id` int(10) unsigned NOT NULL,
646 `vlan_id` int(10) unsigned NOT NULL default '0',
647 `vlan_type` enum('ondemand','compulsory','alien') NOT NULL default 'ondemand',
648 `vlan_descr` char(255) default NULL,
649 PRIMARY KEY (`domain_id`,`vlan_id`),
650 KEY `vlan_id` (`vlan_id`),
219da133 651 CONSTRAINT `VLANDescription-FK-domain_id` FOREIGN KEY (`domain_id`) REFERENCES `VLANDomain` (`id`) ON DELETE CASCADE,
22fdebff
DO
652 CONSTRAINT `VLANDescription-FK-vlan_id` FOREIGN KEY (`vlan_id`) REFERENCES `VLANValidID` (`vlan_id`)
653) ENGINE=InnoDB
654";
655 $query[] = "
656CREATE TABLE `VLANDomain` (
657 `id` int(10) unsigned NOT NULL auto_increment,
658 `description` char(255) default NULL,
659 PRIMARY KEY (`id`),
660 UNIQUE KEY `description` (`description`)
661) ENGINE=InnoDB
662";
663 $query[] = "
664CREATE TABLE `VLANIPv4` (
665 `domain_id` int(10) unsigned NOT NULL,
666 `vlan_id` int(10) unsigned NOT NULL,
667 `ipv4net_id` int(10) unsigned NOT NULL,
668 UNIQUE KEY `network-domain` (`ipv4net_id`,`domain_id`),
669 KEY `VLANIPv4-FK-compound` (`domain_id`,`vlan_id`),
670 CONSTRAINT `VLANIPv4-FK-compound` FOREIGN KEY (`domain_id`, `vlan_id`) REFERENCES `VLANDescription` (`domain_id`, `vlan_id`) ON DELETE CASCADE,
671 CONSTRAINT `VLANIPv4-FK-ipv4net_id` FOREIGN KEY (`ipv4net_id`) REFERENCES `IPv4Network` (`id`) ON DELETE CASCADE
672) ENGINE=InnoDB
673";
674 $query[] = "
675CREATE TABLE `VLANSTRule` (
676 `vst_id` int(10) unsigned NOT NULL,
677 `rule_no` int(10) unsigned NOT NULL,
678 `port_pcre` char(255) NOT NULL,
679 `port_role` enum('access','trunk','uplink','downlink','none') NOT NULL default 'none',
680 `wrt_vlans` char(255) default NULL,
681 `description` char(255) default NULL,
682 UNIQUE KEY `vst-rule` (`vst_id`,`rule_no`),
683 CONSTRAINT `VLANSTRule-FK-vst_id` FOREIGN KEY (`vst_id`) REFERENCES `VLANSwitchTemplate` (`id`) ON DELETE CASCADE
684) ENGINE=InnoDB
685";
686 $query[] = "
687CREATE TABLE `VLANSwitch` (
688 `object_id` int(10) unsigned NOT NULL,
689 `domain_id` int(10) unsigned NOT NULL,
690 `template_id` int(10) unsigned NOT NULL,
691 `mutex_rev` int(10) unsigned NOT NULL default '0',
692 `out_of_sync` enum('yes','no') NOT NULL default 'yes',
693 `last_errno` int(10) unsigned NOT NULL default '0',
694 `last_change` timestamp NOT NULL default '0000-00-00 00:00:00',
695 `last_push_started` timestamp NOT NULL default '0000-00-00 00:00:00',
696 `last_push_finished` timestamp NOT NULL default '0000-00-00 00:00:00',
697 `last_error_ts` timestamp NOT NULL default '0000-00-00 00:00:00',
698 UNIQUE KEY `object_id` (`object_id`),
699 KEY `domain_id` (`domain_id`),
700 KEY `template_id` (`template_id`),
701 KEY `out_of_sync` (`out_of_sync`),
702 KEY `last_errno` (`last_errno`),
703 CONSTRAINT `VLANSwitch-FK-domain_id` FOREIGN KEY (`domain_id`) REFERENCES `VLANDomain` (`id`),
704 CONSTRAINT `VLANSwitch-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `RackObject` (`id`),
705 CONSTRAINT `VLANSwitch-FK-template_id` FOREIGN KEY (`template_id`) REFERENCES `VLANSwitchTemplate` (`id`)
706) ENGINE=InnoDB
707";
708 $query[] = "
709CREATE TABLE `VLANSwitchTemplate` (
710 `id` int(10) unsigned NOT NULL auto_increment,
711 `max_local_vlans` int(10) unsigned default NULL,
712 `description` char(255) default NULL,
713 PRIMARY KEY (`id`),
714 UNIQUE KEY `description` (`description`)
715) ENGINE=InnoDB
716";
717 $query[] = "
718CREATE TABLE `VLANValidID` (
719 `vlan_id` int(10) unsigned NOT NULL default '1',
720 PRIMARY KEY (`vlan_id`)
721) ENGINE=InnoDB
722";
723 $query[] = "SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS";
fa11e5c7 724 for ($i = 1; $i <= 4094; $i++)
a401a680 725 $query[] = "INSERT INTO VLANValidID (vlan_id) VALUES (${i})";
9013f05b 726 $query[] = "UPDATE Config SET varvalue = '0.18.0' WHERE varname = 'DB_VERSION'";
08d1ef24 727 break;
425fd829 728 case '0.18.1':
b6978d62
DO
729 $query[] = "ALTER TABLE Atom ENGINE=InnoDB";
730 $query[] = "ALTER TABLE AttributeMap ENGINE=InnoDB";
731 $query[] = "ALTER TABLE Config ENGINE=InnoDB";
732 $query[] = "ALTER TABLE IPv4Address ENGINE=InnoDB";
733 $query[] = "ALTER TABLE IPv4Allocation ENGINE=InnoDB";
734 $query[] = "ALTER TABLE Molecule ENGINE=InnoDB";
735 $query[] = "ALTER TABLE MountOperation ENGINE=InnoDB";
736 $query[] = "ALTER TABLE PortCompat ENGINE=InnoDB";
737 $query[] = "ALTER TABLE Rack ENGINE=InnoDB";
738 $query[] = "ALTER TABLE RackHistory ENGINE=InnoDB";
739 $query[] = "ALTER TABLE RackObjectHistory ENGINE=InnoDB";
740 $query[] = "ALTER TABLE RackRow ENGINE=InnoDB";
741 $query[] = "ALTER TABLE RackSpace ENGINE=InnoDB";
742 $query[] = "ALTER TABLE Script ENGINE=InnoDB";
735f169f
DO
743 $query[] = "ALTER TABLE AttributeValue DROP FOREIGN KEY `AttributeValue-FK-object_id`";
744 $query[] = "ALTER TABLE AttributeValue ADD CONSTRAINT `AttributeValue-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `RackObject` (`id`) ON DELETE CASCADE";
55267f67
DO
745 $query[] = "ALTER TABLE RackObjectHistory ADD KEY (id)";
746 $query[] = "ALTER TABLE RackObjectHistory ADD CONSTRAINT `RackObjectHistory-FK-object_id` FOREIGN KEY (id) REFERENCES `RackObject` (`id`) ON DELETE CASCADE";
f3552988 747 $query[] = "ALTER TABLE MountOperation ADD CONSTRAINT `MountOperation-FK-object_id` FOREIGN KEY (object_id) REFERENCES RackObject (id) ON DELETE CASCADE";
f7cec175 748 $query[] = "ALTER TABLE RackSpace ADD CONSTRAINT `RackSpace-FK-object_id` FOREIGN KEY (object_id) REFERENCES RackObject (id) ON DELETE CASCADE";
1bcfe894
DO
749 $query[] = "ALTER TABLE Link DROP FOREIGN KEY `Link-FK-a`";
750 $query[] = "ALTER TABLE Link ADD CONSTRAINT `Link-FK-a` FOREIGN KEY (`porta`) REFERENCES `Port` (`id`) ON DELETE CASCADE";
751 $query[] = "ALTER TABLE Link DROP FOREIGN KEY `Link-FK-b`";
752 $query[] = "ALTER TABLE Link ADD CONSTRAINT `Link-FK-b` FOREIGN KEY (`portb`) REFERENCES `Port` (`id`) ON DELETE CASCADE";
753 $query[] = "ALTER TABLE Port DROP FOREIGN KEY `Port-FK-object_id`";
754 $query[] = "ALTER TABLE Port ADD CONSTRAINT `Port-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `RackObject` (`id`) ON DELETE CASCADE";
e7787961
DO
755 $query[] = "ALTER TABLE AttributeMap MODIFY `chapter_id` int(10) unsigned default NULL";
756 $query[] = "ALTER TABLE IPv4Address MODIFY `ip` int(10) unsigned NOT NULL default '0'";
757 $query[] = "ALTER TABLE IPv4Address MODIFY `name` char(255) NOT NULL default ''";
758 $query[] = "ALTER TABLE IPv4Allocation MODIFY `object_id` int(10) unsigned NOT NULL default '0'";
759 $query[] = "ALTER TABLE IPv4Allocation MODIFY `ip` int(10) unsigned NOT NULL default '0'";
760 $query[] = "ALTER TABLE IPv4Allocation MODIFY `name` char(255) NOT NULL default ''";
761 $query[] = "ALTER TABLE IPv4NAT MODIFY `object_id` int(10) unsigned NOT NULL default '0'";
762 $query[] = "ALTER TABLE IPv4NAT MODIFY `proto` enum('TCP','UDP') NOT NULL default 'TCP'";
763 $query[] = "ALTER TABLE IPv4NAT MODIFY `localip` int(10) unsigned NOT NULL default '0'";
764 $query[] = "ALTER TABLE IPv4NAT MODIFY `localport` smallint(5) unsigned NOT NULL default '0'";
765 $query[] = "ALTER TABLE IPv4NAT MODIFY `remoteip` int(10) unsigned NOT NULL default '0'";
766 $query[] = "ALTER TABLE IPv4NAT MODIFY `remoteport` smallint(5) unsigned NOT NULL default '0'";
767 $query[] = "ALTER TABLE IPv4Network MODIFY `ip` int(10) unsigned NOT NULL default '0'";
768 $query[] = "ALTER TABLE IPv4Network MODIFY `mask` int(10) unsigned NOT NULL default '0'";
769 $query[] = "ALTER TABLE Link MODIFY `porta` int(10) unsigned NOT NULL default '0'";
770 $query[] = "ALTER TABLE Link MODIFY `portb` int(10) unsigned NOT NULL default '0'";
771 $query[] = "ALTER TABLE MountOperation MODIFY `object_id` int(10) unsigned NOT NULL default '0'";
772 $query[] = "ALTER TABLE MountOperation MODIFY `ctime` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP";
773 $query[] = "ALTER TABLE Port MODIFY `object_id` int(10) unsigned NOT NULL default '0'";
774 $query[] = "ALTER TABLE Port MODIFY `name` char(255) NOT NULL default ''";
775 $query[] = "ALTER TABLE Port MODIFY `type` int(10) unsigned NOT NULL default '0'";
776 $query[] = "ALTER TABLE PortCompat MODIFY `type1` int(10) unsigned NOT NULL default '0'";
777 $query[] = "ALTER TABLE PortCompat MODIFY `type2` int(10) unsigned NOT NULL default '0'";
778 $query[] = "ALTER TABLE RackHistory MODIFY `ctime` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP";
779 $query[] = "ALTER TABLE RackObjectHistory MODIFY `ctime` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP";
780 $query[] = "ALTER TABLE TagStorage MODIFY `tag_id` int(10) unsigned NOT NULL default '0'";
781 $query[] = "ALTER TABLE UserAccount MODIFY `user_name` char(64) NOT NULL default ''";
425fd829
DO
782 $query[] = "UPDATE Config SET varvalue = '0.18.1' WHERE varname = 'DB_VERSION'";
783 break;
298d2375 784 case '0.18.2':
298d2375 785 $query[] = "ALTER TABLE Rack ADD CONSTRAINT `Rack-FK-row_id` FOREIGN KEY (row_id) REFERENCES RackRow (id)";
b504972c 786 $query[] = "ALTER TABLE RackRow ADD UNIQUE KEY `name` (name)";
b49a479e
DO
787 $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')";
788 $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')";
10eadad9 789 $query[] = "UPDATE Config SET varvalue = '0.18.2' WHERE varname = 'DB_VERSION'";
298d2375 790 break;
2582446d
DO
791 case '0.18.3':
792 $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'";
0328f6d6 793 $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)')";
2582446d
DO
794 $query[] = "UPDATE Config SET varvalue = '0.18.3' WHERE varname = 'DB_VERSION'";
795 break;
3a387b0d 796 case '0.18.4':
ec523868 797 $query[] = "ALTER TABLE VLANSTRule MODIFY port_role enum('access','trunk','anymode','uplink','downlink','none') NOT NULL default 'none'";
3a387b0d
DO
798 $query[] = "UPDATE Config SET varvalue = '0.18.4' WHERE varname = 'DB_VERSION'";
799 break;
95857b5c
DO
800 case '0.18.5':
801 $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')";
1f54e1ba 802 $query[] = "ALTER TABLE `IPv4LB` ADD COLUMN `prio` int(10) unsigned DEFAULT NULL AFTER `vs_id`";
1ebbf889 803 $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')";
95857b5c 804 $query[] = "UPDATE Config SET varvalue = '0.18.5' WHERE varname = 'DB_VERSION'";
f2f95f99
JT
805 break;
806 case '0.18.6':
f2f95f99 807 $query[] = "UPDATE Config SET varvalue = '0.18.6' WHERE varname = 'DB_VERSION'";
95857b5c 808 break;
9fb6900d 809 case '0.18.7':
9fb6900d
DO
810 $query[] = "UPDATE Config SET varvalue = '0.18.7' WHERE varname = 'DB_VERSION'";
811 break;
d3346ce2
DO
812 case '0.19.0':
813 $query[] = 'ALTER TABLE `File` ADD `thumbnail` LONGBLOB NULL AFTER `atime`';
21ee3351
AA
814 $query[] = "
815CREATE TABLE `IPv6Address` (
816 `ip` binary(16) NOT NULL,
817 `name` char(255) NOT NULL default '',
818 `reserved` enum('yes','no') default NULL,
819 PRIMARY KEY (`ip`)
820) ENGINE=InnoDB
821";
822 $query[] = "
823CREATE TABLE `IPv6Allocation` (
824 `object_id` int(10) unsigned NOT NULL default '0',
825 `ip` binary(16) NOT NULL,
826 `name` char(255) NOT NULL default '',
827 `type` enum('regular','shared','virtual','router') default NULL,
8c7b7381
AA
828 PRIMARY KEY (`object_id`,`ip`),
829 CONSTRAINT `IPv6Allocation-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `RackObject` (`id`) ON DELETE CASCADE
21ee3351
AA
830) ENGINE=InnoDB
831";
832 $query[] = "
833CREATE TABLE `IPv6Network` (
834 `id` int(10) unsigned NOT NULL auto_increment,
835 `ip` binary(16) NOT NULL,
836 `mask` int(10) unsigned NOT NULL,
837 `last_ip` binary(16) NOT NULL,
838 `name` char(255) default NULL,
839 `comment` text,
840 PRIMARY KEY (`id`),
841 UNIQUE KEY `ip` (`ip`,`mask`)
842) ENGINE=InnoDB
843";
844 $query[] = "
845CREATE TABLE `VLANIPv6` (
846 `domain_id` int(10) unsigned NOT NULL,
847 `vlan_id` int(10) unsigned NOT NULL,
848 `ipv6net_id` int(10) unsigned NOT NULL,
849 UNIQUE KEY `network-domain` (`ipv6net_id`,`domain_id`),
850 KEY `VLANIPv6-FK-compound` (`domain_id`,`vlan_id`),
851 CONSTRAINT `VLANIPv6-FK-compound` FOREIGN KEY (`domain_id`, `vlan_id`) REFERENCES `VLANDescription` (`domain_id`, `vlan_id`) ON DELETE CASCADE,
852 CONSTRAINT `VLANIPv6-FK-ipv6net_id` FOREIGN KEY (`ipv6net_id`) REFERENCES `IPv6Network` (`id`) ON DELETE CASCADE
853) ENGINE=InnoDB
9a90adc4
DO
854";
855 $query[] = "
8489d2af
DO
856CREATE TABLE IF NOT EXISTS `ObjectLog` (
857 `id` int(10) NOT NULL AUTO_INCREMENT,
858 `object_id` int(10) NOT NULL,
859 `user` varchar(64) NOT NULL,
9a90adc4
DO
860 `date` datetime NOT NULL,
861 `content` text NOT NULL,
8489d2af 862 PRIMARY KEY (`id`)
9a90adc4 863) ENGINE=InnoDB
0682218d 864";
8489d2af
DO
865 # Now we have the same structure of ObjectLog table, which objectlog.php
866 # could have left. Subsequent column updates will handle any existing data.
867 $query[] = "ALTER TABLE ObjectLog MODIFY COLUMN `id` int(10) unsigned NOT NULL AUTO_INCREMENT";
868 $query[] = "ALTER TABLE ObjectLog MODIFY COLUMN `object_id` int(10) unsigned NOT NULL";
869 $query[] = "ALTER TABLE ObjectLog MODIFY COLUMN `user` char(64) NOT NULL";
870 $query[] = "ALTER TABLE ObjectLog ADD KEY `object_id` (`object_id`)";
871 $query[] = "ALTER TABLE ObjectLog ADD KEY `date` (`date`)";
872 $query[] = "ALTER TABLE ObjectLog ADD CONSTRAINT `ObjectLog-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `RackObject` (`id`) ON DELETE CASCADE";
873 # Now it's the way 0.19.0 is expecting it to be.
0682218d
AD
874 $query[] = "
875CREATE TABLE `ObjectParentCompat` (
876 `parent_objtype_id` int(10) unsigned NOT NULL,
877 `child_objtype_id` int(10) unsigned NOT NULL,
878 UNIQUE KEY `parent_child` (`parent_objtype_id`,`child_objtype_id`)
879) ENGINE=InnoDB
880";
881 $query[] = "
882CREATE TABLE `EntityLink` (
883 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
884 `parent_entity_type` enum('ipv4net','ipv4rspool','ipv4vs','ipv6net','object','rack','user') NOT NULL,
885 `parent_entity_id` int(10) unsigned NOT NULL,
886 `child_entity_type` enum('file','object') NOT NULL,
887 `child_entity_id` int(10) unsigned NOT NULL,
888 PRIMARY KEY (`id`),
889 UNIQUE KEY `EntityLink-unique` (`parent_entity_type`,`parent_entity_id`,`child_entity_type`,`child_entity_id`)
890) ENGINE=InnoDB
21ee3351
AA
891";
892 $query[] = "ALTER TABLE `TagStorage` CHANGE COLUMN `entity_realm` `entity_realm` ENUM('file','ipv4net','ipv4vs','ipv4rspool','object','rack','user','ipv6net') NOT NULL DEFAULT 'object' FIRST";
893 $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`";
0c7c9f8b 894 $query[] = 'ALTER TABLE Link ADD COLUMN cable char(64) NULL AFTER portb';
3fb61857 895 $query[] = 'ALTER TABLE RackSpace ADD CONSTRAINT `RackSpace-FK-rack_id` FOREIGN KEY (rack_id) REFERENCES Rack (id)';
8c7b7381 896 $query[] = "ALTER TABLE `IPv4Allocation` ADD CONSTRAINT `IPv4Allocation-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `RackObject` (`id`) ON DELETE CASCADE";
61e79d63 897 $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')";
fbeacc34 898 $query[] = "ALTER TABLE `VLANSwitchTemplate` ADD COLUMN `mutex_rev` int(10) NOT NULL AFTER `id`";
09ec2e59 899 $query[] = "ALTER TABLE `VLANSwitchTemplate` ADD COLUMN `saved_by` char(64) NOT NULL AFTER `description`";
0682218d
AD
900 $query[] = "INSERT INTO `Attribute` (`id`, `type`, `name`) VALUES (26,'dict','Hypervisor')";
901 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (29,'no','Yes/No')";
902 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (30,'no','network chassis models')";
903 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (31,'no','server chassis models')";
904 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (32,'no','virtual switch models')";
905 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (33,'no','virtual switch OS type')";
906 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (4,26,29)";
907 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1502,1,NULL)";
908 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1502,2,31)";
909 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1502,3,NULL)";
910 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1502,14,NULL)";
911 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1502,20,NULL)";
912 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1502,21,NULL)";
913 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1502,22,NULL)";
914 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,1,NULL)";
915 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,2,30)";
916 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,3,NULL)";
588c98f8
AD
917 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,4,14)";
918 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,5,NULL)";
0682218d 919 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,14,NULL)";
588c98f8
AD
920 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,16,NULL)";
921 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,17,NULL)";
922 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,18,NULL)";
0682218d
AD
923 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,20,NULL)";
924 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,21,NULL)";
925 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,22,NULL)";
588c98f8 926 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1503,24,NULL)";
0682218d
AD
927 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1504,3,NULL)";
928 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1504,4,13)";
929 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1504,14,NULL)";
930 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1504,24,NULL)";
931 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1505,14,NULL)";
932 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1506,14,NULL)";
933 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1506,17,NULL)";
934 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1506,18,NULL)";
935 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1507,1,NULL)";
936 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1507,2,32)";
937 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1507,3,NULL)";
938 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1507,4,33)";
939 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1507,5,NULL)";
940 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1507,14,NULL)";
941 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1507,20,NULL)";
942 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1507,21,NULL)";
943 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1507,22,NULL)";
944 $query[] = "INSERT INTO `ObjectParentCompat` (`parent_objtype_id`, `child_objtype_id`) VALUES (3,13)";
945 $query[] = "INSERT INTO `ObjectParentCompat` (`parent_objtype_id`, `child_objtype_id`) VALUES (4,1504)";
946 $query[] = "INSERT INTO `ObjectParentCompat` (`parent_objtype_id`, `child_objtype_id`) VALUES (4,1507)";
947 $query[] = "INSERT INTO `ObjectParentCompat` (`parent_objtype_id`, `child_objtype_id`) VALUES (1502,4)";
948 $query[] = "INSERT INTO `ObjectParentCompat` (`parent_objtype_id`, `child_objtype_id`) VALUES (1503,8)";
949 $query[] = "INSERT INTO `ObjectParentCompat` (`parent_objtype_id`, `child_objtype_id`) VALUES (1505,4)";
950 $query[] = "INSERT INTO `ObjectParentCompat` (`parent_objtype_id`, `child_objtype_id`) VALUES (1505,1504)";
951 $query[] = "INSERT INTO `ObjectParentCompat` (`parent_objtype_id`, `child_objtype_id`) VALUES (1505,1506)";
952 $query[] = "INSERT INTO `ObjectParentCompat` (`parent_objtype_id`, `child_objtype_id`) VALUES (1505,1507)";
953 $query[] = "INSERT INTO `ObjectParentCompat` (`parent_objtype_id`, `child_objtype_id`) VALUES (1506,1504)";
0682218d 954 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('PORT_EXCLUSION_LISTSRC','{\$typeid_3} or {\$typeid_10} or {\$typeid_11} or {\$typeid_1505} or {\$typeid_1506}','string','yes','no','no','List source: objects without ports')";
322ce490 955 $query[] = "UPDATE Config SET varvalue = CONCAT(varvalue, ' or {\$typeid_1502} or {\$typeid_1503} or {\$typeid_1504} or {\$typeid_1507}') WHERE varname = 'IPV4OBJ_LISTSRC'";
0682218d 956 $query[] = "UPDATE Config SET varvalue = '8' WHERE varname = 'MASSCOUNT'";
993f5fa3 957 $query[] = "UPDATE RackObject SET label = NULL WHERE label = ''";
81659c05
AD
958 // Move barcode data so the column can be dropped
959 $result = $dbxlink->query ('SELECT id, objtype_id, barcode FROM RackObject WHERE barcode IS NOT NULL');
a7978f7f
AD
960 $rows = $result->fetchAll (PDO::FETCH_ASSOC);
961 unset ($result);
962 foreach ($rows as $row)
81659c05
AD
963 {
964 // Determine if this object type has the 'OEM S/N 1' attribute associated with it, and if it's set
965 $sn_query = "SELECT (SELECT COUNT(*) FROM AttributeMap WHERE objtype_id=${row['objtype_id']} AND attr_id=1) AS AM_count, ";
966 $sn_query .= "(SELECT COUNT(*) FROM AttributeValue WHERE object_id=${row['id']} AND attr_id=1) AS AV_count";
967 $sn_result = $dbxlink->query ($sn_query);
968 $sn_row = $sn_result->fetch (PDO::FETCH_ASSOC);
969 if ($sn_row['AM_count'] == 1 && $sn_row['AV_count'] == 0)
970 {
971 // 'OEM S/N 1' attribute is mapped to this object type, but it is not set. Good!
972 // Copy the barcode value to the attribute.
973 $query[] = "INSERT INTO AttributeValue (`object_id`, `attr_id`, `string_value`) VALUES (${row['id']}, 1, '${row['barcode']}')";
974 }
975 else
976 {
977 // Some other set of circumstances. Not as good!
978 // Copy the barcode value to a new ObjectLog record.
979 $query[] = "INSERT INTO ObjectLog (`object_id`, `user`, `date`, `content`) VALUES (${row['id']}, '${_SERVER['PHP_AUTH_USER']}', NOW(), 'Upgrade to 0.19 dropped the barcode column. Value was: ${row['barcode']}')";
980 }
981 unset ($sn_query, $sn_result, $sn_row);
982 }
81659c05
AD
983 $query[] = 'ALTER TABLE RackObject DROP COLUMN `barcode`';
984 $query[] = 'ALTER TABLE RackObjectHistory DROP COLUMN `barcode`';
fbeacc34 985 $query[] = 'ALTER TABLE `VLANSwitchTemplate` DROP COLUMN `max_local_vlans`';
81659c05 986 $query[] = "UPDATE Config SET varvalue = '0.19.0' WHERE varname = 'DB_VERSION'";
d3346ce2 987 break;
6d42599c 988 case '0.19.1':
1d5dd3a1
AD
989 $query[] = "ALTER TABLE `Config` CHANGE COLUMN `varvalue` `varvalue` text NOT NULL";
990 $query[] = "ALTER TABLE `UserConfig` CHANGE COLUMN `varvalue` `varvalue` text NOT NULL";
6d42599c 991 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('FILTER_RACKLIST_BY_TAGS','yes','string','yes','no','yes','Rackspace: show only racks matching the current object\'s tags')";
782ad4cd
DO
992 $result = $dbxlink->query ("SHOW TABLES LIKE 'Objectlog'");
993 $rows = $result->fetchAll (PDO::FETCH_ASSOC);
994 unset ($result);
995 if (count ($rows))
996 {
997 # Now the ObjectLog merge... again, because the original table is named
998 # "Objectlog". The job is to merge contents of Objectlog and ObjectLog
999 # into the latter.
1000 $query[] = "INSERT INTO ObjectLog (object_id, user, date, content) SELECT object_id, user, date, content FROM Objectlog WHERE object_id IN(SELECT id FROM RackObject)";
1001 $query[] = "DELETE FROM Objectlog WHERE object_id IN(SELECT id FROM RackObject)";
1002 # Don't delete the old table, if the merge wasn't exhaustive.
1003 $result = $dbxlink->query ('SELECT COUNT(*) AS c FROM Objectlog WHERE object_id NOT IN(SELECT id FROM RackObject)');
1004 $row = $result->fetch (PDO::FETCH_ASSOC);
1005 unset ($result);
1006 if ($row['c'] == 0)
1007 $query[] = 'DROP TABLE Objectlog';
1008 else
1009 $query[] = 'ALTER TABLE Objectlog RENAME TO Objectlog_old_unmerged';
1010 }
6d42599c
AA
1011 $query[] = "UPDATE Config SET varvalue = '0.19.1' WHERE varname = 'DB_VERSION'";
1012 break;
f701420b 1013 case '0.19.2':
f701420b
AA
1014 $query[] = "ALTER TABLE IPv4Allocation ADD KEY `ip` (`ip`)";
1015 $query[] = "ALTER TABLE IPv6Allocation ADD KEY `ip` (`ip`)";
1016 $query[] = "ALTER TABLE IPv4VS ADD KEY `vip` (`vip`)";
1017 $query[] = "ALTER TABLE IPv4RS ADD KEY `rsip` (`rsip`)";
ae67fa11
AD
1018 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (34,'no','power supply chassis models')";
1019 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES (35,'no','power supply models')";
1020 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1397,1,NULL)";
1021 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1397,2,34)";
1022 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1397,14,NULL)";
1023 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1397,21,NULL)";
1024 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1397,22,NULL)";
1025 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1398,1,NULL)";
1026 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1398,2,35)";
1027 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1398,14,NULL)";
1028 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1398,21,NULL)";
1029 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`) VALUES (1398,22,NULL)";
1030 $query[] = "INSERT INTO `ObjectParentCompat` (`parent_objtype_id`, `child_objtype_id`) VALUES (1397,1398)";
1031 $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (1399,1399)";
1032 $query[] = "INSERT INTO `PortInterfaceCompat` (`iif_id`, `oif_id`) VALUES (1,1399)";
1033 $query[] = "UPDATE Config SET varvalue = CONCAT(varvalue, ' or {\$typeid_1397}') WHERE varname = 'IPV4OBJ_LISTSRC'";
c4ad9ac0
AA
1034 $query[] = "ALTER TABLE AttributeValue ADD KEY `attr_id-uint_value` (`attr_id`,`uint_value`)";
1035 $query[] = "ALTER TABLE AttributeValue ADD KEY `attr_id-string_value` (`attr_id`,`string_value`(12))";
0abae5fb 1036 $query[] = "UPDATE Config SET varvalue = '0.19.2' WHERE varname = 'DB_VERSION'";
f701420b 1037 break;
6d2cc13e 1038 case '0.19.3':
6d2cc13e
DO
1039 $query[] = "DELETE FROM RackSpace WHERE object_id IS NULL AND state = 'T'";
1040 $query[] = "UPDATE Config SET varvalue = '0.19.3' WHERE varname = 'DB_VERSION'";
1041 break;
1f02e311 1042 case '0.19.4':
1f02e311
AD
1043 $query[] = "UPDATE Config SET varvalue = '0.19.4' WHERE varname = 'DB_VERSION'";
1044 break;
e1486971 1045 case '0.19.5':
e1486971
DO
1046 // Add 'virtual port' to 'virtual port' mapping
1047 $query[] = "INSERT INTO `PortCompat` (`type1`,`type2`) VALUES (1469,1469)";
1048 $query[] = "INSERT INTO `PortInterfaceCompat` (`iif_id`,`oif_id`) VALUES (1,1469)";
25b8a91f
AA
1049 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('SSH_OBJS_LISTSRC','none','string','yes','no','yes','Rackcode filter for SSH-managed objects')";
1050 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('TELNET_OBJS_LISTSRC','none','string','yes','no','yes','Rackcode filter for telnet-managed objects')";
7d91adc7 1051 $query[] = "UPDATE Link SET cable = NULL WHERE cable = ''";
42b4722b 1052 $query[] = "ALTER TABLE AttributeValue MODIFY string_value char(255) DEFAULT NULL";
e1486971
DO
1053 $query[] = "UPDATE Config SET varvalue = '0.19.5' WHERE varname = 'DB_VERSION'";
1054 break;
2a3a1a6d 1055 case '0.19.6':
2a3a1a6d
AA
1056 $query[] = "UPDATE Config SET varvalue = '0.19.6' WHERE varname = 'DB_VERSION'";
1057 break;
b1bde5f6 1058 case '0.19.7':
b1bde5f6
AD
1059 # A plain "ALTER TABLE Attribute" can leave AUTO_INCREMENT in an odd
1060 # state, hence the table swap.
1061 $query[] = "
1062CREATE TABLE `Attribute_new` (
1063 `id` int(10) unsigned NOT NULL auto_increment,
1064 `type` enum('string','uint','float','dict') default NULL,
1065 `name` char(64) default NULL,
1066 PRIMARY KEY (`id`),
1067 UNIQUE KEY `name` (`name`)
1068) ENGINE=InnoDB
1069";
1070 $query[] = "INSERT INTO Attribute_new SELECT * FROM Attribute";
1071 $query[] = "INSERT INTO Attribute_new VALUES (9999, 'string', 'base MAC address')";
1072 $query[] = "DROP TABLE Attribute";
1073 $query[] = "ALTER TABLE Attribute_new RENAME TO Attribute";
1074 $query[] = "ALTER TABLE AttributeMap ADD KEY (attr_id)";
1075 $query[] = "DELETE FROM AttributeMap WHERE attr_id NOT IN (SELECT id FROM Attribute)";
1076 $query[] = "ALTER TABLE AttributeMap ADD CONSTRAINT `AttributeMap-FK-attr_id` FOREIGN KEY (attr_id) REFERENCES Attribute (id)";
1077 $query[] = "DELETE FROM AttributeValue WHERE attr_id NOT IN (SELECT attr_id FROM AttributeMap)";
1078 $query[] = "ALTER TABLE AttributeValue ADD CONSTRAINT `AttributeValue-FK-attr_id` FOREIGN KEY (attr_id) REFERENCES AttributeMap (attr_id)";
1079 $query[] = "INSERT INTO `ObjectParentCompat` (`parent_objtype_id`, `child_objtype_id`) VALUES (1506,4)";
44cbeb2e
DO
1080 $query[] = "INSERT INTO PortInnerInterface (id, iif_name) VALUES (10, 'QSFP+')";
1081 $query[] = "INSERT INTO PortInterfaceCompat VALUES (10, 1588)";
b1bde5f6
AD
1082 $query[] = "UPDATE Config SET varvalue = '0.19.7' WHERE varname = 'DB_VERSION'";
1083 break;
a03332f7 1084 case '0.19.8':
3aca495a
DO
1085 for ($i = 1424; $i <= 1466; $i++) # CX, then 42 ER channels
1086 $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (${i},${i})";
c7968df3
DO
1087 $query[] = "ALTER TABLE UserAccount ENGINE=InnoDB";
1088 $query[] = "DELETE FROM UserConfig WHERE user NOT IN (SELECT user_name FROM UserAccount)";
1089 $query[] = "ALTER TABLE UserConfig ADD CONSTRAINT `UserConfig-FK-user` FOREIGN KEY (user) REFERENCES UserAccount (user_name) ON DELETE CASCADE";
1090 $query[] = "DELETE FROM UserConfig WHERE varname NOT IN (SELECT varname FROM Config)";
1091 $query[] = "ALTER TABLE UserConfig ADD KEY (varname)";
1092 $query[] = "ALTER TABLE UserConfig ADD CONSTRAINT `UserConfig-FK-varname` FOREIGN KEY (varname) REFERENCES Config (varname) ON DELETE CASCADE";
a03332f7 1093 $query[] = "ALTER TABLE Dictionary ENGINE=InnoDB";
c7968df3
DO
1094 $query[] = "ALTER TABLE Chapter ENGINE=InnoDB";
1095 $query[] = "UPDATE Chapter SET id = 9999 WHERE id = 22";
1096 $query[] = "UPDATE AttributeMap SET chapter_id = 9999 WHERE chapter_id = 22";
1097 $query[] = "UPDATE Dictionary SET chapter_id = 9999 WHERE chapter_id = 22";
1098 $query[] = "DELETE FROM Dictionary WHERE chapter_id NOT IN (SELECT id FROM Chapter)";
1099 $query[] = "ALTER TABLE Dictionary ADD CONSTRAINT `Dictionary-FK-chapter_id` FOREIGN KEY (chapter_id) REFERENCES Chapter (id)";
1100 $query[] = "DELETE FROM AttributeMap WHERE chapter_id NOT IN (SELECT id FROM Chapter)";
1101 $query[] = "ALTER TABLE AttributeMap ADD KEY (chapter_id)";
1102 $query[] = "ALTER TABLE AttributeMap ADD CONSTRAINT `AttributeMap-FK-chapter_id` FOREIGN KEY (chapter_id) REFERENCES Chapter (id)";
c09757f6
DO
1103 $query[] = "
1104CREATE TABLE `CactiGraph` (
1105 `object_id` int(10) unsigned NOT NULL,
1106 `graph_id` int(10) unsigned NOT NULL,
1107 `caption` char(255) DEFAULT NULL,
1108 PRIMARY KEY (`graph_id`),
1109 KEY `object_id` (`object_id`),
1110 CONSTRAINT `CactiGraph-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `Object` (`id`) ON DELETE CASCADE
1111) ENGINE=InnoDB;
1112";
1113 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('CACTI_LISTSRC','false','string','yes','no','no','List of object with Cacti graphs')";
1114 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('CACTI_URL','','string','yes','no','no','Cacti server base URL')";
1115 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('CACTI_USERNAME','','string','yes','no','no','Cacti user account')";
1116 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('CACTI_USERPASS','','string','yes','no','no','Cacti user password')";
a03332f7
DO
1117 $query[] = "UPDATE Config SET varvalue = '0.19.8' WHERE varname = 'DB_VERSION'";
1118 break;
5c0bd7de 1119 case '0.19.9':
5c0bd7de 1120 $query[] = "DELETE FROM Config WHERE varname = 'HNDP_RUNNERS_LISTSRC'";
8920f7f5
DO
1121 # Dismiss some overly-specific OIF types in favour of more generic counterparts.
1122 $squeeze = array
1123 (
1124 1202 => array # 1000Base-SX
1125 (
1126 25, # 1000Base-SX (SC)
1127 26, # 1000Base-SX (LC)
1128 ),
1129 1204 => array # 1000Base-LX
1130 (
1131 27, # 1000Base-LX (SC)
1132 28, # 1000Base-LX (LC)
1133 ),
1134 1196 => array # 100Base-SX
1135 (
1136 22, # 100Base-SX (SC)
1137 23, # 100Base-SX (LC)
1138 ),
1139 1195 => array # 100Base-FX
1140 (
1141 20, # 100Base-FX (SC)
1142 21, # 100Base-FX (LC)
1143 1083, # 100Base-FX (MT-RJ)
1144 ),
1145 );
1146 foreach ($squeeze as $stays => $leaves)
1147 {
1148 $csv = implode (', ', $leaves);
1149 $query[] = "DELETE FROM PortCompat WHERE type1 IN(${csv}) OR type2 IN(${csv})";
1150 $query[] = "INSERT IGNORE INTO PortInterfaceCompat (iif_id, oif_id) SELECT iif_id, ${stays} FROM Port WHERE type IN (${csv})";
1151 $query[] = "UPDATE Port SET type = ${stays} WHERE type IN(${csv})";
1152 $query[] = "DELETE FROM PortInterfaceCompat WHERE oif_id IN(${csv})";
1153 }
fd8de939
DO
1154 $query[] = "UPDATE Config SET varvalue = '0.19.9' WHERE varname = 'DB_VERSION'";
1155 break;
f7494e3c 1156 case '0.19.10':
f7494e3c
DO
1157 $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (1603,1603)";
1158 $query[] = "UPDATE Config SET varvalue = '0.19.10' WHERE varname = 'DB_VERSION'";
1159 break;
d0004c46 1160 case '0.19.11':
8dc2a6c8 1161 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('VIRTUAL_OBJ_LISTSRC','1504,1505,1506,1507','string','no','no','no','List source: virtual objects')";
453cce7e
AD
1162 $query[] = "INSERT INTO `Attribute` (`id`,`type`,`name`) VALUES (28,'string','Slot number')";
1163 $query[] = 'INSERT INTO `AttributeMap` (`objtype_id`,`attr_id`,`chapter_id`) VALUES (4,28,NULL)';
1164 $query[] = 'INSERT INTO `AttributeMap` (`objtype_id`,`attr_id`,`chapter_id`) VALUES (8,28,NULL)';
1165 $query[] = 'INSERT INTO `AttributeMap` (`objtype_id`,`attr_id`,`chapter_id`) VALUES (798,28,NULL)';
1166 $query[] = 'INSERT INTO `AttributeMap` (`objtype_id`,`attr_id`,`chapter_id`) VALUES (1055,28,NULL)';
7d68a0fb
DO
1167 $query[] = 'ALTER TABLE AttributeValue ADD COLUMN object_tid int(10) unsigned NOT NULL default 0 AFTER object_id';
1168 $query[] = 'UPDATE AttributeValue SET object_tid = (SELECT objtype_id FROM Object WHERE id = object_id)';
1169 $query[] = 'ALTER TABLE AttributeValue DROP FOREIGN KEY `AttributeValue-FK-attr_id`';
1170 $query[] = 'ALTER TABLE AttributeValue DROP FOREIGN KEY `AttributeValue-FK-object_id`';
1171 $query[] = 'ALTER TABLE AttributeValue ADD KEY `id-tid` (object_id, object_tid)';
1172 $query[] = 'ALTER TABLE AttributeValue ADD KEY `object_tid-attr_id` (`object_tid`,`attr_id`)';
1173 $query[] = 'ALTER TABLE Object ADD KEY `id-tid` (id, objtype_id)';
09a85f19 1174 $query[] = 'ALTER TABLE AttributeValue ADD CONSTRAINT `AttributeValue-FK-object` FOREIGN KEY (`object_id`, `object_tid`) REFERENCES `Object` (`id`, `objtype_id`) ON DELETE CASCADE ON UPDATE CASCADE';
7d68a0fb 1175 $query[] = 'ALTER TABLE AttributeValue ADD CONSTRAINT `AttributeValue-FK-map` FOREIGN KEY (`object_tid`, `attr_id`) REFERENCES `AttributeMap` (`objtype_id`, `attr_id`)';
9e906292
DO
1176 # 0.19.9 did it right, but kept the IDs in the dictionary. This time
1177 # the dictionary is reduced, but the procedure needs to be repeated,
1178 # in case the user had enough time to use the wrong IDs again.
1179 $squeeze = array
1180 (
1181 1202 => array # 1000Base-SX
1182 (
1183 25, # 1000Base-SX (SC)
1184 26, # 1000Base-SX (LC)
1185 ),
1186 1204 => array # 1000Base-LX
1187 (
1188 27, # 1000Base-LX (SC)
1189 28, # 1000Base-LX (LC)
1190 ),
1191 1196 => array # 100Base-SX
1192 (
1193 22, # 100Base-SX (SC)
1194 23, # 100Base-SX (LC)
1195 ),
1196 1195 => array # 100Base-FX
1197 (
1198 20, # 100Base-FX (SC)
1199 21, # 100Base-FX (LC)
1200 1083, # 100Base-FX (MT-RJ)
1201 ),
1202 );
1203 foreach ($squeeze as $stays => $leaves)
1204 {
1205 $csv = implode (', ', $leaves);
1206 $query[] = "DELETE FROM PortCompat WHERE type1 IN(${csv}) OR type2 IN(${csv})";
1207 $query[] = "INSERT IGNORE INTO PortInterfaceCompat (iif_id, oif_id) SELECT iif_id, ${stays} FROM Port WHERE type IN (${csv})";
1208 $query[] = "UPDATE Port SET type = ${stays} WHERE type IN(${csv})";
1209 $query[] = "DELETE FROM PortInterfaceCompat WHERE oif_id IN(${csv})";
1210 }
18680729 1211 $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (1642,1642)";
d6e7a8e7 1212 $query[] = 'ALTER TABLE `EntityLink` ADD KEY `EntityLink-compound` (`parent_entity_type`,`child_entity_type`,`child_entity_id`)';
d0004c46
AD
1213 $query[] = "UPDATE Config SET varvalue = '0.19.11' WHERE varname = 'DB_VERSION'";
1214 break;
a4c50c50 1215 case '0.19.12':
f6252853 1216 $query[] = "DELETE FROM Config WHERE varname IN('color_F', 'color_A', 'color_U', 'color_T', 'color_Th', 'color_Tw', 'color_Thw')";
2ce1cbdb
DO
1217 $query[] = "INSERT INTO Chapter (id, sticky, name) VALUES (36,'no','serial console server models')";
1218 $query[] = "INSERT INTO AttributeMap (objtype_id, attr_id, chapter_id) VALUES (1644, 1, NULL), (1644, 2, 36), (1644, 3, NULL)";
e7311c79 1219 $query[] = "UPDATE Config SET varvalue = CONCAT (varvalue, '; 10=1588') WHERE varname = 'DEFAULT_PORT_OIF_IDS' AND 0 = INSTR (varvalue, '10=') ";
55732b46
DO
1220 $query[] = "INSERT INTO PortInterfaceCompat VALUES (10,1663), (10,1664)";
1221 $query[] = "INSERT INTO PortCompat VALUES (1588,1588), (1661,1661), (1663,1663), (1664,1664)";
833583b5
DO
1222 $query[] = "INSERT INTO PortInnerInterface (id, iif_name) VALUES (11, 'CFP')";
1223 $query[] = "INSERT INTO PortInterfaceCompat (iif_id, oif_id) VALUES (11,1668),(11,1669),(11,1670),(11,1671)";
1224 $query[] = "INSERT INTO PortCompat (type1, type2) VALUES (1668,1668), (1669,1669), (1670,1670), (1671,1671)";
1225 $query[] = "UPDATE Config SET varvalue = CONCAT (varvalue, '; 11=1668') WHERE varname = 'DEFAULT_PORT_OIF_IDS'";
0c652e58
DO
1226 $query[] = "INSERT INTO Chapter (id, sticky, name) VALUES (37, 'no', 'wireless OS type')";
1227 $query[] = "INSERT INTO AttributeMap (objtype_id, attr_id, chapter_id) VALUES (965, 4, 37)";
a4c50c50
DO
1228 $query[] = "UPDATE Config SET varvalue = '0.19.12' WHERE varname = 'DB_VERSION'";
1229 break;
fd8de939 1230 case '0.20.0':
fd8de939
DO
1231 $query[] = "
1232CREATE TABLE `PortLog` (
1233 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
1234 `port_id` int(10) unsigned NOT NULL,
1235 `date` datetime NOT NULL,
1236 `user` varchar(64) NOT NULL,
1237 `message` text NOT NULL,
1238 PRIMARY KEY (`id`),
1239 KEY `port_id-date` (`port_id`,`date`),
1240 CONSTRAINT `PortLog_ibfk_1` FOREIGN KEY (`port_id`) REFERENCES `Port` (`id`) ON DELETE CASCADE
1241) ENGINE=InnoDB;
1242";
1243 $query[] = "
1244CREATE TABLE `IPv4Log` (
1245 `id` int(10) NOT NULL AUTO_INCREMENT,
1246 `ip` int(10) unsigned NOT NULL,
1247 `date` datetime NOT NULL,
1248 `user` varchar(64) NOT NULL,
1249 `message` text NOT NULL,
1250 PRIMARY KEY (`id`),
1251 KEY `ip-date` (`ip`,`date`)
1252) ENGINE=InnoDB;
4318ced5
AA
1253";
1254 $query[] = "
1255CREATE TABLE `IPv6Log` (
1256 `id` int(10) NOT NULL AUTO_INCREMENT,
1257 `ip` binary(16) NOT NULL,
1258 `date` datetime NOT NULL,
1259 `user` varchar(64) NOT NULL,
1260 `message` text NOT NULL,
1261 PRIMARY KEY (`id`),
1262 KEY `ip-date` (`ip`,`date`)
1263) ENGINE=InnoDB;
fd8de939 1264";
cc3d6915 1265 $query[] = "ALTER TABLE TagStorage MODIFY COLUMN entity_realm ENUM('file','ipv4net','ipv4vs','ipv4rspool','object','rack','user','ipv6net','vst') NOT NULL default 'object'";
30bb83bd 1266 $query[] = "ALTER TABLE `TagStorage` ADD COLUMN `user` char(64) DEFAULT NULL, ADD COLUMN `date` datetime DEFAULT NULL";
9b8174d7
AD
1267
1268 // Rename object tables and keys
1269 $dbxlink->query ('ALTER TABLE `RackObject` RENAME TO `Object`');
1270 $dbxlink->query ('ALTER TABLE `RackObjectHistory` RENAME TO `ObjectHistory`');
1271 $query[] = 'ALTER TABLE `Object` DROP KEY `RackObject_asset_no`';
1272 $query[] = 'ALTER TABLE `Object` ADD UNIQUE KEY `asset_no` (`asset_no`)';
bd7c95ce 1273 $query[] = 'ALTER TABLE `Object` ADD KEY `type_id` (`objtype_id`,`id`)';
9b8174d7
AD
1274 $query[] = 'ALTER TABLE `ObjectHistory` DROP FOREIGN KEY `RackObjectHistory-FK-object_id`';
1275 $query[] = 'ALTER TABLE `ObjectHistory` ADD CONSTRAINT `ObjectHistory-FK-object_id` FOREIGN KEY (`id`) REFERENCES `Object` (`id`) ON DELETE CASCADE';
1276 $query[] = 'ALTER TABLE `RackSpace` DROP FOREIGN KEY `RackSpace-FK-rack_id`';
9b8174d7 1277 // Rack height is now an attribute
a14f752c 1278 $query[] = "INSERT INTO `Attribute` (`id`,`type`,`name`) VALUES (27,'uint','Height, units')";
9b8174d7
AD
1279 $query[] = 'INSERT INTO `AttributeMap` (`objtype_id`,`attr_id`,`chapter_id`) VALUES (1560,27,NULL)';
1280 // Turn rows into objects
1281 $result = $dbxlink->query ('SELECT * FROM RackRow');
1282 $rows = $result->fetchAll (PDO::FETCH_ASSOC);
1283 unset ($result);
1284 foreach ($rows as $row)
1285 {
3daa26fd 1286 $prepared = $dbxlink->prepare ('INSERT INTO `Object` (`label`,`objtype_id`) VALUES (?,?)');
9b8174d7
AD
1287 $prepared->execute (array($row['name'], 1561));
1288 $row_id = $dbxlink->lastInsertId();
1289 // Turn all racks in this row into objects
1290 $result = $dbxlink->query ("SELECT id, name, height, comment FROM Rack WHERE row_id=${row['id']}");
1291 $racks = $result->fetchAll (PDO::FETCH_ASSOC);
1292 unset ($result);
1293 foreach ($racks as $rack)
1294 {
1295 // Add the rack as an object, set the height as an attribute, link the rack to the row,
9374831b 1296 // update rackspace, tags and files to reflect new rack_id, move history
a14f752c 1297 $prepared = $dbxlink->prepare ('INSERT INTO `Object` (`label`,`objtype_id`,`comment`) VALUES (?,?,?)');
9b8174d7
AD
1298 $prepared->execute (array($rack['name'], 1560, $rack['comment']));
1299 $rack_id = $dbxlink->lastInsertId();
1300 $query[] = "INSERT INTO `AttributeValue` (`object_id`,`attr_id`,`uint_value`) VALUES (${rack_id},27,${rack['height']})";
1301 $query[] = "INSERT INTO `EntityLink` (`parent_entity_type`,`parent_entity_id`,`child_entity_type`,`child_entity_id`) VALUES ('object',${row_id},'object',${rack_id})";
1302 $query[] = "UPDATE `RackSpace` SET `rack_id`=${rack_id} WHERE `rack_id`=${rack['id']}";
1f02e311 1303 $query[] = "UPDATE `Atom` SET `rack_id`=${rack_id} WHERE `rack_id`=${rack['id']}";
c718f1e2
AA
1304 $query[] = "UPDATE `TagStorage` SET `entity_id`=${rack_id} WHERE `entity_realm`='rack' AND `entity_id`=${rack['id']}";
1305 $query[] = "UPDATE `FileLink` SET `entity_id`=${rack_id} WHERE `entity_type`='rack' AND `entity_id`=${rack['id']}";
9b8174d7
AD
1306 $query[] = "INSERT INTO `ObjectHistory` (`id`,`name`,`objtype_id`,`comment`,`ctime`,`user_name`) SELECT ${rack_id},`name`,1560,`comment`,`ctime`,`user_name` FROM `RackHistory` WHERE `id`=${rack['id']}";
1307 }
1308 }
9374831b 1309 $query[] = 'ALTER TABLE `RackSpace` ADD CONSTRAINT `RackSpace-FK-rack_id` FOREIGN KEY (`rack_id`) REFERENCES `Object` (`id`)';
9b8174d7
AD
1310 $query[] = 'DROP TABLE `Rack`';
1311 $query[] = 'DROP TABLE `RackRow`';
1312 $query[] = 'DROP TABLE `RackHistory`';
1313 $query[] = "
1314CREATE TABLE `RackThumbnail` (
1315 `rack_id` int(10) unsigned NOT NULL,
1316 `thumb_data` blob,
1317 UNIQUE KEY `rack_id` (`rack_id`),
1318 CONSTRAINT `RackThumbnail-FK-rack_id` FOREIGN KEY (`rack_id`) REFERENCES `Object` (`id`) ON DELETE CASCADE
1319) ENGINE=InnoDB
1320";
1321 $query[] = "
1f02e311 1322CREATE VIEW `Row` AS SELECT id, label AS name
9b8174d7
AD
1323 FROM `Object`
1324 WHERE objtype_id = 1561
1325";
1326 $query[] = "
1f02e311
AD
1327CREATE VIEW `Rack` AS SELECT O.id, O.label AS name, O.asset_no, O.has_problems, O.comment,
1328 AV.uint_value AS height,
1329 RT.thumb_data,
86cbb632 1330 Row.id AS row_id,
1f02e311
AD
1331 Row.name AS row_name
1332 FROM `Object` O
86cbb632 1333 LEFT JOIN `AttributeValue` AV ON O.id = AV.object_id AND AV.attr_id = 27
1f02e311 1334 LEFT JOIN `RackThumbnail` RT ON O.id = RT.rack_id
86cbb632
AA
1335 LEFT JOIN `EntityLink` EL ON O.id = EL.child_entity_id AND EL.parent_entity_type = 'object' AND EL.child_entity_type = 'object'
1336 INNER JOIN `Row` ON EL.parent_entity_id = Row.id
1337 WHERE O.objtype_id = 1560;
9b8174d7
AD
1338";
1339 $query[] = "
d7e9e25b 1340CREATE VIEW `RackObject` AS SELECT id, name, label, objtype_id, asset_no, has_problems, comment FROM `Object`
9b8174d7
AD
1341 WHERE `objtype_id` NOT IN (1560, 1561, 1562)
1342";
1343 $query[] = "UPDATE `Chapter` SET `name` = 'ObjectType' WHERE `id` = 1";
1344 $query[] = "DELETE FROM RackSpace WHERE object_id IS NULL AND state = 'T'";
2265be00 1345
f1cdc9f1 1346 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('SYNC_802Q_LISTSRC','','string','yes','no','no','List of VLAN switches sync is enabled on')";
76a7ec36 1347 $query[] = "UPDATE `Config` SET is_userdefined='yes' WHERE varname='PROXIMITY_RANGE'";
a1d72d2e 1348 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('QUICK_LINK_PAGES','','string','yes','no','yes','List of pages to dislay in quick links')";
6213dc9f 1349 $query[] = "ALTER TABLE `IPv4LB` MODIFY `prio` varchar(255) DEFAULT NULL";
4ed2310e 1350 $query[] = "ALTER TABLE `IPv4RS` ADD COLUMN `comment` varchar(255) NULL";
ed38c73c 1351 $query[] = "ALTER TABLE `IPv4VS` MODIFY `proto` enum('TCP','UDP','MARK') NOT NULL default 'TCP'";
85e868a0
AA
1352 $query[] = "UPDATE Config SET varvalue = '0.20.0' WHERE varname = 'DB_VERSION'";
1353 break;
d15dae2f
DO
1354 case 'dictionary':
1355 $query = reloadDictionary();
1356 break;
fbbb74fb 1357 default:
28537080 1358 showError ("unknown batch '${batchid}'", __FUNCTION__);
fbbb74fb
DO
1359 die;
1360 break;
1361 }
fbbb74fb 1362 $failures = array();
4114697d 1363 echo "<tr><th>Executing batch '${batchid}'</th><td>";
fbbb74fb
DO
1364 foreach ($query as $q)
1365 {
babe4bf5
AA
1366 try
1367 {
1368 $result = $dbxlink->query ($q);
1369 }
1370 catch (PDOException $e)
758fe24c 1371 {
758fe24c
DO
1372 $errorInfo = $dbxlink->errorInfo();
1373 $failures[] = array ($q, $errorInfo[2]);
1374 }
fbbb74fb 1375 }
fbbb74fb 1376 if (!count ($failures))
4114697d 1377 echo "<strong><font color=green>done</font></strong>";
fbbb74fb
DO
1378 else
1379 {
4114697d 1380 echo "<strong><font color=red>The following queries failed:</font></strong><br><pre>";
fbbb74fb
DO
1381 foreach ($failures as $f)
1382 {
1383 list ($q, $i) = $f;
4114697d 1384 echo "${q} -- ${i}\n";
fbbb74fb 1385 }
4114697d 1386 echo "</pre>";
fbbb74fb 1387 }
4114697d 1388 echo '</td></tr>';
fbbb74fb
DO
1389}
1390
120e9ddd 1391function authenticate_admin ($username, $password)
a1f3710a 1392{
43c7895d 1393 global $dbxlink;
4dd08c61
DO
1394 $prepared = $dbxlink->prepare ('SELECT COUNT(*) FROM UserAccount WHERE user_id=1 AND user_name=? AND user_password_hash=?');
1395 if (!$prepared->execute (array ($username, sha1 ($password))))
a1f3710a 1396 die ('SQL query failed in ' . __FUNCTION__);
4dd08c61 1397 $rows = $prepared->fetchAll (PDO::FETCH_NUM);
43c7895d 1398 return $rows[0][0] == 1;
a1f3710a
DO
1399}
1400
c4ee2310
DO
1401// Database version detector. Should behave corretly on any
1402// working dataset a user might have.
1403function getDatabaseVersion ()
1404{
2f5e4db9
DO
1405 global $dbxlink;
1406 $prepared = $dbxlink->prepare ('SELECT varvalue FROM Config WHERE varname = "DB_VERSION" and vartype = "string"');
1407 if (! $prepared->execute())
c4ee2310 1408 {
c4ee2310 1409 $errorInfo = $dbxlink->errorInfo();
2f5e4db9 1410 die (__FUNCTION__ . ': SQL query failed with error ' . $errorInfo[2]);
c4ee2310 1411 }
2f5e4db9 1412 $rows = $prepared->fetchAll (PDO::FETCH_NUM);
c4ee2310
DO
1413 unset ($result);
1414 if (count ($rows) != 1 || !strlen ($rows[0][0]))
1415 die (__FUNCTION__ . ': Cannot guess database version. Config table is present, but DB_VERSION is missing or invalid. Giving up.');
1416 $ret = $rows[0][0];
1417 return $ret;
1418}
1419
964b0388 1420function showError ($info = '', $location = 'N/A')
c4ee2310
DO
1421{
1422 if (preg_match ('/\.php$/', $location))
1423 $location = basename ($location);
1424 elseif ($location != 'N/A')
1425 $location = $location . '()';
1426 echo "<div class=msg_error>An error has occured in [${location}]. ";
1427 if (!strlen ($info))
1428 echo 'No additional information is available.';
1429 else
1430 echo "Additional information:<br><p>\n<pre>\n${info}\n</pre></p>";
2f5e4db9 1431 echo "Go back or try starting from <a href='index.php'>index page</a>.<br></div>\n";
c4ee2310
DO
1432}
1433
964b0388 1434function renderUpgraderHTML()
99ee5479 1435{
b00cc78c
AA
1436 global $found_secret_file;
1437 if (! $found_secret_file)
1438 die ('<center>There is no working RackTables instance here, <a href="?module=installer">install</a>?</center>');
1439
1440 try
964b0388 1441 {
b00cc78c
AA
1442 connectDB();
1443 }
1444 catch (RackTablesError $e)
1445 {
1446 die ("Database connection failed:\n\n" . $e->getMessage());
1447 }
1448
1449 if
1450 (
1451 !isset ($_SERVER['PHP_AUTH_USER']) or
1452 !strlen ($_SERVER['PHP_AUTH_USER']) or
1453 !isset ($_SERVER['PHP_AUTH_PW']) or
1454 !strlen ($_SERVER['PHP_AUTH_PW']) or
1455 !authenticate_admin ($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])
1456 )
1457 {
1458 header ('WWW-Authenticate: Basic realm="RackTables upgrade"');
1459 header ('HTTP/1.0 401 Unauthorized');
a931fc26
DO
1460?>
1461<h1>Trouble logging in?</h1>
f2b6ae86 1462You are trying to authenticate for the RackTables upgrade screen. This means that
a931fc26
DO
1463you must authenticate with the username and password of the main RackTables
1464administrator. There is only one such account in each installation, its default
1465username is "admin". RackTables wiki provides more information on this topic.
1466<?php
120e9ddd 1467 die;
964b0388 1468 }
fbbb74fb 1469
964b0388 1470?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5f016d39 1471<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
2cf36003 1472<head><title>RackTables upgrade script</title>
964b0388
DO
1473<style type="text/css">
1474.tdleft {
1475 text-align: left;
1476}
1477
1478.trok {
1479 background-color: #80FF80;
1480}
1481
1482.trwarning {
1483 background-color: #FFFF80;
1484}
1485
1486.trerror {
1487 background-color: #FF8080;
1488}
1489</style>
5f016d39
DO
1490</head>
1491<body>
1492<h1>Platform check status</h1>
1493<?php
1494
1495if (!platform_is_ok())
1496 die ('</body></html>');
1497
1498echo '<h1>Upgrade status</h1>';
fbbb74fb 1499$dbver = getDatabaseVersion();
5f016d39 1500echo '<table border=1 cellpadding=5>';
4114697d
DO
1501echo "<tr><th>Current status</th><td>Data version: ${dbver}<br>Code version: " . CODE_VERSION . "</td></tr>\n";
1502
1503$path = getDBUpgradePath ($dbver, CODE_VERSION);
1504if ($path === NULL)
758fe24c 1505{
4114697d 1506 echo "<tr><th>Upgrade path</th><td><font color=red>not found</font></td></tr>\n";
d74ae24c
DO
1507 echo "<tr><th>Summary</th><td>Check README for more information. RackTables releases prior to 0.16.4 ";
1508 echo "must be upgraded to 0.16.4 first.</td></tr>\n";
758fe24c 1509}
4114697d 1510else
5f4027b8 1511{
4114697d
DO
1512 if (!count ($path))
1513 echo "<tr><th>Summary</th><td>Come back later.</td></tr>\n";
1514 else
1515 {
1516 echo "<tr><th>Upgrade path</th><td>${dbver} &rarr; " . implode (' &rarr; ', $path) . "</td></tr>\n";
1517 foreach ($path as $batchid)
4114697d 1518 if (isset ($relnotes[$batchid]))
5ae6d365 1519 echo "<tr><th>Release notes for ${batchid}</th><td><pre>" . $relnotes[$batchid] . "</pre></td></tr>\n";
a12022a9
DO
1520 if (array_key_exists ('reallyreally', $_REQUEST))
1521 {
1522 foreach ($path as $batchid)
1523 executeUpgradeBatch ($batchid);
d15dae2f 1524 executeUpgradeBatch ('dictionary');
a12022a9
DO
1525 echo "<tr><th>Summary</th><td>Upgrade complete, it is Ok to ";
1526 echo "<a href='index.php'>enter</a> the system.</td></tr>\n";
1527 }
1528 else
1529 {
1530 echo '<form method=post action="index.php?module=upgrade"><tr><th>Wait!</th>';
1531 echo '<td><p>RackTables database upgrades sometimes go wrong because of assorted reasons. ';
1532 echo 'It is <strong>highly recommended</strong> to make a database backup before ';
1533 echo 'proceeding any further. <tt>mysqldump</tt> and <tt>PHPMyAdmin</tt> are convenient ';
1534 echo 'tools for doing this.</p>';
1535 echo '<p><input type=checkbox name=reallyreally id=reallyreally><label for=reallyreally>';
1536 echo 'I am ready to bear all risks of this upgrade. I am ready to roll it back in case of ';
1537 echo 'a failure.</label> <input type=submit value="Yes, I am."></p></td></tr></form>';
4114697d 1538 }
4114697d 1539 }
5f4027b8 1540}
4114697d 1541echo '</table>';
5f016d39 1542echo '</body></html>';
964b0388 1543}
fbbb74fb
DO
1544
1545?>