BT Home Hub with pseudo SRV fallover for Sipsorcery

UPDATE!!! The pseudo SRV failover described here no longer works, as the Sipsorcery.com website is no longer co-hosted on the sip1.sipsorcery.com server. See here for info Sipsorcery hosting trial

I'm using the BT Home Hub set up as per BT Home Hub as voip wireless Cable router with the excellent and useful MySIPSwitch service (now known as Sipsorcery). The Sipsorcery service has developed into 2 servers with suitable SRV records to provide redundancy. The HH doesn't seem to support SRV records so the following folly shows how to run scripts on the HH to provide SRV-like functionality.

The principle is for the scripts to check connection status with both the Sipsorcery and another well known website. If the internet connection is down, or the connected Sipsorcery instance is down, then the script saves alternate user settings to the HH and reboots it to load the changes.

To get this to work the following steps are needed:
  1. get a telnet console on the HH as outlined in the Firmware area of this site http://www.homehubhacks.co.uk. See further details below,
  2. ftp into the HH using the new username and password, to get write permission it is best to reboot the router with only the pc connected on the lan, nothing else plugged in or wireless connected. Try the "ls -l" command directly in the / directory to test permissions, retry if needed,
  3. cd to the /dl directory and change to binary mode to put the utelnetd binary, the revised samba.conf file and the new "doit" script
  4. you'll need to plug a FAT formatted USB stick into the HH, this is needed to start the samba process, which in turn starts the new scripts,
  5. save the "webcheck" script and the alternative HH settings files in the base directory of the USB stick

The utelnetd binary can be found from the link above or alternatively can be taken from the DG834GT router firmware produced by the DGTeam. The DG834GT router has very similar hardware, big-endian linux kernel etc. With utelnetd installed you can use "telnet 192.168.1.253 4001" to get a linux console on the HH. Then the files can be edited using vi if you feel like it.

These bits of code need to be copied and pasted into appropriately named text files.


[samba.conf]
# Configuration for inventel modules import
#
/dl/doit


[doit]
# check if processes are already running first
#
!( ps | grep -v grep | grep -q utelnetd ) && ( /dl/utelnetd -p 4001 -l /bin/sh -d )
!( ps | grep -v grep | grep -q webcheck ) && ( /dl/disk/webcheck 6 & )


[webcheck]
# no need to check or reboot the HH at night
timecheck() {
    timenow=$(date +%H)
    if [ $timenow -ge 7 ] && [ $timenow -le 22 ] ; then
        return 1
    else
        return 0
    fi
}
groovy=1
forminutes=$1
while [ $groovy -ne 0 ] ; do
    sleep $(($forminutes*60))
    timecheck
    if [ $? -ne 0 ] ; then
        wget -O "/dev/null" "http://www.google.com" >/dev/null 2>&1
        if [ $? -ne 0 ] ; then
#system reboot only
            groovy=0
        else 
            wget -O "/dev/null" "http://www.sipsorcery.com" >/dev/null 2>&1
            if [ $? -ne 0 ] ; then
#sipsorcery website not found
                grep -q "sipsorcery.com" "/dl/user.ini" 
                if [ $? -eq 0 ] ; then
#sipsorcery website not found and sipsorcery.com is setup
#change to sip2.sipsorcery.com setup
                    groovy=0
                    cp "/dl/disk/ss2_user.ini" "/dl/user.ini"
                fi
            else
#sipsorcery website found
                grep -q "174.129.234.254" "/dl/user.ini"
                if [ $? -eq 0 ] ; then
#sipsorcery website found and ss2 is setup
#change to sipsorcery.com setup
                    groovy=0
                    cp "/dl/disk/ss_user.ini" "/dl/user.ini"
                fi
            fi
        fi
    fi
done
reboot


From the webcheck script you can see the alternate HH user setting files are named ss_user.ini and ss2_user.ini respectively. The ss_user.ini file needs to use the primary and reg proxy of sipsorcery.com.
The ss2_user.ini file uses the ip adress of sip2.sipsorcery.com, check with "nslookup -q=srv _sip._udp.sipsorcery.com".
The script relies on the fact that sip1.sipsorcery.com and www.sipsorcery.com have the same ip address. The sip2.sipsorcery.com ip address is hardcoded into the script. If you use a text editor like Scite then the webcheck, ss_user.ini and ss2_user.ini files can be edited in place on the samba share.

Ideally you should use the wget --spider option to check without downloading data, this needs the full version of wget. The busybox wget used here downloads 134 bytes, 10 times/ hour, 16 hours/ day to give 628kb/ month from Sipsorcery.

Related Articles

