#!/usr/bin/perl -w
###############################################################################
# HCCDns.pm - A custom API module for CPanel
# Version 0.1.1 beta - 11/MAY/2005
# (c) 2002-2005 Juan R. Pozo
# http://html.conclase.net/cp/scripts/
# mailto:jrpozo@conclase.net
# Mailing-list: http://www.conclase.net/mailman/listinfo/cpanel_conclase.net
###############################################################################
# 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 2 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, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
###############################################################################
# For INSTALLATION and DOCUMENTATION please see:
# http://html.conclase.net/cp/scripts/HCCDns.txt (plain text), or
# http://html.conclase.net/cp/scripts/HCCDns.pdf (Acrobat)
###############################################################################
# Please consider making a donation today. Visit my amazon.com wishlist at:
# http://html.conclase.net/link/wishlist
# Thank you :)
###############################################################################
package Cpanel::HCCDns;
use strict;
use vars qw(@ISA @EXPORT $VERSION $prefix);
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(
HCCDns_init
HCCDns_NameServers
HCCDns_CurrentNameServers
HCCDns_Whois
HCCDns_Dig
);
$VERSION = '0.1.1';
$prefix = "HCCDns";
Cpanel::Lang::loadlang($Cpanel::CPDATA{LANG});
require 5.004;
sub HCCDns_init {
return(1);
}
sub HCCDns_NameServers {
my $owner = $Cpanel::CPDATA{'OWNER'};
my @ns;
my $numns = 0;
reset_error();
if (-r "/var/cpanel/resellers-nameservers") {
open (NS, ") {
if (/^${owner}:(\S+)/i) {
@ns = split(",", $1);
last;
}
}
close (NS);
}
if (!@ns || !length($ns[0])) {
open (CONF, ") {
if (/^NS\d? (\S+)/) { push (@ns, $1); }
}
close (CONF);
}
foreach my $n (@ns) {
if (length($n)) {
print "
| ".(lc $n)." |
";
$numns++;
}
}
if (!$numns) {
set_error("nons", 1);
}
}
sub HCCDns_CurrentNameServers {
# These are public external servers (see http://www.open-rsc.org/)
# It's better that you use another nearer nameserver which is not
# authoritative for the domains you host and which you have access to
# (for example, a nameserver of your upstream provider, or even
# localhost if you're just using a resolver nameserver in it)
my @srv = (
"AMBER.ELEKTRON.PL", "NS1.QUASAR.NET",
"ASLAN.OPEN-RSC.ORG", "PAN.BIJT.NET"
);
my $srv = $srv[rand(@srv)];
my ($domain, $numns) = (shift, 0);
my @ns = undef;
reset_error();
if ($domain =~ /^\s*["']?([A-Za-z0-9-.]*)["']?\s*$/) {
$domain = $1;
if ($domain eq "") {
$domain = $Cpanel::CPDATA{'DNS'};
}
my $result = open(DIG, "-|");
if (!defined($result)) {
set_error("nopipe", 1);
return;
}
if (!$result) {
# child
# If you open a pipe from minus, the parent can read from the
# filehandle you opened whatever the kid writes to her STDOUT.
exec("/usr/bin/dig", "\@$srv", "$domain", "NS") or do {
set_error("nodig", 1);
exit;
};
} else {
# parent
while () {
if (/IN\s+NS\s+(\S+)\s*$/) {
my $ns = $1;
$ns =~ s/\.$//;
push (@ns, $ns);
}
}
close(DIG);
foreach my $n (sort @ns) {
if (length($n)) {
print "| ".(lc $n)." |
";
$numns++;
}
}
if (!$numns) {
set_error("nons", 1);
}
}
}
}
sub HCCDns_Whois {
my ($domain, $output) = (shift, undef);
reset_error();
if ($domain =~ /^\s*["']?([A-Za-z0-9-.]*)["']?\s*$/) {
$domain = $1;
if ($domain eq "") { $domain = $Cpanel::CPDATA{'DNS'}; }
my $result = open(WHOIS, "-|");
if (!defined($result)) {
set_error("nopipe", 1);
return;
}
if (!$result) {
exec("/usr/bin/whois", "$domain") or do {
set_error("nowhois", 1);
exit;
};
} else {
while () {
print "$_
\n";
}
close(WHOIS);
}
}
}
sub HCCDns_Dig {
my ($domain, $type) = @_;
my $output = undef;
reset_error();
if ($type =~ /^\s*['"]?(A|CNAME|MX|NS|PTR|SOA|ANY)['"]?\s*$/i) {
$type = $1;
} else {
$type = "A";
}
if ($domain =~ /^\s*["']?([A-Za-z0-9-.]*)["']?\s*$/) {
$domain = $1;
if ($domain eq "") { $domain = $Cpanel::CPDATA{'DNS'}; }
my $result = open(DIG, "-|");
if (!defined($result)) {
set_error("nopipe", 1);
return;
}
if (!$result) {
exec("/usr/bin/dig", "$domain", "$type") or do {
set_error("nodig", 1);
exit;
};
} else {
while () {
print "$_
\n";
}
close(DIG);
}
}
}
sub reset_error {
$Cpanel::CPERROR{${prefix}} = 0;
my @errors = ("nons", "nopipe", "nodig", "nowhois", "errstr");
foreach my $key (@errors) {
delete($Cpanel::CPERROR{"${prefix}_${key}"});
}
}
sub set_error {
my ($key, $value) = @_;
$Cpanel::CPERROR{${prefix}} = 1;
$Cpanel::CPERROR{"${prefix}_${key}"} = $value;
$Cpanel::CPERROR{"${prefix}_errstr"} = lang("errstr_${key}");
}
sub lang {
my ($key) = @_;
return $Cpanel::Lang::LANG{$Cpanel::CPDATA{LANG}}{"${prefix}_${key}"};
}
1;