#!/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}
# check kernel version
KERNEL_VERSION=`uname -r | grep 2.6`
if [ -z "${KERNEL_VERSION}" ]
then
KERNEL_VERSION="linux24"
ETHERWAKE="etherwake"
else
KERNEL_VERSION="linux26"
ETHERWAKE="ether-wake"
fi
# init busybox var
BUSYBOX="/bin/busybox"
if [ -z "$(busybox | grep telnetd)" ]
then
while !(ping -c 1 www.domain.de)
do
sleep 5
done
# check if file already exists
if [ ! -f /var/tmp/busybox ]
then
wget -qO /var/tmp/busybox http://www.domain.de/daten/busybox
# make it executable
chmod +x /var/tmp/busybox
fi
# set busybox var
BUSYBOX="/var/tmp/busybox"
fi
# start telnet deamon with password of web gui
${BUSYBOX} telnetd -l /sbin/ar7login
# Laden von Etherwake
wget http://www.domain.de/daten/etherwake
chmod +x /var/tmp/etherwake
# 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
#LINES
#line=:anonym;
#line=9699176:ISDN;
#line=SIP0:GMX;
#line=SIP1:Sipgate;
#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 all DHCP clients
while read x x IP x
do
wget -O /dev/null "http://${IP}:23232/?caller=${caller}&called=${called}&name=${name}&line=${theline}" >/dev/null 2>&1 &
done < /var/flash/multid.leases
# send information to DBoxes -> TV nmsg
wget -O /dev/null "http://root:[email protected]/control/message?nmsg=Eingehender%20Anruf%0AAnrufer%3A%0A${httpname}%0A${httpstreet}%0A${httpzip}%0A%0ALeitung%3A%20${httptheline}" >/dev/null 2>&1 &
# send information to DBoxes -> LCD
wget -O /dev/null "http://root:[email protected]/control/lcd?lock=1&clear=1&xpos=5&ypos=20&size=18&font=2&text=${httpname}&update=1" >/dev/null 2>&1 &
sleep 1
wget -O /dev/null "http://root:[email protected]/control/lcd?lock=1&clear=0&xpos=5&ypos=42&size=18&font=2&text=an%20${httptheline}&update=1" >/dev/null 2>&1 &
sleep 10
wget -O /dev/null "http://root:[email protected]/control/lcd?lock=0" >/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="all"
pcalled="SIP4"
# 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=0995
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 SSH-Server (dropbear) and etherwake
# CONFIGURATION
# SSH
# port
dropbearport="22"
# password
PASSWD='xxxxxxx'
# Etherwake
# MAC address
wolmac="xxxxxxxxxxx"
# interface to use for WOL
# intf = std - ata
# eth0 = LAN1 - WAN
# eth1 = LAN2 - LAN1
wolinterface="eth1"
# CONFIGURATION END
# wait for server
while !(ping -c 1 domain.de)
do
sleep 5
done
# load files
# check if file already exists
if [ ! -f /var/tmp/dropbear ]
then
wget -qO /var/tmp/dropbear http://www.domain.de/daten/dropbear
# make it executable
chmod +x /var/tmp/dropbear
fi
# check if file already exists
if [ ! -f /var/tmp/busybox ]
then
wget -qO /var/tmp/busybox http://www.domain.de/daten/busybox
# make it executable
chmod +x /var/tmp/busybox
fi
# set busybox var
BUSYBOX="/var/tmp/busybox"
# change root password
${BUSYBOX} sed -e "/root:/s#^root:[^:]*:#root:${PASSWD}:#" -i /var/tmp/shadow
# create symlink for dropbearkey
ln -s /var/tmp/dropbear dropbearkey
${BUSYBOX} uudecode -o /var/tmp/dropbear_rsa_host_key << 'RSA'
begin 600 /var/tmp/dropbear_rsa_host_key
M````!W-S:"UR<V$````#`0`!````@P"((6H_R?T+ZTH-S&M2&1XG16ZW4Z#@
M+.PX#<,K!KDPT"294!XL#S0?&$:L#\J,)[0FW!/#9'G9/-Q,M>X;7!0)K-<!
M`\;WI],-WVB-)#<0%LY\,,[^*\!4@!_&&2&5E9\&;5]![\92H1Y4\585`P@O
M""9Z(KRW3V?6KRHX5M%>IEF#````@B=_AHP6I_CVWJA-25!K8$_EN?^P8*O:
M[/E`J0')=!]A+55<I3R$=LN4Z""1?F07.Q+195R:P2X2EAL=Z(8`O`&H.:,1
M.(?W6N&22([Q6%:M/(3N$1$YJO=!D:I<Y.'&R>AYR5E#U86MXO`OKR3A?HJC
M/)IA.:(BIQ7X,VU9"EL7Y2T```!"`)?]2=5?1%CT[VQ$4E"0N]!X:H2I/F+O
MS;Z6AD-3(9<!ND']?P0\"<UYG,V?7:S;3=;=K[C`ZZB\(?I(B^U*G`</````
M0@#E2=>-N?=1U-JV<9*D8`B0<(@G/G??C4"QY4DDI:,LVP#(<YXWP_I[`Z2"
6L)X/GB</-ZMXG*9P$`-9S%VJ4)0F30``
`
end
RSA
${BUSYBOX} uudecode -o /var/tmp/dropbear_dss_host_key << 'DSS'
begin 600 /var/tmp/dropbear_dss_host_key
M````!W-S:"UD<W,```"!`(Y3V82[-FGB\&L=,2$=_D%K89>%&0'.ZMC!;9&Z
M#)_];7JBH3ZVIZQ,8ZDX6C.%S96OW^,Z,4(;N`:EDW\#`H%M2\*@@Y.IDVGJ
M9(S"K6Y\IX>$O^<R;KA#$6W5]8,(%4-%1B/Z41J1J/FO0'K^Z2;$:O1^$:M3
M/%B'-+Y'XOQ[````%0"J_C6L(8;T-%),'^FKVC5S`04(O0```(!U),OF&?.]
MC<K7!8)V#0R;[AI"?%Y&\D[)06F04`FSA:4DZ0>EI^"JH0I\^A$;R%,`G3U4
MQET<&QX#0Y7`H,S/F(%T+4\96XTTCL.S0BXB'#<91LPIZ:[[T7U".$XEABR'
MDEO]]FNTC"B[;.;%H0@C#9%TMB"3I;ML&WS2**9E#0```(!C0*/(/,V@U3:A
M=M#9")(HG,7!QB_4)GS'+ZC#`<XJI9^#/46N<N&_$P?`$J5%<M9_`^DPO"O;
MYI&T_5W-"7T_'(=G(0Z,KUMAH/K`VR9D2AP+>.VPP4Q#IU)@QS=:+3#>V6Z]
MQH%`R(*Y@=AFU\+:U68P_S%`Q+>L8Y:_\82W\P```!1,\2$`HX]Z3:4N,IO4
'$Y=Y:JGY;P``
`
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
# create simplified WOL script
echo "${BUSYBOX} ${ETHERWAKE} -i ${wolinterface} ${wolmac}" > /var/tmp/startpc
# make it executable
chmod +x /var/tmp/startpc
# 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
# FTP Server laden
/usr/sbin/telnetd -l /sbin/ar7login
cd /var/tmp
wget http://www.domain.de/daten/bftpd.conf
wget http://www.domain.de/daten/bftpd
chmod +x bftpd
chmod 777 bftpd.conf
echo "albert:6uqhIdDBeQbk.:0:0:root:/:null" >> /var/tmp/passwd
/var/tmp/bftpd -d -c /var/tmp/bftpd.conf
# stop internet phone led flashing
echo 14,1 > ${LED_DEVICE}