# write dummy callmessage script
echo "#!/bin/sh" > /var/tmp/callmessage.sh
make it executable
chmod +x /var/tmp/callmessage.sh
# more /var/flash/debug.cfg
#!/bin/sh
LED_DEVICE=/proc/led_mod/led
if [ ! -f /proc/led_mod/led ] ; then
LED_DEVICE=/var/led
echo "set led: ${LED_DEVICE}"
fi
# start internet phone led flashing
echo "set internet phone led to blink (modul=14, state=3)"
echo 14,3 > ${LED_DEVICE}
# enable ENUM
sed "s/avme/avm/g" /usr/www/all/html/de/fon/sipoptionen.html > /var/tmp/sipoptionen.html
sed "s/avme/avm/g" /usr/www/all/html/de/fon/sipoptionen.js > /var/tmp/sipoptionen.js
chmod 444 /var/tmp/sipoptionen.html
chmod 444 /var/tmp/sipoptionen.js
mount -o bind /var/tmp/sipoptionen.html /usr/www/all/html/de/fon/sipoptionen.html
mount -o bind /var/tmp/sipoptionen.js /usr/www/all/html/de/fon/sipoptionen.js
major=`grep tffs /proc/devices`
tffs_major=${major%%tffs}
#write calllog
cat > /var/calllog << 'ENDCALLLOG'
#!/bin/sh
CALLER=${1}
LINE=${3}
if [ -z "${LINE}" ]
then
LINE=${2}
fi
if [ "${LINE}" = "ISDN" ]
then
LINE=${2}
fi
if [ -z "${LINE}" ]
then
LINE=${1}
CALLER=""
fi
sh /var/tmp/parse_telefon.sh "${LINE}" "${CALLER}" &
ENDCALLLOG
# save /var/calllog
mknod /var/flash/calllog c $tffs_major $((0x77))
cp /var/calllog /var/flash/calllog
#CONTACTS
#contact=:anonymous;
#contact=016xyxyxyx:016xyxyxyxy;
#contact=030xyxyxyxy:030xyxyxyxy;
#CONTACTSEND
#LINES
#line=:anonymous;
#LINESEND
# write reverse lookup script to file
cat > /var/tmp/invers.sh << 'ENDINVERS'
#!/bin/sh
number=$1
wget -q -O /var/tmp/page "http://www2.dasoertliche.de/?form_name=detail&lastFormName=search_inv&ph=${number}&recFrom=1&hitno=0" 2>/dev/null
while read reverse
do
case ${reverse} in
*detail_top*)
name=${reverse#*\>}
name=${name%%\<*}
break
;;
esac
done < /var/tmp/page
echo "${name}" > /var/tmp/name
# get address
while read reverse
do
if [ -n "${gotaddress}" ]
then
address=${reverse#*\>}
address=${address%\<*}
break
fi
case ${reverse} in
*da_adresse*)
gotaddress=1
;;
esac
done < /var/tmp/page
echo "${address}" | sed -e '{s/ / /g;s/<br \/>/;/g;}' > /var/tmp/address
ENDINVERS
# make it executable
chmod +x /var/tmp/invers.sh
# write send script to file
cat > /var/tmp/callmessage.sh << 'ENDCALLMESSAGE'
#!/bin/sh
caller=${2}
called=${1}
# search name in contact list
entry=`cat /var/flash/debug.cfg 2>/dev/null | fgrep "#contact=${caller}:" | sed
"s/#contact=${caller}://"`
name=${entry%%\;*}
address=${entry#*\;}
address=${address%\;*}
street=${address%%\;*}
zip=${address##*\;}
# name not found?
if [ -z "${name}" ]
then
# do reverse lookup at www.dasoertliche.de
/var/tmp/invers.sh ${caller}
name=`cat /var/tmp/name`
# found name?
if [ -n "${name}" ]
then
# add found contact to debug.cfg
address=`cat /var/tmp/address`
street=${address%%\;*}
zip=${address##*\;}
cat /var/flash/debug.cfg | sed -e "s/^#CONTACTSEND$/#contact=${caller}:${name};${address};#CONTACTSEND/g" | sed -e 's/#CONTACTSEND$/\
#CONTACTSEND/g' > /var/tmp/debug.cfg
else
# add anonymous for contact to debug.cfg
cat /var/flash/debug.cfg | sed -e "s/^#CONTACTSEND$/#contact=${caller}:${caller};#CONTACTSEND/g" | sed -e 's/#CONTACTSEND$/\
#CONTACTSEND/g' > /var/tmp/debug.cfg
fi
cat /var/tmp/debug.cfg > /var/flash/debug.cfg
rm /var/tmp/debug.cfg
fi
# name not found?
if [ -z "${name}" ]
then
name=${caller}
fi
httpname=`echo "${name}" | sed -e '{s/ /%20/g;s/-/Ae/g;s/Í/Oe/g;s/_/Ue/g;s/õ/ae/g;s/÷/oe/g;s/³/ue/g;s/¯/ss/g;s/&/%26/g;}'`
httpstreet=`echo "${street}" | sed -e '{s/ /%20/g;s/-/Ae/g;s/Í/Oe/g;s/_/Ue/g;s/õ/ae/g;s/÷/oe/g;s/³/ue/g;s/¯/ss/g;s/&/%26/g;}'`
httpzip=`echo "${zip}" | sed -e '{s/ /%20/g;s/-/Ae/g;s/Í/Oe/g;s/_/Ue/g;s/õ/ae/g;s/÷/oe/g;s/³/ue/g;s/¯/ss/g;s/&/%26/g;}'`
echo "Name: ${name}"
echo "Strasse: ${street}"
echo "PLZ: ${zip}"
# search line in line list
theline=`cat /var/flash/debug.cfg 2>/dev/null | fgrep "#line=${called}:" | sed "s/#line=${called}://"`
theline=${theline%%\;*}
# line not found?
if [ -z "${theline}" ]
then
theline=${called}
fi
httptheline=`echo "${theline}" | sed -e '{s/ /%20/g;s/-/Ae/g;s/Í/Oe/g;s/_/Ue/g;s/õ/ae/g;s/÷/oe/g;s/³/ue/g;s/¯/ss/g;s/&/%26/g;}'`
# send information to PCs
wget -O /dev/null "http://192.168.178.20:23232/?caller=${caller}&called=${called}&name=${name}&line=${theline}" >/dev/null 2>&1 &
wget -O /dev/null "http://192.168.178.21:23232/?caller=${caller}&called=${called}&name=${name}&line=${theline}" >/dev/null 2>&1 &
wget -O /dev/null "http://192.168.178.22:23232/?caller=${caller}&called=${called}&name=${name}&line=${theline}" >/dev/null 2>&1 &
sleep 3
killall wget
ENDCALLMESSAGE
# make it executable
chmod +x /var/tmp/callmessage.sh
# write WakeOnCall script
cat > /var/tmp/woc.sh << 'ENDWOC'
#!/bin/sh
pcaller="016999999999"
pcalled="99999999"
# read params
caller=$2
called=$1
# check if woc is permitted for caller and called
if [ "${pcaller}" = "all" ]
then
if [ "${pcalled}" = "all" ]
then
/var/tmp/startpc
elif [ "${pcalled}" = "${called}" ]
then
/var/tmp/startpc
fi
elif [ "${pcaller}" = "${caller}" ]
then
if [ "${pcalled}" = "all" ]
then
/var/tmp/startpc
elif [ "${pcalled}" = "${called}" ]
then
/var/tmp/startpc
fi
fi
ENDWOC
# make it executable
chmod +x /var/tmp/woc.sh
# write parse_telefon script to file
cat > /var/tmp/parse_telefon.sh << 'ENDPARSETEL'
#!/bin/sh
trap "" SIGCHLD
prefix=030
caller="$2"
called="$1"
called=${called%%#*}
# normalize caller
case ${caller} in
0049*)
caller=0${caller#*0049}
;;
49????????*)
caller=0${caller#*49}
;;
[1-9]????????*)
caller=0${caller}
;;
[1-9]*)
caller=${prefix}${caller}
;;
esac
# exec woc.sh
/var/tmp/woc.sh ${called} ${caller} &
# exec callmessage.sh
/var/tmp/callmessage.sh ${called} ${caller} &
ENDPARSETEL
# make it executable
chmod +x /var/tmp/parse_telefon.sh
# load VPN-Server (OpenVPN)
# wait for server
while !(ping -c 1 www.inter.net)
do
sleep 5
done
# change dir
cd /var/tmp
# write 'secret.key' to file
cat > /var/tmp/secret.key << 'ENDSECRETKEY'
#
# 2048 bit OpenVPN static key
#
-----BEGIN OpenVPN Static key V1-----
123
-----END OpenVPN Static key V1-----
ENDSECRETKEY
# write 'server.ovpn' to file
cat > /var/tmp/server.ovpn << 'ENDSERVERCONF'
dev tun0
dev-node /dev/misc/net/tun
ifconfig 10.0.0.2 10.0.0.1
secret /var/tmp/secret.key
proto tcp-server
port 1194
tun-mtu 1500
float
keepalive 10 60
verb 4
mssfix
route 10.0.0.0 255.255.255.0
push "route 10.0.0.0 255.255.255.0"
daemon
ENDSERVERCONF
# load files
wget http://www.inter.net/files/openvpn
# make them executable
chmod +x /var/tmp/openvpn
chmod 0600 /var/tmp/server.ovpn
chmod 0600 /var/tmp/secret.key
# start OpenVPN
./openvpn --config ./server.ovpn
# load SSH-Server (dropbear) and etherwake
# CONFIGURATION
# SSH
# port
dropbearport="22"
# password
PASSWD='123'
# Etherwake
# MAC address
wolmac="00:11:AA:22:33:B4"
# interface to use for WOL
# intf = std - ata
# eth0 = LAN1 - WAN
# eth1 = LAN2 - LAN1
wolinterface="eth0"
# CONFIGURATION END
# change root password
cp -p /var/tmp/shadow /var/tmp/shadow.old
sed -e "/root:/s#^root:[^:]*:#root:${PASSWD}:#" /var/tmp/shadow.old > /var/tmp/shadow
# wait for server
while !(ping -c 1 www.inter.net)
do
sleep 5
done
# change dir
cd /var/tmp
# create simplified WOL script
echo "/var/tmp/etherwake -i ${wolinterface} ${wolmac}" > ./startpc
# load files
wget http://www.inter.net/files/dropbear
wget http://www.inter.net/files/busybox
# make them executable
chmod +x /var/tmp/dropbear
chmod +x /var/tmp/busybox
chmod +x /var/tmp/startpc
# create symlink for dropbearkey
ln -s /var/tmp/dropbear dropbearkey
ln -s /var/tmp/busybox etherwake
ln -s /var/tmp/busybox uudecode
/var/tmp/uudecode -o /var/tmp/dropbear_rsa_host_key << 'RSA'
begin 600 /var/tmp/dropbear_rsa_host_key
123
`
end
RSA
/var/tmp/uudecode -o /var/tmp/dropbear_dss_host_key << 'DSS'
begin 600 /var/tmp/dropbear_dss_host_key
123
`
end
DSS
# start dropbear
sleep 60
/var/tmp/dropbear -p ${dropbearport} -r /var/tmp/dropbear_rsa_host_key -d /var/tmp/dropbear_dss_host_key
# make FBF accessable from the internet (192.168.178.253)
sleep 10
ifconfig eth0:1 192.168.178.253 netmask 255.255.255.0 broadcast 192.168.178.255
up
# write firmware check script
cat > /var/tmp/checkfw.sh << 'ENDCHECKFW'
#!/bin/sh
fw_path="ftp://ftp.avm.de/fritz.box/fritzbox.fon_wlan_7050/firmware"
from="[email protected]"
to="[email protected]"
mailserver="mail.inter.net"
mailuser="[email protected]"
mailpassword="passwort"
cd /var/tmp
# check daily
while [ 1 ]
do
# installed version?
CURRENT_VERSION=`/etc/version`
# available version?
ONLINE_VERSION=`wget -O - ${fw_path}/info.txt | grep 'Version' | grep ':' | sed -e '{s/Version//g;s/ //g;s/://g;}'`
# last reported version
if [ -f version_reported ]
then
ONLINE_VERSION_REPORTED=`cat ./version_reported`
else
ONLINE_VERSION_REPORTED='${CURRENT_VERSION}'
fi
# report new firmware if not yet reported
if [ "${ONLINE_VERSION}" = "${ONLINE_VERSION_REPORTED}" ]
then
echo "firmware already reported"
else
# create mail
echo "Installierte Version: ${CURRENT_VERSION}" > ./message.txt
echo "Verf³gbare Version: ${ONLINE_VERSION}" >> ./message.txt
echo "" >> ./message.txt
echo "Die neue Firmware steht unter ${fw_path} zum Download bereit." >> ./message.txt
# send mail
mailer -s "Neue Firmware f³r Ihre Fritz!Box verf³gbar" -f "${from}" -t "${to}" -m "${mailserver}" -a "${mailuser}" -w "${mailpassword}" -i ./message.txt
echo "${ONLINE_VERSION}" > ./version_reported
fi
sleep 86400
done
ENDCHECKFW
# make it executable
chmod +x /var/tmp/checkfw.sh
sleep 120
/var/tmp/checkfw.sh &
# stop internet phone led flashing
echo 14,1 > ${LED_DEVICE}