-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstallmv.php
More file actions
1924 lines (1747 loc) · 72.7 KB
/
installmv.php
File metadata and controls
1924 lines (1747 loc) · 72.7 KB
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
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?PHP
#
# FILE: installmv.php
#
# Part of the Metavus digital collections platform
# Copyright 2009-2025 Edward Almasy and Internet Scout Research Group
# http://metavus.net
#
# @scout:phpstan
namespace Metavus;
use Exception;
use ScoutLib\ApplicationFramework;
use ScoutLib\Database;
use ScoutLib\PluginManager;
use ScoutLib\StdLib;
use ZipArchive;
$Inst = new Installer();
$Inst->install();
class Installer
{
# ----- CONFIGURATION --------------------------------------------------------
const MINIMUM_MYSQL_VERSION = "5.0";
const MINIMUM_PHP_VERSION = "7.4.0";
const OLDEST_UPGRADABLE_VERSION = "3.2.0";
const MINIMUM_PASSWORD_LENGTH = 6;
const SAMPLE_RECORD_FILE = "install/SampleRecords-220620a.zip";
# PHP extensions required by the software
public $RequiredExtensions = [
"curl",
"gd",
"json",
"mysqli",
"openssl",
"session",
"simplexml",
"xml",
"xmlreader",
"zip",
];
# directories that must be writable before install can begin
# (an attempt will be made to create these if they don't exist)
public $DirsThatMustBeWritable = [
"/",
"/include",
"/tmp",
"/local",
"/local/logs",
"/local/data",
"/local/data/caches",
"/local/data/files",
"/local/data/images",
];
# files containing SQL commands to set up initial database
# (index = file name, value = progress message)
public $DatabaseSetupFiles = [
"install/TestDBPerms.sql" => "Testing database permissions...",
"lib/ScoutLib/User--CreateTables.sql" => "Setting up user tables...",
"lib/ScoutLib/ApplicationFramework--CreateTables.sql"
=> "Setting up application framework tables...",
"lib/ScoutLib/SearchEngine--CreateTables.sql"
=> "Setting up search engine tables...",
"lib/ScoutLib/PluginManager--CreateTables.sql"
=> "Setting up plugin manager tables...",
"lib/ScoutLib/RSSClient--CreateTables.sql"
=> "Setting up RSS client tables...",
"install/CreateTables.sql" => "Setting up Metavus tables...",
];
# obsolete files that must be moved aside (renamed with ".OLD" at the end)
public $ObsoleteFiles = [
"objects/ItemFactory.php",
"plugins/MyForumPosts.php",
"plugins/phpBBSync/phpBBSync.php",
"interface/default/include/AjaxDropdown.css",
"interface/default/include/CW-Generic.css",
"interface/default/include/CWIS.css",
"interface/default/include/CW-Legacy.css",
"interface/default/include/CW-Theme-CKEditor.css",
"interface/default/include/CW-Theme.css",
"interface/default/include/jquery-ui.css",
"interface/default/include/SPT--AJAXDropdown.css",
"interface/default/include/SPT--DragAndDrop.css",
"interface/default/include/SPT--EditInPlace.css",
"interface/default/include/SPT--MDTAndAdmin.css",
"interface/default/include/SPT--Stylesheet.css",
];
# SQL errors we can ignore (index = SQL command, value = error message)
# (IMPORTANT: this list MUST match the list in the Developer plugin)
public $SqlErrorsWeCanIgnore = [
"/ALTER TABLE /i" => "/Table '[a-z0-9_.]+' already exists/i",
"/ALTER TABLE [a-z0-9_]+ (CHANGE|MODIFY) COLUMN/i" => "/Unknown column/i",
"/ALTER TABLE [a-z0-9_]+ ADD /i" => "/Duplicate column name/i",
"/ALTER TABLE [a-z0-9_]+ ADD INDEX/i" => "/Duplicate key name/i",
"/ALTER TABLE [a-z0-9_]+ ADD PRIMARY KEY/i" => "/Multiple primary key/i",
"/ALTER TABLE [a-z0-9_]+ DROP COLUMN/i" => "/Check that column/i",
"/ALTER TABLE [a-z0-9_]+ RENAME/i" => "/Table '[a-z0-9_.]+' doesn't exist/i",
"/CREATE (UNIQUE )?INDEX [a-z0-9_]+ ON [a-z0-9_]+/i" => "/Duplicate key name/i",
"/CREATE TABLE /i" => "/Table '[a-z0-9_.]+' already exists/i",
"/DROP INDEX /i" => "/check that column\/key exists/i",
"/DROP TABLE /i" => "/Unknown table '[a-z0-9_.]+'/i",
# (situation-specific patterns, that should eventually be removed)
"/ALTER TABLE RecordImageInts/i" => "/Table '[a-z0-9_.]+' doesn't exist/i",
"/CREATE TABLE [a-z0-9_]+_old AS SELECT/i"
=> "/Table '[a-z0-9_.]+' doesn't exist/i",
"/INSERT INTO [a-z]+ SELECT \* FROM [a-z0-9_]+_old/i"
=> "/Table '[a-z0-9_.]+' doesn't exist/i",
];
# ----- PUBLIC INTERFACE -----------------------------------------------------
/**
* Class constructor, that sets up class for use before the installation begins.
*/
public function __construct()
{
# have all output write out immediately
ob_implicit_flush(true);
# initialize starting values
$this->FVars = $_POST;
# set debug output level
if (isset($_POST["F_Debug"])) {
$this->VerbosityLevel = 2;
}
if (isset($_POST["F_MoreDebug"])) {
$this->VerbosityLevel = 3;
}
if (isset($_POST["F_EvenMoreDebug"])) {
$this->VerbosityLevel = 4;
}
if (isset($_GET["VB"])) {
$this->VerbosityLevel = $_GET["VB"];
}
# grab our version number
if (file_exists("NEWVERSION")) {
$NewVersion = file_get_contents("NEWVERSION");
if ($NewVersion !== false) {
$this->NewVersion = trim($NewVersion);
}
}
}
/**
* Install or upgrade software.
*/
public function install(): void
{
$this->beginHtmlPage();
# if NEWVERSION exists, it indicates that an install/upgrade hasn't yet
# been run and that we can proceed
if (file_exists("NEWVERSION")) {
# check environment to make sure we can run
$this->checkEnvironment();
# check distribution files
if (!array_key_exists("NOCHKSUMS", $_GET)
&& !array_key_exists("NOCHKSUMS", $_POST)) {
$this->checkDistributionFiles($this->NewVersion);
}
} else {
$this->ErrMsgs[] = "It appears that the installation or upgrade "
."has already been completed.";
}
# if problems were found with environment or the install/upgrade was
# already complete
if (count($this->ErrMsgs)) {
# display error messages
$this->printErrorMessages($this->ErrMsgs);
} else {
# if we are upgrading
$OldVersion = $this->checkForUpgrade();
$IsUpgrade = $OldVersion ? true : false;
if ($IsUpgrade) {
# if existing version is too old to upgrade
$VersionIsTooOld = self::legacyVersionCompare(
$OldVersion,
self::OLDEST_UPGRADABLE_VERSION,
"<"
);
if ($VersionIsTooOld) {
$this->ErrMsgs[] = "Your currently installed version (<i>".$OldVersion
."</i>) is too old to be upgraded with this package. "
."You must first upgrade to version "
.self::OLDEST_UPGRADABLE_VERSION
." and then use this package.";
} else {
# load install information from existing files
$this->loadOldInstallInfo();
}
}
# if we have install information
if (isset($this->FVars["F_Submit"]) && !count($this->ErrMsgs)) {
# check installation information
$this->checkInstallInfo();
}
# if install information has not been collected or we encountered errors
if (!isset($this->FVars["F_Submit"]) || count($this->ErrMsgs)) {
# display any error messages
$this->printErrorMessages($this->ErrMsgs);
# if this is an upgrade
if ($IsUpgrade) {
# display pointer to helpful info
$this->printHelpPointers();
} else {
# display install information form
$this->printInstallInfoForm();
}
} else {
# print install parameter summary
$this->printInstallInfoSummary($IsUpgrade);
# set up files
$this->msg(1, "<b>Beginning "
.($IsUpgrade ? "Upgrade" : "Installation")." Process...</b>");
$ErrMsgs = $this->installFiles($IsUpgrade);
# tell Bootloader to use ScoutLib\User instead of Metavus\User
# (because Metavus\User relies on having the User metadata
# schema already set up)
$GLOBALS["StartUpOpt_USE_AXIS_USER"] = true;
# if we are upgrading
if ($IsUpgrade) {
# upgrade existing database
if (!count($this->ErrMsgs)) {
$this->ErrMsgs = $this->upgradeExistingDatabase(
$this->ErrMsgs,
$OldVersion
);
}
# initialize application environment
if (!count($this->ErrMsgs)) {
$this->initializeAF($this->NewVersion);
}
# upgrade site
if (!count($this->ErrMsgs)) {
$this->ErrMsgs = $this->upgradeSite($OldVersion);
}
# clear any existing compiled CSS files and minimized
# JavaScript files so that any updated files will
# instead be used
if (!count($this->ErrMsgs)) {
$AF = ApplicationFramework::getInstance();
if ($AF->clearCompiledCssFiles() === false) {
$this->ErrMsgs[] = "Clearing compiled CSS files failed.";
}
if ($AF->clearMinimizedJavascriptFiles() === false) {
$this->ErrMsgs[] = "Clearing minimized JS files failed.";
}
}
} else {
# set up database
if (!count($this->ErrMsgs)) {
$this->ErrMsgs = $this->setUpNewDatabase($this->ErrMsgs);
}
# initialize application environment (without plugins)
$GLOBALS["StartUpOpt_DO_NOT_LOAD_PLUGINS"] = true;
if (!count($this->ErrMsgs)) {
$this->initializeAF($this->NewVersion);
}
# load default system configuration
if (!count($this->ErrMsgs)) {
$this->ErrMsgs = $this->loadDefaultConfiguration($this->ErrMsgs);
}
# set up site
if (!count($this->ErrMsgs)) {
$this->ErrMsgs = $this->setUpNewSite($this->ErrMsgs);
}
# load plugins
if (!count($this->ErrMsgs)) {
$this->msg(1, "Loading plugins...");
$PluginMgr = PluginManager::getInstance();
$PluginMgr->loadPlugins();
}
}
# if errors encountered
if (count($this->ErrMsgs)) {
# display any error messages
$this->printErrorMessages($this->ErrMsgs);
# display pointer to helpful info
$this->printHelpPointers();
} else {
# queue new install or upgrade follow-up work as appropriate
$this->msg(1, "Queuing follow-up tasks...");
$this->queueFollowUpWork($IsUpgrade, $OldVersion);
# declare victory
$this->msg(1, "<b>".($IsUpgrade ? "Upgrade" : "Installation")
." Process Completed</b>");
# print install complete message
$this->printInstallCompleteInfo($IsUpgrade);
# set version
if ($IsUpgrade) {
if (file_exists("OLDVERSION")) {
unlink("OLDVERSION");
}
rename("VERSION", "OLDVERSION");
}
rename("NEWVERSION", "VERSION");
}
}
}
$this->endHtmlPage();
}
/**
* Message display and logging function for use during site upgrades.
* @param int $VerbLvl Minimum verbosity level required to display message.
* @param string $Message Message string.
*/
public function msg(int $VerbLvl, string $Message): void
{
if ($VerbLvl <= $this->VerbosityLevel) {
for ($Index = $VerbLvl; $Index > 1; $Index--) {
print(" ");
}
print($Message."<br />\n");
$this->logMsg($Message);
}
}
# ----- PRIVATE INTERFACE ----------------------------------------------------
private $ErrMsg;
private $ErrMsgs = [];
private $FVars;
private $NewVersion = "";
private $VerbosityLevel = 1;
/**
* Output the beginning HTML for all of our pages.
*/
private function beginHtmlPage(): void
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Metavus <?= $this->NewVersion ?> Installation</title>
<style type="text/css">
body {
background-color: #B3B3B3;
}
.MainTable {
margin: 5% 10% 10% 10%;
padding: 2em;
background-color: #FFFFFF;
border: 2px solid #999999;
}
.InfoTable {
width: 100%;
}
.InfoTable tr {
vertical-align: top;
}
.InfoTable th {
text-align: right;
white-space: nowrap;
}
.InstallInfoSummaryTable {
border: 1px solid #DDDDDD;
background-color: #EEEEEE;
padding: 15px;
}
.InstallInfoSummaryTable th {
text-align: right;
white-space: nowrap;
padding-right: 10px;
}
.TitleLine {
font-size: 1.5em;
font-weight: bold;
font-family: sans-serif;
}
.LogoMeta
{
color: #111111;
font-weight: bold;
font-family: verdana, arial, helvetica, sans-serif;
}
.LogoVus
{
color: #555555;
font-weight: bold;
font-family: verdana, arial, helvetica, sans-serif;
}
.ErrorList
{
color: red;
}
</style>
</head>
<body>
<table class="MainTable">
<tr><td colspan="2"><span class="TitleLine">Metavus <?=
$this->NewVersion ?> Installation</span></td><tr>
<tr><td colspan="2">
</td></tr>
<tr><td>
<?PHP
}
/**
* Output the ending HTML for all pages.
*/
private function endHtmlPage(): void
{
?>
</td></tr>
</table>
</body>
</html>
<?PHP
}
# ----- FORMS AND MESSAGES ---------------------------------------------------
/**
* Print form to gather installation info.
*/
private function printInstallInfoForm(): void
{
# set up default values
$Protocol = isset($_SERVER["HTTPS"]) ? "https://" : "http://";
$SiteUrl = $this->FVars["F_SiteUrl"]
?? $Protocol.$_SERVER["HTTP_HOST"].dirname($_SERVER["SCRIPT_NAME"])."/";
$DBHost = $this->FVars["F_DBHost"] ?? "localhost";
$DBLogin = $this->FVars["F_DBLogin"] ?? "";
$DBPassword = $this->FVars["F_DBPassword"] ?? "";
$DBName = $this->FVars["F_DBName"] ?? "";
$AdminLogin = $this->FVars["F_AdminLogin"] ?? "";
$AdminPassword = $this->FVars["F_AdminPassword"] ?? "";
$AdminEmail = $this->FVars["F_AdminEmail"] ?? "";
$AdminEmailAgain = $this->FVars["F_AdminEmailAgain"] ?? "";
# display form
?>
<form method="POST" action="installmv.php">
<?PHP
if (array_key_exists("NOCHKSUMS", $_GET)
|| array_key_exists("NOCHKSUMS", $_POST)) {
?><input type="hidden" name="NOCHKSUMS" value="1"><?PHP
}
?>
<table class="InfoTable">
<tr><td colspan="2">
Before beginning installation, we need to gather a few bits of
information to set up the software and allow it to access the SQL
database where the resource data will be stored. It is important
that this information be entered correctly, so please take the time
to read the notes accompanying each field to make sure you enter the
right values, and consult your system administrator if you're not sure.
</td></tr>
<tr><td> </td></tr>
<tr>
<th>Site URL:</th>
<td><input type="text" size="40" maxlength="120"
name="F_SiteUrl" value="<?PHP print($SiteUrl); ?>" /></td>
</tr>
<tr><td></td><td>
This is the URL (web address) where the software will be accessed.
</td></tr>
<tr><td> </td></tr>
<tr>
<th>Database Host:</th>
<td><input type="text" size="30" maxlength="60"
name="F_DBHost" value="<?PHP print($DBHost); ?>" /></td>
</tr>
<tr><td></td><td>
This is the name of the computer on which your SQL database server
is running. If your web server and your database server are running
on the same computer, then you should enter <i>localhost</i> here.
</td></tr>
<tr><td> </td></tr>
<tr>
<th>Database Login:</th>
<td><input type="text" size="15" maxlength="40"
name="F_DBLogin" value="<?PHP print($DBLogin); ?>" /></td>
</tr>
<tr>
<th>Database Password:</th>
<td><input type="text" size="15" maxlength="40"
name="F_DBPassword" value="<?PHP print($DBPassword); ?>" /></td>
</tr>
<tr><td></td><td>
This is the login name and password that you need to
connect to your database server. Please note that this is a
<b>database server</b> user name and password, which must have
already been set up by your database administrator, <b>not</b>
your Linux or OS X login name and password.<br />
<br />
Please Note: If the database named below does not already exist,
this database user account must have <i>CREATE</i> privileges.
If the database <b>does</b> exist, it must not already
contain tables or data.
</td></tr>
<tr><td> </td></tr>
<tr>
<th>Database Name:</th>
<td><input type="text" size="30" maxlength="60"
name="F_DBName" value="<?PHP print($DBName); ?>" /></td>
</tr>
<tr><td></td><td>
This is the name of the SQL database (the internal database name
that you yourself choose, like <i>PortalDB</i> or <i>OurDB</i>, not
the name of the database software package) that we will use to
store portal information.<br />
<br />
Please Note: If this database already exists, it must <b>not</b>
already contain tables or data.
</td></tr>
<tr><td> </td></tr>
<tr>
<th>Admin Login:</th>
<td><input type="text" size="15" maxlength="30"
name="F_AdminLogin" value="<?PHP print($AdminLogin); ?>" /></td>
</tr>
<tr>
<th>Admin Password:</th>
<td><input type="text" size="15" maxlength="30"
name="F_AdminPassword" value="<?PHP print($AdminPassword); ?>" /></td>
</tr>
<tr>
<th>Admin E-Mail:</th>
<td><input type="text" size="40" maxlength="120"
name="F_AdminEmail" value="<?PHP print($AdminEmail); ?>" /></td>
</tr>
<tr>
<th>Admin E-Mail:</th>
<td><input type="text" size="40" maxlength="120"
name="F_AdminEmailAgain" value="<?PHP print($AdminEmailAgain);
?>" /> <b>(again to confirm)</b></td>
</tr>
<tr><td></td><td>
This is the user name and password that you will initially use
to log into and configure your portal, and the e-mail address
where any administrative e-mail will be sent. The password must
be at least six characters long.
</tr>
<tr><td> </td></tr>
<tr><td></td><td>
<input type="submit" name="F_Submit" value="Begin Installation">
<span style="float: right; color: grey; font-size: 12px;">
Verbosity: <input type="checkbox" name="F_Debug" <?PHP
if (isset($this->FVars["F_Debug"])) {
print("checked");
}
?>><input type="checkbox" name="F_MoreDebug" <?PHP
if (isset($this->FVars["F_MoreDebug"])) {
print("checked");
}
?>><input type="checkbox" name="F_EvenMoreDebug" <?PHP
if (isset($this->FVars["F_EvenMoreDebug"])) {
print("checked");
}
?>></span>
</tr>
</table>
</form>
<?PHP
}
/**
* Print list of error messages.
* @param array $ErrMsgs Error messages to print.
*/
private function printErrorMessages(array $ErrMsgs): void
{
if (count($ErrMsgs)) {
?><b>Errors Encountered:</b>
<ul class="ErrorList"><?PHP
foreach ($ErrMsgs as $Msg) {
?><li><?= $Msg ?></li><?PHP
$this->logMsg("ERROR: ".$Msg);
}
?></ul><?PHP
}
}
/**
* Print summary of installation info.
* @param bool $IsUpgrade TRUE if upgrade, or FALSE if new install.
*/
private function printInstallInfoSummary(bool $IsUpgrade): void
{
?>
<table class="InstallInfoSummaryTable" width="100%">
<tr><th>Site Base URL:</th>
<td><i><?PHP print($this->FVars["F_SiteUrl"]); ?></i></td></tr>
<tr><th>Database Host:</th>
<td><i><?PHP print($this->FVars["F_DBHost"]); ?></i></td></tr>
<tr><th>Database Login:</th>
<td><i><?PHP print($this->FVars["F_DBLogin"]); ?></i></td></tr>
<tr><th>Database Name:</th>
<td><i><?PHP print($this->FVars["F_DBName"]); ?></i></td></tr>
<?PHP
if (!$IsUpgrade) {
?>
<tr><th>Admin Login:</th>
<td><i><?PHP print($this->FVars["F_AdminLogin"]); ?></i></td></tr>
<tr><th>Admin E-Mail:</th>
<td><i><?PHP print($this->FVars["F_AdminEmail"]); ?></i></td></tr>
<?PHP
}
?>
</table>
<br />
<?PHP
}
/**
* Print info about installation being completed.
* @param bool $IsUpgrade TRUE if upgrade, or FALSE if new install.
*/
private function printInstallCompleteInfo(bool $IsUpgrade): void
{
?>
<br />
<?PHP
if ($IsUpgrade) {
?>
You may now proceed to your <a href="<?PHP print($this->FVars["F_SiteUrl"]);
?>index.php" target="_blank">upgraded Metavus site</a>.<br />
<?PHP
if ($this->FVars["F_DefaultUI"] == "SPTUI--Default") {
?>
<br />
<b>PLEASE NOTE:</b> It appears that you have upgraded from SPT to Metavus.
If some pages on your site appear to load incorrectly, you may
need to edit the file <code>local/config.php</code> and change the
value of <code>$GLOBALS["G_Config"]["UserInterface"]["DefaultUI"]</code>
to <code>"default"</code>.<br />
<?PHP
}
} else {
?>
You may now proceed to your <a href="<?PHP print($this->FVars["F_SiteUrl"]);
?>index.php">new Metavus site</a> and log in with the user name <i><?PHP
print($this->FVars["F_AdminLogin"]); ?></i> and the password
you supplied.<br />
<?PHP
}
?>
<br />
Thank you for using <span class="LogoMeta">Meta</span><span class="LogoVus">vus</span>!
<?PHP
}
/**
* Print helpful info about what to do about problems encountered.
*/
private function printHelpPointers(): void
{
?>
<br />
Please correct these problems and re-run the installation.<br />
<?PHP
}
# ----- VALIDATION CHECKS ----------------------------------------------------
/**
* Check to make sure our environment will support the software. Any issues
* discovered are recorded via messages added to $this->ErrMsgs.
*/
private function checkEnvironment(): void
{
# check PHP version
if (version_compare(PHP_VERSION, Installer::MINIMUM_PHP_VERSION) == -1) {
$this->ErrMsgs[] = "Required PHP version not found."
." Metavus ".$this->NewVersion." requires PHP version "
.Installer::MINIMUM_PHP_VERSION." or later."
."<br />PHP version <i>".PHP_VERSION
."</i> was detected.";
}
# check for required extensions
foreach ($this->RequiredExtensions as $Ext) {
if (!extension_loaded($Ext)) {
$this->ErrMsgs[] =
"The '".$Ext."' extension is not loaded or is not enabled. "
."Some Linux distributions split this extension off into a "
."separate package, often with a name like 'php81-".$Ext."'.";
}
}
# check to make sure directories are writable
$Cwd = getcwd();
$DirMode = 0755;
foreach ($this->DirsThatMustBeWritable as $Dir) {
# the directory must have a forward slash in the beginning since the
# directory from getcwd() will not have a trailing slash
$Dir = ($Dir[0] != "/") ? "/".$Dir : $Dir;
$Dir = $Cwd.$Dir;
if (!is_dir($Dir)) {
@mkdir($Dir, $DirMode);
if (!is_dir($Dir)) {
$this->ErrMsgs[] = "Directory <i>".$Dir."</i> could not be created.";
}
}
if (is_dir($Dir) && !is_writable($Dir)) {
@chmod($Dir, $DirMode);
if (is_writable($Dir) !== true) { /* @phpstan-ignore notIdentical.alwaysTrue */
$this->ErrMsgs[] = "Directory <i>".$Dir."</i> is not writable.";
}
}
}
}
/**
* Check supplied installation info for validity. Any issues
* discovered are recorded via messages added to $this->ErrMsgs.
*/
private function checkInstallInfo(): void
{
$this->checkDBInfo();
if ($this->FVars["F_Submit"] != "Upgrade Installation") {
$this->checkAdminInfo();
}
}
/**
* Check supplied database info for validity. Any issues
* discovered are recorded via messages added to $this->ErrMsgs.
*/
private function checkDBInfo(): void
{
# check MySQL availability and version and that we can create tables in DB
if (!strlen(trim($this->FVars["F_DBHost"]))
|| !strlen(trim($this->FVars["F_DBLogin"]))
|| !strlen(trim($this->FVars["F_DBPassword"]))) {
if (!strlen(trim($this->FVars["F_DBHost"]))) {
$this->ErrMsgs["F_DBHost"] = "No database host was supplied.";
}
if (!strlen(trim($this->FVars["F_DBLogin"]))) {
$this->ErrMsgs["F_DBLogin"] = "No database login was supplied.";
}
if (!strlen(trim($this->FVars["F_DBPassword"]))) {
$this->ErrMsgs["F_DBPassword"] = "No database password was supplied.";
}
return;
}
require_once("lib/ScoutLib/StdLib.php");
require_once("lib/ScoutLib/Database.php");
$Result = Database::connectionInfoIsValid(
$this->FVars["F_DBHost"],
$this->FVars["F_DBLogin"],
$this->FVars["F_DBPassword"]
);
if (!$Result) {
$this->ErrMsgs[] = "Could not connect to database on "
.$this->FVars["F_DBHost"].".";
return;
}
Database::setGlobalServerInfo(
$this->FVars["F_DBLogin"],
$this->FVars["F_DBPassword"],
$this->FVars["F_DBHost"]
);
$MysqlVersion = Database::getServerVersion();
if (version_compare($MysqlVersion, Installer::MINIMUM_MYSQL_VERSION) == -1) {
$this->ErrMsgs[] = "Required MySQL version not found."
." Metavus ".$this->NewVersion." requires MySQL version "
.Installer::MINIMUM_MYSQL_VERSION." or later."
."<br />MySQL version <i>".$MysqlVersion."</i> was detected.";
return;
}
if (!strlen(trim($this->FVars["F_DBName"]))) {
$this->ErrMsgs["F_DBName"] = "No database name was supplied.";
return;
}
if (!Database::databaseExists($this->FVars["F_DBName"])) {
if (!Database::createDatabase($this->FVars["F_DBName"])) {
$this->ErrMsgs["F_DBName"] = "Could not create database.";
return;
}
Database::dropDatabase($this->FVars["F_DBName"]);
}
}
/**
* Check supplied administrativer user info for validity. Any issues
* discovered are recorded via messages added to $this->ErrMsgs.
*/
private function checkAdminInfo(): void
{
if (!strlen(trim($this->FVars["F_AdminLogin"]))) {
$this->ErrMsgs["F_AdminLogin"] = "No administrative account login was supplied.";
}
if (!strlen(trim($this->FVars["F_AdminPassword"]))) {
$this->ErrMsgs["F_AdminPassword"] =
"No administrative account password was supplied.";
}
if (strlen(trim($this->FVars["F_AdminPassword"]))
< self::MINIMUM_PASSWORD_LENGTH) {
$this->ErrMsgs["F_AdminPassword"] =
"Administrative password supplied was too short."
." Password must be at least ".self::MINIMUM_PASSWORD_LENGTH
." characters long.";
}
$AdminEmail = trim($this->FVars["F_AdminEmail"]);
if (!strlen($AdminEmail)) {
$this->ErrMsgs["F_AdminEmail"] =
"No administrative account e-mail address was supplied.";
} elseif (filter_var($AdminEmail, FILTER_VALIDATE_EMAIL) === false) {
$this->ErrMsgs["F_AdminEmail"] =
"An invalid administrative account e-mail address was supplied.";
} elseif (trim($this->FVars["F_AdminEmailAgain"]) != $AdminEmail) {
$this->ErrMsgs["F_AdminEmailAgain"] =
"The two administrative account e-mail addresses did not match.";
}
}
/**
* Check integrity of distribution files using checksums. Any errors
* encountered are recorded in $this->ErrMsgs.
* @param string $NewVersion Version we are installing or upgrading to.
*/
private function checkDistributionFiles(string $NewVersion): void
{
# error out if checksum file not found
if (!file_exists("install/CHECKSUMS")) {
$this->ErrMsgs[] = "Checksum file <i>install/CHECKSUMS</i> not found.";
return;
}
# load in MD5 checksums
$ErrorCount = 0;
$Lines = file("install/CHECKSUMS", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if ($Lines === false) {
$this->ErrMsgs[] = "Checksum file <i>install/CHECKSUMS</i> not readable.";
return;
}
$Checksums = array();
foreach ($Lines as $Line) {
$Pieces = preg_split("/\s+/", $Line, 2);
if ($Pieces === false) {
$this->ErrMsgs[] = "Unable to parse CHECKSUMS file line \"".$Line."\".";
$ErrorCount++;
continue;
}
$Checksums[$Pieces[1]] = $Pieces[0];
}
# for each checksum
foreach ($Checksums as $FileName => $Chksum) {
# if file exists
if (file_exists($FileName)) {
# generate checksum for file
$CalcChksum = md5_file($FileName);
# if distribution file is missing
if ($CalcChksum === false) {
# record error message about checksum error
$this->ErrMsgs[] = "Could not read Metavus ".$NewVersion
." distribution file <i>".$FileName."</i>.";
$ErrorCount++;
# else if checksums do not match
} elseif (strtolower($CalcChksum) != strtolower($Chksum)) {
# record error message about checksum error
$this->ErrMsgs[] = "Checksum does not match for Metavus ".$NewVersion
." distribution file <i>".$FileName."</i>.";
$ErrorCount++;
}
} else {
# record error message about missing file
$this->ErrMsgs[] = "Distribution file <i>".$FileName."</i> not found.";
$ErrorCount++;
}
# quit if too many errors encountered
if ($ErrorCount > 20) {
$this->ErrMsgs[] = "More than 20 errors encountered when checking"
." distribution file integrity. If files were uploaded"
." to the web server via FTP, please make sure they"
." were transferred using \"Binary\" mode, rather than"
." \"ASCII\" or \"Automatic\" mode.";
break;
}
}
}
# ----- INSTALLATION ---------------------------------------------------------
/**
* Install config, htaccess, and robots.txt files, and move aside any
* obsolete files that are found.
* @param bool $IsUpgrade TRUE if upgrade, or FALSE if new install.
* @return array Any error messages.
*/
private function installFiles(bool $IsUpgrade): array
{
# set up config file with DB info if not present
$ErrMsgs = [];
if (!file_exists("local/config.php") && !file_exists("config.php")) {
$this->msg(1, "Creating configuration file...");
$ConfigReplacements = array(
"X-DBUSER-X" => addslashes($this->FVars["F_DBLogin"]),
"X-DBPASSWORD-X" => addslashes($this->FVars["F_DBPassword"]),
"X-DBHOST-X" => addslashes($this->FVars["F_DBHost"]),
"X-DBNAME-X" => addslashes($this->FVars["F_DBName"]),
);
$ErrMsg = $this->copyFile(
"install/config.php.DIST",
"local/config.php",
$ConfigReplacements
);
if ($ErrMsg) {
$ErrMsgs[] = $ErrMsg;
}
}
# if there is no top-level .htaccess file
if (!file_exists(".htaccess")) {
# set up .htaccess file
$this->msg(1, "Creating .htaccess file...");
$ErrMsg = $this->installHtaccess(".htaccess");
if ($ErrMsg) {
$ErrMsgs[] = $ErrMsg;
}
} else {
# if .htaccess file appears to be from a previous Metavus release
$OldChecksums = $this->getFileChecksums("install/htaccess.CHECKSUMS");
$Lines = file(".htaccess");
if ($Lines === false) {
throw new Exception("Unable to read htaccess file.");
}
$Content = "";
foreach ($Lines as $Line) {
if (!preg_match("/^RewriteBase/", $Line)) {
$Content .= $Line;
}
}
$Checksum = md5($Content);
$this->msg(3, "Checksum for current .htaccess file: ".$Checksum);
if (in_array($Checksum, $OldChecksums)) {
# replace .htaccess file
$this->msg(1, "Replacing .htaccess file...");
$ErrMsg = $this->installHtaccess(".htaccess");
if ($ErrMsg) {
$ErrMsgs [] = $ErrMsg;
}
} else {
# create .htaccess template file
$this->msg(1, "Creating .htaccess template file...");
$ErrMsg = $this->installHtaccess(".htaccess.Metavus");
if ($ErrMsg) {
$ErrMsgs [] = $ErrMsg;