Bearsampp
2026.9.23
Toggle main menu visibility
Loading...
Searching...
No Matches
class.config.php
Go to the documentation of this file.
1
<?php
2
/*
3
*
4
* * Copyright (c) 2022-2025 Bearsampp
5
* * License: GNU General Public License version 3 or later; see LICENSE.txt
6
* * Website: https://bearsampp.com
7
* * Github: https://github.com/Bearsampp
8
*
9
*/
10
17
class
Config
18
{
19
const
CFG_MAX_LOGS_ARCHIVES
=
'maxLogsArchives'
;
20
const
CFG_LOGS_VERBOSE
=
'logsVerbose'
;
21
const
CFG_LANG
=
'lang'
;
22
const
CFG_TIMEZONE
=
'timezone'
;
23
const
CFG_NOTEPAD
=
'notepad'
;
24
const
CFG_SCRIPTS_TIMEOUT
=
'scriptsTimeout'
;
25
const
DOWNLOAD_ID
=
'DownloadId'
;
26
27
const
CFG_INCLUDE_PR
=
'IncludePR'
;
28
const
CFG_ENHANCED_QUICKPICK
=
'EnhancedQuickPick'
;
29
const
CFG_DEFAULT_LANG
=
'defaultLang'
;
30
const
CFG_HOSTNAME
=
'hostname'
;
31
const
CFG_BROWSER
=
'browser'
;
32
const
CFG_ONLINE
=
'online'
;
33
const
CFG_LAUNCH_STARTUP
=
'launchStartup'
;
34
35
const
ENABLED
= 1;
36
const
DISABLED
= 0;
37
38
const
VERBOSE_SIMPLE
= 0;
39
const
VERBOSE_REPORT
= 1;
40
const
VERBOSE_DEBUG
= 2;
41
const
VERBOSE_TRACE
= 3;
42
44
private
$raw
;
45
50
public
function
__construct
()
51
{
52
global
$bearsamppRoot
;
53
54
// Set current timezone to match whats in .conf
55
$this->raw = parse_ini_file(
Path::getConfigFilePath
());
56
date_default_timezone_set($this->
getTimezone
());
57
}
58
66
public
function
getRaw
($key)
67
{
68
return
$this->raw[$key];
69
}
70
77
public
function
replace
($key, $value)
78
{
79
$this->
replaceAll
(array($key => $value));
80
}
81
89
public
function
replaceAll
($params)
90
{
91
global
$bearsamppRoot
;
92
93
Log::trace
(
'Replace config:'
);
94
$content = file_get_contents(
Path::getConfigFilePath
());
95
foreach
($params as $key => $value) {
96
// Only accept well-formed keys and values. The key is interpolated
97
// into a regex pattern and the value into the INI content, so an
98
// unvalidated key/value could inject arbitrary lines or corrupt
99
// other settings (config poisoning). Values that could break out
100
// of the surrounding quotes or add lines are rejected.
101
if
(!is_string($key) || preg_match(
'/^[a-zA-Z0-9_-]+$/'
, $key) !== 1) {
102
throw
new
RuntimeException(
'Invalid configuration key: '
. var_export($key,
true
));
103
}
104
$value = (string)$value;
105
if
(preg_match(
'/[\r\n"\x00-\x1F\x7F]/'
, $value) === 1) {
106
throw
new
RuntimeException(
'Invalid configuration value for key: '
. $key);
107
}
108
109
$content = preg_replace(
'/^'
. preg_quote($key,
'/'
) .
'\s=\s.*/m'
, $key .
' = '
.
'"'
. $value .
'"'
, $content, -1, $count);
110
Log::trace
(
'## '
. $key .
': '
. $value .
' ('
. $count .
' replacements done)'
);
111
$this->raw[$key] = $value;
112
}
113
114
file_put_contents(
Path::getConfigFilePath
(), $content);
115
}
116
122
public
function
getLang
()
123
{
124
return
$this->raw[self::CFG_LANG];
125
}
126
132
public
function
getDefaultLang
()
133
{
134
return
$this->raw[self::CFG_DEFAULT_LANG];
135
}
136
142
public
function
getTimezone
()
143
{
144
return
$this->raw[self::CFG_TIMEZONE];
145
}
146
152
public
function
getDownloadId
()
153
{
154
return
$this->raw[self::DOWNLOAD_ID];
155
}
156
162
public
function
isOnline
()
163
{
164
return
$this->raw[self::CFG_ONLINE] == self::ENABLED;
165
}
166
172
public
function
isLaunchStartup
()
173
{
174
return
$this->raw[self::CFG_LAUNCH_STARTUP] == self::ENABLED;
175
}
176
182
public
function
getBrowser
()
183
{
184
return
$this->raw[self::CFG_BROWSER];
185
}
186
192
public
function
getHostname
()
193
{
194
return
$this->raw[self::CFG_HOSTNAME];
195
}
196
202
public
function
getScriptsTimeout
()
203
{
204
return
intval($this->raw[self::CFG_SCRIPTS_TIMEOUT]);
205
}
206
212
public
function
getNotepad
()
213
{
214
return
$this->raw[self::CFG_NOTEPAD];
215
}
216
222
public
function
getLogsVerbose
()
223
{
224
return
intval($this->raw[self::CFG_LOGS_VERBOSE]);
225
}
226
232
public
function
getMaxLogsArchives
()
233
{
234
return
intval($this->raw[self::CFG_MAX_LOGS_ARCHIVES]);
235
}
236
242
public
function
getIncludePr
()
243
{
244
return
isset($this->raw[self::CFG_INCLUDE_PR]) ? intval($this->raw[self::CFG_INCLUDE_PR]) : 0;
245
}
246
252
public
function
getEnhancedQuickPick
()
253
{
254
return
isset($this->raw[self::CFG_ENHANCED_QUICKPICK]) ? intval($this->raw[self::CFG_ENHANCED_QUICKPICK]) : 0;
255
}
256
262
public
function
validateEnhancedQuickPick
()
263
{
264
// Check if the parameter exists in the config
265
if
(!isset($this->raw[self::CFG_ENHANCED_QUICKPICK])) {
266
return
[
267
'valid'
=>
false
,
268
'error'
=>
'Missing parameter: EnhancedQuickPick is not defined in bearsampp.conf'
269
];
270
}
271
272
$value = $this->raw[self::CFG_ENHANCED_QUICKPICK];
273
274
// Check if the value is either "0" or "1"
275
if
($value !==
"0"
&& $value !==
"1"
) {
276
return
[
277
'valid'
=>
false
,
278
'error'
=>
'Invalid parameter: EnhancedQuickPick must be set to "0" or "1" in bearsampp.conf'
279
];
280
}
281
282
return
[
'valid'
=>
true
];
283
}
284
}
285
$bearsamppRoot
global $bearsamppRoot
Definition
ajax.apache.php:16
Config
Definition
class.config.php:18
Config\CFG_HOSTNAME
const CFG_HOSTNAME
Definition
class.config.php:30
Config\__construct
__construct()
Definition
class.config.php:50
Config\CFG_LOGS_VERBOSE
const CFG_LOGS_VERBOSE
Definition
class.config.php:20
Config\isOnline
isOnline()
Definition
class.config.php:162
Config\getTimezone
getTimezone()
Definition
class.config.php:142
Config\DISABLED
const DISABLED
Definition
class.config.php:36
Config\replaceAll
replaceAll($params)
Definition
class.config.php:89
Config\VERBOSE_REPORT
const VERBOSE_REPORT
Definition
class.config.php:39
Config\getMaxLogsArchives
getMaxLogsArchives()
Definition
class.config.php:232
Config\CFG_ONLINE
const CFG_ONLINE
Definition
class.config.php:32
Config\getNotepad
getNotepad()
Definition
class.config.php:212
Config\VERBOSE_SIMPLE
const VERBOSE_SIMPLE
Definition
class.config.php:38
Config\CFG_TIMEZONE
const CFG_TIMEZONE
Definition
class.config.php:22
Config\getHostname
getHostname()
Definition
class.config.php:192
Config\getEnhancedQuickPick
getEnhancedQuickPick()
Definition
class.config.php:252
Config\CFG_NOTEPAD
const CFG_NOTEPAD
Definition
class.config.php:23
Config\getDefaultLang
getDefaultLang()
Definition
class.config.php:132
Config\CFG_SCRIPTS_TIMEOUT
const CFG_SCRIPTS_TIMEOUT
Definition
class.config.php:24
Config\getBrowser
getBrowser()
Definition
class.config.php:182
Config\isLaunchStartup
isLaunchStartup()
Definition
class.config.php:172
Config\CFG_BROWSER
const CFG_BROWSER
Definition
class.config.php:31
Config\CFG_ENHANCED_QUICKPICK
const CFG_ENHANCED_QUICKPICK
Definition
class.config.php:28
Config\getDownloadId
getDownloadId()
Definition
class.config.php:152
Config\VERBOSE_TRACE
const VERBOSE_TRACE
Definition
class.config.php:41
Config\replace
replace($key, $value)
Definition
class.config.php:77
Config\DOWNLOAD_ID
const DOWNLOAD_ID
Definition
class.config.php:25
Config\getLang
getLang()
Definition
class.config.php:122
Config\ENABLED
const ENABLED
Definition
class.config.php:35
Config\getLogsVerbose
getLogsVerbose()
Definition
class.config.php:222
Config\CFG_LANG
const CFG_LANG
Definition
class.config.php:21
Config\CFG_MAX_LOGS_ARCHIVES
const CFG_MAX_LOGS_ARCHIVES
Definition
class.config.php:19
Config\getIncludePr
getIncludePr()
Definition
class.config.php:242
Config\$raw
$raw
Definition
class.config.php:44
Config\getScriptsTimeout
getScriptsTimeout()
Definition
class.config.php:202
Config\CFG_DEFAULT_LANG
const CFG_DEFAULT_LANG
Definition
class.config.php:29
Config\VERBOSE_DEBUG
const VERBOSE_DEBUG
Definition
class.config.php:40
Config\validateEnhancedQuickPick
validateEnhancedQuickPick()
Definition
class.config.php:262
Config\CFG_LAUNCH_STARTUP
const CFG_LAUNCH_STARTUP
Definition
class.config.php:33
Config\getRaw
getRaw($key)
Definition
class.config.php:66
Config\CFG_INCLUDE_PR
const CFG_INCLUDE_PR
Definition
class.config.php:27
Log\trace
static trace($data, $file=null)
Definition
class.log.php:715
Path\getConfigFilePath
static getConfigFilePath($aetrayPath=false)
Definition
class.path.php:396
sandbox
core
classes
class.config.php
Generated by
1.17.0