[net] miniupnpd: Added uci option notify_interval and presentation_url
[packages.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 serial_number model_number
11         local uuid notify_interval presentation_url
12
13         config_get extiface config external_iface
14         config_get intiface config internal_iface
15         config_get extip config external_ip
16         config_get port config port 5000
17         config_get upload   config upload
18         config_get download config download
19         config_get_bool logging config log_output 0
20         config_get_bool secure config secure_mode 0
21         config_get_bool natpmp config enable_natpmp 0
22         config_get_bool enabled config enabled 0 
23         config_get_bool usesysuptime config use_system_uptime 1
24         config_get conffile config config_file
25         config_get serial_number config serial_number
26         config_get model_number config model_number
27         config_get uuid config uuid
28         config_get notify_interval config notify_interval
29         config_get presentation_url config presentation_url
30
31         include /lib/network
32         scan_interfaces
33
34         local ifname
35         config_get ifname ${extiface:-wan} ifname
36
37         if [ -n "$ifname" ]; then
38                 local args="-i $ifname"
39                 local iface
40
41                 [ -n "$extip" ] && \
42                         append args "-o $extip"
43                 
44                 for iface in ${intiface:-lan}; do
45                         local ipaddr
46                         config_get ipaddr "$iface" ipaddr
47                         [ -n "$ipaddr" ] && append args "-a $ipaddr"
48                 done
49
50                 [ "$port" != "auto" ] && \
51                         append args "-p $port"
52                 
53                 [ "$usesysuptime" -eq 1 ] && \
54                         append args "-U"
55
56                 [ -n "$upload" -a -n "$download" ] && \
57                         append args "-B $(($download * 1024 * 8)) $(($upload * 1024 * 8))"
58
59                 [ "$secure" -gt 0 ] && \
60                         append args "-S"
61
62                 [ "$natpmp" -gt 0 ] && \
63                         append args "-N"
64
65                 [ -n "$conffile" ] && \
66                         append args "-f $conffile"
67
68                 [ -n "${serial_number}" ] && \
69                         append args "-s ${serial_number}"
70                 
71                 [ -n "${model_number}" ] && \
72                         append args "-m ${model_number}"
73                         
74                 [ -z "$uuid" ] && {
75                         uuid="$(cat /proc/sys/kernel/random/uuid)"
76                         uci set upnpd.config.uuid=$uuid
77                         uci commit upnpd
78                 }
79
80                 [ "$uuid" = "nocli" ] || \
81                         append args "-u $uuid"
82                 
83                 [ -n "${notify_interval}" ] && \
84                         append args "-t ${notify_interval}"
85                         
86                 [ -n "${presentation_url}" ] && \
87                         append args "-w \"${presentation_url}\""                        
88                 # start firewall
89                 local zone
90                 config_load firewall
91                 config_get zone core "${extiface:-wan}_zone"
92                 [ -n "$zone" ] && \
93                         miniupnpd_add_rules "$zone" "${extiface:-wan}" "$ifname"
94
95                 if [ "$logging" = "1" ]; then
96                         [ "$enabled" -gt 0 ] && eval start-stop-daemon -S -x miniupnpd -- $args -d | logger -t miniupnpd &
97                 else
98                         [ "$enabled" -gt 0 ] && eval start-stop-daemon -S -x miniupnpd -- $args 2>/dev/null
99                 fi
100         else
101                 logger -t "upnp daemon" "external interface not found, not starting"
102         fi
103 }
104
105 stop() {
106         start-stop-daemon -K -q -x miniupnpd -p /var/run/miniupnpd.pid
107         rm -f /var/run/miniupnpd.pid
108
109         type miniupnpd_remove_rules >/dev/null 2>/dev/null || \
110                 ACTION=- . /etc/hotplug.d/firewall/50-miniupnpd
111
112         miniupnpd_remove_rules
113
114         iptables -t nat -F MINIUPNPD 2>/dev/null
115         iptables -t nat -X MINIUPNPD 2>/dev/null
116         iptables -t filter -F MINIUPNPD 2>/dev/null
117         iptables -t filter -X MINIUPNPD 2>/dev/null
118 }