Free FON

You might know that FON thing, which basically provides you with WiFi on many places. They give you an access point which they suppose you to run and provide that WiFi to others. Then you are eligible to use other peoples WiFi.

The given access point connects itself with a script to the main server and tells it, that it’s online. The server then grants you access to other WiFis.

If you flash the access point, which is called “fonera”, with e.g. OpenWRT then you’ll lose that script. This in pretty bad because you *do* provide free WiFi to the people (unless you don’t run an open WiFi) but lose the right to use others.

There are sites out there which describe, howto do the “heartbeat” yourself, but they have major drawbacks:

  • They are written in Bash
  • The key used is in dropbear format, and not OpenSSH

Also note, that you can receive the files from the Fon development site and steal that heartbeat thing from there.

Thanks to this site I found a way to convert the dropbear key to the OpenSSH format (/usr/lib/dropbear/dropbearconvert dropbear openssh fonkey fonkey.ssh), but that bash thing is still ugly. Also, to use OpenSSH, you have to fiddle with permissions of the keyfile, etc.

So in order to run that heartbeat thing properly on, say, your PC, you don’t want to depend on dropbear or “nvram” to get the MAC address of your wireless interface. You might want to run the following script, of course you have to adapt the variables first. I try to get rid of Bash, but I still have a few problems with Pythons SSH package: I can’t send something to “stdin”, like “echo 'foo' | ssh bar” does.

#!/bin/sh
#
# version 1.1.0 

THINCLIENTPATH="/tmp" # path of this file
ROOTHOME="/tmp/root" # root's home dir
SSHPATH="/usr/bin/ssh" # path to ssh
KEY="/tmp/fonkey.ssh.1" # 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="2" # /etc/fon_revision
FIRMWARE="0.7.2" # 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="
cat > $KEY <> $ROOTHOME/.ssh/known_hosts
}

exec_cron_mode () {
	check_env
	sleep "$((0x$(head /dev/urandom |hexdump |awk '$2 > 0 {print $2}'|head -n1) % 10))"
	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 10 # 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

One thought on “Free FON”

Leave a Reply

Your email address will not be published. Required fields are marked *

Creative Commons Attribution-ShareAlike 3.0 Unported
This work by Muelli is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported.