forked from webmin/authentic-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uconfig_save.cgi
executable file
·62 lines (49 loc) · 1.99 KB
/
uconfig_save.cgi
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
#!/usr/local/bin/perl
#
# Authentic Theme (https://github.com/authentic-theme/authentic-theme)
# Copyright Jamie Cameron <[email protected]>
# Copyright Ilia Rostovtsev <[email protected]>
# Licensed under MIT (https://github.com/authentic-theme/authentic-theme/blob/master/LICENSE)
#
use strict;
use warnings;
our (%text, %in, $root_directory, $config_directory, $user_config_directory);
require("$ENV{'THEME_ROOT'}/authentic-lib.pl");
require("$root_directory/config-lib.pl");
my (%newconfig, %oldconfig, %canconfig, $module, $module_dir, $custom_config, $config_post_save);
$module = $in{'module'};
&error_setup($text{'config_err'});
&foreign_available($module) || &error($text{'config_eaccess'});
&switch_to_remote_user();
&create_user_config_dirs();
mkdir("$user_config_directory/$module", 0700);
&lock_file("$user_config_directory/$module/config");
&read_file("$user_config_directory/$module/config", \%newconfig);
&read_file("$config_directory/$module/canconfig", \%canconfig);
%oldconfig = %newconfig;
$module_dir = &module_root_directory($module);
if (-r "$module_dir/uconfig_info.pl") {
# Module has a custom config editor
&foreign_require($module, "uconfig_info.pl");
my $fn = "${module}::config_form";
if (defined(&$fn)) {
$custom_config++;
&foreign_call($module, "config_save", \%newconfig, \%canconfig);
}
}
if (!$custom_config) {
# Use config.info to parse config inputs
&parse_config(\%newconfig, "$module_dir/uconfig.info", $module, (%canconfig ? \%canconfig : undef), $in{'section'});
}
&write_file("$user_config_directory/$module/config", \%newconfig);
&unlock_file("$user_config_directory/$module/config");
# Call any post-config save function
$config_post_save = "${module}::config_post_save";
if (defined(&$config_post_save)) {
&foreign_call($module, "config_post_save", \%newconfig, \%oldconfig, \%canconfig);
}
if ($in{'save_next'}) {
&redirect("uconfig.cgi?module=$module§ion=$in{'section_next'}");
} else {
&redirect("/$module/");
}