Example #1
0
 public function insertCrawlData($data)
 {
     $router_data = Router_old::getRouterInfo($data['router_id']);
     $actual_crawl_cycle = Crawling::getActualCrawlCycle();
     $last_endet_crawl_cycle = Crawling::getLastEndedCrawlCycle();
     /**Insert Router Interfaces*/
     foreach ($data['interface_data'] as $sendet_interface) {
         //Update RRD Graph DB
         $interface_last_endet_crawl = Interfaces::getInterfaceCrawlByCrawlCycleAndRouterIdAndInterfaceName($last_endet_crawl_cycle['id'], $data['router_id'], $sendet_interface['name']);
         $traffic_rx_bps = round(($sendet_interface['traffic_rx'] - $interface_last_endet_crawl['traffic_rx']) / $GLOBALS['crawl_cycle'] / 60);
         $traffic_rx_bps = $traffic_rx_bps < 0 ? 0 : $traffic_rx_bps;
         $traffic_tx_bps = round(($sendet_interface['traffic_tx'] - $interface_last_endet_crawl['traffic_tx']) / $GLOBALS['crawl_cycle'] / 60);
         $traffic_tx_bps = $traffic_tx_bps < 0 ? 0 : $traffic_tx_bps;
         //Set default indizies to prevent from warnings
         $sendet_interface['wlan_frequency'] = isset($sendet_interface['wlan_frequency']) ? preg_replace("/([A-Za-z])/", "", $sendet_interface['wlan_frequency']) : "";
         $sendet_interface['wlan_mode'] = isset($sendet_interface['wlan_mode']) ? $sendet_interface['wlan_mode'] : "";
         $sendet_interface['wlan_essid'] = isset($sendet_interface['wlan_essid']) ? $sendet_interface['wlan_essid'] : "";
         $sendet_interface['wlan_bssid'] = isset($sendet_interface['wlan_bssid']) ? $sendet_interface['wlan_bssid'] : "";
         $sendet_interface['wlan_tx_power'] = isset($sendet_interface['wlan_tx_power']) ? $sendet_interface['wlan_tx_power'] : 0;
         //check if interface already exists
         $networkinterface_test = new Networkinterface(false, (int) $data['router_id'], $sendet_interface['name']);
         //if interface not exist, create new
         if (!$networkinterface_test->fetch()) {
             $networkinterface_new = new Networkinterface(false, (int) $data['router_id'], $sendet_interface['name']);
             $networkinterface_id = $networkinterface_new->store();
         } else {
             $networkinterface_id = $networkinterface_test->getNetworkinterfaceId();
         }
         //save crawl data for interface
         $networkinterface_status = new NetworkinterfaceStatus(false, (int) $actual_crawl_cycle['id'], (int) $networkinterface_id, (int) $data['router_id'], $sendet_interface['name'], $sendet_interface['mac_addr'], (int) $sendet_interface['mtu'], (int) $sendet_interface['traffic_rx'], (int) $traffic_rx_bps, (int) $sendet_interface['traffic_tx'], (int) $traffic_tx_bps, $sendet_interface['wlan_mode'], $sendet_interface['wlan_frequency'], $sendet_interface['wlan_essid'], $sendet_interface['wlan_bssid'], (int) $sendet_interface['wlan_tx_power'], false);
         $networkinterface_status->store();
         //Update RRDDatabase
         $rrd_path_traffic_rx = ROOT_DIR . "/rrdtool/databases/router_{$data['router_id']}_interface_{$sendet_interface['name']}_traffic_rx.rrd";
         if (!file_exists($rrd_path_traffic_rx)) {
             exec("rrdtool create {$rrd_path_traffic_rx} --step 600 --start " . time() . " DS:traffic_rx:GAUGE:700:U:U DS:traffic_tx:GAUGE:900:U:U RRA:AVERAGE:0:1:144 RRA:AVERAGE:0:6:168 RRA:AVERAGE:0:18:240");
         }
         exec("rrdtool update {$rrd_path_traffic_rx} " . time() . ":" . round($traffic_rx_bps / 1000, 2) . ":" . round($traffic_tx_bps / 1000, 2));
         //add unknown ipv6 link local addresses to netmon
         //prepare data
         $ipv6_link_local_addr = explode("/", $sendet_interface['ipv6_link_local_addr']);
         $ipv6_link_local_netmask = isset($ipv6_link_local_addr[1]) ? (int) $ipv6_link_local_addr[1] : 64;
         $ipv6_link_local_addr = Ip::ipv6Expand($ipv6_link_local_addr[0]);
         //first try to determine network of given address
         $ipv6_link_local_network = Ip::ipv6NetworkFromAddr($ipv6_link_local_addr, (int) $ipv6_link_local_netmask);
         $network = new Network(false, false, $ipv6_link_local_network, (int) $ipv6_link_local_netmask, 6);
         if ($network->fetch()) {
             //if network found, then try to add ip address
             $ip = new Ip(false, (int) $networkinterface_id, $network->getNetworkId(), $ipv6_link_local_addr);
             $ip->store();
         }
     }
     RrdTool::updateRouterClientCountHistory($data['router_id'], $data['client_count']);
 }
