#!/usr/bin/webif-page >|max=10|$FORM_submit EOF if [ "$?" != "0" ] then FORM_submit="" fi NOTICE="@TR<>" Repeated="0" if [ ! -e /tmp/frules ] then touch /tmp/frules fi if [ "$FORM_submit" != "" ] then validate <>|required|$FORM_srule EOF if [ "$?" != "0" ] then NOTICE="@TR<>" else if [ "$FORM_srule" == "add" ] then validate <>|required|$FORM_origp port|FORM_origpr|@TR<>||$FORM_origpr ip|FORM_destip|@TR<>|required|$FORM_destip port|FORM_destp|@TR<>|required|$FORM_destp port|FORM_destpr|@TR<>||$FORM_destpr tcp_udp|FORM_sproto|@TR<>||$FORM_sproto EOF if [ "$?" != "0" ] then NOTICE="@TR<>" else cat /tmp/frules | grep "^open_port \$1 $FORM_origp" > /tmp/repeated for x in `cat /tmp/repeated` do echo $x >> /tmp/repeated if [ "$FORM_sproto" == "both" ] then Repeated="1" elif [ "$x" == "$FORM_sproto" ] then Repeated="1" fi done rm /tmp/repeated if [ "$Repeated" == "1" ] then NOTICE="@TR<>" else if [ "$FORM_origpr" != "" ] then if [ $FORM_origpr -lt $FORM_origp ] then DONTOPEN="1" NOTICE="@TR<>" else FORM_origp=`echo "$FORM_origp":"$FORM_origpr"` fi fi if [ "$FORM_destpr" != "" ] then if [ $FORM_destpr -lt $FORM_destp ] then DONTOPEN="1" NOTICE="@TR<>" else FORM_destp=`echo "$FORM_destp"-"$FORM_destpr"` fi fi if [ "$DONTOPEN" != "1" ] then if [ "$FORM_sproto" == "both" ] then echo "open_port \$1" "$FORM_origp" "$FORM_destip" "$FORM_destp" "udp" >> /etc/config/openports echo "open_port \$1" "$FORM_origp" "$FORM_destip" "$FORM_destp" "tcp" >> /etc/config/openports /etc/init.d/S45firewall else echo "open_port \$1" "$FORM_origp" "$FORM_destip" "$FORM_destp" "$FORM_sproto" >> /etc/config/openports /etc/init.d/S45firewall fi fi fi fi else validate <>|min=0|$FORM_sruledel EOF if [ "$?" != "0" -o -z "$FORM_sruledel" ] then NOTICE="@TR<>" else nentries=`wc -l /tmp/frules | cut -d" " -f7` if [ $FORM_sruledel -gt $nentries ] then NOTICE="@TR<>" else DELLINE=`head -n $FORM_sruledel /tmp/frules | tail -n 1` cat /etc/config/openports | grep -v "$DELLINE" > /etc/config/openports /etc/init.d/S45firewall fi fi fi fi fi FORM_origp="" FORM_origpr="" FORM_destip="" FORM_destp="" FORM_destpr="" FORM_sproto="" ncell="add_normal_cell|" optrull="option" id=1 echo "" > /tmp/pftable echo "" > /tmp/optrules cat /etc/config/openports | grep -v "^#" | grep open_port > /tmp/frules max=`cat /tmp/frules | sed -n '$='` if [ "$max" == "" ] then max=0 fi for i in `seq $max` do x=`head -n $i /tmp/frules | tail -n 1` oport=`echo $x | cut -d" " -f3` dip=`echo $x | cut -d" " -f4` dport=`echo $x | cut -d" " -f5` proto=`echo $x | cut -d" " -f6` if [ "$proto" = "" ] then proto="tcp/udp" fi # New rows of the tabprivate echo "add_row" >> /tmp/pftable echo " $ncell$i" >> /tmp/pftable echo " $ncell$oport" >>/tmp/pftable echo " $ncell$dip" >> /tmp/pftable echo " $ncell$dport" >> /tmp/pftable echo " $ncell$proto" >> /tmp/pftable echo "end_row" >> /tmp/pftable # New option for delete rules echo "option|$i|$i" >> /tmp/optrules done TABLE="$(cat /tmp/pftable)" OPTRULES="$(cat /tmp/optrules)" header "PF_Title#Port Forwarding" cat < EOF display_form <> start_select_cell|srule|$FORM_srule|tableTextSelect|modechange option|add|@TR<> option|remove|@TR<> end_select_cell end_row end_table start_div|fill_rule_stuff end_div start_div|add_rule_stuff start_table|0|10|5 add_row add_label_cell|@TR<> add_input_cell|destip|$FORM_destip|inputIP end_row end_table start_table|0|10|5 add_row add_label_cell|@TR<> add_input_cell|origp|$FORM_origp|inputPort add_input_cell|origpr|$FORM_origpr|inputPort add_checkbox_cell|checkR1|@TR<>  |tableCheckBox|showrange1 end_row add_row add_label_cell|@TR<> add_input_cell|destp|$FORM_destp|inputPort add_input_cell|destpr|$FORM_destpr|inputPort add_checkbox_cell|checkR2|@TR<>  |tableCheckBox|showrange2 end_row end_table start_table|0|10|5 add_row onchange|onchange add_label_cell|@TR<> start_select_cell|sproto|$FORM_sproto|tableTextSelect option|both|@TR<> option|tcp|TCP option|udp|UDP end_select_cell end_row add_row add_label_cell add_button_cell|submit|@TR<> end_row end_table end_div start_div|rem_rule_stuff start_table|0|10|5 add_row add_label_cell|@TR<