Changeset 917
- Timestamp:
- Feb 23, 2022, 10:24:50 AM (3 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Application/Version.php
r915 r917 1 1 <?php 2 2 3 $Revision = 91 5; // Subversion revision3 $Revision = 917; // Subversion revision 4 4 $DatabaseRevision = 911; // SQL structure revision 5 $ReleaseTime = strtotime('202 1-12-07');5 $ReleaseTime = strtotime('2022-02-23'); -
trunk/Modules/Network/Network.php
r914 r917 384 384 'Value' => array('Type' => 'Integer', 'Caption' => 'Signál', 'Default' => '0', 'Suffix' => 'dBm'), 385 385 'Remote' => array('Type' => 'Integer', 'Caption' => 'Vzdálený signál', 'Default' => '0', 'Suffix' => 'dBm'), 386 'RateRx' => array('Type' => 'Integer', 'Caption' => 'Rychlost Rx', 'Default' => '0', 'Suffix' => 'M Hz'),387 'RateTx' => array('Type' => 'Integer', 'Caption' => 'Rychlost Tx', 'Default' => '0', 'Suffix' => 'M Hz'),386 'RateRx' => array('Type' => 'Integer', 'Caption' => 'Rychlost Rx', 'Default' => '0', 'Suffix' => 'Mbps'), 387 'RateTx' => array('Type' => 'Integer', 'Caption' => 'Rychlost Tx', 'Default' => '0', 'Suffix' => 'Mbps'), 388 388 'Device' => array('Type' => 'TNetworkDevice', 'Caption' => 'Měřeno z', 'Default' => '0'), 389 389 ), -
trunk/Modules/NetworkConfigRouterOS/Generators/Signal.php
r911 r917 3 3 class ConfigRouterOSSignal extends NetworkConfigItem 4 4 { 5 private int $Time; 6 5 7 function ReadWirelessRegistration(): void 6 8 { 7 $ Time = time();9 $this->Time = time(); 8 10 $Queries = array(); 9 10 // Load netwatch status from all DHCP routers 11 11 12 $DbResult3 = $this->Database->query('SELECT `Id`, '. 12 '(SELECT `LocalIP` FROM `NetworkInterface` WHERE `NetworkInterface`.`Device` = `NetworkDevice`.`Id` LIMIT 1) AS `LocalIP` '. 13 'FROM `NetworkDevice` WHERE (`API` = 1) AND (`Used` = 1)'); 13 '(SELECT `LocalIP` FROM `NetworkInterface` WHERE `NetworkInterface`.`Device` = `NetworkDevice`.`Id` LIMIT 1) AS `LocalIP`, '. 14 '`Name` '. 15 'FROM `NetworkDevice` WHERE (`API` = 1) AND (`Used` = 1)'); 14 16 while ($Device = $DbResult3->fetch_assoc()) 15 17 { 16 echo($Device['LocalIP']. "\n");18 echo($Device['LocalIP'].' ('.$Device['Name'].")\n"); 17 19 $Routerboard = new RouterosAPI(); 18 20 //$Routerboard->SSL = true; … … 20 22 $Routerboard->Connect($Device['LocalIP'], $this->System->Config['API']['UserName'], $this->System->Config['API']['Password']); 21 23 if (!$Routerboard->Connected) continue; 22 $Routerboard->Write('/interface/wireless/registration-table/getall', false);23 $Routerboard->Write('=.proplist=signal-strength,tx-signal-strength,mac-address,rx-rate,tx-rate', false);24 $Routerboard->Write('=stats=');25 $Read = $Routerboard->Read(false);26 $Array = $Routerboard->ParseResponse($Read);27 foreach ($Array as $Properties)28 {29 $DbResult = $this->Database->select('NetworkInterface', 'Id', 'MAC="'.$Properties['mac-address'].'"');30 if ($DbResult->num_rows > 0)31 {32 $DbRow = $DbResult->fetch_assoc();33 $Interface = $DbRow['Id'];34 } else $Interface = 'NULL';35 24 36 if (strpos($Properties['signal-strength'], '@') === false) 37 { 38 $Strength = $Properties['signal-strength']; 39 } else 40 { 41 $Parts = explode('@', $Properties['signal-strength']); 42 if (substr($Parts[0], -3) == 'dBm') 43 $Strength = substr($Parts[0], 0, -3); // without dBm 44 else $Strength = $Parts[0]; 45 } 46 47 if (array_key_exists('tx-signal-strength', $Properties)) 48 { 49 if (strpos($Properties['tx-signal-strength'], '@') === false) 50 { 51 $RemoteSignal = $Properties['tx-signal-strength']; 52 } else 53 { 54 $Parts = explode('@', $Properties['tx-signal-strength']); 55 if (substr($Parts[0], -3) == 'dBm') 56 $RemoteSignal = substr($Parts[0], 0, -3); // without dBm 57 else $RemoteSignal = $Parts[0]; 58 } 59 } else $RemoteSignal = 0; 60 61 $RateRx = $this->StripUnits($Properties['rx-rate']); 62 $RateTx = $this->StripUnits($Properties['tx-rate']); 63 $Queries[] = 'INSERT INTO `NetworkSignal` (`MAC`, `Value`, `Remote`, `RateRx`, `RateTx`, `Time`, `Interface`, `Device`) VALUES '. 64 '("'.$Properties['mac-address'].'", '.$Strength.', '.$RemoteSignal.', '.$RateRx.', '.$RateTx.', "'. 65 TimeToMysqlDateTime($Time).'", '.$Interface.', '.$Device['Id'].')'; 66 /* 67 $DbResult = $this->Database->select('Measure', 'Id', '`Name` = "'.$Properties['mac-address'].'"'); 68 if ($DbResult->num_rows > 0) 69 { 70 $this->Database->insert('Measure', array('Name' => $Properties['mac-address'])); 71 $Id = $this->Database->LastInsertId; 72 } else { 73 $DbRow = $DbResult->fetch_assoc(); 74 $Id = $DbRow['Id']; 75 } 76 $Measure = new Measure($Id); 77 $Measure->Load($Id); 78 $Measure->AddValue($Properties['signal-strength']); 79 */ 80 } 25 $Queries = array_merge($Queries, $this->ReadWireless($Device, $Routerboard)); 26 $Queries = array_merge($Queries, $this->ReadWireless60G($Device, $Routerboard)); 81 27 } 82 28 $this->Database->Transaction($Queries); 83 29 } 84 30 85 function StripUnits($Value): string 31 // Read normal wireless clients signal 32 function ReadWireless(array $Device, RouterosAPI $Routerboard): array 33 { 34 $Queries = array(); 35 36 $Routerboard->Write('/interface/wireless/registration-table/getall', false); 37 $Routerboard->Write('=.proplist=signal-strength,tx-signal-strength,mac-address,rx-rate,tx-rate', false); 38 $Routerboard->Write('=stats='); 39 $Read = $Routerboard->Read(false); 40 $Array = $Routerboard->ParseResponse($Read); 41 foreach ($Array as $Properties) 42 { 43 $DbResult = $this->Database->select('NetworkInterface', 'Id', 'MAC="'.$Properties['mac-address'].'"'); 44 if ($DbResult->num_rows > 0) 45 { 46 $DbRow = $DbResult->fetch_assoc(); 47 $Interface = $DbRow['Id']; 48 } else $Interface = 'NULL'; 49 50 if (strpos($Properties['signal-strength'], '@') === false) 51 { 52 $Strength = $Properties['signal-strength']; 53 } else 54 { 55 $Parts = explode('@', $Properties['signal-strength']); 56 if (substr($Parts[0], -3) == 'dBm') 57 $Strength = substr($Parts[0], 0, -3); // without dBm 58 else $Strength = $Parts[0]; 59 } 60 61 if (array_key_exists('tx-signal-strength', $Properties)) 62 { 63 if (strpos($Properties['tx-signal-strength'], '@') === false) 64 { 65 $RemoteSignal = $Properties['tx-signal-strength']; 66 } else 67 { 68 $Parts = explode('@', $Properties['tx-signal-strength']); 69 if (substr($Parts[0], -3) == 'dBm') 70 $RemoteSignal = substr($Parts[0], 0, -3); // without dBm 71 else $RemoteSignal = $Parts[0]; 72 } 73 } else $RemoteSignal = 0; 74 75 $RateRx = $this->StripUnits($Properties['rx-rate']); 76 $RateTx = $this->StripUnits($Properties['tx-rate']); 77 $Queries[] = 'INSERT INTO `NetworkSignal` (`MAC`, `Value`, `Remote`, `RateRx`, `RateTx`, `Time`, `Interface`, `Device`) VALUES '. 78 '("'.$Properties['mac-address'].'", '.$Strength.', '.$RemoteSignal.', '.$RateRx.', '.$RateTx.', "'. 79 TimeToMysqlDateTime($this->Time).'", '.$Interface.', '.$Device['Id'].')'; 80 } 81 return $Queries; 82 } 83 84 // Read 60 GHz wireless clients signal 85 function ReadWireless60G(array $Device, RouterosAPI $Routerboard): array 86 { 87 $Queries = array(); 88 89 $Routerboard->Write('/interface/w60g/monitor', false); 90 $Routerboard->Write('=.proplist=tx-phy-rate,rssi,remote-address', false); 91 $Routerboard->Write('=numbers=wlan60-1', false); 92 $Routerboard->Write('=once='); 93 $Read = $Routerboard->Read(false); 94 $Array = $Routerboard->ParseResponse($Read); 95 if (array_key_exists('!trap', $Array)) 96 { 97 //print_r($Array['!trap']); 98 return array(); 99 } 100 foreach ($Array as $Properties) 101 { 102 $DbResult = $this->Database->select('NetworkInterface', 'Id', 'MAC="'.$Properties['remote-address'].'"'); 103 if ($DbResult->num_rows > 0) 104 { 105 $DbRow = $DbResult->fetch_assoc(); 106 $Interface = $DbRow['Id']; 107 } else $Interface = 'NULL'; 108 109 if (strpos($Properties['rssi'], '@') === false) 110 { 111 $Strength = $Properties['rssi']; 112 } else 113 { 114 $Parts = explode('@', $Properties['rssi']); 115 if (substr($Parts[0], -3) == 'dBm') 116 $Strength = substr($Parts[0], 0, -3); // without dBm 117 else $Strength = $Parts[0]; 118 } 119 120 $RateTx = $this->StripUnits($Properties['tx-phy-rate']); 121 $Queries[] = 'INSERT INTO `NetworkSignal` (`MAC`, `Value`, `Remote`, `RateRx`, `RateTx`, `Time`, `Interface`, `Device`) VALUES '. 122 '("'.$Properties['remote-address'].'", '.$Strength.', 0, 0, '.round($RateTx / 1000000).', "'. 123 TimeToMysqlDateTime($this->Time).'", '.$Interface.', '.$Device['Id'].')'; 124 } 125 return $Queries; 126 } 127 128 function StripUnits(string $Value): string 86 129 { 87 130 if (strpos($Value, '-') !== false) $Value = substr($Value, 0, strpos($Value, '-') - 1); // without channel info 88 131 if (substr($Value, -3, 3) == "MHz") $Value = substr($Value, 0, -3); // without MHz unit 89 if (substr($Value, -4, 4) == "Mbps") $Value = substr($Value, 0, -4); // without Mbps unit 90 if (substr($Value, -3, 3) == "Mbp") $Value = substr($Value, 0, -3); // without Mbp unit 91 if (substr($Value, -1, 1) == "M") $Value = substr($Value, 0, -1); // without M unit 132 else if (substr($Value, -4, 4) == "Mbps") $Value = substr($Value, 0, -4); // without Mbps unit 133 else if (substr($Value, -3, 3) == "Mbp") $Value = substr($Value, 0, -3); // without Mbp unit 134 else if (substr($Value, -1, 1) == "M") $Value = substr($Value, 0, -1); // without M unit 135 else if (substr($Value, -4, 4) == "Gbps") $Value = substr($Value, 0, -4) * 1000; // without Gbps unit 136 else if (substr($Value, -3, 3) == "Gbp") $Value = substr($Value, 0, -3) * 1000; // without Gbp unit 137 else if (substr($Value, -1, 1) == "G") $Value = substr($Value, 0, -1) * 1000; // without G unit 92 138 return $Value; 93 139 }
Note:
See TracChangeset
for help on using the changeset viewer.