1 #!/bin/sh /etc/rc.common
4 upnpd_get_port_range
() {
12 export -n -- "${_var}_start=${_val%%[:-]*}"
13 export -n -- "${_var}_end=${_val##*[:-]}"
16 export -n -- "${_var}_start=$_val"
17 export -n -- "${_var}_end="
25 local action external_port_start external_port_end int_addr
26 local internal_port_start internal_port_end
27 config_get action
"$cfg" action
"deny" # allow or deny
28 upnpd_get_port_range
"ext" "$cfg" ext_ports
"0-65535" # external ports: x, x-y, x:y
29 config_get int_addr
"$cfg" int_addr
"0.0.0.0/0" # ip or network and subnet mask (internal)
30 upnpd_get_port_range
"int" "$cfg" int_ports
"0-65535" # internal ports: x, x-y, x:y or range
31 echo "${action} ${ext_start}${ext_end:+-}${ext_end} ${int_addr} ${int_start}${int_end:+-}${int_end}" >>$tmpconf
40 config_get_bool val config
"$opt" "$def"
41 if [ "$val" -eq 0 ]; then
42 echo "${alt:-$opt}=no" >> $tmpconf
44 echo "${alt:-$opt}=yes" >> $tmpconf
49 type miniupnpd_add_rules
>/dev
/null
2>/dev
/null || \
50 ACTION
=- .
/etc
/hotplug.d
/firewall
/50-miniupnpd
53 local extiface intiface upload download logging secure enabled natpmp
54 local extip port usesysuptime conffile serial_number model_number
55 local uuid notify_interval presentation_url enable_upnp
56 local upnp_lease_file clean_ruleset_threshold clean_ruleset_interval
58 config_get extiface config external_iface
59 config_get intiface config internal_iface
60 config_get extip config external_ip
61 config_get port config port
5000
62 config_get upload config upload
63 config_get download config download
64 config_get_bool logging config log_output
0
65 config_get conffile config config_file
66 config_get serial_number config serial_number
67 config_get model_number config model_number
68 config_get uuid config uuid
69 config_get notify_interval config notify_interval
70 config_get presentation_url config presentation_url
71 config_get upnp_lease_file config upnp_lease_file
72 config_get clean_ruleset_threshold config clean_ruleset_threshold
73 config_get clean_ruleset_interval config clean_ruleset_interval
81 config_get ifname
${extiface:-wan} ifname
83 if [ -n "$conffile" ]; then
86 local tmpconf
="/var/etc/miniupnpd.conf"
90 echo "ext_ifname=$ifname" >$tmpconf
95 echo "ext_ip=$extip" >>$tmpconf
97 for iface
in ${intiface:-lan}; do
99 config_get ipaddr
"$iface" ipaddr
100 [ -n "$ipaddr" ] && \
101 echo "listening_ip=$ipaddr" >>$tmpconf
104 [ "$port" != "auto" ] && \
105 echo "port=$port" >>$tmpconf
108 upnpd_write_bool enable_natpmp
1
109 upnpd_write_bool enable_upnp
1
110 upnpd_write_bool secure_mode
1
111 upnpd_write_bool system_uptime
1
113 [ -n "$upnp_lease_file" ] && \
114 echo "lease_file=$upnp_lease_file" >>$tmpconf
116 [ -n "$upload" -a -n "$download" ] && {
117 echo "bitrate_down=$(($download * 1024 * 8))" >>$tmpconf
118 echo "bitrate_up=$(($upload * 1024 * 8))" >>$tmpconf
121 [ -n "${presentation_url}" ] && \
122 echo "presentation_url=${presentation_url}" >>$tmpconf
124 [ -n "${notify_interval}" ] && \
125 echo "notify_interval=${notify_interval}" >>$tmpconf
127 [ -n "${clean_ruleset_threshold}" ] && \
128 echo "clean_ruleset_threshold=${clean_ruleset_threshold}" >>$tmpconf
130 [ -n "${clean_ruleset_interval}" ] && \
131 echo "clean_ruleset_interval=${clean_ruleset_interval}" >>$tmpconf
134 uuid
="$(cat /proc/sys/kernel/random/uuid)"
135 uci
set upnpd.config.uuid
=$uuid
139 [ "$uuid" = "nocli" ] || \
140 echo "uuid=$uuid" >>$tmpconf
142 [ -n "${serial_number}" ] && \
143 echo "serial=${serial_number}" >>$tmpconf
145 [ -n "${model_number}" ] && \
146 echo "model_number=${model_number}" >>$tmpconf
148 config_foreach conf_rule_add perm_rule
"$tmpconf"
152 if [ -n "$ifname" ]; then
156 config_get zone core
"${extiface:-wan}_zone"
158 miniupnpd_add_rules
"$zone" "${extiface:-wan}" "$ifname"
160 if [ "$logging" = "1" ]; then
161 eval start-stop-daemon
-S -x miniupnpd
-- $args -d | logger
-t miniupnpd
&
163 eval start-stop-daemon
-S -x miniupnpd
-- $args 2>/dev
/null
166 logger
-t "upnp daemon" "external interface not found, not starting"
171 start-stop-daemon
-K -q -x miniupnpd
-p /var
/run
/miniupnpd.pid
172 rm -f /var
/run
/miniupnpd.pid
174 type miniupnpd_remove_rules
>/dev
/null
2>/dev
/null || \
175 ACTION
=- .
/etc
/hotplug.d
/firewall
/50-miniupnpd
177 miniupnpd_remove_rules
179 iptables
-t nat
-F MINIUPNPD
2>/dev
/null
180 iptables
-t nat
-X MINIUPNPD
2>/dev
/null
181 iptables
-t filter
-F MINIUPNPD
2>/dev
/null
182 iptables
-t filter
-X MINIUPNPD
2>/dev
/null