Esempio n. 1
0
function searchIP($ip)
{
    $f = new xmlrpcmsg('ipplan.SearchIP', array(new xmlrpcval($ip, "string")));
    $c = new xmlrpc_client(URL, SERVER, RPCPORT);
    $c->setCredentials(USER, PASSWD);
    $c->setDebug(DEBUG ? 1 : 0);
    $r = $c->send($f);
    if ($r->faultCode() <= 0) {
        $v = xmlrpc_decode($r->value());
        $res = "";
        foreach ($v as $value) {
            $res .= sprintf("%s/%s\t%s\n\tCustomer/AS: %s\n", $value["baseaddr"], inet_bits($value["subnetsize"]), $value["descrip"], $value["custdescrip"]);
        }
        return $res;
    } else {
        if (DEBUG) {
            print "Fault! Code: " . $r->faultCode() . " Reason '" . $r->faultString() . "'\n";
        }
        return "Could not query server";
    }
}
Esempio n. 2
0
function searchOverlap($ds, &$w, $cust1, $cust2)
{
    global $block;
    // dont trust variables
    $cust1 = floor($cust1);
    $cust2 = floor($cust2);
    $custdescrip1 = $ds->GetCustomerDescrip($cust1);
    $custdescrip2 = $ds->GetCustomerDescrip($cust2);
    // this query is not quick as indexes cannot be used!!!
    // must have first baseaddr called baseaddr else block pager
    // will not work - may break databases other than mysql
    $result =& $ds->ds->Execute("SELECT t1.baseaddr AS baseaddr,\n                           t1.baseindex AS baseindex1,\n                           t1.subnetsize AS subnetsize1,\n                           t1.descrip AS descrip1,\n                           t2.baseaddr AS baseaddr2,\n                           t2.baseindex AS baseindex2,\n                           t2.subnetsize AS subnetsize2,\n                           t2.descrip AS descrip2\n                        FROM base t1, base t2\n                        WHERE ((t1.baseaddr BETWEEN t2.baseaddr AND\n                                t2.baseaddr+t2.subnetsize-1) OR\n                               (t1.baseaddr+t1.subnetsize-1\n                                BETWEEN t2.baseaddr AND\n                                        t2.baseaddr+t2.subnetsize-1) OR\n                               (t1.baseaddr < t2.baseaddr AND\n                                t1.baseaddr+t1.subnetsize >\n                                t2.baseaddr+t2.subnetsize)) AND\n                               t1.customer={$cust1} AND\n                                t2.customer={$cust2}\n                        ORDER BY t1.baseaddr");
    $totcnt = 0;
    $vars = "";
    // fastforward till first record if not first block of data
    while ($block and $totcnt < $block * MAXTABLESIZE and $row = $result->FetchRow()) {
        $vars = DisplayBlock($w, $row, $totcnt, "&cust1[]=" . $cust1 . "&cust2[]=" . $cust2);
        $totcnt++;
    }
    insert($w, block("<p>"));
    $cnt = 0;
    while ($row = $result->FetchRow()) {
        // draw heading only if there are records to display
        if ($cnt == 0) {
            // create a table
            insert($w, $t = table(array("cols" => "8", "class" => "outputtable")));
            // draw heading
            setdefault("cell", array("class" => "heading"));
            insert($t, $c = cell(array("colspan" => "4")));
            insert($c, block("<center>"));
            insert($c, text($custdescrip1));
            insert($c, block("</center>"));
            insert($t, $c = cell(array("colspan" => "4")));
            insert($c, block("<center>"));
            insert($c, text($custdescrip2));
            insert($c, block("</center>"));
            insert($t, $c = cell());
            if (!empty($vars)) {
                insert($c, anchor($vars, "<<"));
            }
            insert($c, text(my_("Base address")));
            insert($t, $c = cell());
            insert($c, text(my_("Subnet size")));
            insert($t, $c = cell());
            insert($c, text(my_("Subnet mask")));
            insert($t, $c = cell());
            insert($c, text(my_("Description")));
            insert($t, $c = cell());
            insert($c, text(my_("Base address")));
            insert($t, $c = cell());
            insert($c, text(my_("Subnet size")));
            insert($t, $c = cell());
            insert($c, text(my_("Subnet mask")));
            insert($t, $ck = cell());
            insert($ck, text(my_("Description")));
            setdefault("cell", array("class" => color_flip_flop()));
        }
        // customer 1
        if ($row["subnetsize1"] == 1) {
            insert($t, $c = cell());
            insert($c, text(inet_ntoa($row["baseaddr"])));
        } else {
            insert($t, $c = cell());
            insert($c, anchor("displaysubnet.php?baseindex=" . $row["baseindex1"], inet_ntoa($row["baseaddr"])));
        }
        if ($row["subnetsize1"] == 1) {
            insert($t, $c = cell());
            insert($c, text("Host"));
        } else {
            insert($t, $c = cell());
            insert($c, text($row["subnetsize1"]));
        }
        insert($t, $c = cell());
        insert($c, text(inet_ntoa(inet_aton(ALLNETS) + 1 - $row["subnetsize1"]) . "/" . inet_bits($row["subnetsize1"])));
        insert($t, $c = cell());
        insert($c, text($row["descrip1"]));
        // customer 2
        if ($row["subnetsize2"] == 1) {
            insert($t, $c = cell());
            insert($c, text(inet_ntoa($row["baseaddr2"])));
        } else {
            insert($t, $c = cell());
            insert($c, anchor("displaysubnet.php?baseindex=" . $row["baseindex2"], inet_ntoa($row["baseaddr2"])));
        }
        if ($row["subnetsize2"] == 1) {
            insert($t, $c = cell());
            insert($c, text(my_("Host")));
        } else {
            insert($t, $c = cell());
            insert($c, text($row["subnetsize2"]));
        }
        insert($t, $c = cell());
        insert($c, text(inet_ntoa(inet_aton(ALLNETS) + 1 - $row["subnetsize2"]) . "/" . inet_bits($row["subnetsize2"])));
        insert($t, $c = cell());
        insert($c, text($row["descrip2"]));
        if ($totcnt % MAXTABLESIZE == MAXTABLESIZE - 1) {
            break;
        }
        $cnt++;
        $totcnt++;
    }
    insert($w, block("<p>"));
    if ($cnt) {
        $vars = "";
        $printed = 0;
        while ($row = $result->FetchRow()) {
            $totcnt++;
            $vars = DisplayBlock($w, $row, $totcnt, "&cust1[]=" . $cust1 . "&cust2[]=" . $cust2);
            if (!empty($vars) and !$printed) {
                insert($ck, anchor($vars, ">>"));
                $printed = 1;
            }
        }
    }
}
Esempio n. 3
0
 }
 insert($t, $c = cell());
 insert($c, anchor("displaysubnet.php?baseindex=" . $row["baseindex"], inet_ntoa($row["baseaddr"])));
 $export->addCell(inet_ntoa($row["baseaddr"]));
 if ($row["subnetsize"] == 1) {
     insert($t, $c = cell());
     insert($c, text(my_("Host")));
     $export->addCell(my_("Host"));
 } else {
     insert($t, $c = cell());
     insert($c, text($row["subnetsize"]));
     $export->addCell($row["subnetsize"]);
 }
 insert($t, $c = cell());
 insert($c, text(inet_ntoa(inet_aton(ALLNETS) + 1 - $row["subnetsize"]) . "/" . inet_bits($row["subnetsize"])));
 $export->addCell(inet_ntoa(inet_aton(ALLNETS) + 1 - $row["subnetsize"]) . "/" . inet_bits($row["subnetsize"]));
 insert($t, $c = cell());
 insert($c, text($row["descrip"]));
 $export->addCell($row["descrip"]);
 insert($t, $c = cell());
 insert($c, block("<small>"));
 insert($c, block($result->UserTimeStamp($row["lastmod"], "M d Y H:i:s")));
 insert($c, block("</small>"));
 $export->addCell($row["lastmod"]);
 insert($t, $c = cell());
 insert($c, text($row["userid"]));
 $export->addCell($row["userid"]);
 if (REGENABLED) {
     insert($t, $c = cell());
     insert($c, block("<small>"));
     insert($c, block($result->UserTimeStamp($row["swipmod"], "M d Y H:i:s")));
Esempio n. 4
0
function myRangeDropDown($ds, $f2, $cust, $areaindex)
{
    $cust = floor($cust);
    // dont trust $cust as it could
    // come from form post
    $areaindex = floor($areaindex);
    // display range drop down list
    if ($areaindex) {
        $result = $ds->GetRangeInArea($cust, $areaindex);
    } else {
        $result = $ds->GetRange($cust, 0);
    }
    // don't bother if there are no records, will always display "No range"
    insert($f2, textbrbr(my_("Range (optional)")));
    $lst = array();
    $lst["0"] = my_("No range selected");
    while ($row = $result->FetchRow()) {
        $col = $row["rangeindex"];
        $lst["{$col}"] = inet_ntoa($row["rangeaddr"]) . "/" . inet_ntoa(inet_aton(ALLNETS) - $row["rangesize"] + 1) . "/" . inet_bits($row["rangesize"]) . " - " . $row["descrip"];
    }
    insert($f2, selectbox($lst, array("name" => "rangeindex")));
}
Esempio n. 5
0
         }
     }
     $menustring = $menustring . ".|" . htmlspecialchars($custrow["custdescrip"]) . "|displaybase.php?cust=" . $custrow["customer"] . "||||{$expanded}\n";
     $menustring = $menustring . "..|" . my_("All subnets not part of range") . "|displaybase.php?cust=" . $custrow["customer"] . "&areaindex=-1||||\n";
     $arearesult = $ds->GetArea($custrow["customer"], 0);
     //area
     while ($arearow = $arearesult->Fetchrow()) {
         $menustring = $menustring . "..|" . htmlspecialchars(inet_ntoa($arearow["areaaddr"]) . " (" . $arearow["descrip"] . ")") . "|displaybase.php?cust=" . $custrow["customer"] . "&areaindex=" . $arearow["areaindex"] . "||||\n";
         $rangeresult = $ds->GetRangeInArea($custrow["customer"], $arearow["areaindex"]);
         //range
         while ($rangerow = $rangeresult->Fetchrow()) {
             $menustring = $menustring . "...|" . htmlspecialchars(inet_ntoa($rangerow["rangeaddr"]) . " (" . $rangerow["descrip"] . ")") . "|displaybase.php?cust=" . $custrow["customer"] . "&areaindex=" . $arearow["areaindex"] . "&rangeindex=" . $rangerow["rangeindex"] . "&descrip=&sortby=Base+Address" . "||||\n";
             $baseresult = $ds->GetBase($rangerow["rangeaddr"], $rangerow["rangeaddr"] + $rangerow["rangesize"] - 1, "", $custrow["customer"]);
             //subnet (base)
             while ($baserow = $baseresult->Fetchrow()) {
                 $menustring = $menustring . "....|" . htmlspecialchars(inet_ntoa($baserow["baseaddr"]) . " /" . inet_bits($baserow["subnetsize"]) . " (" . $baserow["descrip"] . ")") . "|displaysubnet.php?baseindex=" . $baserow["baseindex"] . "||||\n";
             }
         }
     }
 }
 $mid = new TreeMenu();
 $mid->setDirroot('../menus');
 $mid->setLibjsdir('../menus/libjs/');
 $mid->setImgdir('../menus/menuimages/');
 $mid->setImgwww('../menus/menuimages/');
 $mid->setIcondir('../menus/menuicons/');
 $mid->setIconwww('../menus/menuicons/');
 if (!$menustring) {
     myError($w, $p, my_("No customers"));
 }
 $mid->setMenuStructureString($menustring);
