- Timestamp:
- Apr 6, 2020, 11:17:40 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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'].'), ');
Note:
See TracChangeset
for help on using the changeset viewer.