Changeset 103 for system/generators/iptables.php
- Timestamp:
- Aug 3, 2008, 6:50:25 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
system/generators/iptables.php
r37 r103 1 1 <?php 2 include_once(' ../../html/global.php');2 include_once('/a/www/centrala/global.php'); 3 3 4 4 // Generate firewall rules 5 exec(' iptables -t nat -F Block');6 exec(' iptables -t nat -F POSTROUTING');7 exec(' iptables -t nat -F PreroutingDNAT');8 // exec(' iptables -t nat -A Block -p tcp --destination-port 80 -j REDIRECT --to-ports 3128');5 exec('/sbin/iptables -t nat -F Block'); 6 exec('/sbin/iptables -t nat -F POSTROUTING'); 7 exec('/sbin/iptables -t nat -F PreroutingDNAT'); 8 // exec('/sbin/iptables -t nat -A Block -p tcp --destination-port 80 -j REDIRECT --to-ports 3128'); 9 9 10 10 // Blocking according IP address … … 15 15 while($Row = $DbResult2->fetch_array()) 16 16 { 17 exec(' iptables -t nat -A Block -s '.$Row['IP'].' -j Local');17 exec('/sbin/iptables -t nat -A Block -s '.$Row['IP'].' -j Local'); 18 18 } 19 19 } … … 24 24 while($Row = $DbResult2->fetch_array()) 25 25 { 26 exec(' iptables -t nat -A Block -s '.$Row['IP'].' -j Local');26 exec('/sbin/iptables -t nat -A Block -s '.$Row['IP'].' -j Local'); 27 27 } 28 28 } … … 39 39 if($User['inet'] == 0) 40 40 { 41 if(($Row['block'] == 0) and ($Row['type'] == 1)) exec(' iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Proxy");42 else exec(' iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Local");41 if(($Row['block'] == 0) and ($Row['type'] == 1)) exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Proxy"); 42 else exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Local"); 43 43 } else { 44 44 if($Row['vpn'] == 0) … … 48 48 if($Row['name'] == 'TBC') 49 49 { 50 exec(' iptables -t nat -A PreroutingDNAT -m tcp -p tcp --dport 3724 -d '.$Row['external_ip'].' -j DNAT --to-destination '.$Row['IP'].':3725');51 exec(' iptables -t nat -A POSTROUTING -m tcp -p tcp -s '.$Row['IP'].' --sport 3725 -o eth1 -j SNAT --to-source '.$Row['external_ip'].':3724');50 exec('/sbin/iptables -t nat -A PreroutingDNAT -m tcp -p tcp --dport 3724 -d '.$Row['external_ip'].' -j DNAT --to-destination '.$Row['IP'].':3725'); 51 exec('/sbin/iptables -t nat -A POSTROUTING -m tcp -p tcp -s '.$Row['IP'].' --sport 3725 -o eth1 -j SNAT --to-source '.$Row['external_ip'].':3724'); 52 52 } 53 53 if(strtolower($Row['name']) != 'centrala') … … 55 55 if($Row['external_ip'] != '') 56 56 { 57 exec(' iptables -t nat -A PreroutingDNAT -i eth1 -d '.$Row['external_ip'].' -j DNAT --to-destination '.$Row['IP']);58 exec(' iptables -t nat -A PreroutingDNAT -i eth1 -d '.$Row['external_ip'].' -j ACCEPT');59 exec(' iptables -t nat -A POSTROUTING -s '.$Row['IP'].' -o eth1 -j SNAT --to-source '.$Row['external_ip']);57 exec('/sbin/iptables -t nat -A PreroutingDNAT -i eth1 -d '.$Row['external_ip'].' -j DNAT --to-destination '.$Row['IP']); 58 exec('/sbin/iptables -t nat -A PreroutingDNAT -i eth1 -d '.$Row['external_ip'].' -j ACCEPT'); 59 exec('/sbin/iptables -t nat -A POSTROUTING -s '.$Row['IP'].' -o eth1 -j SNAT --to-source '.$Row['external_ip']); 60 60 } 61 exec(' iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Proxy");61 exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Proxy"); 62 62 } 63 63 } … … 66 66 $CZFreeLocalIP = $Row['external_ip']; 67 67 //echo('vpn'); 68 //exec(' iptables -t nat -A PreroutingDNAT -s '.$Row['IP'].' -p udp -m udp --dport 55556 -j DROP');69 if($Row['external_ip'] != '') exec(' iptables -t nat -A PreroutingDNAT -d '.$Row['external_ip'].' -j ACCEPT');70 exec(' iptables -t nat -A Block -s '.ToVpnIp($Row)." -j Proxy");68 //exec('/sbin/iptables -t nat -A PreroutingDNAT -s '.$Row['IP'].' -p udp -m udp --dport 55556 -j DROP'); 69 if($Row['external_ip'] != '') exec('/sbin/iptables -t nat -A PreroutingDNAT -d '.$Row['external_ip'].' -j ACCEPT'); 70 exec('/sbin/iptables -t nat -A Block -s '.ToVpnIp($Row)." -j Proxy"); 71 71 72 72 if($Row['vpn'] == 1) 73 73 { 74 exec(' iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Local");75 } else if($Row['vpn'] == 2) exec(' iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Proxy");74 exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Local"); 75 } else if($Row['vpn'] == 2) exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Proxy"); 76 76 } 77 77 if($Row['czfree_ip'] != '') 78 78 { 79 79 // CZFree 80 exec(' iptables -t nat -A PreroutingDNAT -i tun0 -d '.$Row['czfree_ip'].' -j DNAT --to-destination '.$CZFreeLocalIP);81 exec(' iptables -t nat -A PreroutingDNAT -i tun0 -d '.$Row['czfree_ip'].' -j ACCEPT');82 exec(' iptables -t nat -A POSTROUTING -s '.$CZFreeLocalIP.' -o tun0 -j SNAT --to-source '.$Row['czfree_ip']);80 exec('/sbin/iptables -t nat -A PreroutingDNAT -i tun0 -d '.$Row['czfree_ip'].' -j DNAT --to-destination '.$CZFreeLocalIP); 81 exec('/sbin/iptables -t nat -A PreroutingDNAT -i tun0 -d '.$Row['czfree_ip'].' -j ACCEPT'); 82 exec('/sbin/iptables -t nat -A POSTROUTING -s '.$CZFreeLocalIP.' -o tun0 -j SNAT --to-source '.$Row['czfree_ip']); 83 83 } 84 84 } … … 90 90 $DbResult = $Database->select('hosts', '*', 'name="MAIL"'); 91 91 $Row = $DbResult->fetch_array(); 92 exec(' iptables -t nat -A PreroutingDNAT -p tcp -m tcp --dport 25 -d 212.111.4.174 -j DROP');93 exec(' iptables -t nat -A PreroutingDNAT -p tcp -m tcp --dport 25 -d '.$Row['external_ip'].' -j DNAT --to-destination '.$Row['IP']);94 exec(' iptables -t nat -A PreroutingDNAT -p tcp -m tcp --dport 25 -d '.$Row['external_ip'].' -j ACCEPT');95 exec(' iptables -t nat -A POSTROUTING -p tcp -m tcp --dport 25 -s 212.111.4.174 -o eth1 -j SNAT --to-source '.$Row['external_ip']);92 exec('/sbin/iptables -t nat -A PreroutingDNAT -p tcp -m tcp --dport 25 -d 212.111.4.174 -j DROP'); 93 exec('/sbin/iptables -t nat -A PreroutingDNAT -p tcp -m tcp --dport 25 -d '.$Row['external_ip'].' -j DNAT --to-destination '.$Row['IP']); 94 exec('/sbin/iptables -t nat -A PreroutingDNAT -p tcp -m tcp --dport 25 -d '.$Row['external_ip'].' -j ACCEPT'); 95 exec('/sbin/iptables -t nat -A POSTROUTING -p tcp -m tcp --dport 25 -s 212.111.4.174 -o eth1 -j SNAT --to-source '.$Row['external_ip']); 96 96 97 97 // Local network NAT 98 98 $DbResult = $Database->select('hosts', '*', 'name="GATE"'); 99 99 $Row = $DbResult->fetch_array(); 100 exec(' iptables -t nat -A POSTROUTING -s 192.168.0.0/255.255.0.0 -o eth1 -j SNAT --to-source '.$Row['external_ip']);101 //exec(' iptables -t nat -A POSTROUTING -s 10.0.0.0/255.0.0.0 -o eth1 -j SNAT --to-source '.$Row['external_ip']);102 //exec(' iptables -t nat -A POSTROUTING -s 212.111.16.94 -o eth1 -j MASQUERADE');100 exec('/sbin/iptables -t nat -A POSTROUTING -s 192.168.0.0/255.255.0.0 -o eth1 -j SNAT --to-source '.$Row['external_ip']); 101 //exec('/sbin/iptables -t nat -A POSTROUTING -s 10.0.0.0/255.0.0.0 -o eth1 -j SNAT --to-source '.$Row['external_ip']); 102 //exec('/sbin/iptables -t nat -A POSTROUTING -s 212.111.16.94 -o eth1 -j MASQUERADE'); 103 103 104 104 exec('/sbin/iptables-save>/etc/sysconfig/iptables');
Note:
See TracChangeset
for help on using the changeset viewer.