ajaxSubnetMembersFilter.php

Go to the documentation of this file.
00001 <?
00002 require("../../../includes/config.inc.php");
00003 require("../../../includes/i18n.inc.php");
00004 require("../../../includes/acl.inc.php");
00005 require("../../../includes/session.inc.php");
00006 require("../../../includes/PageGenerator.php");
00007 require("../../../modules/network/includes/network.inc.php");
00008 require("../../../modules/network/includes/network-xmlrpc.inc.php");
00009 
00010 $filter = $_GET["filter"];
00011 $subnet = $_GET["subnet"];
00012 $subnetInfos = getSubnet($subnet);
00013 $netmask = $subnetInfos[0][1]["dhcpNetMask"][0];
00014 $lines = array();
00015 
00016 foreach(getSubnetHosts($subnet, "") as $dn => $entry) {
00017     $hostname = $entry[1]["cn"][0];
00018     $ipaddress = null;
00019     foreach($entry[1]["dhcpStatements"] as $statements) {
00020         list($name, $value) = explode(" ", $statements, 2);
00021         if ($name == "fixed-address") {
00022             /* Convert to long for easy sorting */
00023             $ipaddress = ip2long($value);
00024             $lines[$ipaddress]["hostname"] =  $hostname;
00025             break;
00026         }
00027     }
00028     if (!$ipaddress) {      
00029         unset($lines[$ipaddress]);
00030         continue; /* We don't support displaying DHCP host with no fixed IP address */
00031     }
00032     list($tmp, $lines[$ipaddress]["macaddress"]) = explode(" ", strtoupper($entry[1]["dhcpHWAddress"][0]));
00033     $lines[$ipaddress]["type"] = _T("Static", "network");
00034     if ($filter) {
00035         /* Don't display a host if filtered */
00036         if (
00037             (strpos($hostname, $filter) === False)
00038             && (strpos(long2ip($ipaddress), $filter) === False)
00039             && (strpos($lines[$ipaddress]["macaddress"], $filter) === False)
00040             ) {
00041             unset($lines[$ipaddress]);
00042         }
00043     }
00044 }
00045 
00046 /* Get current DHCP leases info to display dynamically assigned IP addresses */
00047 $leases = getDhcpLeases();
00048 foreach($leases as $ipaddress => $infos) {
00049     if ($infos["state"] == "active") {
00050         if (ipInNetwork($ipaddress, $subnet, $netmask)) {
00051             /* Only display lease of the current subnet */
00052             $address = ip2long($ipaddress);
00053             $lines[$address]["type"] = _T("Dynamic", "network");
00054             $lines[$address]["macaddress"] = strtoupper($infos["hardware"]);
00055             $lines[$address]["hostname"] = $infos["hostname"];
00056             if ($filter) {
00057                 /* Don't display a host if filtered */
00058                 if (
00059                     (strpos($lines[$address]["hostname"], $filter) === False)
00060                     && (strpos(long2ip($address), $filter) === False)
00061                     && (strpos($lines[$address]["macaddress"], $filter) === False)
00062                     ) {
00063                     unset($lines[$address]);
00064                 }
00065             }            
00066         }
00067     }
00068 }
00069 
00070 ksort($lines);
00071 $hosts = array();
00072 $ipaddresses = array();
00073 $macaddresses = array();
00074 $types = array();
00075 $ends = array();
00076 $params = array();
00077 $actionsAdd = array();
00078 $actionsEdit = array();
00079 $actionsDel = array();
00080 $deleteAction = new ActionPopupItem(_T("Delete host", "network"),"subnetdeletehost","delete","ipaddress", "network", "network");
00081 $addAction = new ActionItem(_T("Add static host", "network"),"subnetaddhost","addhost","ipaddress", "network", "network");
00082 $editAction = new ActionItem(_T("edit static host", "network"),"subnetedithost","edit","ipaddress", "network", "network");
00083 $emptyAction = new EmptyActionItem();
00084 foreach($lines as $ipaddress => $infos) {
00085     $hosts[] = $infos["hostname"];
00086     $ipaddresses[] = long2ip($ipaddress);
00087     $macaddresses[] = $infos["macaddress"];
00088     $types[] = $infos["type"];
00089     $params[] = array("host" => $infos["hostname"],
00090                       "macaddress" => $infos["macaddress"],
00091                       "subnet" => $subnet);
00092     if ($infos["type"] == _T("Static", "network")) {
00093         $actionsAdd[] = $emptyAction;
00094         $actionsDel[] = $deleteAction;
00095         $actionsEdit[] = $editAction;
00096     } else {
00097         $actionsAdd[] = $addAction;
00098         $actionsDel[] = $emptyAction;
00099         $actionsEdit[] = $emptyAction;
00100     }
00101 }
00102 
00103 $n = new ListInfos($ipaddresses, _T("IP address", "network"));
00104 $n->setNavBar(new AjaxNavBar(count($ipaddresses), $filter));
00105 $n->disableFirstColumnActionLink();
00106 $n->setTableHeaderPadding(1);
00107 $n->addExtraInfo($hosts, _T("Host name", "network"));
00108 $n->addExtraInfo($macaddresses, _T("MAC address", "network"));
00109 $n->addExtraInfo($types, _T("Type", "network"));
00110 $n->setName(_T("Host", "network"));
00111 $n->setParamInfo($params);
00112 $n->addActionItemArray($actionsAdd);
00113 $n->addActionItemArray($actionsEdit);
00114 $n->addActionItemArray($actionsDel);
00115 $n->display();
00116 
00117 ?>

Generated on Tue May 4 11:47:32 2010 for MMC web interface by  doxygen 1.5.8