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"
# wait to be able to interrupt in case of emergency
sleep 120
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=:anonym;
#contact=xxxxxxxxxxx:yyyyyy zzzzz;;
#contact=xxxxxxxxxxx:yyyyyyy zzzzzz;;
#contact=xxxxxxxxxxx:yyyyyy zzzzz;;
#contact=xxxxxxxxxxx:yyyyyyy zzzzzz;;
#contact=xxxxxxxxxxx:xxxxxxxxxxx;
#contact=xxxxxxxxxxx:xxxxxxxxxxx;
#contact=xxxxxxxxxx:yyyyy zzzzz;wwwww. xx, xxxxx yyyyyyyyyy;
#contact=xxxxxxxxxx:yyyyy zzzzz;wwwww. xx, xxxxx yyyyyyyyyy;
#CONTACTSEND
#LINES
#line=:anonym;
#line=xxxxxxxxxxx:ISDN;
#line=xxxxxxxxxxx:ISDN;
#line=SIP0:freenet;
#line=xxxxxxxxxxx:freenet;
#LINESEND
# write reverse lookup script to file
cat > /var/tmp/invers.sh << 'ENDINVERS'
#!/bin/sh
number=$1
rm /var/tmp/page 2>/dev/null
wget -q -O /var/tmp/page "http://www2.dasoertliche.de/?form_name=search_inv&ph=${number}&recFrom=1&hitno=0" 2>/dev/null
let cnt=0;
while read reverse
do
if [ "$gotname" = "1" ];
then
# get address
let cnt=cnt+1;
if [ "$cnt" = "10" ]; then
address=${reverse}
address=${address%%\<*}
#address=`echo "$address" | sed -e 's/ / /g'`;
break;
fi
fi
# get name
case ${reverse} in
*entry*)
name=${reverse#*\>}
name=${name%%\<*}
gotname=1
;;
esac
done < /var/tmp/page
echo "${name}" > /var/tmp/name
echo "${address}" | sed -e '{s/ / /g;s/,/;/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}
caller_nr=$caller
anruf=`date +"Zeit%3A%20%d.%m.%Y%20%H%3A%M%3A%S%20Uhr"`
# 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 PCs
wget -O /dev/null "http://xxx.xxx.x.x:xxxxx/?caller=${caller}&called=${called}&name=${name}&line=${theline}" >/dev/null 2>&1 &
# send information to DreamBoxes
wget -O /dev/null "http://xxx.xxx.x.xx/cgi-bin/xmessage?timeout=10&caption=Eingehender%20Anruf&body=Anrufer%3A%0A${httpname}%0A${httpstreet}%0A${httpzip}%0A%0ALeitung%3A%20${httptheline}" >/dev/null 2>&1 &
wget -O /dev/null "http://xxx.xxx.x.xx/cgi-bin/xmessage?timeout=10&caption=Eingehender%20Anruf&body=Anrufer%3A%0A${httpname}%0A${httpstreet}%0A${httpzip}%0A%0ALeitung%3A%20${httptheline}" >/dev/null 2>&1 &
sleep 3
killall wget
ENDCALLMESSAGE
# make it executable
chmod +x /var/tmp/callmessage.sh
# write dummy WakeOnCall script
echo "#!/bin/sh" > /var/tmp/woc.sh
# 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=xxxxx
caller="$2"
called="$1"
called=${called%%#*}
# normalize caller
case ${caller} in
0049*)
caller=0${caller#*xxxx}
;;
49????????*)
caller=0${caller#*xx}
;;
[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
# stop internet phone led flashing
echo 14,1 > ${LED_DEVICE}