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