Class Dnslib
Class Dnslib
Class Dnslib
php
// IPplan v4.92b
//
//
//
// You should have received a copy of the GNU General Public License
//
// versions of php
require_once(dirname(__FILE__)."/config.php");
// form variables
var $hname;
var $ttl;
var $refresh;
var $retry;
var $expire;
var $minimum;
var $responsiblemail;
var $slaveonly;
var $zonepath;
var $seczonepath;
var $info="";
var $serialdate=0;
var $serialnum=0;
var $grps;
var $err = 1;
var $clone = 0;
$this->hname = $hname;
$this->ttl = $ttl;
$this->refresh = $refresh;
$this->retry = $retry;
$this->expire = $expire;
$this->minimum = $minimum;
$this->responsiblemail = $responsiblemail;
$this->slaveonly = $slaveonly;
$this->zonepath = $zonepath;
$this->seczonepath = $seczonepath;
$this->info = $info;
$this->serialdate=$serialdate;
$this->serialnum=$serialnum;
function Serial() {
$now = getdate();
if ($this->serialdate==$newserialdate) {
$this->serialnum++;
}else{
$this->serialdate=$newserialdate;
$this->serialnum=0;
$hname=strtolower($hname);
$domain=strtolower($domain);
if ($hname===$temp) {
$temp=$hname.".";
return $temp;
require_once("Net/DNS.php");
//$res->debug = 1;
$res->persistent_tcp=1;
$res->nameservers=array($server);
$answer = $res->axfr($domain);
/*
echo "<pre>";
var_dump($answer);
//var_dump($res);
//var_dump($answer[0]->header->rcode);
echo "</pre>";
exit;
*/
/*
if ($res->errorstring != "NOERROR") {
$this->err=70;
$this->errstr .= sprintf(my_("Zone transfer for domain %s failed with message %s"), $this-
>domain, $res->errorstring)."\n";
return "";
*/
if ($answer) {
foreach($answer as $rr) {
if ($rr->type == "SOA") {
//var_dump($rr);
$this->ttl=$rr->ttl;
$this->refresh=$rr->refresh;
$this->retry=$rr->retry;
$this->expire=$rr->expire;
$this->minimum=$rr->minimum;
$this->responsiblemail=$rr->rname;
$this->hname[$i++]=$this->strip_domain($rr->nsdname, $this->domain);
}
$this->err = 0;
return $answer;
} else {
$this->errstr .= sprintf(my_("Zone transfer for domain %s failed - using defaults: %s"), $this-
>domain, $res->errorstring)."\n";
$this->err = -1;
return "";
var $cust;
var $dataid;
var $domain;
var $server;
var $createmod;
var $expiremod;
var $regmod;
$this->cust = $cust;
$this->dataid = $dataid;
$this->domain = $domain;
$this->createmod = $createmod;
$this->expiremod = $expiremod;
$this->regmod = $regmod;
$this->cust = $cust;
$this->rangeindex = $dataid;
$this->areaindex = $domain;
FROM fwdzonerec
if ($recs) {
$this->err=50;
$this->errstr .= my_("Cannot delete domain zone - there are still DNS records\n");
return FALSE;
WHERE id=$dataid");
return $result;
$i=5;
foreach($answer as $rr) {
if ($rr->type == "A") {
$recordtype=$rr->type;
$host=$this->strip_domain($rr->name, $this->domain);
$iphostname=$rr->address;
$recordtype=$rr->type;
$host=$this->strip_domain($rr->name, $this->domain);
$iphostname=$this->strip_domain($rr->cname, $this->domain);
}
else if ($rr->type == "NS" and $rr->name != $this->domain) {
$recordtype=$rr->type;
$host=$this->strip_domain($rr->name, $this->domain);
$iphostname=$this->strip_domain($rr->nsdname, $this->domain);
$recordtype=$rr->type;
$host=$this->strip_domain($rr->name, $this->domain);
$recordtype=$rr->type;
$host=$this->strip_domain($rr->name, $this->domain);
$recordtype=$rr->type;
$host=$this->strip_domain($rr->name, $this->domain);
$recordtype=$rr->type;
$host=$this->strip_domain($rr->name, $this->domain);
else {
continue;
}
$this->ds->DBTimeStamp(time()).",".
$this->ds->qstr($host).",".
$this->ds->qstr($recordtype).",".
$this->ds->qstr(getAuthUsername()).",".
$this->ds->qstr($iphostname).")" );
if (!$result) {
return FALSE;
$i=$i+5;
return TRUE;
function FwdAddNS($dataid) {
$hnametemp=$this->hname[$i];
VALUES
($dataid,
".$this->ds->qstr($hnametemp).",
$i)");
if (!$result) {
return FALSE;
return TRUE;
FROM fwdzone
return !empty($row);
$this->cust = $cust;
if (!$this->FwdZoneExists($cust, $dataid)) {
$this->err=90;
$this->errstr .= my_("Could not find the zone - possibly deleted by another user")."\n";
return FALSE;
$this->Serial();
if ($this->slaveonly=="Y") {
FROM fwdzonerec
$row = $result->FetchRow();
if($row["cnt"] > 0) {
$this->err=-50;
$this->errstr .= my_("You are changing this zone to a slave only zone, but there are zone
records\n");
// Updated DB here.
"set serialdate=".$this->ds->qstr($this->serialdate).
", serialnum=$this->serialnum".
",ttl=".$this->ttl.
",refresh=".$this->refresh.
",retry=".$this->retry.
",expire=".$this->expire.
",minimum=".$this->minimum.
",error_message=".$this->ds->qstr("E").
",responsiblemail=".$this->ds->qstr($this->responsiblemail).
",userid=".$this->ds->qstr(getAuthUsername()).
",zonefilepath1=".$this->ds->qstr($this->zonepath).
",zonefilepath2=".$this->ds->qstr($this->seczonepath).
",createmod=".$this->ds->DBDate($this->createmod).
",lastmod=".$this->ds->DBTimeStamp(time()).
",expiremod=".$this->ds->DBDate($this->expiremod).
",regmod=".$this->ds->DBDate($this->regmod).
",slaveonly=".$this->ds->qstr($this->slaveonly).
if($this->ds->GetRow("SELECT info
FROM fwdzoneadd
"set info=".$this->ds->qstr($this->info).
if (!empty($this->info)) {
$dataid.",".
$this->ds->qstr($this->info).")" );
WHERE id=$dataid");
$this->FwdAddNS($dataid);
return $result;
function FwdAddSOA() {
$this->Serial();
// Add to DB here.
"VALUES ($this->cust,".
$this->ds->qstr($this->domain).",".
$this->ds->qstr("E").",".
$this->ds->DBDate($this->createmod).",".
$this->ds->DBTimeStamp(time()).",".
$this->ds->DBDate($this->expiremod).",".
$this->ds->DBDate($this->regmod).",".
$this->ds->qstr($this->serialdate).", $this->serialnum,".
$this->ttl.",".
$this->refresh.",".
$this->retry.",".
$this->expire.",".
$this->minimum.",".
$this->ds->qstr($this->responsiblemail).",".
$this->ds->qstr(getAuthUsername()).",".
$this->ds->qstr($this->zonepath).",".
$this->ds->qstr($this->seczonepath).",".
$this->ds->qstr($this->slaveonly).")" );
if ($result) {
if (DBF_TYPE=="mysql" or DBF_TYPE=="maxsql") {
$dataid=$this->ds->Insert_ID();
else {
$result=$this->ds->Execute("SELECT data_id
FROM fwdzone
domain=".$this->ds->qstr($this->domain));
$temprow = $result->FetchRow();
$dataid=$temprow["data_id"];
if (!empty($info)) {
"VALUES ($this->cust,".
$dataid.",".
$this->ds->qstr($this->info).")" );
return $dataid;
// key error?
return 0;
$this->cust = $cust;
if (!empty($server)) {
$answer=$this->ZoneAXFR($this->domain, $server);
return $this->err;
// could use unique key on database to do check, but requires extra key
if ($restemp->FetchRow()) {
$this->err=-60;
else {
$dataid=$this->FwdAddSOA();
$this->dataid=$dataid;
if ($dataid) {
if(!$this->FwdAddNS($dataid)) {
$this->err = -60;
return $this->err;
if(!$this->FwdZoneAddRR($dataid, $answer)) {
$this->err = -60;
return $this->err;
".$this->ds->qstr(getAuthUsername())." AS userid,
".$this->ds->DBTimeStamp(time())." AS lastmod
fwdzone.domain=".$this->ds->qstr("template.com"));
$this->err = 0;
else {
$this->err = -60;
}
return $this->err;
$this->cust = $cust;
$this->Serial();
// Update DNS Database Serial Count. Update Serial Count only when we export.
"set serialdate=".$this->ds->qstr($this->serialdate).
", userid=".$this->ds->qstr(getAuthUsername()).
", error_message=".$this->ds->qstr("").
", lastexp=".$this->ds->DBTimeStamp(time()).
", serialnum=$this->serialnum".
if ($result) {
FROM fwdzone
$this->domain=$row["domain"];
FROM fwdzoneadd
if(!$tmpfname) {
$this->err=80;
return;
// header of document
fputs($fp, $output);
fputs($fp, "\n");
fputs($fp, "\n");
fputs($fp, sprintf("<path>\n<primary>\n%s\n</primary>\n",
htmlspecialchars($row["zonefilepath1"])));
fputs($fp, sprintf("<primaryfile>\n%s\n</primaryfile>\n",
htmlspecialchars(basename($row["zonefilepath1"]))));
fputs($fp, sprintf("<primarydir>\n%s\n</primarydir>\n",
htmlspecialchars(dirname($row["zonefilepath1"]))));
fputs($fp, sprintf("<secondary>\n%s\n</secondary>\n",
htmlspecialchars($row["zonefilepath2"])));
fputs($fp, sprintf("<secondaryfile>\n%s\n</secondaryfile>\n",
htmlspecialchars(basename($row["zonefilepath2"]))));
fputs($fp, sprintf("<secondarydir>\n%s\n</secondarydir>\n",
htmlspecialchars(dirname($row["zonefilepath2"]))));
fputs($fp, "</path>\n");
// SOA portion
$this->serialdate, $this->serialnum,
$row["ttl"],
$row["retry"],
$row["refresh"],
$row["expire"],
$row["minimum"],
$row["responsiblemail"]
));
fputs($fp, "\n");
// additional fields
if (!empty($info)) {
if ($template->is_error() == FALSE) {
$template->Merge($template->decode($info));
fputs($fp, "<additional>\n");
foreach($template->userfld as $field=>$val) {
fputs($fp, sprintf("\t<%s>%s</%s>\n",
htmlspecialchars($field),
htmlspecialchars($val["value"]),
htmlspecialchars($field)));
fputs($fp, "</additional>\n");
// nameservers
FROM fwddns
WHERE id=$dataid
ORDER BY horder");
$cnt=0;
while($row1 = $result1->FetchRow()) {
fputs($fp, '<record><NS>');
fputs($fp, '</NS></record>');
fputs($fp, "\n");
$cnt++;
if ($cnt < 2) {
fclose($fp);
unlink($tmpfname);
$this->err=70;
$this->errstr .= my_("Invalid zone - zone should have at least two name servers
defined")."\n";
return;
FROM fwdzonerec
ORDER BY sortorder");
while($row = $result->FetchRow()) {
if ($row["recordtype"]=="MX" or $row["recordtype"]=="AFSDB") {
else {
fputs($fp, '<preference>10</preference>');
else if ($row["recordtype"]=="SRV")
{
else {
else {
fputs($fp, "\n");
// close zone
fputs($fp, '</zone>');
fputs($fp, "\n");
fclose($fp);
rename($tmpfname, $tmpfname.".xml");
@chmod($tmpfname.".xml",0644);
$this->err=0;
return $tmpfname.".xml";
//return $tmpfname;
// database error?
var $cust;
var $zoneid;
var $zone;
var $zoneip;
var $size;
var $server;
$this->cust = $cust;
$this->zoneid = $zoneid;
$this->zone = $zone;
$this->zoneip = $zoneip;
$this->size = $size;
}
$this->cust = $cust;
WHERE id=$zoneid");
return $result;
global $grps;
if(!$ds) {
$this->err=90;
$ds->SetGrps($grps);
$ds->SetSearchIn(1);
foreach($answer as $rr) {
if ($rr->type == "PTR") {
$recordtype=$rr->type;
else {
continue;
$ipaddr="$oc4.$oc3.$oc2.$oc1";
if (testIP($ipaddr)) {
continue;
$ds->SetIPaddr($ipaddr);
if (!$result) {
$this->err=70;
$this->errstr .= $ds->errstr;
if ($row = $result->FetchRow()) {
$baseindex=$row["baseindex"];
if (!$affected) {
$ds->AddIP(inet_aton($ipaddr), $baseindex, "", "", "", "",
else {
return TRUE;
function RevAddNS($zoneid) {
$hnametemp=$this->hname[$i];
VALUES
($zoneid,
".$this->ds->qstr($hnametemp).",
$i)");
if (!$result) {
return FALSE;
return TRUE;
$row = $this->ds->GetOne("SELECT id
FROM zones
return !empty($row);
// test if the zone has changed records - check the last serial for the zone
// against the ippaddr table for changed records i.e. records with a date equal or
$sqlfn = $this->ds->SQLDate('Ymd','ipaddr.lastmod');
zones.id=$zoneid");
return !empty($row);
$this->cust = $cust;
if (!$this->RevZoneExists($cust, $zoneid)) {
$this->err=90;
$this->errstr .= my_("Could not find the zone - possibly deleted by another user")."\n";
return FALSE;
$this->Serial();
// Updated DB here.
",zone=".$this->ds->qstr($this->zone).
",zonesize=$size".
",serialdate=".$this->ds->qstr($this->serialdate).
",serialnum=$this->serialnum".
",ttl=".$this->ttl.
",refresh=".$this->refresh.
",retry=".$this->retry.
",expire=".$this->expire.
",minimum=".$this->minimum.
",error_message=".$this->ds->qstr("E").
",responsiblemail=".$this->ds->qstr($this->responsiblemail).
",userid=".$this->ds->qstr(getAuthUsername()).
",zonefilepath1=".$this->ds->qstr($this->zonepath).
",zonefilepath2=".$this->ds->qstr($this->seczonepath).
",lastmod=".$this->ds->DBTimeStamp(time()).
",slaveonly=".$this->ds->qstr($this->slaveonly).
WHERE id=$zoneid");
$this->RevAddNS($zoneid);
return $result;
function RevAddSOA() {
$this->Serial();
// Add to DB here.
$this->ds->qstr($this->zone).", $this->size,".
$this->ds->qstr($this->serialdate).", $this->serialnum,".
$this->ds->qstr("E").",".
$this->ttl.",".
$this->refresh.",".
$this->retry.",".
$this->expire.",".
$this->minimum.",".
$this->ds->DBTimeStamp(time()).",".
$this->ds->qstr($this->responsiblemail).",".
$this->ds->qstr(getAuthUsername()).",".
$this->ds->qstr($this->zonepath).",".
$this->ds->qstr($this->seczonepath).",".
$this->ds->qstr($this->slaveonly).")" );
if ($result) {
if (DBF_TYPE=="mysql" or DBF_TYPE=="maxsql") {
$zoneid=$this->ds->Insert_ID();
}
else {
$result=$this->ds->Execute("SELECT id
FROM zones
zoneip=$this->zoneip");
$temprow = $result->FetchRow();
$zoneid=$temprow["id"];
return $zoneid;
// key error?
return 0;
$this->cust = $cust;
if (!empty($server)) {
$answer=$this->ZoneAXFR($this->zone, $server);
if ($this->err > 0) {
return $this->err;
// could use unique key on database to do check, but requires extra key
if ($restemp->FetchRow()) {
$this->err=-60;
else {
$zoneid=$this->RevAddSOA();
$this->zoneid=$zoneid;
if ($zoneid) {
if(!$this->RevAddNS($zoneid)) {
$this->err = -60;
return $this->err;
if(!$this->RevZoneAddRR($zoneid, $answer)) {
$this->err = -60;
return $this->err;
$this->err = 0;
else {
$this->err = -60;
return $this->err;
$this->cust = $cust;
$this->Serial();
"set serialdate=".$this->ds->qstr($this->serialdate).
", userid=".$this->ds->qstr(getAuthUsername()).
", lastexp=".$this->ds->DBTimeStamp(time()).
", error_message=".$this->ds->qstr("").
if ($result) {
userid, slaveonly
FROM zones
$row = $result->FetchRow();
$this->zone=$row["zone"];
$this->zoneip=$row["zoneip"];
$this->size=$row["zonesize"];
$prefix=inet_bits($row["zonesize"]);
if(!$tmpfname) {
$this->err=80;
return;
// header of document
fputs($fp, "\n");
$ip=inet_ntoa($row["zoneip"]);
list($octet1,$octet2,$octet3,$octet4) = explode(".",$ip);
fputs($fp, "\n");
fputs($fp, sprintf("<path>\n<primary>\n%s\n</primary>\n",
htmlspecialchars($row["zonefilepath1"])));
fputs($fp, sprintf("<primaryfile>\n%s\n</primaryfile>\n",
htmlspecialchars(basename($row["zonefilepath1"]))));
fputs($fp, sprintf("<primarydir>\n%s\n</primarydir>\n",
htmlspecialchars(dirname($row["zonefilepath1"]))));
fputs($fp, sprintf("<secondary>\n%s\n</secondary>\n",
htmlspecialchars($row["zonefilepath2"])));
fputs($fp, sprintf("<secondaryfile>\n%s\n</secondaryfile>\n",
htmlspecialchars(basename($row["zonefilepath2"]))));
fputs($fp, sprintf("<secondarydir>\n%s\n</secondarydir>\n",
htmlspecialchars(dirname($row["zonefilepath2"]))));
fputs($fp, "</path>\n");
// SOA portion
$row["ttl"],
$row["retry"],
$row["refresh"],
$row["expire"],
$row["minimum"],
$row["responsiblemail"]
));
fputs($fp, "\n");
// nameservers
WHERE id=$zoneid
ORDER BY horder");
$cnt=0;
while($row1 = $result1->FetchRow()) {
fputs($fp, '<record><NS>');
fputs($fp, '</NS></record>');
fputs($fp, "\n");
$cnt++;
if ($cnt < 2) {
fclose($fp);
unlink($tmpfname);
$this->err=90;
$this->errstr .= my_("Invalid zone - zone should have at least two name servers defined");
return;
ORDER BY ipaddr.ipaddr");
while($row1 = $result1->FetchRow()) {
$ip=inet_ntoa($row1["ipaddr"]);
if (empty($row1["hname"])) {
continue;
if (!preg_match('/^(([\w][\w\-\.]*)\.)?([\w][\w\-]+)(\.([\w][\w\.]*))?$/', $row1["hname"]))
{
continue;
fputs($fp, '<record><PTR>');
fputs($fp, "\n");
fputs($fp, '</PTR></record>');
fputs($fp, "\n");
// close zone
fputs($fp, '</zone>');
fputs($fp, "\n");
fclose($fp);
rename($tmpfname, $tmpfname.".xml");
@chmod($tmpfname.".xml",0644);
$this->err=0;
return $tmpfname.".xml";
//return $tmpfname;
// database error?
/*
// Update DNS Database Serial Count. Update Serial Count only when we export.
"set serialdate=".$this->ds->qstr($this->serialdate).
", userid=".$this->ds->qstr(getAuthUsername()).
", serialnum=$this->serialnum".
if ($result) {
$row = $result->FetchRow();
$this->domain=$row["domain"];
// header of document
fputs($fp, $output);
fputs($fp, "\n");
fputs($fp, "\n");
// SOA portion
$this->serialdate, $this->serialnum,
$row["ttl"],
$row["retry"],
$row["refresh"],
$row["expire"],
$row["minimum"],
$row["responsiblemail"]
));
fputs($fp, "\n");
// nameservers
FROM fwddns
WHERE id=$zoneid
ORDER BY horder");
$cnt=0;
while($row1 = $result1->FetchRow()) {
fputs($fp, '<record><NS>');
fputs($fp, '</NS></record>');
fputs($fp, "\n");
$cnt++;
if ($cnt < 2) {
insert($w,textbr(my_("Invalid zone - zone should have at least two name servers defined")));
ORDER BY sortorder");
while($row = $result->FetchRow()) {
if ($row["recordtype"]=="MX") {
else {
fputs($fp, '<preference>10</preference>');
else {
fputs($fp, sprintf('<iphostname>%s</iphostname>', $row["ip_hostname"]));
fputs($fp, "\n");
// close zone
fputs($fp, '</zone>');
fputs($fp, "\n");
fclose($fp);
return $tmpfname;
*/
?>