update miniupnpd to 20070112
[openwrt/svn-archive/archive.git] / net / miniupnpd / files / miniupnpd.init
index 4dd2df056199ca05d122e17546386bbb87794449..446a37cecbff775f069b12f072334a893fdd9006 100644 (file)
@@ -1,17 +1,36 @@
-#!/bin/sh
-upnpd_enabled=$(nvram get upnp_enabled)
-if [ "$upnpd_enabled" = "1" ]; then
+#!/bin/sh /etc/rc.common
+START=95
+start() {
+       config_load "upnpd"
+       include /lib/network
+       scan_interfaces
+       config_get ifname wan ifname
+       config_get ipaddr lan ipaddr
+       
        echo "miniupnpd starting ..."
-       iptables_flush.sh 2>&- >&-
-       killall miniupnpd 2>&-
-       iptables_removeall.sh 2>&- >&-
+       stop
        iptables_init.sh
-       upnpd_log=$(nvram get upnpd_log_output)
-       if [ "$upnpd_log" = "1" ]; then
-               miniupnpd -i $(nvram get wan_ifname) -a $(nvram get lan_ipaddr) -p 5000 -U -d | logger -t miniupnpd &
+       # get bitspeed information, if provided
+       config_get upnp_up_bitspeed config upload
+       config_get upnp_down_bitspeed config download
+       bitspeed_str=""
+       [ -n "$upnpd_up_bitspeed" ] && [ -n "$upnpd_down_bitspeed" ] && {
+               # covert to bytespeed
+               upnpd_up_bytespeed=$(($upnpd_up_bitspeed * 1024 / 8))
+               upnpd_down_bytespeed=$(($upnpd_down_bitspeed * 1024 / 8))
+               bitspeed_str="-B $upnpd_down_bytespeed $upnpd_up_bytespeed"
+       }
+       config_get log_output config log_output
+       if [ "$log_output" = "1" ]; then
+               miniupnpd -i "$ifname" -a "$ipaddr" -p 5000 -U $bitspeed_str -d | logger -t miniupnpd &
        else
-               miniupnpd -i $(nvram get wan_ifname) -a $(nvram get lan_ipaddr) -p 5000 -U
+               miniupnpd -i "$ifname" -a "$ipaddr" -p 5000 -U $bitspeed_str
        fi
-else
-       echo "miniupnpd service is disabled. Set nvram upnp_enabled to '1' to enable."
-fi
+}
+
+stop() {
+       pnpd_pid=$(cat /var/run/miniupnpd.pid) 2>&- >&-
+       iptables_flush.sh 2>&- >&-
+       kill $pnpd_pid 2>&-
+       iptables_removeall.sh 2>&- >&-
+}