Format configs cross changes made in UI; fix allowed test

This commit is contained in:
Ilia Rostovtsev
2021-11-04 14:43:27 +03:00
parent 471767d1b8
commit 2b43b2baa4
11 changed files with 28 additions and 10 deletions

View File

@@ -26,7 +26,7 @@ print &ui_form_start("allmanual_save.cgi", "form-data");
print &ui_hidden("file", $in{'file'}),"\n";
# Display nicely too
if ($config{'format_config'} ne '0') {
if (&format_config_allowed()) {
$data = &read_file_lines($in{'file'}, 1);
&format_config($data);
$data = join("\n", @{$data});

View File

@@ -27,7 +27,7 @@ if ($config{'test_manual'}) {
}
}
unlink($temp);
&format_config_file($in{'file'}) if ($config{'format_config'} ne '0');
&format_config_file($in{'file'});
&webmin_log("manual", undef, undef, { 'file' => $in{'file'} });
&redirect("index.cgi?mode=global");

View File

@@ -964,6 +964,7 @@ for($i=0; $i<@chname; $i++) {
&flush_file_lines();
&unlock_apache_files();
&after_changing();
&format_modifed_config_files();
}
# opt_input(value, name, default, size)
@@ -2135,6 +2136,9 @@ sub format_config
{
my ($conf_lref, $indent) = @_;
# Prevent formatting if not allowed in config
return if (!&format_config_allowed());
# Default single indent equals 4 spaces
$indent ||= 4;
$indent = " " x $indent;
@@ -2197,6 +2201,9 @@ sub format_config_file
{
my ($file, $indent) = @_;
# Prevent formatting if not allowed in config
return if (!&format_config_allowed());
# Lock file
&lock_file($file);
@@ -2213,16 +2220,16 @@ my $conf_lref = &read_file_lines($file);
&unlock_file($file);
}
# format_modifed_configs([no-config-test])
# format_modifed_configs([test-config])
# Formats all modifed Apache configs during the call
sub format_modifed_config_files
{
my ($conf_already_tested) = @_;
my ($force_config_test) = @_;
if($saved_conf_files) {
if ($config{'format_config'} ne '0') {
if (&format_config_allowed()) {
# Test config first if not already
# tested and don't format on error
if (!$conf_already_tested) {
if ($force_config_test) {
if ($config{'test_manual'} ||
$config{'test_always'}) {
my $conf_err = &test_config();
@@ -2239,5 +2246,12 @@ if($saved_conf_files) {
}
}
# format_config_allowed()
# Checks if formatting config is allowed
sub format_config_allowed
{
return $config{'format_config'} ne '0';
}
1;

View File

@@ -41,6 +41,7 @@ else {
}
&flush_file_lines();
&unlock_file($d->{'file'});
&format_config_file($d->{'file'});
&update_last_config_change();
&after_changing();

View File

@@ -36,6 +36,7 @@ else {
}
&flush_file_lines();
&unlock_file($d->{'file'});
&format_config_file($d->{'file'});
&update_last_config_change();
&after_changing();

View File

@@ -39,6 +39,7 @@ else {
&flush_file_lines();
&update_last_config_change();
&unlock_file($vconf->[0]->{'file'});
&format_config_file($vconf->[0]->{'file'});
&after_changing();
&webmin_log("dir", "create", &virtual_name($v, 1).":$in{'path'}", \%in);

View File

@@ -33,6 +33,7 @@ else {
&flush_file_lines();
&update_last_config_change();
&unlock_file($in{'file'});
&format_config_file($in{'file'});
&after_changing();
&webmin_log("files", "create", "$in{'file'}:$in{'path'}", \%in);

View File

@@ -246,6 +246,7 @@ foreach my $m (@{$dirsect->{'members'}}) {
&save_directive_struct(undef, $virt, $conf, $conf);
&flush_file_lines();
&unlock_file($f);
&format_config_file($f);
&update_last_config_change();
&unlock_apache_files();

View File

@@ -93,9 +93,7 @@ for($i=$start; $i<=$end; $i++) {
}
# Display nicely too
if ($config{'format_config'} ne '0') {
&format_config(\@buf);
}
&format_config(\@buf);
$buf = join("\n", @buf);
print &ui_textarea("directives", $buf, 15, 80, undef, undef,

View File

@@ -64,7 +64,7 @@ if (!defined($start)) {
$end = @$lref - 1;
}
splice(@$lref, $start, $end-$start+1, @dirs);
&format_config($lref) if ($config{'format_config'} ne '0');
&format_config($lref);
&flush_file_lines();
if ($config{'test_manual'}) {
$err = &test_config();

View File

@@ -139,6 +139,7 @@ else {
&flush_file_lines();
&after_changing();
&unlock_file($vconf->{'file'});
&format_config_file($vconf->{'file'});
&webmin_log("virt", "save", &virtual_name($vconf, 1), \%in);
&redirect("");
}