forked from jakepaulus/collate-network
/
install.php
632 lines (568 loc) · 24.3 KB
/
install.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
<?php
$op = (empty($_GET['op'])) ? 'default' : $_GET['op'];
switch($op){
case "install";
install();
break;
default:
health_check();
break;
}
function health_check(){
# For now, we will be supporting only English for installation
# we still need to include language files for header.php and nav.php to look right.
require_once('./languages/en.php');
$COLLATE["languages"]["selected"] = $languages['en'];
require_once('./include/header.php');
echo "<h1>Install/Upgrade Collate:Network</h1><br>";
# We need php >= 5.1 due to inet_pton()
# Cannot continue install without this
if(phpversion() < 5.1){
echo "<p class=\"installfail\">You need PHP version 5.1 or greater to use Collate:Network</p>";
echo "</div></div>";
require_once('./include/nav.php');
echo "</div>";
exit();
}
else{
echo "<p class=\"tip\">PHP version check passed</p>";
}
# We need LDAP support if the user wants it
if(function_exists('ldap_connect')){
echo "<p class=\"tip\">LDAP support detected</p>";
}
else{
# Warn the user if they don't have it and give help on how to get it
echo "<p class=\"installwarn\">LDAP support NOT detected. You can continue, but you will not be able to use LDAP integration.</p>";
}
# We need mbstring support to detect encoding of uploaded files
if(function_exists('mb_detect_encoding')){
echo "<p class=\"tip\">PHP mbstring support detected</p>";
}
else{
# Warn the user if they don't have it and give help on how to get it
echo "<p class=\"installwarn\">PHP mbstring support is needed to support bulk uploads. You can continue, but this feature will not work.</p>";
}
# Does the server's php.ini permit uplaods?
if(ini_get('file_uploads')){
echo "<p class=\"tip\">"file_uploads" is on in php.ini</p>";
}
else{
echo "<p class=\"installwarn\">"file_uploads" is off in php.ini You can continue, but the bulk import feature will not work.</p>";
}
# Can we connect to the database?
require_once('./include/db_connect.php');
$dbo = getdbo();
if(!is_object($dbo)){
echo "<p class=\"installfail\">$dbo</p>";
echo "</div></div>";
require_once('./include/nav.php');
echo "</div>";
exit();
}
else{
echo "<p class=\"tip\">Database connection looks good</p>";
}
# php version check and db_connect.php both call exit() and are the only two strict failures we
# look for. If they got this far, they can keep going!
echo "<br><form action=\"install.php?op=install\" method=\"POST\"><input type=\"submit\" value=\" Install \"></form>";
echo "</div></div>";
require_once('./include/nav.php');
echo "</div>";
exit();
}
function install(){
require_once('./include/db_connect.php');
$dbo = getdbo();
$install =
"
CREATE TABLE `acl` (
`id` int(9) UNSIGNED NOT NULL auto_increment,
`name` varchar(25) NOT NULL,
`start_ip` int(10) NOT NULL,
`end_ip` int(10) NOT NULL,
`subnet_id` int(9) UNSIGNED NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;
CREATE TABLE `api-keys` (
`apikey` varchar(21) NOT NULL,
`description` varchar(60) NOT NULL,
`active` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`apikey`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE `blocks` (
`id` int(9) UNSIGNED NOT NULL auto_increment,
`name` varchar(25) NOT NULL,
`start_ip` int(10) NOT NULL,
`end_ip` int(10) NOT NULL,
`note` varchar(255) NOT NULL,
`modified_by` varchar(100) NOT NULL,
`modified_at` datetime NOT NULL,
`parent_id` int(9) UNSIGNED,
`type` ENUM('container','ipv4','ipv6') DEFAULT 'ipv4',
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;
CREATE TABLE `ldap-servers` (
`id` tinyint(4) UNSIGNED NOT NULL auto_increment,
`domain` varchar(128) NOT NULL,
`server` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE `logs` (
`id` int(11) UNSIGNED NOT NULL auto_increment,
`occuredat` datetime NOT NULL,
`username` varchar(100) NOT NULL,
`ipaddress` varchar(15) NOT NULL,
`level` varchar(6) NOT NULL,
`message` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
KEY `username` (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE `settings` (
`name` varchar(50) NOT NULL,
`value` longtext NOT NULL,
PRIMARY KEY (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO `settings` VALUES ('passwdlength', '5');
INSERT INTO `settings` VALUES ('accountexpire', '60');
INSERT INTO `settings` VALUES ('loginattempts', '4');
INSERT INTO `settings` VALUES ('version', '2.4');
INSERT INTO `settings` VALUES ('perms', '6');
INSERT INTO `settings` VALUES ('guidance', '');
INSERT INTO `settings` VALUES ('dns', '');
INSERT INTO `settings` VALUES ('auth_type', 'db');
INSERT INTO `settings` VALUES ('domain', '');
INSERT INTO `settings` VALUES ('language', 'en');
CREATE TABLE `statics` (
`id` int(10) UNSIGNED NOT NULL auto_increment,
`ip` int(10) NOT NULL,
`name` varchar(50) NOT NULL,
`contact` varchar(25) NOT NULL,
`note` varchar(255) NOT NULL,
`subnet_id` int(9) UNSIGNED NOT NULL,
`modified_by` varchar(100) NOT NULL,
`modified_at` datetime NOT NULL,
`failed_scans` INT( 16 ) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `ip` (`ip`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;
CREATE TABLE `subnets` (
`id` int(9) UNSIGNED NOT NULL auto_increment,
`name` varchar(60) NOT NULL,
`start_ip` int(10) NOT NULL,
`end_ip` int(10) NOT NULL,
`mask` int(10) NOT NULL,
`note` varchar(255) NOT NULL,
`block_id` int(9) UNSIGNED NOT NULL,
`modified_by` varchar(100) NOT NULL,
`modified_at` datetime NOT NULL,
`guidance` longtext NOT NULL,
`stalescan_enabled` BOOL NOT NULL default true,
PRIMARY KEY (`id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;
CREATE TABLE `users` (
`id` int(9) UNSIGNED NOT NULL auto_increment,
`username` varchar(100) NOT NULL,
`passwd` varchar(40) NOT NULL,
`tmppasswd` varchar(40) NOT NULL,
`accesslevel` tinyint(1) NOT NULL default '0',
`phone` varchar(25) NOT NULL,
`email` varchar(50) NOT NULL,
`loginattempts` tinyint(1) NOT NULL,
`passwdexpire` datetime NOT NULL,
`ldapexempt` tinyint(1) NOT NULL default '0',
`last_login_at` datetime NOT NULL,
`language` VARCHAR(2) NOT NULL default 'en',
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO logs (occuredat, username, level, message) VALUES (NOW(), 'system', 'high', 'Collate:Network Version 2.4 Installed!')
";
$upgrade_from_one_dot_zero =
"
ALTER TABLE subnets ADD guidance LONGTEXT NOT NULL;
ALTER TABLE blocks CHANGE id id INT( 9 ) NOT NULL AUTO_INCREMENT;
ALTER TABLE logs CHANGE id id INT( 11 ) NOT NULL AUTO_INCREMENT;
ALTER TABLE statics CHANGE id id INT( 10 ) NOT NULL AUTO_INCREMENT, CHANGE subnet_id subnet_id INT( 9 ) NOT NULL;
ALTER TABLE subnets CHANGE id id INT( 9 ) NOT NULL AUTO_INCREMENT , CHANGE block_id block_id INT( 9 ) NOT NULL;
INSERT INTO settings (name, value) VALUES ('guidance', '');
";
$upgrade_from_one_dot_two =
"
ALTER TABLE statics CHANGE name name varchar( 50 ) NO NULL;
";
$upgrade_from_one_dot_four =
"
CREATE TABLE `ldap-servers` (
`id` tinyint(4) NOT NULL auto_increment,
`domain` varchar(128) NOT NULL,
`server` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO `settings` VALUES ('dns', '');
INSERT INTO `settings` VALUES ('auth_type', 'db');
INSERT INTO `settings` VALUES ('domain', '');
ALTER TABLE statics ADD last_checked_at datetime NOT NULL;
ALTER TABLE users ADD ldapexempt TINYINT( 1 ) NOT NULL DEFAULT '0';
UPDATE settings SET value='1.5' WHERE name='version';
";
$upgrade_from_one_dot_five =
"
ALTER TABLE statics CHANGE last_checked_at failed_scans INT( 16 ) NOT NULL DEFAULT '0';
UPDATE statics SET failed_scans='0';
ALTER TABLE users CHANGE username username varchar ( 50 ) NOT NULL;
UPDATE settings SET value='1.6' WHERE name='version'
";
function upgrade_from_one_dot_six () {
# Find autoincrement values for each table that uses them
$sql = "SELECT LAST_INSERT_ID() from acl";
$result = $dbo->exec($sql);
$acl_autoincrement = $result->fetchColumn();
$sql = "SELECT LAST_INSERT_ID() from blocks";
$result = $dbo->exec($sql);
$blocks_autoincrement = $result->fetchColumn();
$sql = "SELECT LAST_INSERT_ID() from `ldap-servers`";
$result = $dbo->exec($sql);
$ldap_autoincrement = $result->fetchColumn();
$sql = "SELECT LAST_INSERT_ID() from logs";
$result = $dbo->exec($sql);
$logs_autoincrement = $result->fetchColumn();
$sql = "SELECT LAST_INSERT_ID() from statics";
$result = $dbo->exec($sql);
$statics_autoincrement = $result->fetchColumn();
$sql = "SELECT LAST_INSERT_ID() from subnets";
$result = $dbo->exec($sql);
$subnets_autoincrement = $result->fetchColumn();
$sql = "SELECT LAST_INSERT_ID() from users";
$result = $dbo->exec($sql);
$users_autoincrement = $result->fetchColumn();
# copy old tables to temporary tables using unsigned INTs, then drop old ones, then rename new to old
$data_shuffle =
"
CREATE TABLE `tmp_acl` (
`id` int(9) UNSIGNED NOT NULL auto_increment,
`name` varchar(25) NOT NULL,
`start_ip` int(10) NOT NULL,
`end_ip` int(10) NOT NULL,
`subnet_id` int(9) UNSIGNED NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=$acl_autoincrement DEFAULT CHARSET=latin1;
INSERT INTO `tmp_acl` SELECT CAST((id & 0xFFFFFFFF) AS UNSIGNED), name, start_ip, end_ip, apply FROM acl;
CREATE TABLE `tmp_blocks` (
`id` int(9) UNSIGNED NOT NULL auto_increment,
`name` varchar(25) NOT NULL,
`start_ip` int(10) NOT NULL,
`end_ip` int(10) NOT NULL,
`note` varchar(255) NOT NULL,
`modified_by` varchar(25) NOT NULL,
`modified_at` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=MyISAM AUTO_INCREMENT=$blocks_autoincrement DEFAULT CHARSET=latin1;
INSERT INTO `tmp_blocks` SELECT CAST((id & 0xFFFFFFFF) AS UNSIGNED), name, start_ip, end_ip, note, modified_by, modified_at FROM blocks;
CREATE TABLE `tmp_ldap-servers` (
`id` tinyint(4) UNSIGNED NOT NULL auto_increment,
`domain` varchar(128) NOT NULL,
`server` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=$ldap_autoincrement DEFAULT CHARSET=latin1;
INSERT INTO `tmp_ldap-servers` SELECT CAST((id & 0xFFFFFFFF) AS UNSIGNED), domain, server FROM `ldap-servers`;
CREATE TABLE `tmp_logs` (
`id` int(11) UNSIGNED NOT NULL auto_increment,
`occuredat` datetime NOT NULL,
`username` varchar(30) NOT NULL,
`ipaddress` varchar(15) NOT NULL,
`level` varchar(6) NOT NULL,
`message` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
KEY `username` (`username`)
) ENGINE=MyISAM AUTO_INCREMENT=$logs_autoincrement DEFAULT CHARSET=latin1;
INSERT INTO `tmp_logs` SELECT CAST((id & 0xFFFFFFFF) AS UNSIGNED), occuredat, username, ipaddress, level, message FROM logs;
CREATE TABLE `tmp_statics` (
`id` int(10) UNSIGNED NOT NULL auto_increment,
`ip` int(10) NOT NULL,
`name` varchar(50) NOT NULL,
`contact` varchar(25) NOT NULL,
`note` varchar(255) NOT NULL,
`subnet_id` int(9) UNSIGNED NOT NULL,
`modified_by` varchar(25) NOT NULL,
`modified_at` datetime NOT NULL,
`failed_scans` INT( 16 ) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `ip` (`ip`)
) ENGINE=MyISAM AUTO_INCREMENT=$statics_autoincrement DEFAULT CHARSET=latin1;
INSERT INTO `tmp_statics` SELECT CAST((id & 0xFFFFFFFF) AS UNSIGNED), ip, name, contact, note, CAST((subnet_id & 0xFFFFFFFF) AS UNSIGNED), modified_by, modified_at, failed_scans FROM statics;
CREATE TABLE `tmp_subnets` (
`id` int(9) UNSIGNED NOT NULL auto_increment,
`name` varchar(25) NOT NULL,
`start_ip` int(10) NOT NULL,
`end_ip` int(10) NOT NULL,
`mask` int(10) NOT NULL,
`note` varchar(255) NOT NULL,
`block_id` tinyint(9) UNSIGNED NOT NULL,
`modified_by` varchar(25) NOT NULL,
`modified_at` datetime NOT NULL,
`guidance` longtext NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=MyISAM AUTO_INCREMENT=$subnets_autoincrement DEFAULT CHARSET=latin1;
INSERT INTO `tmp_subnets` SELECT CAST((id & 0xFFFFFFFF) AS UNSIGNED), name, start_ip, end_ip, mask, note, CAST((block_id & 0xFFFFFFFF) AS UNSIGNED), modified_by, modified_at, guidance FROM subnets;
CREATE TABLE `tmp_users` (
`id` int(9) UNSIGNED NOT NULL auto_increment,
`username` varchar(100) NOT NULL,
`passwd` varchar(40) NOT NULL,
`tmppasswd` varchar(40) NOT NULL,
`accesslevel` tinyint(1) NOT NULL default '0',
`phone` varchar(25) NOT NULL,
`email` varchar(50) NOT NULL,
`loginattempts` tinyint(1) NOT NULL,
`passwdexpire` datetime NOT NULL,
`ldapexempt` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=MyISAM AUTO_INCREMENT=$users_autoincrement DEFAULT CHARSET=latin1;
INSERT INTO `tmp_users` SELECT CAST((id & 0xFFFFFFFF) AS UNSIGNED), username, passwd, tmppasswd, accesslevel, phone, email, loginattempts, passwdexpire, ldapexempt FROM users;
DROP TABLE acl;
DROP TABLE blocks;
DROP TABLE `ldap-servers`;
DROP TABLE logs;
DROP TABLE statics;
DROP TABLE subnets;
DROP TABLE users;
RENAME TABLE tmp_acl TO acl;
RENAME TABLE tmp_blocks TO blocks;
RENAME TABLE `tmp_ldap-servers` TO `ldap-servers`;
RENAME TABLE tmp_logs TO logs;
RENAME TABLE tmp_statics TO statics;
RENAME TABLE tmp_subnets TO subnets;
RENAME TABLE tmp_users TO users;
DELETE FROM statics WHERE subnet_id != ALL (SELECT id from subnets);
UPDATE settings SET value='1.7' WHERE name='version'
";
$results = multiple_query("$data_shuffle");
return $results;
}
$upgrade_from_one_dot_seven =
"
ALTER TABLE subnets CHANGE block_id block_id INT( 9 ) UNSIGNED NOT NULL;
UPDATE settings SET value='1.7.1' WHERE name='version';
";
$upgrade_from_one_dot_seven_dot_one =
"
UPDATE settings SET value='1.7.2' WHERE name='version';
";
$upgrade_from_one_dot_seven_dot_two =
"
ALTER TABLE subnets MODIFY name varchar(60);
ALTER TABLE users ADD last_login_at datetime NOT NULL;
ALTER TABLE `subnets` DROP index `name`;
ALTER TABLE `blocks` MODIFY modified_by varchar(100);
ALTER TABLE `logs` MODIFY username varchar(100);
ALTER TABLE `statics` MODIFY modified_by varchar(100);
ALTER TABLE `subnets` MODIFY modified_by varchar(100);
UPDATE settings SET value='2.0' WHERE name='version';
";
$upgrade_from_two_dot_zero =
"
INSERT INTO `settings` VALUES ('language', 'en');
ALTER TABLE `users` ADD `language` VARCHAR(2) NOT NULL default 'en';
UPDATE settings SET value='2.1' WHERE name='version';
CREATE TABLE `api-keys` (
`apikey` varchar(21) NOT NULL,
`description` varchar(60) NOT NULL,
`active` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`apikey`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
ALTER TABLE `blocks` ENGINE = INNODB;
ALTER TABLE `subnets` ENGINE = INNODB;
ALTER TABLE `acl` ENGINE = INNODB;
ALTER TABLE `statics` ENGINE = INNODB
";
$upgrade_from_two_dot_one =
"
ALTER TABLE blocks ADD `parent_id` int(9) UNSIGNED;
ALTER TABLE blocks ADD `type` ENUM('container','ipv4','ipv6') DEFAULT 'ipv4';
ALTER TABLE subnets ADD stalescan_enabled BOOL NOT NULL default true;
UPDATE settings SET value='2.2' WHERE name='version'
";
$upgrade_from_two_dot_two =
"
UPDATE settings SET value='2.2.1' WHERE name='version';
INSERT INTO logs (occuredat, username, level, message) VALUES (NOW(), 'system', 'high', 'Collate:Network upgraded to version 2.2.1!')
";
$upgrade_from_two_dot_two_dot_one =
"
UPDATE settings SET value='2.3' WHERE name='version';
INSERT INTO logs (occuredat, username, level, message) VALUES (NOW(), 'system', 'high', 'Collate:Network upgraded to version 2.3!')
";
$upgrade_from_two_dot_three =
"
UPDATE settings SET value='2.4' WHERE name='version';
INSERT INTO logs (occuredat, username, level, message) VALUES (NOW(), 'system', 'high', 'Collate:Network upgraded to version 2.4!')
";
$sql = "select value from settings where name='version'";
$result = $dbo->query($sql);
if($result != FALSE) { // See what version we're on
$version = $result->fetchColumn();
if($version == '1.0'){
$results = multiple_query("$upgrade_from_one_dot_zero");
$results .= multiple_query("$upgrade_from_one_dot_two");
$results .= multiple_query("$upgrade_from_one_dot_four");
$results .= multiple_query("$upgrade_from_one_dot_five");
$results .= upgrade_from_one_dot_six();
$results .= multiple_query("$upgrade_from_one_dot_seven");
$results .= multiple_query($upgrade_from_one_dot_seven_dot_one);
$results .= multiple_query($upgrade_from_one_dot_seven_dot_two);
$results .= multiple_query($upgrade_from_two_dot_zero);
$results .= multiple_query($upgrade_from_two_dot_one);
$results .= multiple_query($upgrade_from_two_dot_two);
$results .= multiple_query($upgrade_from_two_dot_two_dot_one);
$results .= multiple_query($upgrade_from_two_dot_three);
}
elseif($version == '1.2'){
$results = multiple_query("$upgrade_from_one_dot_two");
$results .= multiple_query("$upgrade_from_one_dot_four");
$results .= multiple_query("$upgrade_from_one_dot_five");
$results .= upgrade_from_one_dot_six();
$results .= multiple_query("$upgrade_from_one_dot_seven");
$results .= multiple_query($upgrade_from_one_dot_seven_dot_one);
$results .= multiple_query($upgrade_from_one_dot_seven_dot_two);
$results .= multiple_query($upgrade_from_two_dot_zero);
$results .= multiple_query($upgrade_from_two_dot_one);
$results .= multiple_query($upgrade_from_two_dot_two);
$results .= multiple_query($upgrade_from_two_dot_two_dot_one);
$results .= multiple_query($upgrade_from_two_dot_three);
}
elseif($version == '1.3' || $version == '1.4'){
$results .= multiple_query("$upgrade_from_one_dot_four");
$results .= multiple_query("$upgrade_from_one_dot_five");
$results .= upgrade_from_one_dot_six();
$results .= multiple_query("$upgrade_from_one_dot_seven");
$results .= multiple_query($upgrade_from_one_dot_seven_dot_one);
$results .= multiple_query($upgrade_from_one_dot_seven_dot_two);
$results .= multiple_query($upgrade_from_two_dot_zero);
$results .= multiple_query($upgrade_from_two_dot_one);
$results .= multiple_query($upgrade_from_two_dot_two);
$results .= multiple_query($upgrade_from_two_dot_two_dot_one);
$results .= multiple_query($upgrade_from_two_dot_three);
}
elseif($version == '1.5'){
$results .= multiple_query("$upgrade_from_one_dot_five");
$results .= upgrade_from_one_dot_six();
$results .= multiple_query("$upgrade_from_one_dot_seven");
$results .= multiple_query($upgrade_from_one_dot_seven_dot_one);
$results .= multiple_query($upgrade_from_one_dot_seven_dot_two);
$results .= multiple_query($upgrade_from_two_dot_zero);
$results .= multiple_query($upgrade_from_two_dot_one);
$results .= multiple_query($upgrade_from_two_dot_two);
$results .= multiple_query($upgrade_from_two_dot_two_dot_one);
$results .= multiple_query($upgrade_from_two_dot_three);
}
elseif($version == '1.6'){
$results = upgrade_from_one_dot_six();
$results .= multiple_query("$upgrade_from_one_dot_seven");
$results .= multiple_query($upgrade_from_one_dot_seven_dot_one);
$results .= multiple_query($upgrade_from_one_dot_seven_dot_two);
$results .= multiple_query($upgrade_from_two_dot_zero);
$results .= multiple_query($upgrade_from_two_dot_one);
$results .= multiple_query($upgrade_from_two_dot_two);
$results .= multiple_query($upgrade_from_two_dot_two_dot_one);
$results .= multiple_query($upgrade_from_two_dot_three);
}
elseif($version == '1.7'){
$results = multiple_query("$upgrade_from_one_dot_seven");
$results .= multiple_query($upgrade_from_one_dot_seven_dot_one);
$results .= multiple_query($upgrade_from_one_dot_seven_dot_two);
$results .= multiple_query($upgrade_from_two_dot_zero);
$results .= multiple_query($upgrade_from_two_dot_one);
$results .= multiple_query($upgrade_from_two_dot_two);
$results .= multiple_query($upgrade_from_two_dot_two_dot_one);
$results .= multiple_query($upgrade_from_two_dot_three);
}
elseif($version == '1.7.1'){
$results = multiple_query($upgrade_from_one_dot_seven_dot_one);
$results .= multiple_query($upgrade_from_one_dot_seven_dot_two);
$results .= multiple_query($upgrade_from_two_dot_zero);
$results .= multiple_query($upgrade_from_two_dot_one);
$results .= multiple_query($upgrade_from_two_dot_two);
$results .= multiple_query($upgrade_from_two_dot_two_dot_one);
$results .= multiple_query($upgrade_from_two_dot_three);
}
elseif($version == '1.7.2'){
$results = multiple_query($upgrade_from_one_dot_seven_dot_two);
$results .= multiple_query($upgrade_from_two_dot_zero);
$results .= multiple_query($upgrade_from_two_dot_one);
$results .= multiple_query($upgrade_from_two_dot_two);
$results .= multiple_query($upgrade_from_two_dot_two_dot_one);
$results .= multiple_query($upgrade_from_two_dot_three);
}
elseif($version == '2.0'){
$results = multiple_query($upgrade_from_two_dot_zero);
$results .= multiple_query($upgrade_from_two_dot_one);
$results .= multiple_query($upgrade_from_two_dot_two);
$results .= multiple_query($upgrade_from_two_dot_two_dot_one);
$results .= multiple_query($upgrade_from_two_dot_three);
}
elseif($version == '2.1'){
$results = multiple_query($upgrade_from_two_dot_one);
$results .= multiple_query($upgrade_from_two_dot_two);
$results .= multiple_query($upgrade_from_two_dot_two_dot_one);
$results .= multiple_query($upgrade_from_two_dot_three);
}
elseif($version == '2.2'){
$results = multiple_query($upgrade_from_two_dot_two);
$results .= multiple_query($upgrade_from_two_dot_two_dot_one);
$results .= multiple_query($upgrade_from_two_dot_three);
}
elseif($version == '2.2.1'){
$results = multiple_query($upgrade_from_two_dot_two_dot_one);
$results .= multiple_query($upgrade_from_two_dot_three);
}
elseif($version == '2.3'){
$results = multiple_query($upgrade_from_two_dot_three);
}
elseif($version == '2.4'){
// We're at the current version!
header("Location: index.php?notice=uptodate-notice");
exit();
}
$notice = "upgradesuccess-notice";
}
else{ // We're installing
$results = multiple_query($install);
$notice = "installsuccess-notice";
}
$tok = strtok($results, "<br />");
if($tok){ // There were erors.
# For now, we will be supporting only English for installation
require_once('./languages/en.php');
$COLLATE["languages"]["selected"] = $languages['en'];
require_once('./include/header.php');
echo "<h1>An error has occured.</h1><br>
<p>Below you will find the mysql errors that prevented this application from installing properly.</p>";
echo "$results";
echo "</div></div>";
require_once('./include/nav.php');
echo "</div>";
exit();
}
else{ // Everything went well.
header("Location: index.php?notice=$notice");
}
}
function multiple_query($sql){
$dbo = getdbo();
$tok = strtok($sql, ";");
$results = "";
while ($tok){
$result = $dbo->exec($tok);
if(!$result){
$dbo->errorInfo();
$results = "$results<br>".$result[2];
}
$tok = strtok(";");
}
return $results;
}
?>