mirror of
https://github.com/webmin/webmin.git
synced 2026-03-20 16:50:24 +00:00
Add ability to save module user prefs if allowed by module
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -361,5 +361,35 @@ foreach my $c (@$info_order) {
|
||||
return @new_order;
|
||||
}
|
||||
|
||||
# save_module_preferences(module, &config)
|
||||
# Check which user preferences can be save for
|
||||
# given module based on module's prefs.info file
|
||||
sub save_module_preferences
|
||||
{
|
||||
my ($module, $curr_config) = @_;
|
||||
my $module_dir = &module_root_directory($module);
|
||||
my $module_prefs_conf = "$module_dir/prefs.info";
|
||||
if (-r $module_prefs_conf) {
|
||||
my %module_prefs_conf_allowed;
|
||||
&read_file($module_prefs_conf, \%module_prefs_conf_allowed);
|
||||
mkdir("$config_directory/$module", 0700);
|
||||
my $user_prefs_file = "$config_directory/$module/prefs.$remote_user";
|
||||
&lock_file($user_prefs_file);
|
||||
if ($module_prefs_conf_allowed{'allowed'} eq "*") {
|
||||
&write_file($user_prefs_file, \%$curr_config);
|
||||
}
|
||||
else {
|
||||
my %newconfigtmp;
|
||||
foreach my $key (keys %{$curr_config}) {
|
||||
if (grep(/^$key$/, split(",", $module_prefs_conf_allowed{'allowed'}))) {
|
||||
$newconfigtmp->{$key} = $curr_config->{$key};
|
||||
}
|
||||
}
|
||||
&write_file($user_prefs_file, \%$newconfigtmp);
|
||||
}
|
||||
&unlock_file($user_prefs_file);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ print &ui_hidden("module", $m),"\n";
|
||||
print &ui_table_start(&text('config_header', $module_info{'desc'}),
|
||||
"width=100%", 2);
|
||||
&read_file("$config_directory/$m/config", \%newconfig);
|
||||
|
||||
&load_module_preferences($m, \%newconfig);
|
||||
$mdir = &module_root_directory($m);
|
||||
if (-r "$mdir/config_info.pl") {
|
||||
# Module has a custom config editor
|
||||
|
||||
@@ -41,6 +41,7 @@ if (!$func) {
|
||||
}
|
||||
&write_file("$config_directory/$m/config", \%newconfig);
|
||||
&unlock_file("$config_directory/$m/config");
|
||||
&save_module_preferences($m, \%newconfig);
|
||||
|
||||
# Call any post-config save function
|
||||
local $pfn = "${m}::config_post_save";
|
||||
|
||||
@@ -1394,6 +1394,38 @@ if (!$_[0]) {
|
||||
print "</html>\n";
|
||||
}
|
||||
|
||||
=head2 load_module_preferences(module, &config)
|
||||
|
||||
Check if user preferences can be loaded for given
|
||||
module based on module's prefs.info special file
|
||||
|
||||
=cut
|
||||
sub load_module_preferences
|
||||
{
|
||||
my ($module, $curr_config) = @_;
|
||||
my $module_dir = &module_root_directory($module);
|
||||
my $module_prefs_conf = "$module_dir/prefs.info";
|
||||
if (-r $module_prefs_conf) {
|
||||
my %module_prefs_conf_allowed;
|
||||
&read_file($module_prefs_conf, \%module_prefs_conf_allowed);
|
||||
my $current_user_prefs = "$config_directory/$module/prefs.$remote_user";
|
||||
if (-r $current_user_prefs) {
|
||||
if ($module_prefs_conf_allowed{'allowed'} eq "*") {
|
||||
&read_file($current_user_prefs, \%$curr_config);
|
||||
}
|
||||
else {
|
||||
my %newconfigtmp;
|
||||
&read_file($current_user_prefs, \%newconfigtmp);
|
||||
foreach my $key (keys %newconfigtmp) {
|
||||
if (grep(/^$key$/, split(",", $module_prefs_conf_allowed{'allowed'}))) {
|
||||
$curr_config->{$key} = $newconfigtmp{$key};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
=head2 load_theme_library
|
||||
|
||||
Immediately loads the current theme's theme.pl file. Not generally useful for
|
||||
@@ -4905,6 +4937,7 @@ if ($module_name) {
|
||||
}
|
||||
%config = ( );
|
||||
&read_file_cached($module_config_file, \%config);
|
||||
&load_module_preferences($module_name, \%config);
|
||||
|
||||
# Create a module-specific var directory
|
||||
my $var_base = "$var_directory/modules";
|
||||
|
||||
Reference in New Issue
Block a user