-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathParaFunc.php
executable file
·5179 lines (4320 loc) · 193 KB
/
ParaFunc.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
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
/*
ParaTracker is released under the MIT license, which reads thus:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
function trackerName()
{
//If you modify this project, please change this value to something of your own, as a courtesy to your users and ours
return "ParaTracker";
}
function trackerVersion()
{
//Return the version number
return 1.5;
}
function versionNumber()
{
//I know this function's name is cryptic, but it existed long before trackerName() and trackerVersion() and I'm not changing all the rest of the code to match...
return(trackerName() . " " . strval(trackerVersion()));
}
define('webServerName', getWebServerName());
//Define the default skin, to be used throughout this file.
//This variable must reference an actual .css file in the skins folder, or it will break stuff. Do not include the file path or extension!
//"JSON" is also a valid value.
//Default value is "Metallic Console"
$defaultSkin = "Metallic Console";
if (!isset($safeToExecuteParaFunc))
{
displayError("ParaFunc.php is a library file and can not be run directly!<br />Try running ParaTrackerStatic.php or ParaTrackerDynamic.php instead.", time(), "");
exit();
}
//Now that validation is complete, declare this value
if(!isset($analyticsBackground))
{
$analyticsBackground = 0;
}
define("analyticsBackground", $analyticsBackground);
//If we are running from within analytics, the client address will not exist. Let's give the error log something useful
if(analyticsBackground)
{
define("clientAddress", "Analytics");
}
else
{
define("clientAddress", $_SERVER['REMOTE_ADDR']);
}
//This block is here to suppress error messages
$trackerTagline = "";
$fileExtList = array();
$dynamicIPAddressPath = "";
$serverIPAddress = "";
$serverPort = "";
$personalDynamicTrackerMessage = "";
$floodProtectTimeout = "";
$loginFloodProtect = 5;
$executeDynamicInstructionsPage = "0";
$backgroundColor = "";
$backgroundOpacity = "100";
$textColor = "";
$playerListColor1 = "";
$playerListColor1Opacity = "100";
$playerListColor2 = "";
$playerListColor2Opacity = "100";
$scrollShaftColor = "";
$scrollThumbColor = "";
$scrollShaftOpacity = "100";
$customFont = "";
$customSkin = "";
$geoipCountryCode = "";
$paraTrackerSkin = "";
$displayGameName = "";
$pgUser = "";
$pgPass = "";
$pgName = "";
$pgHost = "";
$pgPort = "";
$enablePGSQL = "0";
$webServerDomain = "";
$emailEnabled = "";
$useSMTP = "";
$smtpAddress = "";
$smtpPort = "";
$SMTPSecure = true;
$smtpUsername = "";
$smtpPassword = "";
$emailFromAddress = "";
$serverToolsAllowEmailAdministrators = "";
$emailAdministrators = array();
$emailAdminReports = "";
$cleanupInterval = "";
$deleteInterval = "";
$loadLimit = "";
$cleanupLogSize = "";
$errorLogSize = "";
$mapreqEnabled = "";
$analyticsEnabled = "";
$analyticsFrontEndEnabled = "";
$mapreqTextMessage = "";
$cullDatabase = 0;
$databaseCullTime = 0;
$connectionAttempts = 2;
$enableCustomDefaultLevelshots = 0;
$customDefaultLevelshot = "";
//For safety, these MUST be forced to an initial value!
$logPath = "logs";
$infoPath = "info";
$skinsPath = "skins";
$utilitiesPath = "utilities";
//Declare these too
$serverSettingsFilename = "serverSettings.php";
$serverSecurityLogFilename = "SecurityLog.php";
//The default skin must be defined here, before skin validation takes place
define("defaultSkin", $defaultSkin);
//If this file is executed directly, then echoing this value here will display the version number before exiting.
//Either way, the version number will be visible.
echo "<!-- " . versionNumber() . " ";
if (file_exists("ParaConfig.php"))
{
include_once 'ParaConfig.php';
}
else
{
writeNewConfigFile();
//This must be called before calling file_exists!
clearstatcache();
if (file_exists("ParaConfig.php"))
{
echo "<!-- --><h3>ParaConfig.php not found! A default config file has been written to disk.<br />Please add an IP Address and port to it.</h3>";
exit();
}
}
// Make sure this is an array so things don't bug out later...
if(!is_array($emailAdministrators)) {
$emailAdministrators = array($emailAdministrators);
}
define("emailAdministrators", $emailAdministrators);
if(file_exists("GameInfo.php"))
{
$safeToExecuteGameInfo = "1";
include("GameInfo.php");
}
else
{
displayError( "GameInfo.php not found!", "", "");
exit();
}
//Validate the log stuff so it can be used later
$logPath = trim($logPath, '/') . '/';
$infoPath = trim($infoPath, '/') . '/';
$skinsPath = trim($skinsPath, '/') . '/';
$utilitiesPath = trim($utilitiesPath, '/') . '/';
$serverSettingsFilename = trim($serverSettingsFilename);
$serverSecurityLogFilename = trim($serverSecurityLogFilename);
define("logPath", $logPath);
define("infoPath", $infoPath);
define("skinsPath", $skinsPath);
define("utilitiesPath", $utilitiesPath);
define("serverSettingsFilename" , $serverSettingsFilename);
define("serverSecurityLogFilename" , $serverSecurityLogFilename);
//This is an array of log file names that are permitted to be displayed.
$permittedLogFiles = array("cleanupLog.php", "errorLog.php", serverSecurityLogFilename);
define("permittedLogFiles", $permittedLogFiles);
$errorLogSize = numericValidator($errorLogSize, 100, 100000, 10000);
define("errorLogSize", $errorLogSize);
//These IF statements will avoid warning messages during validation
if(!isset($dynamicTrackerCalledFromCorrectFile))
{
$dynamicTrackerCalledFromCorrectFile = "0";
}
if(!isset($calledFromRCon))
{
$calledFromRCon = "0";
}
if(!isset($calledFromParam))
{
$calledFromParam = "0";
}
if(!isset($calledFromElsewhere))
{
$calledFromElsewhere = "0";
}
if(!isset($calledFromAnalytics))
{
$calledFromAnalytics = "0";
}
/*
Before we go any further, let's validate ALL input from the config file!
To validate booleans:
$variableName = booleanValidator($variableName, defaultValue);
To evaluate numeric values:
$variableName = numericValidator($variableName, minValue, maxValue, defaultValue);
To evaluate strings:
$variableName = stringValidator($variableName, maxLength, defaultValue);
To check a value for null:
$variableName = basicValidator($variableName, defaultValue);
*/
//These values MUST be evaluated first, because they are used in the IP address validation.
//All ParaTracker files call this same file, so we need to be sure which file is calling,
//and what to do about it.
$dynamicTrackerCalledFromCorrectFile = booleanValidator($dynamicTrackerCalledFromCorrectFile, 0);
$dynamicTrackerEnabled = booleanValidator($dynamicTrackerEnabled, 0);
if($dynamicTrackerEnabled == "1")
{
$serverToolsEnabled = booleanValidator($serverToolsEnabled, 1);
}
else
{
$serverToolsEnabled = 0;
}
define("dynamicTrackerEnabled", $dynamicTrackerEnabled);
define("serverToolsEnabled", $serverToolsEnabled);
$enablePGSQL = booleanValidator($enablePGSQL, 0);
if ($enablePGSQL == "1")
{
if (!extension_loaded('pgsql'))
{
echo ' pgsql extension not enabled in php.ini ';
$enablePGSQL = 0;
}
}
define("enablePGSQL", $enablePGSQL);
$analyticsEnabled = booleanValidator($analyticsEnabled, 0);
if(enablePGSQL == "0")
{
$analyticsEnabled = "0";
}
define("analyticsEnabled", $analyticsEnabled);
if(analyticsEnabled == 0)
{
$analyticsFrontEndEnabled = 0;
}
else
{
$analyticsFrontEndEnabled = booleanValidator($analyticsFrontEndEnabled, 1);
}
define("analyticsFrontEndEnabled", $analyticsFrontEndEnabled);
if($dynamicTrackerCalledFromCorrectFile == "1" && $calledFromAnalytics == "0")
{
if(dynamicTrackerEnabled == "1")
{
if(isset($_GET["ip"]))
{
$serverIPAddress = $_GET["ip"];
}
else
{
//Terminate the script with an instruction page if no IP address was given!
$executeDynamicInstructionsPage = "1";
}
}
else
{
displayError(trackerName() . ' Dynamic mode is disabled! Dynamic mode must be enabled in ParaConfig.php.', "", "");
exit();
}
if($executeDynamicInstructionsPage == "0")
{
if(isset($_GET["port"]))
{
$serverPort = $_GET["port"];
}
}
}
else
{
//Was this file caled from RCon.php? If so, we can't execute the instructions page.
if(dynamicTrackerEnabled == "1" && $calledFromRCon == "1")
{
//We were called from RCon.php, we are running in dynamic mode, and no IP address was given.
if(isset($_GET["ip"]))
{
$serverIPAddress = $_GET["ip"];
}
else
{
if(!isset($serverIPAddress))
{
displayError("Cannot use RCon without an IP address!", "", "");
}
}
if(isset($_GET["port"]))
{
$serverPort = $_GET["port"];
}
}
elseif($calledFromAnalytics == "1")
{
if(analyticsEnabled != "1")
{
displayError("Analytics is disabled!<br>Analytics must be enabled in ParaConfig.php!", "", "");
exit();
}
//We were called from analytics. Get the IP and port.
if(isset($_GET["ip"]))
{
$serverIPAddress = $_GET["ip"];
}
if(isset($_GET["port"]))
{
$serverPort = $_GET["port"];
}
}
}
//Before initializing, let's validate the database stuff
$pgUser = basicValidator($pgUser, "postgres");
$pgPass = basicValidator($pgPass, "");
$pgName = basicValidator($pgName, strtolower(trackerName()));
$pgHost = basicValidator($pgHost, "localhost");
$pgPort = basicValidator($pgPort, "");
define("pgUser", $pgUser);
define("pgPass", $pgPass);
define("pgName", $pgName);
define("pgHost", $pgHost);
define("pgPort", $pgPort);
$pgCon = null;
$admin = false;
$adminUser = "";
$temp = ipAndPortValidator($serverIPAddress, $serverPort, dynamicTrackerEnabled);
$serverIPAddress = "$temp[0]";
$serverPort = $temp[1];
if($executeDynamicInstructionsPage == "0" && $calledFromAnalytics == "0" && $calledFromElsewhere == "0")
{
$paraTrackerSkin = skinValidator($paraTrackerSkin, $customSkin);
}
else
{
//This line prevents a skin file from being mistakenly applied to the dynamic instructions page or the analytics page.
$paraTrackerSkin = "";
}
if (enablePGSQL)
{
global $pgCon;
$connectString = 'host=' . pgHost . ' dbname=' . pgName . ' user=' . pgUser;
if (!empty(pgPass)) $connectString .= " password=" . pgPass;
if (!empty(pgPort)) $connectString .= " port=" . pgPort;
$pgCon = pg_connect($connectString);
if (!$pgCon)
{
displayError("Could not establish database connection", time(), "");
exit();
}
pg_query($pgCon, 'CREATE SCHEMA IF NOT EXISTS account')
or displayError('could not create account schema', time(), "");
pg_query($pgCon, 'CREATE TABLE IF NOT EXISTS account.user (id BIGSERIAL PRIMARY KEY, username VARCHAR(64) UNIQUE NOT NULL, email TEXT UNIQUE, passhash VARCHAR(128) NOT NULL, salt VARCHAR(16) NOT NULL)')
or displayError('could not create account.user table', time(), "");
pg_query($pgCon, 'CREATE TABLE IF NOT EXISTS account.session (user_id BIGSERIAL PRIMARY KEY REFERENCES account.user (id) ON UPDATE CASCADE ON DELETE CASCADE, token VARCHAR(64) NOT NULL, expires TIMESTAMP NOT NULL)')
or displayError('could not create account.session table', time(), "");
pg_query($pgCon, 'CREATE TABLE IF NOT EXISTS mapreq (
id BIGSERIAL PRIMARY KEY,
game_name VARCHAR(128) NOT NULL CHECK (game_name <> \'\'),
bsp_name VARCHAR(128) NOT NULL CHECK (bsp_name <> \'\'),
dl_link TEXT CHECK (dl_link <> \'\'),
entry_date TIMESTAMP DEFAULT NOW(),
email TEXT,
useradded BOOL NOT NULL DEFAULT false,
UNIQUE(game_name, bsp_name)
)
') or displayError('could not create map request (mapreq) table', time(), "");
pg_query($pgCon, 'CREATE SCHEMA IF NOT EXISTS tracker')
or displayError('could not create tracker schema', time(), "");
pg_query($pgCon, 'CREATE TABLE IF NOT EXISTS tracker.server (
id BIGSERIAL PRIMARY KEY,
location VARCHAR(128) NOT NULL,
port INT NOT NULL CHECK (port > 0 AND port < 65536),
active BOOL NOT NULL DEFAULT TRUE,
UNIQUE( location, port )
)
') or displayError('could not create server (tracker.server) table', time(), "");
pg_query($pgCon, 'CREATE TABLE IF NOT EXISTS tracker.cpuload (
entrydate TIMESTAMP PRIMARY KEY DEFAULT NOW(),
load REAL NOT NULL
)
') or displayError('could not create server (tracker.cpuload) table', time(), "");
pg_query($pgCon, 'CREATE TABLE IF NOT EXISTS tracker.displayerror (
entrydate TIMESTAMP PRIMARY KEY DEFAULT NOW()
)
') or displayError('could not create server (tracker.displayerror) table', time(), "");
pg_query($pgCon, 'CREATE SCHEMA IF NOT EXISTS analytics')
or displayError('could not create analytics schema', time(), "");
/* gamename */
pg_query($pgCon, 'CREATE TABLE IF NOT EXISTS analytics.gamename (
id BIGSERIAL PRIMARY KEY,
name VARCHAR(256) NOT NULL UNIQUE CHECK (name <> \'\')
)
') or displayError('could not create gamename (analytics.gamename) table', time(), "");
/* hostname */
pg_query($pgCon, 'CREATE TABLE IF NOT EXISTS analytics.hostname (
id BIGSERIAL PRIMARY KEY,
name VARCHAR(256) NOT NULL UNIQUE CHECK (name <> \'\')
)
') or displayError('could not create hostname (analytics.hostname) table', time(), "");
/* mapname */
pg_query($pgCon, 'CREATE TABLE IF NOT EXISTS analytics.mapname (
id BIGSERIAL PRIMARY KEY,
name VARCHAR(256) NOT NULL UNIQUE CHECK (name <> \'\')
)
') or displayError('could not create mapname (analytics.mapname) table', time(), "");
/* modname */
pg_query($pgCon, 'CREATE TABLE IF NOT EXISTS analytics.modname (
id BIGSERIAL PRIMARY KEY,
name VARCHAR(256) NOT NULL UNIQUE CHECK (name <> \'\')
)
') or displayError('could not create modname (analytics.modname) table', time(), "");
/* gametype */
pg_query($pgCon, 'CREATE TABLE IF NOT EXISTS analytics.gametype (
id BIGSERIAL PRIMARY KEY,
name VARCHAR(256) NOT NULL UNIQUE CHECK (name <> \'\')
)
') or displayError('could not create gametype (analytics.gametype) table', time(), "");
/* server record */
pg_query($pgCon, 'CREATE TABLE IF NOT EXISTS analytics.record (
id BIGSERIAL PRIMARY KEY,
gamename_id BIGINT NOT NULL REFERENCES analytics.gamename (id) ON UPDATE CASCADE ON DELETE CASCADE,
hostname_id BIGINT NOT NULL REFERENCES analytics.hostname (id) ON UPDATE CASCADE ON DELETE CASCADE,
mapname_id BIGINT NOT NULL REFERENCES analytics.mapname (id) ON UPDATE CASCADE ON DELETE CASCADE,
modname_id BIGINT NOT NULL REFERENCES analytics.modname (id) ON UPDATE CASCADE ON DELETE CASCADE,
gametype_id BIGINT NOT NULL REFERENCES analytics.gametype (id) ON UPDATE CASCADE ON DELETE CASCADE,
player_count INT NOT NULL
)
') or displayError('could not create gamename record (analytics.record) table', time(), "");
/* frame */
pg_query($pgCon, 'CREATE TABLE IF NOT EXISTS analytics.frame (
id BIGSERIAL PRIMARY KEY,
server_id BIGINT NOT NULL REFERENCES tracker.server (id) ON UPDATE CASCADE ON DELETE CASCADE,
entrydate TIMESTAMP NOT NULL DEFAULT NOW(),
record_id BIGINT REFERENCES analytics.record (id) ON UPDATE CASCADE ON DELETE CASCADE
)
') or displayError('could not create uptime (analytics.frame) table', time(), "");
pg_query($pgCon, 'CREATE TABLE IF NOT EXISTS analytics.runtimes (
startdate TIMESTAMP PRIMARY KEY,
enddate TIMESTAMP NOT NULL DEFAULT NOW()
)
') or displayError('could not create uptime (analytics.runtimes) table', time(), "");
$admin = adminCheck();
}
if($dynamicTrackerCalledFromCorrectFile == "1" || $calledFromParam == "1" || $calledFromRCon == "1")
{
//We are running in Dynamic mode.
//Check to see if a skin file was specified in the URL.
if(isset($_GET["skin"]))
{
//A skin was specified - load it in.
$paraTrackerSkin = rawurldecode($_GET["skin"]);
if(trim(strtolower($paraTrackerSkin)) == "custom" && isset($_GET["customSkin"]))
{
//A custom skin was specified - load it in as well.
$customSkin = rawurldecode($_GET["customSkin"]);
$customSkin = skinValidator($paraTrackerSkin, $customSkin);
}
else
{
$paraTrackerSkin = skinValidator($paraTrackerSkin, "");
}
}
}
$connectionTimeout = numericValidator($connectionTimeout, 1, 15, 2);
$trackerTagline = stringValidator($trackerTagline, "", "");
//Have to validate this one twice to make sure it isn't lower than connectionTimeout
$floodProtectTimeout = numericValidator($floodProtectTimeout, 2, 60, 5);
$floodProtectTimeout = numericValidator($floodProtectTimeout, $connectionTimeout, 1200, $floodProtectTimeout);
$loginFloodProtect = numericValidator($loginFloodProtect, 2, 15, 5);
$connectionAttempts = numericValidator($connectionAttempts, 1, 10, 2);
$refreshTimeout = numericValidator($refreshTimeout, 1, 15, 3);
$backgroundColor = colorValidator($backgroundColor);
$backgroundOpacity = numericValidator($backgroundOpacity, 0, 100, 100);
$playerListColor1 = colorValidator($playerListColor1);
$playerListColor1Opacity = numericValidator($playerListColor1Opacity, 0, 100, 100);
$playerListColor2 = colorValidator($playerListColor2);
$playerListColor2Opacity = numericValidator($playerListColor2Opacity, 0, 100, 100);
$scrollShaftColor = colorValidator($scrollShaftColor);
$scrollThumbColor = colorValidator($scrollThumbColor);
//$scrollShaftOpacity = numericValidator($scrollShaftOpacity, 0, 100, 100);
$textColor = colorValidator($textColor);
$customFont = stringValidator($customFont, "50", "");
$levelshotTransitionsEnabled = booleanValidator($levelshotTransitionsEnabled, 1);
$levelshotDisplayTime = numericValidator($levelshotDisplayTime, 1, 15, 3);
$levelshotTransitionTime = numericValidator($levelshotTransitionTime, 0.1, 5, 1);
$levelshotTransitionAnimation = numericValidator($levelshotTransitionAnimation, 0, 32767, 3);
$maximumLevelshots = numericValidator($maximumLevelshots, 1, 99, 20);
$displayGameName = booleanValidator($displayGameName, 1);
$filterOffendingServerNameSymbols = booleanValidator($filterOffendingServerNameSymbols, 1);
$noPlayersOnlineMessage = stringValidator($noPlayersOnlineMessage, "", "No players online.");
$enableAutoRefresh = booleanValidator($enableAutoRefresh, 1);
//Have to validate this one twice to make sure it isn't lower than the floodprotect limit
$autoRefreshTimer = numericValidator($autoRefreshTimer, 10, 300, 30);
$autoRefreshTimer = intval(numericValidator($autoRefreshTimer, $floodProtectTimeout, 300, $autoRefreshTimer));
$maximumServerInfoSize = numericValidator($maximumServerInfoSize, 2000, 50000, 16384);
$RConEnable = booleanValidator($RConEnable, 0);
$RConMaximumMessageSize = numericValidator($RConMaximumMessageSize, 20, 10000, 200);
$RConFloodProtect = numericValidator($RConFloodProtect, 5, 20, 10);
//Have to validate this one twice to make sure it isn't lower than connectionTimeout
$RConFloodProtect = numericValidator($RConFloodProtect, $connectionTimeout, 3600, 20);
$SecurityLogSize = numericValidator($SecurityLogSize, 100, 100000, 2000);
$cleanupInterval = numericValidator($cleanupInterval, 10, 3600, 60);
$deleteInterval = numericValidator($deleteInterval, 1, 30, 7);
//Need to make sure deleteInterval is greater than cleanupInterval.
//cleanupInterval is given in minutes, and deleteInterval is given in days, so divide by 1440.
$deleteInterval = numericValidator($deleteInterval, $cleanupInterval / 1440, 30, 7);
define('deleteInterval', $deleteInterval);
$loadLimit = numericValidator($loadLimit, 50, 100, 90);
$cleanupLogSize = numericValidator($cleanupLogSize, 100, 100000, 10000);
$mapreqEnabled = booleanValidator($mapreqEnabled, 0);
$cullDatabase = booleanValidator($cullDatabase, 0);
//If analytics is disabled, cullDatabase must also be disabled
if($analyticsEnabled != 1)
{
$cullDatabase = 0;
}
$databaseCullTime = numericValidator($databaseCullTime, 90, 2000, 370);
if(enablePGSQL == 0 || !file_exists(utilitiesPath . 'MapReq.php') || dynamicTrackerEnabled == '0')
{
$mapreqEnabled = "0";
}
define("mapreqEnabled", $mapreqEnabled);
//The IP address has already been validated, so we can use it for a directory name
//Make sure we convert the path to lowercase when creating folders for it, or else the flood protection could be bypassed!
if($executeDynamicInstructionsPage == "1")
{
$dynamicIPAddressPath = "";
}
else
{
$dynamicIPAddressPath = makeDynamicAddressPath($serverIPAddress, $serverPort);
}
$enableGeoIP = booleanValidator($enableGeoIP, 0);
//If we are running in dynamic mode and we are not running the setup page, let's check for override values on a few more settings.
if($dynamicTrackerCalledFromCorrectFile == "1" && $executeDynamicInstructionsPage != "1")
{
//If the config file has disabled levelshot transitions, we must abide by it. Otherwise, override it.
if(isset($_GET["levelshotsEnabled"]) && $levelshotTransitionsEnabled == "1")
{
$levelshotTransitionsEnabled = booleanValidator($_GET["levelshotsEnabled"], 1);
}
if(isset($_GET["levelshotTransitionAnimation"]))
{
$levelshotTransitionAnimation = numericValidator($_GET["levelshotTransitionAnimation"], 0, 32767, 3);
}
if(isset($_GET["levelshotDisplayTime"]))
{
$levelshotDisplayTime = numericValidator($_GET["levelshotDisplayTime"], 1, 15, $levelshotDisplayTime);
}
if(isset($_GET["levelshotTransitionTime"]))
{
$levelshotTransitionTime = numericValidator($_GET["levelshotTransitionTime"], 0.1, 5, $levelshotTransitionTime);
}
if(isset($_GET["enableAutoRefresh"]) && $enableAutoRefresh == "1")
{
$enableAutoRefresh = booleanValidator($_GET["enableAutoRefresh"], $enableAutoRefresh);
}
if(isset($_GET["font"]))
{
$customFont = stringValidator(rawurldecode($_GET["font"]), "", "");
}
if(isset($_GET["backgroundColor"]))
{
$backgroundColor = colorValidator($_GET["backgroundColor"]);
}
if(isset($_GET["backgroundOpacity"]))
{
$backgroundOpacity = numericValidator($_GET["backgroundOpacity"], 0, 100, 100);
}
if(isset($_GET["textColor"]))
{
$textColor = colorValidator($_GET["textColor"]);
}
if(isset($_GET["playerListColor1"]))
{
$playerListColor1 = colorValidator($_GET["playerListColor1"]);
}
if(isset($_GET["playerListColor1Opacity"]))
{
$playerListColor1Opacity = numericValidator($_GET["playerListColor1Opacity"], 0, 100, 100);
}
if(isset($_GET["playerListColor2"]))
{
$playerListColor2 = colorValidator($_GET["playerListColor2"]);
}
if(isset($_GET["playerListColor2Opacity"]))
{
$playerListColor2Opacity = numericValidator($_GET["playerListColor2Opacity"], 0, 100, 100);
}
if(isset($_GET["scrollShaftColor"]))
{
$scrollShaftColor = colorValidator($_GET["scrollShaftColor"]);
}
if(isset($_GET["scrollThumbColor"]))
{
$scrollThumbColor = colorValidator($_GET["scrollThumbColor"]);
}
/*
if(isset($_GET["scrollShaftOpacity"]))
{
$scrollShaftOpacity = numericValidator($_GET["scrollShaftOpacity"], 0, 100, 100);
}
*/
if(isset($_GET["displayGameName"]))
{
$displayGameName = booleanValidator($_GET["displayGameName"], $displayGameName);
}
if(isset($_GET["enableGeoIP"]) && $enableGeoIP == "1")
{
$enableGeoIP = booleanValidator($_GET["enableGeoIP"], $enableGeoIP);
}
if(isset($_GET["filterOffendingServerNameSymbols"]))
{
$filterOffendingServerNameSymbols = booleanValidator($_GET["filterOffendingServerNameSymbols"], $filterOffendingServerNameSymbols);
}
}
if(isset($calledFromRCon) && $calledFromRCon)
{
if(isset($_GET["scrollShaftColor"]))
{
$scrollShaftColor = colorValidator($_GET["scrollShaftColor"]);
}
if(isset($_GET["scrollThumbColor"]))
{
$scrollThumbColor = colorValidator($_GET["scrollThumbColor"]);
}
}
if($enableGeoIP == "1")
{
if(!file_exists('vendor/autoload.php'))
{
echo ' Composer does not appear to be installed. ' . trackerName() . ' expects Maxmind GeoIP2 to be installed via Composer. GeoIP has been disabled and will be ignored... ';
$enableGeoIP = 0;
}
else
{
//Composer appears to be installed. Load GeoIP2!
include_once 'vendor/autoload.php';
if (!class_exists('GeoIp2\Database\Reader'))
{
echo ' Maxmind GeoIP2 library does not seem to be present. ' . trackerName() . ' expects this library to be installed via Composer. GeoIP has been disabled and will be ignored... ';
$enableGeoIP = 0;
}
else
{
//If GeoIP is enabled but the file is not found, disable it.
if(!file_exists($geoIPPath))
{
echo ' Could not find a GeoIP Country Database. "' . $geoIPPath . '"' . "\n" . 'GeoIP has been disabled and will be ignored... ';
$enableGeoIP = 0;
$geoIPPath = "";
}
}
}
}
// Validating this is a bad idea, it can break stuff. It is specified manually
// in the config file, so it should be fine to leave it unvalidated
// $webServerDomain = stringValidator($webServerDomain, 255, "");
define("webServerDomain", $webServerDomain);
$emailEnabled = booleanValidator($emailEnabled, 0);
define("emailEnabled", $emailEnabled);
if(emailEnabled)
{
$serverToolsAllowEmailAdministrators = booleanValidator($serverToolsAllowEmailAdministrators, false);
} else {
$serverToolsAllowEmailAdministrators = false;
}
define("serverToolsAllowEmailAdministrators", $serverToolsAllowEmailAdministrators);
// This is needed for serverTools, so it needs validated here
$useSMTP = booleanValidator($useSMTP, 0);
define("useSMTP", $useSMTP);
$emailAdminReports = booleanValidator($emailAdminReports, 0);
define("emailAdminReports", $emailAdminReports);
define("floodProtectTimeout", $floodProtectTimeout);
define("loginFloodProtect", $loginFloodProtect);
define("connectionAttempts", $connectionAttempts);
define("connectionTimeout", $connectionTimeout);
define("refreshTimeout", $refreshTimeout);
define("paraTrackerSkin", $paraTrackerSkin);
define("levelshotTransitionsEnabled", $levelshotTransitionsEnabled);
define("levelshotDisplayTime", $levelshotDisplayTime);
define("levelshotTransitionTime", $levelshotTransitionTime);
define("levelshotTransitionAnimation", $levelshotTransitionAnimation);
define("maximumLevelshots", $maximumLevelshots);
define("displayGameName", $displayGameName);
define("filterOffendingServerNameSymbols", $filterOffendingServerNameSymbols);
define("noPlayersOnlineMessage", $noPlayersOnlineMessage);
define("enableAutoRefresh", $enableAutoRefresh);
define("autoRefreshTimer", $autoRefreshTimer);
define("maximumServerInfoSize", $maximumServerInfoSize);
define("RConEnable", $RConEnable);
define("RConMaximumMessageSize", $RConMaximumMessageSize);
define("RConFloodProtect", $RConFloodProtect);
define("SecurityLogSize", $SecurityLogSize);
define("enableGeoIP", $enableGeoIP);
define("geoIPPath", $geoIPPath);
define("cullDatabase", $cullDatabase);
define("databaseCullTime", $databaseCullTime);
define("backgroundColor", $backgroundColor);
define("backgroundOpacity", $backgroundOpacity);
define("textColor", $textColor);
define("playerListColor1", $playerListColor1);
define("playerListColor1Opacity", $playerListColor1Opacity);
define("playerListColor2", $playerListColor2);
define("playerListColor2Opacity", $playerListColor2Opacity);
define("scrollShaftColor", $scrollShaftColor);
define("scrollThumbColor", $scrollThumbColor);
//define("scrollShaftOpacity", $scrollShaftOpacity);
if(mapreqEnabled)
{
//If mapreq is enabled, there will be text over the missing levelshot, so there is no need to have the "No image found" text
define("levelshotPlaceholder", 'images/loading.gif');
}
else
{
define("levelshotPlaceholder", 'images/missing.gif');
}
define("mapreqTextMessage", $mapreqTextMessage);
define("customFont", $customFont);
define("customSkin", $customSkin);
$enableCustomDefaultLevelshots = booleanValidator($enableCustomDefaultLevelshots, 1);
define("enableCustomDefaultLevelshots", $enableCustomDefaultLevelshots);
if($dynamicTrackerCalledFromCorrectFile == "1" && $enableCustomDefaultLevelshots)
{
//Now, check to see if we were given a custom default levelshot
if(isset($_GET["customDefaultLevelshot"]))
{
$customDefaultLevelshot = rawurldecode($_GET["customDefaultLevelshot"]);
}
}
define("customDefaultLevelshot", $customDefaultLevelshot);
define("trackerTagline", $trackerTagline);
//Convert all file extensions to lowercase before defining, and remove the "." if there is one
for($i = 0; $i < count($fileExtList); $i++)
{
$fileExtList[$i] = strtolower(ltrim($fileExtList[$i], '.'));
}
define("fileExtList", $fileExtList);
//Make sure these directories exist before we do anything
checkDirectoryExistence(infoPath);
checkDirectoryExistence(logPath);
checkDirectoryExistence(skinsPath);
checkDirectoryExistence(utilitiesPath);
//Make sure the necessary tracker files are in place
checkFileExistence("errorLog.php", logPath);
checkFileExistence("cleanupLog.php", logPath);
checkFileExistence("cleanupTimer.txt", infoPath);
checkFileExistence("emailTimer.txt", infoPath);
//Only run this if analytics is disabled. Otherwise, it will be handled by AnalyticsBackground.php
if(!analyticsEnabled)
{
cleanupInfoFolder($cleanupInterval, deleteInterval, $loadLimit, $cleanupLogSize, 0);
}
if(serverToolsEnabled)
{
if(!isset($doNotExecuteServerTools)) $doNotExecuteServerTools = true;
include_once utilitiesPath . 'ServerTools.php'; // We'll need this later on to send emails.
}
function adminCheck()
{
global $pgCon;
global $adminUser;
if (!empty($_POST['logOut'])){
if(!empty($_COOKIE['actoken']))
{
setcookie("actoken", "", 0, "", "", false, true);
pg_query_params($pgCon, 'DELETE FROM account.session WHERE token = $1', array($_COOKIE['actoken']));
}
return false;
}
if (!empty($_POST['username']) || !empty($_POST['password'])) {
$actcheck = pg_fetch_all(pg_query_params($pgCon, 'SELECT id, passhash, salt FROM account.user WHERE username = $1', array($_POST['username'])));
if (!empty($actcheck)) {
$passtest = $_POST['password'] . $actcheck[0]["salt"];
$passtesth = hash("sha512", $passtest);
if ($passtesth == $actcheck[0]["passhash"]) {
$actoken = bin2hex(random_bytes(32));
pg_query_params($pgCon, 'INSERT INTO account.session (user_id, token, expires) VALUES ($1, $2, NOW() + interval\'86400 seconds\') ON CONFLICT (user_id) DO UPDATE SET token = $2, expires = NOW() + interval\'86400 seconds\'',
array($actcheck[0]['id'], $actoken));
setcookie("actoken", $actoken, 0, "", "", false, true);
$adminUser = $_POST['username'];
return true;
}
}
} else if (!empty($_COOKIE['actoken'])) {
$actoken = $_COOKIE['actoken'];
if (!empty($actoken)) {
pg_query('DELETE FROM account.session WHERE expires < NOW()');
$actcheck = pg_fetch_all(pg_query_params($pgCon, 'SELECT account.user.username FROM account.session INNER JOIN account.user ON account.session.user_id = account.user.id WHERE account.session.token = $1', array($actoken)));
if (!empty($actcheck)) {
$adminUser = $actcheck[0]['username'];
return true;
}
}
}
return false;
}
define("admin", $admin);
define("adminUser", $adminUser);
if($executeDynamicInstructionsPage == "1")
{
dynamicInstructionsPage($personalDynamicTrackerMessage);
}
function checkForMissingFiles($dynamicIPAddressPath)
{
if(!checkFileExistence("connectionErrorMessage.txt", infoPath . $dynamicIPAddressPath)) return 0;
if(!checkFileExistence("errorMessage.txt", infoPath . $dynamicIPAddressPath)) return 0;
if(!checkFileExistence("RConTime.txt", infoPath . $dynamicIPAddressPath)) return 0;
if(!checkFileExistence("loginTime.txt", infoPath . $dynamicIPAddressPath)) return 0;
if(!checkFileExistence("serverDump.txt", infoPath . $dynamicIPAddressPath)) return 0;
if(!checkFileExistence("time.txt", infoPath . $dynamicIPAddressPath)) return 0;
if(!checkFileExistence("JSONServerInfo.txt", infoPath . $dynamicIPAddressPath)) return 0;
if(!checkFileExistence("JSONParsedInfo.txt", infoPath . $dynamicIPAddressPath)) return 0;
if(!checkFileExistence("JSONParams.txt", infoPath . $dynamicIPAddressPath)) return 0;
if(!checkFileExistence("JSONPlayerInfo.txt", infoPath . $dynamicIPAddressPath)) return 0;
if(!checkFileExistence("postgresData.txt", infoPath . $dynamicIPAddressPath)) return 0;
if(!checkServerSettingsFileExistence($dynamicIPAddressPath)) return 0;
//If we are using the old RCon file name, we need to address that!
if(file_exists(logPath . $dynamicIPAddressPath . "RConLog.php"))
{
if(!file_exists(logPath . $dynamicIPAddressPath . serverSecurityLogFilename))
{
renameSecurityLogFile($dynamicIPAddressPath);
unlink(logPath . $dynamicIPAddressPath . "RConLog.php");
}
else
{
unlink(logPath . $dynamicIPAddressPath . "RConLog.php");
}
}
return 1;
}
function renameSecurityLogFile($dynamicIPAddressPath)
{
//This function converts the old log files from SecurityLog.php to the new filename specified in $serverSecurityLogFilename
//Do not remove this...it isn't hurting anything by being left here
$oldFilename = "RConLog.php";
$splitPoint = strrpos($oldFilename, "/");
if($splitPoint != 0)
{
$splitPoint++;
}
$logFileName = substr($oldFilename, $splitPoint);
$output = readLogFile($dynamicIPAddressPath . $oldFilename);
$output = logHeader($dynamicIPAddressPath . serverSecurityLogFilename) . implode("\n", $output) . logFooter();
$oldPath = logPath . $dynamicIPAddressPath . $oldFilename;
$newPath = logPath . $dynamicIPAddressPath . serverSecurityLogFilename;
file_put_contents($newPath, $output);
}
function checkFileExistence($filename, $folder)
{