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