Exemplo n.º 1
0
 public function store()
 {
     $networkinterface = new Networkinterface(false, $this->getRouterId(), $this->getName());
     $networkinterface->fetch();
     if ($this->getNetworkinterfaceId() != 0 and $networkinterface->getNetworkinterfaceId() == $this->getNetworkinterfaceId()) {
         try {
             $stmt = DB::getInstance()->prepare("UPDATE interfaces SET\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\trouter_id = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tname = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tupdate_date = NOW()\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE id=?");
             $stmt->execute(array($this->getRouterId(), $this->getName(), $this->getNetworkinterfaceId()));
             return $stmt->rowCount();
         } catch (PDOException $e) {
             echo $e->getMessage();
             echo $e->getTraceAsString();
         }
     } elseif ($this->getRouterId() != 0 and $this->getName() != "" and $networkinterface->getNetworkinterfaceId() == 0) {
         try {
             $stmt = DB::getInstance()->prepare("INSERT INTO interfaces (router_id, name, create_date, update_date)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tVALUES (?, ?, NOW(), NOW())");
             $stmt->execute(array($this->getRouterId(), $this->getName()));
             return DB::getInstance()->lastInsertId();
         } catch (PDOException $e) {
             echo $e->getMessage();
             echo $e->getTraceAsString();
         }
     }
     return false;
 }
Exemplo n.º 2
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']);
 }
