LaFonera Software Heartbeat-dev
From DD-WRT Wiki
Contents |
Talk
>> i will reduce the number of files downloaded but not reduce any functionality like he did.
I'm not sure what you added to the code Wildblue, but as the Alternative Hotspot Script is literally Freddy's original code other than a few Fonera specific variables (and no logging), which itself is the original code formatted slightly differently, then I don't see how it can have any reduced functionality unless you added something additional to yours.
I've also found a small bug in cronjob useage (may not really be a bug, just a feature, but everyone's written code assuming it would work so...). Not tested it in the Fonera yet, but it's happened in 3 WRT54Gs running DD-WRT RC-1 through RC-3 so...
Entries saved in to /tmp/crontab and custom scripts created in /tmp/cron.d/ are deleted everytime the WAN address is lost then regained. Something to do with it running a load of startup like scripts (ip-up, rc.firewall...) but not the actual "startup commands". Anyway, the way around it is to add all cronjobs via the web control panel in the Additional Cron Jobs box as these are recreated (in /tmp/cron.d/cron_jobs) after the WAN ip is refreshed. In other words, may be appropriate to get rid of the cronjob line in startup commands and add info on adding it to the cron jobs box.
The LaFonera Heartbeat Script
This work is based on the work of freddy (http://fon.freddy.eu.org), futejia (http://futejia.blogspot.com), krikkit (http://www.krikkit.net) and wildblue (www.wildblue.de)
Startup Commands
#!/bin/sh mkdir /tmp/simthefon echo '#!/bin/sh sleep 30 cd /tmp/simthefon /usr/bin/wget http://www.wildblue.de/fonera/heartbeat/key /usr/bin/wget http://www.wildblue.de/fonera/heartbeat/simthefon /usr/bin/wget http://www.wildblue.de/fonera/heartbeat/known_hosts cat /tmp/simthefon/known_hosts >> /tmp/root/.ssh/known_hosts chmod a+x /tmp/simthefon/simthefon ( /tmp/simthefon/simthefon cron >/tmp/simthefon/simthefon.log & ) &' >> /tmp/simthefon/heartbeat echo 'SHELL=/bin/sh PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin HOME=/tmp/root */5 * * * * root /tmp/simthefon/simthefon cron >/tmp/simthefon/simthefon.log' >> /tmp/cron.d/heartbeat chmod a+x /tmp/simthefon/heartbeat /tmp/simthefon/heartbeat stopservice cron && startservice cron
known_hosts file
download.fon.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA0zJFtj5NtrVsj8+qG0dtPE8WpHHDpTXp5+d3vvtSS7Hx7vYHyrfN/8PBVrrYOgl4dySY65sGtq34EU04VN4a7xQHSKJBunDUSQ/2Xz+eyo53LCVeFy1zNRCmB6jrFlJQvl5yviLvXmMtOGxG8Z1dfu4qavfGtBxwtwxKPKuiyhs=
http://wildblue.de/fonera/heartbeat/simthefon
#!/bin/sh ########################################## # simthefon.sh # # # # simulate an active LaFonera with an # # alternative firmware on maps.fon.com # # # # First version made by # # fon.freddy.eu.org@freddy.eu.org # # http://fon.freddy.eu.org/ # # # # modified by futejia # # futejia.blog@gmail.com # # http://futejia.blogspot.com/ # # # # updated to work on dd-wrt (2007-02-02) # # http://www.krikkit.net/contact # # # # made it working (2007-02-05) # # MailTo ben@wildblue.de # # # # A step by step guide is available at # # www.wildblue.de/fonera/heartbeat/howto # # # ########################################## # version 2.0.0 (modified for DD-WRT) # # version 2.0.1 (autodetection MAC) # # version 2.0.2 (added cron mode) # # version 2.0.3 (changed MAC-retrival) # # version 2.0.4 (changed update freq.) # ########################################## echo "***********************************************************" echo "* simthefon - heartbeat script for the LaFonera *" echo "* This script makes your LaFonera active on maps.fon.com *" echo "* *" echo "* Version 2.0.4 *" echo "* This Version made by ben@wildblue.de *" echo "***********************************************************" WLMAC="$(nvram get ath0_hwaddr )" #the WLAN mac-adress MAC="$(nvram get et0macaddr)" #the WAN mac-adress FONREV=2 FIRMWARE=0.7.1 FONKEY=/tmp/simthefon/key #the path to the fon-public-key DEVICE="fonera" CHILLVER="1.0" THCLVER="1.0" echo echo "Your WLAN MAC is: " $WLMAC echo "Your Ethernet MAC is:" $MAC echo echo "* starting ..." echo "mode='start' wlmac='$WLMAC' mac='$MAC' fonrev='$FONREV' firmware='$FIRMWARE' chillver='$CHILLVER' thclver='$THCLVER' device='$DEVICE'" | dbclient -T -p 1937 -i $FONKEY openwrt@download.fon.com > startscript exec_every_mode () { echo "* making connection to fon" echo "mode='cron' wlmac='$WLMAC' mac='$MAC' fonrev='$FONREV' firmware='$FIRMWARE'" | dbclient -T -p 1937 -i $FONKEY openwrt@download.fon.com > newscript if cat newscript | grep http > /dev/null 2>&1 then echo "* downloading a new version" DWL_DATE=$(date +%Y%m%d-%H%M) FON_FILE=$DWL_DATE.fon wget -q -O $FON_FILE $(cat newscript | grep http | awk '{print $2}') rm newscript #begin untar package dd if=$FON_FILE of=VERSION_FILE bs=1 count=4 > /dev/null 2>&1 VERSION=$(cat VERSION_FILE) rm VERSION_FILE dd if=$FON_FILE of=OFFSET_FILE bs=1 count=3 skip=4 > /dev/null 2>&1 OFFSET=$(expr $(cat OFFSET_FILE)) rm OFFSET_FILE dd if=$FON_FILE of=SIGNATURE_FILE bs=1 count=$OFFSET skip=7 > /dev/null 2>&1 rm SIGNATURE_FILE TO_SKIP=$(expr $OFFSET + 7) dd if=$FON_FILE of=tar_file bs=1 skip=$TO_SKIP > /dev/null 2>&1 tar zx -f ./tar_file rm ./tar_file UPGRADE_FILE=$(cat upgrade | grep tar | awk '{print $3}') rm -f ./upgrade rm -f hotfix mkdir fon-firmware > /dev/null 2>&1 tar xzf $UPGRADE_FILE -C fon-firmware/ rm $UPGRADE_FILE #end untar package #begin get new versions FONREV=$(cat fon-firmware/etc/fon_revision) FIRMWARE=$(cat fon-firmware/etc/fon_version) echo "* Version is now $FIRMWARE, Revision is now $FONREV" #end get new versions else echo "* Can't find a new version"; fi } exec_cron_mode () { echo "* Cron Mode - repeating must be done with a cronjob!" echo exec_every_mode exit } exec_standard_mode () { while true; do echo "* Standard mode - Repeating is done with a sleep command!" echo exec_every_mode RANDOM_S=$((0x$(head -c2 /dev/urandom | hexdump | awk '$2 > 0 {print $2}') % 1800)) TIMTS=$(echo "`expr 1800 + $RANDOM_S`") echo "* going to sleep for $TIMTS seconds" sleep $TIMTS done; exit } case "$1" in cron) exec_cron_mode ;; *) exec_standard_mode exit esac
The Fon Key
http://www.wildblue.de/fonera/heartbeat/key or http://fon.freddy.eu.org/heartbeat/fonkey
Alternative Hotspot Script
This is a modified version of freddy's thinclient script that uses cron to run and only downloads two files to the Fonera. To install, firstly create a cronjob for the heartbeat by adding the following to the Additional Cron Jobs box on the Admin > Management tab. Ensure you copy and paste, as the spaces between *'s must be tabs and you can't effiectively add these yourself on the web page (tabs don't work).
24,54 * * * * root /jffs/thinclient cron > /dev/null 2>&1 &
Click Apply Settings to save the cron job.
Now just copy and paste the following in to the commands box on the Administration > Commands tab in the web control panel, click Save Startup and reboot the router. If you think it will take longer for an internet connection to be established by the Fonera, just increase the sleep time (in seconds) that is currently set to 10 minutes (600 seconds).
#!/bin/sh # wait until net connection established sleep 600 # get heartbeat files cd /tmp wget http://www.inaudible.co.uk/perm/fonera/thinclient wget http://fon.freddy.eu.org/heartbeat/fonkey chmod 755 /tmp/thinclient
The script will download from my personal web server a modified version of Freddy's original thinclient script ( http://fon.freddy.eu.org/heartbeat/thinclient ) using additional information from wildblue's simthefon script to make it work with the La Fonera, and also downloads freddy's original fonkey file from freddy's webserver.
Changes include "/jffs" changed to "/tmp", FONREV and FIRMWARE changed to the La Fonera's, DEVICE="fonera" added with extra device variables in exec_start_mode, and "| logger" replaced by "> /dev/null 2>&1 &" to stop logging.
http://www.inaudible.co.uk/perm/fonera/thinclient
#!/bin/sh # #version 1.0.6F (modified by pepsi_max2k for la fonera) # THINCLIENTPATH="/tmp" # path of this file ROOTHOME="/tmp/root" # root's home dir SSHPATH="/usr/bin/ssh" # path to ssh KEY="/tmp/fonkey" # private key for fetching the info from the FON server THINCLIENTOUT="/tmp/.thinclient.sh" # output file THINCLIENTOUTDEFAULT="33" # default size of the output file THCLVER="1.0" CHILLVER="1.0-1" FONREV="5" # /etc/fon_revision FIRMWARE="0.7.1" # taken from /etc/banner (without Beta) DEVICE="fonera" USER="openwrt" SERVER="download.fon.com" PORT="1937" FONSIG="$SERVER ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA0zJFtj5NtrVsj8+qG0dtPE8WpHHDpTXp5+d3vvtSS7Hx7vYHyrfN/8PBVrrYOgl4dySY65sGtq34EU04VN4a7xQHSKJBunDUSQ/2Xz+eyo53LCVeFy1zNRCmB6jrFlJQvl5yviLvXmMtOGxG8Z1dfu4qavfGtBxwtwxKPKuiyhs=" # gather information about this machine WLMAC="$(/usr/sbin/nvram get ath0_hwaddr)" ETMAC="$(/usr/sbin/nvram get et0macaddr)" MAC=`echo $WLMAC|tr A-Z a-z` check_env () { [ -d "$ROOTHOME/.ssh" ] || mkdir $ROOTHOME/.ssh [ -f "$ROOTHOME/.ssh/known_hosts" ] || touch $ROOTHOME/.ssh/known_hosts [ `grep -c $SERVER $ROOTHOME/.ssh/known_hosts` = "0" ] && echo $FONSIG >> $ROOTHOME/.ssh/known_hosts } exec_cron_mode () { check_env sleep "$((0x$(head /dev/urandom |hexdump |awk '$2 > 0 {print $2}'|head -n1) % 60))" echo "mode='cron' wlmac='$MAC' mac='$ETMAC' fonrev='$FONREV' firmware='$FIRMWARE'" | $SSHPATH -T ${PORT:+ -p $PORT}${KEY:+ -i $KEY} "${USER}@${SERVER}" > $THINCLIENTOUT echo "sent: mode='cron' wlmac='$MAC' mac='$ETMAC' fonrev='$FONREV' firmware='$FIRMWARE'" exec_check_thinclient } exec_start_mode () { sleep 60 # make sure WAN is up and crond is running check_env [ -f "/tmp/crontab" ] || touch /tmp/crontab [ `grep -c thinclient /tmp/crontab` = "0" ] && echo "24,54 * * * * root $THINCLIENTPATH/thinclient cron > /dev/null 2>&1 &" >> /tmp/crontab echo "mode='start' wlmac='$MAC' mac='$ETMAC' fonrev='$FONREV' firmware='$FIRMWARE' chillver='$CHILLVER' thclver='$THCLVER' device='$DEVICE'" | $SSHPATH -T ${PORT:+ -p $PORT}${KEY:+ -i $KEY} "${USER}@${SERVER}" > $THINCLIENTOUT echo "sent: mode='start' wlmac='$MAC' mac='$ETMAC' fonrev='$FONREV' firmware='$FIRMWARE' chillver='$CHILLVER' thclver='$THCLVER' device='$DEVICE'" exec_check_thinclient } exec_check_thinclient () { if [ -f $THINCLIENTOUT ] then THINSIZE="$(wc -c < $THINCLIENTOUT)" if [ $THINSIZE = "0" ] then echo "Something is wrong, $THINCLIENTOUT is empty" elif [ $THINSIZE != "33" ] then echo "Something is different in $THINCLIENTOUT:" cat $THINCLIENTOUT else echo "$THINCLIENTOUT is the default one, deleted" rm $THINCLIENTOUT fi else echo "Something is wrong, $THINCLIENTOUT does not exist!" fi } case "$1" in cron) exec_cron_mode ;; start) exec_start_mode ;; check) exec_check_thinclient ;; *) echo "Usage: `basename $0` {cron|start|check}" exit esac
Help developing the code
If you want to help developing the original dd-wrt LaFonera Heartbeat code just contact me (ben@wildblue.de) and/or make updates here and contact me.