source: trunk/Modules/NetworkConfigAirOS/Generators/Signal.php

Last change on this file was 975, checked in by chronos, 3 days ago
  • Modified: Improved RouterOS signal logging.
File size: 2.0 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/SSHClient.php');
4
5class ConfigAirOSSignal extends NetworkConfigItem
6{
7 function ReadWirelessRegistration(): void
8 {
9 $Time = time();
10 $NetworkMac = new NetworkMac($this->System);
11
12 // Load netwatch status from all DHCP routers
13 $DbResult3 = $this->Database->query('SELECT `Id`, `LoginName`, `LoginPassword`, '.
14 '(SELECT `LocalIP` FROM `NetworkInterface` WHERE `NetworkInterface`.`Device` = `NetworkDevice`.`Id` LIMIT 1) AS `LocalIP`, `Name` '.
15 'FROM `NetworkDevice` WHERE (`API` = 2) AND (`Used` = 1)');
16 while ($Device = $DbResult3->fetch_assoc())
17 {
18 echo($Device['LocalIP'].' ('.$Device['Name']."): ");
19 $SSHClient = new SSHClient($Device['LocalIP'], $Device['LoginName'], $Device['LoginPassword']);
20 //$SSHClient->Debug = true;
21 $Result = $SSHClient->Execute('wstalist');
22 if (count($Result) > 0)
23 {
24 $Array = json_decode(implode("\n", $Result), true);
25 foreach ($Array as $Properties)
26 {
27 $DbResult = $this->Database->select('NetworkInterface', 'Id', '`MAC`="'.$Properties['mac'].'"');
28 if ($DbResult->num_rows > 0)
29 {
30 $DbRow = $DbResult->fetch_assoc();
31 $Interface = $DbRow['Id'];
32 } else $Interface = null;
33
34 $Strength = $Properties['signal'];
35 $RemoteSignal = $Properties['remote']['signal'];
36 $RateRx = $Properties['rx'];
37 $RateTx = $Properties['tx'];
38 $MacRef = $NetworkMac->GetIndex($Properties['mac']);
39 $this->Database->insert('NetworkSignal', array('MAC' => $MacRef,
40 'Value' => $Strength, 'Remote' => $RemoteSignal, 'RateRx' => $RateRx, 'RateTx' => $RateTx,
41 'Time' => TimeToMysqlDateTime($Time), 'Interface' => $Interface, 'Device' => $Device['Id']));
42 echo('.');
43 }
44 echo("\n");
45 } else echo("Empty response\n");
46 }
47 }
48
49 function Run(): void
50 {
51 RepeatFunction(60 * 60, array($this, 'ReadWirelessRegistration'));
52 }
53}
Note: See TracBrowser for help on using the repository browser.