Example #2
0
<?php

/** Include Classes **/
require_once 'runtime.php';
require_once './lib/core/router_old.class.php';
require_once './lib/core/crawling.class.php';
require_once './lib/core/Chipsetlist.class.php';
/** Get and assign global messages **/
$smarty->assign('message', Message::getMessage());
/** Get and assign crawler status **/
$last_ended_crawl_cycle = Crawling::getLastEndedCrawlCycle();
if (!empty($last_ended_crawl_cycle)) {
    $last_ended_crawl_cycle['crawl_date_end'] = strtotime($last_ended_crawl_cycle['crawl_date']) + $GLOBALS['crawl_cycle'] * 60;
    $actual_crawl_cycle = Crawling::getActualCrawlCycle();
    $actual_crawl_cycle['crawl_date_end'] = strtotime($actual_crawl_cycle['crawl_date']) + $GLOBALS['crawl_cycle'] * 60;
    $actual_crawl_cycle['crawl_date_end_minutes'] = floor(($actual_crawl_cycle['crawl_date_end'] - time()) / 60) . ':' . sprintf("%02d", ($actual_crawl_cycle['crawl_date_end'] - time()) % 60);
    $smarty->assign('last_ended_crawl_cycle', $last_ended_crawl_cycle);
    $smarty->assign('actual_crawl_cycle', $actual_crawl_cycle);
    /**Get number of routers by chipset **/
    $chipsetlist = new Chipsetlist();
    $router_chipsets = array();
    foreach ($chipsetlist->getList() as $key => $chipset) {
        $router_chipsets[$key]['chipset_id'] = $chipset->getChipsetId();
        $router_chipsets[$key]['chipset_name'] = $chipset->getName();
        $router_chipsets[$key]['hardware_name'] = $chipset->getHardwareName();
        $router_chipsets[$key]['count'] = Router_old::countRoutersByChipsetId($chipset->getChipsetId());
    }
    /*	echo "<pre>";
    	print_r($router_chipsets);
    	die();*/
    $smarty->assign('router_chipsets', $router_chipsets);
Example #3
0
 public function getRoutersClients()
 {
     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('Style');
     $xw->writeAttribute('id', 'sh_client-pushpin-1');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>1.0</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/clients_2_1.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('Style');
     $xw->writeAttribute('id', 'sh_client-pushpin-2');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>1.0</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/clients_2_2.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('Style');
     $xw->writeAttribute('id', 'sh_client-pushpin-3');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>1.0</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/clients_2_3.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('Style');
     $xw->writeAttribute('id', 'sh_client-pushpin-4');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>1.0</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/clients_2_4.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('Style');
     $xw->writeAttribute('id', 'sh_client-pushpin-5');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>1.0</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/clients_2_5.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('Style');
     $xw->writeAttribute('id', 'sh_client-pushpin-6');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>1.0</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/clients_2_6.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('Style');
     $xw->writeAttribute('id', 'sh_blue-pushpin');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>0.5</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/ip_highlighted.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('ListStyle');
     $xw->endElement();
     $xw->startElement('Style');
     $xw->writeAttribute('id', 'sh_ip_online_highlighted_pushpin');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>0.5</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/ip_online_highlighted_1.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('ListStyle');
     $xw->endElement();
     $xw->startElement('Style');
     $xw->writeAttribute('id', 'sh_red-pushpin');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>0.5</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/ip_offline.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('ListStyle');
     $xw->endElement();
     $xw->startElement('Style');
     $xw->writeAttribute('id', 'sh_yellow-pushpin');
     $xw->startElement('IconStyle');
     $xw->writeRaw('<scale>0.5</scale>');
     $xw->startElement('Icon');
     $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/ip_unknown.png</href>');
     $xw->endElement();
     $xw->endElement();
     $xw->endElement();
     $xw->startElement('ListStyle');
     $xw->endElement();
     $xw->startElement('Folder');
     $xw->startElement('name');
     $xw->writeRaw('create');
     $xw->endElement();
     $last_endet_crawl_cycle = Crawling::getLastEndedCrawlCycle();
     $crawl_routers = Router_old::getCrawlRoutersByCrawlCycleId($last_endet_crawl_cycle['id']);
     foreach ($crawl_routers as $crawl_router) {
         $router_data = Router_old::getRouterInfo($crawl_router['router_id']);
         $crawl_interfaces = Interfaces::getInterfacesCrawlByCrawlCycle($last_endet_crawl_cycle['id'], $crawl_router['router_id']);
         $row['traffic'] = 0;
         foreach ($crawl_interfaces as $interface) {
             $traffic = $traffic + $interface['traffic_rx_avg'] + $interface['traffic_tx_avg'];
         }
         $traffic = round($traffic / 1024, 2);
         //Make coordinates and location information
         if (!empty($crawl_router['longitude']) and !empty($crawl_router['latitude'])) {
             $longitude = $crawl_router['longitude'];
             $latitude = $crawl_router['latitude'];
             $location = $crawl_router['location'];
             $do = true;
         } elseif (!empty($router_data['longitude']) and !empty($router_data['latitude'])) {
             $longitude = $router_data['longitude'];
             $latitude = $router_data['latitude'];
             $location = $router_data['location'];
             $do = true;
         } else {
             $do = false;
         }
         if ($do) {
             $xw->startElement('Placemark');
             $xw->startElement('name');
             $xw->writeRaw("<![CDATA[Router <a href='" . $GLOBALS['url_to_netmon'] . "/router.php?router_id=" . $router_data['router_id'] . "'>" . $router_data['hostname'] . "</a>]]>");
             $xw->endElement();
             $xw->startElement('description');
             $box_inhalt = "Clients";
             $xw->writeRaw("<![CDATA[{$box_inhalt}]]>");
             $xw->endElement();
             $xw->startElement('styleUrl');
             if ($crawl_router['client_count'] == 0) {
                 $xw->writeRaw('#sh_client-pushpin-0');
             } elseif ($crawl_router['client_count'] == 1) {
                 $xw->writeRaw('#sh_client-pushpin-1');
             } elseif ($crawl_router['client_count'] == 2) {
                 $xw->writeRaw('#sh_client-pushpin-2');
             } elseif ($crawl_router['client_count'] == 3) {
                 $xw->writeRaw('#sh_client-pushpin-3');
             } elseif ($crawl_router['client_count'] == 4) {
                 $xw->writeRaw('#sh_client-pushpin-4');
             } elseif ($crawl_router['client_count'] == 5) {
                 $xw->writeRaw('#sh_client-pushpin-5');
             } elseif ($crawl_router['client_count'] >= 6) {
                 $xw->writeRaw('#sh_client-pushpin-6');
             }
             $xw->endElement();
             $xw->startElement('Point');
             $xw->startElement('coordinates');
             $xw->writeRaw("{$longitude},{$latitude},0");
             $xw->endElement();
             $xw->endElement();
             $xw->endElement();
         }
     }
     $xw->endElement();
     $xw->endElement();
     $xw->endDocument();
     print $xw->outputMemory(true);
     return true;
 }
Example #4
0
    if (permission::checkIfUserIsOwnerOrPermitted(PERM_ROOT, $router->getUserId())) {
        $smarty->assign('router', $router);
        $smarty->display("header.tpl.html");
        $smarty->display("interface_add.tpl.html");
        $smarty->display("footer.tpl.html");
    } else {
        Permission::denyAccess(PERM_ROOT, $router->getUserId());
    }
} elseif ($_GET['section'] == 'insert_add') {
    $router = new Router((int) $_GET['router_id']);
    $router->fetch();
    if (permission::checkIfUserIsOwnerOrPermitted(PERM_ROOT, $router->getUserId())) {
        $networkinterface = new Networkinterface(false, (int) $_GET['router_id'], $_POST['name']);
        if ($networkinterface->fetch() == false) {
            $networkinterface_id = $networkinterface->store();
            $networkinterface_status = new NetworkinterfaceStatus(false, (int) Crawling::getLastEndedCrawlCycle()['id'], (int) $networkinterface_id, (int) $_GET['router_id']);
            $networkinterface_status->store();
            $message[] = array("Das Netzwerkinterface " . $_POST['name'] . " wurde hinzugefügt.", 1);
            Message::setMessage($message);
            header('Location: ./router.php?router_id=' . $_GET['router_id']);
        } else {
            $message[] = array("Das Netzwerkinterface " . $_POST['name'] . " existiert bereits.", 2);
            Message::setMessage($message);
            header('Location: ./router.php?router_id=' . $_GET['router_id']);
        }
    } else {
        Permission::denyAccess(PERM_ROOT, $router->getUserId());
    }
} elseif ($_GET['section'] == 'delete') {
    $networkinterface = new Networkinterface((int) $_GET['interface_id']);
    $networkinterface->fetch();
Example #5
0
 public function store()
 {
     if ($this->getStatusId() != 0 and $this->getCrawlCycleId() != 0 and $this->getRouterId() != 0 and $this->getStatus() != "") {
         echo "UPDATE NOT IMPLEMENTED NOW (and will possibly never be implemented because it is not needed...";
     } elseif ($this->getCrawlCycleId() != 0 and $this->getRouterId() != 0 and $this->getStatus() != "") {
         //check if there already exists an crawl item in this crawl cycle
         $tmp = new RouterStatus(false, $this->getCrawlCycleId(), $this->getRouterId());
         if (!$tmp->fetch()) {
             try {
                 $stmt = DB::getInstance()->prepare("INSERT INTO crawl_routers (router_id, crawl_cycle_id, crawl_date, status,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   hostname, distname, distversion, chipset,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   cpu, memory_total, memory_caching, memory_buffering,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   memory_free, loadavg, processes, uptime, idletime,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   local_time, batman_advanced_version, fastd_version,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   kernel_version, configurator_version,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   nodewatcher_version, firmware_version,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   firmware_revision, openwrt_core_revision,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   openwrt_feeds_packages_revision, client_count)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tVALUES (?, ?, NOW(), ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t?, ?, ?, ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t?, ?, ?, ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t?, ?, ?, ?, ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t?, ?, ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t?, ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t?, ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t?, ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t?, ?)");
                 $stmt->execute(array($this->getRouterId(), $this->getCrawlCycleId(), $this->getStatus(), $this->getHostname(), $this->getDistname(), $this->getDistversion(), $this->getChipset(), $this->getCpu(), $this->getMemoryTotal(), $this->getMemoryCaching(), $this->getMemoryBuffering(), $this->getMemoryFree(), $this->getLoadavg(), $this->getProcesses(), $this->getUptime(), $this->getIdletime(), $this->getLocaltime(), $this->getBatmanAdvancedVersion(), $this->getFastdVersion(), $this->getKernelVersion(), $this->getConfiguratorVersion(), $this->getNodewatcherVersion(), $this->getFirmwareVersion(), $this->getFirmwareRevision(), $this->getOpenwrtCoreRevision(), $this->getOpenwrtFeedsPackagesRevision(), $this->getClientCount()));
             } catch (PDOException $e) {
                 echo $e->getMessage();
                 echo $e->getTraceAsString();
             }
             //Update RRD-Files for graphs
             RrdTool::updateRouterMemoryHistory($this->getRouterId(), $this->getMemoryFree(), $this->getMemoryCaching(), $this->getMemoryBuffering());
             $processes = explode("/", $this->getProcesses());
             $processes[0] = isset($processes[0]) ? $processes[0] : 0;
             $processes[1] = isset($processes[1]) ? $processes[1] : 1;
             RrdTool::updateRouterProcessHistory($this->getRouterId(), $processes[0], $processes[1]);
             //create events
             $eventlist = new Eventlist();
             $router = new Router($this->getRouterId());
             $router->fetch();
             $last_router_status = new RouterStatus(false, (int) Crawling::getLastEndedCrawlCycle()['id'], $this->getRouterId());
             if ($last_router_status->fetch()) {
                 if ($this->getStatus() and $last_router_status->getStatus() and $this->getStatus() != $last_router_status->getStatus()) {
                     $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "status", array('from' => $last_router_status->getStatus(), 'to' => $this->getStatus(), 'hostname' => $router->getHostname())));
                 }
                 if ($this->getUptime() and $last_router_status->getUptime() and $this->getUptime() < $last_router_status->getUptime()) {
                     $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "reboot", array('hostname' => $router->getHostname())));
                 }
                 if ($this->getHostname() and $last_router_status->getHostname() and $this->getHostname() != $last_router_status->getHostname()) {
                     $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "hostname", array('from' => $last_router_status->getHostname(), 'to' => $this->getHostname(), 'hostname' => $router->getHostname())));
                 }
                 if ($this->getChipset() and $last_router_status->getChipset() and $this->getChipset() != $last_router_status->getChipset()) {
                     $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "chipset", array('from' => $last_router_status->getChipset(), 'to' => $this->getChipset(), 'hostname' => $router->getHostname())));
                 }
                 if ($this->getNodewatcherVersion() and $last_router_status->getNodewatcherVersion() and $this->getNodewatcherVersion() != $last_router_status->getNodewatcherVersion()) {
                     $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "nodewatcher_version", array('from' => $last_router_status->getNodewatcherVersion(), 'to' => $this->getNodewatcherVersion(), 'hostname' => $router->getHostname())));
                 }
                 if ($this->getFirmwareVersion() and $last_router_status->getFirmwareVersion() and $this->getFirmwareVersion() != $last_router_status->getFirmwareVersion()) {
                     $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "firmware_version", array('from' => $last_router_status->getFirmwareVersion(), 'to' => $this->getFirmwareVersion(), 'hostname' => $router->getHostname())));
                 }
                 if ($this->getBatmanAdvancedVersion() and $last_router_status->getBatmanAdvancedVersion() and $this->getBatmanAdvancedVersion() != $last_router_status->getBatmanAdvancedVersion()) {
                     $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "batman_advanced_version", array('from' => $last_router_status->getBatmanAdvancedVersion(), 'to' => $this->getBatmanAdvancedVersion(), 'hostname' => $router->getHostname())));
                 }
                 if ($this->getDistversion() and $last_router_status->getDistversion() and $this->getDistversion() != $last_router_status->getDistversion()) {
                     $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "distversion", array('from' => $last_router_status->getDistversion(), 'to' => $this->getDistversion(), 'hostname' => $router->getHostname())));
                 }
                 if ($this->getDistname() and $last_router_status->getDistname() and $this->getDistname() != $last_router_status->getDistname()) {
                     $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "distname", array('from' => $last_router_status->getDistname(), 'to' => $this->getDistname(), 'hostname' => $router->getHostname())));
                 }
             }
             $eventlist->store();
             //Check if netmon already knows the given chipset and if
             //the router assigned to this status has the right chipset set
             if ($this->getStatus() == "online" and $router->getChipset()->getName() != $this->getChipset()) {
                 $chipset = new Chipset(false, $this->getChipset());
                 if (!$chipset->fetch()) {
                     $chipset->store();
                 }
                 $router->setChipsetId($chipset->getChipsetId());
                 $router->store();
             }
             //Return the ID of the inserted RouterStatus
             return DB::getInstance()->lastInsertId();
         }
     }
     return false;
 }
