예제 #1
0
function genSWIP($ds, $baseindex, $start, $end, $cust, $descrip, $swipmod, $filename)
{
    global $ntnameopt;
    //************ now process customer standard fields ************//
    $result1 =& $ds->ds->Execute("SELECT *\n            FROM custinfo\n            WHERE customer={$cust}");
    // should only be one row here, none if SWIP turned off during creation
    // of customer
    $row1 = $result1->FetchRow();
    $result2 =& $ds->ds->Execute("SELECT hname, ipaddr\n            FROM revdns\n            WHERE customer={$cust}\n            ORDER BY horder");
    $fields = array();
    $fields["ntsnum"] = $start;
    $fields["ntenum"] = $end;
    $fields = array_merge($fields, $row1);
    // use subnet description field? then only a-z, 0-9 max 21 chars allowed
    if ($ntnameopt and preg_match("/^[A-Za-z0-9\\-]{1,21}\$/", $descrip)) {
        $ntname = $descrip;
    } else {
        $ntname = MAINTAINERID . "-" . str_replace(".", "-", $start);
    }
    $fields["ntname"] = $ntname;
    $fields["maint"] = MAINTAINERID;
    if ($row2 = $result2->FetchRow()) {
        $fields["hname1"] = $row2["hname"];
        $fields["ipaddr1"] = $row2["ipaddr"];
    } else {
        $fields["hname1"] = "";
        $fields["ipaddr1"] = "";
    }
    if ($row2 = $result2->FetchRow()) {
        $fields["hname2"] = $row2["hname"];
        $fields["ipaddr2"] = $row2["ipaddr"];
    } else {
        $fields["hname1"] = "";
        $fields["ipaddr1"] = "";
    }
    if ($row2 = $result2->FetchRow()) {
        $fields["hname3"] = $row2["hname"];
        $fields["ipaddr3"] = $row2["ipaddr"];
    } else {
        $fields["hname1"] = "";
        $fields["ipaddr1"] = "";
    }
    $cnt = 3;
    while ($row2 = $result2->FetchRow()) {
        $fields["hname{$cnt}"] = $row2["hname"];
        $fields["ipaddr{$cnt}"] = $row2["ipaddr"];
        $cnt++;
    }
    $fields["regid"] = REGID;
    $fields["password"] = REGPASS;
    $fields["source"] = REGISTRY;
    // add a UTC format date
    $now = getdate();
    $fields["date"] = $now["year"] . str_pad($now["mon"], 2, '0', STR_PAD_LEFT) . str_pad($now["mday"], 2, '0', STR_PAD_LEFT);
    $fields["swipmod"] = $swipmod;
    //************ now process customer template fields ************//
    // if a specific customer template exists
    $err = TRUE;
    $template = new IPplanIPTemplate("custtemplate", $cust);
    $err = $template->is_error();
    // process fields form the user defined template
    if (!$err) {
        $restmp =& $ds->ds->Execute("SELECT info\n                FROM custadd\n                WHERE customer={$cust}");
        if ($rowadd = $restmp->FetchRow()) {
            $template->Merge($template->decode($rowadd["info"]));
            foreach ($template->userfld as $key => $arr) {
                $fields[$key] = $arr["value"];
            }
        }
    }
    //************ now process base template fields ************//
    // if a specific base template exists, use that, else use generic template
    $err = TRUE;
    $template = new IPplanIPTemplate("basetemplate", $cust);
    $err = $template->is_error();
    if (!$err) {
        $result_template =& $ds->ds->Execute("SELECT info, infobin\n                FROM baseadd\n                WHERE baseindex={$baseindex}");
        if ($rowadd = $result_template->FetchRow()) {
            $template->Merge($template->decode($rowadd["info"]));
            foreach ($template->userfld as $key => $arr) {
                $fields[$key] = $arr["value"];
            }
        }
    }
    $rep = new myTemplate();
    if ($rep->get("../templates/{$filename}") == FALSE) {
        return FALSE;
    }
    $swip = $rep->process($fields);
    return $swip;
}
예제 #2
0
insert($con, textbrbr(my_("Refresh")));
insert($con, input_text(array("name" => "refresh", "value" => "{$refresh}", "size" => "5", "maxlength" => "10")));
insert($con, textbrbr(my_("Retry")));
insert($con, input_text(array("name" => "retry", "value" => "{$retry}", "size" => "5", "maxlength" => "10")));
insert($con, textbrbr(my_("Expire")));
insert($con, input_text(array("name" => "expire", "value" => "{$expire}", "size" => "5", "maxlength" => "10")));
insert($con, textbrbr(my_("Minimum TTL")));
insert($con, input_text(array("name" => "minimum", "value" => "{$minimum}", "size" => "5", "maxlength" => "10")));
$dbfinfo = $ds->ds->GetOne("SELECT info FROM fwdzoneadd \n                          WHERE customer={$cust} AND data_id={$dataid}");
// use base template (for additional subnet information)
$template = new IPplanIPTemplate("fwdzonetemplate", $cust);
if ($template->is_error() == FALSE) {
    insert($f, $con = container("fieldset", array("class" => "fieldset")));
    insert($con, $legend = container("legend", array("class" => "legend")));
    insert($legend, text(my_("Additional information")));
    $template->Merge($template->decode($dbfinfo));
    $template->DisplayTemplate($con);
}
insert($f, $con = container("fieldset", array("class" => "fieldset")));
insert($con, $legend = container("legend", array("class" => "legend")));
insert($legend, text(my_("Forward zone location")));
insert($con, textbr(my_("Zone File Path")));
insert($con, span(my_("The path where the zone file will be written once exported and processed. Examples:"), array("class" => "textSmall")));
insert($con, span(my_("ftp://myhost.com/var/named/test.zone - if you want to transfer the zone using ncftput"), array("class" => "textSmall")));
insert($con, span(my_("user@myhost.com:/var/named/test.zone - if you want to transfer the zone using scp"), array("class" => "textSmall")));
insert($con, input_text(array("name" => "zonepath", "value" => "{$zonepath}", "size" => "80", "maxlength" => "254")));
insert($con, textbrbr(my_("Secondary Zone File Path")));
insert($con, input_text(array("name" => "seczonepath", "value" => "{$seczonepath}", "size" => "80", "maxlength" => "254")));
insert($f, submit(array("value" => my_("Save"))));
insert($f, freset(array("value" => my_("Clear"))));
myCopyPaste($f, "ipplanCPdnsrecord", "ENTRY");
예제 #3
0
header("Content-Type: bad/type");
header("Content-Disposition: attachment; filename=base.txt");
header("Pragma: no-cache");
header("Expires: 0");
$startnum = inet_aton(DEFAULTROUTE);
$endnum = inet_aton(ALLNETS);
// if a specific network template exists, use that, else use generic template
$template = new IPplanIPTemplate("basetemplate", $cust);
$err = $template->is_error();
$result = $ds->GetBase($startnum, $endnum, '', $cust);
while ($row = $result->FetchRow()) {
    echo inet_ntoa($row["baseaddr"]) . FIELDS_TERMINATED_BY . $row["descrip"] . FIELDS_TERMINATED_BY . inet_ntoa(inet_aton(ALLNETS) + 1 - $row["subnetsize"]) . FIELDS_TERMINATED_BY;
    if (!$err) {
        $result_template =& $ds->ds->Execute("SELECT info, infobin\n                FROM baseadd\n                WHERE baseindex=" . $row["baseindex"]);
        if ($rowadd = $result_template->FetchRow()) {
            $template->Merge($template->decode($rowadd["info"]));
            foreach ($template->userfld as $arr) {
                $tmpfield = csv_escape($arr["value"]);
                echo FIELDS_TERMINATED_BY . $arr["value"];
            }
        }
    }
    echo "\n";
}
// wrap any multiline string with quotes
// this function only works with php 5 and above
function csv_escape($str)
{
    if (PHP_VERSION >= 5) {
        $str = str_replace(array('"', ',', "\n", "\r"), array('""', ',', "\n", "\r"), $str, $count);
        if ($count) {
예제 #4
0
 function FwdZoneExport($cust, $dataid)
 {
     // use local function variables as they may change
     $this->cust = $cust;
     $this->Serial();
     // Update DNS Database Serial Count.  Update Serial Count only when we export.
     $result = $this->ds->Execute("UPDATE fwdzone " . "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}" . " WHERE customer={$cust} AND data_id=" . $dataid);
     if ($result) {
         $sqllastmod = $this->ds->SQLDate("M d Y H:i:s", 'lastmod');
         $result = $this->ds->Execute("SELECT data_id, domain, engineer, error_message, \n                        responsiblemail, serialdate, serialnum, ttl, refresh, retry, expire, \n                        minimum, zonefilepath1, zonefilepath2, customer, admingrp, \n                        {$sqllastmod} AS lastmod, userid, slaveonly\n                    FROM fwdzone \n                    WHERE customer={$cust} AND data_id={$dataid}");
         $row = $result->FetchRow();
         $this->domain = $row["domain"];
         $info = $this->ds->GetOne("SELECT info\n                    FROM fwdzoneadd\n                    WHERE customer={$cust} AND data_id={$dataid}");
         $tmpfname = tempnam(DNSEXPORTPATH, "zone_" . $this->domain . "_");
         if (!$tmpfname) {
             $this->err = 80;
             $this->errstr .= my_("Could not create temporary file!");
             return;
         }
         $fp = fopen("{$tmpfname}", "w");
         // header of document
         $output = '<?xml version="1.0" ?>';
         fputs($fp, $output);
         fputs($fp, "\n");
         fputs($fp, sprintf('<zone domain="%s" slaveonly="%s">', $row["domain"], empty($row["slaveonly"]) ? "N" : $row["slaveonly"]));
         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
         fputs($fp, sprintf('<soa serialdate="%s" serialnum="%02d" ttl="%s" retry="%s" refresh="%s" expire="%s" minimumttl="%s" email="%s" />', $this->serialdate, $this->serialnum, $row["ttl"], $row["retry"], $row["refresh"], $row["expire"], $row["minimum"], $row["responsiblemail"]));
         fputs($fp, "\n");
         // additional fields
         if (!empty($info)) {
             $template = new IPplanIPTemplate("fwdzonetemplate", $cust);
             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
         $result1 = $this->ds->Execute("SELECT hname\n                    FROM fwddns\n                    WHERE id={$dataid}\n                    ORDER BY horder");
         $cnt = 0;
         while ($row1 = $result1->FetchRow()) {
             fputs($fp, '<record><NS>');
             fputs($fp, sprintf('<iphostname>%s</iphostname>', $row1["hname"]));
             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;
         }
         $sqllastmod = $this->ds->SQLDate("M d Y H:i:s", 'lastmod');
         $result = $this->ds->Execute("SELECT recidx, data_id, host, recordtype, ip_hostname, \n                        error_message, sortorder, customer, {$sqllastmod} AS lastmod, userid\n                    FROM fwdzonerec\n                    WHERE customer={$cust} AND data_id={$dataid}\n                    ORDER BY sortorder");
         // loop through each host record
         while ($row = $result->FetchRow()) {
             fputs($fp, sprintf('<record><%s>', $row["recordtype"]));
             fputs($fp, sprintf('<host>%s</host>', $row["host"]));
             // MX records are in format "10 hostname.com" in database field ip_hostname
             if ($row["recordtype"] == "MX" or $row["recordtype"] == "AFSDB") {
                 list($preference, $iphost) = explode(" ", $row["ip_hostname"], 2);
                 if (is_numeric($preference) and $preference >= 0) {
                     fputs($fp, sprintf('<preference>%s</preference>', $preference));
                     fputs($fp, sprintf('<iphostname>%s</iphostname>', $iphost));
                 } else {
                     fputs($fp, '<preference>10</preference>');
                     fputs($fp, sprintf('<iphostname>%s</iphostname>', $row["ip_hostname"]));
                 }
             } else {
                 if ($row["recordtype"] == "SRV") {
                     list($priority, $weight, $port, $iphost) = explode(" ", $row["ip_hostname"], 4);
                     if (is_numeric($priority) and is_numeric($weight) and is_numeric($port) and $priority >= 0 and $weight >= 0 and $port >= 0) {
                         fputs($fp, sprintf('<preference>%s %s %s</preference>', $priority, $weight, $port));
                         fputs($fp, sprintf('<iphostname>%s</iphostname>', $iphost));
                     } else {
                         fputs($fp, '<preference> Invalid SRV record </preference>');
                         fputs($fp, sprintf('<iphostname>%s</iphostname>', $row["ip_hostname"]));
                     }
                 } else {
                     fputs($fp, sprintf('<iphostname>%s</iphostname>', $row["ip_hostname"]));
                 }
             }
             fputs($fp, sprintf('</%s></record>', $row["recordtype"]));
             fputs($fp, "\n");
         }
         // close zone
         fputs($fp, '</zone>');
         fputs($fp, "\n");
         fclose($fp);
         // give file proper extension
         rename($tmpfname, $tmpfname . ".xml");
         @chmod($tmpfname . ".xml", 0644);
         $this->err = 0;
         return $tmpfname . ".xml";
     }
     //return $tmpfname;
     // database error?
 }