#!/bin/sh ### # # FreeWLAN Addons - http://www.freewlan.info # # This Script is based on the original La Fonera Firmware version 0.7.1r2 # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA # # http://www.gnu.org/copyleft/gpl.html # ### . /etc/functions.sh config_load router config_get mode mode mode if [ "$mode" -eq "1" ]; then . /tmp/network-config TMP_C=/tmp/chilli.conf ETC_C=/etc/chilli.conf PID_F=/var/run/chilli.pid PID_LOOP_F=/var/run/chilli_loop.pid LOG_LOOP_F=/var/log/chilli_loop.log WANIP="$(ifconfig "$wan_ifname" | grep inet | awk -F'[: ]+' '{print $4}')" MAC=$(ifconfig wifi0 | head -n1 | awk '{print $5}'|sed s/:/-/g) MAC=${MAC:-fon} LOOP=true DELAY=86400 SECONDS=0 DELAY2=10 SECONDS2=0 RADIUSSERVER=radius01.fon.com RADIUSSECRET=garrafon RADIUSADMUSR=chillispot RADIUSADMPWD=chillispot quit() { LOOP="false" circular_log $LOG_LOOP_F "Signal caught. Exiting..." } circular_log() { echo "chillispot $(date) $2" >> $1 tail -24 $1 > $1.tmp mv $1.tmp $1 } do_reload() { [ -f $PID_F ] && kill -HUP $(cat $PID_F) >/dev/null 2>&1 } is_alive() { if [ ! -f $PID_F ]; then echo "dead" return 0 fi TEST_PID=$(cat $PID_F) if [ ! -d /proc/$TEST_PID ]; then rm $PID_F echo "dead" return 0 fi CANDIDATE=$(cat /proc/$TEST_PID/status | grep Name: | awk '{ print $2 }') if [ "$CANDIDATE" = "chilli" ]; then echo "alive" return 0 else rm $PID_F echo "dead" return 0 fi } radconfig() { /usr/sbin/chilli_radconfig \ -c /dev/null \ --radiusserver1="$RADIUSSERVER" \ --radiussecret="$RADIUSSECRET" \ --adminuser="$RADIUSADMUSR" \ --adminpasswd="$RADIUSADMPWD" \ --radiusnasid="$MAC" \ --dhcpif $wifi_ifname \ > $TMP_C [ -n "$(cat $TMP_C)" ] && { MD5SUM_TMP=$(md5sum $TMP_C | awk '{ print $1 }') MD5SUM_ETC=$(md5sum $ETC_C | awk '{ print $1 }') if [ ! "$MD5SUM_TMP" = "$MD5SUM_ETC" ]; then rm $ETC_C mv $TMP_C $ETC_C circular_log $LOG_LOOP_F "RELOAD" do_reload else circular_log $LOG_LOOP_F "NO RELOAD" fi return 0 } circular_log $LOG_LOOP_F "NO RELOAD" } case $1 in restart) ALIVE=$(is_alive) if [ $ALIVE = "alive" ]; then exit 0 fi /sbin/insmod tun >/dev/null 2>&1 ifconfig $wifi_ifname 0.0.0.0 # deconfigure the wifi interface /usr/sbin/chilli \ --dns1="$WANIP" \ --dns2="$WANIP" \ --radiusnasid="$MAC" \ --dhcpif $wifi_ifname \ --pidfile=$PID_F circular_log $LOG_LOOP_F "RESTART" ;; start) ALIVE=$(is_alive) if [ $ALIVE = "alive" ]; then exit 0 fi radconfig /sbin/ifup hotspot /etc/init.d/S60redirect stop /sbin/insmod tun >/dev/null 2>&1 ifconfig $wifi_ifname 0.0.0.0 # deconfigure the wifi interface /usr/sbin/chilli \ --dns1="$WANIP" \ --dns2="$WANIP" \ --radiusnasid="$MAC" \ --dhcpif $wifi_ifname \ --pidfile=$PID_F if [ $? -eq 0 ]; then $0 loop & fi circular_log $LOG_LOOP_F "START" ;; radconfig) radconfig ;; stop) /sbin/ifdown hotspot ALIVE=$(is_alive) if [ ! $ALIVE = "alive" ]; then echo ERROR: chillispot is not running [ -f $PID_LOOP_F ] && kill $(cat $PID_LOOP_F) > /dev/null 2>&1 rm -f $PID_LOOP_F > /dev/null 2>&1 exit 0 fi [ -f $PID_F ] && kill $(cat $PID_F) >/dev/null 2>&1 rm -f $PID_F [ -f $PID_LOOP_F ] && kill $(cat $PID_LOOP_F) > /dev/null 2>&1 rm -f $PID_LOOP_F circular_log $LOG_LOOP_F "STOP" ;; loop) trap quit SIGINT SIGTERM SIGHUP SIGKILL echo $$ > $PID_LOOP_F while [ $LOOP = "true" ] ; do sleep 1 SECONDS=$(expr $SECONDS + 1) if [ "$SECONDS" = "$DELAY" ]; then radconfig fi SECONDS2=$(expr $SECONDS2 + 1) if [ "$SECONDS2" = "$DELAY2" ]; then $0 restart SECONDS2=0 fi done exit 0 ;; reload) do_reload exit 0 ;; alive) ALIVE=$(is_alive) echo "chillispot is $ALIVE" if [ $ALIVE = "alive" ]; then exit 1 fi exit 0 ;; *) echo "usage: $0 (start|stop|radconfig|reload)" exit 1 esac fi