Example #6
0
 public function insertNewRouter()
 {
     $check_router_hostname_exist = Router_old::getRouterByHostname($_POST['hostname']);
     if (!isset($_POST['allow_router_auto_assign'])) {
         $_POST['allow_router_auto_assign'] = 0;
         $_POST['router_auto_assign_login_string'] = '';
     }
     if ($_POST['allow_router_auto_assign'] == '1' and !empty($_POST['router_auto_assign_login_string'])) {
         $check_router_auto_assign_login_string = Router_old::getRouterByAutoAssignLoginString($_POST['router_auto_assign_login_string']);
     }
     if (empty($_POST['hostname'])) {
         $message[] = array("Bitte geben Sie einen Hostname an.", 2);
         Message::setMessage($message);
         return array("result" => false, "router_id" => $router_id);
     } elseif (!empty($check_router_hostname_exist)) {
         $message[] = array("Ein Router mit dem Hostnamen {$_POST['hostname']} existiert bereits, bitte wählen Sie einen anderen Hostnamen.", 2);
         Message::setMessage($message);
         return array("result" => false, "router_id" => $router_id);
     } elseif (!(is_string($_POST['hostname']) and strlen($_POST['hostname']) <= 255 and preg_match("/^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])(\\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]))*\$/", $_POST['hostname']))) {
         //check for valid hostname as specified in rfc 1123
         //see http://stackoverflow.com/a/3824105
         $message[] = array("Der Hostname ist ungültig. Erlaubt sind Hostnames nach RFC 1123.", 2);
         Message::setMessage($message);
         return array("result" => false, "router_id" => $router_id);
     } elseif (!empty($check_router_auto_assign_login_string)) {
         $message[] = array("Der Router Auto Assign Login String wird bereits verwendet.", 2);
         Message::setMessage($message);
         return array("result" => false, "router_id" => $router_id);
     } elseif ($_POST['allow_router_auto_assign'] == '1' and ($_POST['router_auto_assign_login_string'] == "Mac-Adresse..." or empty($_POST['router_auto_assign_login_string']) or ctype_space($_POST['router_auto_assign_login_string']))) {
         $message[] = array("Wenn Automatische Routerzuweisung aktiviert ist, muss eine Mac-Adresse gesetzt werden.", 2);
         $message[] = array("Du findest die Mac-Adresse oft auf der Rückseite des Routers.", 0);
         Message::setMessage($message);
         return array("result" => false, "router_id" => $router_id);
     } else {
         if (!is_numeric($_POST['latitude']) or !is_numeric($_POST['longitude'])) {
             $_POST['latitude'] = 0;
             $_POST['longitude'] = 0;
         }
         try {
             $stmt = DB::getInstance()->prepare("INSERT INTO routers (user_id, create_date, update_date, crawl_method, hostname, allow_router_auto_assign, router_auto_assign_login_string, description, location, latitude, longitude, chipset_id)\n\t\t\t\t\t\t\t\t    VALUES (?, NOW(), NOW(), ?, ?, ?, ?, ?, ?, ?, ?, ?)");
             $stmt->execute(array($_SESSION['user_id'], $_POST['crawl_method'], $_POST['hostname'], $_POST['allow_router_auto_assign'], $_POST['router_auto_assign_login_string'], $_POST['description'], $_POST['location'], $_POST['latitude'], $_POST['longitude'], $_POST['chipset_id']));
             $router_id = DB::getInstance()->lastInsertId();
         } catch (PDOException $e) {
             echo $e->getMessage();
             echo $e->getTraceAsString();
         }
         $crawl_cycle_id = Crawling::getLastEndedCrawlCycle();
         $router_status = new RouterStatus(false, (int) $crawl_cycle_id['id'], (int) $router_id, "offline");
         $router_status->store();
         //add new api key
         do {
             $api_key = new ApiKey(false, ApiKey::generateApiKey(), (int) $router_id, "router", "Initial key");
             $api_key_id = $api_key->store();
         } while (!$api_key_id);
         if ($_POST['allow_router_auto_assign'] == '1' and !empty($_POST['router_auto_assign_login_string'])) {
             RoutersNotAssigned::deleteByAutoAssignLoginString($_POST['router_auto_assign_login_string']);
         }
         $message[] = array("Der Router {$_POST['hostname']} wurde angelegt.", 1);
         //Add event for new router
         //TODO: add Router Object to data array
         $event = new Event(false, 'router', (int) $router_id, 'new', array());
         $event->store();
         //Send Message to twitter
         if ($_POST['twitter_notification'] == '1') {
             Message::postTwitterMessage(Config::getConfigValueByName('community_name') . " hat einen neuen #Freifunk Knoten! Wo? Schau nach: " . Config::getConfigValueByName('url_to_netmon') . "/router.php?router_id={$router_id}");
         }
         Message::setMessage($message);
         return array("result" => true, "router_id" => $router_id);
     }
 }
Example #7
0
 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;
 }