82ea652c745a5f68b33dda43bddd7fa883ebf9bf
[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 natpmp
10 local extip port usesysuptime conffile
11
12 config_get extiface config external_iface
13 config_get intiface config internal_iface
14 config_get extip config external_ip
15 config_get port config port 5000
16 config_get upload config upload
17 config_get download config download
18 config_get_bool logging config log_output 0
19 config_get_bool secure config secure_mode 0
20 config_get_bool natpmp config enable_natpmp 0
21 config_get_bool enabled config enabled 0
22 config_get_bool usesysuptime config use_system_uptime 1
23 config_get conffile config config_file
24
25 include /lib/network
26 scan_interfaces
27
28 local ifname
29 config_get ifname ${extiface:-wan} ifname
30
31 if [ -n "$ifname" ]; then
32 local args="-i $ifname"
33 local iface
34
35 [ -n "$extip" ] && \
36 append args "-o $extip"
37
38 for iface in ${intiface:-lan}; do
39 local ipaddr
40 config_get ipaddr "$iface" ipaddr
41 [ -n "$ipaddr" ] && append args "-a $ipaddr"
42 done
43
44 [ "$port" != "auto" ] && \
45 append args "-p $port"
46
47 [ "$usesysuptime" -eq 1 ] && \
48 append args "-U"
49
50 [ -n "$upload" -a -n "$download" ] && \
51 append args "-B $(($download * 1024 * 8)) $(($upload * 1024 * 8))"
52
53 [ "$secure" -gt 0 ] && \
54 append args "-S"
55
56 [ "$natpmp" -gt 0 ] && \
57 append args "-N"
58
59 [ -n "$conffile" ] && \
60 append args "-f $conffile"
61
62 # start firewall
63 local zone
64 config_load firewall
65 config_get zone core "${extiface:-wan}_zone"
66 [ -n "$zone" ] && \
67 miniupnpd_add_rules "$zone" "${extiface:-wan}" "$ifname"
68
69 if [ "$logging" = "1" ]; then
70 [ "$enabled" -gt 0 ] && eval start-stop-daemon -S -x miniupnpd -- $args -d | logger -t miniupnpd &
71 else
72 [ "$enabled" -gt 0 ] && eval start-stop-daemon -S -x miniupnpd -- $args 2>/dev/null
73 fi
74 else
75 logger -t "upnp daemon" "external interface not found, not starting"
76 fi
77 }
78
79 stop() {
80 start-stop-daemon -K -q -x miniupnpd -p /var/run/miniupnpd.pid
81 rm -f /var/run/miniupnpd.pid
82
83 type miniupnpd_remove_rules >/dev/null 2>/dev/null || \
84 ACTION=- . /etc/hotplug.d/firewall/50-miniupnpd
85
86 miniupnpd_remove_rules
87
88 iptables -t nat -F MINIUPNPD 2>/dev/null
89 iptables -t nat -X MINIUPNPD 2>/dev/null
90 iptables -t filter -F MINIUPNPD 2>/dev/null
91 iptables -t filter -X MINIUPNPD 2>/dev/null
92 }