public function GetNetworkRecord($id, $page = 0, $plimit = 4294967296, $firstfree = false) { $network = $this->db->GetRow('SELECT no.ownerid, ne.id, ne.name, inet_ntoa(ne.address) AS address, ne.address AS addresslong, ne.mask, ne.interface, ne.gateway, ne.dns, ne.dns2, ne.domain, ne.wins, ne.dhcpstart, ne.dhcpend, ne.hostid, mask2prefix(inet_aton(ne.mask)) AS prefix, ne.notes, inet_ntoa(broadcast(ne.address, inet_aton(ne.mask))) AS broadcast FROM networks ne LEFT JOIN nodes no ON (no.netid = ne.id AND no.ipaddr = 0 AND no.ipaddr_pub = 0) WHERE ne.id = ?', array($id)); if ($network['ownerid']) { $customer_manager = new LMSCustomerManager($this->db, $this->auth, $this->cache, $this->syslog); $network['customername'] = $customer_manager->GetCustomerName($network['ownerid']); } $nodes = $this->db->GetAllByKey(' SELECT id, name, ipaddr, ownerid, netdev FROM vnodes WHERE netid = ? AND ipaddr > ? AND ipaddr < ? UNION ALL SELECT id, name, ipaddr_pub AS ipaddr, ownerid, netdev FROM vnodes WHERE ipaddr_pub > ? AND ipaddr_pub < ?', 'ipaddr', array($id, $network['addresslong'], ip_long($network['broadcast']), $network['addresslong'], ip_long($network['broadcast']))); if ($network['hostid']) { $network['hostname'] = $this->db->GetOne('SELECT name FROM hosts WHERE id=?', array($network['hostid'])); } $network['size'] = pow(2, 32 - $network['prefix']); $network['assigned'] = sizeof($nodes); $network['free'] = $network['size'] - $network['assigned'] - 2; if ($network['dhcpstart']) { $network['free'] = $network['free'] - (ip_long($network['dhcpend']) - ip_long($network['dhcpstart']) + 1); } if (!$plimit) { $plimit = 256; } $network['pages'] = ceil($network['size'] / $plimit); if ($page > $network['pages']) { $page = $network['pages']; } if ($page < 1) { $page = 1; } $page--; while (1) { $start = $page * $plimit; $end = $network['size'] > $plimit ? $start + $plimit : $network['size']; $network['pageassigned'] = 0; unset($network['nodes']); for ($i = 0; $i < $end - $start; $i++) { $longip = (string) ($network['addresslong'] + $i + $start); $network['nodes']['addresslong'][$i] = $longip; $network['nodes']['address'][$i] = long2ip($longip); if (isset($nodes[$longip])) { $network['nodes']['id'][$i] = $nodes[$longip]['id']; $network['nodes']['netdev'][$i] = $nodes[$longip]['netdev']; $network['nodes']['ownerid'][$i] = $nodes[$longip]['ownerid']; $network['nodes']['name'][$i] = $nodes[$longip]['name']; $network['pageassigned']++; } else { $network['nodes']['id'][$i] = 0; if ($longip == $network['addresslong']) { $network['nodes']['name'][$i] = '<b>NETWORK</b>'; } elseif ($network['nodes']['address'][$i] == $network['broadcast']) { $network['nodes']['name'][$i] = '<b>BROADCAST</b>'; } elseif ($network['nodes']['address'][$i] == $network['gateway']) { $network['nodes']['name'][$i] = '<b>GATEWAY</b>'; } elseif ($longip >= ip_long($network['dhcpstart']) && $longip <= ip_long($network['dhcpend'])) { $network['nodes']['name'][$i] = '<b>DHCP</b>'; } else { $freenode = true; } } } if ($firstfree && !isset($freenode)) { if ($page + 1 >= $network['pages']) { break; } $page++; } else { break; } } $network['rows'] = ceil(sizeof($network['nodes']['address']) / 4); $network['page'] = $page + 1; return $network; }
public function GetNode($id) { if ($result = $this->db->GetRow('SELECT n.*, rs.name AS linkradiosectorname, inet_ntoa(n.ipaddr) AS ip, inet_ntoa(n.ipaddr_pub) AS ip_pub, lc.name AS city_name, (CASE WHEN ls.name2 IS NOT NULL THEN ' . $this->db->Concat('ls.name2', "' '", 'ls.name') . ' ELSE ls.name END) AS street_name, lt.name AS street_type, lb.name AS borough_name, lb.type AS borough_type, ld.name AS district_name, lst.name AS state_name FROM vnodes n LEFT JOIN netradiosectors rs ON rs.id = n.linkradiosector LEFT JOIN location_cities lc ON (lc.id = n.location_city) LEFT JOIN location_streets ls ON (ls.id = n.location_street) LEFT JOIN location_street_types lt ON (lt.id = ls.typeid) LEFT JOIN location_boroughs lb ON (lb.id = lc.boroughid) LEFT JOIN location_districts ld ON (ld.id = lb.districtid) LEFT JOIN location_states lst ON (lst.id = ld.stateid) WHERE n.id = ?', array($id))) { $customer_manager = new LMSCustomerManager($this->db, $this->auth, $this->cache, $this->syslog); $user_manager = new LMSUserManager($this->db, $this->auth, $this->cache, $this->syslog); $result['radiosectors'] = $this->db->GetAll('SELECT * FROM netradiosectors WHERE netdev = ?', array($result['netdev'])); $result['owner'] = $customer_manager->GetCustomerName($result['ownerid']); $result['createdby'] = $user_manager->GetUserName($result['creatorid']); $result['modifiedby'] = $user_manager->GetUserName($result['modid']); $result['creationdateh'] = date('Y/m/d, H:i', $result['creationdate']); $result['moddateh'] = date('Y/m/d, H:i', $result['moddate']); $result['lastonlinedate'] = lastonline_date($result['lastonline']); $result['mac'] = preg_split('/,/', $result['mac']); foreach ($result['mac'] as $mac) { $result['macs'][] = array('mac' => $mac, 'producer' => get_producer($mac)); } unset($result['mac']); if ($netname = $this->db->GetOne('SELECT name FROM networks WHERE id = ?', array($result['netid']))) { $result['netname'] = $netname; } if ($result['ip_pub'] != '0.0.0.0') { $network_manager = new LMSNetworkManager($this->db, $this->auth, $this->cache, $this->syslog); $result['netpubid'] = $network_manager->GetNetIDByIP($result['ip_pub']); $result['netpubname'] = $this->db->GetOne('SELECT name FROM networks WHERE id = ?', array($result['netpubid'])); } return $result; } else { return FALSE; } }