add a log entry limit to the object page (Mantis#769)
[racktables] / wwwroot / inc / install.php
1 <?php
2
3 # This file is a part of RackTables, a datacenter and server room management
4 # framework. See accompanying file "COPYING" for the full copyright and
5 # licensing information.
6
7 function renderInstallerHTML()
8 {
9 $stepfunc[1] = 'not_already_installed';
10 $stepfunc[2] = 'platform_is_ok';
11 $stepfunc[3] = 'init_config';
12 $stepfunc[4] = 'check_config_access';
13 $stepfunc[5] = 'init_database_static';
14 $stepfunc[6] = 'init_database_dynamic';
15 $stepfunc[7] = 'congrats';
16
17 if (isset ($_REQUEST['step']))
18 $step = intval ($_REQUEST['step']);
19 else
20 $step = 1;
21
22 if (! array_key_exists ($step, $stepfunc))
23 {
24 // Leave the installer module.
25 header ('Location: ' . $_SERVER['PHP_SELF']);
26 exit;
27 }
28 $title = "RackTables installation: step ${step} of " . count ($stepfunc);
29 header ('Content-Type: text/html; charset=UTF-8');
30 // Heredoc, not nowdoc!
31 echo <<<"ENDOFTEXT"
32 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
33 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
34 <head><title>${title}</title>
35 <style type="text/css">
36 .tdleft {
37 text-align: left;
38 }
39
40 .trok {
41 background-color: #80FF80;
42 }
43
44 .trwarning {
45 background-color: #FFFF80;
46 }
47
48 .trerror {
49 background-color: #FF8080;
50 }
51 </style>
52 </head>
53 <body>
54 <center>
55 ENDOFTEXT;
56 echo "<h1>${title}</h1><p>";
57
58 echo "</p><form method=post>\n";
59 $testres = $stepfunc[$step] ();
60 if ($testres)
61 {
62 $next_step = $step + 1;
63 echo "<br><input type=submit value='proceed'>";
64 }
65 else
66 {
67 $next_step = $step;
68 echo "<br><input type=submit value='retry'>";
69 }
70 echo "<input type=hidden name=step value='${next_step}'>\n";
71 echo '</form>';
72 echo '</center>';
73 echo '</body>';
74 echo '</html>';
75 }
76
77 // Check if the software is already installed.
78 function not_already_installed()
79 {
80 global $found_secret_file, $pdo_dsn;
81 if ($found_secret_file && isset ($pdo_dsn))
82 {
83 echo 'Your configuration file exists and seems to hold necessary data already.<br>';
84 return FALSE;
85 }
86 else
87 {
88 echo 'There seems to be no existing installation here, let\'s set one up now.<br>';
89 return TRUE;
90 }
91 }
92
93 // Test that the web-server can write to the configuration file.
94 // If so, prompt for the DB connection parameters and test
95 // the connection. Do not save the parameters into the configuration
96 // file until the database connection succeeds. Do not proceed to the
97 // next steps until a working configuration file is in place.
98 function init_config ()
99 {
100 function print_form
101 (
102 $use_tcp = TRUE,
103 $tcp_host = 'localhost',
104 $tcp_port = '',
105 $unix_socket = '/var/lib/mysql/mysql.sock',
106 $database = 'racktables_db',
107 $username = 'racktables_user',
108 $password = ''
109 )
110 {
111 echo "<input type=hidden name=save_config value=1>\n";
112 echo '<h3>Server-side MySQL setup of the database:</h3><div align=left><pre class=trok>';
113 echo "mysql&gt;\nCREATE DATABASE racktables_db CHARACTER SET utf8 COLLATE utf8_general_ci;\n";
114 echo "CREATE USER racktables_user@localhost IDENTIFIED BY 'MY_SECRET_PASSWORD';\n";
115 echo "GRANT ALL PRIVILEGES ON racktables_db.* TO racktables_user@localhost;\n</pre></div>";
116 echo '<table>';
117 echo '<tr><td><label for=conn_tcp>TCP connection</label></td>';
118 echo '<td><input type=radio name=conn value=conn_tcp id=conn_tcp' . ($use_tcp ? ' checked' : '') . '></td></tr>';
119 echo '<tr><td><label for=conn_unix>UNIX socket</label></td>';
120 echo '<td><input type=radio name=conn value=conn_unix id=conn_unix' . ($use_tcp ? '' : ' checked') . '></td></tr>';
121 echo "<tr><td><label for=mysql_host>TCP host:</label></td>";
122 echo "<td><input type=text name=mysql_host id=mysql_host value='${tcp_host}'></td></tr>\n";
123 echo "<tr><td><label for=mysql_port>TCP port (if not 3306):</label></td>";
124 echo "<td><input type=text name=mysql_port id=mysql_port value='${tcp_port}'></td></tr>\n";
125 echo "<tr><td><label for=mysql_socket>UNIX socket:</label></td>";
126 echo "<td><input type=text name=mysql_socket id=mysql_socket value='${unix_socket}'></td></tr>\n";
127 echo "<tr><td><label for=mysql_db>database:</label></td>";
128 echo "<td><input type=text name=mysql_db id=mysql_db value='${database}'></td></tr>\n";
129 echo "<tr><td><label for=mysql_username>username:</label></td>";
130 echo "<td><input type=text name=mysql_username id=mysql_username value='${username}'></td></tr>\n";
131 echo "<tr><td><label for=mysql_password>password:</label></td>";
132 echo "<td><input type=password name=mysql_password id=mysql_password value='${password}'></td></tr>\n";
133 echo '</table>';
134 }
135 global $path_to_secret_php;
136 if (!is_writable ($path_to_secret_php))
137 {
138 echo "The $path_to_secret_php file is not writable by web-server. Make sure it is.";
139 echo "The following commands should suffice:<pre>touch '$path_to_secret_php'; chmod a=rw '$path_to_secret_php'</pre>";
140 echo 'Fedora Linux with SELinux may require this file to be owned by specific user (apache) and/or executing "setenforce 0" for the time of installation. ';
141 echo 'SELinux may be turned back on with "setenforce 1" command.<br>';
142 return FALSE;
143 }
144 if (! array_key_exists ('save_config', $_REQUEST))
145 {
146 print_form();
147 return FALSE;
148 }
149 if (empty ($_REQUEST['mysql_db']) || empty ($_REQUEST['mysql_username']))
150 {
151 print_form
152 (
153 $_REQUEST['conn'] == 'conn_tcp',
154 $_REQUEST['mysql_host'],
155 $_REQUEST['mysql_port'],
156 $_REQUEST['mysql_socket'],
157 $_REQUEST['mysql_db'],
158 $_REQUEST['mysql_username'],
159 $_REQUEST['mysql_password']
160 );
161 echo '<h2 class=trerror>Missing database/username parameter!</h2>';
162 return FALSE;
163 }
164 if ($_REQUEST['conn'] == 'conn_tcp' && empty ($_REQUEST['mysql_host']))
165 {
166 print_form
167 (
168 $_REQUEST['conn'] == 'conn_tcp',
169 $_REQUEST['mysql_host'],
170 $_REQUEST['mysql_port'],
171 $_REQUEST['mysql_socket'],
172 $_REQUEST['mysql_db'],
173 $_REQUEST['mysql_username'],
174 $_REQUEST['mysql_password']
175 );
176 echo '<h2 class=trerror>Missing TCP hostname parameter!</h2>';
177 return FALSE;
178 }
179 if ($_REQUEST['conn'] == 'conn_unix' && empty ($_REQUEST['mysql_socket']))
180 {
181 print_form
182 (
183 $_REQUEST['conn'] == 'conn_tcp',
184 $_REQUEST['mysql_host'],
185 $_REQUEST['mysql_port'],
186 $_REQUEST['mysql_socket'],
187 $_REQUEST['mysql_db'],
188 $_REQUEST['mysql_username'],
189 $_REQUEST['mysql_password']
190 );
191 echo '<h2 class=trerror>Missing UNIX socket parameter!</h2>';
192 return FALSE;
193 }
194 # finally OK to make a connection attempt
195 $pdo_dsn = 'mysql:';
196 switch ($_REQUEST['conn'])
197 {
198 case 'conn_tcp':
199 $pdo_dsn .= 'host=' . $_REQUEST['mysql_host'];
200 if (! empty ($_REQUEST['mysql_port']) && $_REQUEST['mysql_port'] != '3306')
201 $pdo_dsn .= ';port=' . $_REQUEST['mysql_port'];
202 break;
203 case 'conn_unix':
204 $pdo_dsn .= 'unix_socket=' . $_REQUEST['mysql_socket'];
205 break;
206 default:
207 print_form();
208 echo '<h2 class=trerror>form error</h2>';
209 return FALSE;
210 }
211 $pdo_dsn .= ';dbname=' . $_REQUEST['mysql_db'];
212 try
213 {
214 $dbxlink = new PDO ($pdo_dsn, $_REQUEST['mysql_username'], $_REQUEST['mysql_password']);
215 }
216 catch (PDOException $e)
217 {
218 print_form
219 (
220 $_REQUEST['conn'] == 'conn_tcp',
221 $_REQUEST['mysql_host'],
222 $_REQUEST['mysql_port'],
223 $_REQUEST['mysql_socket'],
224 $_REQUEST['mysql_db'],
225 $_REQUEST['mysql_username'],
226 $_REQUEST['mysql_password']
227 );
228 echo "<h2 class=trerror>Database connection failed. Check parameters and try again.</h2>\n";
229 echo "PDO DSN: <tt class=trwarning>${pdo_dsn}</tt><br>";
230 return FALSE;
231 }
232
233 $conf = fopen ($path_to_secret_php, 'w+');
234 if ($conf === FALSE)
235 {
236 echo "Error: failed to open $path_to_secret_php for writing";
237 return FALSE;
238 }
239 fwrite ($conf, "<?php\n# This file has been generated automatically by RackTables installer.\n");
240 fwrite ($conf, "\$pdo_dsn = '${pdo_dsn}';\n");
241 fwrite ($conf, "\$db_username = '" . $_REQUEST['mysql_username'] . "';\n");
242 fwrite ($conf, "\$db_password = '" . $_REQUEST['mysql_password'] . "';\n\n");
243 fwrite ($conf, <<<'ENDOFTEXT'
244 # Set this if you need to override the default plugins directory.
245 #$racktables_plugins_dir = '/path/to/plugins';
246
247 # Setting MySQL client buffer size may be required to make downloading work for
248 # larger files, but it does not work with mysqlnd.
249 # $pdo_bufsize = 50 * 1024 * 1024;
250 # Setting PDO SSL key, cert, and CA will allow a SSL/TLS connection to the MySQL
251 # DB. Make sure the files are readable by the web server
252 # $pdo_ssl_key = '/path/to/ssl/key'
253 # $pdo_ssl_cert = '/path/to/ssl/cert'
254 # $pdo_ssl_ca = '/path/to/ssl/ca'
255
256 $user_auth_src = 'database';
257 $require_local_account = TRUE;
258 # Default setting is to authenticate users locally, but it is possible to
259 # employ existing LDAP or Apache user accounts. Check RackTables wiki for
260 # more information, in particular, this page for LDAP configuration details:
261 # http://wiki.racktables.org/index.php?title=LDAP
262
263 #$LDAP_options = array
264 #(
265 # 'server' => 'localhost',
266 # 'domain' => 'example.com',
267 # 'search_attr' => '',
268 # 'search_dn' => '',
269 # // The following credentials will be used when searching for the user's DN:
270 # 'search_bind_rdn' => NULL,
271 # 'search_bind_password' => NULL,
272 # 'displayname_attrs' => '',
273 # 'options' => array (LDAP_OPT_PROTOCOL_VERSION => 3),
274 # 'use_tls' => 2, // 0 == don't attempt, 1 == attempt, 2 == require
275 #);
276
277 # For SAML configuration details:
278 # http://wiki.racktables.org/index.php?title=SAML
279
280 #$SAML_options = array
281 #(
282 # 'simplesamlphp_basedir' => '../simplesaml',
283 # 'sp_profile' => 'default-sp',
284 # 'usernameAttribute' => 'eduPersonPrincipName',
285 # 'fullnameAttribute' => 'fullName',
286 # 'groupListAttribute' => 'memberOf',
287 #);
288
289 # This HTML banner is intended to assist users in dispatching their issues
290 # to the local tech support service. Its text (in its verbatim form) will
291 # be appended to assorted error messages visible in user's browser (including
292 # "not authenticated" message). Beware of placing any sensitive information
293 # here, it will be readable by unauthorized visitors.
294 #$helpdesk_banner = '<B>This RackTables instance is supported by Example Inc. IT helpdesk, dial ext. 1234 to report a problem.</B>';
295
296 ENDOFTEXT
297 );
298 fclose ($conf);
299 echo "The configuration file has been written successfully.<br>";
300 return TRUE;
301 }
302
303 function get_process_owner()
304 {
305 // this function requires the posix extention and returns the fallback value otherwise
306 if (is_callable ('posix_getpwuid') && is_callable ('posix_geteuid'))
307 {
308 $user = posix_getpwuid(posix_geteuid());
309 if (isset ($user['name']))
310 return $user['name'];
311 }
312 return 'nobody';
313 }
314
315 function check_config_access()
316 {
317 global $path_to_secret_php;
318 if (! is_writable ($path_to_secret_php) && is_readable ($path_to_secret_php))
319 {
320 echo 'The configuration file ownership and permissions seem to be OK.<br>';
321 return TRUE;
322 }
323 $uname = get_process_owner();
324 echo 'Please set ownership (<tt>chown</tt>) and/or permissions (<tt>chmod</tt>) ';
325 echo "of <tt>${path_to_secret_php}</tt> on the server filesystem as follows:";
326 echo '<div align=left><ul>';
327 echo '<li>The file MUST NOT be writable by the httpd process.</li>';
328 echo '<li>The file MUST be readable by the httpd process.</li>';
329 echo '<li>The file should not be readable by anyone except the httpd process.</li>';
330 echo '<li>The file should not be writable by anyone.</li>';
331 echo '</ul></div>';
332 echo 'For example, if httpd runs as user "' . $uname . '" and group "nogroup", commands ';
333 echo 'similar to the following may work (though not guaranteed to, please consider ';
334 echo 'only as an example):';
335 echo "<pre>chown $uname:nogroup secret.php; chmod 440 secret.php</pre>";
336 return FALSE;
337 }
338
339 function connect_to_db_or_die ()
340 {
341 try
342 {
343 connectDB();
344 }
345 catch (RackTablesError $e)
346 {
347 die ('Error connecting to the database');
348 }
349 }
350
351 function init_database_static ()
352 {
353 connect_to_db_or_die();
354 global $dbxlink;
355 // platform_is_ok() didn't check for InnoDB support during its previous invocation, which
356 // was right because at that time secret.php did not exist yet and $dbxlink was not available.
357 if (!isInnoDBSupported())
358 {
359 echo 'InnoDB test failed! Please configure MySQL server properly and retry.';
360 return FALSE;
361 }
362 $result = $dbxlink->query ('show tables');
363 $tables = $result->fetchAll (PDO::FETCH_NUM);
364 $result->closeCursor();
365 unset ($result);
366 if (count ($tables))
367 {
368 echo 'Your database is already holding ' . count ($tables);
369 echo ' tables, so I will stop here and let you check it yourself.<br>';
370 echo 'There is some important data there probably.<br>';
371 return FALSE;
372 }
373 echo 'Initializing the database...<br>';
374 echo '<table border=1>';
375 echo "<tr><th>section</th><th>queries</th><th>errors</th></tr>";
376 $failures = array();
377 foreach (array ('structure', 'dictbase') as $part)
378 {
379 echo "<tr><td>${part}</td>";
380 $nq = $nerrs = 0;
381 foreach (get_pseudo_file ($part) as $q)
382 try
383 {
384 $result = $dbxlink->query ($q);
385 $nq++;
386 }
387 catch (PDOException $e)
388 {
389 $nerrs++;
390 $errorInfo = $dbxlink->errorInfo();
391 $failures[] = array ($q, $errorInfo[2]);
392 }
393 echo "<td>${nq}</td><td>${nerrs}</td></tr>\n";
394 }
395 if (!count ($failures))
396 echo "<strong><font color=green>done</font></strong>";
397 else
398 {
399 echo "<strong><font color=red>The following queries failed:</font></strong><br><pre>";
400 foreach ($failures as $f)
401 {
402 list ($q, $i) = $f;
403 echo "${q} -- ${i}\n";
404 }
405 }
406 // (re)load dictionary by pure PHP means w/o any external file
407 echo "<tr><td>dictionary</td>";
408 $nq = $nerrs = 0;
409 $dictq = array();
410 foreach (reloadDictionary() as $query)
411 {
412 $nq++;
413 if ($dbxlink->exec ($query) === FALSE)
414 {
415 $nerrs++;
416 $errlist[] = $query;
417 }
418 }
419 echo "<td>${nq}</td><td>${nerrs}</td></tr>\n";
420
421 echo '</table>';
422 if (isset($errlist) && count ($errlist))
423 {
424 echo '<pre>The following queries failed:\n';
425 foreach ($errlist as $q)
426 echo "${q}\n\n";
427 echo '</pre>';
428 return FALSE;
429 }
430 return TRUE;
431 }
432
433 function init_database_dynamic ()
434 {
435 connect_to_db_or_die();
436 global $dbxlink;
437 if (! isset ($_REQUEST['password']) || empty ($_REQUEST['password']))
438 {
439 $result = $dbxlink->query ('select count(user_id) from UserAccount where user_id = 1');
440 $row = $result->fetch (PDO::FETCH_NUM);
441 $nrecs = $row[0];
442 $result->closeCursor();
443 if (!$nrecs)
444 {
445 echo '<table border=1>';
446 echo '<caption>Administrator password not set</caption>';
447 echo '<tr><td><input type=password name=password></td></tr>';
448 echo '</table>';
449 }
450 return FALSE;
451 }
452 else
453 {
454 // Never send cleartext password over the wire.
455 $hash = sha1 ($_REQUEST['password']);
456 $query = "INSERT INTO `UserAccount` (`user_id`, `user_name`, `user_password_hash`, `user_realname`) " .
457 "VALUES (1,'admin','${hash}','RackTables Administrator')";
458 $result = $dbxlink->exec ($query);
459 echo "Administrator password has been set successfully.<br>";
460 return TRUE;
461 }
462 }
463
464 function congrats ()
465 {
466 echo 'Congratulations! RackTables installation is complete. After pressing Proceed you will ';
467 echo 'enter the system. Authenticate with <strong>admin</strong> username.<br>RackTables project has a ';
468 echo "<a href='http://wiki.racktables.org/index.php?title=RackTablesAdminGuide'>";
469 echo "wiki</a> and a ";
470 echo "<a href='http://www.freelists.org/list/racktables-users'>mailing list</a> for users. Have fun.<br>";
471 return TRUE;
472 }
473
474 function get_pseudo_file ($name)
475 {
476 switch ($name)
477 {
478 case 'structure':
479 $query = array();
480
481 $query[] = "alter database character set utf8 collate utf8_unicode_ci";
482 $query[] = "set names 'utf8'";
483 $query[] = "SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0";
484
485 $query[] = "CREATE TABLE `Atom` (
486 `molecule_id` int(10) unsigned NOT NULL,
487 `rack_id` int(10) unsigned NOT NULL,
488 `unit_no` int(10) unsigned NOT NULL,
489 `atom` enum('front','interior','rear') NOT NULL,
490 PRIMARY KEY (`molecule_id`,`rack_id`,`unit_no`,`atom`),
491 KEY `Atom-FK-rack_id` (`rack_id`),
492 CONSTRAINT `Atom-FK-molecule_id` FOREIGN KEY (`molecule_id`) REFERENCES `Molecule` (`id`) ON DELETE CASCADE,
493 CONSTRAINT `Atom-FK-rack_id` FOREIGN KEY (`rack_id`) REFERENCES `Object` (`id`) ON DELETE CASCADE
494 ) ENGINE=InnoDB";
495
496 $query[] = "CREATE TABLE `Attribute` (
497 `id` int(10) unsigned NOT NULL auto_increment,
498 `type` enum('string','uint','float','dict','date') default NULL,
499 `name` char(64) default NULL,
500 PRIMARY KEY (`id`),
501 UNIQUE KEY `name` (`name`)
502 ) ENGINE=InnoDB";
503
504 $query[] = "CREATE TABLE `AttributeMap` (
505 `objtype_id` int(10) unsigned NOT NULL default '1',
506 `attr_id` int(10) unsigned NOT NULL default '1',
507 `chapter_id` int(10) unsigned default NULL,
508 `sticky` enum('yes','no') default 'no',
509 UNIQUE KEY `objtype_id` (`objtype_id`,`attr_id`),
510 KEY `attr_id` (`attr_id`),
511 KEY `chapter_id` (`chapter_id`),
512 CONSTRAINT `AttributeMap-FK-chapter_id` FOREIGN KEY (`chapter_id`) REFERENCES `Chapter` (`id`),
513 CONSTRAINT `AttributeMap-FK-attr_id` FOREIGN KEY (`attr_id`) REFERENCES `Attribute` (`id`)
514 ) ENGINE=InnoDB";
515
516 $query[] = "CREATE TABLE `AttributeValue` (
517 `object_id` int(10) unsigned NOT NULL,
518 -- Default value intentionally breaks the constraint, this blocks
519 -- any insertion that doesn't have 'object_tid' on the column list.
520 `object_tid` int(10) unsigned NOT NULL default '0',
521 `attr_id` int(10) unsigned NOT NULL,
522 `string_value` char(255) default NULL,
523 `uint_value` int(10) unsigned default NULL,
524 `float_value` float default NULL,
525 PRIMARY KEY (`object_id`,`attr_id`),
526 KEY `attr_id-uint_value` (`attr_id`,`uint_value`),
527 KEY `attr_id-string_value` (`attr_id`,`string_value`(12)),
528 KEY `id-tid` (`object_id`,`object_tid`),
529 KEY `object_tid-attr_id` (`object_tid`,`attr_id`),
530 CONSTRAINT `AttributeValue-FK-map` FOREIGN KEY (`object_tid`, `attr_id`) REFERENCES `AttributeMap` (`objtype_id`, `attr_id`),
531 CONSTRAINT `AttributeValue-FK-object` FOREIGN KEY (`object_id`, `object_tid`) REFERENCES `Object` (`id`, `objtype_id`) ON DELETE CASCADE ON UPDATE CASCADE
532 ) ENGINE=InnoDB";
533
534 $query[] = "CREATE TABLE `CachedPAV` (
535 `object_id` int(10) unsigned NOT NULL,
536 `port_name` char(255) NOT NULL,
537 `vlan_id` int(10) unsigned NOT NULL default '0',
538 PRIMARY KEY (`object_id`,`port_name`,`vlan_id`),
539 KEY `vlan_id` (`vlan_id`),
540 CONSTRAINT `CachedPAV-FK-object-port` FOREIGN KEY (`object_id`, `port_name`) REFERENCES `CachedPVM` (`object_id`, `port_name`) ON DELETE CASCADE,
541 CONSTRAINT `CachedPAV-FK-vlan_id` FOREIGN KEY (`vlan_id`) REFERENCES `VLANValidID` (`vlan_id`)
542 ) ENGINE=InnoDB";
543
544 $query[] = "CREATE TABLE `CachedPNV` (
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 `CachedPNV-FK-compound` FOREIGN KEY (`object_id`, `port_name`, `vlan_id`) REFERENCES `CachedPAV` (`object_id`, `port_name`, `vlan_id`) ON DELETE CASCADE
551 ) ENGINE=InnoDB";
552
553 $query[] = "CREATE TABLE `CachedPVM` (
554 `object_id` int(10) unsigned NOT NULL,
555 `port_name` char(255) NOT NULL,
556 `vlan_mode` enum('access','trunk') NOT NULL default 'access',
557 PRIMARY KEY (`object_id`,`port_name`),
558 CONSTRAINT `CachedPVM-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `Object` (`id`) ON DELETE CASCADE
559 ) ENGINE=InnoDB";
560
561 $query[] = "CREATE TABLE `Chapter` (
562 `id` int(10) unsigned NOT NULL auto_increment,
563 `sticky` enum('yes','no') default 'no',
564 `name` char(128) NOT NULL,
565 PRIMARY KEY (`id`),
566 UNIQUE KEY `name` (`name`)
567 ) ENGINE=InnoDB";
568
569 $query[] = "CREATE TABLE `Config` (
570 `varname` char(32) NOT NULL,
571 `varvalue` text NOT NULL,
572 `vartype` enum('string','uint') NOT NULL default 'string',
573 `emptyok` enum('yes','no') NOT NULL default 'no',
574 `is_hidden` enum('yes','no') NOT NULL default 'yes',
575 `is_userdefined` enum('yes','no') NOT NULL default 'no',
576 `description` text,
577 PRIMARY KEY (`varname`)
578 ) ENGINE=InnoDB";
579
580 $query[] = "CREATE TABLE `Dictionary` (
581 `chapter_id` int(10) unsigned NOT NULL,
582 `dict_key` int(10) unsigned NOT NULL auto_increment,
583 `dict_sticky` enum('yes','no') DEFAULT 'no',
584 `dict_value` char(255) default NULL,
585 PRIMARY KEY (`dict_key`),
586 UNIQUE KEY `dict_unique` (`chapter_id`,`dict_value`,`dict_sticky`),
587 CONSTRAINT `Dictionary-FK-chapter_id` FOREIGN KEY (`chapter_id`) REFERENCES `Chapter` (`id`)
588 ) ENGINE=InnoDB";
589
590 $query[] = "CREATE TABLE `EntityLink` (
591 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
592 `parent_entity_type` enum('location','object','rack','row') NOT NULL,
593 `parent_entity_id` int(10) unsigned NOT NULL,
594 `child_entity_type` enum('location','object','rack','row') NOT NULL,
595 `child_entity_id` int(10) unsigned NOT NULL,
596 PRIMARY KEY (`id`),
597 UNIQUE KEY `EntityLink-unique` (`parent_entity_type`,`parent_entity_id`,`child_entity_type`,`child_entity_id`),
598 KEY `EntityLink-compound` (`parent_entity_type`,`child_entity_type`,`child_entity_id`)
599 ) ENGINE=InnoDB";
600
601 $query[] = "CREATE TABLE `File` (
602 `id` int(10) unsigned NOT NULL auto_increment,
603 `name` char(255) NOT NULL,
604 `type` char(255) NOT NULL,
605 `size` int(10) unsigned NOT NULL,
606 `ctime` datetime NOT NULL,
607 `mtime` datetime NOT NULL,
608 `atime` datetime NOT NULL,
609 `thumbnail` longblob,
610 `contents` longblob NOT NULL,
611 `comment` text,
612 PRIMARY KEY (`id`),
613 UNIQUE KEY `name` (`name`)
614 ) ENGINE=InnoDB";
615
616 $query[] = "CREATE TABLE `FileLink` (
617 `id` int(10) unsigned NOT NULL auto_increment,
618 `file_id` int(10) unsigned NOT NULL,
619 `entity_type` enum('ipv4net','ipv4rspool','ipv4vs','ipvs','ipv6net','location','object','rack','row','user') NOT NULL default 'object',
620 `entity_id` int(10) NOT NULL,
621 PRIMARY KEY (`id`),
622 KEY `FileLink-file_id` (`file_id`),
623 UNIQUE KEY `FileLink-unique` (`file_id`,`entity_type`,`entity_id`),
624 CONSTRAINT `FileLink-File_fkey` FOREIGN KEY (`file_id`) REFERENCES `File` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
625 ) ENGINE=InnoDB";
626
627 $query[] = "CREATE TABLE `IPv4Address` (
628 `ip` int(10) unsigned NOT NULL default '0',
629 `name` char(255) NOT NULL default '',
630 `comment` char(255) NOT NULL default '',
631 `reserved` enum('yes','no') default NULL,
632 PRIMARY KEY (`ip`)
633 ) ENGINE=InnoDB";
634
635 $query[] = "CREATE TABLE `IPv4Allocation` (
636 `object_id` int(10) unsigned NOT NULL default '0',
637 `ip` int(10) unsigned NOT NULL default '0',
638 `name` char(255) NOT NULL default '',
639 `type` enum('regular','shared','virtual','router','point2point','sharedrouter') NOT NULL DEFAULT 'regular',
640 PRIMARY KEY (`object_id`,`ip`),
641 KEY `ip` (`ip`),
642 CONSTRAINT `IPv4Allocation-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `Object` (`id`) ON DELETE CASCADE
643 ) ENGINE=InnoDB";
644
645 $query[] = "CREATE TABLE `IPv4LB` (
646 `object_id` int(10) unsigned default NULL,
647 `rspool_id` int(10) unsigned default NULL,
648 `vs_id` int(10) unsigned default NULL,
649 `prio` varchar(255) default NULL,
650 `vsconfig` text,
651 `rsconfig` text,
652 UNIQUE KEY `LB-VS` (`object_id`,`vs_id`),
653 KEY `IPv4LB-FK-rspool_id` (`rspool_id`),
654 KEY `IPv4LB-FK-vs_id` (`vs_id`),
655 CONSTRAINT `IPv4LB-FK-vs_id` FOREIGN KEY (`vs_id`) REFERENCES `IPv4VS` (`id`),
656 CONSTRAINT `IPv4LB-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `Object` (`id`),
657 CONSTRAINT `IPv4LB-FK-rspool_id` FOREIGN KEY (`rspool_id`) REFERENCES `IPv4RSPool` (`id`)
658 ) ENGINE=InnoDB";
659
660 $query[] = "CREATE TABLE `IPv4Log` (
661 `id` int(10) NOT NULL AUTO_INCREMENT,
662 `ip` int(10) unsigned NOT NULL,
663 `date` datetime NOT NULL,
664 `user` varchar(64) NOT NULL,
665 `message` text NOT NULL,
666 PRIMARY KEY (`id`),
667 KEY `ip-date` (`ip`,`date`)
668 ) ENGINE=InnoDB";
669
670 $query[] = "CREATE TABLE `IPv6Log` (
671 `id` int(10) NOT NULL AUTO_INCREMENT,
672 `ip` binary(16) NOT NULL,
673 `date` datetime NOT NULL,
674 `user` varchar(64) NOT NULL,
675 `message` text NOT NULL,
676 PRIMARY KEY (`id`),
677 KEY `ip-date` (`ip`,`date`)
678 ) ENGINE=InnoDB";
679
680 $query[] = "CREATE TABLE `IPv4NAT` (
681 `object_id` int(10) unsigned NOT NULL default '0',
682 `proto` enum('TCP','UDP','ALL') NOT NULL default 'TCP',
683 `localip` int(10) unsigned NOT NULL default '0',
684 `localport` smallint(5) unsigned NOT NULL default '0',
685 `remoteip` int(10) unsigned NOT NULL default '0',
686 `remoteport` smallint(5) unsigned NOT NULL default '0',
687 `description` char(255) default NULL,
688 PRIMARY KEY (`object_id`,`proto`,`localip`,`localport`,`remoteip`,`remoteport`),
689 KEY `localip` (`localip`),
690 KEY `remoteip` (`remoteip`),
691 KEY `object_id` (`object_id`),
692 CONSTRAINT `IPv4NAT-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `Object` (`id`)
693 ) ENGINE=InnoDB";
694
695 $query[] = "CREATE TABLE `IPv4Network` (
696 `id` int(10) unsigned NOT NULL auto_increment,
697 `ip` int(10) unsigned NOT NULL default '0',
698 `mask` int(10) unsigned NOT NULL default '0',
699 `name` char(255) default NULL,
700 `comment` text,
701 PRIMARY KEY (`id`),
702 UNIQUE KEY `base-len` (`ip`,`mask`)
703 ) ENGINE=InnoDB";
704
705 $query[] = "CREATE TABLE `IPv4RS` (
706 `id` int(10) unsigned NOT NULL auto_increment,
707 `inservice` enum('yes','no') NOT NULL default 'no',
708 `rsip` varbinary(16) NOT NULL,
709 `rsport` smallint(5) unsigned default NULL,
710 `rspool_id` int(10) unsigned default NULL,
711 `rsconfig` text,
712 `comment` varchar(255) DEFAULT NULL,
713 PRIMARY KEY (`id`),
714 KEY `rsip` (`rsip`),
715 UNIQUE KEY `pool-endpoint` (`rspool_id`,`rsip`,`rsport`),
716 CONSTRAINT `IPv4RS-FK` FOREIGN KEY (`rspool_id`) REFERENCES `IPv4RSPool` (`id`) ON DELETE CASCADE
717 ) ENGINE=InnoDB";
718
719 $query[] = "CREATE TABLE `IPv4RSPool` (
720 `id` int(10) unsigned NOT NULL auto_increment,
721 `name` char(255) default NULL,
722 `vsconfig` text,
723 `rsconfig` text,
724 PRIMARY KEY (`id`)
725 ) ENGINE=InnoDB";
726
727 $query[] = "CREATE TABLE `IPv4VS` (
728 `id` int(10) unsigned NOT NULL auto_increment,
729 `vip` varbinary(16) NOT NULL,
730 `vport` smallint(5) unsigned default NULL,
731 `proto` enum('TCP','UDP','MARK') NOT NULL default 'TCP',
732 `name` char(255) default NULL,
733 `vsconfig` text,
734 `rsconfig` text,
735 PRIMARY KEY (`id`),
736 KEY `vip` (`vip`)
737 ) ENGINE=InnoDB";
738
739 $query[] = "CREATE TABLE `IPv6Address` (
740 `ip` binary(16) NOT NULL,
741 `name` char(255) NOT NULL default '',
742 `comment` char(255) NOT NULL default '',
743 `reserved` enum('yes','no') default NULL,
744 PRIMARY KEY (`ip`)
745 ) ENGINE=InnoDB";
746
747 $query[] = "CREATE TABLE `IPv6Allocation` (
748 `object_id` int(10) unsigned NOT NULL default '0',
749 `ip` binary(16) NOT NULL,
750 `name` char(255) NOT NULL default '',
751 `type` enum('regular','shared','virtual','router','point2point','sharedrouter') NOT NULL DEFAULT 'regular',
752 PRIMARY KEY (`object_id`,`ip`),
753 KEY `ip` (`ip`),
754 CONSTRAINT `IPv6Allocation-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `Object` (`id`) ON DELETE CASCADE
755 ) ENGINE=InnoDB";
756
757 $query[] = "CREATE TABLE `IPv6Network` (
758 `id` int(10) unsigned NOT NULL auto_increment,
759 `ip` binary(16) NOT NULL,
760 `mask` int(10) unsigned NOT NULL,
761 `last_ip` binary(16) NOT NULL,
762 `name` char(255) default NULL,
763 `comment` text,
764 PRIMARY KEY (`id`),
765 UNIQUE KEY `ip` (`ip`,`mask`)
766 ) ENGINE=InnoDB";
767
768 $query[] = "CREATE TABLE `LDAPCache` (
769 `presented_username` char(64) NOT NULL,
770 `successful_hash` char(40) NOT NULL,
771 `first_success` timestamp NOT NULL default CURRENT_TIMESTAMP,
772 `last_retry` timestamp NULL default NULL,
773 `displayed_name` char(128) default NULL,
774 `memberof` text,
775 UNIQUE KEY `presented_username` (`presented_username`),
776 KEY `scanidx` (`presented_username`,`successful_hash`)
777 ) ENGINE=InnoDB";
778
779 $query[] = "CREATE TABLE `Link` (
780 `porta` int(10) unsigned NOT NULL default '0',
781 `portb` int(10) unsigned NOT NULL default '0',
782 `cable` char(64) DEFAULT NULL,
783 PRIMARY KEY (`porta`,`portb`),
784 UNIQUE KEY `porta` (`porta`),
785 UNIQUE KEY `portb` (`portb`),
786 CONSTRAINT `Link-FK-a` FOREIGN KEY (`porta`) REFERENCES `Port` (`id`) ON DELETE CASCADE,
787 CONSTRAINT `Link-FK-b` FOREIGN KEY (`portb`) REFERENCES `Port` (`id`) ON DELETE CASCADE
788 ) ENGINE=InnoDB";
789
790 $query[] = "CREATE TABLE `Molecule` (
791 `id` int(10) unsigned NOT NULL auto_increment,
792 PRIMARY KEY (`id`)
793 ) ENGINE=InnoDB";
794
795 $query[] = "CREATE TABLE `MountOperation` (
796 `id` int(10) unsigned NOT NULL auto_increment,
797 `object_id` int(10) unsigned NOT NULL default '0',
798 `ctime` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
799 `user_name` char(64) default NULL,
800 `old_molecule_id` int(10) unsigned default NULL,
801 `new_molecule_id` int(10) unsigned default NULL,
802 `comment` text,
803 PRIMARY KEY (`id`),
804 UNIQUE KEY `old_molecule_id` (`old_molecule_id`),
805 UNIQUE KEY `new_molecule_id` (`new_molecule_id`),
806 KEY `object_id` (`object_id`),
807 CONSTRAINT `MountOperation-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `Object` (`id`) ON DELETE CASCADE,
808 CONSTRAINT `MountOperation-FK-old_molecule_id` FOREIGN KEY (`old_molecule_id`) REFERENCES `Molecule` (`id`) ON DELETE CASCADE,
809 CONSTRAINT `MountOperation-FK-new_molecule_id` FOREIGN KEY (`new_molecule_id`) REFERENCES `Molecule` (`id`) ON DELETE CASCADE
810 ) ENGINE=InnoDB";
811
812 $query[] = "CREATE TABLE `ObjectLog` (
813 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
814 `object_id` int(10) unsigned NOT NULL,
815 `user` char(64) NOT NULL,
816 `date` datetime NOT NULL,
817 `content` text NOT NULL,
818 PRIMARY KEY (`id`),
819 KEY `object_id` (`object_id`),
820 KEY `date` (`date`),
821 CONSTRAINT `ObjectLog-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `Object` (`id`) ON DELETE CASCADE
822 ) ENGINE=InnoDB";
823
824 $query[] = "CREATE TABLE `ObjectParentCompat` (
825 `parent_objtype_id` int(10) unsigned NOT NULL,
826 `child_objtype_id` int(10) unsigned NOT NULL,
827 UNIQUE KEY `parent_child` (`parent_objtype_id`,`child_objtype_id`)
828 ) ENGINE=InnoDB";
829
830 $query[] = "CREATE TABLE `PatchCableConnector` (
831 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
832 `origin` enum('default','custom') NOT NULL DEFAULT 'custom',
833 `connector` char(32) NOT NULL,
834 PRIMARY KEY (`id`),
835 UNIQUE KEY `connector_per_origin` (`connector`,`origin`)
836 ) ENGINE=InnoDB";
837
838 $query[] = "CREATE TABLE `PatchCableConnectorCompat` (
839 `pctype_id` int(10) unsigned NOT NULL,
840 `connector_id` int(10) unsigned NOT NULL,
841 PRIMARY KEY (`pctype_id`,`connector_id`),
842 KEY `connector_id` (`connector_id`),
843 CONSTRAINT `PatchCableConnectorCompat-FK-connector_id` FOREIGN KEY (`connector_id`) REFERENCES `PatchCableConnector` (`id`),
844 CONSTRAINT `PatchCableConnectorCompat-FK-pctype_id` FOREIGN KEY (`pctype_id`) REFERENCES `PatchCableType` (`id`)
845 ) ENGINE=InnoDB";
846
847 $query[] = "CREATE TABLE `PatchCableHeap` (
848 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
849 `pctype_id` int(10) unsigned NOT NULL,
850 `end1_conn_id` int(10) unsigned NOT NULL,
851 `end2_conn_id` int(10) unsigned NOT NULL,
852 `amount` smallint(5) unsigned NOT NULL DEFAULT '0',
853 `length` decimal(5,2) unsigned NOT NULL DEFAULT '1.00',
854 `description` char(255) DEFAULT NULL,
855 PRIMARY KEY (`id`),
856 KEY `compat1` (`pctype_id`,`end1_conn_id`),
857 KEY `compat2` (`pctype_id`,`end2_conn_id`),
858 CONSTRAINT `PatchCableHeap-FK-compat1` FOREIGN KEY (`pctype_id`, `end1_conn_id`) REFERENCES `PatchCableConnectorCompat` (`pctype_id`, `connector_id`),
859 CONSTRAINT `PatchCableHeap-FK-compat2` FOREIGN KEY (`pctype_id`, `end2_conn_id`) REFERENCES `PatchCableConnectorCompat` (`pctype_id`, `connector_id`)
860 ) ENGINE=InnoDB";
861
862 $query[] = "CREATE TABLE `PatchCableHeapLog` (
863 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
864 `heap_id` int(10) unsigned NOT NULL,
865 `date` datetime NOT NULL,
866 `user` char(64) NOT NULL,
867 `message` char(255) NOT NULL,
868 PRIMARY KEY (`id`),
869 KEY `heap_id-date` (`heap_id`,`date`),
870 CONSTRAINT `PatchCableHeapLog-FK-heap_id` FOREIGN KEY (`heap_id`) REFERENCES `PatchCableHeap` (`id`) ON DELETE CASCADE
871 ) ENGINE=InnoDB";
872
873 $query[] = "CREATE TABLE `PatchCableOIFCompat` (
874 `pctype_id` int(10) unsigned NOT NULL,
875 `oif_id` int(10) unsigned NOT NULL,
876 PRIMARY KEY (`pctype_id`,`oif_id`),
877 KEY `oif_id` (`oif_id`),
878 CONSTRAINT `PatchCableOIFCompat-FK-oif_id` FOREIGN KEY (`oif_id`) REFERENCES `PortOuterInterface` (`id`),
879 CONSTRAINT `PatchCableOIFCompat-FK-pctype_id` FOREIGN KEY (`pctype_id`) REFERENCES `PatchCableType` (`id`)
880 ) ENGINE=InnoDB";
881
882 $query[] = "CREATE TABLE `PatchCableType` (
883 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
884 `origin` enum('default','custom') NOT NULL DEFAULT 'custom',
885 `pctype` char(64) NOT NULL,
886 PRIMARY KEY (`id`),
887 UNIQUE KEY `pctype_per_origin` (`pctype`,`origin`)
888 ) ENGINE=InnoDB";
889
890 $query[] = "CREATE TABLE `Plugin` (
891 `name` char(255) NOT NULL,
892 `longname` char(255) NOT NULL,
893 `version` char(64) NOT NULL,
894 `home_url` char(255) NOT NULL,
895 `state` enum('disabled','enabled') NOT NULL default 'disabled',
896 PRIMARY KEY (`name`)
897 ) ENGINE=InnoDB";
898
899 $query[] = "CREATE TABLE `Port` (
900 `id` int(10) unsigned NOT NULL auto_increment,
901 `object_id` int(10) unsigned NOT NULL default '0',
902 `name` char(255) NOT NULL default '',
903 `iif_id` int(10) unsigned NOT NULL,
904 `type` int(10) unsigned NOT NULL default '0',
905 `l2address` char(64) default NULL,
906 `reservation_comment` char(255) default NULL,
907 `label` char(255) default NULL,
908 PRIMARY KEY (`id`),
909 UNIQUE KEY `object_iif_oif_name` (`object_id`,`iif_id`,`type`,`name`),
910 KEY `type` (`type`),
911 KEY `comment` (`reservation_comment`),
912 KEY `l2address` (`l2address`),
913 KEY `Port-FK-iif-oif` (`iif_id`,`type`),
914 CONSTRAINT `Port-FK-iif-oif` FOREIGN KEY (`iif_id`, `type`) REFERENCES `PortInterfaceCompat` (`iif_id`, `oif_id`),
915 CONSTRAINT `Port-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `Object` (`id`) ON DELETE CASCADE
916 ) ENGINE=InnoDB";
917
918 $query[] = "CREATE TABLE `PortAllowedVLAN` (
919 `object_id` int(10) unsigned NOT NULL,
920 `port_name` char(255) NOT NULL,
921 `vlan_id` int(10) unsigned NOT NULL default '0',
922 PRIMARY KEY (`object_id`,`port_name`,`vlan_id`),
923 KEY `vlan_id` (`vlan_id`),
924 CONSTRAINT `PortAllowedVLAN-FK-object-port` FOREIGN KEY (`object_id`, `port_name`) REFERENCES `PortVLANMode` (`object_id`, `port_name`) ON DELETE CASCADE,
925 CONSTRAINT `PortAllowedVLAN-FK-vlan_id` FOREIGN KEY (`vlan_id`) REFERENCES `VLANValidID` (`vlan_id`)
926 ) ENGINE=InnoDB";
927
928 $query[] = "CREATE TABLE `PortCompat` (
929 `type1` int(10) unsigned NOT NULL default '0',
930 `type2` int(10) unsigned NOT NULL default '0',
931 UNIQUE KEY `type1_2` (`type1`,`type2`),
932 KEY `type2` (`type2`),
933 CONSTRAINT `PortCompat-FK-oif_id1` FOREIGN KEY (`type1`) REFERENCES `PortOuterInterface` (`id`),
934 CONSTRAINT `PortCompat-FK-oif_id2` FOREIGN KEY (`type2`) REFERENCES `PortOuterInterface` (`id`)
935 ) ENGINE=InnoDB";
936
937 $query[] = "CREATE TABLE `PortInnerInterface` (
938 `id` int(10) unsigned NOT NULL,
939 `iif_name` char(16) NOT NULL,
940 PRIMARY KEY (`id`),
941 UNIQUE KEY `iif_name` (`iif_name`)
942 ) ENGINE=InnoDB";
943
944 $query[] = "CREATE TABLE `PortInterfaceCompat` (
945 `iif_id` int(10) unsigned NOT NULL,
946 `oif_id` int(10) unsigned NOT NULL,
947 UNIQUE KEY `pair` (`iif_id`,`oif_id`),
948 CONSTRAINT `PortInterfaceCompat-FK-iif_id` FOREIGN KEY (`iif_id`) REFERENCES `PortInnerInterface` (`id`),
949 CONSTRAINT `PortInterfaceCompat-FK-oif_id` FOREIGN KEY (`oif_id`) REFERENCES `PortOuterInterface` (`id`)
950 ) ENGINE=InnoDB";
951
952 $query[] = "CREATE TABLE `PortLog` (
953 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
954 `port_id` int(10) unsigned NOT NULL,
955 `date` datetime NOT NULL,
956 `user` varchar(64) NOT NULL,
957 `message` text NOT NULL,
958 PRIMARY KEY (`id`),
959 KEY `port_id-date` (`port_id`,`date`),
960 CONSTRAINT `PortLog_ibfk_1` FOREIGN KEY (`port_id`) REFERENCES `Port` (`id`) ON DELETE CASCADE
961 ) ENGINE=InnoDB";
962
963 $query[] = "CREATE TABLE `PortNativeVLAN` (
964 `object_id` int(10) unsigned NOT NULL,
965 `port_name` char(255) NOT NULL,
966 `vlan_id` int(10) unsigned NOT NULL default '0',
967 PRIMARY KEY (`object_id`,`port_name`,`vlan_id`),
968 UNIQUE KEY `port_id` (`object_id`,`port_name`),
969 CONSTRAINT `PortNativeVLAN-FK-compound` FOREIGN KEY (`object_id`, `port_name`, `vlan_id`) REFERENCES `PortAllowedVLAN` (`object_id`, `port_name`, `vlan_id`) ON DELETE CASCADE
970 ) ENGINE=InnoDB";
971
972 $query[] = "CREATE TABLE `PortOuterInterface` (
973 `id` int(10) unsigned NOT NULL auto_increment,
974 `oif_name` char(48) NOT NULL,
975 PRIMARY KEY (`id`),
976 UNIQUE KEY `oif_name` (`oif_name`)
977 ) ENGINE=InnoDB";
978
979 $query[] = "CREATE TABLE `PortVLANMode` (
980 `object_id` int(10) unsigned NOT NULL,
981 `port_name` char(255) NOT NULL,
982 `vlan_mode` enum('access','trunk') NOT NULL default 'access',
983 PRIMARY KEY (`object_id`,`port_name`),
984 CONSTRAINT `PortVLANMode-FK-object-port` FOREIGN KEY (`object_id`, `port_name`) REFERENCES `CachedPVM` (`object_id`, `port_name`)
985 ) ENGINE=InnoDB";
986
987 $query[] = "CREATE TABLE `Object` (
988 `id` int(10) unsigned NOT NULL auto_increment,
989 `name` char(255) default NULL,
990 `label` char(255) default NULL,
991 `objtype_id` int(10) unsigned NOT NULL default '1',
992 `asset_no` char(64) default NULL,
993 `has_problems` enum('yes','no') NOT NULL default 'no',
994 `comment` text,
995 PRIMARY KEY (`id`),
996 UNIQUE KEY `asset_no` (`asset_no`),
997 KEY `id-tid` (`id`,`objtype_id`),
998 KEY `type_id` (`objtype_id`,`id`)
999 ) ENGINE=InnoDB";
1000
1001 $query[] = "CREATE TABLE `ObjectHistory` (
1002 `event_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
1003 `id` int(10) unsigned default NULL,
1004 `name` char(255) default NULL,
1005 `label` char(255) default NULL,
1006 `objtype_id` int(10) unsigned default NULL,
1007 `asset_no` char(64) default NULL,
1008 `has_problems` enum('yes','no') NOT NULL default 'no',
1009 `comment` text,
1010 `ctime` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
1011 `user_name` char(64) default NULL,
1012 PRIMARY KEY (`event_id`),
1013 KEY `id` (`id`),
1014 CONSTRAINT `ObjectHistory-FK-object_id` FOREIGN KEY (`id`) REFERENCES `Object` (`id`) ON DELETE CASCADE
1015 ) ENGINE=InnoDB";
1016
1017 $query[] = "CREATE TABLE `RackSpace` (
1018 `rack_id` int(10) unsigned NOT NULL default '0',
1019 `unit_no` int(10) unsigned NOT NULL default '0',
1020 `atom` enum('front','interior','rear') NOT NULL default 'interior',
1021 `state` enum('A','U','T') NOT NULL default 'A',
1022 `object_id` int(10) unsigned default NULL,
1023 PRIMARY KEY (`rack_id`,`unit_no`,`atom`),
1024 KEY `RackSpace_object_id` (`object_id`),
1025 CONSTRAINT `RackSpace-FK-rack_id` FOREIGN KEY (`rack_id`) REFERENCES `Object` (`id`),
1026 CONSTRAINT `RackSpace-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `Object` (`id`) ON DELETE CASCADE
1027 ) ENGINE=InnoDB";
1028
1029 $query[] = "CREATE TABLE `RackThumbnail` (
1030 `rack_id` int(10) unsigned NOT NULL,
1031 `thumb_data` blob,
1032 UNIQUE KEY `rack_id` (`rack_id`),
1033 CONSTRAINT `RackThumbnail-FK-rack_id` FOREIGN KEY (`rack_id`) REFERENCES `Object` (`id`) ON DELETE CASCADE
1034 ) ENGINE=InnoDB";
1035
1036 $query[] = "CREATE TABLE `Script` (
1037 `script_name` char(64) NOT NULL,
1038 `script_text` longtext,
1039 PRIMARY KEY (`script_name`)
1040 ) ENGINE=InnoDB";
1041
1042 $query[] = "CREATE TABLE `TagStorage` (
1043 `entity_realm` enum('file','ipv4net','ipv4rspool','ipv4vs','ipvs','ipv6net','location','object','rack','user','vst') NOT NULL default 'object',
1044 `entity_id` int(10) unsigned NOT NULL,
1045 `tag_id` int(10) unsigned NOT NULL default '0',
1046 `tag_is_assignable` enum('yes','no') NOT NULL DEFAULT 'yes',
1047 `user` char(64) DEFAULT NULL,
1048 `date` datetime DEFAULT NULL,
1049 UNIQUE KEY `entity_tag` (`entity_realm`,`entity_id`,`tag_id`),
1050 KEY `entity_id` (`entity_id`),
1051 KEY `TagStorage-FK-tag_id` (`tag_id`),
1052 KEY `tag_id-tag_is_assignable` (`tag_id`,`tag_is_assignable`),
1053 CONSTRAINT `TagStorage-FK-TagTree` FOREIGN KEY (`tag_id`, `tag_is_assignable`) REFERENCES `TagTree` (`id`, `is_assignable`)
1054 ) ENGINE=InnoDB";
1055
1056 $query[] = "CREATE TABLE `TagTree` (
1057 `id` int(10) unsigned NOT NULL auto_increment,
1058 `parent_id` int(10) unsigned default NULL,
1059 `is_assignable` enum('yes','no') NOT NULL DEFAULT 'yes',
1060 `tag` char(255) default NULL,
1061 `color` mediumint(8) unsigned DEFAULT NULL,
1062 `description` char(255) COLLATE utf8_unicode_ci DEFAULT NULL,
1063 PRIMARY KEY (`id`),
1064 UNIQUE KEY `tag` (`tag`),
1065 KEY `TagTree-K-parent_id` (`parent_id`),
1066 KEY `id-is_assignable` (`id`,`is_assignable`),
1067 CONSTRAINT `TagTree-K-parent_id` FOREIGN KEY (`parent_id`) REFERENCES `TagTree` (`id`)
1068 ) ENGINE=InnoDB";
1069
1070 $query[] = "CREATE TABLE `UserAccount` (
1071 `user_id` int(10) unsigned NOT NULL auto_increment,
1072 `user_name` char(64) NOT NULL default '',
1073 `user_password_hash` char(40) default NULL,
1074 `user_realname` char(64) default NULL,
1075 PRIMARY KEY (`user_id`),
1076 UNIQUE KEY `user_name` (`user_name`)
1077 ) ENGINE=InnoDB";
1078
1079 $query[] = "CREATE TABLE `UserConfig` (
1080 `varname` char(32) NOT NULL,
1081 `varvalue` text NOT NULL,
1082 `user` char(64) NOT NULL,
1083 UNIQUE KEY `user_varname` (`user`,`varname`),
1084 KEY `varname` (`varname`),
1085 CONSTRAINT `UserConfig-FK-varname` FOREIGN KEY (`varname`) REFERENCES `Config` (`varname`) ON DELETE CASCADE ON UPDATE CASCADE
1086 ) ENGINE=InnoDB";
1087
1088 $query[] = "CREATE TABLE `VLANDescription` (
1089 `domain_id` int(10) unsigned NOT NULL,
1090 `vlan_id` int(10) unsigned NOT NULL default '0',
1091 `vlan_type` enum('ondemand','compulsory','alien') NOT NULL default 'ondemand',
1092 `vlan_descr` char(255) default NULL,
1093 PRIMARY KEY (`domain_id`,`vlan_id`),
1094 KEY `vlan_id` (`vlan_id`),
1095 CONSTRAINT `VLANDescription-FK-domain_id` FOREIGN KEY (`domain_id`) REFERENCES `VLANDomain` (`id`) ON DELETE CASCADE,
1096 CONSTRAINT `VLANDescription-FK-vlan_id` FOREIGN KEY (`vlan_id`) REFERENCES `VLANValidID` (`vlan_id`)
1097 ) ENGINE=InnoDB";
1098
1099 $query[] = "CREATE TABLE `VLANDomain` (
1100 `id` int(10) unsigned NOT NULL auto_increment,
1101 `group_id` int(10) unsigned default NULL,
1102 `description` char(255) default NULL,
1103 PRIMARY KEY (`id`),
1104 UNIQUE KEY `description` (`description`),
1105 CONSTRAINT `VLANDomain-FK-group_id` FOREIGN KEY (`group_id`) REFERENCES `VLANDomain` (`id`) ON DELETE SET NULL
1106 ) ENGINE=InnoDB";
1107
1108 $query[] = "CREATE TABLE `VLANIPv4` (
1109 `domain_id` int(10) unsigned NOT NULL,
1110 `vlan_id` int(10) unsigned NOT NULL,
1111 `ipv4net_id` int(10) unsigned NOT NULL,
1112 UNIQUE KEY `network-domain-vlan` (`ipv4net_id`,`domain_id`,`vlan_id`),
1113 KEY `VLANIPv4-FK-compound` (`domain_id`,`vlan_id`),
1114 CONSTRAINT `VLANIPv4-FK-compound` FOREIGN KEY (`domain_id`, `vlan_id`) REFERENCES `VLANDescription` (`domain_id`, `vlan_id`) ON DELETE CASCADE,
1115 CONSTRAINT `VLANIPv4-FK-ipv4net_id` FOREIGN KEY (`ipv4net_id`) REFERENCES `IPv4Network` (`id`) ON DELETE CASCADE
1116 ) ENGINE=InnoDB";
1117
1118 $query[] = "CREATE TABLE `VLANIPv6` (
1119 `domain_id` int(10) unsigned NOT NULL,
1120 `vlan_id` int(10) unsigned NOT NULL,
1121 `ipv6net_id` int(10) unsigned NOT NULL,
1122 UNIQUE KEY `network-domain-vlan` (`ipv6net_id`,`domain_id`,`vlan_id`),
1123 KEY `VLANIPv6-FK-compound` (`domain_id`,`vlan_id`),
1124 CONSTRAINT `VLANIPv6-FK-compound` FOREIGN KEY (`domain_id`, `vlan_id`) REFERENCES `VLANDescription` (`domain_id`, `vlan_id`) ON DELETE CASCADE,
1125 CONSTRAINT `VLANIPv6-FK-ipv6net_id` FOREIGN KEY (`ipv6net_id`) REFERENCES `IPv6Network` (`id`) ON DELETE CASCADE
1126 ) ENGINE=InnoDB";
1127
1128 $query[] = "CREATE TABLE `VLANSTRule` (
1129 `vst_id` int(10) unsigned NOT NULL,
1130 `rule_no` int(10) unsigned NOT NULL,
1131 `port_pcre` char(255) NOT NULL,
1132 `port_role` enum('access','trunk','anymode','uplink','downlink','none') NOT NULL default 'none',
1133 `wrt_vlans` text,
1134 `description` char(255) default NULL,
1135 UNIQUE KEY `vst-rule` (`vst_id`,`rule_no`),
1136 CONSTRAINT `VLANSTRule-FK-vst_id` FOREIGN KEY (`vst_id`) REFERENCES `VLANSwitchTemplate` (`id`) ON DELETE CASCADE
1137 ) ENGINE=InnoDB";
1138
1139 $query[] = "CREATE TABLE `VLANSwitch` (
1140 `object_id` int(10) unsigned NOT NULL,
1141 `domain_id` int(10) unsigned NOT NULL,
1142 `template_id` int(10) unsigned NOT NULL,
1143 `mutex_rev` int(10) unsigned NOT NULL default '0',
1144 `out_of_sync` enum('yes','no') NOT NULL default 'yes',
1145 `last_errno` int(10) unsigned NOT NULL default '0',
1146 `last_change` timestamp NOT NULL default '0000-00-00 00:00:00',
1147 `last_push_started` timestamp NOT NULL default '0000-00-00 00:00:00',
1148 `last_push_finished` timestamp NOT NULL default '0000-00-00 00:00:00',
1149 `last_error_ts` timestamp NOT NULL default '0000-00-00 00:00:00',
1150 UNIQUE KEY `object_id` (`object_id`),
1151 KEY `domain_id` (`domain_id`),
1152 KEY `template_id` (`template_id`),
1153 KEY `out_of_sync` (`out_of_sync`),
1154 KEY `last_errno` (`last_errno`),
1155 CONSTRAINT `VLANSwitch-FK-domain_id` FOREIGN KEY (`domain_id`) REFERENCES `VLANDomain` (`id`),
1156 CONSTRAINT `VLANSwitch-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `Object` (`id`),
1157 CONSTRAINT `VLANSwitch-FK-template_id` FOREIGN KEY (`template_id`) REFERENCES `VLANSwitchTemplate` (`id`)
1158 ) ENGINE=InnoDB";
1159
1160 $query[] = "CREATE TABLE `VLANSwitchTemplate` (
1161 `id` int(10) unsigned NOT NULL auto_increment,
1162 `mutex_rev` int(10) NOT NULL,
1163 `description` char(255) default NULL,
1164 `saved_by` char(64) NOT NULL,
1165 PRIMARY KEY (`id`),
1166 UNIQUE KEY `description` (`description`)
1167 ) ENGINE=InnoDB";
1168
1169 $query[] = "CREATE TABLE `VLANValidID` (
1170 `vlan_id` int(10) unsigned NOT NULL default '1',
1171 PRIMARY KEY (`vlan_id`)
1172 ) ENGINE=InnoDB";
1173
1174 $query[] = "CREATE TABLE `VS` (
1175 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
1176 `name` char(255) DEFAULT NULL,
1177 `vsconfig` text,
1178 `rsconfig` text,
1179 PRIMARY KEY (`id`)
1180 ) ENGINE=InnoDB";
1181
1182 $query[] = "CREATE TABLE `VSIPs` (
1183 `vs_id` int(10) unsigned NOT NULL,
1184 `vip` varbinary(16) NOT NULL,
1185 `vsconfig` text,
1186 `rsconfig` text,
1187 PRIMARY KEY (`vs_id`,`vip`),
1188 KEY `vip` (`vip`),
1189 CONSTRAINT `VSIPs-vs_id` FOREIGN KEY (`vs_id`) REFERENCES `VS` (`id`) ON DELETE CASCADE
1190 ) ENGINE=InnoDB";
1191
1192 $query[] = "CREATE TABLE `VSPorts` (
1193 `vs_id` int(10) unsigned NOT NULL,
1194 `proto` enum('TCP','UDP','MARK') NOT NULL,
1195 `vport` int(10) unsigned NOT NULL,
1196 `vsconfig` text,
1197 `rsconfig` text,
1198 PRIMARY KEY (`vs_id`,`proto`,`vport`),
1199 KEY `proto-vport` (`proto`,`vport`),
1200 CONSTRAINT `VS-vs_id` FOREIGN KEY (`vs_id`) REFERENCES `VS` (`id`) ON DELETE CASCADE
1201 ) ENGINE=InnoDB";
1202
1203 $query[] = "CREATE TABLE `VSEnabledIPs` (
1204 `object_id` int(10) unsigned NOT NULL,
1205 `vs_id` int(10) unsigned NOT NULL,
1206 `vip` varbinary(16) NOT NULL,
1207 `rspool_id` int(10) unsigned NOT NULL,
1208 `prio` varchar(255) DEFAULT NULL,
1209 `vsconfig` text,
1210 `rsconfig` text,
1211 PRIMARY KEY (`object_id`,`vs_id`,`vip`,`rspool_id`),
1212 KEY `vip` (`vip`),
1213 KEY `VSEnabledIPs-FK-vs_id-vip` (`vs_id`,`vip`),
1214 KEY `VSEnabledIPs-FK-rspool_id` (`rspool_id`),
1215 CONSTRAINT `VSEnabledIPs-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `Object` (`id`) ON DELETE CASCADE,
1216 CONSTRAINT `VSEnabledIPs-FK-rspool_id` FOREIGN KEY (`rspool_id`) REFERENCES `IPv4RSPool` (`id`) ON DELETE CASCADE,
1217 CONSTRAINT `VSEnabledIPs-FK-vs_id-vip` FOREIGN KEY (`vs_id`, `vip`) REFERENCES `VSIPs` (`vs_id`, `vip`) ON DELETE CASCADE
1218 ) ENGINE=InnoDB";
1219
1220 $query[] = "CREATE TABLE `VSEnabledPorts` (
1221 `object_id` int(10) unsigned NOT NULL,
1222 `vs_id` int(10) unsigned NOT NULL,
1223 `proto` enum('TCP','UDP','MARK') NOT NULL,
1224 `vport` int(10) unsigned NOT NULL,
1225 `rspool_id` int(10) unsigned NOT NULL,
1226 `vsconfig` text,
1227 `rsconfig` text,
1228 PRIMARY KEY (`object_id`,`vs_id`,`proto`,`vport`,`rspool_id`),
1229 KEY `VSEnabledPorts-FK-vs_id-proto-vport` (`vs_id`,`proto`,`vport`),
1230 KEY `VSEnabledPorts-FK-rspool_id` (`rspool_id`),
1231 CONSTRAINT `VSEnabledPorts-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES `Object` (`id`) ON DELETE CASCADE,
1232 CONSTRAINT `VSEnabledPorts-FK-rspool_id` FOREIGN KEY (`rspool_id`) REFERENCES `IPv4RSPool` (`id`) ON DELETE CASCADE,
1233 CONSTRAINT `VSEnabledPorts-FK-vs_id-proto-vport` FOREIGN KEY (`vs_id`, `proto`, `vport`) REFERENCES `VSPorts` (`vs_id`, `proto`, `vport`) ON DELETE CASCADE
1234 ) ENGINE=InnoDB";
1235
1236 $query[] = "
1237 CREATE TRIGGER `EntityLink-before-insert` BEFORE INSERT ON `EntityLink` FOR EACH ROW
1238 EntityLinkTrigger:BEGIN
1239 DECLARE parent_objtype, child_objtype, count INTEGER;
1240
1241 # forbid linking an entity to itself
1242 IF NEW.parent_entity_type = NEW.child_entity_type AND NEW.parent_entity_id = NEW.child_entity_id THEN
1243 SET NEW.parent_entity_id = NULL;
1244 LEAVE EntityLinkTrigger;
1245 END IF;
1246
1247 # in some scenarios, only one parent is allowed
1248 CASE CONCAT(NEW.parent_entity_type, '.', NEW.child_entity_type)
1249 WHEN 'location.location' THEN
1250 SELECT COUNT(*) INTO count FROM EntityLink WHERE parent_entity_type = 'location' AND child_entity_type = 'location' AND child_entity_id = NEW.child_entity_id;
1251 WHEN 'location.row' THEN
1252 SELECT COUNT(*) INTO count FROM EntityLink WHERE parent_entity_type = 'location' AND child_entity_type = 'row' AND child_entity_id = NEW.child_entity_id;
1253 WHEN 'row.rack' THEN
1254 SELECT COUNT(*) INTO count FROM EntityLink WHERE parent_entity_type = 'row' AND child_entity_type = 'rack' AND child_entity_id = NEW.child_entity_id;
1255 ELSE
1256 # some other scenario, assume it is valid
1257 SET count = 0;
1258 END CASE;
1259 IF count > 0 THEN
1260 SET NEW.parent_entity_id = NULL;
1261 LEAVE EntityLinkTrigger;
1262 END IF;
1263
1264 IF NEW.parent_entity_type = 'object' AND NEW.child_entity_type = 'object' THEN
1265 # lock objects to prevent concurrent link establishment
1266 SELECT objtype_id INTO parent_objtype FROM Object WHERE id = NEW.parent_entity_id FOR UPDATE;
1267 SELECT objtype_id INTO child_objtype FROM Object WHERE id = NEW.child_entity_id FOR UPDATE;
1268
1269 # only permit the link if object types are compatibile
1270 SELECT COUNT(*) INTO count FROM ObjectParentCompat WHERE parent_objtype_id = parent_objtype AND child_objtype_id = child_objtype;
1271 IF count = 0 THEN
1272 SET NEW.parent_entity_id = NULL;
1273 END IF;
1274 END IF;
1275 END;
1276 ";
1277 $query[] = "
1278 CREATE TRIGGER `EntityLink-before-update` BEFORE UPDATE ON `EntityLink` FOR EACH ROW
1279 EntityLinkTrigger:BEGIN
1280 DECLARE parent_objtype, child_objtype, count INTEGER;
1281
1282 # forbid linking an entity to itself
1283 IF NEW.parent_entity_type = NEW.child_entity_type AND NEW.parent_entity_id = NEW.child_entity_id THEN
1284 SET NEW.parent_entity_id = NULL;
1285 LEAVE EntityLinkTrigger;
1286 END IF;
1287
1288 # in some scenarios, only one parent is allowed
1289 CASE CONCAT(NEW.parent_entity_type, '.', NEW.child_entity_type)
1290 WHEN 'location.location' THEN
1291 SELECT COUNT(*) INTO count FROM EntityLink WHERE parent_entity_type = 'location' AND child_entity_type = 'location' AND child_entity_id = NEW.child_entity_id AND id != NEW.id;
1292 WHEN 'location.row' THEN
1293 SELECT COUNT(*) INTO count FROM EntityLink WHERE parent_entity_type = 'location' AND child_entity_type = 'row' AND child_entity_id = NEW.child_entity_id AND id != NEW.id;
1294 WHEN 'row.rack' THEN
1295 SELECT COUNT(*) INTO count FROM EntityLink WHERE parent_entity_type = 'row' AND child_entity_type = 'rack' AND child_entity_id = NEW.child_entity_id AND id != NEW.id;
1296 ELSE
1297 # some other scenario, assume it is valid
1298 SET count = 0;
1299 END CASE;
1300 IF count > 0 THEN
1301 SET NEW.parent_entity_id = NULL;
1302 LEAVE EntityLinkTrigger;
1303 END IF;
1304
1305 IF NEW.parent_entity_type = 'object' AND NEW.child_entity_type = 'object' THEN
1306 # lock objects to prevent concurrent link establishment
1307 SELECT objtype_id INTO parent_objtype FROM Object WHERE id = NEW.parent_entity_id FOR UPDATE;
1308 SELECT objtype_id INTO child_objtype FROM Object WHERE id = NEW.child_entity_id FOR UPDATE;
1309
1310 # only permit the link if object types are compatibile
1311 SELECT COUNT(*) INTO count FROM ObjectParentCompat WHERE parent_objtype_id = parent_objtype AND child_objtype_id = child_objtype;
1312 IF count = 0 THEN
1313 SET NEW.parent_entity_id = NULL;
1314 END IF;
1315 END IF;
1316 END;
1317 ";
1318 $link_trigger_body = <<<'ENDOFTRIGGER'
1319 LinkTrigger:BEGIN
1320 DECLARE tmp, porta_type, portb_type, count INTEGER;
1321
1322 IF NEW.porta = NEW.portb THEN
1323 # forbid connecting a port to itself
1324 SET NEW.porta = NULL;
1325 LEAVE LinkTrigger;
1326 ELSEIF NEW.porta > NEW.portb THEN
1327 # force porta < portb
1328 SET tmp = NEW.porta;
1329 SET NEW.porta = NEW.portb;
1330 SET NEW.portb = tmp;
1331 END IF;
1332
1333 # lock ports to prevent concurrent link establishment
1334 SELECT type INTO porta_type FROM Port WHERE id = NEW.porta FOR UPDATE;
1335 SELECT type INTO portb_type FROM Port WHERE id = NEW.portb FOR UPDATE;
1336
1337 # only permit the link if ports are compatibile
1338 SELECT COUNT(*) INTO count FROM PortCompat WHERE (type1 = porta_type AND type2 = portb_type) OR (type1 = portb_type AND type2 = porta_type);
1339 IF count = 0 THEN
1340 SET NEW.porta = NULL;
1341 END IF;
1342 END;
1343 ENDOFTRIGGER;
1344 $query[] = "CREATE TRIGGER `Link-before-insert` BEFORE INSERT ON `Link` FOR EACH ROW $link_trigger_body";
1345 $query[] = "CREATE TRIGGER `Link-before-update` BEFORE UPDATE ON `Link` FOR EACH ROW $link_trigger_body";
1346
1347 $query[] = "CREATE VIEW `Location` AS SELECT O.id, O.name, O.has_problems, O.comment, P.id AS parent_id, P.name AS parent_name
1348 FROM `Object` O
1349 LEFT JOIN (
1350 `Object` P INNER JOIN `EntityLink` EL
1351 ON EL.parent_entity_id = P.id AND P.objtype_id = 1562 AND EL.parent_entity_type = 'location' AND EL.child_entity_type = 'location'
1352 ) ON EL.child_entity_id = O.id
1353 WHERE O.objtype_id = 1562";
1354
1355 $query[] = "CREATE VIEW `Row` AS SELECT O.id, O.name, L.id AS location_id, L.name AS location_name
1356 FROM `Object` O
1357 LEFT JOIN `EntityLink` EL ON O.id = EL.child_entity_id AND EL.parent_entity_type = 'location' AND EL.child_entity_type = 'row'
1358 LEFT JOIN `Object` L ON EL.parent_entity_id = L.id AND L.objtype_id = 1562
1359 WHERE O.objtype_id = 1561";
1360
1361 $query[] = "CREATE VIEW `Rack` AS SELECT O.id, O.name AS name, O.asset_no, O.has_problems, O.comment,
1362 AV_H.uint_value AS height,
1363 AV_S.uint_value AS sort_order,
1364 RT.thumb_data,
1365 R.id AS row_id,
1366 R.name AS row_name,
1367 L.id AS location_id,
1368 L.name AS location_name
1369 FROM `Object` O
1370 LEFT JOIN `AttributeValue` AV_H ON O.id = AV_H.object_id AND AV_H.attr_id = 27
1371 LEFT JOIN `AttributeValue` AV_S ON O.id = AV_S.object_id AND AV_S.attr_id = 29
1372 LEFT JOIN `RackThumbnail` RT ON O.id = RT.rack_id
1373 LEFT JOIN `EntityLink` RL ON O.id = RL.child_entity_id AND RL.parent_entity_type = 'row' AND RL.child_entity_type = 'rack'
1374 INNER JOIN `Object` R ON R.id = RL.parent_entity_id
1375 LEFT JOIN `EntityLink` LL ON R.id = LL.child_entity_id AND LL.parent_entity_type = 'location' AND LL.child_entity_type = 'row'
1376 LEFT JOIN `Object` L ON L.id = LL.parent_entity_id
1377 WHERE O.objtype_id = 1560";
1378
1379 $query[] = "CREATE VIEW `RackObject` AS SELECT id, name, label, objtype_id, asset_no, has_problems, comment FROM `Object`
1380 WHERE `objtype_id` NOT IN (1560, 1561, 1562)";
1381
1382 $query[] = "SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS";
1383
1384 return $query;
1385 ##########################################################################
1386 case 'dictbase':
1387 $db_version = CODE_VERSION;
1388 $query = array();
1389
1390 $query[] = "INSERT INTO `Attribute` (`id`, `type`, `name`) VALUES
1391 (1,'string','OEM S/N 1'),
1392 (2,'dict','HW type'),
1393 (3,'string','FQDN'),
1394 (4,'dict','SW type'),
1395 (5,'string','SW version'),
1396 (6,'uint','number of ports'),
1397 (7,'float','max. current, Ampers'),
1398 (8,'float','power load, percents'),
1399 (13,'float','max power, Watts'),
1400 (14,'string','contact person'),
1401 (16,'uint','flash memory, MB'),
1402 (17,'uint','DRAM, MB'),
1403 (18,'uint','CPU, MHz'),
1404 (20,'string','OEM S/N 2'),
1405 (21,'date','support contract expiration'),
1406 (22,'date','HW warranty expiration'),
1407 (24,'date','SW warranty expiration'),
1408 (25,'string','UUID'),
1409 (26,'dict','Hypervisor'),
1410 (27,'uint','Height, units'),
1411 (28,'string','Slot number'),
1412 (29,'uint','Sort order'),
1413 (30,'dict','Mgmt type'),
1414 -- ^^^^^ Any new 'default' attributes must go above this line! ^^^^^
1415 -- Primary key value 9999 makes sure that AUTO_INCREMENT on server restart
1416 -- doesn't drop below 10000 (other code relies on this, site-specific
1417 -- attributes are assigned IDs starting from 10000).
1418 (9999,'string','base MAC address')";
1419
1420 $query[] = "INSERT INTO `Chapter` (`id`, `sticky`, `name`) VALUES
1421 (1,'yes','ObjectType'),
1422 (11,'no','server models'),
1423 (12,'no','network switch models'),
1424 (13,'no','server OS type'),
1425 (14,'no','switch OS type'),
1426 (16,'no','router OS type'),
1427 (17,'no','router models'),
1428 (18,'no','disk array models'),
1429 (19,'no','tape library models'),
1430 (21,'no','KVM switch models'),
1431 (23,'no','console models'),
1432 (24,'no','network security models'),
1433 (25,'no','wireless models'),
1434 (26,'no','fibre channel switch models'),
1435 (27,'no','PDU models'),
1436 (28,'no','Voice/video hardware'),
1437 (29,'no','Yes/No'),
1438 (30,'no','network chassis models'),
1439 (31,'no','server chassis models'),
1440 (32,'no','virtual switch models'),
1441 (33,'no','virtual switch OS type'),
1442 (34,'no','power supply chassis models'),
1443 (35,'no','power supply models'),
1444 (36,'no','serial console server models'),
1445 (37,'no','wireless OS type'),
1446 (38,'no','management interface type'),
1447 (39,'no','UPS models'),
1448 -- Default chapters must have ID less than 10000, add them above this line.
1449 (9999,'no','multiplexer models')";
1450
1451 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_id`, `sticky`) VALUES
1452 (2,1,NULL,'no'),
1453 (2,2,27,'no'),
1454 (2,3,NULL,'no'),
1455 (2,5,NULL,'no'),
1456 (4,1,NULL,'no'),
1457 (4,2,11,'no'),
1458 (4,3,NULL,'no'),
1459 (4,4,13,'no'),
1460 (4,14,NULL,'no'),
1461 (4,21,NULL,'no'),
1462 (4,22,NULL,'no'),
1463 (4,24,NULL,'no'),
1464 (4,25,NULL,'no'),
1465 (4,26,29,'yes'),
1466 (4,28,NULL,'yes'),
1467 (5,1,NULL,'no'),
1468 (5,2,18,'no'),
1469 (6,1,NULL,'no'),
1470 (6,2,19,'no'),
1471 (6,20,NULL,'no'),
1472 (7,1,NULL,'no'),
1473 (7,2,17,'no'),
1474 (7,3,NULL,'no'),
1475 (7,4,16,'no'),
1476 (7,5,NULL,'no'),
1477 (7,14,NULL,'no'),
1478 (7,16,NULL,'no'),
1479 (7,17,NULL,'no'),
1480 (7,18,NULL,'no'),
1481 (7,21,NULL,'no'),
1482 (7,22,NULL,'no'),
1483 (7,24,NULL,'no'),
1484 (8,1,NULL,'yes'),
1485 (8,2,12,'yes'),
1486 (8,3,NULL,'no'),
1487 (8,4,14,'yes'),
1488 (8,5,NULL,'no'),
1489 (8,14,NULL,'no'),
1490 (8,16,NULL,'no'),
1491 (8,17,NULL,'no'),
1492 (8,18,NULL,'no'),
1493 (8,20,NULL,'no'),
1494 (8,21,NULL,'no'),
1495 (8,22,NULL,'no'),
1496 (8,24,NULL,'no'),
1497 (8,28,NULL,'yes'),
1498 (9,6,NULL,'no'),
1499 (12,1,NULL,'no'),
1500 (12,3,NULL,'no'),
1501 (12,7,NULL,'no'),
1502 (12,8,NULL,'no'),
1503 (12,13,NULL,'no'),
1504 (12,20,NULL,'no'),
1505 (15,2,23,'no'),
1506 (445,1,NULL,'no'),
1507 (445,2,21,'no'),
1508 (445,3,NULL,'no'),
1509 (445,5,NULL,'no'),
1510 (445,14,NULL,'no'),
1511 (445,22,NULL,'no'),
1512 (447,1,NULL,'no'),
1513 (447,2,9999,'no'),
1514 (447,3,NULL,'no'),
1515 (447,5,NULL,'no'),
1516 (447,14,NULL,'no'),
1517 (447,22,NULL,'no'),
1518 (798,1,NULL,'no'),
1519 (798,2,24,'no'),
1520 (798,3,NULL,'no'),
1521 (798,5,NULL,'no'),
1522 (798,14,NULL,'no'),
1523 (798,16,NULL,'no'),
1524 (798,17,NULL,'no'),
1525 (798,18,NULL,'no'),
1526 (798,20,NULL,'no'),
1527 (798,21,NULL,'no'),
1528 (798,22,NULL,'no'),
1529 (798,24,NULL,'no'),
1530 (798,28,NULL,'yes'),
1531 (965,1,NULL,'no'),
1532 (965,2,25,'no'),
1533 (965,3,NULL,'no'),
1534 (965,4,37,'no'),
1535 (1055,2,26,'no'),
1536 (1055,28,NULL,'yes'),
1537 (1323,1,NULL,'no'),
1538 (1323,2,28,'no'),
1539 (1323,3,NULL,'no'),
1540 (1323,5,NULL,'no'),
1541 (1397,1,NULL,'no'),
1542 (1397,2,34,'no'),
1543 (1397,14,NULL,'no'),
1544 (1397,21,NULL,'no'),
1545 (1397,22,NULL,'no'),
1546 (1398,1,NULL,'no'),
1547 (1398,2,35,'no'),
1548 (1398,14,NULL,'no'),
1549 (1398,21,NULL,'no'),
1550 (1398,22,NULL,'no'),
1551 (1502,1,NULL,'no'),
1552 (1502,2,31,'no'),
1553 (1502,3,NULL,'no'),
1554 (1502,14,NULL,'no'),
1555 (1502,20,NULL,'no'),
1556 (1502,21,NULL,'no'),
1557 (1502,22,NULL,'no'),
1558 (1503,1,NULL,'no'),
1559 (1503,2,30,'no'),
1560 (1503,3,NULL,'no'),
1561 (1503,4,14,'no'),
1562 (1503,5,NULL,'no'),
1563 (1503,14,NULL,'no'),
1564 (1503,16,NULL,'no'),
1565 (1503,17,NULL,'no'),
1566 (1503,18,NULL,'no'),
1567 (1503,20,NULL,'no'),
1568 (1503,21,NULL,'no'),
1569 (1503,22,NULL,'no'),
1570 (1503,24,NULL,'no'),
1571 (1504,3,NULL,'no'),
1572 (1504,4,13,'no'),
1573 (1504,14,NULL,'no'),
1574 (1504,24,NULL,'no'),
1575 (1505,14,NULL,'no'),
1576 (1506,14,NULL,'no'),
1577 (1506,17,NULL,'no'),
1578 (1506,18,NULL,'no'),
1579 (1507,1,NULL,'no'),
1580 (1507,2,32,'no'),
1581 (1507,3,NULL,'no'),
1582 (1507,4,33,'no'),
1583 (1507,5,NULL,'no'),
1584 (1507,14,NULL,'no'),
1585 (1507,20,NULL,'no'),
1586 (1507,21,NULL,'no'),
1587 (1507,22,NULL,'no'),
1588 (1560,27,NULL,'yes'),
1589 (1560,29,NULL,'yes'),
1590 (1562,14,NULL,'no'),
1591 (1644,1,NULL,'no'),
1592 (1644,2,36,'no'),
1593 (1644,3,NULL,'no'),
1594 (1787,3,NULL,'no'),
1595 (1787,14,NULL,'no'),
1596 (1787,30,38,'yes'),
1597 (12,2,39,'no')";
1598
1599 $query[] = "INSERT INTO PatchCableConnector (id, origin, connector) VALUES
1600 (1,'default','FC/PC'),(2,'default','FC/APC'),
1601 (3,'default','LC/PC'),(4,'default','LC/APC'),
1602 (5,'default','MPO-12/PC'),(6,'default','MPO-12/APC'),
1603 (7,'default','MPO-24/PC'),(8,'default','MPO-24/APC'),
1604 (9,'default','SC/PC'),(10,'default','SC/APC'),
1605 (11,'default','ST/PC'),(12,'default','ST/APC'),
1606 (13,'default','T568/8P8C/RJ45'),
1607 (14,'default','SFP-1000'),
1608 (15,'default','SFP+'),
1609 (999,'default','CX4/SFF-8470')";
1610
1611 $query[] = "INSERT INTO PatchCableType (id, origin, pctype) VALUES
1612 (1,'default','duplex OM1'),
1613 (2,'default','duplex OM2'),
1614 (3,'default','duplex OM3'),
1615 (4,'default','duplex OM4'),
1616 (5,'default','duplex OS1'),
1617 (6,'default','duplex OS2'),
1618 (7,'default','simplex OM1'),
1619 (8,'default','simplex OM2'),
1620 (9,'default','simplex OM3'),
1621 (10,'default','simplex OM4'),
1622 (11,'default','simplex OS1'),
1623 (12,'default','simplex OS2'),
1624 (13,'default','Cat.5 TP'),
1625 (14,'default','Cat.6 TP'),
1626 (15,'default','Cat.6a TP'),
1627 (16,'default','Cat.7 TP'),
1628 (17,'default','Cat.7a TP'),
1629 (18,'default','12-fiber OM3'),
1630 (19,'default','12-fiber OM4'),
1631 (20,'default','10Gb/s CX4 coax'),
1632 (21,'default','24-fiber OM3'),
1633 (22,'default','24-fiber OM4'),
1634 (23,'default','1Gb/s 50cm shielded'),
1635 (24,'default','10Gb/s 24AWG twinax'),
1636 (25,'default','10Gb/s 26AWG twinax'),
1637 (26,'default','10Gb/s 28AWG twinax'),
1638 (27,'default','10Gb/s 30AWG twinax'),
1639 (999,'default','Cat.3 TP')";
1640
1641 $query[] = "INSERT INTO PatchCableConnectorCompat (pctype_id, connector_id) VALUES
1642 (1,1),(2,1),(3,1),(4,1),(5,1),(6,1),(7,1),(8,1),(9,1),(10,1),(11,1),(12,1), -- FC/PC
1643 (1,2),(2,2),(3,2),(4,2),(5,2),(6,2),(7,2),(8,2),(9,2),(10,2),(11,2),(12,2), -- FC/APC
1644 (1,3),(2,3),(3,3),(4,3),(5,3),(6,3),(7,3),(8,3),(9,3),(10,3),(11,3),(12,3), -- LC/PC
1645 (1,4),(2,4),(3,4),(4,4),(5,4),(6,4),(7,4),(8,4),(9,4),(10,4),(11,4),(12,4), -- LC/APC
1646 (1,9),(2,9),(3,9),(4,9),(5,9),(6,9),(7,9),(8,9),(9,9),(10,9),(11,9),(12,9), -- SC/PC
1647 (1,10),(2,10),(3,10),(4,10),(5,10),(6,10),(7,10),(8,10),(9,10),(10,10),(11,10),(12,10), -- SC/APC
1648 (1,11),(2,11),(3,11),(4,11),(5,11),(6,11),(7,11),(8,11),(9,11),(10,11),(11,11),(12,11), -- ST/PC
1649 (1,12),(2,12),(3,12),(4,12),(5,12),(6,12),(7,12),(8,12),(9,12),(10,12),(11,12),(12,12), -- ST/APC
1650 (13,13),(14,13),(15,13),(16,13),(17,13),(999,13), -- T568
1651 (18,5),(19,5), -- MPO-12/PC
1652 (18,6),(19,6), -- MPO-12/APC
1653 (20,999), -- CX4
1654 (21,7),(22,7), -- MPO-24/PC
1655 (21,8),(22,8), -- MPO-24/APC
1656 (23,14), -- SFP-1000
1657 (24,15),(25,15),(26,15),(27,15) -- SFP+";
1658
1659 $query[] = "INSERT INTO `PortInnerInterface` VALUES
1660 (1,'hardwired'),
1661 (2,'SFP-100'),
1662 (3,'GBIC'),
1663 (4,'SFP-1000'),
1664 (5,'XENPAK'),
1665 (6,'X2'),
1666 (7,'XPAK'),
1667 (8,'XFP'),
1668 (9,'SFP+'),
1669 (10,'QSFP+'),
1670 (11,'CFP'),
1671 (12,'CFP2'),
1672 (13,'CPAK'),
1673 (14,'CXP'),
1674 (15,'QSFP28'),
1675 (16,'SFP28')";
1676
1677 $query[] = "INSERT INTO `PortOuterInterface` VALUES
1678 (16,'AC-in'),
1679 (17,'10Base2'),
1680 (18,'10Base-T'),
1681 (19,'100Base-TX'),
1682 (24,'1000Base-T'),
1683 (29,'RS-232 (RJ-45)'),
1684 (30,'10GBase-SR'),
1685 (31,'virtual bridge'),
1686 (32,'sync serial'),
1687 (33,'KVM (host)'),
1688 (34,'1000Base-ZX'),
1689 (35,'10GBase-ER'),
1690 (36,'10GBase-LR'),
1691 (37,'10GBase-LRM'),
1692 (38,'10GBase-ZR'),
1693 (39,'10GBase-LX4'),
1694 (40,'10GBase-CX4'),
1695 (41,'10GBase-KX4'),
1696 (42, '1000Base-EX'),
1697 (439,'dry contact'),
1698 (440,'unknown'),
1699 (446,'KVM (console)'),
1700 (681,'RS-232 (DB-9)'),
1701 (682,'RS-232 (DB-25)'),
1702 (1077,'empty SFP-1000'),
1703 (1078,'empty GBIC'),
1704 (1079,'empty XENPAK'),
1705 (1080,'empty X2'),
1706 (1081,'empty XPAK'),
1707 (1082,'empty XFP'),
1708 (1084,'empty SFP+'),
1709 (1087,'1000Base-T (Dell 1855)'),
1710 (1088,'1000Base-BX40-D'),
1711 (1089,'1000Base-BX40-U'),
1712 (1090,'1000Base-BX80-D'),
1713 (1091,'1000Base-BX80-U'),
1714 (1195,'100Base-FX'),
1715 (1196,'100Base-SX'),
1716 (1197,'100Base-LX10'),
1717 (1198,'100Base-BX10-D'),
1718 (1199,'100Base-BX10-U'),
1719 (1200,'100Base-EX'),
1720 (1201,'100Base-ZX'),
1721 (1202,'1000Base-SX'),
1722 (1203,'1000Base-SX+'),
1723 (1204,'1000Base-LX'),
1724 (1205,'1000Base-LX10'),
1725 (1206,'1000Base-BX10-D'),
1726 (1207,'1000Base-BX10-U'),
1727 (1208,'empty SFP-100'),
1728 (1209,'1000Base-CWDM80-1470 (gray)'),
1729 (1210,'1000Base-CWDM80-1490 (violet)'),
1730 (1211,'1000Base-CWDM80-1510 (blue)'),
1731 (1212,'1000Base-CWDM80-1530 (green)'),
1732 (1213,'1000Base-CWDM80-1550 (yellow)'),
1733 (1214,'1000Base-CWDM80-1570 (orange)'),
1734 (1215,'1000Base-CWDM80-1590 (red)'),
1735 (1216,'1000Base-CWDM80-1610 (brown)'),
1736 (1217,'1000Base-DWDM80-61.42 (ITU 20)'),
1737 (1218,'1000Base-DWDM80-60.61 (ITU 21)'),
1738 (1219,'1000Base-DWDM80-59.79 (ITU 22)'),
1739 (1220,'1000Base-DWDM80-58.98 (ITU 23)'),
1740 (1221,'1000Base-DWDM80-58.17 (ITU 24)'),
1741 (1222,'1000Base-DWDM80-57.36 (ITU 25)'),
1742 (1223,'1000Base-DWDM80-56.55 (ITU 26)'),
1743 (1224,'1000Base-DWDM80-55.75 (ITU 27)'),
1744 (1225,'1000Base-DWDM80-54.94 (ITU 28)'),
1745 (1226,'1000Base-DWDM80-54.13 (ITU 29)'),
1746 (1227,'1000Base-DWDM80-53.33 (ITU 30)'),
1747 (1228,'1000Base-DWDM80-52.52 (ITU 31)'),
1748 (1229,'1000Base-DWDM80-51.72 (ITU 32)'),
1749 (1230,'1000Base-DWDM80-50.92 (ITU 33)'),
1750 (1231,'1000Base-DWDM80-50.12 (ITU 34)'),
1751 (1232,'1000Base-DWDM80-49.32 (ITU 35)'),
1752 (1233,'1000Base-DWDM80-48.51 (ITU 36)'),
1753 (1234,'1000Base-DWDM80-47.72 (ITU 37)'),
1754 (1235,'1000Base-DWDM80-46.92 (ITU 38)'),
1755 (1236,'1000Base-DWDM80-46.12 (ITU 39)'),
1756 (1237,'1000Base-DWDM80-45.32 (ITU 40)'),
1757 (1238,'1000Base-DWDM80-44.53 (ITU 41)'),
1758 (1239,'1000Base-DWDM80-43.73 (ITU 42)'),
1759 (1240,'1000Base-DWDM80-42.94 (ITU 43)'),
1760 (1241,'1000Base-DWDM80-42.14 (ITU 44)'),
1761 (1242,'1000Base-DWDM80-41.35 (ITU 45)'),
1762 (1243,'1000Base-DWDM80-40.56 (ITU 46)'),
1763 (1244,'1000Base-DWDM80-39.77 (ITU 47)'),
1764 (1245,'1000Base-DWDM80-38.98 (ITU 48)'),
1765 (1246,'1000Base-DWDM80-38.19 (ITU 49)'),
1766 (1247,'1000Base-DWDM80-37.40 (ITU 50)'),
1767 (1248,'1000Base-DWDM80-36.61 (ITU 51)'),
1768 (1249,'1000Base-DWDM80-35.82 (ITU 52)'),
1769 (1250,'1000Base-DWDM80-35.04 (ITU 53)'),
1770 (1251,'1000Base-DWDM80-34.25 (ITU 54)'),
1771 (1252,'1000Base-DWDM80-33.47 (ITU 55)'),
1772 (1253,'1000Base-DWDM80-32.68 (ITU 56)'),
1773 (1254,'1000Base-DWDM80-31.90 (ITU 57)'),
1774 (1255,'1000Base-DWDM80-31.12 (ITU 58)'),
1775 (1256,'1000Base-DWDM80-30.33 (ITU 59)'),
1776 (1257,'1000Base-DWDM80-29.55 (ITU 60)'),
1777 (1258,'1000Base-DWDM80-28.77 (ITU 61)'),
1778 (1259,'10GBase-ZR-DWDM80-61.42 (ITU 20)'),
1779 (1260,'10GBase-ZR-DWDM80-60.61 (ITU 21)'),
1780 (1261,'10GBase-ZR-DWDM80-59.79 (ITU 22)'),
1781 (1262,'10GBase-ZR-DWDM80-58.98 (ITU 23)'),
1782 (1263,'10GBase-ZR-DWDM80-58.17 (ITU 24)'),
1783 (1264,'10GBase-ZR-DWDM80-57.36 (ITU 25)'),
1784 (1265,'10GBase-ZR-DWDM80-56.55 (ITU 26)'),
1785 (1266,'10GBase-ZR-DWDM80-55.75 (ITU 27)'),
1786 (1267,'10GBase-ZR-DWDM80-54.94 (ITU 28)'),
1787 (1268,'10GBase-ZR-DWDM80-54.13 (ITU 29)'),
1788 (1269,'10GBase-ZR-DWDM80-53.33 (ITU 30)'),
1789 (1270,'10GBase-ZR-DWDM80-52.52 (ITU 31)'),
1790 (1271,'10GBase-ZR-DWDM80-51.72 (ITU 32)'),
1791 (1272,'10GBase-ZR-DWDM80-50.92 (ITU 33)'),
1792 (1273,'10GBase-ZR-DWDM80-50.12 (ITU 34)'),
1793 (1274,'10GBase-ZR-DWDM80-49.32 (ITU 35)'),
1794 (1275,'10GBase-ZR-DWDM80-48.51 (ITU 36)'),
1795 (1276,'10GBase-ZR-DWDM80-47.72 (ITU 37)'),
1796 (1277,'10GBase-ZR-DWDM80-46.92 (ITU 38)'),
1797 (1278,'10GBase-ZR-DWDM80-46.12 (ITU 39)'),
1798 (1279,'10GBase-ZR-DWDM80-45.32 (ITU 40)'),
1799 (1280,'10GBase-ZR-DWDM80-44.53 (ITU 41)'),
1800 (1281,'10GBase-ZR-DWDM80-43.73 (ITU 42)'),
1801 (1282,'10GBase-ZR-DWDM80-42.94 (ITU 43)'),
1802 (1283,'10GBase-ZR-DWDM80-42.14 (ITU 44)'),
1803 (1284,'10GBase-ZR-DWDM80-41.35 (ITU 45)'),
1804 (1285,'10GBase-ZR-DWDM80-40.56 (ITU 46)'),
1805 (1286,'10GBase-ZR-DWDM80-39.77 (ITU 47)'),
1806 (1287,'10GBase-ZR-DWDM80-38.98 (ITU 48)'),
1807 (1288,'10GBase-ZR-DWDM80-38.19 (ITU 49)'),
1808 (1289,'10GBase-ZR-DWDM80-37.40 (ITU 50)'),
1809 (1290,'10GBase-ZR-DWDM80-36.61 (ITU 51)'),
1810 (1291,'10GBase-ZR-DWDM80-35.82 (ITU 52)'),
1811 (1292,'10GBase-ZR-DWDM80-35.04 (ITU 53)'),
1812 (1293,'10GBase-ZR-DWDM80-34.25 (ITU 54)'),
1813 (1294,'10GBase-ZR-DWDM80-33.47 (ITU 55)'),
1814 (1295,'10GBase-ZR-DWDM80-32.68 (ITU 56)'),
1815 (1296,'10GBase-ZR-DWDM80-31.90 (ITU 57)'),
1816 (1297,'10GBase-ZR-DWDM80-31.12 (ITU 58)'),
1817 (1298,'10GBase-ZR-DWDM80-30.33 (ITU 59)'),
1818 (1299,'10GBase-ZR-DWDM80-29.55 (ITU 60)'),
1819 (1300,'10GBase-ZR-DWDM80-28.77 (ITU 61)'),
1820 (1316,'1000Base-T (Dell M1000e)'),
1821 (1322,'AC-out'),
1822 (1399,'DC'),
1823 (1424,'1000Base-CX'),
1824 (1425,'10GBase-ER-DWDM40-61.42 (ITU 20)'),
1825 (1426,'10GBase-ER-DWDM40-60.61 (ITU 21)'),
1826 (1427,'10GBase-ER-DWDM40-59.79 (ITU 22)'),
1827 (1428,'10GBase-ER-DWDM40-58.98 (ITU 23)'),
1828 (1429,'10GBase-ER-DWDM40-58.17 (ITU 24)'),
1829 (1430,'10GBase-ER-DWDM40-57.36 (ITU 25)'),
1830 (1431,'10GBase-ER-DWDM40-56.55 (ITU 26)'),
1831 (1432,'10GBase-ER-DWDM40-55.75 (ITU 27)'),
1832 (1433,'10GBase-ER-DWDM40-54.94 (ITU 28)'),
1833 (1434,'10GBase-ER-DWDM40-54.13 (ITU 29)'),
1834 (1435,'10GBase-ER-DWDM40-53.33 (ITU 30)'),
1835 (1436,'10GBase-ER-DWDM40-52.52 (ITU 31)'),
1836 (1437,'10GBase-ER-DWDM40-51.72 (ITU 32)'),
1837 (1438,'10GBase-ER-DWDM40-50.92 (ITU 33)'),
1838 (1439,'10GBase-ER-DWDM40-50.12 (ITU 34)'),
1839 (1440,'10GBase-ER-DWDM40-49.32 (ITU 35)'),
1840 (1441,'10GBase-ER-DWDM40-48.51 (ITU 36)'),
1841 (1442,'10GBase-ER-DWDM40-47.72 (ITU 37)'),
1842 (1443,'10GBase-ER-DWDM40-46.92 (ITU 38)'),
1843 (1444,'10GBase-ER-DWDM40-46.12 (ITU 39)'),
1844 (1445,'10GBase-ER-DWDM40-45.32 (ITU 40)'),
1845 (1446,'10GBase-ER-DWDM40-44.53 (ITU 41)'),
1846 (1447,'10GBase-ER-DWDM40-43.73 (ITU 42)'),
1847 (1448,'10GBase-ER-DWDM40-42.94 (ITU 43)'),
1848 (1449,'10GBase-ER-DWDM40-42.14 (ITU 44)'),
1849 (1450,'10GBase-ER-DWDM40-41.35 (ITU 45)'),
1850 (1451,'10GBase-ER-DWDM40-40.56 (ITU 46)'),
1851 (1452,'10GBase-ER-DWDM40-39.77 (ITU 47)'),
1852 (1453,'10GBase-ER-DWDM40-38.98 (ITU 48)'),
1853 (1454,'10GBase-ER-DWDM40-38.19 (ITU 49)'),
1854 (1455,'10GBase-ER-DWDM40-37.40 (ITU 50)'),
1855 (1456,'10GBase-ER-DWDM40-36.61 (ITU 51)'),
1856 (1457,'10GBase-ER-DWDM40-35.82 (ITU 52)'),
1857 (1458,'10GBase-ER-DWDM40-35.04 (ITU 53)'),
1858 (1459,'10GBase-ER-DWDM40-34.25 (ITU 54)'),
1859 (1460,'10GBase-ER-DWDM40-33.47 (ITU 55)'),
1860 (1461,'10GBase-ER-DWDM40-32.68 (ITU 56)'),
1861 (1462,'10GBase-ER-DWDM40-31.90 (ITU 57)'),
1862 (1463,'10GBase-ER-DWDM40-31.12 (ITU 58)'),
1863 (1464,'10GBase-ER-DWDM40-30.33 (ITU 59)'),
1864 (1465,'10GBase-ER-DWDM40-29.55 (ITU 60)'),
1865 (1466,'10GBase-ER-DWDM40-28.77 (ITU 61)'),
1866 (1469,'virtual port'),
1867 (1588,'empty QSFP'),
1868 (1589,'empty CFP2'),
1869 (1590,'empty CPAK'),
1870 (1591,'empty CXP'),
1871 (1592,'empty SFP28'),
1872 (1603,'1000Base-T (HP c-Class)'),
1873 (1604,'100Base-TX (HP c-Class)'),
1874 (1642,'10GBase-T'),
1875 (1651,'25GBase-KR'),
1876 (1652,'25GBase-T'),
1877 (1653,'25GBase-CR'),
1878 (1654,'25GBase-SR'),
1879 (1655,'25GBase-LR'),
1880 (1656,'25Gbase-ER'),
1881 (1660,'40GBase-FR'),
1882 (1661,'40GBase-KR4'),
1883 (1662,'40GBase-ER4'),
1884 (1663,'40GBase-SR4'),
1885 (1664,'40GBase-LR4'),
1886 (1668,'empty CFP'),
1887 (1669,'100GBase-SR10'),
1888 (1670,'100GBase-LR4'),
1889 (1671,'100GBase-ER4'),
1890 (1672,'100GBase-SR4'),
1891 (1673,'100GBase-KR4'),
1892 (1674,'100GBase-KP4'),
1893
1894 (1675,'100GBase-LR10'),
1895 (1676,'100GBase-ER10'),
1896 (1677,'100GBase-CR4'),
1897 (1678,'100GBase-CR10'),
1898
1899 (1999,'10GBase-KR')
1900 ";
1901 // Add new outer interface types with id < 2000. Values 2000 and up are for
1902 // users' local types.
1903
1904 $query[] = "INSERT INTO PatchCableOIFCompat (pctype_id, oif_id) VALUES
1905 (13,18),(14,18),(15,18),(16,18),(17,18),(999,18), -- 10Base-T: Cat.3+ TP
1906 (11,1198),(12,1198),(11,1199),(12,1199), -- 100Base-BX10: 1xSMF
1907 (5,1197),(6,1197), -- 100Base-LX10: 2xSMF
1908 (5,1200),(6,1200), -- 100Base-EX: 2xSMF
1909 (5,1201),(6,1201), -- 100Base-ZX: 2xSMF
1910 (1,1195),(2,1195),(3,1195),(4,1195), -- 100Base-FX: 2xMMF
1911 (1,1196),(2,1196),(3,1196),(4,1196), -- 100Base-SX: 2xMMF
1912 (13,19),(14,19),(15,19),(16,19),(17,19), -- 100Base-TX: Cat.5+ TP
1913 (11,1206),(12,1206),(11,1207),(12,1207), -- 1000Base-BX10: 1xSMF
1914 (11,1088),(12,1088),(11,1089),(12,1089), -- 1000Base-BX40: 1xSMF
1915 (11,1090),(12,1090),(11,1091),(12,1091), -- 1000Base-BX80: 1xSMF
1916 (5,1204),(6,1204), -- 1000Base-LX: 2xSMF
1917 (5,1205),(6,1205), -- 1000Base-LX10: 2xSMF
1918 (1,1202),(2,1202),(3,1202),(4,1202), -- 1000Base-SX: 2xMMF
1919 (1,1203),(2,1203),(3,1203),(4,1203), -- 1000Base-SX+: 2xMMF
1920 (13,24),(14,24),(15,24),(16,24),(17,24), -- 1000Base-T: Cat.5+ TP
1921 (5,34),(6,34), -- 1000Base-ZX: 2xSMF
1922 (23,1077), -- 1000Base direct attach: shielded
1923 (1,30),(2,30),(3,30),(4,30), -- 10GBase-SR: 2xMMF
1924 (5,36),(6,36), -- 10GBase-LR: 2xSMF
1925 (5,35),(6,35), -- 10GBase-ER: 2xSMF
1926 (5,38),(6,38), -- 10GBase-ZR: 2xSMF
1927 (1,39),(2,39),(3,39),(4,39),(5,39),(6,39), -- 10GBase-LX4: 2xMMF/2xSMF
1928 (1,37),(2,37),(3,37),(4,37), -- 10GBase-LRM: 2xMMF
1929 (14,1642),(15,1642),(16,1642),(17,1642), -- 10GBase-T: Cat.6+ TP
1930 (20,40), -- 10GBase-CX4: coax
1931 (24,1084),(25,1084),(26,1084),(27,1084), -- 10GBase direct attach: twinax
1932 (18,1663),(19,1663), -- 40GBase-SR4: 8xMMF
1933 (5,1664),(6,1664), -- 40GBase-LR4: 2xSMF
1934 (5,1662),(6,1662), -- 40GBase-ER4: 2xSMF
1935 (5,1660),(6,1660), -- 40GBase-FR: 2xSMF
1936 (21,1669),(22,1669), -- 100GBase-SR10: 20xMMF
1937 (18,1672),(19,1672), -- 100GBase-SR4: 8xMMF
1938 (5,1670),(6,1670), -- 100GBase-LR4: 2xSMF
1939 (5,1671),(6,1671), -- 100GBase-ER4: 2xSMF
1940 (5,1675),(6,1675), -- 100GBase-LR10: 2xSMF
1941 (5,1676),(6,1676) -- 100GBase-ER10: 2xSMF";
1942
1943 $query[] = "INSERT INTO `ObjectParentCompat` VALUES
1944 (3,13),
1945 (4,1504),
1946 (4,1507),
1947 (1397,1398),
1948 (1502,4),
1949 (1503,8),
1950 (1505,4),
1951 (1505,1504),
1952 (1505,1506),
1953 (1505,1507),
1954 (1506,4),
1955 (1506,1504),
1956 (1787,4),
1957 (1787,8),
1958 (1787,1502)";
1959
1960 $query[] = "INSERT INTO `PortInterfaceCompat` VALUES
1961 -- SFP-100: empty SFP-100, 100Base-FX, 100Base-SX, 100Base-LX10, 100Base-BX10-D, 100Base-BX10-U, 100Base-EX, 100Base-ZX
1962 (2,1208),(2,1195),(2,1196),(2,1197),(2,1198),(2,1199),(2,1200),(2,1201),
1963 -- GBIC: empty GBIC, 1000Base-T, 1000Base-ZX, 1000Base-EX, 1000Base-SX, 1000Base-SX+, 1000Base-LX, 1000Base-LX10, 1000Base-BX10-D, 1000Base-BX10-U
1964 (3,1078),(3,24),(3,34),(3,42),(3,1202),(3,1203),(3,1204),(3,1205),(3,1206),(3,1207),
1965 -- SFP-1000: empty SFP-1000, 1000Base-T, 1000Base-ZX, 1000Base-EX, 1000Base-SX, 1000Base-SX+, 1000Base-LX, 1000Base-LX10, 1000Base-BX10-D, 1000Base-BX10-U
1966 (4,1077),(4,24),(4,34),(4,42),(4,1202),(4,1203),(4,1204),(4,1205),(4,1206),(4,1207),
1967 -- SFP-1000: 1000Base-BX40-D, 1000Base-BX40-U, 1000Base-BX80-D, 1000Base-BX80-U
1968 (4,1088),(4,1089),(4,1090),(4,1091),
1969 -- XENPAK: empty XENPAK, 10GBase-SR, 10GBase-ER, 10GBase-LR, 10GBase-LRM, 10GBase-ZR, 10GBase-LX4, 10GBase-CX4
1970 (5,1079),(5,30),(5,35),(5,36),(5,37),(5,38),(5,39),(5,40),
1971 -- X2: empty X2, 10GBase-SR, 10GBase-ER, 10GBase-LR, 10GBase-LRM, 10GBase-ZR, 10GBase-LX4, 10GBase-CX4
1972 (6,1080),(6,30),(6,35),(6,36),(6,37),(6,38),(6,39),(6,40),
1973 -- XPAK: empty XPAK, 10GBase-SR, 10GBase-ER, 10GBase-LR, 10GBase-LRM, 10GBase-ZR, 10GBase-LX4, 10GBase-CX4
1974 (7,1081),(7,30),(7,35),(7,36),(7,37),(7,38),(7,39),(7,40),
1975 -- XFP: empty XFP, 10GBase-SR, 10GBase-ER, 10GBase-LR, 10GBase-LRM, 10GBase-ZR, 10GBase-LX4, 10GBase-CX4
1976 (8,1082),(8,30),(8,35),(8,36),(8,37),(8,38),(8,39),(8,40),
1977 -- SFP+: empty SFP+, 10GBase-SR, 10GBase-ER, 10GBase-LR, 10GBase-LRM, 10GBase-ZR, 10GBase-LX4, 10GBase-CX4
1978 (9,1084),(9,30),(9,35),(9,36),(9,37),(9,38),(9,39),(9,40),
1979 -- QSFP+: empty QSFP, 40GBase-FR, 40GBase-ER4, 40GBase-SR4, 40GBase-LR4
1980 (10,1588),(10,1660),(10,1662),(10,1663),(10,1664),
1981 -- CFP: empty CFP, 100GBase-SR10, 100GBase-LR4, 100GBase-ER4, 100GBase-SR4, 100GBase-KR4, 100GBase-KP4, 100GBase-LR10, 100GBase-ER10
1982 (11,1668),(11,1669),(11,1670),(11,1671),(11,1672),(11,1673),(11,1674),(11,1675),(11,1676),
1983 -- CFP2: empty CFP2, 100GBase-SR10, 100GBase-LR4, 100GBase-ER4, 100GBase-SR4, 100GBase-KR4, 100GBase-KP4, 100GBase-LR10, 100GBase-ER10
1984 (12,1589),(12,1669),(12,1670),(12,1671),(12,1672),(12,1673),(12,1674),(12,1675),(12,1676),
1985 -- CPAK: empty CPAK, 100GBase-SR10, 100GBase-LR4, 100GBase-ER4, 100GBase-SR4, 100GBase-KR4, 100GBase-KP4, 100GBase-LR10, 100GBase-ER10
1986 (13,1590),(13,1669),(13,1670),(13,1671),(13,1672),(13,1673),(13,1674),(13,1675),(13,1676),
1987 -- CXP: empty CXP, 100GBase-CR4, 100GBase-CR10
1988 (14,1591),(14,1677),(14,1678),
1989 -- QSFP28: empty QSFP, 40GBase-FR, 40GBase-ER4, 40GBase-SR4, 40GBase-LR4, 100GBase-LR4, 100GBase-ER4, 100GBase-SR4, 100GBase-KR4, 100GBase-KP4
1990 (15,1588),(15,1660),(15,1662),(15,1663),(15,1664),(15,1670),(15,1671),(15,1672),(15,1673),(15,1674),
1991 -- SFP28: empty SFP28, 25Gbase-KR, 25GBase-CR, 25Gbase-SR, 25GBase-LR, 25GBase-ER
1992 (16,1592),(16,1651),(16,1653),(16,1654),(16,1655),(16,1656),
1993 -- SFP28: 10GBase-SR, 10GBase-ER, 10GBase-LR, 10GBase-LRM, 10GBase-ZR, 10GBase-LX4, 10GBase-CX4
1994 (16,30),(16,35),(16,36),(16,37),(16,38),(16,39),(16,40),
1995 -- hardwired: AC-in, 100Base-TX, 1000Base-T, RS-232 (RJ-45), virtual bridge, KVM (host), KVM (console), RS-232 (DB-9), RS-232 (DB-25), AC-out, DC, virtual port
1996 (1,16),(1,19),(1,24),(1,29),(1,31),(1,33),(1,446),(1,681),(1,682),(1,1322),(1,1399),(1,1469)";
1997
1998 $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES
1999 (17,17),
2000 (18,18),
2001 (19,19),
2002 (24,24),
2003 (18,19),
2004 (18,24),
2005 (19,24),
2006 (29,29),
2007 (30,30),
2008 (16,1322),
2009 (29,681),
2010 (29,682),
2011 (32,32),
2012 (33,446),
2013 (34,34),
2014 (35,35),
2015 (36,36),
2016 (37,37),
2017 (38,38),
2018 (39,39),
2019 (40,40),
2020 (41,41),
2021 (42,42),
2022 (439,439),
2023 (681,681),
2024 (681,682),
2025 (682,682),
2026 (1077,1077),
2027 (1084,1084),
2028 (1087,1087),
2029 (1088,1089),
2030 (1090,1091),
2031 (1195,1195),
2032 (1196,1196),
2033 (1197,1197),
2034 (1198,1199),
2035 (1200,1200),
2036 (1201,1201),
2037 (1202,1202),
2038 (1203,1203),
2039 (1204,1204),
2040 (1205,1205),
2041 (1206,1207),
2042 (1209,1209),
2043 (1210,1210),
2044 (1211,1211),
2045 (1212,1212),
2046 (1213,1213),
2047 (1214,1214),
2048 (1215,1215),
2049 (1216,1216),
2050 (1217,1217),
2051 (1218,1218),
2052 (1219,1219),
2053 (1220,1220),
2054 (1221,1221),
2055 (1222,1222),
2056 (1223,1223),
2057 (1224,1224),
2058 (1225,1225),
2059 (1226,1226),
2060 (1227,1227),
2061 (1228,1228),
2062 (1229,1229),
2063 (1230,1230),
2064 (1231,1231),
2065 (1232,1232),
2066 (1233,1233),
2067 (1234,1234),
2068 (1235,1235),
2069 (1236,1236),
2070 (1237,1237),
2071 (1238,1238),
2072 (1239,1239),
2073 (1240,1240),
2074 (1241,1241),
2075 (1242,1242),
2076 (1243,1243),
2077 (1244,1244),
2078 (1245,1245),
2079 (1246,1246),
2080 (1247,1247),
2081 (1248,1248),
2082 (1249,1249),
2083 (1250,1250),
2084 (1251,1251),
2085 (1252,1252),
2086 (1253,1253),
2087 (1254,1254),
2088 (1255,1255),
2089 (1256,1256),
2090 (1257,1257),
2091 (1258,1258),
2092 (1259,1259),
2093 (1260,1260),
2094 (1261,1261),
2095 (1262,1262),
2096 (1263,1263),
2097 (1264,1264),
2098 (1265,1265),
2099 (1266,1266),
2100 (1267,1267),
2101 (1268,1268),
2102 (1269,1269),
2103 (1270,1270),
2104 (1271,1271),
2105 (1272,1272),
2106 (1273,1273),
2107 (1274,1274),
2108 (1275,1275),
2109 (1276,1276),
2110 (1277,1277),
2111 (1278,1278),
2112 (1279,1279),
2113 (1280,1280),
2114 (1281,1281),
2115 (1282,1282),
2116 (1283,1283),
2117 (1284,1284),
2118 (1285,1285),
2119 (1286,1286),
2120 (1287,1287),
2121 (1288,1288),
2122 (1289,1289),
2123 (1290,1290),
2124 (1291,1291),
2125 (1292,1292),
2126 (1293,1293),
2127 (1294,1294),
2128 (1295,1295),
2129 (1296,1296),
2130 (1297,1297),
2131 (1298,1298),
2132 (1299,1299),
2133 (1300,1300),
2134 (1316,1316),
2135 (1424,1424),
2136 (1425,1425),
2137 (1426,1426),
2138 (1427,1427),
2139 (1428,1428),
2140 (1429,1429),
2141 (1430,1430),
2142 (1431,1431),
2143 (1432,1432),
2144 (1433,1433),
2145 (1434,1434),
2146 (1435,1435),
2147 (1436,1436),
2148 (1437,1437),
2149 (1438,1438),
2150 (1439,1439),
2151 (1440,1440),
2152 (1441,1441),
2153 (1442,1442),
2154 (1443,1443),
2155 (1444,1444),
2156 (1445,1445),
2157 (1446,1446),
2158 (1447,1447),
2159 (1448,1448),
2160 (1449,1449),
2161 (1450,1450),
2162 (1451,1451),
2163 (1452,1452),
2164 (1453,1453),
2165 (1454,1454),
2166 (1455,1455),
2167 (1456,1456),
2168 (1457,1457),
2169 (1458,1458),
2170 (1459,1459),
2171 (1460,1460),
2172 (1461,1461),
2173 (1462,1462),
2174 (1463,1463),
2175 (1464,1464),
2176 (1465,1465),
2177 (1466,1466),
2178 (1469,1469),
2179 (1399,1399),
2180 (1588,1588),
2181 (1588,1589),
2182 (1588,1590),
2183 (1589,1589),
2184 (1589,1590),
2185 (1590,1590),
2186 (1591,1591),
2187 (1592,1592),
2188 (1592,1084),
2189 (1603,1603),
2190 (1651,1651),
2191 (1652,1652),
2192 (1653,1653),
2193 (1654,1654),
2194 (1655,1655),
2195 (1656,1656),
2196 (1660,1660),
2197 (1661,1661),
2198 (1662,1662),
2199 (1663,1663),
2200 (1664,1664),
2201 (1668,1668),
2202 (1669,1669),
2203 (1670,1670),
2204 (1671,1671),
2205 (1672,1672),
2206 (1673,1673),
2207 (1674,1674),
2208 (1675,1675),
2209 (1676,1676),
2210 (1677,1677),
2211 (1678,1678),
2212 (1642,1642),
2213 (1999,1999)";
2214
2215 // make PortCompat symmetric (insert missing reversed-order pairs)
2216 $query[] = "INSERT INTO PortCompat SELECT pc1.type2, pc1.type1 FROM PortCompat pc1 LEFT JOIN PortCompat pc2 ON pc1.type1 = pc2.type2 AND pc1.type2 = pc2.type1 WHERE pc2.type1 IS NULL";
2217
2218 $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES
2219 ('IPV4_TREE_SHOW_UNALLOCATED', 'yes', 'string', 'no', 'no', 'yes', 'Show unallocated networks in IPv4 tree'),
2220 ('MASSCOUNT','8','uint','no','no','yes','&quot;Fast&quot; form is this many records tall'),
2221 ('MAXSELSIZE','30','uint','no','no','yes','&lt;SELECT&gt; lists height'),
2222 ('enterprise','MyCompanyName','string','no','no','no','Organization name'),
2223 ('ROW_SCALE','2','uint','no','no','yes','Picture scale for rack row display'),
2224 ('IPV4_ADDRS_PER_PAGE','256','uint','no','no','yes','IPv4 addresses per page'),
2225 ('DEFAULT_RACK_HEIGHT','42','uint','yes','no','yes','Default rack height'),
2226 ('DEFAULT_SLB_VS_PORT','','uint','yes','no','yes','Default port of SLB virtual service'),
2227 ('DEFAULT_SLB_RS_PORT','','uint','yes','no','yes','Default port of SLB real server'),
2228 ('DETECT_URLS','no','string','yes','no','yes','Detect URLs in text fields'),
2229 ('RACK_PRESELECT_THRESHOLD','1','uint','no','no','yes','Rack pre-selection threshold'),
2230 ('DEFAULT_IPV4_RS_INSERVICE','no','string','no','no','yes','Inservice status for new SLB real servers'),
2231 ('AUTOPORTS_CONFIG','4 = 1*33*kvm + 2*24*eth%u;15 = 1*446*kvm','string','yes','no','no','AutoPorts configuration'),
2232 ('DEFAULT_OBJECT_TYPE','4','uint','yes','no','yes','Default object type for new objects'),
2233 ('SHOW_EXPLICIT_TAGS','yes','string','no','no','yes','Show explicit tags'),
2234 ('SHOW_IMPLICIT_TAGS','yes','string','no','no','yes','Show implicit tags'),
2235 ('SHOW_AUTOMATIC_TAGS','no','string','no','no','yes','Show automatic tags'),
2236 ('IPV4_AUTO_RELEASE','1','uint','no','no','yes','Auto-release IPv4 addresses on allocation'),
2237 ('SHOW_LAST_TAB','yes','string','yes','no','yes','Remember last tab shown for each page'),
2238 ('EXT_IPV4_VIEW','yes','string','no','no','yes','Extended IPv4 view'),
2239 ('TREE_THRESHOLD','25','uint','yes','no','yes','Tree view auto-collapse threshold'),
2240 ('IPV4_JAYWALK','no','string','no','no','no','Enable IPv4 address allocations w/o covering network'),
2241 ('ADDNEW_AT_TOP','yes','string','no','no','yes','Render \"add new\" line at top of the list'),
2242 ('IPV4_TREE_SHOW_USAGE','no','string','no','no','yes','Show address usage in IPv4 tree'),
2243 ('PREVIEW_TEXT_MAXCHARS','10240','uint','yes','no','yes','Max chars for text file preview'),
2244 ('PREVIEW_TEXT_ROWS','25','uint','yes','no','yes','Rows for text file preview'),
2245 ('PREVIEW_TEXT_COLS','80','uint','yes','no','yes','Columns for text file preview'),
2246 ('PREVIEW_IMAGE_MAXPXS','320','uint','yes','no','yes','Max pixels per axis for image file preview'),
2247 ('VENDOR_SIEVE','','string','yes','no','yes','Vendor sieve configuration'),
2248 ('IPV4LB_LISTSRC','false','string','yes','no','no','List source: IPv4 load balancers'),
2249 ('IPV4OBJ_LISTSRC','not ({\$typeid_3} or {\$typeid_9} or {\$typeid_10} or {\$typeid_11})','string','yes','no','no','List source: IPv4-enabled objects'),
2250 ('IPV4NAT_LISTSRC','{\$typeid_4} or {\$typeid_7} or {\$typeid_8} or {\$typeid_798}','string','yes','no','no','List source: IPv4 NAT performers'),
2251 ('ASSETWARN_LISTSRC','{\$typeid_4} or {\$typeid_7} or {\$typeid_8}','string','yes','no','no','List source: objects for that asset tag should be set'),
2252 ('NAMEWARN_LISTSRC','{\$typeid_4} or {\$typeid_7} or {\$typeid_8}','string','yes','no','no','List source: objects for that common name should be set'),
2253 ('RACKS_PER_ROW','12','uint','yes','no','yes','Racks per row'),
2254 ('FILTER_PREDICATE_SIEVE','','string','yes','no','yes','Predicate sieve regex(7)'),
2255 ('FILTER_DEFAULT_ANDOR','and','string','no','no','yes','Default list filter boolean operation (or/and)'),
2256 ('FILTER_SUGGEST_ANDOR','yes','string','no','no','yes','Suggest and/or selector in list filter'),
2257 ('FILTER_SUGGEST_TAGS','yes','string','no','no','yes','Suggest tags in list filter'),
2258 ('FILTER_SUGGEST_PREDICATES','yes','string','no','no','yes','Suggest predicates in list filter'),
2259 ('FILTER_SUGGEST_EXTRA','yes','string','no','no','yes','Suggest extra expression in list filter'),
2260 ('DEFAULT_SNMP_COMMUNITY','public','string','no','no','no','Default SNMP Community string'),
2261 ('IPV4_ENABLE_KNIGHT','yes','string','no','no','yes','Enable IPv4 knight feature'),
2262 ('TAGS_TOPLIST_SIZE','50','uint','yes','no','yes','Tags top list size'),
2263 ('TAGS_QUICKLIST_SIZE','20','uint','no','no','yes','Tags quick list size'),
2264 ('TAGS_QUICKLIST_THRESHOLD','50','uint','yes','no','yes','Tags quick list threshold'),
2265 ('ENABLE_MULTIPORT_FORM','no','string','no','no','yes','Enable \"Add/update multiple ports\" form'),
2266 ('DEFAULT_PORT_IIF_ID','1','uint','no','no','no','Default port inner interface ID'),
2267 ('DEFAULT_PORT_OIF_IDS','1=24; 3=1078; 4=1077; 5=1079; 6=1080; 8=1082; 9=1084; 10=1588; 11=1668; 12=1589; 13=1590; 14=1591; 15=1588; 16=1592','string','no','no','no','Default port outer interface IDs'),
2268 ('IPV4_TREE_RTR_AS_CELL','no','string','no','no','yes','Show full router info for each network in IPv4 tree view'),
2269 ('PROXIMITY_RANGE','0','uint','yes','no','yes','Proximity range (0 is current rack only)'),
2270 ('VLANSWITCH_LISTSRC', '', 'string', 'yes', 'no', 'yes', 'List of VLAN running switches'),
2271 ('VLANNET_LISTSRC', '', 'string', 'yes', 'no', 'yes', 'List of VLAN-related IPv4/IPv6 networks'),
2272 ('IPV4_TREE_SHOW_VLAN','yes','string','no','no','yes','Show VLAN for each network in IPv4 tree'),
2273 ('DEFAULT_VDOM_ID','','uint','yes','no','yes','Default VLAN domain ID'),
2274 ('DEFAULT_VST_ID','','uint','yes','no','yes','Default VLAN switch template ID'),
2275 ('8021Q_DEPLOY_MINAGE','300','uint','no','no','no','802.1Q deploy minimum age'),
2276 ('8021Q_DEPLOY_MAXAGE','3600','uint','no','no','no','802.1Q deploy maximum age'),
2277 ('8021Q_DEPLOY_RETRY','10800','uint','no','no','no','802.1Q deploy retry timer'),
2278 ('8021Q_WRI_AFTER_CONFT_LISTSRC','false','string','no','no','no','802.1Q: save device configuration after deploy (RackCode)'),
2279 ('8021Q_INSTANT_DEPLOY','no','string','no','no','yes','802.1Q: instant deploy'),
2280 ('STATIC_FILTER','yes','string','no','no','yes','Enable Filter Caching'),
2281 ('ENABLE_BULKPORT_FORM','yes','string','no','no','yes','Enable \"Bulk Port\" form'),
2282 ('CDP_RUNNERS_LISTSRC', '', 'string', 'yes', 'no', 'no', 'List of devices running CDP'),
2283 ('LLDP_RUNNERS_LISTSRC', '', 'string', 'yes', 'no', 'no', 'List of devices running LLDP'),
2284 ('SHRINK_TAG_TREE_ON_CLICK','yes','string','no','no','yes','Dynamically hide useless tags in tagtree'),
2285 ('MAX_UNFILTERED_ENTITIES','0','uint','no','no','yes','Max item count to display on unfiltered result page'),
2286 ('SYNCDOMAIN_MAX_PROCESSES','0','uint','yes','no', 'no', 'How many worker proceses syncdomain cron script should create'),
2287 ('PORT_EXCLUSION_LISTSRC','{\$typeid_3} or {\$typeid_10} or {\$typeid_11} or {\$typeid_1505} or {\$typeid_1506}','string','yes','no','no','List source: objects without ports'),
2288 ('FILTER_RACKLIST_BY_TAGS','yes','string','yes','no','yes','Rackspace: show only racks matching the current object\'s tags'),
2289 ('MGMT_PROTOS','ssh: {\$typeid_4}; telnet: {\$typeid_8}','string','yes','no','yes','Mapping of management protocol to devices'),
2290 ('SYNC_8021Q_LISTSRC','','string','yes','no','no','List of VLAN switches sync is enabled on'),
2291 ('QUICK_LINK_PAGES','depot,ipv4space,rackspace','string','yes','no','yes','List of pages to display in quick links'),
2292 ('VIRTUAL_OBJ_CSV','1504,1505,1506,1507','string','no','no','no','List source: virtual objects'),
2293 ('DATETIME_ZONE','UTC','string','yes','no','yes','Timezone to use for displaying/calculating dates'),
2294 ('DATETIME_FORMAT','%Y-%m-%d','string','no','no','yes','PHP strftime() format for date+time'),
2295 ('DATEONLY_FORMAT','%Y-%m-%d','string','no','no','yes','PHP strftime() format for dates'),
2296 ('SEARCH_DOMAINS','','string','yes','no','yes','DNS domain list (comma-separated) to search in FQDN attributes'),
2297 ('8021Q_EXTSYNC_LISTSRC','false','string','yes','no','no','List source: objects with extended 802.1Q sync'),
2298 ('8021Q_MULTILINK_LISTSRC','false','string','yes','no','no','List source: IPv4/IPv6 networks allowing multiple VLANs from same domain'),
2299 ('REVERSED_RACKS_LISTSRC', 'false', 'string', 'yes', 'no', 'no', 'List of racks with reversed (top to bottom) units order'),
2300 ('NEAREST_RACKS_CHECKBOX', 'yes', 'string', 'yes', 'no', 'yes', 'Enable nearest racks in port list filter by default'),
2301 ('SHOW_OBJECTTYPE', 'yes', 'string', 'no', 'no', 'yes', 'Show object type column on depot page'),
2302 ('OBJECTLOG_PREVIEW_ENTRIES','5','uint','no','no','yes','Object log preview maximum entries (0 disables the preview)'),
2303 ('DB_VERSION','${db_version}','string','no','yes','no','Database version.')";
2304
2305 $query[] = "INSERT INTO `Script` VALUES ('RackCode','allow {\$userid_1}')";
2306
2307 $tmpstr = 'INSERT INTO VLANValidID (vlan_id) VALUES ';
2308 $sep = '';
2309 for ($i = 1; $i <= 4094; $i++)
2310 {
2311 $tmpstr .= "${sep}(${i})";
2312 $sep = ', ';
2313 }
2314 $query[] = $tmpstr;
2315 unset ($i);
2316 unset ($sep);
2317 unset ($tmpstr);
2318
2319 return $query;
2320 }
2321 }