Skip to content

Commit 191b321

Browse files
fix: remove all direct config accessors
This addresses an issue in pfSense 24.11 where the global variable has been deprecated
1 parent 7e15d95 commit 191b321

File tree

4 files changed

+12
-21
lines changed

4 files changed

+12
-21
lines changed

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/Form.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ class Form {
319319
*/
320320
final public function print_form(): void {
321321
# Print the static pfSense UI and include any custom CSS or JS files
322-
global $config, $user_settings;
322+
global $user_settings;
323323
$pgtitle = $this->title_path;
324324
include 'head.inc';
325325
echo "<link rel='stylesheet' href='$this->custom_css'/>";

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/Model.inc

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,7 @@ class Model {
550550
*/
551551
protected static function init_config(string $path) {
552552
# Initialize the configuration array of a specified path.
553-
global $config;
554-
array_init_path($config, $path);
553+
config_init_path($path);
555554
}
556555

557556
/**
@@ -562,8 +561,7 @@ class Model {
562561
* path keys an empty string and $default is non-null
563562
*/
564563
public static function get_config(string $path, mixed $default = null) {
565-
global $config;
566-
return array_get_path($config, $path, $default);
564+
return config_get_path($path, $default);
567565
}
568566

569567
/**
@@ -574,8 +572,7 @@ class Model {
574572
* @returns mixed $val or $default if the path prefix does not exist
575573
*/
576574
public static function set_config(string $path, mixed $value, mixed $default = null) {
577-
global $config;
578-
return array_set_path($config, $path, $value, $default);
575+
return config_set_path($path, $value, $default);
579576
}
580577

581578
/**
@@ -616,8 +613,7 @@ class Model {
616613
* @returns array copy of the removed value or null
617614
*/
618615
public static function del_config(string $path): mixed {
619-
global $config;
620-
return array_del_path($config, $path);
616+
return config_del_path($path);
621617
}
622618

623619
/**
@@ -630,8 +626,7 @@ class Model {
630626
* non-null value, otherwise false.
631627
*/
632628
public static function is_config_enabled(string $path, string $enable_key = 'enable'): bool {
633-
global $config;
634-
return array_path_enabled($config, $path, $enable_key);
629+
return config_path_enabled($path, $enable_key);
635630
}
636631

637632
/**
@@ -680,8 +675,7 @@ class Model {
680675
* @param bool $force_parse Force an entire reparse of the config.xml file instead of the cached config.
681676
*/
682677
public static function reload_config(bool $force_parse = false): void {
683-
global $config;
684-
$config = parse_config(parse: $force_parse);
678+
config_set_path("", parse_config(parse: $force_parse));
685679
}
686680

687681
/**

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/TestCase.inc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ class TestCase {
4444
* @throws Error|Exception The exception thrown by failed Tests, typically an AssertionError.
4545
*/
4646
public function run(): void {
47-
# Need direct config access to revert any changes made by Tests
48-
global $config;
49-
5047
# Collect available environment variables
5148
$this->get_envs();
5249

@@ -64,7 +61,7 @@ class TestCase {
6461
# If this method starts with `test`, run the function.
6562
if (str_starts_with($method, 'test')) {
6663
# Backup the current config so we can undo any changes made during the test
67-
$original_config = unserialize(serialize($config));
64+
$original_config = config_get_path("");
6865

6966
# Set the current method undergoing testing
7067
$this->method = $method;
@@ -78,14 +75,14 @@ class TestCase {
7875
$this->$method();
7976
} catch (Error | Exception $e) {
8077
# Restore the original configuration, teardown the TestCase and throw the encountered error
81-
$config = $original_config;
78+
config_set_path("", $original_config);
8279
write_config("Restored config after API test '$method'");
8380
$this->teardown();
8481
throw $e;
8582
}
8683

8784
# Restore the config as it was when the test began.
88-
$config = $original_config;
85+
config_set_path("", $original_config);
8986
write_config("Restored config after API test '$method'");
9087
}
9188
}

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/RoutingGateway.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ class RoutingGateway extends Model {
207207
# Ensure the gateway cannot be disabled while it is in use by a system DNS server
208208
# TODO: replace with a Model query when the SystemDNSServer Model is developed
209209
$dnsgw_counter = 1;
210-
while (isset($config['system']["dns{$dnsgw_counter}gw"])) {
211-
if ($this->name->value == $config['system']["dns{$dnsgw_counter}gw"]) {
210+
while ($this->get_config("system/dns{$dnsgw_counter}gw")) {
211+
if ($this->name->value == $this->get_config("system/dns{$dnsgw_counter}gw")) {
212212
throw new ValidationError(
213213
message: 'Gateway cannot be disabled because it is in use by a system DNS ' .
214214
"server with ID `$dnsgw_counter`",

0 commit comments

Comments
 (0)