pwrtray: Add support for FB blanking
[openwrt/svn-archive/archive.git] / net / miniupnpd / files / miniupnpd.init
1 #!/bin/sh /etc/rc.common
2 START=95
3
4 start() {
5 type miniupnpd_add_rules >/dev/null 2>/dev/null || \
6 ACTION=- . /etc/hotplug.d/firewall/50-miniupnpd
7
8 config_load "upnpd"
9 local extiface intiface upload download logging secure enabled
10
11 config_get extiface config external_iface
12 config_get intiface config internal_iface
13 config_get upload config upload
14 config_get download config download
15 config_get_bool logging config log_output 0
16 config_get_bool secure config secure_mode 0
17 config_get_bool enabled config enabled 0
18
19 include /lib/network
20 scan_interfaces
21
22 local ifname
23 config_get ifname ${extiface:-wan} ifname
24
25 if [ -n "$ifname" ]; then
26 local args="-i $ifname"
27 local iface
28
29 for iface in ${intiface:-lan}; do
30 local ipaddr
31 config_get ipaddr "$iface" ipaddr
32 [ -n "$ipaddr" ] && append args "-a $ipaddr"
33 done
34
35 append args "-p 5000 -U"
36
37 [ -n "$upload" -a -n "$download" ] && \
38 append args "-B $(($download * 1024 * 8)) $(($upload * 1024 * 8))"
39
40 [ "$secure" -gt 0 ] && \
41 append args "-S"
42
43 if [ "$logging" = "1" ]; then
44 [ "$enabled" -gt 0 ] && eval start-stop-daemon -S -x miniupnpd -- $args -d | logger -t miniupnpd &
45 else
46 [ "$enabled" -gt 0 ] && eval start-stop-daemon -S -x miniupnpd -- $args 2>/dev/null
47 fi
48
49 # start firewall
50 local zone
51 config_load firewall
52 config_get zone core "${extiface:-wan}_zone"
53 [ -n "$zone" ] && \
54 miniupnpd_add_rules "$zone" "${extiface:-wan}" "$ifname"
55 else
56 logger -t "upnp daemon" "external interface not found, not starting"
57 fi
58 }
59
60 stop() {
61 start-stop-daemon -K -q -x miniupnpd -p /var/run/miniupnpd.pid
62 rm -f /var/run/miniupnpd.pid
63
64 type miniupnpd_remove_rules >/dev/null 2>/dev/null || \
65 ACTION=- . /etc/hotplug.d/firewall/50-miniupnpd
66
67 miniupnpd_remove_rules
68
69 iptables -t nat -F MINIUPNPD 2>/dev/null
70 iptables -t nat -X MINIUPNPD 2>/dev/null
71 iptables -t filter -F MINIUPNPD 2>/dev/null
72 iptables -t filter -X MINIUPNPD 2>/dev/null
73 }