mirror of
https://github.com/webmin/webmin.git
synced 2026-03-20 16:50:24 +00:00
allow edit and save multi line globals
This commit is contained in:
@@ -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 "<form action=save_global.cgi>\n";
|
||||
print "<table border width=100%>\n";
|
||||
print "<tr $tb> <td><b>$text{'global_header'}</b></td> </tr>\n";
|
||||
print "<tr $cb> <td><table>\n";
|
||||
print "<table border width=\"100%\">\n";
|
||||
print "<tr $tb> <td><b>$text{'global_header'}</b><div id=\"saved\">$saved</div></td> </tr>\n";
|
||||
print "<tr $cb> <td><table width=\"100%\">\n";
|
||||
|
||||
$whereami = &find_value("whereami", $conf);
|
||||
print "<tr> <td><b>$text{'global_whereami'}</b></td>\n";
|
||||
@@ -30,7 +34,26 @@ print "<tr> <td><b>$text{'global_sendmail'}</b></td>\n";
|
||||
print "<td><input name=sendmail_command size=40 value=\"$sendmail\">",
|
||||
&file_chooser_button("sendmail_command", 0),"</td> </tr>\n";
|
||||
|
||||
print "<tr>\n";
|
||||
print &multi_input("global_taboo_headers", $text{'access_theader'}, $conf);
|
||||
print "</tr>\n";
|
||||
|
||||
print "<tr>\n";
|
||||
print &multi_input("global_taboo_body", $text{'access_tbody'}, $conf);
|
||||
print "</tr>\n";
|
||||
|
||||
print "<tr> <td colspan=4>$text{'access_taboo'}</td> </tr>\n";
|
||||
|
||||
print "</table></td></tr></table>\n";
|
||||
print "<input type=submit value=\"$text{'save'}\"></form>\n";
|
||||
|
||||
&ui_print_footer("", $text{'index_return'});
|
||||
|
||||
# hide "saved" after klick
|
||||
print <<'EOF';
|
||||
<script type="text/javascript">
|
||||
function hidesaved() { document.getElementById('saved').style.display = 'none'; };
|
||||
setTimeout(hidesaved, 5000); document.onmousedown=hidesaved;
|
||||
</script>
|
||||
EOF
|
||||
|
||||
|
||||
@@ -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. <tt>foo@bar.com</tt>
|
||||
mesg_reply="Reply-To:" Adresse der Liste
|
||||
access_taboo=Hinweis: Alle Ausdrücke (regexps) der Taboo-/ und der Adressen-Liste müssen mit einem <tt>/</tt> beginnen und enden. Z.B. <tt>/foobar.de/</tt> oder <tt>/obscene/</tt>.
|
||||
access_taboo=Hinweis: Alle Ausdrücke (regexps) der Taboo-/ und der Adressen-Liste müssen mit einem <tt>/</tt> beginnen und enden. Z.B. <tt>/foobar.de/</tt> oder <tt>/obscene/</tt><br>Zum zurückweisen von SPAM tragen sie z.B. <tt>/^X-Spam-Flag: YES/i</tt> oder <tt>/^X-Spam-Level: \*\*\*\*\*/i</tt> 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)
|
||||
|
||||
@@ -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. <tt>foo@bar.com</tt>
|
||||
mesg_reply="Reply-To:" Adresse der Liste
|
||||
access_taboo=Hinweis: Alle Ausdrücke (regexps) der Taboo-/ und der Adressen-Liste müssen mit einem <tt>/</tt> beginnen und enden. Z.B. <tt>/foobar.de/</tt> oder <tt>/obscene/</tt>.
|
||||
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 <tt>/</tt> beginnen und enden. Z.B. <tt>/foobar.de/</tt> oder <tt>/obscene/</tt><br>Zum zurückweisen von SPAM tragen sie z.B. <tt>/^X-Spam-Flag: YES/i</tt> oder <tt>/^X-Spam-Level: \*\*\*\*\*/i</tt> 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)
|
||||
|
||||
@@ -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 <tt>/</tt> , like <tt>/foobar.com/</tt> or <tt>/obscene/</tt>.
|
||||
access_taboo=Note: all taboo and address regexps must begin and end with <tt>/</tt> , like <tt>/foobar.com/</tt> or <tt>/obscene/</tt><br>For purpose of SPAM rejection enter e.g. <tt>/^X-Spam-Flag: YES/i</tt> or <tt>/^X-Spam-Level: \*\*\*\*\*/i</tt> as taboo header regex.
|
||||
|
||||
head_title=Headers and Footers
|
||||
head_header=Resent email headers and footers
|
||||
|
||||
@@ -26,8 +26,8 @@ while(<CONF>) {
|
||||
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(<CONF>) {
|
||||
$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(<CONF>) {
|
||||
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(<CONF>) {
|
||||
$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(<CONF>) {
|
||||
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(<CONF>) {
|
||||
$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
|
||||
{
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user