MySIPSwitch
BT Home Hub as FXS
BT Home Hub as voip wireless Cable router
UPDATE!!! The pseudo SRV failover described here no longer works, as the Sipsorcery.com website is no longer co-hosted on the sip1.sipsorcery.com server. See here for info Sipsorcery hosting trial

I'm using the BT Home Hub set up as per BT Home Hub as voip wireless Cable router with the excellent and useful MySIPSwitch service (now known as Sipsorcery). The Sipsorcery service has developed into 2 servers with suitable SRV records to provide redundancy. The HH doesn't seem to support SRV records so the following folly shows how to run scripts on the HH to provide SRV-like functionality.

The principle is for the scripts to check connection status with both the Sipsorcery and another well known website. If the internet connection is down, or the connected Sipsorcery instance is down, then the script saves alternate user settings to the HH and reboots it to load the changes.

To get this to work the following steps are needed:
  1. get a telnet console on the HH as outlined in the Firmware area of this site http://www.homehubhacks.co.uk. See further details below,
  2. ftp into the HH using the new username and password, to get write permission it is best to reboot the router with only the pc connected on the lan, nothing else plugged in or wireless connected. Try the "ls -l" command directly in the / directory to test permissions, retry if needed,
  3. cd to the /dl directory and change to binary mode to put the utelnetd binary, the revised samba.conf file and the new "doit" script
  4. you'll need to plug a FAT formatted USB stick into the HH, this is needed to start the samba process, which in turn starts the new scripts,
  5. save the "webcheck" script and the alternative HH settings files in the base directory of the USB stick

The utelnetd binary can be found from the link above or alternatively can be taken from the DG834GT router firmware produced by the DGTeam. The DG834GT router has very similar hardware, big-endian linux kernel etc. With utelnetd installed you can use "telnet 192.168.1.253 4001" to get a linux console on the HH. Then the files can be edited using vi if you feel like it.

These bits of code need to be copied and pasted into appropriately named text files.


[samba.conf]
# Configuration for inventel modules import
#
/dl/doit


[doit]
# check if processes are already running first
#
!( ps | grep -v grep | grep -q utelnetd ) && ( /dl/utelnetd -p 4001 -l /bin/sh -d )
!( ps | grep -v grep | grep -q webcheck ) && ( /dl/disk/webcheck 6 & )


[webcheck]
# no need to check or reboot the HH at night
timecheck() {
    timenow=$(date +%H)
    if [ $timenow -ge 7 ] && [ $timenow -le 22 ] ; then
        return 1
    else
        return 0
    fi
}
groovy=1
forminutes=$1
while [ $groovy -ne 0 ] ; do
    sleep $(($forminutes*60))
    timecheck
    if [ $? -ne 0 ] ; then
        wget -O "/dev/null" "http://www.google.com" >/dev/null 2>&1
        if [ $? -ne 0 ] ; then
#system reboot only
            groovy=0
        else 
            wget -O "/dev/null" "http://www.sipsorcery.com" >/dev/null 2>&1
            if [ $? -ne 0 ] ; then
#sipsorcery website not found
                grep -q "sipsorcery.com" "/dl/user.ini" 
                if [ $? -eq 0 ] ; then
#sipsorcery website not found and sipsorcery.com is setup
#change to sip2.sipsorcery.com setup
                    groovy=0
                    cp "/dl/disk/ss2_user.ini" "/dl/user.ini"
                fi
            else
#sipsorcery website found
                grep -q "174.129.234.254" "/dl/user.ini"
                if [ $? -eq 0 ] ; then
#sipsorcery website found and ss2 is setup
#change to sipsorcery.com setup
                    groovy=0
                    cp "/dl/disk/ss_user.ini" "/dl/user.ini"
                fi
            fi
        fi
    fi
done
reboot


From the webcheck script you can see the alternate HH user setting files are named ss_user.ini and ss2_user.ini respectively. The ss_user.ini file needs to use the primary and reg proxy of sipsorcery.com.
The ss2_user.ini file uses the ip adress of sip2.sipsorcery.com, check with "nslookup -q=srv _sip._udp.sipsorcery.com".
The script relies on the fact that sip1.sipsorcery.com and www.sipsorcery.com have the same ip address. The sip2.sipsorcery.com ip address is hardcoded into the script. If you use a text editor like Scite then the webcheck, ss_user.ini and ss2_user.ini files can be edited in place on the samba share.

Ideally you should use the wget --spider option to check without downloading data, this needs the full version of wget. The busybox wget used here downloads 134 bytes, 10 times/ hour, 16 hours/ day to give 628kb/ month from Sipsorcery.

Related Articles

MySIPSwitch
BT Home Hub as FXS
BT Home Hub as voip wireless Cable router
Created by: jadam, Last modification: Sat 01 of May, 2010 (20:02 UTC)
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+