Changeset 887 for trunk/Modules/NetworkConfigRouterOS
- Timestamp:
- Nov 20, 2020, 12:08:12 AM (4 years ago)
- Location:
- trunk/Modules/NetworkConfigRouterOS
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/NetworkConfigRouterOS/Generators/DHCP.php
r873 r887 4 4 class ConfigRouterOSDHCP extends NetworkConfigItem 5 5 { 6 function Run() 6 function Run(): void 7 7 { 8 8 $Path = array('ip', 'dhcp-server', 'lease'); -
trunk/Modules/NetworkConfigRouterOS/Generators/DNS.php
r873 r887 3 3 class ConfigRouterOSDNS extends NetworkConfigItem 4 4 { 5 function Run() 5 function Run(): void 6 6 { 7 7 $Path = array('ip', 'dns', 'static'); -
trunk/Modules/NetworkConfigRouterOS/Generators/FirewallFilter.php
r873 r887 3 3 class ConfigRouterOSFirewallFilter extends NetworkConfigItem 4 4 { 5 function Run() 5 function Run(): void 6 6 { 7 7 $Path = array('ip', 'firewall', 'filter'); -
trunk/Modules/NetworkConfigRouterOS/Generators/FirewallMangle.php
r873 r887 3 3 class ConfigRouterOSFirewallMangle extends NetworkConfigItem 4 4 { 5 function ProcessNode($Node) 5 function ProcessNode($Node): void 6 6 { 7 7 global $InetInterface, $ItemsFirewall; 8 8 9 foreach ($Node['Items'] as $I ndex => $Item)9 foreach ($Node['Items'] as $Item) 10 10 { 11 11 if (count($Item['Items']) == 0) … … 47 47 } 48 48 49 function Run() 49 function Run(): void 50 50 { 51 51 $this->RunIPv4(); … … 53 53 } 54 54 55 function RunIPv4() 55 function RunIPv4(): void 56 56 { 57 57 global $ItemsFirewall; … … 149 149 } 150 150 151 function RunIPv6() 151 function RunIPv6(): void 152 152 { 153 153 global $ItemsFirewall; -
trunk/Modules/NetworkConfigRouterOS/Generators/FirewallNAT.php
r873 r887 3 3 class ConfigRouterOSFirewallNAT extends NetworkConfigItem 4 4 { 5 function Run() 5 function Run(): void 6 6 { 7 7 $Path = array('ip', 'firewall', 'nat'); -
trunk/Modules/NetworkConfigRouterOS/Generators/Netwatch.php
r873 r887 3 3 class ConfigRouterOSNetwatch extends NetworkConfigItem 4 4 { 5 function Run() 5 function Run(): void 6 6 { 7 7 $Path = array('tool', 'netwatch'); -
trunk/Modules/NetworkConfigRouterOS/Generators/NetwatchImport.php
r873 r887 3 3 class ConfigRouterOSNetwatchImport extends NetworkConfigItem 4 4 { 5 function NetwatchImport() 5 function NetwatchImport(): void 6 6 { 7 7 $StartTime = time(); … … 44 44 $Queries = array(); 45 45 $QueriesInsert = array(); 46 foreach ($Interfaces as $In dex => $Interface)46 foreach ($Interfaces as $Interface) 47 47 { 48 48 // Update last online time if still online … … 103 103 } 104 104 105 function Run() 105 function Run(): void 106 106 { 107 107 RepeatFunction(10, array($this, 'NetwatchImport')); -
trunk/Modules/NetworkConfigRouterOS/Generators/Queue.php
r873 r887 14 14 } 15 15 16 function Print() 16 function Print(): string 17 17 { 18 18 $Output = '(Min: '.$this->Min.' Max: '.$this->Max; … … 46 46 } 47 47 48 function CheckName($Name, &$UsedNames) 48 function CheckName($Name, &$UsedNames): void 49 49 { 50 50 if (in_array($Name, $UsedNames)) die("\n".'Duplicate name: '.$Name); … … 52 52 } 53 53 54 function GetCommands(&$UsedNames = null) 54 function GetCommands(&$UsedNames = null): array 55 55 { 56 56 if ($UsedNames == null) $UsedNames = array(); … … 72 72 } 73 73 74 function GetParentName(string $Suffix) 74 function GetParentName(string $Suffix): string 75 75 { 76 76 if ($this->Parent != null) return $this->Parent->Name.$Suffix; … … 78 78 } 79 79 80 function UpdateMinSpeeds() 80 function UpdateMinSpeeds(): void 81 81 { 82 82 if (($this->LimitIn->Min == 0) or ($this->LimitOut->Min == 0)) … … 100 100 class SpeedLimitItems extends GenericList 101 101 { 102 function AddNew(string $Name, SpeedLimitItem $Parent = null) 102 function AddNew(string $Name, SpeedLimitItem $Parent = null): SpeedLimitItem 103 103 { 104 104 $Item = new SpeedLimitItem($Name, $Parent); 105 $Item->LimitIn = new SpeedLimit( );106 $Item->LimitOut = new SpeedLimit( );105 $Item->LimitIn = new SpeedLimit(0, 0); 106 $Item->LimitOut = new SpeedLimit(0, 0); 107 107 $this->Items[] = $Item; 108 108 return $Item; … … 119 119 } 120 120 121 function GetCommands(&$UsedNames) 121 function GetCommands(&$UsedNames): array 122 122 { 123 123 $Output = array(); … … 137 137 var $SpeedLimits; 138 138 139 function Run() 139 function Run(): void 140 140 { 141 141 $PathQueue = array('queue', 'tree'); … … 149 149 $this->UsedNames = array(); 150 150 151 $Finance = & $this->System->Modules['Finance'];151 $Finance = &ModuleFinance::Cast($this->System->GetModule('Finance'))->Finance; 152 152 $Finance->LoadMonthParameters(0); 153 153 … … 280 280 } 281 281 282 function BuildSpeedLimit(&$SpeedLimit, $TopSpeedLimitItem) 282 function BuildSpeedLimit(&$SpeedLimit, $TopSpeedLimitItem): void 283 283 { 284 284 $SpeedLimitName = $SpeedLimit['Name'].'-grp'; … … 297 297 } 298 298 299 function LoadSpeedLimits($SpeedLimitItem) 299 function LoadSpeedLimits($SpeedLimitItem): void 300 300 { 301 301 echo('Limit groups: '); … … 326 326 } 327 327 328 function UpdateMinSpeed($DeviceId) 328 function UpdateMinSpeed($DeviceId): void 329 329 { 330 330 $MinSpeed = 0; … … 340 340 341 341 // Calculate maximum real speed available for each network device Start with main router and continue with adjecement nodes. 342 function BuildTree($RootDeviceId, $BaseSpeed) 342 function BuildTree($RootDeviceId, $BaseSpeed): void 343 343 { 344 344 // Load network devices … … 438 438 } 439 439 440 function BuildQueueItems($DeviceId, $SpeedLimitParent) 440 function BuildQueueItems($DeviceId, $SpeedLimitParent): void 441 441 { 442 442 $Device = $this->Devices[$DeviceId]; … … 475 475 } 476 476 477 function RunTopology() 477 function RunTopology(): void 478 478 { 479 479 $PathQueue = array('queue', 'tree'); … … 487 487 $this->UsedNames = array(); 488 488 489 $Finance = & $this->System->Modules['Finance'];489 $Finance = &ModuleFinance::Cast($this->System->GetModule('Finance'))->Finance; 490 490 $Finance->LoadMonthParameters(0); 491 491 -
trunk/Modules/NetworkConfigRouterOS/Generators/Signal.php
r874 r887 3 3 class ConfigRouterOSSignal extends NetworkConfigItem 4 4 { 5 function ReadWirelessRegistration() 5 function ReadWirelessRegistration(): void 6 6 { 7 7 $Time = time(); … … 66 66 $this->Database->Transaction($Queries); 67 67 } 68 69 function StripUnits($Value) 68 69 function StripUnits($Value): string 70 70 { 71 71 if (strpos($Value, '-') !== false) $Value = substr($Value, 0, strpos($Value, '-') - 1); // without channel info 72 72 if (substr($Value, -3, 3) == "MHz") $Value = substr($Value, 0, -3); // without MHz unit 73 if (substr($Value, -4, 4) == "Mbps") $Value = substr($Value, 0, -4); // without Mbps unit 74 if (substr($Value, -3, 3) == "Mbp") $Value = substr($Value, 0, -3); // without Mbp unit 73 if (substr($Value, -4, 4) == "Mbps") $Value = substr($Value, 0, -4); // without Mbps unit 74 if (substr($Value, -3, 3) == "Mbp") $Value = substr($Value, 0, -3); // without Mbp unit 75 75 if (substr($Value, -1, 1) == "M") $Value = substr($Value, 0, -1); // without M unit 76 76 return $Value; 77 77 } 78 78 79 function Run() 79 function Run(): void 80 80 { 81 81 RepeatFunction(60 * 60, array($this, 'ReadWirelessRegistration')); -
trunk/Modules/NetworkConfigRouterOS/NetworkConfigRouterOS.php
r874 r887 18 18 class ModuleNetworkConfigRouterOS extends AppModule 19 19 { 20 function __construct( $System)20 function __construct(System $System) 21 21 { 22 22 parent::__construct($System); … … 29 29 } 30 30 31 function DoInstall() 31 function DoInstall(): void 32 32 { 33 33 } 34 34 35 function DoUnInstall() 35 function DoUnInstall(): void 36 36 { 37 37 } 38 38 39 function DoStart() 39 function DoStart(): void 40 40 { 41 41 $this->System->Pages['zdarma'] = 'PageFreeAccess'; 42 $this->System->ModuleManager->Modules['NetworkConfig']->RegisterConfigItem('routeros-dns', 'ConfigRouterOSDNS');43 $this->System->ModuleManager->Modules['NetworkConfig']->RegisterConfigItem('routeros-dhcp', 'ConfigRouterOSDHCP');44 $this->System->ModuleManager->Modules['NetworkConfig']->RegisterConfigItem('routeros-signal', 'ConfigRouterOSSignal');45 $this->System->ModuleManager->Modules['NetworkConfig']->RegisterConfigItem('routeros-netwatch', 'ConfigRouterOSNetwatch');46 $this->System->ModuleManager->Modules['NetworkConfig']->RegisterConfigItem('routeros-netwatch-import', 'ConfigRouterOSNetwatchImport');47 $this->System->ModuleManager->Modules['NetworkConfig']->RegisterConfigItem('routeros-firewall-filter', 'ConfigRouterOSFirewallFilter');48 $this->System->ModuleManager->Modules['NetworkConfig']->RegisterConfigItem('routeros-firewall-nat', 'ConfigRouterOSFirewallNAT');49 $this->System->ModuleManager->Modules['NetworkConfig']->RegisterConfigItem('routeros-firewall-mangle', 'ConfigRouterOSFirewallMangle');50 $this->System->ModuleManager->Modules['NetworkConfig']->RegisterConfigItem('routeros-queue', 'ConfigRouterOSQueue');42 ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-dns', 'ConfigRouterOSDNS'); 43 ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-dhcp', 'ConfigRouterOSDHCP'); 44 ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-signal', 'ConfigRouterOSSignal'); 45 ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-netwatch', 'ConfigRouterOSNetwatch'); 46 ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-netwatch-import', 'ConfigRouterOSNetwatchImport'); 47 ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-firewall-filter', 'ConfigRouterOSFirewallFilter'); 48 ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-firewall-nat', 'ConfigRouterOSFirewallNAT'); 49 ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-firewall-mangle', 'ConfigRouterOSFirewallMangle'); 50 ModuleNetworkConfig::Cast($this->System->GetModule('NetworkConfig'))->RegisterConfigItem('routeros-queue', 'ConfigRouterOSQueue'); 51 51 } 52 52 } … … 54 54 class PageFreeAccess extends Page 55 55 { 56 var $FullTitle = 'Přístup zdarma k Internetu'; 57 var $ShortTitle = 'Internet zdarma'; 58 var $ParentClass = 'PagePortal'; 59 var $AddressList = 'free-access'; 60 var $Timeout; 56 public string $AddressList = 'free-access'; 57 public int $Timeout; 61 58 62 function __construct( $System)59 function __construct(System $System) 63 60 { 64 61 parent::__construct($System); 62 $this->FullTitle = 'Přístup zdarma k Internetu'; 63 $this->ShortTitle = 'Internet zdarma'; 64 $this->ParentClass = 'PagePortal'; 65 65 66 $this->Timeout = 24 * 60 * 60; 66 67 } 67 68 68 function Show() 69 function Show(): string 69 70 { 70 71 $IPAddress = GetRemoteAddress(); 71 72 $Output = 'Vaše IP adresa je: '.$IPAddress.'<br/>'; 72 if (IsInternetAddr($IPAddress)) { 73 if (IsInternetAddr($IPAddress)) 74 { 73 75 $Output .= '<p>Internet zdarma je dostupný pouze z vnitřní sítě.</p>'; 74 76 return $Output; … … 117 119 class ScheduleConfigureFreeAccess extends SchedulerTask 118 120 { 119 function Execute() 121 function Execute(): string 120 122 { 121 123 $Output = ''; -
trunk/Modules/NetworkConfigRouterOS/Routerboard.php
r874 r887 19 19 } 20 20 21 function Execute( $Commands)21 function Execute(array $Commands): array 22 22 { 23 23 $Output = array(); … … 44 44 } 45 45 46 function ExecuteBatch( $Commands)46 function ExecuteBatch(string $Commands): string 47 47 { 48 48 $Commands = trim($Commands); … … 65 65 } 66 66 67 function ItemGet( $Path)67 function ItemGet(array $Path): array 68 68 { 69 69 $Result = $this->Execute(implode(' ', $Path).' print'); … … 82 82 } 83 83 84 function ListGet( $Path, $Properties, $Conditions = array())84 function ListGet(array $Path, array $Properties, array $Conditions = array()): array 85 85 { 86 86 $PropertyList = '"'; … … 116 116 } 117 117 118 function ListGetPrint($Path, $Properties, $Conditions = array()) 118 function ListGetPrint($Path, $Properties, $Conditions = array()): array 119 119 { 120 120 $ConditionList = ''; … … 151 151 } 152 152 153 function ListEraseAll( $Path)153 function ListEraseAll(array $Path): void 154 154 { 155 155 $this->Execute(implode(' ', $Path).' { remove [find] }'); 156 156 } 157 157 158 function ListUpdate( $Path, $Properties, $Values, $Condition = array(), $UsePrint = false)158 function ListUpdate(array $Path, array $Properties, array $Values, array $Condition = array(), bool $UsePrint = false): array 159 159 { 160 160 // Get current list from routerboard -
trunk/Modules/NetworkConfigRouterOS/Routerboard2.php
r874 r887 11 11 ); 12 12 13 function Execute($Commands) 13 function Execute($Commands): array 14 14 { 15 15 if (is_array($Commands)) $Commands = implode(';', $Commands); … … 17 17 } 18 18 19 function GetItem($Command) 19 function GetItem($Command): array 20 20 { 21 21 $Result = $this->Execute($Command); … … 25 25 { 26 26 $ResultLineParts = explode(' ', trim($ResultLine)); 27 if ($ResultLineParts[1] {0}== '"') $ResultLineParts[1] = substr($ResultLineParts[1], 1, -1); // Remove quotes27 if ($ResultLineParts[1][0] == '"') $ResultLineParts[1] = substr($ResultLineParts[1], 1, -1); // Remove quotes 28 28 $List[substr($ResultLineParts[0], 0, -1)] = $ResultLineParts[1]; 29 29 } … … 31 31 } 32 32 33 function GetList($Command, $Properties) 33 function GetList($Command, $Properties): array 34 34 { 35 35 $PropertyList = '"'; … … 55 55 } 56 56 57 function GetSystemResource() 57 function GetSystemResource(): array 58 58 { 59 59 return $this->GetItem('/system resource print'); 60 60 } 61 61 62 function GetFirewallFilterList() 62 function GetFirewallFilterList(): array 63 63 { 64 64 return $this->GetList('/ip firewall nat', array('src-address', 'dst-address', 'bytes')); 65 65 } 66 66 67 function GetDHCPServerLeasesList() 67 function GetDHCPServerLeasesList(): array 68 68 { 69 69 return $this->GetList('/ip dhcp-server lease', array('address', 'active-address', 'comment', 'lease-time', 'status', 'host-name')); -
trunk/Modules/NetworkConfigRouterOS/RouterboardAPI.php
r874 r887 25 25 } 26 26 27 function EncodeLength($Length) 28 { 29 if ($Length < 0x80) { 27 function EncodeLength(int $Length): int 28 { 29 if ($Length < 0x80) 30 { 30 31 $Length = chr($Length); 31 } else if ($Length < 0x4000) { 32 } else if ($Length < 0x4000) 33 { 32 34 $Length |= 0x8000; 33 35 $Length = chr(($Length >> 8) & 0xFF).chr($Length & 0xFF); 34 } else if ($Length < 0x200000) { 36 } else if ($Length < 0x200000) 37 { 35 38 $Length |= 0xC00000; 36 39 $Length = chr(($Length >> 16) & 0xFF).chr(($Length >> 8) & 0xFF).chr($Length & 0xFF); 37 } else if ($Length < 0x10000000) { 40 } else if ($Length < 0x10000000) 41 { 38 42 $Length |= 0xE0000000; 39 43 $Length = chr(($Length >> 24) & 0xFF).chr(($Length >> 16) & 0xFF).chr(($Length >> 8) & 0xFF).chr($Length & 0xFF); … … 43 47 } 44 48 45 function ConnectOnce( $IP, $Login, $Password)49 function ConnectOnce(string $IP, string $Login, string $Password): void 46 50 { 47 51 if ($this->Connected) $this->Disconnect(); … … 63 67 } 64 68 65 function Connect( $IP, $Login, $Password)69 function Connect(string $IP, string $Login, string $Password): bool 66 70 { 67 71 for ($Attempt = 1; $Attempt <= $this->Attempts; $Attempt++) … … 74 78 } 75 79 76 function Disconnect() 80 function Disconnect(): void 77 81 { 78 82 if ($this->Connected) … … 83 87 } 84 88 85 function ParseResponse($Response) 86 { 87 if (is_array($Response)) { 89 function ParseResponse(array $Response): array 90 { 91 if (is_array($Response)) 92 { 88 93 $Parsed = array(); 89 94 $Current = null; 90 95 $SingleValue = null; 91 96 $count = 0; 92 foreach ($Response as $x) { 97 foreach ($Response as $x) 98 { 93 99 if (in_array($x, array( 94 100 '!fatal', 95 101 '!re', 96 102 '!trap' 97 ))) { 98 if ($x == '!re') { 103 ))) 104 { 105 if ($x == '!re') 106 { 99 107 $Current =& $Parsed[]; 100 108 } else 101 109 $Current =& $Parsed[$x][]; 102 } else if ($x != '!done') { 103 if (preg_match_all('/[^=]+/i', $x, $Matches)) { 110 } else if ($x != '!done') 111 { 112 if (preg_match_all('/[^=]+/i', $x, $Matches)) 113 { 104 114 if ($Matches[0][0] == 'ret') { 105 115 $SingleValue = $Matches[0][1]; … … 109 119 } 110 120 } 111 if (empty($Parsed) && !is_null($SingleValue)) { 121 if (empty($Parsed) && !is_null($SingleValue)) 122 { 112 123 $Parsed = $SingleValue; 113 124 } … … 117 128 } 118 129 119 function ArrayChangeKeyName(&$array) 120 { 121 if (is_array($array)) { 122 foreach ($array as $k => $v) { 130 function ArrayChangeKeyName(array &$array): array 131 { 132 if (is_array($array)) 133 { 134 foreach ($array as $k => $v) 135 { 123 136 $tmp = str_replace("-", "_", $k); 124 137 $tmp = str_replace("/", "_", $tmp); 125 if ($tmp) { 138 if ($tmp) 139 { 126 140 $array_new[$tmp] = $v; 127 } else { 141 } else 142 { 128 143 $array_new[$k] = $v; 129 144 } 130 145 } 131 146 return $array_new; 132 } else { 147 } else 148 { 133 149 return $array; 134 150 } 135 151 } 136 152 137 function Read( $Parse = true)153 function Read(bool $Parse = true): array 138 154 { 139 155 $Line = ''; 140 156 $Response = array(); 141 while (true) { 157 while (true) 158 { 142 159 // Read the first byte of input which gives us some or all of the length 143 160 // of the remaining reply. … … 149 166 // If the fourth bit is set, we need to remove anything left in the first byte 150 167 // and then read in yet another byte. 151 if ($Byte & 0x80) { 152 if (($Byte & 0xc0) == 0x80) { 168 if ($Byte & 0x80) 169 { 170 if (($Byte & 0xc0) == 0x80) 171 { 153 172 $Length = (($Byte & 63) << 8) + ord(fread($this->Socket, 1)); 154 } else { 155 if (($Byte & 0xe0) == 0xc0) { 173 } else 174 { 175 if (($Byte & 0xe0) == 0xc0) 176 { 156 177 $Length = (($Byte & 31) << 8) + ord(fread($this->Socket, 1)); 157 178 $Length = ($Length << 8) + ord(fread($this->Socket, 1)); 158 } else { 159 if (($Byte & 0xf0) == 0xe0) { 179 } else 180 { 181 if (($Byte & 0xf0) == 0xe0) 182 { 160 183 $Length = (($Byte & 15) << 8) + ord(fread($this->Socket, 1)); 161 184 $Length = ($Length << 8) + ord(fread($this->Socket, 1)); 162 185 $Length = ($Length << 8) + ord(fread($this->Socket, 1)); 163 } else { 186 } else 187 { 164 188 $Length = ord(fread($this->Socket, 1)); 165 189 $Length = ($Length << 8) + ord(fread($this->Socket, 1)); … … 169 193 } 170 194 } 171 } else { 195 } else 196 { 172 197 $Length = $Byte; 173 198 } 174 199 // If we have got more characters to read, read them in. 175 if ($Length > 0) { 200 if ($Length > 0) 201 { 176 202 $Line = ''; 177 203 $RetLen = 0; 178 while ($RetLen < $Length) { 204 while ($RetLen < $Length) 205 { 179 206 $ToRead = $Length - $RetLen; 180 207 $Line .= fread($this->Socket, $ToRead); … … 196 223 } 197 224 198 function Write( $Command, $Param2 = true)225 function Write(string $Command, bool $Param2 = true): bool 199 226 { 200 227 if ($Command) 201 228 { 202 229 $Data = explode("\n", $Command); 203 foreach ($Data as $Com) { 230 foreach ($Data as $Com) 231 { 204 232 $Com = trim($Com); 205 233 fwrite($this->Socket, $this->EncodeLength(strlen($Com)).$Com); 206 234 } 207 if (gettype($Param2) == 'integer') { 235 if (gettype($Param2) == 'integer') 236 { 208 237 fwrite($this->Socket, $this->EncodeLength(strlen('.tag='.$Param2)).'.tag='.$Param2.chr(0)); 209 238 } else if (gettype($Param2) == 'boolean') … … 214 243 } 215 244 216 function Comm( $Com, $Arr = array())245 function Comm(string $Com, array $Arr = array()): array 217 246 { 218 247 $Count = count($Arr); 219 248 $this->write($Com, !$Arr); 220 249 $i = 0; 221 foreach ($Arr as $k => $v) { 222 switch ($k[0]) { 250 foreach ($Arr as $k => $v) 251 { 252 switch ($k[0]) 253 { 223 254 case "?": 224 255 $el = "$k=$v";
Note:
See TracChangeset
for help on using the changeset viewer.