r1698 + attach a KVM port to a new console by default
[racktables] / upgrade.php
CommitLineData
b325120a 1<?php
fbbb74fb
DO
2
3// At the moment we assume, that for any two releases we can
4// sequentally execute all batches, that separate them, and
5// nothing will break. If this changes one day, the function
6// below will have to generate smarter upgrade paths, while
7// the upper layer will remain the same.
8// Returning an empty array means that no upgrade is necessary.
9function getDBUpgradePath ($v1, $v2)
10{
a6f83a72
DO
11 $versionhistory = array
12 (
13 '0.14.4',
14 '0.14.5',
15 '0.14.6',
16 '0.14.7',
17 '0.14.8',
18 '0.14.9',
2ff234d6 19 '0.14.10',
2c53a252
DO
20 '0.14.11',
21 '0.14.12'
a6f83a72 22 );
fbbb74fb
DO
23 if (!in_array ($v1, $versionhistory) || !in_array ($v2, $versionhistory))
24 {
25 showError ("An upgrade path has been requested for versions '${v1}' and '${v2}', " .
26 "and at least one of those isn't known to me.");
27 die;
28 }
29 $skip = TRUE;
30 $path = array();
31 // Now collect all versions > $v1 and <= $v2
32 foreach ($versionhistory as $v)
33 {
34 if ($v == $v1)
35 {
36 $skip = FALSE;
37 continue;
38 }
39 if ($skip)
40 continue;
41 $path[] = $v;
42 if ($v == $v2)
43 break;
44 }
45 return $path;
46}
47
48// Upgrade batches are name exactly as the release where they first appear.
49// That simple, but seems sufficient for beginning.
50function executeUpgradeBatch ($batchid)
51{
52 $query = array();
ce109ff2 53 global $dbxlink;
fbbb74fb
DO
54 switch ($batchid)
55 {
56 case '0.14.5':
57 // We can't realiably distinguish between 0.14.4 and 0.14.5, but
58 // luckily the SQL statements below can be safely executed for both.
59
60
61 // This has to be checked once more to be sure IPAddress allocation
62 // conventions are correct.
63 $query[] = "delete from IPAddress where name = '' and reserved = 'no'";
64
65 // In the 0.14.4 release we had AUTO_INCREMENT low in the dictionary and auth
66 // data tables, thus causing new user's data to take primary keys equal to
67 // the values of shipped data in future releases. Let's shift user's data
68 // up and keep DB consistent.
69 $query[] = "alter table Attribute AUTO_INCREMENT = 10000";
70 $query[] = "alter table Chapter AUTO_INCREMENT = 10000";
71 $query[] = "alter table Dictionary AUTO_INCREMENT = 10000";
72 $query[] = "alter table UserAccount AUTO_INCREMENT = 10000";
73 $query[] = "update UserAccount set user_id = user_id + 10000 where user_id between 2 and 10000";
74 $query[] = "update UserPermission set user_id = user_id + 10000 where user_id between 2 and 10000";
75 $query[] = "update Attribute set attr_id = attr_id + 10000 where attr_id between 25 and 10000";
76 $query[] = "update AttributeMap set attr_id = attr_id + 10000 where attr_id between 25 and 10000";
77 $query[] = "update Chapter set chapter_no = chapter_no + 10000 where chapter_no between 21 and 10000";
78 $query[] = "update AttributeMap set chapter_no = chapter_no + 10000 where chapter_no between 21 and 10000";
79 break; // --------------------------------------------
80 case '0.14.6':
81 // This version features new dictionary entries, the correction above should allow us
82 // inject them w/o a problem.
83 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (13,25,'FreeBSD 1.x')";
84 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (13,26,'FreeBSD 2.x')";
85 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (13,27,'FreeBSD 3.x')";
86 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (13,28,'FreeBSD 4.x')";
87 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (13,29,'FreeBSD 5.x')";
88 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (13,30,'FreeBSD 6.x')";
89 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (13,31,'RHFC8')";
90 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (13,32,'ALTLinux Master 4.0')";
91 $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (20,20)";
92 $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (21,21)";
93 $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (22,22)";
94 $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (23,23)";
95 $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (24,24)";
96 $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (25,25)";
97 $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (26,26)";
98 $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (27,27)";
99 $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (28,28)";
100 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (2,20,'KVM')";
101 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (2,21,'1000Base-ZX')";
102 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (2,22,'10GBase-ER')";
103 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (2,23,'10GBase-LR')";
104 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (2,24,'10GBase-LRM')";
105 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (2,25,'10GBase-ZR')";
106 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (2,26,'10GBase-LX4')";
107 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (2,27,'10GBase-CX4')";
108 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (2,28,'10GBase-Kx')";
109 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (12,114,'Cisco Catalyst 2970G-24T')";
110 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (12,115,'Cisco Catalyst 2970G-24TS')";
111 $query[] = "INSERT INTO `UserPermission` (`user_id`, `page`, `tab`, `access`) VALUES (0,'help','%','yes')";
112 // And 0.14.6 is the first release, which features Config table. Let's create
113 // and fill it with default values.
114 $query[] = "
115CREATE TABLE `Config` (
116 `varname` char(32) NOT NULL,
117 `varvalue` char(64) NOT NULL,
118 `vartype` enum('string','uint') NOT NULL default 'string',
119 `emptyok` enum('yes','no') NOT NULL default 'no',
120 `is_hidden` enum('yes','no') NOT NULL default 'yes',
121 `description` text,
122 PRIMARY KEY (`varname`)
123) ENGINE=MyISAM DEFAULT CHARSET=latin1
124 ";
125 $query[] = "INSERT INTO `Config` VALUES ('rtwidth_0','9','uint','no','yes','')";
126 $query[] = "INSERT INTO `Config` VALUES ('rtwidth_1','21','uint','no','yes','')";
127 $query[] = "INSERT INTO `Config` VALUES ('rtwidth_2','9','uint','no','yes','')";
128 $query[] = "INSERT INTO `Config` VALUES ('color_F','8fbfbf','string','no','no','HSV: 180-25-75. Free atoms, they are available for allocation to objects.')";
129 $query[] = "INSERT INTO `Config` VALUES ('color_A','bfbfbf','string','no','no','HSV: 0-0-75. Absent atoms.')";
130 $query[] = "INSERT INTO `Config` VALUES ('color_U','bf8f8f','string','no','no','HSV: 0-25-75. Unusable atoms. Some problems keep them from being free.')";
131 $query[] = "INSERT INTO `Config` VALUES ('color_T','408080','string','no','no','HSV: 180-50-50. Taken atoms, object_id should be set for such.')";
132 $query[] = "INSERT INTO `Config` VALUES ('color_Th','80ffff','string','no','no','HSV: 180-50-100. Taken atoms with highlight. They are not stored in the database and are only used for highlighting.')";
133 $query[] = "INSERT INTO `Config` VALUES ('color_Tw','804040','string','no','no','HSV: 0-50-50. Taken atoms with object problem. This is detected at runtime.')";
134 $query[] = "INSERT INTO `Config` VALUES ('color_Thw','ff8080','string','no','no','HSV: 0-50-100. An object can be both current and problematic. We run highlightObject() first and markupObjectProblems() second.')";
135 $query[] = "INSERT INTO `Config` VALUES ('default_port_type','11','uint','no','no','Default value for port type selects.')";
136 $query[] = "INSERT INTO `Config` VALUES ('MASSCOUNT','15','uint','no','no','Number of lines in object mass-adding form.')";
137 $query[] = "INSERT INTO `Config` VALUES ('MAXSELSIZE','30','uint','no','no','Maximum size of a SELECT HTML element.')";
138 $query[] = "INSERT INTO `Config` VALUES ('enterprise','MyCompanyName','string','no','no','Fit to your needs.')";
139 $query[] = "INSERT INTO `Config` VALUES ('NAMEFUL_OBJTYPES','4,7,8','string','yes','no','These are the object types, which assume a common name to be normally configured. If a name is absent for an object of one of such types, HTML output is corrected to accent this misconfiguration.')";
140 $query[] = "INSERT INTO `Config` VALUES ('ROW_SCALE','2','uint','no','no','Row-scope picture scale factor.')";
141 $query[] = "INSERT INTO `Config` VALUES ('PORTS_PER_ROW','12','uint','no','yes','Max switch port per one row on the switchvlans dynamic tab.')";
142 $query[] = "INSERT INTO `Config` VALUES ('DB_VERSION','0.14.6','string','no','yes','Database version.')";
143 break; // --------------------------------------------
803338c1 144 case '0.14.7':
ce109ff2 145 // IPAddress is hopefully fixed now finally.
803338c1 146 $query[] = "delete from IPAddress where name = '' and reserved != 'yes'";
ce109ff2
DO
147
148 // Now rebuild the dictionary into a new table with the same data,
149 // but proper indexing. We are going to convert compound index
150 // into 1-field one to employ AUTO_INCREMENT properly. This means
151 // renumbering lots of records in Dictionary and adjusting records
152 // in related tables. After that we can safely swap the tables.
9bf70f70
DO
153 $query[] = "
154CREATE TABLE `Dictionary_0_14_7_new` (
155 `chapter_no` int(10) unsigned NOT NULL,
156 `dict_key` int(10) unsigned NOT NULL auto_increment,
157 `dict_value` char(128) default NULL,
158 PRIMARY KEY (`dict_key`),
159 UNIQUE KEY `chap_to_key` (`chapter_no`,`dict_key`),
160 UNIQUE KEY `chap_to_val` (`chapter_no`,`dict_value`)
161) TYPE=MyISAM AUTO_INCREMENT=50000
162";
ce109ff2 163
758fe24c 164echo '<pre>';
ce109ff2
DO
165 // Find all chapter numbers, which will require AttributeValue adjustment.
166 $q2 = 'select distinct chapter_no from AttributeMap where chapter_no != 0';
167 $r2 = $dbxlink->query ($q2);
758fe24c
DO
168 $chaplist = array();
169 while ($row = $r2->fetch (PDO::FETCH_NUM))
170 $chaplist[] = $row[0];
ce109ff2 171 $r2->closeCursor();
758fe24c 172 unset ($r2);
ce109ff2
DO
173
174 $stock = array();
175 // Below I list the records, which are known to be the stock
176 // dictionary records of 0.14.6 release.
177 $stock[1] = array
178 (
179 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16
180 );
181 $stock[2] = array
182 (
183 3, 4, 5, 6, 7, 8, 9,
184 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
185 20, 21, 22, 23, 24, 25, 26, 27, 28
186 );
187 $stock[11] = array
188 (
189 1, 3, 4, 5, 6, 7, 8, 9,
190 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
191 21, 22, 24, 25, 26, 27, 28, 29,
192 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
193 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
194 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
195 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
196 70, 71, 72, 73, 74, 75, 76
197 );
198 $stock[12] = array
199 (
200 1, 11, 13, 14, 15, 16, 17, 18, 19, 20, 26, 29,
201 31, 32, 33, 34, 35, 36, 37, 38, 39,
202 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
203 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
204 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
205 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
206 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
207 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
208 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
db1147d2 209 110, 111, 112, 113, 114, 115
ce109ff2
DO
210 );
211 $stock[13] = array
212 (
213 1, 2, 3, 4, 5, 6, 7, 8, 9,
214 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
215 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
216 30, 31, 32
217 );
218 $stock[14] = array
219 (
220 1, 2, 9, 11, 13, 15, 19, 20, 21, 22
221 );
222 $stock[16] = array
223 (
224 1, 2, 3, 4, 5, 6, 7, 8
225 );
226 $stock[17] = array
227 (
228 1, 2, 3, 4, 5, 6, 7, 8, 9,
229 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
230 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
231 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
232 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
233 50
234 );
235 $stock[18] = array
236 (
237 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
238 );
239 $stock[19] = array
240 (
241 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
242 );
243 $stock[20] = array
244 (
245 1, 2
246 );
247
248 // Load dictionary and transform into two tree structures for
249 // stock and user record sets.
250 $dict = array();
264b07b4 251 $q3 = 'select chapter_no, dict_key, dict_value from Dictionary order by chapter_no, dict_key';
ce109ff2
DO
252 $r3 = $dbxlink->query ($q3);
253
9e7f8a4b 254 while ($row = $r3->fetch (PDO::FETCH_ASSOC))
ce109ff2
DO
255 {
256 $tree = 'user';
257 $dict_key = $row['dict_key'];
258 $chapter_no = $row['chapter_no'];
259 switch ($chapter_no)
260 {
261 case 1: // RackObjectType
262 case 2: // PortType
263 case 11: // server models
264 case 12: // network switch models
265 case 13: // server OS type
266 case 14: // network switch OS type
267 case 16: // router OS type
268 case 17: // router models
269 case 18: // disk array models
270 case 19: // tape library models
271 case 20: // Protocols
272 if (in_array ($dict_key, $stock[$chapter_no]))
273 $tree = 'stock';
274 break;
275 }
a07a39b1 276 $dict[$tree][$chapter_no][$dict_key] = array ('value' => $row['dict_value']);
ce109ff2
DO
277 }
278 $r3->closeCursor();
758fe24c 279 unset ($r3);
ce109ff2
DO
280
281
282 // Now we store stock dataset first, bump up key value and store
283 // user's data. After that we will know the new dict_key for all
284 // records.
285 // The result of both datasets processing is saved in $new_dict.
286 // Save on calling LAST_ISERT_ID() each time by keeping own key.
287 $newkey = 1;
288 $new_dict = array();
289 foreach ($dict['stock'] as $chapter_no => $words)
290 {
291 $new_dict[$chapter_no] = array();
292 foreach ($words as $dict_key => $entry)
293 {
1b5942be 294 $query[] = "insert into Dictionary_0_14_7_new (chapter_no, dict_key, dict_value) " .
ce109ff2
DO
295 "values (${chapter_no}, ${newkey}, '${entry['value']}')";
296 $new_dict[$chapter_no][$dict_key] = $entry;
297 $new_dict[$chapter_no][$dict_key]['newkey'] = $newkey;
298 $newkey++;
299 }
300 }
e7882270 301 $newkey = 50000;
ce109ff2
DO
302 foreach ($dict['user'] as $chapter_no => $words)
303 {
304 // Some chapters may appear on the user dataset only.
305 if (!isset ($new_dict[$chapter_no]))
306 $new_dict[$chapter_no] = array();
307 foreach ($words as $dict_key => $entry)
308 {
309 $query[] = "insert into Dictionary_0_14_7_new " .
310 "values (${chapter_no}, ${newkey}, '${entry['value']}')";
311 $new_dict[$chapter_no][$dict_key] = $entry;
312 $new_dict[$chapter_no][$dict_key]['newkey'] = $newkey;
313 $newkey++;
314 }
315 }
316 // The new table should now have adequate AUTO_INCREMENT w/o our care.
758fe24c
DO
317 // Install the new data.
318 $query[] = 'drop table Dictionary';
319 $query[] = 'alter table Dictionary_0_14_7_new rename to Dictionary';
ce109ff2
DO
320
321 // Now we iterate over the joint dataset, picking some chapters and
322 // performing additional processing:
323 // 1 (RackObjectType) --- adjust RackObject and regenerate AttributeMap
a07a39b1 324 // 2 (PortType) --- adjust Port and regenerate PortCompat (at a latter point)
ce109ff2
DO
325 // 3 (RackRow) --- adjust Rack
326 // 20 (Protocols) --- adjust PortForwarding
327 // All other chapters listed in $chaplist --- adjust AttributeValue
328
329 $query[] = "delete from AttributeMap";
330 foreach ($new_dict as $chapter_no => $words)
331 {
332 foreach ($words as $oldkey => $data)
333 {
334 $value = $data['value'];
335 $newkey = $data['newkey'];
264b07b4
DO
336 // Even if the key doesn't change, go on to have
337 // AttributeMap regenerated completely.
9bf70f70 338#echo "oldkey == ${oldkey} newkey == ${newkey} value == ${value}\n";
ce109ff2
DO
339 if ($chapter_no == 1)
340 {
341 $q4 = "select id from RackObject where objtype_id = ${oldkey}";
342 $r4 = $dbxlink->query ($q4);
343 while ($row = $r4->fetch (PDO::FETCH_ASSOC))
344 $query[] = "update RackObject set objtype_id = ${newkey} where id = ${row['id']} limit 1";
345 $r4->closeCursor();
264b07b4 346 unset ($r4);
ce109ff2 347
758fe24c
DO
348 $q5 = "select attr_id, chapter_no from AttributeMap where objtype_id = ${oldkey}";
349 $r5 = $dbxlink->query ($q5);
350 while ($row = $r5->fetch (PDO::FETCH_ASSOC))
ce109ff2 351 $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (${newkey}, ${row['attr_id']}, ${row['chapter_no']})";
758fe24c 352 $r5->closeCursor();
264b07b4 353 unset ($r5);
ce109ff2 354 }
a07a39b1
DO
355 elseif ($chapter_no == 2)
356 {
758fe24c 357 $q46 = "select id from Port where type = ${oldkey}";
758fe24c
DO
358 $r46 = $dbxlink->query ($q46);
359 if ($r46 == NULL)
360 echo 'ERROR';
361 while ($row = $r46->fetch (PDO::FETCH_ASSOC))
a07a39b1 362 $query[] = "update Port set type = ${newkey} where id = ${row['id']} limit 1";
758fe24c 363 $r46->closeCursor();
264b07b4 364 unset ($r46);
a07a39b1 365 }
ce109ff2
DO
366 elseif ($chapter_no == 3)
367 {
758fe24c
DO
368 $q7 = "select id from Rack where row_id = ${oldkey}";
369 $r7 = $dbxlink->query ($q7);
370 while ($row = $r7->fetch (PDO::FETCH_ASSOC))
ce109ff2 371 $query[] = "update Rack set row_id = ${newkey} where id = ${row['id']} limit 1";
758fe24c 372 $r7->closeCursor();
264b07b4 373 unset ($r7);
ce109ff2 374 }
a07a39b1
DO
375 elseif ($chapter_no == 20)
376 {
264b07b4
DO
377 $q8 = "select object_id, localip, localport, remoteip, remoteport from PortForwarding where proto = ${oldkey}";
378 $r8 = $dbxlink->query ($q8);
758fe24c 379 while ($row = $r8->fetch (PDO::FETCH_ASSOC))
264b07b4
DO
380 $query[] = "update PortForwarding set proto = ${newkey} where " .
381 "object_id = ${row['object_id']} and localip = ${row['localip']} and " .
382 "localport = ${row['localport']} and remoteip = ${row['remoteip']} and " .
383 "remoteport = ${row['remoteport']} and proto = ${oldkey} limit 1";
758fe24c 384 $r8->closeCursor();
264b07b4 385 unset ($r8);
758fe24c
DO
386 }
387 elseif (in_array ($chapter_no, $chaplist))
388 {
5b1d68c5 389 $q81 = "select object_id, AttributeValue.attr_id from " .
264b07b4
DO
390 "AttributeValue natural join Attribute natural join AttributeMap " .
391 "inner join RackObject on RackObject.id = object_id and RackObject.objtype_id = AttributeMap.objtype_id " .
392 "where attr_type = 'dict' and chapter_no = ${chapter_no} and uint_value = ${oldkey}";
393 $r81 = $dbxlink->query ($q81);
394 while ($row = $r81->fetch (PDO::FETCH_ASSOC))
1b5942be
DO
395 $query[] = "update AttributeValue set uint_value = ${newkey} " .
396 "where object_id = ${row['object_id']} and attr_id = ${row['attr_id']}";
264b07b4
DO
397 $r81->closeCursor();
398 unset ($r81);
a07a39b1 399 }
ce109ff2
DO
400 }
401 }
a07a39b1 402 // Now it's possible to schedule PortCompat regeneration.
1b5942be
DO
403 // Convert the fields to unsigned on occasion.
404 $query[] = 'drop table PortCompat';
405 $query[] = 'create table PortCompat (type1 int(10) unsigned NOT NULL, type2 int(10) unsigned NOT NULL)';
758fe24c
DO
406 $q9 = "select type1, type2 from PortCompat";
407 $r9 = $dbxlink->query ($q9);
408 while ($row = $r9->fetch (PDO::FETCH_ASSOC))
a07a39b1
DO
409 {
410 $new_type1 = $new_dict[2][$row['type1']]['newkey'];
411 $new_type2 = $new_dict[2][$row['type2']]['newkey'];
412 $query[] = "insert into PortCompat (type1, type2) values (${new_type1}, ${new_type2})";
413 }
758fe24c 414 $r9->closeCursor();
264b07b4 415 unset ($r9);
758fe24c 416echo '</pre>';
a07a39b1
DO
417
418 // Give the configuration some finish
419 $query[] = "update Config set is_hidden = 'yes' where varname = 'color_F'";
420 $query[] = "update Config set is_hidden = 'yes' where varname = 'color_A'";
421 $query[] = "update Config set is_hidden = 'yes' where varname = 'color_U'";
422 $query[] = "update Config set is_hidden = 'yes' where varname = 'color_T'";
423 $query[] = "update Config set is_hidden = 'yes' where varname = 'color_Th'";
424 $query[] = "update Config set is_hidden = 'yes' where varname = 'color_Tw'";
425 $query[] = "update Config set is_hidden = 'yes' where varname = 'color_Thw'";
426 $query[] = "update Config set description = 'Default port type' where varname = 'default_port_type'";
427 $query[] = "update Config set description = 'Picture scale for rack row display' where varname = 'ROW_SCALE'";
428 $query[] = "update Config set description = 'Organization name' where varname = 'enterprise'";
429 $query[] = "update Config set description = 'Expect common name configured for the following object types' where varname = 'NAMEFUL_OBJTYPES'";
430 $query[] = "update Config set description = '&lt;SELECT&gt; lists height' where varname = 'MAXSELSIZE'";
431 $query[] = "update Config set description = '&quot;Fast&quot; form is this many records tall' where varname = 'MASSCOUNT'";
264b07b4 432 $query[] = "update Config set is_hidden = 'no', description = 'Ports per row in VLANs tab' where varname = 'PORTS_PER_ROW'";
a07a39b1 433 $query[] = "INSERT INTO `Config` VALUES ('IPV4_ADDRS_PER_PAGE','256','uint','no','no','IPv4 addresses per page')";
9e7f8a4b 434 $query[] = "INSERT INTO `Config` VALUES ('DEFAULT_RACK_HEIGHT','42','uint','yes','no','Default rack height')";
bd912758
DO
435 // After Dictionary transformation we ought to list 337 stock records in DB. Add more.
436 $new_words = array();
437 $new_words[338] = array (12 => 'Dell PowerConnect 2216');
438 $new_words[] = array (12 => 'Dell PowerConnect 2224');
439 $new_words[] = array (12 => 'Dell PowerConnect 2324');
440 $new_words[] = array (12 => 'Dell PowerConnect 2708');
441 $new_words[] = array (12 => 'Dell PowerConnect 2716');
442 $new_words[] = array (12 => 'Dell PowerConnect 2724');
443 $new_words[] = array (12 => 'Dell PowerConnect 2748');
444 $new_words[] = array (12 => 'Dell PowerConnect 3424');
445 $new_words[] = array (12 => 'Dell PowerConnect 3424P');
446 $new_words[] = array (12 => 'Dell PowerConnect 3448');
447 $new_words[] = array (12 => 'Dell PowerConnect 3448P');
448 $new_words[] = array (12 => 'Dell PowerConnect 5324');
449 $new_words[] = array (12 => 'Dell PowerConnect 6224');
450 $new_words[] = array (12 => 'Dell PowerConnect 6224P');
451 $new_words[] = array (12 => 'Dell PowerConnect 6224F');
452 $new_words[] = array (12 => 'Dell PowerConnect 6248');
453 $new_words[] = array (12 => 'Dell PowerConnect 6248P');
454 $new_words[] = array (11 => 'Dell PowerEdge 6850');
455 $new_words[] = array (11 => 'Dell PowerEdge 6950');
456 $new_words[] = array (11 => 'Dell PowerEdge R900');
457 $new_words[] = array (11 => 'Dell PowerEdge 4400');
458 $new_words[] = array (11 => 'Dell PowerEdge 2650');
459 $new_words[] = array (11 => 'Dell PowerEdge 2550');
460 $new_words[] = array (11 => 'Dell PowerEdge 750');
461 $new_words[] = array (11 => 'Dell PowerEdge 2450');
462 $new_words[] = array (11 => 'Dell PowerEdge 850');
463 $new_words[] = array (11 => 'Dell PowerEdge 1850');
464 $new_words[] = array (11 => 'Dell PowerEdge 860');
465 $new_words[] = array (11 => 'Dell PowerEdge 2900');
466 $new_words[] = array (11 => 'Dell PowerEdge 2970');
467 $new_words[] = array (11 => 'Dell PowerEdge SC1435');
468 $new_words[] = array (12 => 'Cisco Catalyst 6509');
469 $new_words[] = array (12 => 'Cisco ME 6524GS-8S');
470 $new_words[] = array (12 => 'Cisco ME 6524GT-8S');
471 $new_words[] = array (12 => 'Cisco Catalyst 4503-E');
472 $new_words[] = array (12 => 'Cisco Catalyst 4506-E');
473 $new_words[] = array (12 => 'Cisco Catalyst 4507R-E');
474 $new_words[] = array (12 => 'Cisco Catalyst 4510R-E');
475 $new_words[] = array (12 => 'Cisco Catalyst 3750-24TE-M');
476 $new_words[] = array (12 => 'Cisco Catalyst 4948-10GE');
477 $new_words[] = array (12 => 'Cisco ME 4924-10GE');
478 $new_words[] = array (12 => 'Cisco Catalyst 2960-24');
479 $new_words[] = array (12 => 'Cisco Catalyst 2950-24');
480 $new_words[] = array (12 => 'Cisco Catalyst 2950-12');
481 $new_words[] = array (12 => 'Cisco Catalyst 2950C-24');
482 $new_words[] = array (12 => 'Cisco Catalyst 2950G-24-DC');
483 $new_words[] = array (12 => 'Cisco Catalyst 2950SX-48');
484 $new_words[] = array (12 => 'Cisco Catalyst 2950SX-24');
485 $new_words[] = array (12 => 'Cisco Catalyst 2950T-24');
486 $new_words[] = array (12 => 'Cisco Catalyst 2950T-48');
487 $new_words[] = array (12 => 'Cisco Catalyst 2950G-12');
488 $new_words[] = array (12 => 'Cisco Catalyst 2950G-24');
489 $new_words[] = array (12 => 'Cisco Catalyst 2950G-48');
bd912758
DO
490 $new_words[] = array (12 => 'Cisco Catalyst 3508G XL');
491 $new_words[] = array (12 => 'Cisco Catalyst 3512 XL');
492 $new_words[] = array (12 => 'Cisco Catalyst 3524 XL');
493 $new_words[] = array (12 => 'Cisco Catalyst 3524 PWR XL');
494 $new_words[] = array (12 => 'Cisco Catalyst 3548 XL');
495 $new_words[] = array (12 => 'Cisco ME 2400-24TS-A');
496 $new_words[] = array (12 => 'Cisco ME 2400-24TS-D');
497 $new_words[] = array (12 => 'Cisco Catalyst 3550-12T');
498 $new_words[] = array (12 => 'Cisco Catalyst 3550-12G');
499 $new_words[] = array (12 => 'Cisco Catalyst 3550-24');
500 $new_words[] = array (12 => 'Cisco Catalyst 3550-24 FX');
501 $new_words[] = array (12 => 'Cisco Catalyst 3550-24 DC');
502 $new_words[] = array (12 => 'Cisco Catalyst 3550-24 PWR');
503 $new_words[] = array (12 => 'Cisco Catalyst 3550-48');
504 $new_words[] = array (12 => 'Cisco ME 3400G-12CS-A');
505 $new_words[] = array (12 => 'Cisco ME 3400G-12CS-D');
506 $new_words[] = array (12 => 'Cisco ME 3400G-2CS-A');
507 $new_words[] = array (12 => 'Cisco ME 3400-24TS-A');
508 $new_words[] = array (12 => 'Cisco ME 3400-24TS-D');
509 $new_words[] = array (12 => 'Cisco ME 3400-24FS-A');
7373a304
DO
510 $new_words[] = array (12 => 'Foundry FastIron GS 624XGP');
511 $new_words[] = array (12 => 'Foundry FastIron GS 624XGP-POE');
512 $new_words[] = array (12 => 'Foundry FastIron LS 624');
513 $new_words[] = array (12 => 'Foundry FastIron LS 648');
514 $new_words[] = array (12 => 'Foundry NetIron M2404F');
515 $new_words[] = array (12 => 'Foundry NetIron M2404C');
516 $new_words[] = array (17 => 'Foundry BigIron RX-32');
e7882270
DO
517 $new_words[] = array (13 => 'Debian 2.0 (hamm)');
518 $new_words[] = array (13 => 'Debian 2.1 (slink)');
519 $new_words[] = array (13 => 'Debian 2.2 (potato)');
520 $new_words[] = array (13 => 'Debian 4.0 (etch)');
521 $new_words[] = array (13 => 'ALTLinux Server 4.0');
e7882270
DO
522 $new_words[] = array (13 => 'ALTLinux Sisyphus');
523 $new_words[] = array (13 => 'openSUSE 10.0');
524 $new_words[] = array (13 => 'openSUSE 10.1');
525 $new_words[] = array (13 => 'openSUSE 10.2');
526 $new_words[] = array (13 => 'openSUSE 10.3');
527 $new_words[] = array (13 => 'Ubuntu 4.10');
528 $new_words[] = array (13 => 'Ubuntu 5.04');
529 $new_words[] = array (13 => 'Ubuntu 5.10');
530 $new_words[] = array (13 => 'Ubuntu 6.06 LTS');
531 $new_words[] = array (13 => 'Ubuntu 6.10');
532 $new_words[] = array (13 => 'Ubuntu 7.04');
533 $new_words[] = array (13 => 'Ubuntu 7.10');
534 $new_words[] = array (13 => 'Ubuntu 8.04 LTS');
535 $new_words[] = array (13 => 'RHEL5');
5f58747d
DO
536 $new_words[] = array (18 => 'Dell PowerVault 210S');
537 $new_words[] = array (18 => 'Dell PowerVault 221S');
ab0ec3ef
DO
538 $new_words[] = array (2 => 'dry contact');
539 $new_words[] = array (2 => 'unknown');
499dfa73
DO
540 // Two above records ought to take keys 439 and 440.
541 $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (439,439)";
efb6bab4
DO
542 $new_words[] = array (13 => 'CentOS-2');
543 $new_words[] = array (13 => 'CentOS-3');
544 $new_words[] = array (13 => 'CentOS-4');
545 $new_words[] = array (13 => 'CentOS-5');
bd912758
DO
546 foreach ($new_words as $dict_key => $tmp)
547 foreach ($tmp as $chapter_no => $dict_value)
548 $query[] = 'INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) ' .
549 "VALUES (${chapter_no}, ${dict_key}, '${dict_value}')";
57913f20
DO
550 // Resetting to defaults is worse, than remapping, but better than
551 // leaving messed values.
552 $query[] = "update Config set varvalue = '24' where varname = 'default_port_type' limit 1";
ce109ff2 553 // We are done.
54c2a7a8 554 $query[] = "update Config set varvalue = '0.14.7' where varname = 'DB_VERSION'";
803338c1 555 break; // --------------------------------------------
a6305acc
DO
556 case '0.14.8':
557 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('REQUIRE_ASSET_TAG_FOR','4,7,8','string','yes','no','Require asset tag for the following object types')";
78f44cbc
DO
558 $query[] = "alter table Port modify column id int(10) unsigned NOT NULL auto_increment";
559 $query[] = "alter table Port modify column object_id int(10) unsigned NOT NULL";
560 $query[] = "alter table Port modify column type int(10) unsigned NOT NULL";
561 $query[] = "alter table Link modify column porta int(10) unsigned";
562 $query[] = "alter table Link modify column portb int(10) unsigned";
ba1c6d42
DO
563 $query[] = "alter table PortForwarding modify column object_id int(10) unsigned not null";
564 $query[] = "alter table PortForwarding modify column localport smallint(5) unsigned not null";
565 $query[] = "alter table PortForwarding modify column remoteport smallint(5) unsigned not null";
566 $query[] = "alter table IPBonds modify column object_id int(10) unsigned not null";
567 $query[] = "alter table IPRanges modify column id int(10) unsigned not null";
568 $query[] = "alter table IPRanges modify column mask int(10) unsigned not null";
78f44cbc
DO
569 $query[] = "alter table Port add index `type` (type)";
570 $query[] = "alter table PortCompat add index `type1` (type1)";
571 $query[] = "alter table PortCompat add index `type2` (type2)";
992d2ec2
DO
572 $query[] = "update Dictionary set dict_value = 'Debian 3.0 (woody)' where dict_key = 234";
573 $query[] = "update Dictionary set dict_value = 'Debian 3.1 (sarge)' where dict_key = 235";
574 $query[] = "update Dictionary set dict_value = 'Foundry BigIron 15000' where dict_key = 311";
575 $query[] = "update Dictionary set dict_value = 'RHF7' where dict_key = 232";
576 $query[] = "update Dictionary set dict_value = 'RHF8' where dict_key = 242";
c8b74094
DO
577 $query[] = "INSERT INTO `Attribute` (`attr_id`, `attr_type`, `attr_name`) VALUES (25,'string','UUID');";
578 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_no`) VALUES (4,25,0);";
ba1c6d42
DO
579 $query[] = "update Dictionary set dict_value = '[[Cisco Catalyst 2970G-24T | http://www.cisco.com/en/US/products/hw/switches/ps5206/ps5313/index.html]]' where dict_key = 210";
580 $query[] = "update Dictionary set dict_value = '[[Cisco Catalyst 2970G-24TS | http://www.cisco.com/en/US/products/hw/switches/ps5206/ps5437/index.html]]' where dict_key = 211";
78f44cbc 581 $query[] = "update Config set varvalue = '0.14.8' where varname = 'DB_VERSION'";
a6305acc 582 break; // --------------------------------------------
cf48742e
DO
583 case '0.14.9':
584 $query[] = "alter table IPRanges modify column id int(10) unsigned not null auto_increment";
0a7136d4 585 $query[] = "alter table Rack modify column height tinyint(3) unsigned not null default '42'";
86f94102 586 $query[] = "alter table Rack add column thumb_data blob after comment";
2526f63c
DO
587 $query[] = "
588CREATE TABLE `IPLoadBalancer` (
589 `object_id` int(10) unsigned default NULL,
590 `rspool_id` int(10) unsigned default NULL,
70c24883 591 `vs_id` int(10) unsigned default NULL,
2526f63c
DO
592 `vsconfig` text,
593 `rsconfig` text,
70c24883 594 UNIQUE KEY `LB-VS` (`object_id`,`vs_id`)
2526f63c
DO
595) ENGINE=MyISAM";
596 $query[] = "
597CREATE TABLE `IPRSPool` (
598 `id` int(10) unsigned NOT NULL auto_increment,
2526f63c
DO
599 `name` char(255) default NULL,
600 `vsconfig` text,
601 `rsconfig` text,
602 PRIMARY KEY (`id`)
603) ENGINE=MyISAM";
604 $query[] = "
605CREATE TABLE `IPRealServer` (
606 `id` int(10) unsigned NOT NULL auto_increment,
35b72b35 607 `inservice` enum('yes','no') NOT NULL default 'no',
2526f63c
DO
608 `rsip` int(10) unsigned default NULL,
609 `rsport` smallint(5) unsigned default NULL,
610 `rspool_id` int(10) unsigned default NULL,
611 `rsconfig` text,
70c24883
DO
612 PRIMARY KEY (`id`),
613 UNIQUE KEY `pool-endpoint` (`rspool_id`,`rsip`,`rsport`)
2526f63c
DO
614) ENGINE=MyISAM";
615 $query[] = "
616CREATE TABLE `IPVirtualService` (
617 `id` int(10) unsigned NOT NULL auto_increment,
618 `vip` int(10) unsigned default NULL,
619 `vport` smallint(5) unsigned default NULL,
620 `proto` enum('TCP','UDP') NOT NULL default 'TCP',
621 `name` char(255) default NULL,
622 `vsconfig` text,
623 `rsconfig` text,
d800a805 624 PRIMARY KEY (`id`)
2526f63c 625) ENGINE=MyISAM";
d800a805 626 $query[] = "INSERT INTO `Config` VALUES ('DEFAULT_SLB_VS_PORT','','uint','yes','no','Default port of SLB virtual service')";
73e11958 627 $query[] = "INSERT INTO `Config` VALUES ('DEFAULT_SLB_RS_PORT','','uint','yes','no','Default port of SLB real server')";
6dbdc7c7
DO
628 $query[] = "INSERT INTO `Config` VALUES ('IPV4_PERFORMERS','1,4,7,8,12,14','string','yes','no','IPv4-capable object types')";
629 $query[] = "INSERT INTO `Config` VALUES ('NATV4_PERFORMERS','4,7,8','string','yes','no','NATv4-capable object types')";
f2154c9f 630 $query[] = "INSERT INTO `Config` VALUES ('USER_AUTH_SRC','database','string','no','no','User authentication source')";
3e0fc4b6 631 $query[] = "alter table RackSpace drop column problem_id";
d800a805 632 $query[] = "update Config set varvalue = '0.14.9' where varname = 'DB_VERSION'";
cf48742e 633 break; // --------------------------------------------
a6f83a72
DO
634 case '0.14.10':
635 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('DETECT_URLS','no','string','yes','no','Detect URLs in text fields')";
f187f2ec
DO
636 $query[] = "alter table RackHistory modify column height tinyint(3) unsigned";
637 $query[] = "alter table RackHistory add column thumb_data blob after comment";
4b8d413e 638 $query[] = "INSERT INTO `Config` VALUES ('RACK_PRESELECT_THRESHOLD','1','uint','no','no','Rack pre-selection threshold')";
a6f83a72 639 $query[] = "update Config set varvalue = '0.14.10' where varname = 'DB_VERSION'";
81dbd3bc 640 break; // --------------------------------------------
2ff234d6
DO
641 case '0.14.11':
642 $new_words = array();
643 $new_words[445] = array (1 => 'KVM switch');
644 $new_words[] = array (2 => 'KVM (console)');
645 $new_words[] = array (1 => 'multiplexer');
646 $query[] = "update Dictionary set dict_value = 'network switch' where dict_key = 8";
647 $query[] = "update Dictionary set dict_value = 'KVM (host)' where dict_key = 33";
648 $query[] = "delete from PortCompat where type1 = 33 and type2 = 33";
649 $query[] = "insert into PortCompat (type1, type2) values (33, 446)";
650 $query[] = "insert into PortCompat (type1, type2) values (446, 33)";
35d3ecaf
DO
651 $query[] = "insert into Chapter (chapter_no, sticky, chapter_name) values (21, 'no', 'KVM switch models')";
652 $query[] = "insert into Chapter (chapter_no, sticky, chapter_name) values (22, 'no', 'multiplexer models')";
2ff234d6
DO
653 $query[] = "update Chapter set chapter_name = 'network switch models' where chapter_no = 12";
654 $new_words[] = array (21 => '[[Avocent DSR1021 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=2418]]');
655 $new_words[] = array (21 => '[[Avocent DSR1022 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=2498]]');
656 $new_words[] = array (21 => '[[Avocent DSR1024 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=2588]]');
657 $new_words[] = array (21 => '[[Avocent DSR1031 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=2804]]');
658 $new_words[] = array (21 => '[[Avocent DSR1020 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=2340]]');
659 $new_words[] = array (21 => '[[Avocent DSR2020 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=2884]]');
660 $new_words[] = array (21 => '[[Avocent DSR4020 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=3100]]');
661 $new_words[] = array (21 => '[[Avocent DSR8020 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=3358]]');
662 $new_words[] = array (21 => '[[Avocent DSR1030 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=2726]]');
663 $new_words[] = array (21 => '[[Avocent DSR2030 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=2988]]');
664 $new_words[] = array (21 => '[[Avocent DSR2035 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=3050]]');
665 $new_words[] = array (21 => '[[Avocent DSR4030 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=3196]]');
666 $new_words[] = array (21 => '[[Avocent DSR8030 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=3472]]');
667 $new_words[] = array (21 => '[[Avocent DSR8035 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=3580]]');
668 $new_words[] = array (21 => '[[Avocent AutoView 1415 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=1612]]');
669 $new_words[] = array (21 => '[[Avocent AutoView 1515 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=1736]]');
670 $new_words[] = array (21 => '[[Avocent AutoView 2015 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=1930]]');
671 $new_words[] = array (21 => '[[Avocent AutoView 2020 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=2012]]');
672 $new_words[] = array (21 => '[[Avocent AutoView 2030 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=2114]]');
673 $new_words[] = array (21 => '[[Avocent AutoView 3100 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=2222]]');
674 $new_words[] = array (21 => '[[Avocent AutoView 3200 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=2266]]');
675 $new_words[] = array (21 => '[[Avocent SwitchView 1000 4-port | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=4016]]');
676 $new_words[] = array (21 => '[[Avocent SwitchView 1000 8-port | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=4094]]');
677 $new_words[] = array (21 => '[[Avocent SwitchView 1000 16-port | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=3934]]');
678 $new_words[] = array (22 => '[[Cronyx FMUX/S-4E1 | http://www.cronyx.ru/hardware/fmux-ring.html]]');
679 $new_words[] = array (22 => '[[Cronyx FMUX/S-4E1/ETS | http://www.cronyx.ru/hardware/fmux-ring.html]]');
680 $new_words[] = array (22 => '[[Cronyx FMUX/S-4E1/M | http://www.cronyx.ru/hardware/fmux-ring.html]]');
681 $new_words[] = array (22 => '[[Cronyx FMUX/S-8E1 | http://www.cronyx.ru/hardware/fmux-ring.html]]');
682 $new_words[] = array (22 => '[[Cronyx FMUX/S-8E1/ETS | http://www.cronyx.ru/hardware/fmux-ring.html]]');
683 $new_words[] = array (22 => '[[Cronyx FMUX/S-8E1/M | http://www.cronyx.ru/hardware/fmux-ring.html]]');
684 $new_words[] = array (22 => '[[Cronyx FMUX/S-16E1 | http://www.cronyx.ru/hardware/fmux-ring.html]]');
685 $new_words[] = array (22 => '[[Cronyx FMUX/S-16E1/ETS | http://www.cronyx.ru/hardware/fmux-ring.html]]');
686 $new_words[] = array (22 => '[[Cronyx FMUX/S-16E1/M | http://www.cronyx.ru/hardware/fmux-ring.html]]');
687 $new_words[] = array (22 => '[[Cronyx E1-XL/S | http://www.cronyx.ru/hardware/e1xl-s.html]]');
688 $new_words[] = array (22 => '[[Cronyx E1-DXC/S | http://www.cronyx.ru/hardware/e1dxc-s.html]]');
689 $new_words[] = array (22 => '[[Cronyx FMUX-4-E2 | http://www.cronyx.ru/hardware/fmux4-e2.html]]');
690 $new_words[] = array (22 => '[[Cronyx FMUX-4-E3 | http://www.cronyx.ru/hardware/fmux16-e3.html]]');
691 $new_words[] = array (22 => '[[Cronyx FMUX/SAT | http://www.cronyx.ru/hardware/fmux-sat.html]]');
692 $new_words[] = array (22 => '[[Cronyx E1-XL/S-IP | http://www.cronyx.ru/hardware/e1xl-ip.html]]');
693 $new_words[] = array (17 => '[[RAD FCD-IPM | http://www.rad.com/Article/0,6583,36426-E1_T1_or_Fractional_E1_T1_Modular_Access_Device_with_Integrated_Router,00.html]]');
694 $new_words[] = array (22 => '[[RAD FCD-E1M | http://www.rad.com/Article/0,6583,36723-E1_T1_Modular_Access_Multiplexer,00.html]]');
695 $new_words[] = array (22 => '[[RAD FCD-T1M | http://www.rad.com/Article/0,6583,36723-E1_T1_Modular_Access_Multiplexer,00.html]]');
696 $new_words[] = array (22 => '[[RAD FCD-155E | http://www.rad.com/Article/0,6583,36276-Ethernet_over_SDH_SONET_ADM,00.html]]');
697 $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (445, 1, 0)";
698 $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (445, 2, 21)";
699 $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (445, 3, 0)";
700 $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (445, 5, 0)";
701 $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (445, 14, 0)";
702 $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (445, 22, 0)";
703 $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (447, 1, 0)";
704 $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (447, 2, 22)";
705 $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (447, 3, 0)";
706 $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (447, 5, 0)";
707 $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (447, 14, 0)";
708 $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (447, 22, 0)";
709# $query[] = "";
710 foreach ($new_words as $dict_key => $tmp)
711 foreach ($tmp as $chapter_no => $dict_value)
712 $query[] = 'INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) ' .
713 "VALUES (${chapter_no}, ${dict_key}, '${dict_value}')";
f70bed91 714 $query[] = "update Rack set thumb_data = NULL";
2ff234d6
DO
715 $query[] = "update Config set varvalue = '0.14.11' where varname = 'DB_VERSION'";
716 break; // --------------------------------------------
7e7a8387 717 case '0.14.12':
2c53a252 718 $query[] = "INSERT INTO `Config` VALUES ('DEFAULT_IPV4_RS_INSERVICE','no','string','no','no','Inservice status for new SLB real servers')";
ad0e4754 719 $query[] = "INSERT INTO `Config` VALUES ('AUTOPORTS_CONFIG','4 = 1*33*kvm + 2*24*eth%u','string','no','no','AutoPorts configuration')";
b83abd29
DO
720 $query[] = "alter table Dictionary modify column dict_value char(255)";
721 $query[] = "update Dictionary set dict_value = '[[RAD FCD-IPM | http://www.rad.com/Article/0,6583,36426-E1_T1_or_Fractional_E1_T1_Modular_Access_Device_with_Integrated_Router,00.html]]' where dict_key = 487";
9bf05a0d 722 $query[] = "update Dictionary set dict_value = '[[Cronyx FMUX-16-E3 | http://www.cronyx.ru/hardware/fmux16-e3.html]]' where dict_key = 484";
b83abd29 723 $query[] = "update Config set varvalue = '0.14.12' where varname = 'DB_VERSION'";
7e7a8387
DO
724 break; // --------------------------------------------
725# case '0.14.13':
80a40611
DO
726# $query[] = "alter table Rack add column left_is_front enum ('yes', 'no') not null default 'yes' after height";
727# $query[] = "alter table Rack add column bottom_is_unit1 enum ('yes', 'no') not null default 'yes' after left_is_front";
7e7a8387 728# $query[] = "update Config set varvalue = '0.14.13' where varname = 'DB_VERSION'";
80a40611 729# break; // --------------------------------------------
fbbb74fb
DO
730 default:
731 showError ("executeUpgradeBatch () failed, because batch '${batchid}' isn't defined");
732 die;
733 break;
734 }
fbbb74fb 735 $failures = array();
ce109ff2 736 $ndots = 0;
22e40283 737 echo "<pre>Executing database upgrade batch '${batchid}':\n";
fbbb74fb
DO
738 foreach ($query as $q)
739 {
740 $result = $dbxlink->query ($q);
741 if ($result != NULL)
fbbb74fb 742 echo '.';
758fe24c
DO
743 else
744 {
745 echo '!';
746 $errorInfo = $dbxlink->errorInfo();
747 $failures[] = array ($q, $errorInfo[2]);
748 }
749 if (++$ndots == 50)
750 {
751 echo "\n";
15a50768 752 flush();
758fe24c 753 $ndots = 0;
fbbb74fb 754 }
fbbb74fb
DO
755 }
756 echo '<br>';
757 if (!count ($failures))
758 echo "No errors!\n";
759 else
760 {
761 echo "The following queries failed:\n";
762 foreach ($failures as $f)
763 {
764 list ($q, $i) = $f;
765 echo "${q} // ${i}\n";
766 }
767 }
768 echo '</pre>';
769}
770
771// ******************************************************************
772//
773// Execution starts here
774//
775// ******************************************************************
776
777$root = (empty($_SERVER['HTTPS'])?'http':'https').
778 '://'.
779 (isset($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:($_SERVER['SERVER_NAME'].($_SERVER['SERVER_PORT']=='80'?'':$_SERVER['SERVER_PORT']))).
54c2a7a8
DO
780 dirname($_SERVER['PHP_SELF']);
781if (substr ($root, -1) != '/')
782 $root .= '/';
fbbb74fb
DO
783
784// The below will be necessary as long as we rely on showError()
785require_once 'inc/interface.php';
786
787require_once 'inc/config.php';
788require_once 'inc/database.php';
789if (file_exists ('inc/secret.php'))
790 require_once 'inc/secret.php';
791else
792 die ("Database connection parameters are read from inc/secret.php file, " .
793 "which cannot be found.\nCopy provided inc/secret-sample.php to " .
794 "inc/secret.php and modify to your setup.\n\nThen reload the page.");
795
796try
797{
798 $dbxlink = new PDO ($pdo_dsn, $db_username, $db_password);
799}
800catch (PDOException $e)
801{
802 die ("Database connection failed:\n\n" . $e->getMessage());
803}
804
fbbb74fb
DO
805// Now we need to be sure that the current user is the administrator.
806// The rest doesn't matter within this context.
807// We still continue to use the current authenticator though, but this will
808// last only till the UserAccounts remains the same. After that this file
809// will have to dig into the DB for the user accounts.
810require_once 'inc/auth.php';
811
812// This will not fail sanely, because getUserAccounts() depends on showError()
813$accounts = getUserAccounts();
814
d78fdaea
DO
815// Only administrator is always authenticated locally, so reject others
816// for authenticate() to succeed.
99ee5479
DO
817
818if
819(
820 !isset ($_SERVER['PHP_AUTH_USER']) or
821 !isset ($_SERVER['PHP_AUTH_PW']) or
822 $accounts[$_SERVER['PHP_AUTH_USER']]['user_id'] != 1 or
823 !authenticated_via_database (escapeString ($_SERVER['PHP_AUTH_USER']), escapeString ($_SERVER['PHP_AUTH_PW']))
824)
825{
c0142c01
DO
826 header ('WWW-Authenticate: Basic realm="RackTables upgrade"');
827 header ('HTTP/1.0 401 Unauthorized');
828 showError ('You must be authenticated as an administrator to complete the upgrade.');
99ee5479
DO
829 die;
830}
fbbb74fb
DO
831
832$dbver = getDatabaseVersion();
833echo 'Code version == ' . CODE_VERSION;
834echo '<br>Database version == ' . $dbver;
835if ($dbver == CODE_VERSION)
758fe24c 836{
fbbb74fb
DO
837 die ("<p align=justify>Your database seems to be up-to-date. " .
838 "Now the best thing to do would be to follow to the <a href='${root}'>main page</a> " .
839 "and explore your data. Have a nice day.</p>");
758fe24c 840}
fbbb74fb
DO
841
842foreach (getDBUpgradePath ($dbver, CODE_VERSION) as $batchid)
843 executeUpgradeBatch ($batchid);
844
845echo '<br>Database version == ' . getDatabaseVersion();
846echo "<p align=justify>Your database seems to be up-to-date. " .
847 "Now the best thing to do would be to follow to the <a href='${root}'>main page</a> " .
848 "and explore your data. Have a nice day.</p>";
849
850?>