#! /bin/sh #------------------------------------------------------------------------------ # pf.cgi - show the firewall config # # Creation: 05.08.2005 jw5 # Last Update: $Id$ # #------------------------------------------------------------------------------ # Functions dump_rules () { rules="$1" f="echo \"Table filter\"; iptables --line-numbers -nvL" n="echo \"Table nat\"; iptables --line-numbers -t nat -nvL" r="echo \"Table raw\"; iptables --line-numbers -t raw -nvL" case $rules in INPUT | FORWARD | OUTPUT) eval $f $1 ;; PORTFW) eval $n PORTFW ;; all) eval $f eval $n eval $r ;; *[,:]*) for p in `echo $rules | sed -e 's/,/ /g'` do set `echo $p | sed -e 's/:/ /g'` case $# in 1) eval $f $1 ;; 2) echo "Table $1" iptables --line-numbers -t $1 -nvL $2 ;; esac done ;; *) eval $f INPUT eval $f FORWARD eval $f OUTPUT eval $n POSTROUTING ;; esac } format_output () { while read line do case "$line" in '') ;; Table*) table=$(echo "$line" | sed 's/^Table[[:space:]]*//') ;; Chain*) case $head in yes) echo '' show_tab_footer ;; esac show_tab_header "$line [$table]" no echo '
/;s/[[:space:]]\+/<\/th> | /g' echo " | additional restrictions | " #config source | comment | " ;; *) set -f set -- $line def=`echo "$1 $2 $3 $4 $5 $6 $7 $8 $9 ${10}" | sed -e 's/^//;s/[[:space:]]\+/<\/td> | /g;s/$/<\/td>/;s# | \(all\|[*]\|--\|0\.\0\.\0\.0/0\) | #\ | #g'` target=$4 shift 10 restr=`echo "$* | " | sed -e 's,/[*].*[*]/,,;s## | \ | #g'` if echo "$*" | grep -q '/\*.*\*/'; then comment="`echo "$*" | sed -e 's#.*/\*\(.*\)\*/[^*/]*#\1#'`" else comment="" fi echo "
---|---|---|---|
$comment |
" dump_rules $FORM_action echo "" ;; *) dump_rules $FORM_action | format_output ;; esac show_tab_footer show_html_footer