public function batman_advanced_conn_nexthop() { header('Content-type: text/xml'); $xw = new xmlWriter(); $xw->openMemory(); $xw->startDocument('1.0', 'UTF-8'); $xw->startElement('kml'); $xw->writeAttribute('xmlns', 'http://earth.google.com/kml/2.1'); $xw->startElement('Document'); $xw->writeElement('name', '200903170407-200903170408'); $xw->startElement('Folder'); $xw->startElement('name'); $xw->writeRaw('create'); $xw->endElement(); $routers = Router_old::getRouters(); $last_endet_crawl_cycle = Crawling::getLastEndedCrawlCycle(); foreach ($routers as $router) { //set own position to the position saved fix in netmon $router_longitude = $router['longitude']; $router_latitude = $router['latitude']; //if the router has an position in it's actual crawl data, then prefer this position $router_crawl = Router_old::getCrawlRouterByCrawlCycleId($last_endet_crawl_cycle['id'], $router['id']); if (!empty($router_crawl['longitude']) and !empty($router_crawl['latitude'])) { $router_longitude = $router_crawl['longitude']; $router_latitude = $router_crawl['latitude']; } //if the own position is not empt, then look for neighbours if (!empty($router_longitude) and !empty($router_latitude)) { //$originators = BatmanAdvanced::getCrawlBatmanAdvOriginatorsByCrawlCycleId($last_endet_crawl_cycle['id'], $router['id']); $originators = BatmanAdvanced::getCrawlBatmanAdvNexthopsByCrawlCycleId($last_endet_crawl_cycle['id'], $router['id']); //$originators = unserialize($originators['originators']); if (!empty($originators)) { foreach ($originators as $originator) { $neighbour_router = Router_old::getRouterByMacAndCrawlCycleId($originator['nexthop'], $last_endet_crawl_cycle['id']); $neighbour_router_longitude = $neighbour_router['longitude']; $neighbour_router_latitude = $neighbour_router['latitude']; $neighbour_router = Router_old::getCrawlRouterByCrawlCycleId($last_endet_crawl_cycle['id'], $neighbour_router['router_id']); if (!empty($neighbour_router['longitude']) and !empty($neighbour_router['latitude'])) { $neighbour_router_longitude = $neighbour_router['longitude']; $neighbour_router_latitude = $neighbour_router['latitude']; } //check if the position is not empty if (!empty($neighbour_router_longitude) and !empty($neighbour_router_longitude) and strlen($originator['nexthop']) == 17) { $xw->startElement('Placemark'); $xw->startElement('Style'); $xw->startElement('LineStyle'); $xw->startElement('color'); if (Config::getConfigValueByName('routervpnif') == $originator['outgoing_interface']) { $xw->writeRaw("20ff0000"); } else { if ($originator['link_quality'] >= 0 and $originator['link_quality'] < 105) { $xw->writeRaw("ff1e1eff"); } elseif ($originator['link_quality'] >= 105 and $originator['link_quality'] < 130) { $xw->writeRaw("ff4949ff"); } elseif ($originator['link_quality'] >= 130 and $originator['link_quality'] < 155) { $xw->writeRaw("ff6a6aff"); } elseif ($originator['link_quality'] >= 155 and $originator['link_quality'] < 180) { $xw->writeRaw("ff53acff"); } elseif ($originator['link_quality'] >= 180 and $originator['link_quality'] < 205) { $xw->writeRaw("ff79ebff"); } elseif ($originator['link_quality'] >= 205 and $originator['link_quality'] < 230) { $xw->writeRaw("ff7cff79"); } elseif ($originator['link_quality'] >= 230) { $xw->writeRaw("ff0aff04"); } } $xw->endElement(); /*$xw->startElement('width'); $xw->writeRaw("5"); $xw->endElement();*/ $xw->endElement(); $xw->endElement(); $xw->startElement('name'); $xw->writeRaw("myname"); $xw->endElement(); $xw->startElement('Polygon'); $xw->startElement('outerBoundaryIs'); $xw->startElement('LinearRing'); $xw->startElement('coordinates'); $xw->writeRaw("{$router['longitude']},{$router['latitude']},0\n\t\t\t\t\t\t\t{$neighbour_router_longitude},{$neighbour_router_latitude},0"); $xw->endElement(); $xw->endElement(); $xw->endElement(); $xw->endElement(); $xw->endElement(); } } } } } $xw->endElement(); $xw->endElement(); $xw->endElement(); $xw->endDocument(); print $xw->outputMemory(true); return true; }
public function getRouterListByUserId($user_id) { $routers = array(); $last_endet_crawl_cycle = Crawling::getLastEndedCrawlCycle(); try { $stmt = DB::getInstance()->prepare("SELECT routers.id as router_id, routers.create_date as router_create_date, routers.*,\n\t\t\t\t\tchipsets.id as chipset_id, chipsets.name as chipset_name, chipsets.*,\n\t\t\t\t\tusers.id as user_id, users.*,\n\t\t\t\t\tcrawl_routers.status, crawl_routers.nodewatcher_version\n\n\t\t\t\t\tFROM routers\n\t\t\t\t\tLEFT JOIN chipsets on (chipsets.id=routers.chipset_id)\n\t\t\t\t\tLEFT JOIN users on (users.id=routers.user_id)\n\t\t\t\t\tLEFT JOIN crawl_routers on (crawl_routers.router_id=routers.id AND crawl_routers.crawl_cycle_id=?)\n\t\t\t\t\tWHERE routers.user_id=?"); $stmt->execute(array($last_endet_crawl_cycle['id'], $user_id)); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { echo $e->getMessage(); echo $e->getTraceAsString(); } foreach ($rows as $row) { $text = $row['location']; $shorttext = $text; $length = 20; if (strlen($text) > $length) { $shorttext = substr($text, 0, $length - 1); $var = explode(" ", substr($text, $length, strlen($text))); $shorttext .= $var[0]; } $row['short_location'] = $shorttext; $text = $row['chipset_name']; $shorttext = $text; $length = 16; if (strlen($text) > $length) { $shorttext = substr($text, 0, $length - 1); $var = explode(" ", substr($text, $length, strlen($text))); $shorttext .= $var[0]; } $row['short_chipset_name'] = $shorttext; $row['actual_crawl_data'] = Router_old::getCrawlRouterByCrawlCycleId($last_endet_crawl_cycle['id'], $row['router_id']); $row['router_reliability'] = Router_old::getRouterReliability($row['router_id'], 500); $row['originators_count'] = count(BatmanAdvanced::getCrawlBatmanAdvOriginatorsByCrawlCycleId($last_endet_crawl_cycle['id'], $row['router_id'])); $row['interfaces'] = Interfaces::getInterfacesCrawlByCrawlCycle($last_endet_crawl_cycle['id'], $row['router_id']); $row['traffic'] = 0; foreach ($row['interfaces'] as $interface) { $row['traffic'] = $row['traffic'] + $interface['traffic_rx_avg'] + $interface['traffic_tx_avg']; } $row['traffic'] = round($row['traffic'] / 1024, 2); $routers[] = $row; } return $routers; }