So you've talked up a good 'home IT' solution to the finance manager (i.e. The Wife) - you've visited Amazon (or Kikatek in my case), splashed your green all over the internet .... bemoaned the fact that you allowed the thing to be shipped 2nd class to save yourself circa £1.50 in delivery costs ... danced with glee as Pat and Jess come knocking on your door with a parcel ... powered the thing up, only to find that something is wrong. Terribly wrong in fact.
IT DOESN'T DO WHAT IT'S SUPPOSED TO!!!
You can take that statement two ways. Either the manufacturer advertised functionality that wasn't present upon inspection - or - whilst you were dreaming up a nerdy home IT solution, you allowed your imagination to colour in some feature that you really really wanted but actually found out all too late wasn't ever promised. Worse still - you either have to make it work, or explain to the finance manager why the thing you just purchased might not quite work the way you had promised.
And so it was for me with the SPA3102. The IP telephony and PSTN convergence unit did everything it promised - but it did not promise time based / scheduled dial plans. You see, I had foolishly promised the wife that I would be able to use the SPA3102 to seamlessly switch between cheap voip calls during the working day and free BT calls in the evenings and weekends. "I don't want any more fuss" she said. "I can't be arsed with all this messing about so if it's more hassle for me then it's going straight back and you can live with the expensive and lengthy phone calls to my mother." However, the SPA3102 would not let me so this! I could have one dial plan .. and bleedin well like it!!
YES - A CISCO/LINKSYS SPA3102. IF YOU DIDN'T KNOW THIS ALREADY AND HAD READ THIS FAR .. THEN I'M IMPRESSED! AWARD YOURSELF A COOKIE.
As a starter for 10, I configured the plan to dial voip by default for all but emergency calls - but allowed the option of routing through PSTN by virtue of prefixing all numbers with a '9'. Let me tell you, the 'dial 9 for a line - evenings and weekends' awareness program in our house didn't go down very well. I could sing it .. I could dance it .. I could stick it in my pipe and smoke it.
There was no option, I had to find a way round the issue. At the back of my mind I already knew that it would require Linux somwhere and some extensive time at the University of Google. Determination (plus a few lucky page hits) paid off and I've now found a way to switch between to separate dial plans for the SPA3102 - abandoning the need to hit 9 for PSTN in the evenings.
So here follows my mini 'How To' for time based dial plan scheduling on the SPA3102. Please note - these are 'guidelines' explaining how I managed to get this working. You follow them at your own risk. At the very least - ensure that you have tested backup and restore prior to messing around with your config. I also assume that this is your kit and that you don't mind if it breaks. I don't want anyone to visit supermonkeyhaha land with a broken SPA3102 and a baseball bat.
AIM: Get the Cisco Linksys SPA3102 unit to switch dial plans on a timed basis.
REQUIRED: Basic understanding of HTML / A Linux server on the LAN / Firefox web browser / SPA3102 (this may well work with other similar units) and a general understanding of how that unit operates. If you require a configuration guide (UK) then I recommend: Andrew Oakley's brilliant guide which can be found here: http://www.aoakley.com/articles/2008-01-08.php
ASSUMPTION: Your SPA3102 is sitting on an existing LAN converging VOIP and PSTN - not acting as a gateway. This process will briefly reboot your SPA3102 and result in loss of gateway services (probably).
OVERVIEW: We're going to dump out different configurations that we would like to use on the SPA3102 (including our varying dial plans) - then we're going to convert that extracted data in to separate uncomplicated dial plan scripts. We will then set up a schedule to trigger the scripts to update the SPA3102 with the required dial plan.
In my example, I'm going to create one script for VOIP centric calls between midnight and 6pm and then another to route all calls via PSTN between 6pm and midnight.
First things first. Key to this solution is an understanding of the manual 'save as' backup and recovery method found here - http://voipstuff.net.au/SPA3000.html#toc10
As you will see - it's surprisingly easy to copy out and restore back configs to the SPA3102 without the need for fancy tools. Now what we need is to save a backup for each version of the dial plan that we want in our time based schedule. Let's say I've called mine voip.htm and pstn.htm
Now - edit each file using a text editor (notepad etc) and search for the form tag. Switch the method from POST to GET. Additionally - amend the action so that it's action=http://*your SPA3102 name or IP goes here*
If you then load the page with Firefox (I had issues trying this with IE 8) and submit the form - lo and behold, your address bar is absolutely packed with all the config variables that you need. Copy them out somewhere for safe keeping (notepad etc).
Now - log on to your Linux server and change in to your scrpits directory (or create one). Mine is /opt/scripts
Create a script file for each plan you wish to schedule and make it executable. So for my voip dial plan it would be:
chmod +x voip
Open it with your favourate text editor and add #!/bin/bash to the first line. On the next line type curl -d ""
Now return to the data you copied out of Firefox. Copy everything apart from the URL (basically the entire SPA3102 config) and then switch back to the script on your Linux host. Past the contents between the quotes.
Now go back to the Firefox data and copy the URL (excluding the ? at the end) and place that in your Linux script right at the end ensuring that there is a space before http://
You should now have a script file that goes something like this:
curl -d "xxxxxxx lots and lots of config data goes here" http://myspa3102/admin/asipura.spa
Now save the file.
If you don't have curl installed - install it using standard repository tools for your distro (apt-get or yum install .. etc etc).
Rinse and repeat for each dial plan variant you have captured. Now you're ready to test the scripts individually to see if curl posts the config to the SPA3102. So, for my voip script, from the command line it's: ./voip
After this has run - you will get a text based equivalent of the confirmation page in the console notifying you that change is about to be applied. Wait 10 seconds and then log in to the SPA3102 and check your dial plan. If everything has gone according to plan, you should see the dial plan info relating to the script that you've just submitted. Now repeat the process for another dial plan to ensure that the dial plan changes accordingly.
OK .. all being well, you'll have seen the dial plans switch purely by scripting. The next step is to enable time based scheduling with cron
Edit crontab with the command: crontab -e
Here's an example of my crontab. Two entries listed - the first to run at 23:59 Sunday to Thursday. 59th minute - 23rd hour - every day of the month - every month - days 0 (Sunday) to 4 (Thursday) - invoking /opt/scripts/voip
The second second runs /opt/scripts/pstn at 6pm - Monday to Friday
# m h dom mon dow command
59 23 * * 0-4 /opt/scripts/voip
0 18 * * 1-5 /opt/scripts/pstn
Now you have your crontab in place, your dial plan configs should be set according to your schedule and hey presto - no more 9 for a line. Just remember that if you make changes to your system - unless you update your scripts to reflect those changes, you'll lose them next time cron kicks in.
Hey! I never said it was perfect!