-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfig.php
119 lines (102 loc) · 4.4 KB
/
config.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
<?php
include_once(__DIR__."/lib/common/log.php");
function load_config() {
global $config;
$config = parse_ini_file(CONFIGFILE);
}
function get_config($key, $default = null, $type = "string") {
global $config;
if(!isset($config)) die("Error: Config not loaded; exiting...");
if(empty($default)) {
if(strtolower($type) === "int") {
$default = 0;
} else if(strtolower($type) === "boolean") {
$default = 'true';
}
}
$value = $config[$key] ?? $default;
if(strtolower($type) === "boolean") {
// $value = strtolower($value) === "true"; # Seems 'true' string values are 1 already from the ini file load.
} else if(strtolower($type) === "int") {
$value = intval($value);
}
return $value;
}
define("MAPROOT", __DIR__);
define("CONFIGFILE", MAPROOT."/.env");
require __DIR__ . '/vendor/autoload.php';
$lostPasswordRandomGeneratorStrengthStrings = array_keys((new SecurityLib\Strength)->getConstList());
# All but deprecated and notices.
# TODO: This is a dev or prod setting currently?
error_reporting((E_ALL ^ E_DEPRECATED) & ~E_NOTICE);
!file_exists(CONFIGFILE) and die('Project `.env` file not found and must be provided.');
load_config();
$cacheFolderRootPath = get_config("cacheFolderRootPath", sys_get_temp_dir());
$cacheFolder = $cacheFolderRootPath."/Tingle";
# Database
$dbms = get_config("DBMS" );
$dbhost = get_config("DBHOST" );
$dbuser = get_config("DBUSER" );
$dbpasswd = get_config("DBPASSWD");
$dbname = get_config("DBNAME" );
$dbport = get_config("DBPORT" , type: "int");
$dbsocket = get_config("DBSOCKET");
$map_prefix = get_config("PREFIX" );
$minify = get_config("minify", type: "boolean");
$enableTests = get_config("enableTests", type: "boolean");
# User features
$lostPasswordRandomGeneratorStrengthString = get_config("LOST_PASSWORD_RANDOM_GENERATOR_STRENGTH");
if(
array_search(
$lostPasswordRandomGeneratorStrengthString, $lostPasswordRandomGeneratorStrengthStrings
) === false
) {
error_log("Miconfigured \"LOST_PASSWORD_RANDOM_GENERATOR_STRENGTH\" setting; using the value \"MEDIUM\" by default.");
$lostPasswordRandomGeneratorStrengthString = "MEDIUM";
}
$lostPasswordRandomGeneratorStrengthConstant = new SecurityLib\Strength((new SecurityLib\Strength)->getConstList()[$lostPasswordRandomGeneratorStrengthString]);
# Mail
$mailEnabled = get_config('mailEnabled');
$mailServer = get_config('server' );
$mailPort = get_config('port' );
$mailUsername = get_config('username' );
$mailPassword = get_config('password' );
$mailReplyToAddress = get_config('replyToAddress');
$mailReplyToName = get_config('replyToName');
$lostPasswordSubject = get_config("lostPasswordSubject");
$lostPasswordBodyTemplateFilePath = get_config("lostPasswordBodyTemplateFilePath");
if(!empty($lostPasswordBodyTemplateFilePath)) {
$lostPasswordBodyTemplateFilePath = __DIR__."/$lostPasswordBodyTemplateFilePath";
$lostPasswordBodyTemplate = file_get_contents($lostPasswordBodyTemplateFilePath);
}
if(
empty($mailServer) ||
empty($mailPort) ||
empty($mailUsername) ||
empty($mailPassword) ||
empty($mailReplyToAddress) ||
empty($mailReplyToName) ||
empty($lostPasswordSubject) ||
empty($lostPasswordBodyTemplateFilePath)
) {
# Don't want this message output for every request.
// error_log("Warning: Disabling mail server integration as a required setting was blank...");
$mailEnabled = false;
}
$debugLoggingMode = get_config('debugLoggingMode', default: 'errorLog');
// debug_log("debugLoggingMode: $debugLoggingMode");
$cFRPFileExists = file_exists($cacheFolderRootPath);
$cFFileExists = file_exists($cacheFolder);
// debug_log("cacheFolderRootPath: $cacheFolderRootPath");
// debug_log("cacheFolder : $cacheFolder");
// debug_log("cFRPFileExists : $cFRPFileExists");
// debug_log("cFFileExists : $cFFileExists");
if(!$cFRPFileExists) {
mkdir($cacheFolderRootPath) or
die("Cache root directory error at: ".$cacheFolderRootPath);
}
if(!$cFFileExists) {
mkdir($cacheFolder) or
die("Cache directory error at: ".$cacheFolder);
}
?>