#!/usr/bin/perl

print "Content-Type: Text/HTML\n\n";

use CGI ':standard';
use Vpanel 1.00;
use Data::Dumper;
require $header;
require $accountinfo;

$domainname = find_domain ($mainuser);
#$spam_whitelist = "$whitelistdir$domainname";
$num_addresses = 0;

# Define the tab which appears to the front
$tab_section = $tabnum_mailwall;

# Output the content associated with this tab
print "<body class=section-$tab_section>";

# display tabs
require $tabdisplay;

print_header("Amending the spam whitelist for $domainname");

print "<form method=post action=/$script_bin/$confirm_add_to_spam_whitelist class=text>";


$ret = php_request ("getWhiteList", "scope=domain:$domainname");
@whitelist_addresses = ();
if (defined ($ret) && ref ($ret) eq "HASH") {
	# ADD GREP HERE
	%ret = %{$ret};
	@whitelist_addresses = split /,/, $ret{'whitelist'};
}

if ( scalar (@whitelist_addresses) > 0)
{
	# ensure that the input is not an ipaddress and is also not 127.0.0.1
	#	if ( (is_ip_address_syntax_correct($_) eq "no") && (!($_ =~ "127.0.0.1")) )
	#	{
	#		push @whitelist_addresses, $_;
	#	}

	$num_whitelist_addresses = @whitelist_addresses;
	print qq!

	Below are a list of email addresses which you  currently have whitelisted. If you wish to remove any of these email
	adresses from your whitelist please uncheck the relevant box.<BR><BR>
	<table width=40% class=text border=0>
	!;

	for $_ (@whitelist_addresses)
	{
		print "<tr><td width=20%>$_</td><td><input type=checkbox name=addresses value=$_ checked></td></tr>";
	}
	print "</table><BR>";
}

print "<input type=hidden name=numaddresses value=$num_whitelist_addresses>";

print qq!
	If you wish to add an address to your whitelist please type the email address in the box below:<BR>
	<BR>Email address: <input type=text class=text name=newaddress size=40>
!;

print_end_of_form();

require $footer;
