Bearsampp
2026.9.23
Toggle main menu visibility
Loading...
Searching...
No Matches
ajax.apply.moduleconfig.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
21
22
// Set appropriate headers for AJAX response
23
header(
'Content-Type: application/json'
);
24
25
// Initialize response array
26
$response
= array();
27
28
// Check if this is a POST request
29
if
($_SERVER[
'REQUEST_METHOD'
] ===
'POST'
) {
30
$moduleName = isset($_POST[
'moduleName'
]) ? $_POST[
'moduleName'
] :
null
;
31
$version = isset($_POST[
'version'
]) ? $_POST[
'version'
] :
null
;
32
33
if
($moduleName && $version) {
34
// Validate both inputs before they reach the config file. Config::replace()
35
// embeds these values directly into bearsampp.conf, which later drives
36
// generated shell commands, so anything other than a plain module
37
// identifier / version string must be rejected (config poisoning).
38
$moduleName = strtolower($moduleName);
39
if
(preg_match(
'/^[a-z0-9_-]+$/'
, $moduleName) !== 1 ||
40
preg_match(
'/^[0-9][0-9a-zA-Z.\-+]*$/'
, $version) !== 1) {
41
$response
= [
'error'
=>
'Invalid module name or version format.'
];
42
}
else
{
43
try
{
44
global
$bearsamppConfig
;
45
46
Log::debug
(
"Applying config for module: $moduleName, version: $version"
);
47
48
// Update the configuration file
49
$configKey = $moduleName .
'Version'
;
50
$bearsamppConfig
->replace($configKey, $version);
51
52
Log::info
(
"Successfully updated $moduleName version to $version in bearsampp.conf"
);
53
54
$response
= [
55
'success'
=>
true
,
56
'message'
=>
"Configuration updated successfully!\n\n✓ Set $moduleName"
.
"Version = \"$version\"\n\nNow right-click the Bearsampp tray icon and select 'Reload' to activate the new version."
57
];
58
}
catch
(Exception $e) {
59
$response
= [
'error'
=>
'Failed to update configuration: '
. $e->getMessage()];
60
error_log(
'Exception in apply module config: '
. $e->getMessage());
61
}
62
}
63
}
else
{
64
$response
= [
'error'
=>
'Invalid module name or version.'
];
65
}
66
}
else
{
67
$response
= [
'error'
=>
'Invalid request method.'
];
68
}
69
70
// Send the JSON response
71
echo json_encode(
$response
);
72
exit
;
73
exit
exit
Definition
ajax.apply.moduleconfig.php:72
$response
$response
Definition
ajax.apply.moduleconfig.php:26
Log\info
static info($data, $file=null)
Definition
class.log.php:737
Log\debug
static debug($data, $file=null)
Definition
class.log.php:726
$bearsamppConfig
global $bearsamppConfig
Definition
homepage.php:46
sandbox
core
resources
homepage
ajax
ajax.apply.moduleconfig.php
Generated by
1.17.0