Exemplo n.º 3
0
            echo $e->getTraceAsString();
        }
        //Make output
        echo "success;" . $router_data['router_id'] . ";" . $hash . ";" . $router_data['hostname'] . ";" . $row['api_key'];
    }
}
if ($_GET['section'] == "autoadd_ipv6_address") {
    //first try to determine network of given address
    $ipv6_network = Ip::ipv6NetworkFromAddr($_GET['ip'], (int) $_GET['netmask']);
    $network = new Network(false, false, $ipv6_network, (int) $_GET['netmask'], (int) $_GET['ipv']);
    if ($network->fetch()) {
        //if network found, then try to add ip address.
        //first we need to check if the interface we want to add th ip to already exists
        //and if not we need to create it.
        $networkinterface = new Networkinterface(false, (int) $_GET['router_id'], $_GET['networkinterface_name']);
        if (!$networkinterface->fetch()) {
            $networkinterface_id = $networkinterface->store();
            if (!$networkinterface_id) {
                echo "error,new_interface_not_stored";
                die;
            }
        } else {
            $networkinterface_id = $networkinterface->getNetworkinterfaceId();
        }
        //then we can create the ip
        $ip = new Ip(false, (int) $networkinterface_id, (int) $network->getNetworkId(), $_GET['ip']);
        if ($ip->store()) {
            echo "success,address_does_not_exists," . $ip->getIp();
        } else {
            echo "error,new_ip_not_stored";
            die;
Exemplo n.º 4
0
 private function networkinterface()
 {
     if ($this->get_request_method() == "GET" && isset($this->_request['id'])) {
         $networkinterface = new Networkinterface((int) $this->_request['id']);
         if ($networkinterface->fetch()) {
             $domxmldata = $networkinterface->getDomXMLElement($this->domxml);
             $this->response($this->finishxml($domxmldata), 200);
         } else {
             $this->error_code = 1;
             $this->error_message = "Networkinterface not found";
             $this->response($this->finishxml(), 404);
         }
     }
 }
Exemplo n.º 5
0
 public function getNetworkinterface()
 {
     $networkinterface = new Networkinterface($this->getInterfaceId());
     if ($networkinterface->fetch()) {
         return $networkinterface;
     }
     return false;
 }
Exemplo n.º 6
0
        $smarty->assign('message', Message::getMessage());
        $smarty->assign('networkinterface', $networkinterface);
        $networklist = new Networklist();
        $smarty->assign('networklist', $networklist->getNetworklist());
        $router = new Router((int) $_GET['router_id']);
        $router->fetch();
        $smarty->assign('router', $router);
        $smarty->display("header.tpl.html");
        $smarty->display("ip_add.tpl.html");
        $smarty->display("footer.tpl.html");
    } else {
        Permission::denyAccess(PERM_ROOT, $networkinterface->getRouter()->getUserId());
    }
} elseif ($_GET['section'] == 'insert_add') {
    $networkinterface = new Networkinterface((int) $_GET['interface_id']);
    $networkinterface->fetch();
    if (permission::checkIfUserIsOwnerOrPermitted(PERM_ROOT, $networkinterface->getRouter()->getUserId())) {
        $ip = new Ip(false, (int) $_GET['interface_id'], (int) $_POST['network_id'], $_POST['ip']);
        if ($ip->store()) {
            $message[] = array('Die IP ' . $_POST['ip'] . ' wurde angelegt.', 1);
            Message::setMessage($message);
        } else {
            $message[] = array('Die IP ' . $_POST['ip'] . ' konnte nicht angelegt werden.', 2);
            Message::setMessage($message);
        }
        header('Location: ./router.php?router_id=' . $_GET['router_id']);
    } else {
        Permission::denyAccess(PERM_ROOT, $networkinterface->getRouter()->getUserId());
    }
} elseif ($_GET['section'] == 'delete') {
    $ip = new Ip((int) $_GET['ip_id']);
Exemplo n.º 7
0
 $actual_crawl_cycle = Crawling::getActualCrawlCycle();
 $router_has_been_crawled = Crawling::checkIfRouterHasBeenCrawled($_POST['router_id'], $actual_crawl_cycle['id']);
 if (!$router_has_been_crawled) {
     $last_endet_crawl_cycle = Crawling::getLastEndedCrawlCycle();
     /**Insert Router System Data*/
     $router_status = new RouterStatus(false, (int) $actual_crawl_cycle['id'], (int) $_POST['router_id'], $_POST['status'], false, $_POST['hostname'], (int) $_POST['client_count'], $_POST['chipset'], $_POST['cpu'], (int) $_POST['memory_total'], (int) $_POST['memory_caching'], (int) $_POST['memory_buffering'], (int) $_POST['memory_free'], $_POST['loadavg'], $_POST['processes'], $_POST['uptime'], $_POST['idletime'], $_POST['local_time'], $_POST['distname'], $_POST['distversion'], $_POST['openwrt_core_revision'], $_POST['openwrt_feeds_packages_revision'], $_POST['firmware_version'], $_POST['firmware_revision'], $_POST['kernel_version'], $_POST['configurator_version'], $_POST['nodewatcher_version'], $_POST['fastd_version'], $_POST['batman_advanced_version']);
     $router_status->store();
     /**Insert Router Interfaces*/
     foreach ($_POST['int'] as $sendet_interface) {
         /**
          * Interface
          */
         //check if interface already exists
         $networkinterface_test = new Networkinterface(false, (int) $_POST['router_id'], $sendet_interface['name']);
         //if interface not exist, create new
         if (!$networkinterface_test->fetch()) {
             $networkinterface_new = new Networkinterface(false, (int) $_POST['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, false, (int) $networkinterface_id, (int) $_POST[router_id], $sendet_interface['name'], $sendet_interface['mac_addr'], (int) $sendet_interface['mtu'], (int) $sendet_interface['traffic_rx'], (int) $traffic_rx_per_second_byte, (int) $sendet_interface['traffic_tx'], (int) $traffic_tx_per_second_byte, $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();
         //TODO: Remove networkinterfaces that are not linked to any status, service, habe no ip addresses and are not marked as protected
         //Update RRD Graph DB
         $rrd_path_traffic_rx = __DIR__ . "/rrdtool/databases/router_{$_POST['router_id']}_interface_{$sendet_interface['name']}_traffic_rx.rrd";
         if (!file_exists($rrd_path_traffic_rx)) {
             //Create new RRD-Database
             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");
         }