From 420bcb986a4994d67cc7c1170b216aeadb88876a Mon Sep 17 00:00:00 2001
From: Jonas Smedegaard <dr@jones.dk>
Date: Wed, 26 Jun 2002 18:19:17 +0000
Subject: ipmasq: Add files for portforwarding.

---
 ipmasq/rules/A80precompute_pfw.def | 56 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 ipmasq/rules/A80precompute_pfw.def

(limited to 'ipmasq/rules/A80precompute_pfw.def')

diff --git a/ipmasq/rules/A80precompute_pfw.def b/ipmasq/rules/A80precompute_pfw.def
new file mode 100644
index 0000000..491da60
--- /dev/null
+++ b/ipmasq/rules/A80precompute_pfw.def
@@ -0,0 +1,56 @@
+# You should not edit this file.  Instead, create a file with the same
+# name as this one, but with a .rul extension instead of .def.  The
+# .rul file will override this one.
+#
+# However, any changes you make to this file will be preserved.
+
+# Some reused regex'es
+re_protos='[a-z\,]\+'
+re_ports='[a-z0-9\,:]\+'
+re_port='[a-z0-9:]\+'
+re_host='[a-z0-9]\+'
+re_pool='[a-z0-9_]\+'
+re_cfg="[[:space:]]*\($re_protos\)[[:space:]]\+\($re_ports\)[[:space:]]\+\($re_host\)\([[:space:]]\+\($re_port\)\)\?[[:space:]]*"
+re_cfgline="portfw_pool_\($re_pool\)[[:space:]]*=[[:space:]]*'$re_cfg'"
+
+# Extract portforward hosts
+PFW=$(set | grep '^portfw_ip_' | sed "s/^portfw_ip_\($re_host\).*/\1/")
+
+# remove hosts with no pools attached
+if [ -n "$PFW" ]; then
+    for i in $PFW; do
+	poolhits=$(set | grep '^portfw_pool_' | sed "s/$re_cfgline/\4/" | grep "^$i$")
+	if [ -z "$poolhits" ]; then
+	    PFW=$(echo $PFW | sed "s/\(  *\|^\)$i\(  *\|$\)/\1/")
+	fi
+    done
+fi
+
+# Extract ips and ports
+if [ -n "$PFW" ]; then
+    if [ "$SHOWRULES" = "yes" ]; then
+	echo "#: These ports are forwarded:"
+    fi
+    PFWPOOLS=""
+    for i in $PFW; do
+	eval "ip=\"\$portfw_ip_$i\""
+	pools=$(set | grep '^portfw_pool_' | sed "s/$re_cfgline/\1:\4/" | grep ":$i$" | sed "s/:$i$//")
+	for pool in $pools; do
+	    PFWPOOLS="$PFWPOOLS $pool"
+	    eval "config=\"\$portfw_pool_$pool\""
+	    protos_bulk=$(echo $config | sed "s/$re_cfg/\1/")
+	    protos=$(echo $protos_bulk | sed 's/,/ /g')
+	    origports_bulk=$(echo $config | sed "s/$re_cfg/\2/")
+	    origports=$(echo $origports_bulk | sed 's/,/ /g')
+	    destport=$(echo $config | sed "s/$re_cfg/\5/")
+	    [ "$origports" = "$destport" ] && destport=""
+	    eval "PFWPROTO_$pool=\"\$protos\""
+	    eval "PFWORIGPORTS_$pool=\"$origports\""
+	    eval "PFWIP_$pool=\"$ip\""
+	    eval "PFWPORT_$pool=\"$destport\""
+	    if [ "$SHOWRULES" = "yes" ]; then
+        	echo -e "#:   $protos_bulk \t$origports_bulk \t->\t $ip $destport \t($pool->$i)"
+	    fi
+	done
+    done
+fi
-- 
cgit v1.2.3

