Ignore:
Timestamp:
Jan 8, 2016, 11:00:11 PM (9 years ago)
Author:
chronos
Message:
  • Modified: Network configure actions now can be executed through cmd.php interface using "php cmd.php config <action>".
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/NetworkConfigRouterOS/Generators/Signal.php

    r752 r781  
    11<?php
    22
    3 if(array_key_exists('REMOTE_ADDR', $_SERVER)) die();
    4 include_once(dirname(__FILE__).'/../../../Application/System.php');
    5 $System = new System();
    6 $System->ShowPage = false;
    7 $System->Run();
     3class ConfigRouterOSSignal extends NetworkConfigItem
     4{
     5  function ReadWirelessRegistration()
     6  {
     7    $Time = time();
    88
    9 function ReadWirelessRegistration()
    10 {
    11   global $System, $Config;
     9    // Load netwatch status from all DHCP routers
     10    $DbResult3 = $this->Database->query('SELECT `Id`, '.
     11        '(SELECT `LocalIP` FROM `NetworkInterface` WHERE `NetworkInterface`.`Device` = `NetworkDevice`.`Id` LIMIT 1) AS `LocalIP` '.
     12        'FROM `NetworkDevice` WHERE (`API` = 1) AND (`Used` = 1)');
     13    while($Device = $DbResult3->fetch_assoc())
     14    {
     15      echo($Device['LocalIP']."\n");
     16      $Routerboard = new RouterosAPI();
     17      //$Routerboard->SSL = true;
     18      //$Routerboard->Port = 8729;
     19      $Routerboard->Connect($Device['LocalIP'], $this->System->Config['API']['UserName'], $this->System->Config['API']['Password']);
     20      if(!$Routerboard->Connected) continue;
     21      $Routerboard->Write('/interface/wireless/registration-table/getall', false);
     22      $Routerboard->Write('=.proplist=signal-strength,mac-address,rx-rate,tx-rate', false);
     23      $Routerboard->Write('=stats=');
     24      $Read = $Routerboard->Read(false);
     25      $Array = $Routerboard->ParseResponse($Read);
     26      foreach($Array as $Properties)
     27      {
     28        $DbResult = $this->Database->select('NetworkInterface', 'Id', 'MAC="'.$Properties['mac-address'].'"');
     29        if($DbResult->num_rows > 0)
     30        {
     31          $DbRow = $DbResult->fetch_assoc();
     32          $Interface = $DbRow['Id'];
     33        } else $Interface = null;
    1234
    13   $Time = time();
    14 
    15   // Load netwatch status from all DHCP routers
    16   $DbResult3 = $System->Database->query('SELECT `Id`, '.
    17     '(SELECT `LocalIP` FROM `NetworkInterface` WHERE `NetworkInterface`.`Device` = `NetworkDevice`.`Id` LIMIT 1) AS `LocalIP` '.
    18     'FROM `NetworkDevice` WHERE (`API` = 1) AND (`Used` = 1)');
    19   while($Device = $DbResult3->fetch_assoc())
    20   {
    21     echo($Device['LocalIP']."\n");
    22     $Routerboard = new RouterosAPI();
    23     //$Routerboard->SSL = true;
    24     //$Routerboard->Port = 8729;
    25     $Routerboard->Connect($Device['LocalIP'], $Config['API']['UserName'], $Config['API']['Password']);
    26     if(!$Routerboard->Connected) continue;
    27     $Routerboard->Write('/interface/wireless/registration-table/getall', false);
    28     $Routerboard->Write('=.proplist=signal-strength,mac-address,rx-rate,tx-rate', false);
    29     $Routerboard->Write('=stats=');
    30     $Read = $Routerboard->Read(false);
    31     $Array = $Routerboard->ParseResponse($Read);
    32     foreach($Array as $Properties)
    33     {
    34       $DbResult = $System->Database->select('NetworkInterface', 'Id', 'MAC="'.$Properties['mac-address'].'"');
    35       if($DbResult->num_rows > 0)
    36       {
    37         $DbRow = $DbResult->fetch_assoc();
    38         $Interface = $DbRow['Id'];
    39       } else $Interface = null;
    40 
    41       if(strpos($Properties['signal-strength'], '@') === false)
    42       {
    43         $Strength = $Properties['signal-strength'];
    44       } else {
    45         $Parts = explode('@', $Properties['signal-strength']);
    46         if(substr($Parts[0], -3) == 'dBm')
    47           $Strength = substr($Parts[0], 0, -3); // without dBm
    48           else $Strength = $Parts[0];
     35        if(strpos($Properties['signal-strength'], '@') === false)
     36        {
     37          $Strength = $Properties['signal-strength'];
     38        } else {
     39          $Parts = explode('@', $Properties['signal-strength']);
     40          if(substr($Parts[0], -3) == 'dBm')
     41            $Strength = substr($Parts[0], 0, -3); // without dBm
     42            else $Strength = $Parts[0];
     43        }
     44        $RateRx = substr($Properties['rx-rate'], 0, -3); // without MHz
     45        $RateTx = substr($Properties['tx-rate'], 0, -3); // without MHz
     46        $this->Database->insert('NetworkSignal', array('MAC' => $Properties['mac-address'],
     47            'Value' => $Strength, 'RateRx' => $RateRx, 'RateTx' => $RateTx,
     48            'Time' => TimeToMysqlDateTime($Time), 'Interface' => $Interface, 'Device' => $Device['Id']));
     49        /*
     50         $DbResult = $this->Database->select('Measure', 'Id', '`Name` = "'.$Properties['mac-address'].'"');
     51         if($DbResult->num_rows > 0)
     52         {
     53         $this->Database->insert('Measure', array('Name' => $Properties['mac-address']));
     54         $Id = $this->Database->LastInsertId;
     55         } else {
     56         $DbRow = $DbResult->fetch_assoc();
     57         $Id = $DbRow['Id'];
     58         }
     59         $Measure = new Measure($Id);
     60         $Measure->Load($Id);
     61         $Measure->AddValue($Properties['signal-strength']);
     62         */
    4963      }
    50       $RateRx = substr($Properties['rx-rate'], 0, -3); // without MHz
    51       $RateTx = substr($Properties['tx-rate'], 0, -3); // without MHz
    52       $System->Database->insert('NetworkSignal', array('MAC' => $Properties['mac-address'],
    53         'Value' => $Strength, 'RateRx' => $RateRx, 'RateTx' => $RateTx,
    54         'Time' => TimeToMysqlDateTime($Time), 'Interface' => $Interface, 'Device' => $Device['Id']));
    55       /*
    56       $DbResult = $System->Database->select('Measure', 'Id', '`Name` = "'.$Properties['mac-address'].'"');
    57       if($DbResult->num_rows > 0)
    58       {
    59         $System->Database->insert('Measure', array('Name' => $Properties['mac-address']));
    60         $Id = $System->Database->LastInsertId;
    61       } else {
    62         $DbRow = $DbResult->fetch_assoc();
    63         $Id = $DbRow['Id'];
    64       }
    65       $Measure = new Measure($Id);
    66       $Measure->Load($Id);
    67       $Measure->AddValue($Properties['signal-strength']);
    68       */
    6964    }
    7065  }
     66
     67  function Run()
     68  {
     69    RepeatFunction(60 * 60, array($this, 'ReadWirelessRegistration'));
     70  }
    7171}
    72 
    73 RepeatFunction(60 * 60, 'ReadWirelessRegistration');
Note: See TracChangeset for help on using the changeset viewer.