From 0e77146a48ee6d7f87fa11cd1bf317b755b6fbdf Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 7 Jun 2017 14:58:01 +0200 Subject: [PATCH] allow edit and save multi line globals --- majordomo/edit_global.cgi | 29 +++++- majordomo/lang/de | 3 +- majordomo/lang/de.UTF-8 | 3 +- majordomo/lang/en | 3 +- majordomo/majordomo-lib.pl | 189 ++++++++++++++++++++----------------- majordomo/save_global.cgi | 4 +- 6 files changed, 139 insertions(+), 92 deletions(-) diff --git a/majordomo/edit_global.cgi b/majordomo/edit_global.cgi index 36f45d58f..5d6138938 100755 --- a/majordomo/edit_global.cgi +++ b/majordomo/edit_global.cgi @@ -1,17 +1,21 @@ #!/usr/local/bin/perl # edit_global.cgi # Edit global majordomo options +use Data::Dump 'dump'; require './majordomo-lib.pl'; +&ReadParse(); + $conf = &get_config(); %access = &get_module_acl(); $access{'global'} || &error($text{'global_ecannot'}); &ui_print_header(undef, $text{'global_title'}, ""); +$saved = $text{'global_saved'} if $in{'saved'}; print "
\n"; -print "\n"; -print "\n"; -print "
$text{'global_header'}
\n"; +print "
\n"; +print "\n"; +print "
$text{'global_header'}
$saved
\n"; $whereami = &find_value("whereami", $conf); print "\n"; @@ -30,7 +34,26 @@ print "\n"; print "\n"; +print "\n"; +print &multi_input("global_taboo_headers", $text{'access_theader'}, $conf); +print "\n"; + +print "\n"; +print &multi_input("global_taboo_body", $text{'access_tbody'}, $conf); +print "\n"; + +print "\n"; + print "
$text{'global_whereami'}
$text{'global_sendmail'}", &file_chooser_button("sendmail_command", 0),"
$text{'access_taboo'}
\n"; print "\n"; &ui_print_footer("", $text{'index_return'}); + +# hide "saved" after klick +print <<'EOF'; + +EOF + diff --git a/majordomo/lang/de b/majordomo/lang/de index b2d441e1c..214c754e6 100644 --- a/majordomo/lang/de +++ b/majordomo/lang/de @@ -42,7 +42,7 @@ mesg_emaxlength=Fehlende oder ungültige Einstellung der maximalen Nachricht digest_lines=Linien members_eunsubaddr=Die Adresse, die entfernt werden soll muss einen kompletten Domainnamen besitzen, z.B. foo@bar.com mesg_reply="Reply-To:" Adresse der Liste -access_taboo=Hinweis: Alle Ausdrücke (regexps) der Taboo-/ und der Adressen-Liste müssen mit einem / beginnen und enden. Z.B. /foobar.de/ oder /obscene/. +access_taboo=Hinweis: Alle Ausdrücke (regexps) der Taboo-/ und der Adressen-Liste müssen mit einem / beginnen und enden. Z.B. /foobar.de/ oder /obscene/
Zum zurückweisen von SPAM tragen sie z.B. /^X-Spam-Flag: YES/i oder /^X-Spam-Level: \*\*\*\*\*/i als nicht erlaubte Kopfzeile ein. log_info=Aktualisierte Nachrichten und Beschreibungen der Liste $1 log_create_list=Mailingliste wurde erstellt: $1 delete_aliases=Diese Mail-Aliase werden ebenfalls entfernt : @@ -224,3 +224,4 @@ index_mail=Mail Adresse index_moderated=Modieriert index_count=# Teilnehmer create_minimum=Mindestens erforderlich Angaben +global_saved=(gespeichert) diff --git a/majordomo/lang/de.UTF-8 b/majordomo/lang/de.UTF-8 index 0b331cfcf..aab1f5ff0 100644 --- a/majordomo/lang/de.UTF-8 +++ b/majordomo/lang/de.UTF-8 @@ -42,8 +42,8 @@ mesg_emaxlength=Fehlende oder ungültige Einstellung der maximalen Nachrichtengr digest_lines=Linien members_eunsubaddr=Die Adresse, die entfernt werden soll muss einen kompletten Domainnamen besitzen, z.B. foo@bar.com mesg_reply="Reply-To:" Adresse der Liste -access_taboo=Hinweis: Alle Ausdrücke (regexps) der Taboo-/ und der Adressen-Liste müssen mit einem / beginnen und enden. Z.B. /foobar.de/ oder /obscene/. log_info=Aktualisierte Nachrichten und Beschreibungen der Liste $1 +access_taboo=Hinweis: Alle Ausdrücke (regexps) der Taboo-/ und der Adressen-Liste müssen mit einem / beginnen und enden. Z.B. /foobar.de/ oder /obscene/
Zum zurückweisen von SPAM tragen sie z.B. /^X-Spam-Flag: YES/i oder /^X-Spam-Level: \*\*\*\*\*/i als nicht erlaubte Kopfzeile ein. log_create_list=Mailingliste wurde erstellt: $1 delete_aliases=Diese Mail-Aliase werden ebenfalls entfernt : info_below=So wie unten eingetragen... @@ -224,3 +224,4 @@ index_mail=Mail Adresse index_moderated=Modieriert index_count=# Teilnehmer create_minimum=Mindestens erforderlich Angaben +global_saved=(gespeichert) diff --git a/majordomo/lang/en b/majordomo/lang/en index 1101da840..6b985319e 100644 --- a/majordomo/lang/en +++ b/majordomo/lang/en @@ -36,6 +36,7 @@ global_ewhereami=Missing or invalid mail server hostname global_ewhoami=Missing or invalid Majordomo address global_eowner=Missing or invalid owner's address global_esendmail=Sendmail command '$1' does not exist +global_saved=(saved) create_ecannot=You are not allowed to create new lists create_title=Create Mailing List @@ -184,7 +185,7 @@ access_res1=List members access_res2=Addresses in file access_tbody=Taboo body regexps access_theader=Taboo header regexps -access_taboo=Note: all taboo and address regexps must begin and end with / , like /foobar.com/ or /obscene/. +access_taboo=Note: all taboo and address regexps must begin and end with / , like /foobar.com/ or /obscene/
For purpose of SPAM rejection enter e.g. /^X-Spam-Flag: YES/i or /^X-Spam-Level: \*\*\*\*\*/i as taboo header regex. head_title=Headers and Footers head_header=Resent email headers and footers diff --git a/majordomo/majordomo-lib.pl b/majordomo/majordomo-lib.pl index 11e1f9854..32b219023 100755 --- a/majordomo/majordomo-lib.pl +++ b/majordomo/majordomo-lib.pl @@ -26,8 +26,8 @@ while() { elsif (/^\s*\$(\S+)\s*=\s*<<\s*'(\S+)';\s*$/) { # multiline config option local $o = { 'name' => $1, - 'line' => $2 }; - local $end = $3; + 'line' => $line }; + local $end = $2; while() { $line++; last if ($_ =~ /^$end[\r\n]+$/); @@ -57,7 +57,46 @@ close(CONF); return \@rv; } -# save_directive(&config, name, value) +# get_list_config(file) +sub get_list_config +{ +local(@rv, $line); +$line = 0; +open(CONF, $_[0]); +while() { + s/\r|\n//g; + s/#.*$//g; + if (/^\s*(\S+)\s*=\s*(.*)$/) { + # single value + push(@rv, { 'name' => $1, + 'value' => $2, + 'index' => scalar(@rv), + 'line' => $line, + 'eline' => $line }); + } + elsif (/^\s*(\S+)\s*<<\s*(\S+)/) { + # multi-line value + local $c = { 'name' => $1, + 'index' => scalar(@rv), + 'line' => $line }; + local $end = $2; + while() { + $lnum++; + last if (/^$end[\r\n]+$/); + s/^--/-/; + s/^-\n/\n/; + $c->{'value'} .= $_; + } + $c->{'eline'} = $line; + push(@rv, $c); + } + $line++; + } +return \@rv; +} + + +# save_directive(&config, name, value, multiline) # Update some directive in the global config file sub save_directive { @@ -65,18 +104,67 @@ local $old = &find($_[1], $_[0]); return if (!$old); local $lref = &read_file_lines($config{'majordomo_cf'}); local $olen = $old->{'eline'} - $old->{'line'} + 1; +local $pos = $old->{'line'}; local $v = $_[2]; $v =~ s/\n$//; -if ($v =~ /\n/) { - splice(@$lref, $old->{'line'}, $olen, - ( "\$$_[1] = <<'END';", split(/\n/, $v, -1), "END" )); + +if ($_[3]) { + local $ov = $old->{'value'}; + $ov =~ s/\n$//; + local $v = $_[2]; + $v =~ s/\n$//; + local @lines = split(/\n/, $v, -1); + @lines = map { s/^-/--/; s/^$/-/; $_ } @lines; + splice(@$lref, $pos, $olen, ("\$$_[1] = <<'END';", @lines, "END")) + if (!$old || $v ne $ov); + $nlen = (!$old || $v ne $ov) ? @lines + 2 : $olen; } else { $v =~ s/\@/\\@/g; - splice(@$lref, $old->{'line'}, $olen, "\$$_[1] = \"$v\";"); + splice(@$lref, $pos, $olen, "\$$_[1] = \"$v\";"); } } +# save_list_directive(&config, file, name, value, multiline) +sub save_list_directive +{ +local $old = &find($_[2], $_[0]); +local $lref = &read_file_lines($_[1]); +local ($pos, $olen, $nlen); +if ($old) { + $olen = $old->{'eline'} - $old->{'line'} + 1; + $pos = $old->{'line'}; + } +else { + $olen = 0; + $pos = @$lref; + } +if ($_[4]) { + local $ov = $old->{'value'}; + $ov =~ s/\n$//; + local $v = $_[3]; + $v =~ s/\n$//; + local @lines = split(/\n/, $v, -1); + @lines = map { s/^-/--/; s/^$/-/; $_ } @lines; + splice(@$lref, $pos, $olen, ("$_[2] << END", @lines, "END")) + if (!$old || $v ne $ov); + $nlen = (!$old || $v ne $ov) ? @lines + 2 : $olen; + } +else { + splice(@$lref, $pos, $olen, "$_[2] = $_[3]") + if (!$old || $_[3] ne $old->{'value'}); + $nlen = 1; + } +if ($old && $nlen != $olen) { + foreach $c (@{$_[0]}) { + if ($c->{'line'} > $old->{'eline'}) { + $c->{'line'} += ($nlen - $olen); + $c->{'eline'} += ($nlen - $olen); + } + } + } +} + # find(name, &array) sub find { @@ -133,84 +221,6 @@ $list{'owner'} = "$ldir/$_[0].owner"; return \%list; } -# get_list_config(file) -sub get_list_config -{ -local(@rv, $line); -$lnum = 0; -open(CONF, $_[0]); -while() { - s/\r|\n//g; - s/#.*$//g; - if (/^\s*(\S+)\s*=\s*(.*)$/) { - # single value - push(@rv, { 'name' => $1, - 'value' => $2, - 'index' => scalar(@rv), - 'line' => $lnum, - 'eline' => $lnum }); - } - elsif (/^\s*(\S+)\s*<<\s*(\S+)/) { - # multi-line value - local $c = { 'name' => $1, - 'index' => scalar(@rv), - 'line' => $lnum }; - local $end = $2; - while() { - $lnum++; - last if (/^$end[\r\n]+$/); - s/^--/-/; - s/^-\n/\n/; - $c->{'value'} .= $_; - } - $c->{'eline'} = $lnum; - push(@rv, $c); - } - $lnum++; - } -return \@rv; -} - -# save_list_directive(&config, file, name, value, multiline) -sub save_list_directive -{ -local $old = &find($_[2], $_[0]); -local $lref = &read_file_lines($_[1]); -local ($pos, $olen, $nlen); -if ($old) { - $olen = $old->{'eline'} - $old->{'line'} + 1; - $pos = $old->{'line'}; - } -else { - $olen = 0; - $pos = @$lref; - } -if ($_[4]) { - local $ov = $old->{'value'}; - $ov =~ s/\n$//; - local $v = $_[3]; - $v =~ s/\n$//; - local @lines = split(/\n/, $v, -1); - @lines = map { s/^-/--/; s/^$/-/; $_ } @lines; - splice(@$lref, $pos, $olen, ("$_[2] << END", @lines, "END")) - if (!$old || $v ne $ov); - $nlen = (!$old || $v ne $ov) ? @lines + 2 : $olen; - } -else { - splice(@$lref, $pos, $olen, "$_[2] = $_[3]") - if (!$old || $_[3] ne $old->{'value'}); - $nlen = 1; - } -if ($old && $nlen != $olen) { - foreach $c (@{$_[0]}) { - if ($c->{'line'} > $old->{'eline'}) { - $c->{'line'} += ($nlen - $olen); - $c->{'eline'} += ($nlen - $olen); - } - } - } -} - # get_aliases_file() # Returns the paths to the sendmail-style aliases files sub get_aliases_file @@ -391,6 +401,15 @@ $in{$_[2]} =~ s/\r//g; &save_list_directive($_[0], $_[1], $_[2], $in{$_[2]}, 1); } +# save_multi_global(&config, name) +sub save_multi_global +{ +$in{$_[1]} =~ s/\r//g; +&save_directive($_[0], $_[1], $in{$_[1]}, 1); +} + + + # can_edit_list(&access, name) sub can_edit_list { diff --git a/majordomo/save_global.cgi b/majordomo/save_global.cgi index 2406e73e7..c177aad9b 100755 --- a/majordomo/save_global.cgi +++ b/majordomo/save_global.cgi @@ -25,8 +25,10 @@ $in{'whoami_owner'} =~ /^\S+$/ || &save_directive($conf, "whoami", $in{'whoami'}); &save_directive($conf, "whoami_owner", $in{'whoami_owner'}); &save_directive($conf, "sendmail_command", $in{'sendmail_command'}); +&save_multi_global($conf, "global_taboo_body"); +&save_multi_global($conf, "global_taboo_headers"); &flush_file_lines(); &unlock_file($config{'majordomo_cf'}); &webmin_log("global", undef, undef, \%in); -&redirect(""); +&redirect("edit_global.cgi?saved=true");