Esempio n. 6
0
     }
 }
 if ($arr[$i]["subnetsize"] == 1) {
     insert($t, $c = cell());
     insert($c, text(my_("Host")));
 } else {
     insert($t, $c = cell());
     insert($c, text($arr[$i]["subnetsize"]));
 }
 insert($t, $c = cell());
 insert($c, text(inet_ntoa(inet_aton(ALLNETS) + 1 - $arr[$i]["subnetsize"]) . "/" . inet_bits($arr[$i]["subnetsize"])));
 insert($t, $c = cell());
 $export->addRow(NULL);
 $export->addCell(inet_ntoa($arr[$i]['baseaddr']));
 $export->addCell($arr[$i]['subnetsize']);
 $export->addCell(inet_ntoa(inet_aton(ALLNETS) + 1 - $arr[$i]['subnetsize']) . "/" . inet_bits($arr[$i]['subnetsize']));
 // hack to make it more intuitive for ISP's
 if ($free) {
     insert($c, text(my_("Free/Unassigned space")));
 } else {
     if ($arr[$i]["descrip"] == DUPWARN) {
         insert($c, span(my_("SPACE IS ASSIGNED OVER MULTIPLE CUSTOMERS/AS's"), array("class" => "textError")));
         $export->addCell(my_("SPACE IS ASSIGNED OVER MULTIPLE CUSTOMERS/AS's"));
     } else {
         if ($arr[$i]["descrip"] == DUPWARNFREE) {
             insert($c, span(my_("SPACE IS ASSIGNED OVER MULTIPLE CUSTOMERS/AS's AND CONTAINS SPACE MARKED FREE"), array("class" => "textError")));
             $export->addCell(my_("SPACE IS ASSIGNED OVER MULTIPLE CUSTOMERS/AS's AND CONTAINS SPACE MARKED FREE"));
         } else {
             insert($c, text($arr[$i]["descrip"]));
             $export->addCell($arr[$i]["descrip"]);
         }
Esempio n. 7
0
function insertEditGroupForm($w, $ds)
{
    list($ipaddr, $size, $grp) = myRegister("S:ipaddr S:size S:grp");
    $result =& $ds->ds->Execute("SELECT * FROM grp WHERE grp=" . $ds->ds->qstr($grp));
    $row = $result->FetchRow();
    $grpdescrip = $row["grpdescrip"];
    $createcust = $row["createcust"];
    $grpopt = $row["grpopt"];
    $resaddr = $row["resaddr"];
    insert($w, $t = table(array("width" => "100%", "cols" => "2", "border" => "0", "cellspacing" => "0", "valign" => "middle")));
    insert($t, $c = cell());
    insert($c, block("<b>"));
    insert($c, text(my_("Editing Group:") . " {$grp}"));
    insert($c, block("</b><br>"));
    insert($c, block("<i>" . my_(" Description: ") . "</i>"));
    insert($c, text($grpdescrip));
    insert($w, generic("br"));
    insert($t, $c = cell(array("align" => "right")));
    insert($c, $f = form(array("method" => "post", "action" => $_SERVER["PHP_SELF"])));
    insert($f, hidden(array("name" => "action", "value" => "deletegroup")));
    insert($f, hidden(array("name" => "grp", "value" => "{$grp}")));
    insert($f, submit(array("value" => my_("Delete Group"))));
    // MODIFY GROUP FORM
    insert($w, $f1 = form(array("method" => "post", "action" => $_SERVER["PHP_SELF"])));
    insert($f1, $con = container("fieldset", array("class" => "fieldset")));
    insert($con, $legend = container("legend", array("class" => "legend")));
    insert($legend, text(my_("Modify group")));
    insert($con, hidden(array("name" => "grp", "value" => "{$grp}")));
    insert($con, hidden(array("name" => "action", "value" => "modifygroup")));
    insert($con, textbr(my_("Group description:")));
    insert($con, input_text(array("name" => "grpdescrip", "value" => "{$grpdescrip}", "size" => "80", "maxlength" => "80")));
    insert($con, textbrbr(my_("Group can create/modify/delete customers?")));
    insert($con, selectbox(array("N" => my_("No"), "Y" => my_("Yes")), array("name" => "createcust"), $createcust));
    insert($con, textbrbr(my_("Group can view any customers data?")));
    // first bit defines view capability
    insert($con, selectbox(array("N" => my_("No"), "Y" => my_("Yes")), array("name" => "grpview"), $grpopt & 1 ? "Y" : "N"));
    insert($con, textbrbr(my_("Number of reserved addresses at start of subnets:")));
    insert($con, span(my_("NOTE: if the user belongs to multiple groups and one of the groups does not contain a reserved limit, then the user is allowed all actions"), array("class" => "textSmall")));
    insert($con, input_text(array("name" => "resaddr", "value" => "{$resaddr}", "size" => "4", "maxlength" => "4")));
    insert($con, generic("br"));
    insert($con, generic("br"));
    insert($con, submit(array("value" => my_("Update"))));
    insert($con, generic("br"));
    // START Add User Form
    $result1 =& $ds->ds->Execute("SELECT userid\n            FROM users\n            ORDER BY userid");
    $c = 0;
    $lst = array();
    while ($row = $result1->FetchRow()) {
        $col = $row["userid"];
        $lst["{$col}"] = $row["userid"];
        $c++;
        // here
    }
    if ($c > 0) {
        insert($w, $con = container("fieldset", array("class" => "fieldset")));
        insert($con, $legend = container("legend", array("class" => "legend")));
        insert($legend, text(my_("User Membership")));
        insert($con, $f2 = form(array("name" => "ENTRY", "method" => "post", "action" => $_SERVER["PHP_SELF"])));
        insert($f2, selectbox($lst, array("name" => "userid")));
        insert($f2, hidden(array("name" => "action", "value" => "addusertogroup")));
        insert($f2, hidden(array("name" => "refpage", "value" => "grp")));
        insert($f2, hidden(array("name" => "grp", "value" => "{$grp}")));
        insert($f2, submit(array("value" => my_("Add User"))));
        // Edit users assigned to the group.
        $result =& $ds->ds->Execute("SELECT * FROM usergrp WHERE grp=" . $ds->ds->qstr($grp));
        $lst = array();
        while ($row = $result->FetchRow()) {
            $col = $row["userid"];
            $lst["{$col}"] = $row["userid"];
        }
        if (!empty($lst)) {
            insert($con, $t = table(array("cols" => "2")));
            //insert($con,$t = table(array("cols"=>"2", "class"=>"outputtable")));
            //setdefault("cell",array("class"=>"heading"));
            insert($t, $c = cell());
            insert($c, text(my_("Current Members")));
            insert($t, $c = cell());
            $icecream = 0;
            foreach ($lst as $u) {
                //setdefault("cell",array("class"=>color_flip_flop()));
                $icecream++;
                insert($t, $c = cell());
                insert($c, block("{$u}"));
                insert($t, $c = cell());
                insert($c, $f = form(array("name" => "userkill{$icecream}", "method" => "post", "action" => $_SERVER["PHP_SELF"])));
                insert($f, hidden(array("name" => "action", "value" => "deleteuserfromgroup")));
                insert($f, hidden(array("name" => "userid", "value" => "{$u}")));
                insert($f, hidden(array("name" => "grp", "value" => "{$grp}")));
                insert($f, hidden(array("name" => "refpage", "value" => "grp")));
                insert($c, block("<a href='#' onclick='userkill{$icecream}.submit();'>" . my_("Remove From Group") . "</a>"));
            }
        }
    }
    insert($w, generic("br"));
    // Ok.  How bout adding bounds to the group???
    insert($w, $con = container("fieldset", array("class" => "fieldset")));
    insert($con, $legend = container("legend", array("class" => "legend")));
    insert($con, textbr(my_("NOTE: if the user belongs to multiple groups and one of the groups does not contain authority boundaries, then the user is allowed all actions")));
    insert($legend, text(my_("Authority Boundaries")));
    insert($con, $f2 = form(array("name" => "ENTRY", "method" => "post", "action" => $_SERVER["PHP_SELF"])));
    insert($f2, hidden(array("name" => "grp", "value" => "{$grp}")));
    insert($f2, hidden(array("name" => "action", "value" => "addgroupboundary")));
    insert($f2, text(my_("Authority boundary start address")));
    // from previous post?
    if ($ipaddr == "0.0.0.0") {
        $ipaddr = "";
    }
    insert($f2, input_text(array("name" => "ipaddr", "value" => "{$ipaddr}", "size" => "15", "maxlength" => "15")));
    insert($f2, generic("br"));
    insert($f2, text(my_("Authority size/mask")));
    insert($f2, selectbox(array("4" => "255.255.255.252/30 - 4 hosts", "8" => "255.255.255.248/29 - 8 hosts", "16" => "255.255.255.240/28 - 16 hosts", "32" => "255.255.255.224/27 - 32 hosts", "64" => "255.255.255.192/26 - 64 hosts", "128" => "255.255.255.128/25 - 128 hosts", "256" => "255.255.255.0/24 - 256 hosts (class C)", "512" => "255.255.254.0/23 - 512 hosts", "1024" => "255.255.252.0/22 - 1k hosts", "2048" => "255.255.248.0/21 - 2k hosts", "4096" => "255.255.240.0/20 - 4k hosts", "8192" => "255.255.224.0/19 - 8k hosts", "16384" => "255.255.192.0/18 - 16k hosts", "32768" => "255.255.128.0/17 - 32k hosts", "65536" => "255.255.0.0/16 - 64k hosts (class B)", "16777216" => "255.0.0.0/8 - 16m hosts (class A)"), array("name" => "size"), $size));
    insert($f2, submit(array("value" => my_("Add Boundary"))));
    // add readonly button
    insert($con, $f2 = form(array("name" => "READONLY", "method" => "post", "action" => $_SERVER["PHP_SELF"])));
    insert($f2, hidden(array("name" => "ipaddr", "value" => "0.0.0.0")));
    insert($f2, hidden(array("name" => "size", "value" => "0")));
    insert($f2, hidden(array("name" => "grp", "value" => "{$grp}")));
    insert($f2, hidden(array("name" => "action", "value" => "addgroupboundary")));
    insert($f2, submit(array("value" => my_("Read only group"))));
    insert($f2, generic("br"));
    $result =& $ds->ds->Execute("SELECT boundsaddr, boundssize, grp\n            FROM bounds\n            WHERE grp=" . $ds->ds->qstr($grp) . "\n            ORDER BY boundsaddr");
    // logic here is:
    // boundsaddr=0 and boundssize=0 -> then this is a read only group
    // boundsaddr=0 and boundssize>0 -> number of addresses this group is not allowed to edit
    //                                        at start of subnets
    // boundsaddr>1 and boundssize>0 -> normal bounds within which this group can edit subnets
    //                                      and ip addresses
    $tricky = 0;
    while ($row = $result->FetchRow()) {
        // create a table
        if ($tricky == 0) {
            ++$tricky;
            insert($con, $t = table(array("cols" => "3")));
            // draw heading
            insert($t, $c = cell());
            insert($c, text(my_("Current Boundaries")));
            insert($t, $c = cell());
            insert($t, $c = cell());
        }
        insert($t, $c = cell());
        if ($row["boundsaddr"] == 0) {
            insert($c, text(my_("Read only group")));
            insert($t, $c = cell());
        } else {
            insert($c, text(inet_ntoa($row["boundsaddr"])));
            insert($t, $c = cell());
            insert($c, text(inet_ntoa(inet_aton(ALLNETS) + 1 - $row["boundssize"]) . "/" . inet_bits($row["boundssize"])));
        }
        insert($t, $c = cell());
        list($ipplanParanoid) = myRegister("I:ipplanParanoid");
        insert($c, anchor("usermanager.php?action=deletegroupboundary&grp=" . urlencode($row["grp"]) . "&boundsaddr=" . $row["boundsaddr"], my_("Delete boundary"), $ipplanParanoid ? array("onclick" => "return confirm('" . my_("Are you sure?") . "')") : FALSE));
        if ($row["boundsaddr"] == 0) {
            break;
        }
    }
    insert($w, generic("br"));
}
Esempio n. 8
0
 function RevZoneExport($cust, $zoneid)
 {
     // use local function variables as they may change
     $this->cust = $cust;
     $this->Serial();
     $result = $this->ds->Execute("UPDATE zones " . "set serialdate=" . $this->ds->qstr($this->serialdate) . ", userid=" . $this->ds->qstr(getAuthUsername()) . ", lastexp=" . $this->ds->DBTimeStamp(time()) . ", error_message=" . $this->ds->qstr("") . ", serialnum={$this->serialnum} " . " WHERE customer={$cust} AND id={$zoneid}");
     if ($result) {
         $sqllastmod = $this->ds->SQLDate("M d Y H:i:s", 'lastmod');
         $result = $this->ds->Execute("SELECT id, zoneip, zonesize, zone, serialdate, \n                        serialnum, ttl, refresh, retry, expire, minimum, zonefilepath1, \n                        zonefilepath2, responsiblemail, customer, {$sqllastmod} AS lastmod, \n                        userid, slaveonly\n                    FROM zones\n                    WHERE customer={$cust} AND id={$zoneid}");
         $row = $result->FetchRow();
         $this->zone = $row["zone"];
         $this->zoneip = $row["zoneip"];
         $this->size = $row["zonesize"];
         $prefix = inet_bits($row["zonesize"]);
         $tmpfname = tempnam(DNSEXPORTPATH, "revzone_" . $this->zone . "_");
         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");
         $ip = inet_ntoa($row["zoneip"]);
         list($octet1, $octet2, $octet3, $octet4) = explode(".", $ip);
         fputs($fp, sprintf('<zone domain="%s" zoneip="%s" zonesize="%s" prefix="%s" slaveonly="%s" octect1="%s" octect2="%s" octect3="%s" octect4="%s">', $row["zone"], $ip, $row["zonesize"], $prefix, empty($row["slaveonly"]) ? "N" : $row["slaveonly"], $octet1, $octet2, $octet3, $octet4));
         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");
         // nameservers
         $result1 = $this->ds->Execute("SELECT hname FROM zonedns\n                    WHERE id={$zoneid}\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 = 90;
             $this->errstr .= my_("Invalid zone - zone should have at least two name servers defined");
             return;
         }
         // get records from main ipplan ipaddr tables
         $result1 = $this->ds->Execute("SELECT ipaddr.ipaddr, ipaddr.hname\n                    FROM base, ipaddr\n                    WHERE base.customer = {$cust} AND\n                    base.baseindex = ipaddr.baseindex AND\n                    ipaddr.ipaddr >= " . $row["zoneip"] . " AND\n                    ipaddr.ipaddr <= " . ($row["zoneip"] + $row["zonesize"]) . "\n                    ORDER BY ipaddr.ipaddr");
         while ($row1 = $result1->FetchRow()) {
             $ip = inet_ntoa($row1["ipaddr"]);
             // ignore blank records
             if (empty($row1["hname"])) {
                 continue;
             }
             // test for valid domain name
             if (!preg_match('/^(([\\w][\\w\\-\\.]*)\\.)?([\\w][\\w\\-]+)(\\.([\\w][\\w\\.]*))?$/', $row1["hname"])) {
                 $this->errstr .= sprintf(my_("Invalid record - ignored: %s %s"), $ip, $row1["hname"]);
                 continue;
             }
             fputs($fp, '<record><PTR>');
             fputs($fp, sprintf('<host>%s</host>', $row1["hname"]));
             list($octet1, $octet2, $octet3, $octet4) = explode(".", $ip);
             fputs($fp, sprintf('<octet1>%s</octet1>', $octet1));
             fputs($fp, sprintf('<octet2>%s</octet2>', $octet2));
             fputs($fp, sprintf('<octet3>%s</octet3>', $octet3));
             fputs($fp, sprintf('<octet4>%s</octet4>', $octet4));
             fputs($fp, "\n");
             fputs($fp, sprintf('<iphostname>%s</iphostname>', $ip));
             fputs($fp, '</PTR></record>');
             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?
     /*
     
     
     
     
     
         // 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()).
             ", serialnum=$this->serialnum".
             " WHERE customer=$cust AND data_id=".$zoneid);
         if ($result) {
         $result = $this->ds->Execute("SELECT * FROM fwdzone 
             WHERE customer=$cust AND data_id=$zoneid");
             $row = $result->FetchRow();
             $this->domain=$row["domain"];
         $tmpfname = tempnam (DNSEXPORTPATH, "zone_") or
             myError($w,$p, my_("Could not create temporary file!"));
             $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");
         // 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");
         // nameservers
             $result1 = $this->ds->Execute("SELECT hname
             FROM fwddns
             WHERE id=$zoneid
             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) {
             insert($w,textbr(my_("Invalid zone - zone should have at least two name servers defined")));
             }
         $result = $this->ds->Execute("SELECT * FROM fwdzonerec
             WHERE customer=$cust AND data_id=$zoneid
             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") {
                 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 {
                 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);
         }
     return $tmpfname;
     */
 }
Esempio n. 9
0
    $recs = $result->PO_RecordCount("ipaddr", "baseindex={$baseindex} {$sql}");
}
if (!$recs) {
    if ($search) {
        // only display error if searching and no records
        myError($w, $p, my_("Search found no matching entries"));
    }
}
// sanity check if MAXTABLESIZE in config.php is modified on the fly
// and person has maybe bookmarked paged
if ($baseaddr + $block * MAXTABLESIZE >= $baseaddr + $maxcnt) {
    myError($w, $p, my_("This page was bookmarked and contains invalid information which cannot be displayed anymore - restart from main menu"));
}
insert($w, block("<h3>"));
insert($w, textbr(my_("Customer/autonomous system description:") . " " . $ds->GetCustomerDescrip($cust)));
insert($w, text(my_("Subnet:") . " " . inet_ntoa($baseaddr) . " " . my_("Mask:") . " " . inet_ntoa(inet_aton(ALLNETS) + 1 - $maxcnt) . "/" . inet_bits($maxcnt)));
insert($w, textbr());
insert($w, text(my_("Description:") . " " . $netdescrip));
insert($w, block("<small>"));
insert($w, anchor("modifybase.php?cust={$cust}&descrip=" . urlencode($netdescrip), my_("Delete/Edit/Modify/Split/Join Subnet")));
insert($w, block("</small>"));
/* not all vars available for link
    insert($w,anchor("modifysubnet.php?baseindex=".$row["baseindex"].
                     "&areaindex=".$areaindex."&rangeindex=".$rangeindex.
                     "&cust=".$cust."&descrip=".urlencode($row["descrip"]).
                     "&ipaddr=".urlencode($ipaddr)."&search=".urlencode($descrip).
                     "&grp=".urlencode($row["admingrp"]), 
                     my_("Modify")));

// modifysubnet.php?baseindex=4336&areaindex=0&rangeindex=0&cust=25&descrip=Loopback&ipaddr=127&search=&grp=abcadm
*/
Esempio n. 10
0
function ProcessNmap($ds, $base, $id, $size)
{
    global $addhostinfo;
    $resarr = array();
    if ($addhostinfo) {
        $command = NMAP . " -sP " . escapeshellarg(inet_ntoa($base) . "/" . inet_bits($size)) . " -oX -";
    } else {
        $command = NMAP . " -n -sP " . escapeshellarg(inet_ntoa($base) . "/" . inet_bits($size)) . " -oX -";
    }
    exec($command, $resarr, $retval);
    // did NMAP fail due to safe mode or other error?
    if ($retval) {
        return 1;
    } else {
        // no error
        require_once "../xmllib.php";
        $input = implode("", $resarr);
        // nmap parser always returns arrays for tags of form
        // [tagname][0...x][element]
        // array index will mostly be zero if one as most results
        // return 1 tag
        $xml_parser = new xmlnmap("HOST");
        if (!$xml_parser->parser) {
            return 1;
            // XML parser failure - probably not compiled in
        }
        $output = $xml_parser->parse($input);
        if (!$output) {
            return 1;
            // not XML format
        }
        foreach ($output as $value) {
            if ($value["STATUS"][0]["STATE"] == "up") {
                // need to loop through ADDR array here! Check that
                // ["ADDRESS"][0]["ADDRTYPE"]=="ipv4" or
                // ["ADDRESS"][0]["ADDRTYPE"]=="mac"
                $newbase = inet_aton($value["ADDRESS"][0]["ADDR"]);
                $newmac = "";
                if ($value["ADDRESS"][1]["ADDRTYPE"] == "mac") {
                    $newmac = str_replace(array(":", "-", " "), "", $value["ADDRESS"][1]["ADDR"]);
                }
                if (empty($value["OSMATCH"][0]["NAME"])) {
                    $newuser = "";
                } else {
                    $newuser = $value["OSMATCH"][0]["NAME"];
                }
                $newdescrip = "active";
                if (!empty($value["HOSTNAME"][0]["NAME"])) {
                    $newhname = $value["HOSTNAME"][0]["NAME"];
                } else {
                    $newhname = "";
                }
                // check within range of subnet before adding to ignore
                // broadcast and network addresses
                if ($newbase > $base and $newbase < $base + $size - 1) {
                    $ds->AddIP($newbase, $id, $newuser, "", "", $newmac, $newdescrip, $newhname, "");
                    // address was polled? So add polled status
                    $ds->UpdateIPPoll($id, $newbase);
                }
            }
        }
        return 0;
    }
}
Esempio n. 11
0
     insert($c, textb($row["zone"]));
     insert($c, block(" &Dagger;"));
 } else {
     insert($c, text($row["zone"]));
 }
 //    insert($c,text($row["zone"]));
 insert($c, textbr());
 insert($c, block("<small><i>"));
 if ($row["slaveonly"] == "Y") {
     insert($c, text(my_("Slave zone")));
     insert($c, textbr());
     $export->addCell($row["zone"] . my_(" (Slave zone)") . " " . inet_ntoa($row['zoneip']) . "/" . inet_bits($row['zonesize']));
 } else {
     $export->addCell($row["zone"] . " " . inet_ntoa($row['zoneip']) . "/" . inet_bits($row['zonesize']));
 }
 insert($c, anchor("findfree.php?cust={$cust}&showused=1" . "&start=" . inet_ntoa($row["zoneip"]) . "&end=" . inet_ntoa($row["zoneip"] + $row["zonesize"] - 1), inet_ntoa($row["zoneip"]) . "/" . inet_bits($row["zonesize"])));
 insert($c, block("</i></small>"));
 $result1 =& $ds->ds->Execute("SELECT hname FROM zonedns\n            WHERE id=" . $row["id"] . "\n            ORDER BY horder");
 insert($t, $c = cell());
 $row1 = $result1->FetchRow();
 insert($c, text($row1["hname"]));
 $export->addCell($row1["hname"]);
 insert($t, $c = cell());
 $row1 = $result1->FetchRow();
 insert($c, text($row1["hname"]));
 $export->addCell($row1["hname"]);
 insert($t, $c = cell());
 insert($c, text($row["serialdate"] . str_pad($row["serialnum"], 2, '0', STR_PAD_LEFT)));
 $export->addCell($row["serialdate"] . str_pad($row["serialnum"], 2, '0', STR_PAD_LEFT));
 insert($t, $c = cell());
 insert($c, text($row["ttl"]));
Esempio n. 12
0
insert($t, $ck = cell());
insert($ck, text(my_("Action")));
$cnt = 0;
while ($row = $result->FetchRow()) {
    setdefault("cell", array("class" => color_flip_flop()));
    insert($t, $c = cell());
    insert($c, anchor("displaysubnet.php?baseindex=" . $row["baseindex"] . "&cust=" . $cust, inet_ntoa($row["baseaddr"])));
    if ($row["subnetsize"] == 1) {
        insert($t, $c = cell());
        insert($c, text(my_("Host")));
    } else {
        insert($t, $c = cell());
        insert($c, text($row["subnetsize"]));
    }
    insert($t, $c = cell());
    insert($c, text(inet_ntoa(inet_aton(ALLNETS) + 1 - $row["subnetsize"]) . "/" . inet_bits($row["subnetsize"])));
    insert($t, $c = cell());
    insert($c, text($row["descrip"]));
    insert($t, $c = cell());
    insert($c, block("<small>"));
    insert($c, anchor("../admin/usermanager.php?action=groupeditform&grp=" . urlencode($row["admingrp"]), $row["admingrp"]));
    insert($c, block("</small>"));
    insert($t, $c = cell());
    insert($c, block("<small>"));
    insert($c, checkbox(array("name" => "baseindex[]", "value" => $row["baseindex"]), ""));
    insert($c, anchor($_SERVER["PHP_SELF"] . "?baseindex=" . $row["baseindex"] . "&cust=" . $cust . "&areaindex=" . $areaindex . "&rangeindex=" . $rangeindex . "&descrip=" . urlencode($descrip) . "&block=" . $block . "&ipaddr=" . $ipaddr . "&action=delete", my_("Delete Subnet"), $ipplanParanoid ? array("onclick" => "return confirm('" . my_("Are you sure?") . "')") : FALSE));
    insert($c, block(" | "));
    insert($c, anchor("modifysubnet.php?baseindex=" . $row["baseindex"] . "&areaindex=" . $areaindex . "&rangeindex=" . $rangeindex . "&cust=" . $cust . "&descrip=" . urlencode($row["descrip"]) . "&ipaddr=" . urlencode($ipaddr) . "&search=" . urlencode($descrip) . "&grp=" . urlencode($row["admingrp"]), my_("Modify/Copy/Move subnet details")));
    insert($c, block(" | "));
    insert($c, anchor($_SERVER["PHP_SELF"] . "?baseindex=" . $row["baseindex"] . "&cust=" . $cust . "&areaindex=" . $areaindex . "&rangeindex=" . $rangeindex . "&descrip=" . urlencode($descrip) . "&block=" . $block . "&ipaddr=" . $ipaddr . "&action=join", my_("Join Subnet"), $ipplanParanoid ? array("onclick" => "return confirm('" . my_("Are you sure?") . "')") : FALSE));
    if ($row["subnetsize"] > 1) {
Esempio n. 13
0
    if (isset($val["dbfsize"])) {
        insert($t, $c = cell());
        if ($val["dbfsize"] == 1) {
            insert($c, text($val["dbfbase"]));
        } else {
            insert($c, anchor("displaysubnet.php?baseindex=" . $val["baseindex"], $val["dbfbase"]));
        }
        insert($t, $c = cell());
        if ($val["dbfsize"] == 1) {
            insert($c, text(my_("Host")));
        } else {
            insert($c, text($val["dbfsize"]));
        }
        insert($t, $c = cell());
        if ($val["dbfsize"]) {
            insert($c, text(inet_ntoa(inet_aton(ALLNETS) + 1 - $val["dbfsize"]) . "/" . inet_bits($val["dbfsize"])));
        }
        insert($t, $c = cell());
        insert($c, text($val["dbfdescrip"]));
    } else {
        insert($t, $c = cell());
        insert($t, $c = cell());
        insert($t, $c = cell());
        insert($t, $c = cell());
    }
    $cnt++;
}
insert($w, block("<p>"));
insert($w, textb(sprintf(my_("Total records: %u"), $cnt)));
$result->Close();
printhtml($p);
Esempio n. 14
0
insert($fdel, hidden(array("name" => "baseindex", "value" => "{$baseindex}")));
insert($fdel, hidden(array("name" => "ip", "value" => "{$ip}")));
insert($fdel, hidden(array("name" => "subnetsize", "value" => "{$subnetsize}")));
insert($fdel, hidden(array("name" => "action", "value" => "delete")));
insert($fdel, hidden(array("name" => "block", "value" => "{$block}")));
insert($fdel, hidden(array("name" => "search", "value" => "{$search}")));
insert($fdel, hidden(array("name" => "expr", "value" => "{$expr}")));
insert($fdel, hidden(array("name" => "md5str", "value" => "{$md5str}")));
insert($fdel, hidden(array("name" => "close", "value" => "{$close}")));
insert($fdel, submit(array("value" => my_("Delete record"))));
insert($fdel, text(my_("WARNING: Deleting an entry does not preserve the last modified information as the record is completely removed from the database to conserve space. ")));
if (is_array($files)) {
    myError($fdel, $p, my_("Deleting this record will delete all associated uploaded files!") . "\n", FALSE);
}
// end of delete form
// dummy form for "follow" function
$settings = array("name" => "DUMMY", "method" => "get", "action" => "displaybase.php");
insert($w, $f = form($settings));
insert($f, hidden(array("name" => "ipaddr", "value" => $lnk)));
insert($f, hidden(array("name" => "cust", "value" => $cust)));
insert($f, hidden(array("name" => "searchin", "value" => "1")));
insert($f, hidden(array("name" => "jump", "value" => "1")));
// create the export view form
$export = new exportForm();
$export->addRow(array("user", "location", "description", "hostname", "telephone", "mac_addr", "linked_addr"));
$export->saveRow();
$export->addRow(array($userinf, $location, $descrip, $hname, $telno, $macaddr, $lnk));
$export->saveRow();
$export->setInfo(array(array("subnet_ID", "subnet_addr", "subnet_mask", "subnet_description", "ip_address"), array($baseindex, inet_ntoa($baseaddr), inet_ntoa(inet_aton(ALLNETS) + 1 - $subnetsize) . "/" . inet_bits($subnetsize), $netdescrip, $ip)));
$export->createExportForm($w, $template);
printhtml($p);