#!/usr/local/bin/perl
# list_masq.cgi
# List domains for which masquerading is done

require './sendmail-lib.pl';
$access{'masq'} || &error($text{'masq_ecannot'});
&header($text{'masq_title'}, "");
print "<hr>\n";
$conf = &get_sendmailcf();

# Get the domain we masquerade as
foreach $d (&find_type("D", $conf)) {
	if ($d->{'value'} =~ /^M\s*(\S*)/) { $masq = $1; }
	}

# Get masq domains from a file
foreach $f (&find_type("F", $conf)) {
	if ($f->{'value'} =~ /^M[^\/]*(\S*)/) { $cmfile = $1; }
	} 
if ($cmfile) {
	open(CM, $cmfile);
	while(<CM>) {
		s/\r|\n//g;
		s/#.*$//g;
		if (/\S/) { push(@mlist, $_); }
		}
	close(CM);
	}

# Add domains from sendmail.cf
foreach $m (&find_type("C", $conf)) {
	if ($m->{'value'} =~ /^M\s*(.*)$/) {
		push(@mlist, split(/\s+/, $1));
		}
	}
print "<form method=post action=save_masq.cgi enctype=multipart/form-data>\n";
print "<input type=hidden name=cmfile value=\"$cmfile\">\n";
print "<b>$text{'masq_domain'}</b>\n";
print "<input name=masq size=30 value=\"$masq\"><br>\n";

print "<table cellpadding=5 width=100%><tr><td valign=top nowrap>\n";
print "<b>$text{'masq_domains'}</b><br>\n";
print "<textarea name=mlist rows=15 cols=65>",
	join("\n", @mlist),"</textarea><br>\n";
print "<input type=submit value=\"$text{'save'}\">\n";

print "</td><td valign=top>\n";
print &text('masq_desc1', 'list_generics.cgi'),"<p>\n";
print $text{'masq_desc2'},"\n";
print "</td></tr></table>\n";
print "</form>\n";

print "<hr>\n";
&footer("", $text{'index_return'});

