r2288 add network security chapter and dictionary entries. closes ticket 148
[racktables] / upgrade.php
CommitLineData
6dc745d2 1<?php
fbbb74fb
DO
2
3// At the moment we assume, that for any two releases we can
4// sequentally execute all batches, that separate them, and
5// nothing will break. If this changes one day, the function
6// below will have to generate smarter upgrade paths, while
7// the upper layer will remain the same.
8// Returning an empty array means that no upgrade is necessary.
9function getDBUpgradePath ($v1, $v2)
10{
a6f83a72
DO
11 $versionhistory = array
12 (
b3f866fc 13 '0.16.4',
30d0a2a3 14 '0.17.0',
a6f83a72 15 );
fbbb74fb
DO
16 if (!in_array ($v1, $versionhistory) || !in_array ($v2, $versionhistory))
17 {
18 showError ("An upgrade path has been requested for versions '${v1}' and '${v2}', " .
b0348307 19 "and at least one of those isn't known to me.", __FILE__);
fbbb74fb
DO
20 die;
21 }
22 $skip = TRUE;
23 $path = array();
24 // Now collect all versions > $v1 and <= $v2
25 foreach ($versionhistory as $v)
26 {
27 if ($v == $v1)
28 {
29 $skip = FALSE;
30 continue;
31 }
32 if ($skip)
33 continue;
34 $path[] = $v;
35 if ($v == $v2)
36 break;
37 }
38 return $path;
39}
40
5f4027b8
DO
41function printReleaseNotes ($batchid)
42{
43 switch ($batchid)
44 {
5f4027b8
DO
45 default:
46 break;
47 }
48}
49
fbbb74fb
DO
50// Upgrade batches are name exactly as the release where they first appear.
51// That simple, but seems sufficient for beginning.
52function executeUpgradeBatch ($batchid)
53{
54 $query = array();
ce109ff2 55 global $dbxlink;
fbbb74fb
DO
56 switch ($batchid)
57 {
30d0a2a3 58 case '0.17.0':
e1ae3fb4
AD
59 // create tables for storing files (requires InnoDB support)
60 if (!isInnoDBSupported ())
61 {
62 die ('<b>Cannot upgrade because InnoDB tables are not supported by your MySQL server. See the README for details.</b>');
63 }
64 $query[] = "
65CREATE TABLE `File` (
66 `id` int(10) unsigned NOT NULL auto_increment,
67 `name` char(255) NOT NULL,
68 `type` char(255) NOT NULL,
69 `size` int(10) unsigned NOT NULL,
70 `ctime` datetime NOT NULL,
71 `mtime` datetime NOT NULL,
72 `atime` datetime NOT NULL,
73 `contents` longblob NOT NULL,
74 `comment` text,
75 PRIMARY KEY (`id`)
76) ENGINE=InnoDB";
77 $query[] = "
78CREATE TABLE `FileLink` (
79 `id` int(10) unsigned NOT NULL auto_increment,
80 `file_id` int(10) unsigned NOT NULL,
81 `entity_type` enum('ipv4net','ipv4rspool','ipv4vs','object','rack','user') NOT NULL default 'object',
82 `entity_id` int(10) NOT NULL,
83 PRIMARY KEY (`id`),
84 KEY `FileLink-file_id` (`file_id`),
85 CONSTRAINT `FileLink-File_fkey` FOREIGN KEY (`file_id`) REFERENCES `File` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
86) ENGINE=InnoDB";
87 $query[] = "ALTER TABLE TagStorage MODIFY COLUMN target_realm enum('file','ipv4net','ipv4rspool','ipv4vs','object','rack','user') NOT NULL default 'object'";
d4739002
AD
88 $query[] = "INSERT INTO `Chapter` (`chapter_no`, `sticky`, `chapter_name`) VALUES (24,'no','network security models')";
89 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_no`) VALUES (798,1,0)";
90 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_no`) VALUES (798,2,24)";
91 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_no`) VALUES (798,3,0)";
92 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_no`) VALUES (798,5,0)";
93 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_no`) VALUES (798,14,0)";
94 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_no`) VALUES (798,16,0)";
95 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_no`) VALUES (798,17,0)";
96 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_no`) VALUES (798,18,0)";
97 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_no`) VALUES (798,20,0)";
98 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_no`) VALUES (798,21,0)";
99 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_no`) VALUES (798,22,0)";
100 $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_no`) VALUES (798,24,0)";
101 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (1,798,'Network security')";
102 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,799,'Cisco%GPASS%ASA 5505')";
103 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,800,'Cisco%GPASS%ASA 5510')";
104 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,801,'Cisco%GPASS%ASA 5520')";
105 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,802,'Cisco%GPASS%ASA 5540')";
106 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,803,'Cisco%GPASS%ASA 5550')";
107 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,804,'Cisco%GPASS%ASA 5580-20')";
108 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,805,'Cisco%GPASS%ASA 5580-40')";
109 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,806,'[[Cisco%GPASS%IDS 4215 | http://www.cisco.com/en/US/products/hw/vpndevc/ps4077/ps5367/index.html]]')";
110 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,807,'[[Cisco%GPASS%IDS 4240 | http://www.cisco.com/en/US/products/ps5768/index.html]]')";
111 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,808,'[[Cisco%GPASS%IDS 4255 | http://www.cisco.com/en/US/products/ps5769/index.html]]')";
112 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,809,'[[Cisco%GPASS%IDS 4260 | http://www.cisco.com/en/US/products/ps6751/index.html]]')";
113 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,810,'[[Cisco%GPASS%IDS 4270 | http://www.cisco.com/en/US/products/ps9157/index.html]]')";
114 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,811,'Foundry%GPASS%SecureIron 100')";
115 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,812,'Foundry%GPASS%SecureIron 100C')";
116 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,813,'Foundry%GPASS%SecureIron 300')";
117 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,814,'Foundry%GPASS%SecureIron 300C')";
118 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,815,'Foundry%GPASS%SecureIronLS 100-4802')";
119 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,816,'Foundry%GPASS%SecureIronLS 300-32GC02')";
120 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,817,'Foundry%GPASS%SecureIronLS 300-32GC10G')";
121 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,818,'[[D-Link%GPASS%DFL-1600 | http://www.dlink.com/products/?sec=0&pid=454]]')";
122 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,819,'[[D-Link%GPASS%DFL-M510 | http://www.dlink.com/products/?sec=0&pid=455]]')";
123 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,820,'[[Extreme Networks%GPASS%Sentriant AG200 | http://www.extremenetworks.com/products/sentriant-ag200.aspx]]')";
124 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,821,'[[Extreme Networks%GPASS%Sentriant NG300 | http://www.extremenetworks.com/products/sentriant-ng300.aspx]]')";
125 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,822,'[[Force10%GPASS%P-Series | http://www.force10networks.com/products/pseries.asp]]')";
126 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,823,'[[Juniper%GPASS%SSG 140 | http://www.juniper.net/products_and_services/firewall_slash_ipsec_vpn/ssg_140/index.html]]')";
127 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,824,'[[Juniper%GPASS%SSG 320 | http://www.juniper.net/products_and_services/firewall_slash_ipsec_vpn/ssg_300_series/index.html]]')";
128 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,825,'[[Juniper%GPASS%SSG 350 | http://www.juniper.net/products_and_services/firewall_slash_ipsec_vpn/ssg_300_series/index.html]]')";
129 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,826,'[[Juniper%GPASS%SSG 520 | http://www.juniper.net/products_and_services/firewall_slash_ipsec_vpn/ssg_500_series/index.html]]')";
130 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,827,'[[Juniper%GPASS%SSG 550 | http://www.juniper.net/products_and_services/firewall_slash_ipsec_vpn/ssg_500_series/index.html]]')";
131 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,828,'[[Juniper%GPASS%ISG 1000 | http://www.juniper.net/products_and_services/firewall_slash_ipsec_vpn/isg_series_slash_gprs/index.html]]')";
132 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,829,'[[Juniper%GPASS%ISG 2000 | http://www.juniper.net/products_and_services/firewall_slash_ipsec_vpn/isg_series_slash_gprs/index.html]]')";
133 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,830,'[[Juniper%GPASS%NetScreen 5200 | http://www.juniper.net/products_and_services/firewall_slash_ipsec_vpn/isg_series_slash_gprs/index.html]]')";
134 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,831,'[[Juniper%GPASS%NetScreen 5400 | http://www.juniper.net/products_and_services/firewall_slash_ipsec_vpn/isg_series_slash_gprs/index.html]]')";
135 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,832,'[[Juniper%GPASS%SRX 5600 | http://www.juniper.net/products_and_services/srx_series/index.html]]')";
136 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,833,'[[Juniper%GPASS%SRX 5800 | http://www.juniper.net/products_and_services/srx_series/index.html]]')";
137 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,834,'[[SonicWall%GPASS%PRO 1260 | http://www.sonicwall.com/us/products/PRO_1260.html]]')";
138 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,835,'[[SonicWall%GPASS%PRO 2040 | http://www.sonicwall.com/us/products/PRO_2040.html]]')";
139 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,836,'[[SonicWall%GPASS%PRO 3060 | http://www.sonicwall.com/us/products/PRO_3060.html]]')";
140 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,837,'[[SonicWall%GPASS%PRO 4060 | http://www.sonicwall.com/us/products/PRO_4060.html]]')";
141 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,838,'[[SonicWall%GPASS%PRO 4100 | http://www.sonicwall.com/us/products/PRO_4100.html]]')";
142 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,839,'[[SonicWall%GPASS%PRO 5060 | http://www.sonicwall.com/us/products/PRO_5060.html]]')";
143 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,840,'[[SonicWall%GPASS%NSA 240 | http://www.sonicwall.com/us/products/NSA_240.html]]')";
144 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,841,'[[SonicWall%GPASS%NSA 2400 | http://www.sonicwall.com/us/products/NSA_2400.html]]')";
145 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,842,'[[SonicWall%GPASS%NSA 3500 | http://www.sonicwall.com/us/products/NSA_3500.html]]')";
146 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,843,'[[SonicWall%GPASS%NSA 4500 | http://www.sonicwall.com/us/products/NSA_4500.html]]')";
147 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,844,'[[SonicWall%GPASS%NSA 5000 | http://www.sonicwall.com/us/products/NSA_5000.html]]')";
148 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,845,'[[SonicWall%GPASS%NSA E5500 | http://www.sonicwall.com/us/products/NSA_E5500.html]]')";
149 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,846,'[[SonicWall%GPASS%NSA E6500 | http://www.sonicwall.com/us/products/NSA_E6500.html]]')";
150 $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (24,847,'[[SonicWall%GPASS%NSA E7500 | http://www.sonicwall.com/us/products/NSA_E7500.html]]')";
151 $query[] = "UPDATE Dictionary SET chapter_no = 24 WHERE (dict_key = 717 OR dict_key = 718 OR dict_key = 719)";
152 $query[] = "UPDATE Dictionary SET chapter_no = 24, dict_value = '[[Juniper%GPASS%NetScreen 100 | http://www.juniper.net/customers/support/products/netscreen100.jsp]]' WHERE dict_key = 287";
153 $query[] = "UPDATE Dictionary SET dict_value = 'Network switch' WHERE dict_key = 8";
e1ae3fb4 154 $query[] = "UPDATE Config SET varvalue = '0.17.0' WHERE varname = 'DB_VERSION'";
b3f866fc 155 break;
fbbb74fb 156 default:
b0348307 157 showError ("executeUpgradeBatch () failed, because batch '${batchid}' isn't defined", __FILE__);
fbbb74fb
DO
158 die;
159 break;
160 }
fbbb74fb 161 $failures = array();
ce109ff2 162 $ndots = 0;
22e40283 163 echo "<pre>Executing database upgrade batch '${batchid}':\n";
fbbb74fb
DO
164 foreach ($query as $q)
165 {
166 $result = $dbxlink->query ($q);
167 if ($result != NULL)
fbbb74fb 168 echo '.';
758fe24c
DO
169 else
170 {
171 echo '!';
172 $errorInfo = $dbxlink->errorInfo();
173 $failures[] = array ($q, $errorInfo[2]);
174 }
175 if (++$ndots == 50)
176 {
177 echo "\n";
15a50768 178 flush();
758fe24c 179 $ndots = 0;
fbbb74fb 180 }
fbbb74fb
DO
181 }
182 echo '<br>';
183 if (!count ($failures))
184 echo "No errors!\n";
185 else
186 {
7fc5565c 187 echo "The following queries failed:\n<font color=red>";
fbbb74fb
DO
188 foreach ($failures as $f)
189 {
190 list ($q, $i) = $f;
191 echo "${q} // ${i}\n";
192 }
193 }
7fc5565c 194 echo '</font></pre>';
fbbb74fb
DO
195}
196
197// ******************************************************************
198//
199// Execution starts here
200//
201// ******************************************************************
202
203$root = (empty($_SERVER['HTTPS'])?'http':'https').
204 '://'.
205 (isset($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:($_SERVER['SERVER_NAME'].($_SERVER['SERVER_PORT']=='80'?'':$_SERVER['SERVER_PORT']))).
54c2a7a8
DO
206 dirname($_SERVER['PHP_SELF']);
207if (substr ($root, -1) != '/')
208 $root .= '/';
fbbb74fb
DO
209
210// The below will be necessary as long as we rely on showError()
211require_once 'inc/interface.php';
212
213require_once 'inc/config.php';
214require_once 'inc/database.php';
215if (file_exists ('inc/secret.php'))
216 require_once 'inc/secret.php';
217else
218 die ("Database connection parameters are read from inc/secret.php file, " .
219 "which cannot be found.\nCopy provided inc/secret-sample.php to " .
220 "inc/secret.php and modify to your setup.\n\nThen reload the page.");
221
222try
223{
224 $dbxlink = new PDO ($pdo_dsn, $db_username, $db_password);
225}
226catch (PDOException $e)
227{
228 die ("Database connection failed:\n\n" . $e->getMessage());
229}
230
fbbb74fb
DO
231// Now we need to be sure that the current user is the administrator.
232// The rest doesn't matter within this context.
233// We still continue to use the current authenticator though, but this will
234// last only till the UserAccounts remains the same. After that this file
235// will have to dig into the DB for the user accounts.
236require_once 'inc/auth.php';
237
a1f3710a
DO
238// 1. This didn't fail sanely, because getUserAccounts() depended on showError()
239// 2. getUserAccounts() doesn't work for old DBs since 0.16.0. Let's have own
240// copy until it breaks too.
241
242function getUserAccounts_local ()
243{
244 global $dbxlink;
245 $query = 'select user_id, user_name, user_password_hash from UserAccount order by user_name';
246 if (($result = $dbxlink->query ($query)) == NULL)
247 die ('SQL query failed in ' . __FUNCTION__);
248 $ret = array();
249 while ($row = $result->fetch (PDO::FETCH_ASSOC))
250 foreach (array ('user_id', 'user_name', 'user_password_hash') as $cname)
251 $ret[$row['user_name']][$cname] = $row[$cname];
252 return $ret;
253}
254
255$accounts = getUserAccounts_local();
fbbb74fb 256
d78fdaea
DO
257// Only administrator is always authenticated locally, so reject others
258// for authenticate() to succeed.
99ee5479
DO
259
260if
261(
262 !isset ($_SERVER['PHP_AUTH_USER']) or
263 !isset ($_SERVER['PHP_AUTH_PW']) or
264 $accounts[$_SERVER['PHP_AUTH_USER']]['user_id'] != 1 or
265 !authenticated_via_database (escapeString ($_SERVER['PHP_AUTH_USER']), escapeString ($_SERVER['PHP_AUTH_PW']))
266)
267{
c0142c01
DO
268 header ('WWW-Authenticate: Basic realm="RackTables upgrade"');
269 header ('HTTP/1.0 401 Unauthorized');
b0348307 270 showError ('You must be authenticated as an administrator to complete the upgrade.', __FILE__);
99ee5479
DO
271 die;
272}
fbbb74fb
DO
273
274$dbver = getDatabaseVersion();
5f4027b8
DO
275echo 'Code version: ' . CODE_VERSION . '<br>';
276echo 'Database version: ' . $dbver . '<br>';
fbbb74fb 277if ($dbver == CODE_VERSION)
758fe24c 278{
5f4027b8
DO
279 die ("<p align=justify>No action is necessary. " .
280 "Proceed to the <a href='${root}'>main page</a>, " .
281 "check your data and have a nice day.</p>");
758fe24c 282}
fbbb74fb
DO
283
284foreach (getDBUpgradePath ($dbver, CODE_VERSION) as $batchid)
5f4027b8 285{
fbbb74fb 286 executeUpgradeBatch ($batchid);
5f4027b8
DO
287 printReleaseNotes ($batchid);
288}
fbbb74fb
DO
289
290echo '<br>Database version == ' . getDatabaseVersion();
291echo "<p align=justify>Your database seems to be up-to-date. " .
292 "Now the best thing to do would be to follow to the <a href='${root}'>main page</a> " .
293 "and explore your data. Have a nice day.</p>";
294
295?>