예제 #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']);
 }
예제 #2
0
 public function __construct($user_id = false, $ipv = false, $offset = false, $limit = false, $sort_by = false, $order = false)
 {
     $result = array();
     if ($offset !== false) {
         $this->setOffset((int) $offset);
     }
     if ($limit !== false) {
         $this->setLimit((int) $limit);
     }
     if ($sort_by !== false) {
         $this->setSortBy($sort_by);
     }
     if ($order !== false) {
         $this->SetOrder($order);
     }
     // initialize $total_count with the total number of objects in the list (over all pages)
     try {
         $stmt = DB::getInstance()->prepare("SELECT COUNT(*) as total_count\n\t\t\t\t\t\t\t\t\t\t\t\t\tFROM networks\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t(user_id = :user_id OR :user_id=0) AND\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t(ipv = :ipv OR :ipv=0)");
         $stmt->bindParam(':user_id', $user_id, PDO::PARAM_INT);
         $stmt->bindParam(':ipv', $ipv, PDO::PARAM_INT);
         $stmt->execute();
         $total_count = $stmt->fetch(PDO::FETCH_ASSOC);
     } catch (PDOException $e) {
         echo $e->getMessage();
         echo $e->getTraceAsString();
     }
     $this->setTotalCount((int) $total_count['total_count']);
     //if limit -1 then get all ressource records
     if ($this->getLimit() == -1) {
         $this->setLimit($this->getTotalCount());
     }
     try {
         $stmt = DB::getInstance()->prepare("SELECT id as network_id\n\t\t\t\t\t\t\t\t\t\t\t\t\tFROM networks\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t(user_id = :user_id OR :user_id=0) AND\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t(ipv = :ipv OR :ipv=0)\n\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcase :sort_by\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\twhen 'create_date' then networks.create_date\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\telse NULL\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tend\n\t\t\t\t\t\t\t\t\t\t\t\t\t" . $this->getOrder() . "\n\t\t\t\t\t\t\t\t\t\t\t\t\tLIMIT :offset, :limit");
         $stmt->bindParam(':user_id', $user_id, PDO::PARAM_INT);
         $stmt->bindParam(':ipv', $ipv, PDO::PARAM_INT);
         $stmt->bindParam(':offset', $this->getOffset(), PDO::PARAM_INT);
         $stmt->bindParam(':limit', $this->getLimit(), PDO::PARAM_INT);
         $stmt->bindParam(':sort_by', $this->getSortBy(), PDO::PARAM_STR);
         $stmt->execute();
         $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
     } catch (PDOException $e) {
         echo $e->getMessage();
         echo $e->getTraceAsString();
     }
     foreach ($result as $network) {
         $network = new Network((int) $network['network_id']);
         $network->fetch();
         $this->networklist[] = $network;
     }
 }
예제 #3
0
            $stmt = DB::getInstance()->prepare("SELECT api_key\n\t\t\t\t\t\t\t\t\t\t\t\tFROM routers, users\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE routers.id=? AND users.id=routers.user_id");
            $stmt->execute(array($router_data['router_id']));
            $row = $stmt->fetch(PDO::FETCH_ASSOC);
        } catch (PDOException $e) {
            echo $e->getMessage();
            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']);
예제 #4
0
파일: api.php 프로젝트: wAmpIre/netmon
 private function network()
 {
     if ($this->get_request_method() == "GET") {
         $this->_request['network_id'] = !isset($this->_request['network_id']) ? false : $this->_request['network_id'];
         $this->_request['user_id'] = !isset($this->_request['user_id']) ? false : $this->_request['user_id'];
         $this->_request['ip'] = !isset($this->_request['ip']) ? false : $this->_request['ip'];
         $this->_request['netmask'] = !isset($this->_request['netmask']) ? false : $this->_request['netmask'];
         $this->_request['ipv'] = !isset($this->_request['ipv']) ? false : $this->_request['ipv'];
         $network = new Network((int) $this->_request['network_id'], (int) $this->_request['user_id'], $this->_request['ip'], $this->_request['netmask'], $this->_request['ipv']);
         if ($network->fetch()) {
             $domxmldata = $network->getDomXMLElement($this->domxml);
             $this->response($this->finishxml($domxmldata), 200);
         } else {
             $this->error_code = 2;
             $this->error_message = "Network not found.";
             $this->response($this->finishxml(), 404);
         }
     } else {
         $this->error_code = 2;
         $this->error_message = "The Network could not be created, your request seems to be malformed.";
         $this->response($this->finishxml(), 400);
     }
 }
예제 #5
0
파일: Ip.class.php 프로젝트: wAmpIre/netmon
 public function setNetworkId($network_id)
 {
     if (is_int($network_id)) {
         $network = new Network($network_id);
         if ($network->fetch()) {
             $this->network_id = $network_id;
             $this->network = $network;
             return true;
         }
     }
     return false;
 }
예제 #6
0
파일: iplist.php 프로젝트: wAmpIre/netmon
<?php

require_once 'runtime.php';
require_once ROOT_DIR . '/lib/core/Network.class.php';
require_once ROOT_DIR . '/lib/core/Iplist.class.php';
$network = new Network((int) $_GET['network_id']);
$network->fetch();
$smarty->assign('network', $network);
$iplist = new Iplist(false, (int) $_GET['network_id']);
$smarty->assign('iplist', $iplist->getIplist());
$smarty->display("header.tpl.html");
$smarty->display("iplist.tpl.html");
$smarty->display("footer.tpl.html");