Changeset 873 for trunk/Modules/NetworkConfigRouterOS
- Timestamp:
- Apr 6, 2020, 11:17:40 PM (5 years ago)
- Location:
- trunk/Modules/NetworkConfigRouterOS
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/NetworkConfigRouterOS/Generators/AddressPortability.php
r738 r873 1 1 <?php 2 2 3 if (isset($_SERVER['REMOTE_ADDR'])) die();3 if (isset($_SERVER['REMOTE_ADDR'])) die(); 4 4 include_once(dirname(__FILE__).'/../../../Common/Global.php'); 5 5 include_once(dirname(__FILE__).'/../Routerboard.php'); … … 11 11 { 12 12 $TimeParts = explode(':', $Time); 13 return ($TimeParts[0] * 3600 + $TimeParts[1] * 60 + $TimeParts[2]);13 return ($TimeParts[0] * 3600 + $TimeParts[1] * 60 + $TimeParts[2]); 14 14 } 15 15 … … 19 19 20 20 $DbResult3 = $System->Database->query('SELECT * FROM `NetworkSubnet` WHERE `Member` = 0 GROUP BY `DHCP`'); 21 while ($Subnet = $DbResult3->fetch_assoc())21 while ($Subnet = $DbResult3->fetch_assoc()) 22 22 { 23 23 echo($Subnet['AddressRange'].'/'.$Subnet['Mask'].' on router '.$Subnet['DHCP']."\n"); 24 24 $Routerboard->HostName = $Subnet['DHCP']; 25 25 $List = $Routerboard->ListGet($Path, array('address', 'active-mac-address', 'active-address', 'expires-after', 'server', 'dynamic')); 26 foreach ($List as $Properties)26 foreach ($List as $Properties) 27 27 { 28 if ($Properties['dynamic'] == 'true')28 if ($Properties['dynamic'] == 'true') 29 29 //and ($Properties['address'] != $Properties['active-address'])) 30 30 { … … 32 32 echo('MAC: '.$Properties['active-mac-address']."\n"); 33 33 $DbRows2 = $System->Database->query('SELECT `Id` FROM `NetworkInterface` WHERE `MAC`="'.$Properties['active-mac-address'].'"'); 34 if ($DbRows2->num_rows > 0)34 if ($DbRows2->num_rows > 0) 35 35 { 36 36 $Interface = $DbRows2->fetch_assoc(); 37 37 $InterfaceId = $Interface['Id']; 38 38 $DbRows2 = $System->Database->query('SELECT `Id` FROM `NetworkInterfacePortable` WHERE `NetworkInterface`='.$InterfaceId); 39 if ($DbRows2->num_rows > 0)39 if ($DbRows2->num_rows > 0) 40 40 { 41 41 $System->Database->update('NetworkInterfacePortable', '`Time` < "'.TimeToMysqlDateTime($Properties['expires-after']).'" AND `NetworkInterface`='.$InterfaceId, array('DynamicIP' => $Properties['active-address'], 'Update' => 1)); … … 53 53 $NATRule = array(); 54 54 $DbRows = $System->Database->query('SELECT NetworkDevice.Name AS DeviceName, NetworkInterface.Name AS InterfaceName, DynamicIP FROM `NetworkInterfacePortable` JOIN NetworkInterface ON NetworkInterface.Id=NetworkInterfacePortable.NetworkInterface JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE `Update`=1'); 55 while ($Portable = $DbRows->fetch_assoc())55 while ($Portable = $DbRows->fetch_assoc()) 56 56 { 57 57 $Name = $Portable['DeviceName']; 58 if ($Portable['InterfaceName'] != '') $Name .= '-'.$Portable['InterfaceName'];58 if ($Portable['InterfaceName'] != '') $Name .= '-'.$Portable['InterfaceName']; 59 59 array_push($NATRule, implode(' ', $PathNAT).' set [find comment="'.$Name.'-in"] to-addresses='.$Portable['DynamicIP']); 60 60 array_push($NATRule, implode(' ', $PathNAT).' set [find comment="'.$Name.'-out"] src-address='.$Portable['DynamicIP']); -
trunk/Modules/NetworkConfigRouterOS/Generators/Common.php
r870 r873 6 6 7 7 $DbResult = $Database->query('SELECT `Id` FROM `NetworkMark` WHERE `Comment`="'.$Comment.'"'); 8 if ($DbResult->num_rows > 0)8 if ($DbResult->num_rows > 0) 9 9 { 10 10 $DbRow = $DbResult->fetch_assoc(); 11 return ($DbRow['Id']);11 return ($DbRow['Id']); 12 12 } else 13 13 { 14 14 $DbResult = $Database->query('INSERT INTO `NetworkMark` (`Comment`) VALUES ("'.$Comment.'")'); 15 return ($Database->insert_id);15 return ($Database->insert_id); 16 16 } 17 17 } … … 22 22 23 23 $DbResult = $Database->query('SELECT `Id` FROM `NetworkMangleSubgroup` WHERE `AddressRange`="'.$AddressRange.'"'); 24 if ($DbResult->num_rows > 0)24 if ($DbResult->num_rows > 0) 25 25 { 26 26 $DbRow = $DbResult->fetch_assoc(); 27 return ($DbRow['Id']);27 return ($DbRow['Id']); 28 28 } else 29 29 { 30 30 $DbResult = $Database->query('INSERT INTO `NetworkMangleSubgroup` (`AddressRange`) VALUES ("'.$AddressRange.'")'); 31 return ($Database->insert_id);31 return ($Database->insert_id); 32 32 } 33 33 } … … 38 38 39 39 $Found = false; 40 foreach ($Tree['Items'] as $Index => $Node)40 foreach ($Tree['Items'] as $Index => $Node) 41 41 { 42 if ($Node['Address']->Contain($Address))42 if ($Node['Address']->Contain($Address)) 43 43 { 44 44 InsertToAddressTreeIPv4($Tree['Items'][$Index], $Address, $Name, true); … … 46 46 } 47 47 } 48 if ($Found == false)48 if ($Found == false) 49 49 { 50 if ($InterSubnets and ($Tree['Address']->Prefix < $Config['MainRouter']['MangleRuleSubgroupMinPrefix']) and50 if ($InterSubnets and ($Tree['Address']->Prefix < $Config['MainRouter']['MangleRuleSubgroupMinPrefix']) and 51 51 ($Address->Prefix > ($Tree['Address']->Prefix + 1))) 52 52 { … … 62 62 // Should be existed items placed under new node? 63 63 $Found = false; 64 foreach ($Tree['Items'] as $Index => $Node)64 foreach ($Tree['Items'] as $Index => $Node) 65 65 { 66 if (($Node['Address']->Address == $NewNode['Address']->Address) and66 if (($Node['Address']->Address == $NewNode['Address']->Address) and 67 67 ($Node['Address']->Prefix == $NewNode['Address']->Prefix)) $Found = true; 68 68 69 if ($Address->Contain($Node['Address']))69 if ($Address->Contain($Node['Address'])) 70 70 { 71 71 $NewNode['Items'][] = $Node; … … 73 73 } 74 74 } 75 if ($Found == false) $Tree['Items'][] = $NewNode;75 if ($Found == false) $Tree['Items'][] = $NewNode; 76 76 } 77 77 } … … 83 83 84 84 $Found = false; 85 foreach ($Tree['Items'] as $Index => $Node)85 foreach ($Tree['Items'] as $Index => $Node) 86 86 { 87 if ($Node['Address']->Contain($Address))87 if ($Node['Address']->Contain($Address)) 88 88 { 89 89 InsertToAddressTreeIPv6($Tree['Items'][$Index], $Address, $Name, true); … … 91 91 } 92 92 } 93 if ($Found == false)93 if ($Found == false) 94 94 { 95 if ($InterSubnets and ($Tree['Address']->Prefix < $Config['MainRouter']['MangleRuleSubgroupMinPrefix']) and95 if ($InterSubnets and ($Tree['Address']->Prefix < $Config['MainRouter']['MangleRuleSubgroupMinPrefix']) and 96 96 ($Address->Prefix > ($Tree['Address']->Prefix + 1))) 97 97 { … … 107 107 // Should be existed items placed under new node? 108 108 $Found = false; 109 foreach ($Tree['Items'] as $Index => $Node)109 foreach ($Tree['Items'] as $Index => $Node) 110 110 { 111 if (($Node['Address']->Address == $NewNode['Address']->Address) and111 if (($Node['Address']->Address == $NewNode['Address']->Address) and 112 112 ($Node['Address']->Prefix == $NewNode['Address']->Prefix)) $Found = true; 113 113 114 if ($Address->Contain($Node['Address']))114 if ($Address->Contain($Node['Address'])) 115 115 { 116 116 $NewNode['Items'][] = $Node; … … 118 118 } 119 119 } 120 if ($Found == false) $Tree['Items'][] = $NewNode;120 if ($Found == false) $Tree['Items'][] = $NewNode; 121 121 } 122 122 } … … 126 126 { 127 127 echo(str_repeat(' ', $Indent).$Node['Address']->AddressToString().'/'.$Node['Address']->Prefix.' '.$Node['Name']."\n"); 128 foreach ($Node['Items'] as $Index => $Item)128 foreach ($Node['Items'] as $Index => $Item) 129 129 { 130 130 ShowSubnetNode($Item, $Indent + 1); -
trunk/Modules/NetworkConfigRouterOS/Generators/DHCP.php
r861 r873 14 14 15 15 $DbResult = $this->Database->query('SELECT * FROM `NetworkSubnet` WHERE `Configure`=1'); 16 while ($Subnet = $DbResult->fetch_assoc())16 while ($Subnet = $DbResult->fetch_assoc()) 17 17 { 18 18 echo($Subnet['DHCP']); … … 24 24 'WHERE CompareNetworkPrefix(INET_ATON(`LocalIP`), INET_ATON("'.$Subnet['AddressRange'].'"), '.$Subnet['Mask'].') '. 25 25 'AND (`MAC` != "00:00:00:00:00:00") ORDER BY `LocalIP`'); 26 while ($Interface = $DbResult2->fetch_assoc())26 while ($Interface = $DbResult2->fetch_assoc()) 27 27 { 28 28 $Name = $Interface['DeviceName']; 29 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];29 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name']; 30 30 $Items[] = array('mac-address' => $Interface['MAC'], 'address' => $Interface['LocalIP'], 'server' => $Server, 'comment' => $Name, 'lease-time' => '1d'); 31 31 } -
trunk/Modules/NetworkConfigRouterOS/Generators/DNS.php
r781 r873 13 13 14 14 $DbResult = $this->Database->query('SELECT * FROM `NetworkDomain`'); 15 while ($Domain = $DbResult->fetch_assoc())15 while ($Domain = $DbResult->fetch_assoc()) 16 16 { 17 17 $DomainName = $Domain['Name']; … … 19 19 // Get full domain name from parent items 20 20 $CurrentDomain = $Domain; 21 while ($CurrentDomain['Parent'] > 0)21 while ($CurrentDomain['Parent'] > 0) 22 22 { 23 23 $DbResult2 = $this->Database->query('SELECT * FROM `NetworkDomain` WHERE `Id`='.$CurrentDomain['Parent']); … … 32 32 'JOIN `NetworkDevice` ON `NetworkInterface`.`Device`=`NetworkDevice`.`Id` '. 33 33 'WHERE (`NetworkDevice`.`Used`=1)'); 34 while ($Interface = $DbResult2->fetch_assoc())34 while ($Interface = $DbResult2->fetch_assoc()) 35 35 { 36 36 $Name = $Interface['DeviceName']; 37 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];37 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name']; 38 38 $NameFull = $Name.'.'.$DomainName; 39 39 $NameExtFull = $Name.'-ext.'.$DomainName; 40 if ($Interface['LocalIP'] != '')40 if ($Interface['LocalIP'] != '') 41 41 $Items[] = array('name' => $NameFull, 'address' => $Interface['LocalIP']); 42 if ($Interface['IPv6'] != '')42 if ($Interface['IPv6'] != '') 43 43 $Items[] = array('name' => $NameFull, 'address' => $Interface['IPv6']); 44 if ($Interface['ExternalIP'] != '')44 if ($Interface['ExternalIP'] != '') 45 45 $Items[] = array('name' => $NameExtFull, 'address' => $Interface['ExternalIP']); 46 46 } … … 53 53 'WHERE (`NetworkDevice`.`Used`=1) AND '. 54 54 '(CONCAT_WS("-", `NetworkDevice`.`Name`, NULLIF(`NetworkInterface`.`Name`, "")) = `NetworkDomainAlias`.`Target`)'); 55 while ($Alias = $DbResult2->fetch_assoc())55 while ($Alias = $DbResult2->fetch_assoc()) 56 56 { 57 57 $Name = $Alias['Name']; 58 58 $NameFull = $Name.'.'.$DomainName; 59 59 $NameExtFull = $Name.'-ext.'.$DomainName; 60 if ($Alias['LocalIP'] != '')60 if ($Alias['LocalIP'] != '') 61 61 $Items[] = array('name' => $NameFull, 'address' => $Alias['LocalIP']); 62 if ($Alias['IPv6'] != '')62 if ($Alias['IPv6'] != '') 63 63 $Items[] = array('name' => $NameFull, 'address' => $Alias['IPv6']); 64 if ($Alias['ExternalIP'] != '')64 if ($Alias['ExternalIP'] != '') 65 65 $Items[] = array('name' => $NameExtFull, 'address' => $Alias['ExternalIP']); 66 66 } 67 67 68 68 $DbResult2 = $this->Database->query('SELECT * FROM `NetworkDomainServer` WHERE `Domain`='.$Domain['Id']); 69 while ($Server = $DbResult2->fetch_assoc())69 while ($Server = $DbResult2->fetch_assoc()) 70 70 { 71 71 $Routerboard->HostName = $Server['Address']; -
trunk/Modules/NetworkConfigRouterOS/Generators/FirewallFilter.php
r831 r873 42 42 // Insert blocked addresses 43 43 $DbResult = $this->Database->query('SELECT Member.*, Subject.Name FROM Member JOIN Subject ON Member.Subject = Subject.Id WHERE Member.Blocked=1'); 44 while ($Member = $DbResult->fetch_assoc())44 while ($Member = $DbResult->fetch_assoc()) 45 45 { 46 46 echo($Member['Name'].': '); 47 47 // Hosts 48 48 $DbResult2 = $this->Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface LEFT JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE (NetworkInterface.ExternalIP <> "") AND (NetworkDevice.Member = '.$Member['Id'].') AND (NetworkInterface.LocalIP != NetworkInterface.ExternalIP) ORDER BY id DESC'); 49 while ($Interface = $DbResult2->fetch_assoc())49 while ($Interface = $DbResult2->fetch_assoc()) 50 50 { 51 51 $Name = $Interface['DeviceName']; 52 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];52 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name']; 53 53 $Name = RouterOSIdent($Name); 54 54 echo($Name.'('.$Interface['LocalIP'].'), '); … … 59 59 // Subnets 60 60 $DbResult2 = $this->Database->select('NetworkSubnet', '*', 'Member='.$Member['Id']); 61 while ($Subnet = $DbResult2->fetch_assoc())61 while ($Subnet = $DbResult2->fetch_assoc()) 62 62 { 63 63 $Subnet['Name'] = RouterOSIdent('subnet-'.$Subnet['Name']); … … 67 67 $NewAddress->Prefix = $Subnet['ExtMask']; 68 68 $Range = $NewAddress->GetRange(); 69 if ($Subnet['ExtMask'] != 32) $Range = $Range['From']->AddressToString().'-'.$Range['To']->AddressToString();69 if ($Subnet['ExtMask'] != 32) $Range = $Range['From']->AddressToString().'-'.$Range['To']->AddressToString(); 70 70 else $Range = $Range['From']->AddressToString(); 71 if ($Subnet['Mask'] == 32) $Src = $Subnet['AddressRange'];71 if ($Subnet['Mask'] == 32) $Src = $Subnet['AddressRange']; 72 72 else $Src = $Subnet['AddressRange'].'/'.$Subnet['Mask']; 73 73 $Items[] = array('chain' => 'forward', 'out-interface' => $InetInterface, 'src-address' => $Src, 'action' => 'drop','comment' => $Subnet['Name'].'-out-drop'); … … 77 77 $NewAddress->Prefix = $Subnet['Mask']; 78 78 $Range = $NewAddress->GetRange(); 79 if ($Subnet['Mask'] != 32) $Range = $Range['From']->AddressToString().'-'.$Range['To']->AddressToString();79 if ($Subnet['Mask'] != 32) $Range = $Range['From']->AddressToString().'-'.$Range['To']->AddressToString(); 80 80 else $Range = $Range['From']->AddressToString(); 81 if ($Subnet['ExtMask'] == 32) $Dest = $Subnet['ExtAddressRange'];81 if ($Subnet['ExtMask'] == 32) $Dest = $Subnet['ExtAddressRange']; 82 82 else $Dest = $Subnet['ExtAddressRange'].'/'.$Subnet['ExtMask']; 83 83 $Items[] = array('chain' => 'forward', 'in-interface' => $InetInterface, 'dst-address' => $Dest, 'action' => 'drop', 'comment' => $Subnet['Name'].'-in-drop'); -
trunk/Modules/NetworkConfigRouterOS/Generators/FirewallMangle.php
r870 r873 7 7 global $InetInterface, $ItemsFirewall; 8 8 9 foreach ($Node['Items'] as $Index => $Item)10 { 11 if (count($Item['Items']) == 0)9 foreach ($Node['Items'] as $Index => $Item) 10 { 11 if (count($Item['Items']) == 0) 12 12 { 13 13 // Hosts 14 14 $ParentSubnetId = GetSubgroupByRange($Node['Address']->AddressToString().'/'.$Node['Address']->Prefix); 15 15 $Address = $Item['Address']->AddressToString(); 16 if ($Item['Address']->Prefix != 32) $Address .= '/'.$Item['Address']->Prefix;16 if ($Item['Address']->Prefix != 32) $Address .= '/'.$Item['Address']->Prefix; 17 17 18 18 $PacketMark = GetMarkByComment($Item['Name'].'-out'); … … 28 28 29 29 $Address = $Item['Address']->AddressToString(); 30 if ($Item['Address']->Prefix != 32) $Address .= '/'.$Item['Address']->Prefix;30 if ($Item['Address']->Prefix != 32) $Address .= '/'.$Item['Address']->Prefix; 31 31 32 32 $ItemsFirewall[] = array('chain' => 'inet-'.$ParentSubnetId.'-out', 'src-address' => $Address, 'out-interface' => $InetInterface, 'action' => 'jump', 'jump-target' => 'inet-'.$SubnetId.'-out', 'comment' => $Item['Name'].'-out'); … … 36 36 } 37 37 } 38 if ($Node['ForceMark'] == true)38 if ($Node['ForceMark'] == true) 39 39 { 40 40 // Mark member subnets … … 72 72 // Divide rules by subnet number 73 73 $DbResult = $this->System->Database->query('SELECT `Id`, `Name`, `AddressRange`, `Mask` FROM `NetworkSubnet` WHERE `Member` IS NULL'); 74 while ($Subnet = $DbResult->fetch_assoc())74 while ($Subnet = $DbResult->fetch_assoc()) 75 75 { 76 76 $NewAddress = new NetworkAddressIPv4(); … … 84 84 'LEFT JOIN `Subject` ON `Subject`.`Id` = `Member`.`Subject` '. 85 85 'WHERE `Member`.`Blocked` = 0'); 86 while ($Member = $DbResult->fetch_assoc())86 while ($Member = $DbResult->fetch_assoc()) 87 87 { 88 88 $Member['Name'] = RouterOSIdent($Member['Name'].'-'.$Member['Id'] ); … … 90 90 91 91 $DbResult2 = $this->System->Database->select('NetworkDevice', '*', '`Used` = 1 AND `Member` = '.$Member['Id']); 92 while ($Device = $DbResult2->fetch_assoc())92 while ($Device = $DbResult2->fetch_assoc()) 93 93 { 94 94 $DbResult3 = $this->Database->select('NetworkInterface', '*', '`Device` = '.$Device['Id'].' AND `LocalIP` != ""'); 95 while ($Interface = $DbResult3->fetch_assoc())95 while ($Interface = $DbResult3->fetch_assoc()) 96 96 { 97 97 $Name = $Device['Name']; 98 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];98 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name']; 99 99 $Name = RouterOSIdent($Name); 100 100 echo($Name.', '); … … 107 107 108 108 $DbResult2 = $this->Database->select('NetworkSubnet', '*', '(`Member`='.$Member['Id'].') AND (AddressRange != "")'); 109 while ($Subnet = $DbResult2->fetch_assoc())109 while ($Subnet = $DbResult2->fetch_assoc()) 110 110 { 111 111 $Subnet['Name'] = RouterOSIdent('subnet-'.$Subnet['Name']); … … 114 114 $NewAddress->AddressFromString($Subnet['AddressRange']); 115 115 $NewAddress->Prefix = $Subnet['Mask']; 116 if ($Subnet['Member'] != 0) $ForceMark = true;116 if ($Subnet['Member'] != 0) $ForceMark = true; 117 117 else $ForceMark = false; 118 118 echo($ForceMark.', '); … … 169 169 $DbResult = $this->System->Database->query('SELECT `Id`, `Name`, `AddressRangeIPv6`, `MaskIPv6` FROM `NetworkSubnet` '. 170 170 'WHERE (`Member` IS NULL) AND (`AddressRangeIPv6` != "")'); 171 while ($Subnet = $DbResult->fetch_assoc())171 while ($Subnet = $DbResult->fetch_assoc()) 172 172 { 173 173 $NewAddress = new NetworkAddressIPv6(); … … 181 181 'LEFT JOIN `Subject` ON `Subject`.`Id` = `Member`.`Subject` '. 182 182 'WHERE `Member`.`Blocked` = 0'); 183 while ($Member = $DbResult->fetch_assoc())183 while ($Member = $DbResult->fetch_assoc()) 184 184 { 185 185 $Member['Name'] = RouterOSIdent($Member['Name'].'-'.$Member['Id'] ); … … 187 187 188 188 $DbResult2 = $this->System->Database->select('NetworkDevice', '*', '`Used` = 1 AND `Member` = '.$Member['Id']); 189 while ($Device = $DbResult2->fetch_assoc())189 while ($Device = $DbResult2->fetch_assoc()) 190 190 { 191 191 $DbResult3 = $this->Database->select('NetworkInterface', '*', '`Device` = '.$Device['Id'].' AND `IPv6` != ""'); 192 while ($Interface = $DbResult3->fetch_assoc())192 while ($Interface = $DbResult3->fetch_assoc()) 193 193 { 194 194 $Name = $Device['Name']; 195 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];195 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name']; 196 196 $Name = RouterOSIdent($Name); 197 197 echo($Name.', '); … … 204 204 205 205 $DbResult2 = $this->Database->select('NetworkSubnet', '*', '(`Member`='.$Member['Id'].') AND (AddressRangeIPv6 != "")'); 206 while ($Subnet = $DbResult2->fetch_assoc())206 while ($Subnet = $DbResult2->fetch_assoc()) 207 207 { 208 208 $Subnet['Name'] = RouterOSIdent('subnet-'.$Subnet['Name']); … … 211 211 $NewAddress->AddressFromString($Subnet['AddressRangeIPv6']); 212 212 $NewAddress->Prefix = $Subnet['MaskIPv6']; 213 if ($Subnet['Member'] != 0) $ForceMark = true;213 if ($Subnet['Member'] != 0) $ForceMark = true; 214 214 else $ForceMark = false; 215 215 echo($ForceMark.', '); -
trunk/Modules/NetworkConfigRouterOS/Generators/FirewallNAT.php
r860 r873 39 39 'LEFT JOIN `Subject` ON `Subject`.`Id` = `Member`.`Subject` '. 40 40 'WHERE `Member`.`Blocked` = 0'); 41 while ($Member = $DbResult->fetch_assoc())41 while ($Member = $DbResult->fetch_assoc()) 42 42 { 43 43 echo($Member['Name'].': '); … … 47 47 ' AND (`NetworkInterface`.`LocalIP` <> "")'. 48 48 ' AND (`NetworkDevice`.`Member` = '.$Member['Id'].') AND (`NetworkInterface`.`LocalIP` != `NetworkInterface`.`ExternalIP`) ORDER BY `id` DESC'); 49 while ($Interface = $DbResult2->fetch_assoc())49 while ($Interface = $DbResult2->fetch_assoc()) 50 50 { 51 51 $Name = $Interface['DeviceName']; 52 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];52 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name']; 53 53 $Name = RouterOSIdent($Name); 54 54 echo($Name.'('.$Interface['LocalIP'].'), '); 55 if ($Member['Blocked'] == 0)55 if ($Member['Blocked'] == 0) 56 56 { 57 57 $Items[] = array('chain' => 'inet-out', 'src-address' => $Interface['LocalIP'], 'action' => 'src-nat', 'to-addresses' => $Interface['ExternalIP'], 'comment' => $Name.'-out'); 58 if ($Interface['InboundNATPriority'] > 0)58 if ($Interface['InboundNATPriority'] > 0) 59 59 $Items[] = array('chain' => 'inet-in', 'dst-address' => $Interface['ExternalIP'], 'action' => 'dst-nat', 'to-addresses' => $Interface['LocalIP'], 'comment' => $Name.'-in'); 60 60 } else … … 66 66 // Subnets 67 67 $DbResult2 = $this->Database->select('NetworkSubnet', '*', '`Member`='.$Member['Id']); 68 while ($Subnet = $DbResult2->fetch_assoc())68 while ($Subnet = $DbResult2->fetch_assoc()) 69 69 { 70 70 $Subnet['Name'] = RouterOSIdent('subnet-'.$Subnet['Name']); 71 71 echo($Subnet['Name'].'('.$Subnet['AddressRange'].'/'.$Subnet['Mask'].'), '); 72 if ($Member['Blocked'] == 0)72 if ($Member['Blocked'] == 0) 73 73 { 74 74 $NewAddress = new NetworkAddressIPv4(); … … 76 76 $NewAddress->Prefix = $Subnet['ExtMask']; 77 77 $Range = $NewAddress->GetRange(); 78 if ($Subnet['ExtMask'] != 32) $Range = $Range['From']->AddressToString().'-'.$Range['To']->AddressToString();78 if ($Subnet['ExtMask'] != 32) $Range = $Range['From']->AddressToString().'-'.$Range['To']->AddressToString(); 79 79 else $Range = $Range['From']->AddressToString(); 80 if ($Subnet['Mask'] == 32) $Src = $Subnet['AddressRange'];80 if ($Subnet['Mask'] == 32) $Src = $Subnet['AddressRange']; 81 81 else $Src = $Subnet['AddressRange'].'/'.$Subnet['Mask']; 82 82 $Items[] = array('chain' => 'inet-out', 'src-address' => $Src, 'action' => 'src-nat', 'to-addresses' => $Range, 'comment' => $Subnet['Name'].'-out'); … … 86 86 $NewAddress->Prefix = $Subnet['Mask']; 87 87 $Range = $NewAddress->GetRange(); 88 if ($Subnet['Mask'] != 32) $Range = $Range['From']->AddressToString().'-'.$Range['To']->AddressToString();88 if ($Subnet['Mask'] != 32) $Range = $Range['From']->AddressToString().'-'.$Range['To']->AddressToString(); 89 89 else $Range = $Range['From']->AddressToString(); 90 if ($Subnet['ExtMask'] == 32) $Dest = $Subnet['ExtAddressRange'];90 if ($Subnet['ExtMask'] == 32) $Dest = $Subnet['ExtAddressRange']; 91 91 else $Dest = $Subnet['ExtAddressRange'].'/'.$Subnet['ExtMask']; 92 92 $Items[] = array('chain' => 'inet-in', 'dst-address' => $Dest, 'action' => 'dst-nat', 'to-addresses' => $Range, 'comment' => $Subnet['Name'].'-in'); 93 93 } else 94 94 { 95 if ($Subnet['Mask'] == 32) $Src = $Subnet['AddressRange'];95 if ($Subnet['Mask'] == 32) $Src = $Subnet['AddressRange']; 96 96 else $Src = $Subnet['AddressRange'].'/'.$Subnet['Mask']; 97 97 $Items[] = array('chain' => 'dstnat', 'src-address' => $Src, 'protocol' => 'tcp', 'dst-port' => 80, 'action' => 'dst-nat', 'to-addresses' => $IPCentrala, 'to-ports' => 81, 'comment' => $Subnet['Name'].'-out'); … … 124 124 // Route public addresses localy 125 125 $DbResult = $this->Database->query('SELECT Member.*, Subject.Name FROM Member JOIN Subject ON Member.Subject = Subject.Id'); 126 while ($Member = $DbResult->fetch_assoc())126 while ($Member = $DbResult->fetch_assoc()) 127 127 { 128 128 echo($Member['Name'].': '); 129 129 // Hosts 130 130 $DbResult2 = $this->Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface LEFT JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE (NetworkInterface.ExternalIP <> "") AND (NetworkDevice.Member = '.$Member['Id'].') AND (NetworkInterface.LocalIP != NetworkInterface.ExternalIP) ORDER BY id DESC'); 131 while ($Interface = $DbResult2->fetch_assoc())131 while ($Interface = $DbResult2->fetch_assoc()) 132 132 { 133 133 $Name = $Interface['DeviceName']; 134 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];134 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name']; 135 135 $Name = RouterOSIdent($Name); 136 136 echo($Name.'('.$Interface['LocalIP'].'), '); -
trunk/Modules/NetworkConfigRouterOS/Generators/Netwatch.php
r835 r873 13 13 14 14 $DbResult3 = $this->Database->query('SELECT DISTINCT (`DHCP`) FROM `NetworkSubnet` WHERE `Configure` = 1'); // WHERE `Member` = 0'); 15 while ($Router = $DbResult3->fetch_assoc())15 while ($Router = $DbResult3->fetch_assoc()) 16 16 { 17 17 echo($Router['DHCP']."\n"); … … 19 19 $Items = array(); 20 20 $DbResult = $this->Database->query('SELECT * FROM `NetworkSubnet` WHERE (`Configure` = 1) AND (`DHCP`="'.$Router['DHCP'].'")'); 21 while ($Subnet = $DbResult->fetch_assoc())21 while ($Subnet = $DbResult->fetch_assoc()) 22 22 { 23 23 $I = explode('.', $Subnet['AddressRange']); … … 26 26 ' LEFT JOIN `NetworkDevice` ON `NetworkDevice`.`Id` = `NetworkInterface`.`Device` WHERE CompareNetworkPrefix(INET_ATON(`LocalIP`), INET_ATON("'.$Subnet['AddressRange'].'"), '.$Subnet['Mask'].')'. 27 27 ' AND (`NetworkDevice`.`Used` = 1) ORDER BY `NetworkInterface`.`LocalIP`'); 28 while ($Interface = $DbResult2->fetch_assoc())28 while ($Interface = $DbResult2->fetch_assoc()) 29 29 { 30 30 $Name = $Interface['DeviceName']; 31 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];31 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name']; 32 32 echo($Name.', '); 33 33 $Items[] = array('host' => $Interface['LocalIP'], 'interval' => '00:00:10', 'comment' => $Name); -
trunk/Modules/NetworkConfigRouterOS/Generators/NetwatchImport.php
r863 r873 10 10 $Interfaces = array(); 11 11 $DbResult = $this->Database->select('NetworkInterface', '`Id`, `LocalIP` AS `IP`, `Online`, 0 AS `NewOnline`'); 12 while ($DbRow = $DbResult->fetch_assoc())12 while ($DbRow = $DbResult->fetch_assoc()) 13 13 $Interfaces[$DbRow['IP']] = $DbRow; 14 14 … … 16 16 $DbResult3 = $this->Database->query('SELECT `DHCP` FROM `NetworkSubnet` '. 17 17 'WHERE (`Configure` = 1) AND (`Member` IS NULL) GROUP BY `DHCP`'); 18 while ($Subnet = $DbResult3->fetch_assoc())18 while ($Subnet = $DbResult3->fetch_assoc()) 19 19 { 20 20 echo('router '.$Subnet['DHCP']."\n"); … … 22 22 $Routerboard->Connect($Subnet['DHCP'], $this->System->Config['API']['UserName'], 23 23 $this->System->Config['API']['Password']); 24 if (!$Routerboard->Connected) continue;24 if (!$Routerboard->Connected) continue; 25 25 $Routerboard->Write('/tool/netwatch/getall', false); 26 26 $Routerboard->Write('=.proplist=host,status'); 27 27 $Read = $Routerboard->Read(false); 28 28 $List = $Routerboard->ParseResponse($Read); 29 foreach ($List as $Properties)29 foreach ($List as $Properties) 30 30 { 31 31 $IP = $Properties['host']; 32 if ($Properties['status'] == 'up') $Online = 1;32 if ($Properties['status'] == 'up') $Online = 1; 33 33 else $Online = 0; 34 34 35 if ($Online)35 if ($Online) 36 36 { 37 if (array_key_exists($IP, $Interfaces))37 if (array_key_exists($IP, $Interfaces)) 38 38 $Interfaces[$IP]['NewOnline'] = 1; 39 39 else echo('IP '.$IP.' not found.'."\n"); … … 44 44 $Queries = array(); 45 45 $QueriesInsert = array(); 46 foreach ($Interfaces as $Index => $Interface)46 foreach ($Interfaces as $Index => $Interface) 47 47 { 48 48 // Update last online time if still online 49 if ($Interface['NewOnline'])49 if ($Interface['NewOnline']) 50 50 $Queries[] = $this->Database->GetUpdate('NetworkInterface', '`Id` = '.$Interface['Id'], 51 51 array('LastOnline' => TimeToMysqlDateTime($StartTime))); 52 52 53 if ($Interface['Online'] != $Interface['NewOnline'])53 if ($Interface['Online'] != $Interface['NewOnline']) 54 54 { 55 55 // Online state changed … … 78 78 $DbResult = $this->Database->select('NetworkInterface', '*', '(`Online` = 1) AND '. 79 79 '(`LastOnline` < "'.TimeToMysqlDateTime($StartTime).'")'); 80 while ($DbRow = $DbResult->fetch_assoc())80 while ($DbRow = $DbResult->fetch_assoc()) 81 81 { 82 82 echo('IP '.$DbRow['LocalIP'].' online but time not updated.'."\n"); … … 84 84 $DbResult = $this->Database->select('NetworkInterface', '*', '(`Online` = 0) AND '. 85 85 '(`LastOnline` >= "'.TimeToMysqlDateTime($StartTime).'")'); 86 while ($DbRow = $DbResult->fetch_assoc())86 while ($DbRow = $DbResult->fetch_assoc()) 87 87 { 88 88 echo('IP '.$DbRow['LocalIP'].' not online but time updated.'."\n"); … … 92 92 // Update device online state 93 93 $DbResult = $this->Database->select('NetworkInterface', '`Device`, SUM(`Online`) AS `SumOnline`', '`Online` = 1 GROUP BY `Device`'); 94 while ($Device = $DbResult->fetch_assoc())94 while ($Device = $DbResult->fetch_assoc()) 95 95 { 96 if ($Device['SumOnline'] > 0)96 if ($Device['SumOnline'] > 0) 97 97 $Queries[] = $this->Database->GetUpdate('NetworkDevice', 'Id='.$Device['Device'], array('LastOnline' => TimeToMysqlDateTime($StartTime), 'Online' => 1)); 98 98 } -
trunk/Modules/NetworkConfigRouterOS/Generators/Queue.php
r869 r873 48 48 function CheckName($Name, &$UsedNames) 49 49 { 50 if (in_array($Name, $UsedNames)) die("\n".'Duplicate name: '.$Name);50 if (in_array($Name, $UsedNames)) die("\n".'Duplicate name: '.$Name); 51 51 else $UsedNames[] = $Name; 52 52 } … … 189 189 $DbResult = $this->Database->query('SELECT `Member`.*, `Subject`.`Name` FROM `Member` '. 190 190 'LEFT JOIN `Subject` ON `Subject`.`Id` = `Member`.`Subject` WHERE `Member`.`Blocked`=0'); 191 while ($Member = $DbResult->fetch_assoc())191 while ($Member = $DbResult->fetch_assoc()) 192 192 { 193 193 $ServiceIndex = 1; … … 198 198 'WHERE (`ServiceCustomerRel`.`Customer` = '.$Member['Id'].') AND (`ServiceCustomerRel`.`ChangeAction` IS NULL) '. 199 199 'AND (`Service`.`InternetSpeedMax` > 0) AND (`Service`.`InternetSpeedMin` > 0)'); 200 while ($Service = $DbResult4->fetch_assoc())200 while ($Service = $DbResult4->fetch_assoc()) 201 201 { 202 202 echo('Služba '.$Service['Name'].': '); … … 231 231 $Row = $DbResult2->fetch_row(); 232 232 $HostCount = $Row[0]; 233 if ($HostCount > 0)233 if ($HostCount > 0) 234 234 { 235 235 $HostSpeedIn = round($SpeedIn / $HostCount); … … 242 242 243 243 $DbResult2 = $this->Database->select('NetworkDevice', '*', $Filter); 244 while ($Device = $DbResult2->fetch_assoc())244 while ($Device = $DbResult2->fetch_assoc()) 245 245 { 246 246 $DbResult3 = $this->Database->select('NetworkInterface', '*', '`Device` = '.$Device['Id'].' AND `LocalIP` != ""'); 247 while ($Interface = $DbResult3->fetch_assoc())247 while ($Interface = $DbResult3->fetch_assoc()) 248 248 { 249 249 $DeviceName = $Device['Name']; 250 if ($Interface['Name'] != '') $DeviceName .= '-'.$Interface['Name'];250 if ($Interface['Name'] != '') $DeviceName .= '-'.$Interface['Name']; 251 251 $DeviceName = RouterOSIdent($DeviceName); 252 252 echo($DeviceName.', '); … … 258 258 259 259 $DbResult2 = $this->Database->select('NetworkSubnet', '*', '`Service`='.$Service['RelId']); 260 while ($Subnet = $DbResult2->fetch_assoc())260 while ($Subnet = $DbResult2->fetch_assoc()) 261 261 { 262 262 $SubnetName = RouterOSIdent('subnet-'.$Subnet['Name']); … … 329 329 { 330 330 $MinSpeed = 0; 331 foreach ($this->Devices[$DeviceId]['Childs'] as $DeviceChild)331 foreach ($this->Devices[$DeviceId]['Childs'] as $DeviceChild) 332 332 { 333 333 $this->UpdateMinSpeed($DeviceChild); … … 335 335 } 336 336 $this->Devices[$DeviceId]['MinSpeed'] = $MinSpeed; 337 if ($this->Devices[$DeviceId]['DeviceCount'] > 0)337 if ($this->Devices[$DeviceId]['DeviceCount'] > 0) 338 338 $this->Devices[$DeviceId]['MinSpeed'] += round($this->Devices[$DeviceId]['InternetSpeedMin'] / $this->Devices[$DeviceId]['DeviceCount']); 339 339 } … … 349 349 'LEFT JOIN `ServiceCustomerRel` ON `ServiceCustomerRel`.`Id`=`NetworkDevice`.`Service` '. 350 350 'LEFT JOIN `Service` ON `Service`.`Id` = `ServiceCustomerRel`.`Service`'); 351 while ($Device = $DbResult->fetch_assoc())351 while ($Device = $DbResult->fetch_assoc()) 352 352 { 353 353 $Device['Interfaces'] = array(); … … 364 364 $Interfaces = array(); 365 365 $DbResult = $this->Database->query('SELECT `Device`,`Name`,`Id` FROM `NetworkInterface`'); 366 while ($Interface = $DbResult->fetch_assoc())366 while ($Interface = $DbResult->fetch_assoc()) 367 367 { 368 368 $Interface['Links'] = array(); … … 376 376 '`NetworkLink`.`Interface2`,`NetworkLinkType`.`MaxRealSpeed` FROM `NetworkLink` '. 377 377 'LEFT JOIN `NetworkLinkType` ON `NetworkLinkType`.`Id`=`NetworkLink`.`Type`'); 378 while ($Link = $DbResult->fetch_assoc())378 while ($Link = $DbResult->fetch_assoc()) 379 379 { 380 380 $Links[$Link['Id']] = $Link; … … 388 388 $this->Devices[$RootDeviceId]['Calculated'] = true; 389 389 390 while (count($DevicesToCheck) > 0)390 while (count($DevicesToCheck) > 0) 391 391 { 392 392 //echo('Pass'."\n"); 393 393 $NewDevicesToCheck = array(); 394 foreach ($DevicesToCheck as $DeviceId)394 foreach ($DevicesToCheck as $DeviceId) 395 395 { 396 396 //echo($this->Devices[$DeviceId]['Name'].': '); 397 foreach ($this->Devices[$DeviceId]['Interfaces'] as $InterfaceId)397 foreach ($this->Devices[$DeviceId]['Interfaces'] as $InterfaceId) 398 398 { 399 foreach ($Interfaces[$InterfaceId]['Links'] as $LinkId)399 foreach ($Interfaces[$InterfaceId]['Links'] as $LinkId) 400 400 { 401 401 $Link = $Links[$LinkId]; 402 402 $Interface2Id = $Link['Interface1']; 403 if ($Interface2Id == $InterfaceId) $Interface2Id = $Links[$LinkId]['Interface2'];403 if ($Interface2Id == $InterfaceId) $Interface2Id = $Links[$LinkId]['Interface2']; 404 404 405 405 $Device2Id = $Interfaces[$Interface2Id]['Device']; 406 if ($this->Devices[$Device2Id]['Calculated'] == false)406 if ($this->Devices[$Device2Id]['Calculated'] == false) 407 407 { 408 408 $this->Devices[$Device2Id]['Calculated'] = true; 409 409 $NewMaxSpeed = $this->Devices[$DeviceId]['MaxSpeed']; 410 if ($NewMaxSpeed > $Link['MaxRealSpeed'])410 if ($NewMaxSpeed > $Link['MaxRealSpeed']) 411 411 $NewMaxSpeed = $Link['MaxRealSpeed']; 412 412 //echo($this->Devices[$Device2Id]['Name'].' '.$Device2Id.', '); … … 431 431 432 432 echo('Not linked network devices: '); 433 foreach ($this->Devices as $Device)434 { 435 if ($Device['MaxSpeed'] == 0) echo($Device['Name'].', ');433 foreach ($this->Devices as $Device) 434 { 435 if ($Device['MaxSpeed'] == 0) echo($Device['Name'].', '); 436 436 } 437 437 echo("\n"); … … 455 455 $DbResult3 = $this->Database->select('NetworkInterface', '*', '`Device` = '.$DeviceId.' AND `LocalIP` != ""'); 456 456 $IntCount = $DbResult3->num_rows; 457 while ($Interface = $DbResult3->fetch_assoc())457 while ($Interface = $DbResult3->fetch_assoc()) 458 458 { 459 459 $InterfaceName = $Device['Name']; 460 if ($Interface['Name'] != '') $InterfaceName .= '-'.$Interface['Name'];460 if ($Interface['Name'] != '') $InterfaceName .= '-'.$Interface['Name']; 461 461 else $InterfaceName .= '-'; 462 462 $InterfaceName = RouterOSIdent($InterfaceName); … … 469 469 470 470 // Process childs 471 foreach ($Device['Childs'] as $DeviceChild)471 foreach ($Device['Childs'] as $DeviceChild) 472 472 { 473 473 $this->BuildQueueItems($DeviceChild, $LimitDevice); … … 505 505 506 506 $DbResult = $this->Database->select('Service', '*', '(`ChangeAction` IS NULL) AND (`Id`='.TARIFF_FREE.')'); 507 if ($DbResult->num_rows == 1)507 if ($DbResult->num_rows == 1) 508 508 { 509 509 $Service = $DbResult->fetch_array(); -
trunk/Modules/NetworkConfigRouterOS/Generators/Signal.php
r851 r873 12 12 '(SELECT `LocalIP` FROM `NetworkInterface` WHERE `NetworkInterface`.`Device` = `NetworkDevice`.`Id` LIMIT 1) AS `LocalIP` '. 13 13 'FROM `NetworkDevice` WHERE (`API` = 1) AND (`Used` = 1)'); 14 while ($Device = $DbResult3->fetch_assoc())14 while ($Device = $DbResult3->fetch_assoc()) 15 15 { 16 16 echo($Device['LocalIP']."\n"); … … 19 19 //$Routerboard->Port = 8729; 20 20 $Routerboard->Connect($Device['LocalIP'], $this->System->Config['API']['UserName'], $this->System->Config['API']['Password']); 21 if (!$Routerboard->Connected) continue;21 if (!$Routerboard->Connected) continue; 22 22 $Routerboard->Write('/interface/wireless/registration-table/getall', false); 23 23 $Routerboard->Write('=.proplist=signal-strength,mac-address,rx-rate,tx-rate', false); … … 25 25 $Read = $Routerboard->Read(false); 26 26 $Array = $Routerboard->ParseResponse($Read); 27 foreach ($Array as $Properties)27 foreach ($Array as $Properties) 28 28 { 29 29 $DbResult = $this->Database->select('NetworkInterface', 'Id', 'MAC="'.$Properties['mac-address'].'"'); 30 if ($DbResult->num_rows > 0)30 if ($DbResult->num_rows > 0) 31 31 { 32 32 $DbRow = $DbResult->fetch_assoc(); … … 34 34 } else $Interface = 'NULL'; 35 35 36 if (strpos($Properties['signal-strength'], '@') === false)36 if (strpos($Properties['signal-strength'], '@') === false) 37 37 { 38 38 $Strength = $Properties['signal-strength']; 39 39 } else { 40 40 $Parts = explode('@', $Properties['signal-strength']); 41 if (substr($Parts[0], -3) == 'dBm')41 if (substr($Parts[0], -3) == 'dBm') 42 42 $Strength = substr($Parts[0], 0, -3); // without dBm 43 43 else $Strength = $Parts[0]; … … 50 50 /* 51 51 $DbResult = $this->Database->select('Measure', 'Id', '`Name` = "'.$Properties['mac-address'].'"'); 52 if ($DbResult->num_rows > 0)52 if ($DbResult->num_rows > 0) 53 53 { 54 54 $this->Database->insert('Measure', array('Name' => $Properties['mac-address'])); … … 74 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 return ($Value);76 return ($Value); 77 77 } 78 78 -
trunk/Modules/NetworkConfigRouterOS/NetworkConfigRouterOS.php
r860 r873 70 70 $IPAddress = GetRemoteAddress(); 71 71 $Output = 'Vaše IP adresa je: '.$IPAddress.'<br/>'; 72 if (IsInternetAddr($IPAddress)) {72 if (IsInternetAddr($IPAddress)) { 73 73 $Output .= '<p>Internet zdarma je dostupný pouze z vnitřní sítě.</p>'; 74 return ($Output);74 return ($Output); 75 75 } 76 76 $Time = time(); … … 78 78 $DbResult = $this->Database->select('NetworkFreeAccess', '*', '(IPAddress="'.$IPAddress. 79 79 '") ORDER BY Time DESC LIMIT 1'); 80 if ($DbResult->num_rows > 0)80 if ($DbResult->num_rows > 0) 81 81 { 82 82 $DbRow = $DbResult->fetch_assoc(); 83 83 $ActivationTime = MysqlDateTimeToTime($DbRow['Time']); 84 if (($ActivationTime + $this->Timeout) < $Time)84 if (($ActivationTime + $this->Timeout) < $Time) 85 85 { 86 86 $Activated = false; … … 88 88 } else $Activated = false; 89 89 90 if (array_key_exists('a', $_GET))90 if (array_key_exists('a', $_GET)) 91 91 { 92 if ($_GET['a'] == 'activate')92 if ($_GET['a'] == 'activate') 93 93 { 94 if ($Activated == false)94 if ($Activated == false) 95 95 { 96 96 $DbResult = $this->Database->insert('NetworkFreeAccess', … … 108 108 109 109 $PrefixMultiplier = new PrefixMultiplier(); 110 if ($Activated) $Output .= 'Aktivováno. Vyprší za '.$PrefixMultiplier->Add($ActivationTime + $this->Timeout - $Time, '', 4, 'Time');110 if ($Activated) $Output .= 'Aktivováno. Vyprší za '.$PrefixMultiplier->Add($ActivationTime + $this->Timeout - $Time, '', 4, 'Time'); 111 111 else $Output .= '<a href="?a=activate">Aktivovat</a>'; 112 112 113 return ($Output);113 return ($Output); 114 114 } 115 115 } … … 122 122 $Commands = array(); 123 123 $DbResult = $this->Database->select('NetworkFreeAccess', '`Id`, `IPAddress`', '(`Configured`=0)'); 124 while ($DbRow = $DbResult->fetch_assoc())124 while ($DbRow = $DbResult->fetch_assoc()) 125 125 { 126 126 $Commands[] = '/ip firewall address-list add address='.$DbRow['IPAddress']. … … 135 135 $Routerboard->ExecuteBatch(implode(';', $Commands)); 136 136 137 return ($Output);137 return ($Output); 138 138 } 139 139 } -
trunk/Modules/NetworkConfigRouterOS/Routerboard.php
r860 r873 22 22 { 23 23 $Output = array(); 24 if (is_array($Commands))24 if (is_array($Commands)) 25 25 { 26 26 $I = 0; 27 27 $Batch = array(); 28 while ($I < count($Commands))29 { 30 if (($I % $this->MaxBurstLineCount) == 0)31 { 32 if (count($Batch) > 0)28 while ($I < count($Commands)) 29 { 30 if (($I % $this->MaxBurstLineCount) == 0) 31 { 32 if (count($Batch) > 0) 33 33 $Output = array_merge($Output, $this->ExecuteBatch(implode(';', $Batch))); 34 34 $Batch = array(); … … 37 37 $I++; 38 38 } 39 if (count($Batch) > 0)39 if (count($Batch) > 0) 40 40 $Output = array_merge($Output, $this->ExecuteBatch(implode(';', $Batch))); 41 41 } else 42 42 $Output = array_merge($Output, $this->ExecuteBatch($Commands)); 43 return ($Output);43 return ($Output); 44 44 } 45 45 … … 47 47 { 48 48 $Commands = trim($Commands); 49 if ($Commands != '')49 if ($Commands != '') 50 50 { 51 51 $Commands = addslashes($Commands); … … 57 57 $Command = $this->SSHPath.' -oBatchMode=no -o ConnectTimeout='.$this->Timeout.' -l '.$this->UserName. 58 58 $PrivKey.' '.$this->HostName.' "'.$Commands.'"'; 59 if ($this->Debug) echo($Command);59 if ($this->Debug) echo($Command); 60 60 $Output = array(); 61 61 exec($Command, $Output); 62 62 } else $Output = ''; 63 if ($this->Debug) print_r($Output);64 return ($Output);63 if ($this->Debug) print_r($Output); 64 return ($Output); 65 65 } 66 66 … … 70 70 array_pop($Result); 71 71 $List = array(); 72 foreach ($Result as $ResultLine)72 foreach ($Result as $ResultLine) 73 73 { 74 74 $ResultLineParts = explode(' ', trim($ResultLine)); 75 if (count($ResultLineParts) > 1)76 { 77 if ($ResultLineParts[1]{0} == '"') $ResultLineParts[1] = substr($ResultLineParts[1], 1, -1); // Remove quotes75 if (count($ResultLineParts) > 1) 76 { 77 if ($ResultLineParts[1]{0} == '"') $ResultLineParts[1] = substr($ResultLineParts[1], 1, -1); // Remove quotes 78 78 $List[substr($ResultLineParts[0], 0, -1)] = $ResultLineParts[1]; 79 79 } else $List[substr($ResultLineParts[0], 0, -1)] = ''; 80 80 } 81 return ($List);81 return ($List); 82 82 } 83 83 … … 85 85 { 86 86 $PropertyList = '"'; 87 foreach ($Properties as $Index => $Property)87 foreach ($Properties as $Index => $Property) 88 88 { 89 89 $PropertyList .= $Index.'=".[get $i '.$Property.']." '; … … 92 92 93 93 $ConditionList = ''; 94 foreach ($Conditions as $Index => $Item)95 { 96 if ($Item == 'no') $ConditionList .= $Index.'='.$Item.' ';94 foreach ($Conditions as $Index => $Item) 95 { 96 if ($Item == 'no') $ConditionList .= $Index.'='.$Item.' '; 97 97 else $ConditionList .= $Index.'="'.$Item.'" '; 98 98 } … … 101 101 $Result = $this->Execute(implode(' ', $Path).' {:foreach i in=[find '.$ConditionList.'] do={:put ('.$PropertyList.')}}'); 102 102 $List = array(); 103 foreach ($Result as $ResultLine)103 foreach ($Result as $ResultLine) 104 104 { 105 105 $ResultLineParts = explode(' ', $ResultLine); 106 106 $ListItem = array(); 107 foreach ($ResultLineParts as $ResultLinePart)107 foreach ($ResultLineParts as $ResultLinePart) 108 108 { 109 109 $Value = explode('=', $ResultLinePart); 110 if (count($Value) > 1) $ListItem[$Properties[$Value[0]]] = $Value[1];110 if (count($Value) > 1) $ListItem[$Properties[$Value[0]]] = $Value[1]; 111 111 else $ListItem[$Properties[$Value[0]]] = ''; 112 112 } 113 113 $List[] = $ListItem; 114 114 } 115 return ($List);115 return ($List); 116 116 } 117 117 … … 119 119 { 120 120 $ConditionList = ''; 121 foreach ($Conditions as $Index => $Item)121 foreach ($Conditions as $Index => $Item) 122 122 { 123 123 $ConditionList .= $Index.'="'.$Item.'" '; 124 124 } 125 125 $ConditionList = substr($ConditionList, 0, -1); 126 if (trim($ConditionList) != '')126 if (trim($ConditionList) != '') 127 127 $ConditionList = ' where '.$ConditionList; 128 128 129 129 $Result = $this->Execute(implode(' ', $Path).' print terse'.$ConditionList); 130 130 $List = array(); 131 foreach ($Result as $ResultLine)131 foreach ($Result as $ResultLine) 132 132 { 133 133 $ResultLineParts = explode(' ', $ResultLine); 134 134 $ListItem = array(); 135 foreach ($ResultLineParts as $ResultLinePart)135 foreach ($ResultLineParts as $ResultLinePart) 136 136 { 137 137 $Value = explode('=', $ResultLinePart); 138 if (in_array($Value[0], $Properties))139 { 140 if (count($Value) > 1)138 if (in_array($Value[0], $Properties)) 139 { 140 if (count($Value) > 1) 141 141 { 142 if ($Value[1]{0} == '"') $Value[1] = substr($Value[1], 1, -1);143 //if (strlen($Value[1]) > 0)142 if ($Value[1]{0} == '"') $Value[1] = substr($Value[1], 1, -1); 143 //if (strlen($Value[1]) > 0) 144 144 $ListItem[$Value[0]] = $Value[1]; 145 145 } else $ListItem[$Value[0]] = ''; 146 146 } 147 147 } 148 if (count($ListItem) > 0) $List[] = $ListItem;149 } 150 return ($List);148 if (count($ListItem) > 0) $List[] = $ListItem; 149 } 150 return ($List); 151 151 } 152 152 … … 159 159 { 160 160 // Get current list from routerboard 161 if ($UsePrint == 0)161 if ($UsePrint == 0) 162 162 { 163 163 $List = $this->ListGet($Path, $Properties, $Condition); 164 164 // Change boolean values yes/no to true/false 165 foreach ($List as $Index => $ListItem)166 { 167 foreach ($ListItem as $Index2 => $Item2)168 { 169 if ($Item2 == 'true') $List[$Index][$Index2] = 'yes';170 if ($Item2 == 'false') $List[$Index][$Index2] = 'no';165 foreach ($List as $Index => $ListItem) 166 { 167 foreach ($ListItem as $Index2 => $Item2) 168 { 169 if ($Item2 == 'true') $List[$Index][$Index2] = 'yes'; 170 if ($Item2 == 'false') $List[$Index][$Index2] = 'no'; 171 171 } 172 172 } … … 178 178 179 179 // Add empty properties to values 180 foreach ($Values as $Index => $Item)181 { 182 foreach ($Properties as $Property)183 { 184 if (!array_key_exists($Property, $Item))180 foreach ($Values as $Index => $Item) 181 { 182 foreach ($Properties as $Property) 183 { 184 if (!array_key_exists($Property, $Item)) 185 185 $Item[$Property] = ''; 186 186 } 187 187 $Values[$Index] = $Item; 188 188 } 189 foreach ($List as $Index => $Item)190 { 191 foreach ($Properties as $Property)192 { 193 if (!array_key_exists($Property, $Item))189 foreach ($List as $Index => $Item) 190 { 191 foreach ($Properties as $Property) 192 { 193 if (!array_key_exists($Property, $Item)) 194 194 $Item[$Property] = ''; 195 195 } … … 198 198 199 199 // Sort properties 200 foreach ($Values as $Index => $Item)200 foreach ($Values as $Index => $Item) 201 201 { 202 202 ksort($Values[$Index]); 203 203 } 204 foreach ($List as $Index => $Item)204 foreach ($List as $Index => $Item) 205 205 { 206 206 ksort($List[$Index]); 207 207 } 208 if ($this->Debug) print_r($List);209 if ($this->Debug) print_r($Values);208 if ($this->Debug) print_r($List); 209 if ($this->Debug) print_r($Values); 210 210 211 211 // Erase all items not existed in $Values 212 foreach ($List as $Index => $ListItem)213 { 214 if (!in_array($ListItem, $Values))212 foreach ($List as $Index => $ListItem) 213 { 214 if (!in_array($ListItem, $Values)) 215 215 { 216 216 $Prop = ''; 217 foreach ($ListItem as $Index => $Property)218 { 219 if ($Property != '')217 foreach ($ListItem as $Index => $Property) 218 { 219 if ($Property != '') 220 220 { 221 if (($Property == 'yes') or ($Property == 'no')) $Prop .= $Index.'='.$Property.' ';221 if (($Property == 'yes') or ($Property == 'no')) $Prop .= $Index.'='.$Property.' '; 222 222 else $Prop .= $Index.'="'.$Property.'" '; 223 223 } 224 224 } 225 225 $Prop = substr($Prop, 0, -1); 226 if (trim($Prop) != '')226 if (trim($Prop) != '') 227 227 $Commands[] = implode(' ', $Path).' remove [find '.$Prop.']'; 228 228 } … … 230 230 231 231 // Add new items 232 foreach ($Values as $ListItem)233 { 234 if (!in_array($ListItem, $List))232 foreach ($Values as $ListItem) 233 { 234 if (!in_array($ListItem, $List)) 235 235 { 236 236 $Prop = ''; 237 foreach ($ListItem as $Index => $Property)238 { 239 if ($Property != '') $Prop .= $Index.'="'.$Property.'" ';237 foreach ($ListItem as $Index => $Property) 238 { 239 if ($Property != '') $Prop .= $Index.'="'.$Property.'" '; 240 240 } 241 241 $Prop = substr($Prop, 0, -1); … … 243 243 } 244 244 } 245 if ($this->Debug) print_r($Commands);246 return ($this->Execute($Commands));245 if ($this->Debug) print_r($Commands); 246 return ($this->Execute($Commands)); 247 247 } 248 248 } -
trunk/Modules/NetworkConfigRouterOS/Routerboard2.php
r738 r873 13 13 function Execute($Commands) 14 14 { 15 if (is_array($Commands)) $Commands = implode(';', $Commands);16 return (parent::Execute($Commands));15 if (is_array($Commands)) $Commands = implode(';', $Commands); 16 return (parent::Execute($Commands)); 17 17 } 18 18 … … 22 22 array_pop($Result); 23 23 $List = array(); 24 foreach ($Result as $ResultLine)24 foreach ($Result as $ResultLine) 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 } 30 return ($List);30 return ($List); 31 31 } 32 32 … … 34 34 { 35 35 $PropertyList = '"'; 36 foreach ($Properties as $Property)36 foreach ($Properties as $Property) 37 37 { 38 38 $PropertyList .= $Property.'=".[get $i '.$Property.']." '; … … 41 41 $Result = $this->Execute($Command.' {:foreach i in=[find] do={:put ('.$PropertyList.')}}'); 42 42 $List = array(); 43 foreach ($Result as $ResultLine)43 foreach ($Result as $ResultLine) 44 44 { 45 45 $ResultLineParts = explode(' ', $ResultLine); 46 46 $ListItem = array(); 47 foreach ($ResultLineParts as $ResultLinePart)47 foreach ($ResultLineParts as $ResultLinePart) 48 48 { 49 49 $Value = explode('=', $ResultLinePart); … … 52 52 $List[] = $ListItem; 53 53 } 54 return ($List);54 return ($List); 55 55 } 56 56 57 57 function GetSystemResource() 58 58 { 59 return ($this->GetItem('/system resource print'));59 return ($this->GetItem('/system resource print')); 60 60 } 61 61 62 62 function GetFirewallFilterList() 63 63 { 64 return ($this->GetList('/ip firewall nat', array('src-address', 'dst-address', 'bytes')));64 return ($this->GetList('/ip firewall nat', array('src-address', 'dst-address', 'bytes'))); 65 65 } 66 66 67 67 function GetDHCPServerLeasesList() 68 68 { 69 return ($this->GetList('/ip dhcp-server lease', array('address', 'active-address', 'comment', 'lease-time', 'status', 'host-name')));69 return ($this->GetList('/ip dhcp-server lease', array('address', 'active-address', 'comment', 'lease-time', 'status', 'host-name'))); 70 70 } 71 71 } -
trunk/Modules/NetworkConfigRouterOS/RouterboardAPI.php
r861 r873 40 40 } else if ($Length >= 0x10000000) 41 41 $Length = chr(0xF0).chr(($Length >> 24) & 0xFF).chr(($Length >> 16) & 0xFF).chr(($Length >> 8) & 0xFF).chr($Length & 0xFF); 42 return ($Length);42 return ($Length); 43 43 } 44 44 45 45 function ConnectOnce($IP, $Login, $Password) 46 46 { 47 if ($this->Connected) $this->Disconnect();48 if ($this->SSL)47 if ($this->Connected) $this->Disconnect(); 48 if ($this->SSL) 49 49 { 50 50 $IP = 'ssl://'.$IP; 51 51 } 52 52 $this->Socket = @fsockopen($IP, $this->Port, $this->ErrorNo, $this->ErrorStr, $this->Timeout); 53 if ($this->Socket)53 if ($this->Socket) 54 54 { 55 55 socket_set_timeout($this->Socket, $this->Timeout); … … 58 58 $this->Write('=password='.$Password); 59 59 $Response = $this->Read(false); 60 if ((count($Response) > 0) and ($Response[0] == '!done')) $this->Connected = true;61 if (!$this->Connected) fclose($this->Socket);60 if ((count($Response) > 0) and ($Response[0] == '!done')) $this->Connected = true; 61 if (!$this->Connected) fclose($this->Socket); 62 62 } 63 63 } … … 65 65 function Connect($IP, $Login, $Password) 66 66 { 67 for ($Attempt = 1; $Attempt <= $this->Attempts; $Attempt++)67 for ($Attempt = 1; $Attempt <= $this->Attempts; $Attempt++) 68 68 { 69 69 $this->ConnectOnce($IP, $Login, $Password); 70 if ($this->Connected) break;70 if ($this->Connected) break; 71 71 sleep($this->Delay); 72 72 } 73 return ($this->Connected);73 return ($this->Connected); 74 74 } 75 75 76 76 function Disconnect() 77 77 { 78 if ($this->Connected)78 if ($this->Connected) 79 79 { 80 80 fclose($this->Socket); … … 183 183 $Response[] = $Line; 184 184 } 185 if ($this->Debug) echo($Line);185 if ($this->Debug) echo($Line); 186 186 // If we get a !done, make a note of it. 187 187 if ($Line == "!done") $ReceivedDone = true; … … 192 192 break; 193 193 } 194 if ($Parse) $Response = $this->ParseResponse($Response);194 if ($Parse) $Response = $this->ParseResponse($Response); 195 195 return $Response; 196 196 } … … 198 198 function Write($Command, $Param2 = true) 199 199 { 200 if ($Command)200 if ($Command) 201 201 { 202 202 $Data = explode("\n", $Command); … … 234 234 $this->Write($el, $Last); 235 235 } 236 return ($this->Read());236 return ($this->Read()); 237 237 } 238 238 } -
trunk/Modules/NetworkConfigRouterOS/SSH.php
r738 r873 18 18 { 19 19 echo($Commands); 20 if (!function_exists("ssh2_connect")) die("Function ssh2_connect doesn't exist");21 if (!($this->Session = ssh2_connect($this->HostName, 22, $this->Methods))) echo("Fail: Unable to establish connection to host\n");20 if (!function_exists("ssh2_connect")) die("Function ssh2_connect doesn't exist"); 21 if (!($this->Session = ssh2_connect($this->HostName, 22, $this->Methods))) echo("Fail: Unable to establish connection to host\n"); 22 22 else 23 23 { 24 if (!ssh2_auth_password($this->Session, $this->UserName, $this->Password)) echo("Fail: unable to authenticate\n");24 if (!ssh2_auth_password($this->Session, $this->UserName, $this->Password)) echo("Fail: unable to authenticate\n"); 25 25 else 26 26 { 27 //if (!($Stream = ssh2_shell($this->Session, 'xterm', null, 80, 40, SSH2_TERM_UNIT_CHARS))) echo("Fail: unable to execute command\n");28 if (!($Stream = ssh2_exec($this->Session, $Commands))) echo("Fail: unable to execute command\n");27 //if (!($Stream = ssh2_shell($this->Session, 'xterm', null, 80, 40, SSH2_TERM_UNIT_CHARS))) echo("Fail: unable to execute command\n"); 28 if (!($Stream = ssh2_exec($this->Session, $Commands))) echo("Fail: unable to execute command\n"); 29 29 else 30 30 { 31 31 $Response = ''; 32 32 stream_set_blocking($Stream, true); 33 while ($Buffer = fread($Stream, 4000))33 while ($Buffer = fread($Stream, 4000)) 34 34 { 35 35 $Response .= $Buffer; … … 37 37 /* 38 38 //echo(') '.strlen($Buffer).' '.ord($Buffer{0}).'('); 39 for ($I = 0; $I < strlen($Buffer); $I++)39 for ($I = 0; $I < strlen($Buffer); $I++) 40 40 { 41 if (((ord($Buffer{$I}) >= 32) and (ord($Buffer{$I}) <= 128)) or ($Buffer{$I} = "\n") or ($Buffer{$I} = "\r")) echo($Buffer{$I});42 if ($Buffer{$I} == '>')41 if (((ord($Buffer{$I}) >= 32) and (ord($Buffer{$I}) <= 128)) or ($Buffer{$I} = "\n") or ($Buffer{$I} = "\r")) echo($Buffer{$I}); 42 if ($Buffer{$I} == '>') 43 43 { 44 44 fwrite($Stream, $Commands."\n\r"); … … 54 54 } 55 55 echo($Response); 56 return (explode("\n", substr($Response, 0, -1)));56 return (explode("\n", substr($Response, 0, -1))); 57 57 } 58 58 }
Note:
See TracChangeset
for help on using the changeset viewer.