1
0
This repository has been archived on 2025-01-10. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Anderson Luiz Alves 0464e230c1 stock 103961
2017-07-30 16:48:04 -03:00

134 lines
3.4 KiB
Bash
Executable File

#!/bin/sh
# /etc/bewan/lib/miniupnpd(-igd)
# To avoid multiple includes
MINIUPNPD_LIB=1
miniupnpd_create_lan() {
local ip=`cat $LAND/$1/ip/ipaddr 2>/dev/null`
[ "$ip" = '' ] && return 1
local mask=`cat $LAND/$1/ip/ipmask 2>/dev/null`
[ "$mask" = '' ] && return 1
local ipnet="$ip/`ipmask $mask`"
echo "listening_ip=$ipnet" >> $conf
return 0
}
miniupnpd_build_configfile()
{
rm -f $conf
local count=${LANDevice_Count:-0}
if [ "$count" = 0 ]; then
return
fi
local name="Pace iBox"
if [ "$Services_MiniUPnPd_FriendlyName" != '' ]; then
name=$Services_MiniUPnPd_FriendlyName
fi
local upnp=no
local natpmp=no
if [ "$Services_MiniUPnPd_Enable" = "1" ]; then
if [ "$Services_MiniUPnPd_EnableUPnP" = 1 ]; then
upnp=yes
fi
if [ "$Services_MiniUPnPd_EnableNATPMP" = 1 ]; then
natpmp=yes
fi
fi
local interval=$Services_MiniUPnPd_NotifyInterval
if [ "$interval" = '' ]; then
interval=60
fi
local secure=no
if [ "$Services_MiniUPnPd_SecureMode" = 1 ]; then
secure=yes
fi
local icam=no
if [ "$Services_MiniUPnPd_EnableiCamDetection" = 1 ]; then
icam=yes
fi
local stealth=no
if [ "$Services_MiniUPnPd_EnableStealthMode" = 1 ]; then
stealth=yes
fi
local port_mapping_state=no
if [ "$Services_MiniUPnPd_EnablePortMapping" = 1 ]; then
port_mapping_state=yes
fi
local serial=`pzinfo serial`
local uprate=100000000
local dnrate=100000000
which adslinfo >/dev/null && {
uprate=`adslinfo|grep "up actual rate (kbps) : "|cut -c 26-100`
dnrate=`adslinfo|grep "down actual rate (kbps) : "|cut -c 26-100`
}
cat >$conf << EOF
friendly_name=$name
enable_upnp=$upnp
enable_natpmp=$natpmp
bitrate_up=$uprate
bitrate_down=$dnrate
secure_mode=$secure
notify_interval=$interval
uuid=$Services_MiniUPnPd_UUID
serial=$serial
lease_file=$home/upnp.leases
upnp_nat_chain=UPNP-DNAT
upnp_forward_chain=none
system_uptime=yes
clean_ruleset_threshold=${Services_MiniUPnPd_CleanRulesetThreshold:-"20"}
clean_ruleset_interval=${Services_MiniUPnPd_CleanRulesetInterval:-"600"}
model_number=1
port=0
enable_icam_detection=$icam
enable_stealth_mode=$stealth
enable_port_mapping=$port_mapping_state
port_mapping_maxlimit=${Services_MiniUPnPd_PortMappingMaxLimit:-"-1"}
port_mapping_maxreject=${Services_MiniUPnPd_PortMappingMaxReject:-"0"}
EOF
local interfaces intf ix ok
# Create ext_ifname configuration parameter
# Take first internet active connection
interfaces=`cat $WAND/internet 2>/dev/null`
for ix in `strip $interfaces`; do
local ifname=`cat $WAND/$ix/ip/ifname 2>/dev/null`
if [ "$ifname" != '' ]; then
echo "ext_ifname=$ifname" >>$conf
echo $ifname > $home/wan-interface
break
fi
done
# Create listening_ip and allow configuration parameters
# Build the list of all or specified interfaces
interfaces=$Services_MiniUPnPd_ListenInterfaces
if [ "$interfaces" = '' ]; then
ix=0
while [ $ix -lt $count ]; do
ix=$(($ix + 1))
if [ "$interfaces" != '' ]; then
interfaces="${interfaces},"
fi
interfaces="${interfaces}${ix}"
done
fi
# Save this list for ip-up event
echo $interfaces > $home/lan-interfaces
# Create subnet keyword
ok=0
for ix in `strip $interfaces`; do
if miniupnpd_create_lan $ix; then
ok=1
break
fi
done
touch $home/upnp.leases
# No lan found -> give-up
[ $ok = 0 ] && rm -f $conf
}