Current File : //scripts/addtorsdcli
#!/usr/local/cpanel/3rdparty/bin/perl

use URI;
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
use Net::DNS qw();


$password = "iag9kaiK3aih4aishej8qu";

$configFileName = "/usr/local/scripts/changemx.conf";
open ( _FH, $configFileName ) or die "Unable to open config file: $!";

$domain = shift;
$mailhost = shift;

if ($domain eq "") {
	$erro ="Usage: /scripts/addtorsd domain.dom mailhost.for.domain.dom";
	print $erro."\n";
	die "\n";
}
if ($mailhost eq "") {
	$erro ="Usage: /scripts/addtorsd domain.dom mailhost.for.domain.dom";
	print $erro."\n";
	die "\n";
}

my $query = Net::DNS::Resolver->new->search($mailhost);

if ($query) {
    foreach my $rr ($query->answer) {
        next unless 'CNAME' eq $rr->type;
	print "$mailhost is a CNAME and cannot be used as a destination. Change it to A record or use the server's name instead. \n";
	die "\n";
    }
}

my $url      = 'http://rsd.cleanmx.pt/newcli.php';

my $ua = LWP::UserAgent->new;
my $result = $ua->request(POST $url, [
  password => $password,
  domain => $domain,
  mailserver => $mailhost,
]);

$cmd = "/usr/local/scripts/changemx.pl -d $domain";
system($cmd);

#print $result->as_string;