Changeset 738 for trunk/Modules/NetworkConfigRouterOS/Generators
- Timestamp:
- Apr 14, 2015, 10:20:16 PM (10 years ago)
- Location:
- trunk/Modules/NetworkConfigRouterOS/Generators
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/NetworkConfigRouterOS/Generators/AddressPortability.php
r548 r738 6 6 $Path = array('ip', 'dhcp-server', 'lease'); 7 7 8 $Host = array(); 8 $Host = array(); 9 9 10 10 function ConvertExpireTime2($Time) -
trunk/Modules/NetworkConfigRouterOS/Generators/Common.php
r548 r738 6 6 { 7 7 global $Database; 8 8 9 9 $DbResult = $Database->query('SELECT `Id` FROM `NetworkMark` WHERE `Comment`="'.$Comment.'"'); 10 10 if($DbResult->num_rows > 0) … … 16 16 $DbResult = $Database->query('INSERT INTO `NetworkMark` (`Comment`) VALUES ("'.$Comment.'")'); 17 17 return($Database->insert_id); 18 } 18 } 19 19 } 20 20 … … 22 22 { 23 23 global $Database; 24 24 25 25 $DbResult = $Database->query('SELECT `Id` FROM `NetworkMangleSubgroup` WHERE `AddressRange`="'.$AddressRange.'"'); 26 26 if($DbResult->num_rows > 0) … … 32 32 $DbResult = $Database->query('INSERT INTO `NetworkMangleSubgroup` (`AddressRange`) VALUES ("'.$AddressRange.'")'); 33 33 return($Database->insert_id); 34 } 34 } 35 35 } 36 36 … … 38 38 { 39 39 global $Config; 40 40 41 41 $Found = false; 42 42 foreach($Tree['Items'] as $Index => $Node) … … 50 50 if($Found == false) 51 51 { 52 if($InterSubnets and ($Tree['Address']->Prefix < $Config['MainRouter']['MangleRuleSubgroupMinPrefix']) and 52 if($InterSubnets and ($Tree['Address']->Prefix < $Config['MainRouter']['MangleRuleSubgroupMinPrefix']) and 53 53 ($Address->Prefix > ($Tree['Address']->Prefix + 1))) 54 54 { … … 61 61 } else 62 62 { 63 63 64 64 $NewNode = array('Address' => $Address, 'Name' => $Name, 'Items' => array(), 'ForceMark' => $ForceMark); 65 65 66 66 // Should be existed items placed under new node? 67 67 $Found = false; 68 68 foreach($Tree['Items'] as $Index => $Node) 69 69 { 70 if(($Node['Address']->Address == $NewNode['Address']->Address) and 71 ($Node['Address']->Prefix == $NewNode['Address']->Prefix)) $Found = true; 72 70 if(($Node['Address']->Address == $NewNode['Address']->Address) and 71 ($Node['Address']->Prefix == $NewNode['Address']->Prefix)) $Found = true; 72 73 73 //echo($Index.','); 74 74 if($Address->Contain($Node['Address'])) … … 78 78 } 79 79 } 80 if($Found == false) $Tree['Items'][] = $NewNode; 80 if($Found == false) $Tree['Items'][] = $NewNode; 81 81 } 82 82 } … … 89 89 { 90 90 ShowSubnetNode($Item, $Indent + 1); 91 } 91 } 92 92 } 93 93 -
trunk/Modules/NetworkConfigRouterOS/Generators/DHCP.php
r617 r738 29 29 $Items[] = array('mac-address' => $Interface['MAC'], 'address' => $Interface['LocalIP'], 'server' => $Server, 'comment' => $Name); 30 30 } 31 32 print_r($Routerboard->ListUpdate($Path, array('mac-address', 'address', 'server', 'comment'), $Items, array('server' => $Server, 'dynamic' => 'no'))); 31 32 print_r($Routerboard->ListUpdate($Path, array('mac-address', 'address', 'server', 'comment'), $Items, array('server' => $Server, 'dynamic' => 'no'))); 33 33 echo("\n"); 34 34 } -
trunk/Modules/NetworkConfigRouterOS/Generators/FirewallFilter.php
r617 r738 24 24 25 25 // Inet traffic groups 26 //$Items[] = array('chain' => 'forward', 'out-interface' => $InetInterface, 'action' => 'jump', 'jump-target' => 'inet-out', 'comment' => 'inet-out'); 26 //$Items[] = array('chain' => 'forward', 'out-interface' => $InetInterface, 'action' => 'jump', 'jump-target' => 'inet-out', 'comment' => 'inet-out'); 27 27 //$Items[] = array('chain' => 'forward', 'in-interface' => $InetInterface, 'action' => 'jump', 'jump-target' => 'inet-in', 'comment' => 'inet-in'); 28 28 … … 63 63 $DbResult2 = $System->Database->select('NetworkSubnet', '*', 'Member='.$Member['Id']); 64 64 while($Subnet = $DbResult2->fetch_assoc()) 65 { 65 { 66 66 $Subnet['Name'] = RouterOSIdent('subnet-'.$Subnet['Name']); 67 67 echo($Subnet['Name'].'('.$Subnet['AddressRange'].'/'.$Subnet['Mask'].'), '); … … 75 75 else $Src = $Subnet['AddressRange'].'/'.$Subnet['Mask']; 76 76 $Items[] = array('chain' => 'forward', 'out-interface' => $InetInterface, 'src-address' => $Src, 'action' => 'drop','comment' => $Subnet['Name'].'-out-drop'); 77 77 78 78 $NewAddress = new NetworkAddressIPv4(); 79 79 $NewAddress->AddressFromString($Subnet['AddressRange']); -
trunk/Modules/NetworkConfigRouterOS/Generators/FirewallMangle.php
r735 r738 30 30 $NewAddress->AddressFromString($Subnet['AddressRange']); 31 31 $NewAddress->Prefix = $Subnet['Mask']; 32 InsertToAddressTree($AddressTree, $NewAddress, 'subnet-'.RouterOSIdent($Subnet['Name'])); 32 InsertToAddressTree($AddressTree, $NewAddress, 'subnet-'.RouterOSIdent($Subnet['Name'])); 33 33 } 34 34 … … 58 58 } 59 59 } 60 60 61 61 $DbResult2 = $System->Database->select('NetworkSubnet', '*', '`Member`='.$Member['Id']); 62 62 while($Subnet = $DbResult2->fetch_assoc()) … … 80 80 { 81 81 global $InetInterface, $ItemsFirewall; 82 82 83 83 foreach($Node['Items'] as $Index => $Item) 84 84 { … … 89 89 $Address = $Item['Address']->AddressToString(); 90 90 if($Item['Address']->Prefix != 32) $Address .= '/'.$Item['Address']->Prefix; 91 91 92 92 $PacketMark = GetMarkByComment($Item['Name'].'-out'); 93 93 $ItemsFirewall[] = array('chain' => 'inet-'.$ParentSubnetId.'-out', 'src-address' => $Address, 'out-interface' => $InetInterface, 'action' => 'mark-packet', 'new-packet-mark' => $PacketMark, 'passthrough' => 'no', 'comment' => $Item['Name'].'-out'); … … 100 100 $SubnetId = GetSubgroupByRange($Item['Address']->AddressToString().'/'.$Item['Address']->Prefix); 101 101 $PacketMark = GetMarkByComment($Item['Name'].'-out'); 102 102 103 103 $Address = $Item['Address']->AddressToString(); 104 104 if($Item['Address']->Prefix != 32) $Address .= '/'.$Item['Address']->Prefix; 105 106 $ItemsFirewall[] = array('chain' => 'inet-'.$ParentSubnetId.'-out', 'src-address' => $Address, 'out-interface' => $InetInterface, 'action' => 'jump', 'jump-target' => 'inet-'.$SubnetId.'-out', 'comment' => $Item['Name'].'-out'); 107 $ItemsFirewall[] = array('chain' => 'inet-'.$ParentSubnetId.'-in', 'dst-address' => $Address, 'in-interface' => $InetInterface, 'action' => 'jump', 'jump-target' => 'inet-'.$SubnetId.'-in', 'comment' => $Item['Name'].'-in'); 108 109 ProcessNode($Item); 110 } 105 106 $ItemsFirewall[] = array('chain' => 'inet-'.$ParentSubnetId.'-out', 'src-address' => $Address, 'out-interface' => $InetInterface, 'action' => 'jump', 'jump-target' => 'inet-'.$SubnetId.'-out', 'comment' => $Item['Name'].'-out'); 107 $ItemsFirewall[] = array('chain' => 'inet-'.$ParentSubnetId.'-in', 'dst-address' => $Address, 'in-interface' => $InetInterface, 'action' => 'jump', 'jump-target' => 'inet-'.$SubnetId.'-in', 'comment' => $Item['Name'].'-in'); 108 109 ProcessNode($Item); 110 } 111 111 } 112 112 if($Node['ForceMark'] == true) … … 133 133 // Slow free internet 134 134 $PacketMark = GetMarkByComment('free-out'); 135 $ItemsFirewall[] = array('chain' => 'inet-1-out', 'out-interface' => $InetInterface, 135 $ItemsFirewall[] = array('chain' => 'inet-1-out', 'out-interface' => $InetInterface, 136 136 'action' => 'mark-packet', 'new-packet-mark' => $PacketMark, 'comment' => 'free-out', 'passthrough' => 'yes'); 137 137 $PacketMark = GetMarkByComment('free-in'); 138 $ItemsFirewall[] = array('chain' => 'inet-1-in', 'in-interface' => $InetInterface, 139 138 $ItemsFirewall[] = array('chain' => 'inet-1-in', 'in-interface' => $InetInterface, 139 'action' => 'mark-packet', 'new-packet-mark' => $PacketMark, 'comment' => 'free-in', 'passthrough' => 'no'); 140 140 // Unregistred clients add to address list 141 $ItemsFirewall[] = array('chain' => 'inet-1-out', 'out-interface' => $InetInterface, 'src-address' => '10.145.0.0/16', 142 'action' => 'add-src-to-address-list', 'address-list' => 'unregistred', 'timeout' => '1d', 143 141 $ItemsFirewall[] = array('chain' => 'inet-1-out', 'out-interface' => $InetInterface, 'src-address' => '10.145.0.0/16', 142 'action' => 'add-src-to-address-list', 'address-list' => 'unregistred', 'timeout' => '1d', 143 'comment' => 'unregistred-clients'); 144 144 145 145 //print_r($ItemsFirewall); -
trunk/Modules/NetworkConfigRouterOS/Generators/FirewallNAT.php
r735 r738 34 34 35 35 // Skip local subnet 36 //$Items[] = array('chain' => 'inet-out', 'dst-address' => '172.16.1.1/30', 'action' => 'accept', 'comment' => 'Local_subnet'); 36 //$Items[] = array('chain' => 'inet-out', 'dst-address' => '172.16.1.1/30', 'action' => 'accept', 'comment' => 'Local_subnet'); 37 37 //$Items[] = array('chain' => 'inet-in', 'dst-address' => '172.16.1.1/30', 'action' => 'accept', 'comment' => 'Local_subnet'); 38 38 … … 46 46 $DbResult2 = $System->Database->query('SELECT `NetworkInterface`.*, `NetworkDevice`.`Name` AS `DeviceName`, `NetworkDevice`.`InboundNATPriority` FROM `NetworkInterface`'. 47 47 ' LEFT JOIN `NetworkDevice` ON `NetworkDevice`.`Id` = `NetworkInterface`.`Device` WHERE (`NetworkInterface`.`ExternalIP` <> "")'. 48 ' AND (`NetworkInterface`.`LocalIP` <> "")'. 48 ' AND (`NetworkInterface`.`LocalIP` <> "")'. 49 49 ' AND (`NetworkDevice`.`Member` = '.$Member['Id'].') AND (`NetworkInterface`.`LocalIP` != `NetworkInterface`.`ExternalIP`) ORDER BY `id` DESC'); 50 50 while($Interface = $DbResult2->fetch_assoc()) … … 57 57 { 58 58 $Items[] = array('chain' => 'inet-out', 'src-address' => $Interface['LocalIP'], 'action' => 'src-nat', 'to-addresses' => $Interface['ExternalIP'], 'comment' => $Name.'-out'); 59 if($Interface['InboundNATPriority'] > 0) 59 if($Interface['InboundNATPriority'] > 0) 60 60 $Items[] = array('chain' => 'inet-in', 'dst-address' => $Interface['ExternalIP'], 'action' => 'dst-nat', 'to-addresses' => $Interface['LocalIP'], 'comment' => $Name.'-in'); 61 } else 61 } else 62 62 { 63 63 $Items[] = array('chain' => 'dstnat', 'src-address' => $Interface['LocalIP'], 'protocol' => 'tcp', 'dst-port' => 80, 'action' => 'dst-nat', 'to-addresses' => $IPCentrala, 'to-ports' => 81, 'comment' => $Name.'-out'); … … 68 68 $DbResult2 = $System->Database->select('NetworkSubnet', '*', '`Member`='.$Member['Id']); 69 69 while($Subnet = $DbResult2->fetch_assoc()) 70 { 70 { 71 71 $Subnet['Name'] = RouterOSIdent('subnet-'.$Subnet['Name']); 72 72 echo($Subnet['Name'].'('.$Subnet['AddressRange'].'/'.$Subnet['Mask'].'), '); … … 82 82 else $Src = $Subnet['AddressRange'].'/'.$Subnet['Mask']; 83 83 $Items[] = array('chain' => 'inet-out', 'src-address' => $Src, 'action' => 'src-nat', 'to-addresses' => $Range, 'comment' => $Subnet['Name'].'-out'); 84 84 85 85 $NewAddress = new NetworkAddressIPv4(); 86 86 $NewAddress->AddressFromString($Subnet['AddressRange']); … … 114 114 115 115 // Accept free-access clients 116 $Items[] = array('chain' => 'dstnat', 'dst-address' => '!10.145.0.0/16', 117 'src-address-list' => 'free-access', 'in-interface' => $LocalInterface, 118 116 $Items[] = array('chain' => 'dstnat', 'dst-address' => '!10.145.0.0/16', 117 'src-address-list' => 'free-access', 'in-interface' => $LocalInterface, 118 'action' => 'accept', 'comment' => 'Free_access'); 119 119 // Redirect unregistred clients to free access activation page 120 $Items[] = array('chain' => 'dstnat', 'dst-address' => '!10.145.0.0/16', 121 'src-address-list' => 'unregistred', 'in-interface' => $LocalInterface, 122 120 $Items[] = array('chain' => 'dstnat', 'dst-address' => '!10.145.0.0/16', 121 'src-address-list' => 'unregistred', 'in-interface' => $LocalInterface, 122 'action' => 'dst-nat', 'to-addresses' => '10.145.64.8', 'to-ports' => 82, 'comment' => 'Redirect_unregistred'); 123 123 124 124 /* -
trunk/Modules/NetworkConfigRouterOS/Generators/Netwatch.php
r617 r738 35 35 } 36 36 } 37 $Routerboard->ListUpdate($Path, array('host', 'interval', 'comment'), $Items); 37 $Routerboard->ListUpdate($Path, array('host', 'interval', 'comment'), $Items); 38 38 echo("\n"); 39 39 } -
trunk/Modules/NetworkConfigRouterOS/Generators/NetwatchImport.php
r697 r738 21 21 // Load netwatch status from all DHCP routers 22 22 $DbResult3 = $System->Database->query('SELECT `DHCP`, `AddressRange`, `Mask` FROM `NetworkSubnet` '. 23 23 'WHERE (`Configure` = 1) AND (`Member` IS NULL) GROUP BY DHCP'); 24 24 while($Subnet = $DbResult3->fetch_assoc()) 25 25 { … … 54 54 array('LastOnline' => TimeToMysqlDateTime($StartTime))); 55 55 56 56 if($Interface['Online'] != $Interface['NewOnline']) 57 57 { 58 58 // Online state changed 59 59 $DbResult = $System->Database->query('INSERT INTO `NetworkInterfaceUpDown` (`Interface`, 60 60 `State`, `Time`, `Duration`) VALUES ('.$Interface['Id'].', '.$Interface['NewOnline'].', "'. 61 61 TimeToMysqlDateTime($StartTime).'", NULL)'); 62 62 // Update previous record duration in UpDown table … … 64 64 '`TM`.`Time`, (SELECT `Time` FROM (SELECT * FROM `NetworkInterfaceUpDown`) AS `TA` WHERE (`TA`.`Time` > `TM`.`Time`) '. 65 65 'AND (`TA`.`Interface`=`TM`.`Interface`) ORDER BY `TA`.`Time` ASC LIMIT 1)) '. 66 66 'WHERE (`TM`.`Duration` IS NULL) AND (`TM`.`Interface` ='.$Interface['Id'].')'); 67 67 $System->Database->update('NetworkInterface', '`Id` = "'.$Interface['Id'].'"', 68 68 array('Online' => $Interface['NewOnline'])); … … 75 75 while($DbRow = $DbResult->fetch_assoc()) 76 76 { 77 77 echo('IP '.$DbRow['LocalIP'].' online but time not updated.'."\n"); 78 78 } 79 79 $DbResult = $System->Database->select('NetworkInterface', '*', '(`Online` = 0) AND '. -
trunk/Modules/NetworkConfigRouterOS/Generators/Queue.php
r726 r738 22 22 { 23 23 global $UsedNames; 24 24 25 25 if(in_array($Name, $UsedNames)) die("\n".'Duplicate name: '.$Name); 26 26 else $UsedNames[] = $Name; … … 53 53 if($DbResult->num_rows == 1) 54 54 { 55 55 $Service = $DbResult->fetch_array(); 56 56 $FreeInetSpeed = $Service['InternetSpeedMax'] * 1000; 57 57 } else $FreeInetSpeed = 0; … … 128 128 } 129 129 } 130 130 131 131 $DbResult2 = $System->Database->select('NetworkSubnet', '*', '`Service`='.$Service['RelId']); 132 132 while($Subnet = $DbResult2->fetch_assoc()) -
trunk/Modules/NetworkConfigRouterOS/Generators/Signal.php
r682 r738 35 35 if($DbResult->num_rows > 0) 36 36 { 37 37 $DbRow = $DbResult->fetch_assoc(); 38 38 $Interface = $DbRow['Id']; 39 39 } else $Interface = null;
Note:
See TracChangeset
for help on using the changeset viewer.