IFS=$OLDIFS;
if [[ -e $RULES ]]; then
# {(!)in|(!)out|(!)fwd},iface,proto,scidr,sport,dcidr,dport,state
while IFS=, read policy iface proto scidr sport dcidr dport state;do
c="0";
case $policy in
!in) pol="INPUT -i"; jmp="DROP"; ;;
!out) pol="OUTPUT -o"; jmp="DROP"; ;;
!fwd) pol="FORWARD -i"; jmp="DROP"; ;;
in) pol="INPUT -i"; jmp="ACCEPT"; ;;
out) pol="OUTPUT -o"; jmp="ACCEPT"; ;;
fwd) pol="FORWARD -i"; jmp="ACCEPT"; ;;
*) c="1"; ;;
esac
case $state in
i) state="-m state --state $I"; ;;
n) state="-m state --state $N"; ;;
e) state="-m state --state $E"; ;;
r) state="-m state --state $R"; ;;
ne) state="-m state --state $N,$E"; ;;
nr) state="-m state --state $N,$R"; ;;
er) state="-m state --state $E,$R"; ;;
ner) state="-m state --state $N,$E,$R"; ;;
*) state=""; ;;
esac
if [[ ! $iface = "" ]];then rules=("$iface"); fi
if [[ ! $proto = "" ]];then rules=(${rules[@]} " -p $proto"); fi
if [[ ! $scidr = "" ]];then rules=(${rules[@]} " -s $scidr"); fi
if [[ ! $sport = "" ]];then rules=(${rules[@]} " --sport $sport"); fi
if [[ ! $dcidr = "" ]];then rules=(${rules[@]} " -d $dcidr"); fi
if [[ ! $dport = "" ]];then rules=(${rules[@]} " --dport $dport"); fi
if [[ ! $state = "" ]];then rules=(${rules[@]} " $stat"); fi
if [[ $c = 0 ]];then
if [ $d ];then echo "Rules Array:"; printArray "'${rules[@]}'"; fi
for i in ${rules[@]};do req="${req}${i}"; done²
if [ $d ];then echo -e "Iptables Query:\n'$BIN -A $pol $req -j $jmp'"; fi
$BIN -A $pol $req -j $jmp;
fi
unset pol req jmp
done < $RULES
writeDebug "init RULES=1";
else
if [[ $v ]];then echo "$RULES not found, this mean you should setup $BIN yourself. See man $BIN."; fi
writeDebug "init RULES=0";
fi