Changeset 187 for trunk/system/generators/nat_routerboard.php
- Timestamp:
- Apr 5, 2009, 3:54:46 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/generators/nat_routerboard.php
r174 r187 3 3 include_once('../../global.php'); 4 4 5 $InetInterface = 'ether3'; 6 $Router = '192.168.0.11'; 5 $InetInterface = $Config['MainRouter']['InetInterface']; 7 6 8 7 $Commands = array(); … … 12 11 while($Member = $DbResult->fetch_assoc()) 13 12 { 14 echo($Member['Name']."\n"); 13 echo($Member['Name'].': '); 14 // Hosts 15 15 $DbResult2 = $Database->select('hosts', '*', '(external_ip <> "") AND (user='.$Member['Id'].') AND (IP != external_ip) ORDER BY id DESC'); 16 16 while($Host = $DbResult2->fetch_assoc()) 17 17 { 18 echo($Host['name']."\n"); 18 $Host['name'] = RouterOSIdent($Host['name']); 19 echo($Host['name'].'('.$Host['IP'].'), '); 19 20 $Commands[] = ' /ip firewall nat add chain=srcnat src-address='.$Host['IP'].' out-interface='.$InetInterface.' action=src-nat to-addresses='.$Host['external_ip'].' comment="'.$Host['name'].'"'; 20 21 $Commands[] = ' /ip firewall nat add chain=dstnat dst-address='.$Host['external_ip'].' in-interface='.$InetInterface.' action=dst-nat to-addresses='.$Host['IP'].' comment="'.$Host['name'].'"'; 21 22 } 23 24 // Subnets 25 $DbResult2 = $Database->select('NetworkSubnet', '*', 'Member='.$Member['Id']); 26 while($Subnet = $DbResult2->fetch_assoc()) 27 { 28 $Subnet['Name'] = RouterOSIdent('subnet-'.$Subnet['Name']); 29 echo($Subnet['Name'].'('.$Subnet['AddressRange'].'/'.$Subnet['Mask'].'), '); 30 $Range = CIDRToAddressRange($Subnet['ExtAddressRange'], $Subnet['ExtMask']); 31 $Range = $Range['From'].'-'.$Range['To']; 32 $Commands[] = ' /ip firewall nat add chain=srcnat src-address-list='.$Subnet['AddressRange'].'/'.$Subnet['Mask'].' out-interface='.$InetInterface.' action=src-nat to-addresses='.$Range.' comment="'.$Subnet['Name'].'"'; 33 $Range = CIDRToAddressRange($Subnet['AddressRange'], $Subnet['Mask']); 34 $Range = $Range['From'].'-'.$Range['To']; 35 $Commands[] = ' /ip firewall nat add chain=dstnat dst-address-list='.$Subnet['ExtAddressRange'].'/'.$Subnet['ExtMask'].' in-interface='.$InetInterface.' action=dst-nat to-addresses='.$Range.' comment="'.$Subnet['Name'].'"'; 36 } 37 echo("\n"); 22 38 } 23 39 … … 29 45 30 46 $Commands = addslashes(implode(';', $Commands)); 31 $Command = '/usr/bin/ssh -l admin-ssh -i id_dsa '.$Router.' "'.$Commands.'"'; 47 $Command = '/usr/bin/ssh -l '.$Config['MainRouter']['UserName'].' -i id_dsa '.$Config['MainRouter']['HostName'].' "'.$Commands.'"'; 48 $Output = array(); 32 49 echo($Command."\n"); 33 //exec($Command, $Output);50 exec($Command, $Output); 34 51 //array_pop($Output); 35 52 //print_r($Output);
Note:
See TracChangeset
for help on using the changeset viewer.