* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ function ReplaceRule($type,$table,$chain,$id,$lang) { $id++; echo "
" ."" ."" ."" ."" .""; if ($type=="replace") { echo ""; } $ifaces=GetInterfaces(); sort($ifaces); if ($chain=="INPUT" or $chain=="PREROUTING") { // interface selectbox (in) echo ""; } elseif ($chain=="OUTPUT" or $chain=="POSTROUTING") { // interface selectbox (out) echo ""; } else { // interface selectbox (in) echo ""; // interface selectbox (out) echo ""; } // exit; $protocols=GetProtocols(); echo "" ."" ."" ."" ."" ."" ."" ."
".strtoupper($lang["chruleheader"])."
".$lang["table"].":$table
".$lang["chain"].":$chain
".$lang["ruletypedesc"].":".$lang["$type"]."
".$lang["position"].":$id
".$lang["ifacein"].":" ."
".$lang["ifaceout"].":" ."
".$lang["ifacein"].":" ."
".$lang["ifaceout"].":" ."
".$lang["protocol"].":" .""; echo "
" ."
"; } function ReplaceRule2($type,$table,$chain,$max,$ifacein,$ifaceout,$position,$protocol,$modules,$lang) { if ($type=="insert") $positiondesc="(".$lang["position"]." $position)"; else $positiondesc=""; echo "
" ."" ."" ."" ."" .""; // interface (in) if (isset($ifacein)) { if ($ifacein=="any") $ifacedesc=$lang["any"]; else $ifacedesc=$ifacein; echo ""; echo ""; } // interface (out) if (isset($ifaceout)) { if ($ifaceout=="any") $ifacedesc=$lang["any"]; else $ifacedesc=$ifaceout; echo ""; echo ""; } // protocol if ($protocol=="all") $protodesc=$lang["all"]; else $protodesc=$protocol; echo ""; echo ""; // modules echo ""; echo ""; if ($protocol!="all") { echo ""; echo ""; } echo ""; echo ""; echo ""; echo ""; echo ""; echo "
".strtoupper($lang["chruleheader"])."
".$lang["table"].":$table
".$lang["chain"].":$chain
".$lang["ruletypedesc"].":".$lang["$type"]." $positiondesc
".$lang["ifacein"].":$ifacedesc
".$lang["ifaceout"].":$ifacedesc
".$lang["protocol"].":$protodesc
".$lang["selmodules"]."
".$lang["modules"].":"; $i=-1; foreach ($modules["$protocol"] as $idx => $modulename) { if ($i % 3 == 0 and $i < count($modules["$protocol"]) and $i != 0) echo "
"; if ($modulename!=$protocol) echo " $modulename "; $i++; } echo "
".$lang["modulepre"]."$protocol
"; } function ReplaceRule3($type,$table,$chain,$ifacein,$ifaceout,$position,$protocol,$modules,$selmodules,$targets,$lang,$ipt) { if ($type=="replace") $positiondesc="(".$lang["position"]." $position)"; else $positiondesc=""; echo "" ."" ."" ."" ."" .""; // interface (in) if (isset($ifacein)) { if ($ifacein=="any") $ifacedesc=$lang["any"]; else $ifacedesc=$ifacein; echo ""; echo ""; } // interface (out) if (isset($ifaceout)) { if ($ifaceout=="any") $ifacedesc=$lang["any"]; else $ifacedesc=$ifaceout; echo ""; echo ""; } // protocol if ($protocol=="all") $protodesc=$lang["all"]; else $protodesc=$protocol; echo ""; echo ""; include "modules/all.inc.php"; if ($protocol=="tcp") include "modules/tcp.inc.php"; if ($protocol=="udp") include "modules/udp.inc.php"; if ($protocol=="icmp") include "modules/icmp.inc.php"; if (count($selmodules) > 0) foreach ($selmodules as $idx => $modulename) include "modules/$modulename.inc.php"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
".strtoupper($lang["chruleheader"])."
".$lang["table"].":$table
".$lang["chain"].":$chain
".$lang["ruletypedesc"].":".$lang["$type"]." $positiondesc
".$lang["ifacein"].":$ifacedesc
".$lang["ifaceout"].":$ifacedesc
".$lang["protocol"].":$protodesc
"; } function ReplaceRule4($type,$table,$chain,$ifacein,$ifaceout,$position,$protocol,$moduleoption,$lang,$iptables,$target,$rejectwith,$logprefix,$toports,$dnat,$snat,$tos,$mark,$dscp,$dscpclass) { $cmd="$iptables -t $table "; $cmd.="-R $chain $position "; if ($protocol!="all") $cmd.="-p $protocol "; //$cmd.="-p $protocol -m $protocol "; if (isset($ifacein) and $ifacein!="any") $cmd.="-i $ifacein "; if (isset($ifaceout) and $ifaceout!="any") $cmd.="-o $ifaceout "; if (isset($moduleoption["all"]) and count($moduleoption["all"] > 0)) { foreach ($moduleoption["all"] as $option => $value) { if ($value!="") $cmd.="$option $value "; } } foreach ($moduleoption as $modulename => $desc) { if ($modulename!="all" and $modulename!="target") { $cmd.="-m $modulename "; if ($modulename=="unclean") continue; foreach ($moduleoption["$modulename"] as $option => $value) { if ($option=="--uid-owner" and substr($value,0,1)=="!") { $cmd.="! $option ".substr($value,1,strlen($value)-1)." "; continue; } if ($option=="--gid-owner" and substr($value,0,1)=="!") { $cmd.="! $option ".substr($value,1,strlen($value)-1)." "; continue; } if ($option=="--string") { $cmd.="$option \"$value\" "; continue; } if ($option=="--comment") { $cmd.="$option \"$value\" "; continue; } if ($value!="") $cmd.="$option $value "; } } } // target/jump if ($target!="") $cmd.="-j $target "; switch($target) { case "REJECT" : $cmd.="--reject-with $rejectwith "; break; case "LOG" : $cmd.="--log-prefix \"$logprefix\" "; break; case "REDIRECT" : $cmd.="--to-ports $toports "; break; case "SNAT" : $cmd.="--to-source $snat "; break; case "DNAT" : $cmd.="--to-destination $dnat "; break; case "TOS" : $cmd.="--set-tos $tos "; break; case "MARK" : $cmd.="--set-mark $mark "; break; case "DSCP" : if ($dscp!="") $cmd.="--set-dscp $dscp "; if ($dscpclass!="") $cmd.="--set-dscp-class $dscpclass" ; break; } $file="/tmp/firewalladmin-".rand(); echo exec("sudo $cmd &> $file",$output,$return); echo "" .""; if ($return==0) { echo ""; echo ""; } else { echo ""; echo ""; } echo ""; echo ""; echo "
".$lang["chruleheader"]."
".$lang["success"]."
".$lang["command"].":
$cmd
".$lang["failure"]."
$cmd
".cmderror($file,$lang)."
"; } ?>