Compare commits

...

9 Commits

Author SHA1 Message Date
Ilia Ross
3885773f6e Fix to correctly test if hash ref is empty 2023-11-07 21:32:37 +02:00
Ilia Ross
dc3ed53c43 Fix to re-use un_urlize API 2023-11-07 11:48:45 +02:00
Ilia Ross
24ca182b18 Fix to correctly extract config query for Save and Next 2023-11-07 02:46:56 +02:00
Ilia Ross
54c7856672 Fix to also automatically detect if prefix was loaded 2023-11-07 02:14:01 +02:00
Ilia Ross
9b3fb73aea Fix missing semicolon 2023-11-07 02:04:14 +02:00
Ilia Ross
692c9cc5e1 Fix to correctly process params
(remove leaked debug code)
2023-11-07 01:40:38 +02:00
Ilia Ross
62bcd25eb9 Add support for preserving config params in Legacy Theme 2023-11-06 22:27:00 +02:00
Ilia Ross
a6d23844ce Add support for preserving config params in Framed Theme 2023-11-06 22:17:12 +02:00
Ilia Ross
a9cd02aa6d Add API to preserve module params as going to config page 2023-11-06 22:16:30 +02:00
5 changed files with 95 additions and 7 deletions

View File

@@ -407,5 +407,89 @@ if (-r $module_prefs_conf) {
}
}
# read_config_params(url, insert-prefix)
# Parses the URL parameters from a URL, and returns a hash ref
sub read_config_params
{
my ($url, $pref) = @_;
# Extract the part of the URL after the question mark
my ($query_string) = $url =~ /\?(.*)$/;
my %params;
# Split the query string on '&' to get the individual key-value pairs
for my $pair (split(/&/, $query_string)) {
my ($key, $value) = split /=/, $pair;
$value = &un_urlize($value);
my $param_prefix = $pref ? "_cparam-" : "";
$params{"$param_prefix$key"} = $value;
}
return \%params;
}
# print_config_posted_params()
# Prints hidden fields for all the parameters in the referrer URL
sub print_config_posted_params
{
my $env_referer = $ENV{'HTTP_REFERER'};
my $params_referer = &read_config_params($env_referer);
my $params_url = &read_config_params($ENV{'REQUEST_URI'});
my $params = { %$params_referer, %$params_url };
my @params;
if (%$params) {
foreach my $param (keys %{$params}) {
my $param_prefix = "_cparam-";
if ($param =~ /section|module|mode|section_next|nnext|nprev|xnavigation/ ||
!$params->{$param} || $env_referer =~ /$param_prefix$param=/ ||
$params_url =~ /$param_prefix$param=/ || &indexof($param, @params) > -1) {
next;
}
$param_prefix = "" if ($param =~ /^$param_prefix/);
push(@params, $param);
print &ui_hidden("$param_prefix$param", $params->{$param}), "\n";
}
}
}
# get_query_config_posted_params(url)
# Returns the currently posted parameters from the URL
sub get_query_config_posted_params
{
my ($url) = @_;
foreach my $key (keys %in) {
if ($key =~ /^_cparam-/) {
my $value = $in{$key};
if ($value) {
my $delimiter = ($url =~ /\?/) ? "&" : '?';
$url .= "$delimiter$key=$value"
}
}
}
return $url;
}
# get_config_posted_params(target)
# Returns the referrer URL with all the parameters from the POST request
sub get_config_posted_params
{
my ($target) = @_;
my $param_prefix = "_cparam-";
my $env_referer = $ENV{'HTTP_REFERER'};
my $env_referer_prefixed = ($env_referer =~ /$param_prefix/ ? 1 : 0);
my $params_referer = &read_config_params($env_referer, !$env_referer_prefixed);
my %keys = (%in, %$params_referer);
foreach my $key (keys %keys) {
if ($key =~ /^$param_prefix(.*)/) {
my $k = $1;
my $v = $keys{$key};
if ($v && $target !~ /$k=/) {
my $delimiter = ($target =~ /\?/) ? "&" : '?';
$v = &urlize($v) if ($v =~ /^\//);
$target .= "$delimiter$k=$v"
}
}
}
return $target;
}
1;

View File

@@ -25,6 +25,7 @@ else {
print &ui_form_start("config_save.cgi", "post");
print &ui_hidden("module", $m),"\n";
&print_config_posted_params();
print &ui_table_start(&text('config_header', $module_info{'desc'}),
"width=100%", 2);
&read_file("$config_directory/$m/config", \%newconfig);
@@ -51,5 +52,5 @@ if (!$func) {
print &ui_table_end();
print &ui_form_end([ [ "save", $text{'save'} ] ]);
&ui_print_footer("/$m", $text{'index'});
&ui_print_footer(&get_config_posted_params("/$m/"), $text{'index'});

View File

@@ -56,5 +56,5 @@ if (&foreign_check("webmin")) {
}
&webmin_log("_config_", undef, undef, \%in, $m);
&redirect("/$m/");
&redirect(&get_config_posted_params("/$m/"));

View File

@@ -62,6 +62,7 @@ if (@sections > 1) {
print &ui_form_start("config.cgi");
print &ui_hidden("module", $m),"\n";
print $text{'config_section'},"\n";
&print_config_posted_params();
print &ui_select("section", $in{'section'}, \@sections,
1, 0, 0, 0, "onChange='form.submit()'");
print &ui_submit($text{'config_change'});
@@ -76,6 +77,7 @@ if (@sections > 1) {
print &ui_form_start("config_save.cgi", "post");
print &ui_hidden("module", $m),"\n";
print &ui_hidden("section", $in{'section'}),"\n";
&print_config_posted_params();
if ($s) {
# Find next section
$idx = &indexof($s, @sections);
@@ -122,6 +124,6 @@ if ($m eq "virtual-server") {
&ui_print_footer("/right.cgi", $text{'config_return'});
}
else {
&ui_print_footer("/$m", $text{'index'});
&ui_print_footer(&get_config_posted_params("/$m/"), $text{'index'});
}

View File

@@ -41,13 +41,14 @@ if (&foreign_require($m) &&
}
&webmin_log("_config_", undef, undef, \%in, $m);
my $redirect_url;
if ($in{'save_next'}) {
&redirect("config.cgi?module=$in{'module'}&section=$in{'section_next'}");
$redirect_url = &get_query_config_posted_params("config.cgi?module=$in{'module'}&section=$in{'section_next'}");
}
elsif ($m eq "virtual-server") {
&redirect("/right.cgi");
$redirect_url = "/right.cgi";
}
else {
&redirect("/$m/");
$redirect_url = &get_config_posted_params("/$m/");
}
&redirect($redirect_url);