#!/usr/local/cpanel/3rdparty/bin/perl
#WHMADDON:addonupdates:ConfigServer Mail Manage
#ACLS:configserver
###############################################################################
# Copyright (C) 2006-2025 Jonathan Michaelson
#
# https://github.com/waytotheweb/scripts
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, see .
###############################################################################
## no critic (RequireUseWarnings, ProhibitExplicitReturnUndef, ProhibitMixedBooleanOperators, RequireBriefOpen)
use strict;
use CGI::Carp qw(fatalsToBrowser);
use Sys::Hostname qw(hostname);
use IPC::Open3;
use File::Basename;
use Fcntl qw(:DEFAULT :flock);
use lib '/usr/local/cpanel';
require Cpanel::Form;
require Cpanel::Config;
require Whostmgr::ACLS;
require Cpanel::Rlimit;
require Cpanel::Template;
require Cpanel::Version::Tiny;
###############################################################################
# start main
our ($class, $day, $hrs, $images, $min, $month, $myv, $script, $subdir, $used,
$user, $versionfile, $x, $year, @localdomains, %FORM, $downloadserver);
%FORM = Cpanel::Form::parseform();
Whostmgr::ACLS::init_acls();
if (!Whostmgr::ACLS::hasroot()) {
print "Content-type: text/html\r\n\r\n";
print "You do not have access to this option.\n";
exit();
}
Cpanel::Rlimit::set_rlimit_to_infinity();
$script = "cmm.cgi";
$images = "cmm";
$versionfile = "/usr/local/cpanel/whostmgr/docroot/cgi/configserver/cmm/cmmversion.txt";
open (my $IN, "<", $versionfile) or die $!;
flock ($IN, LOCK_SH);
$myv = <$IN>;
close ($IN);
chomp $myv;
$downloadserver = &getdownloadserver;
my $thisapp = "cmm";
my $reregister;
my $modalstyle;
if ($Cpanel::Version::Tiny::major_version >= 65) {
if (-e "/usr/local/cpanel/whostmgr/docroot/cgi/configserver/${thisapp}/${thisapp}.conf") {
sysopen (my $CONF, "/usr/local/cpanel/whostmgr/docroot/cgi/configserver/${thisapp}/${thisapp}.conf", O_RDWR | O_CREAT);
flock ($CONF, LOCK_EX);
my @confdata = <$CONF>;
chomp @confdata;
for (0..scalar(@confdata)) {
if ($confdata[$_] =~ /^target=mainFrame/) {
$confdata[$_] = "target=_self";
$reregister = 1;
}
}
if ($reregister) {
seek ($CONF, 0, 0);
truncate ($CONF, 0);
foreach (@confdata) {
print $CONF "$_\n";
}
&printcmd("/usr/local/cpanel/bin/register_appconfig","/usr/local/cpanel/whostmgr/docroot/cgi/configserver/${thisapp}/${thisapp}.conf");
$reregister = "
Updated application. The next time you login to WHM this will open within the native WHM main window instead of launching a separate window
\n";
}
close ($CONF);
}
}
print "Content-type: text/html\r\n\r\n";
if ($Cpanel::Version::Tiny::major_version < 65) {
$modalstyle = "style='top:120px'";
}
my $bootstrapcss = "";
my $jqueryjs = "";
my $bootstrapjs = "";
my $templatehtml;
unless ($FORM{action} eq "viewmail") {
open SCRIPTOUT, '>', \$templatehtml;
select SCRIPTOUT;
print <
$jqueryjs
$bootstrapjs
EOF
} else {
print <
$bootstrapcss
$jqueryjs
$bootstrapjs
EOF
}
print <
ConfigServer Mail Manage - cmm v$myv
EOF
if ($reregister ne "") {print $reregister}
$| = 1; ## no critic
my $mailscanner = 0;
if (-e "/usr/mscpanel/version.txt") {$mailscanner = 1}
if ($FORM{domain} ne "" and $FORM{domain} =~ /[^\w\-\.]/) {
print "Invalid domain name [$FORM{domain}]";
}
elsif ($FORM{account} ne "" and $FORM{account} =~ /[^a-zA-Z0-9\-\_\.\@\+]/) {
print "Invalid account name [$FORM{account}]";
}
elsif ($FORM{action} eq "Manage Mail Forwarders") {
my %userdomains;
open (my $IN, "<","/etc/userdomains");
flock ($IN, LOCK_SH);
my @localusers = <$IN>;
close ($IN);
chomp @localusers;
foreach my $line (@localusers) {
my ($domain,$user) = split(/\:\s*/,$line,2);
$userdomains{$domain} = $user;
}
print "
\n";
print "
\n";
print "
Mail Forwarders for $FORM{domain}
";
print "
Forwarder
Recipient
";
my $total = 0;
open (my $VALIASES, "<", "/etc/valiases/$FORM{domain}");
flock ($VALIASES, LOCK_SH);
my @forwarders = <$VALIASES>;
close ($VALIASES);
chomp @forwarders;
foreach my $aliases (@forwarders) {
my ($alias,$recipient) = split(/: /,$aliases,2);
if ($alias eq "*") {$alias .= " (Default Address)"}
print "
$alias
$recipient
\n";
$total++;
}
unless ($total) {print "
No entries found
\n"}
print "
";
my ($childin, $childout);
my $cmdpid = open3($childin, $childout, $childout, "/usr/bin/quota", "-qlu", $userdomains{$FORM{domain}});
my @data = <$childout>;
waitpid ($cmdpid, 0);
chomp @data;
if ($data[0] =~ /Block limit reached/) {
print "
cPanel account over quota - editing disabled
";
} else {
print " ";
}
print "
\n";
print "
\n";
print "
Total Accounts: $total
\n";
print "\n";
}
elsif ($FORM{action} eq "Edit Mail Forwarders") {
open (my $IN,"<","/etc/valiases/$FORM{domain}");
flock ($IN, LOCK_SH);
my @confdata = <$IN>;
close ($IN);
chomp @confdata;
my $max = 80;
foreach my $line (@confdata) {if (length($line) > $max) {$max = length($line) + 1}}
print "\n";
print "\n";
}
elsif ($FORM{action} eq "saveforwarders") {
$FORM{formdata} =~ s/\r//g;
sysopen(my $OUT,"/etc/valiases/$FORM{domain}", O_WRONLY | O_CREAT | O_TRUNC);
flock ($OUT, LOCK_EX);
print $OUT $FORM{formdata};
close ($OUT);
my %userdomains;
open (my $IN, "<","/etc/userdomains");
flock ($IN, LOCK_SH);
my @localusers = <$IN>;
close ($IN);
chomp @localusers;
foreach my $line (@localusers) {
my ($domain,$user) = split(/\: /,$line,2);
$userdomains{$domain} = $user;
}
chown ((getpwnam($userdomains{$FORM{domain}}))[2],(getgrnam("mail"))[2],"/etc/valiases/$FORM{domain}");
print "
Changes saved.
\n";
print "\n";
}
elsif ($FORM{action} eq "Manage Mail Filters") {
my %userdomains;
open (my $IN,"<","/etc/userdomains");
flock ($IN, LOCK_SH);
my @localusers = <$IN>;
close ($IN);
chomp @localusers;
foreach my $line (@localusers) {
my ($domain,$user) = split(/\: /,$line,2);
$userdomains{$domain} = $user;
}
print "\n";
print "
\n";
print "
Mail Filters for $FORM{domain}
";
my $class = "tdshade2_noborder";
if (-z "/etc/vfilters/$FORM{domain}") {
print "
No entries found
\n";
} else {
print "
\n";
open (my $IN, "<", "/etc/vfilters/$FORM{domain}");
flock ($IN, LOCK_SH);
my @data = <$IN>;
close ($IN);
foreach my $line (@data) {
$line =~ s/&/&/g;
$line =~ s/>/>/g;
$line =~ s/</g;
print $line;
}
}
print "
\n";
print "
\n";
my ($childin, $childout);
my $cmdpid = open3($childin, $childout, $childout, "/usr/bin/quota", "-qlu", $userdomains{$FORM{domain}});
my @data = <$childout>;
waitpid ($cmdpid, 0);
chomp @data;
if ($data[0] =~ /Block limit reached/) {
print "
cPanel account over quota - editing disabled
";
} else {
print " \n";
}
print "
\n";
print "
\n";
print "\n";
}
elsif ($FORM{action} eq "Edit Mail Filters") {
open (my $IN, "<","/etc/vfilters/$FORM{domain}");
flock ($IN, LOCK_SH);
my @confdata = <$IN>;
close ($IN);
chomp @confdata;
my $max = 80;
foreach my $line (@confdata) {if (length($line) > $max) {$max = length($line) + 1}}
print "\n";
print "\n";
}
elsif ($FORM{action} eq "savefilters") {
$FORM{formdata} =~ s/\r//g;
open(my $OUT,">","/etc/vfilters/$FORM{domain}");
print $OUT $FORM{formdata};
close($OUT);
my %userdomains;
open(my $IN,"<","/etc/userdomains");
my @localusers = <$IN>;
close($IN);
chomp @localusers;
foreach my $line (@localusers) {
my ($domain,$user) = split(/\: /,$line,2);
$userdomains{$domain} = $user;
}
chown ((getpwnam($userdomains{$FORM{domain}}))[2],(getgrnam("mail"))[2],"/etc/vfilters/$FORM{domain}");
print "
Changes saved.
\n";
print "\n";
}
elsif ($FORM{action} eq "Manage Mail Hourly Limits") {
if ($FORM{domain} ne "") {
my $cpconf = Cpanel::Config::loadcpconf();
my $maxemails = $cpconf->{maxemailsperhour};
my $account;
my %userdomains;
my $usermaxemails;
my $domainmaxemails;
open(my $IN,"<","/etc/userdomains");
my @localusers = <$IN>;
close($IN);
chomp @localusers;
foreach my $line (@localusers) {
my ($domain,$user) = split(/\: /,$line,2);
$userdomains{$domain} = $user;
}
$account = $userdomains{$FORM{domain}};
open(my $DOMAIN,"<","/var/cpanel/users/$userdomains{$FORM{domain}}");
my @confdata = <$DOMAIN>;
close($DOMAIN);
chomp @confdata;
foreach my $line (@confdata) {
if ($line =~ /^MAX_EMAIL_PER_HOUR=(\d+)/) {$usermaxemails = $1}
if ($line =~ /^MAX_EMAIL_PER_HOUR-$FORM{domain}=(\d+)/) {$domainmaxemails = $1}
}
if ($usermaxemails > 0) {$maxemails = $usermaxemails}
if ($domainmaxemails > 0) {$maxemails = $domainmaxemails}
if ($maxemails eq "") {$maxemails = 0}
print "\n";
print "\n";
} else {
print "
You must select a domain first
\n";
}
print "\n";
}
elsif ($FORM{action} eq "savelimits") {
my %userdomains;
open (my $IN,"<","/etc/userdomains");
flock ($IN, LOCK_SH);
my @localusers = <$IN>;
close ($IN);
chomp @localusers;
foreach my $line (@localusers) {
my ($domain,$user) = split(/\: /,$line,2);
$userdomains{$domain} = $user;
}
open (my $USERS, "<","/var/cpanel/users/$userdomains{$FORM{domain}}");
flock ($USERS, LOCK_SH);
my @confdata = <$USERS>;
close ($USERS);
chomp @confdata;
my @newconfdata;
foreach my $line (@confdata) {
if ($line =~ /^MAX_EMAIL_PER_HOUR-$FORM{domain}=(\d+)/) {next}
push @newconfdata,$line;
}
push @newconfdata, "MAX_EMAIL_PER_HOUR-$FORM{domain}=$FORM{maxemails}";
sysopen (my $OUT, "/var/cpanel/users/$userdomains{$FORM{domain}}", O_WRONLY | O_CREAT | O_TRUNC);
flock ($OUT, LOCK_EX);
foreach my $line (@newconfdata) {print $OUT "$line\n"}
close ($OUT);
my $cmd = "/scripts/updateuserdomains";
my ($childin, $childout);
my $cmdpid = open3($childin, $childout, $childout, $cmd);
my @data = <$childout>;
waitpid ($cmdpid, 0);
chomp @data;
print "
\n";
print "\n";
}
elsif ($FORM{action} eq "deletemail") {
if (-f $FORM{file}) {
my %userdomains;
open (my $IN,"<","/etc/userdomains");
flock ($IN, LOCK_SH);
my @localusers = <$IN>;
close ($IN);
chomp @localusers;
foreach my $line (@localusers) {
my ($domain,$user) = split(/\: /,$line,2);
$userdomains{$domain} = $user;
}
my ($file, $filedir) = fileparse($FORM{file});
my $homedir = ( getpwnam($userdomains{$FORM{domain}}) )[7];
if ($homedir eq "" or $filedir !~ /^$homedir/) {
print "Invalid file [$FORM{file}]";
} else {
print "
\n";
print "
Delete Email
";
unlink $FORM{file};
my ($file, $filedir) = fileparse($FORM{file});
if (-e "$filedir/../maildirsize") {unlink "$filedir/../maildirsize"}
print "
Email deleted
\n";
print "
\n";
}
} else {
print "File [$FORM{file}] not found";
}
}
elsif ($FORM{action} eq "emptydir") {
if (-d $FORM{file}) {
my %userdomains;
open (my $IN,"<","/etc/userdomains");
flock ($IN, LOCK_SH);
my @localusers = <$IN>;
close ($IN);
chomp @localusers;
chomp @localusers;
foreach my $line (@localusers) {
my ($domain,$user) = split(/\: /,$line,2);
$userdomains{$domain} = $user;
}
my ($file, $filedir) = fileparse($FORM{file});
my $homedir = ( getpwnam($userdomains{$FORM{domain}}) )[7];
if ($homedir eq "" or $filedir !~ /^$homedir/) {
print "Invalid directory [$FORM{file}]";
} else {
my $total = 0;
print "
\n";
print "
Empty Directory [$FORM{file}]
";
print "
";
opendir (my $DIR, $FORM{file});
while (my $file = readdir($DIR)) {
if (readlink "$FORM{file}/$file") {next}
if ((-f "$FORM{file}/$file") and ($file =~ /^\d+\./)) {
print ". ";
unlink ("$FORM{file}/$file");
$total++;
}
}
if (-e "$FORM{file}/../maildirsize") {unlink "$FORM{file}/../maildirsize"}
closedir ($DIR);
print "
Total emails removed: $total
\n";
print "
Directory emptied
\n";
print "
\n";
}
} else {
print "Directory [$FORM{file}] not found";
}
}
elsif ($FORM{action} eq "salearn") {
if (-d $FORM{file}) {
my %userdomains;
open (my $IN,"<","/etc/userdomains");
flock ($IN, LOCK_SH);
my @localusers = <$IN>;
close ($IN);
chomp @localusers;
foreach my $line (@localusers) {
my ($domain,$user) = split(/\: /,$line,2);
$userdomains{$domain} = $user;
}
my ($file, $filedir) = fileparse($FORM{file});
my $homedir = ( getpwnam($userdomains{$FORM{domain}}) )[7];
if ($homedir eq "" or $filedir !~ /^$homedir/) {
print "Invalid file [$FORM{file}]";
} else {
$| = 1; ## no critic
print "
\n";
print "
Running sa-learn for spam against [$FORM{file}]
";
print "
This may take some time depending on the number of emails and the speed of SpamAssassin:
\n
\n\# /usr/local/cpanel/3rdparty/bin/sa-learn --spam --showdots $FORM{file}\n";
my ($childin, $childout);
my $cmdpid = open3($childin, $childout, $childout, "/usr/local/cpanel/3rdparty/bin/sa-learn", "--spam", "--showdots", $FORM{file});
while (<$childout>) {print $_}
waitpid ($cmdpid, 0);
print "
\n
\n";
print "
\n";
print "\n";
}
} else {
print "File [$FORM{file}] not found";
}
}
elsif ($FORM{action} eq "bulkdelete") {
my $total = 0;
my $anyfile;
my %userdomains;
open (my $IN,"<","/etc/userdomains");
flock ($IN, LOCK_SH);
my @localusers = <$IN>;
close ($IN);
chomp @localusers;
foreach my $line (@localusers) {
my ($domain,$user) = split(/\: /,$line,2);
$userdomains{$domain} = $user;
}
print "
\n";
print "
Delete Selected Mails
";
print "
";
for ($x = 1; $x <= $FORM{total} ;$x++) {
my $delfile = $FORM{"cmmdel_$x"};
if (-f $delfile) {
my ($file, $filedir) = fileparse($delfile);
my $homedir = ( getpwnam($userdomains{$FORM{domain}}) )[7];
if ($homedir eq "" or $filedir !~ /^$homedir/) {
print "Invalid file [$delfile]";
} else {
unlink ($delfile);
$total++;
$anyfile = $delfile;
}
}
}
my ($file, $filedir) = fileparse($anyfile);
if (-d $filedir) {
my $homedir = ( getpwnam($userdomains{$FORM{domain}}) )[7];
if ($homedir eq "" or $filedir !~ /^$homedir/) {
print "Invalid directory [$filedir]";
} else {
if (-e "$filedir/../maildirsize") {unlink "$filedir/../maildirsize"}
}
}
print "
Total emails removed: $total
\n";
print "
\n";
print "\n";
}
elsif ($FORM{action} eq "changequota") {
my %userdomains;
open (my $IN,"<","/etc/userdomains");
flock ($IN, LOCK_SH);
my @localusers = <$IN>;
close ($IN);
chomp @localusers;
foreach my $line (@localusers) {
my ($domain,$user) = split(/\: /,$line,2);
$userdomains{$domain} = $user;
}
if (($FORM{quota} =~ /[^\d\.]/) or ($FORM{quota} == 0)) {$FORM{quota} = "unlimited"}
print "
\n";
print "
Change Quota for $FORM{account}\@$FORM{domain}
";
print "
";
eval {
local $) = local $(; ## no critic
local $> = local $<; ## no critic
local $ENV{'REMOTE_USER'} = $user;
&drop($userdomains{$FORM{domain}});
my ($childin, $childout);
my $cmdpid = open3($childin, $childout, $childout, "/usr/local/cpanel/cpanel-email", "editquota", $FORM{account}, $FORM{domain}, $FORM{quota});
my @data = <$childout>;
waitpid ($cmdpid, 0);
chomp @data;
my $cnt = 0;
foreach my $line (@data) {
if ($line =~ /^stdin: is not a tty/) {next}
if ($line =~ /^[\r\n]/) {next}
if ($line =~ /^ /) {next}
print "
$line
\n";
$cnt++;
}
unless ($cnt) {print "
Quota changed to $FORM{quota} MB
\n"}
};
print "
\n";
print "
\n";
print "\n";
}
elsif ($FORM{action} eq "password") {
print "\n";
print "\n";
}
elsif ($FORM{action} eq "Change Password") {
my %userdomains;
open (my $IN,"<","/etc/userdomains");
flock ($IN, LOCK_SH);
my @localusers = <$IN>;
close ($IN);
chomp @localusers;
foreach my $line (@localusers) {
my ($domain,$user) = split(/\: /,$line,2);
$userdomains{$domain} = $user;
}
print "
\n";
print "
Change Password for $FORM{account}\@$FORM{domain}
";
if ($FORM{password} eq "") {
print "
Failed: Empty password field
\n";
}
elsif ($FORM{password} ne $FORM{confirmpassword}) {
print "
Failed: Passwords do not match
\n";
}
elsif ($FORM{password} =~ /\"/) {
print "
Failed: password must not contain quotes
\n";
}
else {
print "
\n";
eval {
local $) = local $(; ## no critic
local $> = local $<; ## no critic
local $ENV{'REMOTE_USER'} = $user;
&drop($userdomains{$FORM{domain}});
my ($childin, $childout);
my $cmdpid = open3($childin, $childout, $childout, "/usr/local/cpanel/cpanel-email", "passwdpop", $FORM{account}, "$FORM{password}", "0", $FORM{domain});
my @data = <$childout>;
waitpid ($cmdpid, 0);
chomp @data;
my $cnt = 0;
foreach my $line (@data) {
if ($line =~ /^stdin: is not a tty/) {next}
print "
$line
\n";
$cnt++;
}
unless ($cnt) {print "
Password changed
\n"}
};
}
print "
\n";
print "\n";
}
elsif ($FORM{action} eq "delete") {
print "\n";
print "\n";
}
elsif ($FORM{action} eq "Delete Mailbox") {
my %userdomains;
open (my $IN,"<","/etc/userdomains");
flock ($IN, LOCK_SH);
my @localusers = <$IN>;
close ($IN);
chomp @localusers;
foreach my $line (@localusers) {
my ($domain,$user) = split(/\: /,$line,2);
$userdomains{$domain} = $user;
}
print "
\n";
print "
Delete Mailbox $FORM{account}\@$FORM{domain}
";
print "
\n";
eval {
local $) = local $(; ## no critic
local $> = local $<; ## no critic
local $ENV{'REMOTE_USER'} = $user;
&drop($userdomains{$FORM{domain}});
my ($childin, $childout);
my $cmdpid = open3($childin, $childout, $childout, "/usr/local/cpanel/cpanel-email", "delpop", $FORM{account}, "0", $FORM{domain});
my @data = <$childout>;
waitpid ($cmdpid, 0);
chomp @data;
my $cnt = 0;
foreach my $line (@data) {
if ($line =~ /^stdin: is not a tty/) {next}
print "
$line
\n";
$cnt++;
}
print "
Account deleted
\n";
};
print "
\n";
print "\n";
}
elsif ($FORM{action} eq "Add Mailbox") {
my %userdomains;
open (my $IN,"<","/etc/userdomains");
flock ($IN, LOCK_SH);
my @localusers = <$IN>;
close ($IN);
chomp @localusers;
foreach my $line (@localusers) {
my ($domain,$user) = split(/\: /,$line,2);
$userdomains{$domain} = $user;
}
if (($FORM{quota} =~ /[^\d\.]/) or ($FORM{quota} == 0)) {$FORM{quota} = "unlimited"}
print "
\n";
print "
Add Mailbox $FORM{account}\@$FORM{domain}
";
if ($FORM{password} eq "") {
print "
Failed: Empty password field
\n";
}
elsif ($FORM{password} ne $FORM{confirmpassword}) {
print "
Failed: Passwords do not match
\n";
}
elsif ($FORM{password} =~ /\"/) {
print "
Failed: password must not contain quotes
\n";
}
else {
print "
\n";
eval {
local $) = local $(; ## no critic
local $> = local $<; ## no critic
local $ENV{'REMOTE_USER'} = $user;
&drop($userdomains{$FORM{domain}});
my ($childin, $childout);
my $cmdpid = open3($childin, $childout, $childout, "/usr/local/cpanel/cpanel-email", "addpop", $FORM{account}, "$FORM{password}", $FORM{quota}, $FORM{domain});
my @data = <$childout>;
waitpid ($cmdpid, 0);
chomp @data;
my $cnt = 0;
foreach my $line (@data) {
if ($line =~ /^stdin: is not a tty/) {next}
print "
$line
\n";
$cnt++;
}
print "
Account created
\n";
};
print "
\n";
}
print "
\n";
print "\n";
}
elsif (($FORM{action} =~ /^Mail Quota Report \((.*)\)/) or ($FORM{action} eq "Manage Mail Accounts")) {
my $report = $1;
my $total = 0;
my $colspan = 5;
my $extracol = "
\n";
my @localdomains;
open (my $IN,"<","/etc/userdomains");
flock ($IN, LOCK_SH);
while (my $entry = <$IN>) {
chomp $entry;
my ($domain,$user) = split(/:\s*/,$entry);
if ($user eq "nobody") {next}
if ($domain eq "") {next}
if ($domain eq "*") {next}
push @localdomains, $domain;
}
close($IN);
my $client = Cpanel::GreyList::Client->new();
$client->disable_opt_out_for_domains(\@localdomains);
print "\n";
}
elsif ($FORM{action} eq "Bulk Show GreyListing") {
require Cpanel::GreyList::Client;
print "
\n";
my @localdomains;
open (my $IN,"<","/etc/userdomains");
flock ($IN, LOCK_SH);
my @entries = <$IN>;
close ($IN);
chomp @entries;
foreach my $entry (sort @entries) {
chomp $entry;
my ($domain,$user) = split(/:\s*/,$entry);
if ($user eq "nobody") {next}
if ($domain eq "") {next}
if ($domain eq "*") {next}
my $client = Cpanel::GreyList::Client->new();
if ($client->is_greylisting_enabled($domain)) {
print "
\n";
my @domains;
my $client = Cpanel::GreyList::Client->new();
@domains = ($FORM{domain});
$client->enable_opt_out_for_domains(\@domains);
}
print "\n";
}
elsif ($FORM{action} eq "upgrade") {
$| = 1; ## no critic
print "
";
if (-e "/usr/src/cmm.tgz") {unlink ("/usr/src/cmm.tgz") or die $!}
print "Retrieving new cmm package...\n";
my ($status, $text) = &urlget("https://$downloadserver/cmm.tgz","/usr/src/cmm.tgz");
if ($status) {print "Oops: $text\n"}
if (! -z "/usr/src/cmm.tgz") {
print "Unpacking new cmm package...\n";
print "
";
&printcmd("cd /usr/src ; tar -xzf cmm.tgz ; cd cmm ; sh install.sh 2>&1");
print "
";
print "Tidying up...\n";
print "
";
&printcmd("rm -Rfv /usr/src/cmm*");
print "
";
print "...All done.\n";
}
print "
";
open (my $IN, "<",$versionfile) or die $!;
flock ($IN, LOCK_SH);
$myv = <$IN>;
close ($IN);
chomp $myv;
print "\n";
}
else {
open (my $IN, "<","/etc/userdomains");
flock ($IN, LOCK_SH);
while (my $entry = <$IN>) {
chomp $entry;
my ($domain,$user) = split(/:\s*/,$entry);
if ($user eq "nobody") {next}
push @localdomains, $domain;
}
close ($IN);
@localdomains = sort @localdomains;
my $domainlist;
my $domaincnt;
foreach my $domain (@localdomains) {
$domainlist .= "\n";
$domaincnt ++;
}
print "\n";
}
print "