Voipfone Outbound Calls and Asterisk (“Sorry your call can’t be connected. Please try again.” / “SIP/2.0 603 No Funds”)

So I recently tried to use our voipfone sip trunk to make outgoing calls through Asterisk, but every time I was met with the voice message:

Sorry your call can’t be connected. Please try again.

No explanation as to why the call could not be connected, but a wild guess was either lack of funds or an incorrect (incompatible) voice codec.  Of course I had plenty of funds in my account, so it wouldn’t be that…  of course it was that…!

Thanks largely to the guidance here…

https://newspaint.wordpress.com/2014/09/01/voipfone-peer-with-asterisk-reports-no-funds/

…I was able to get everything working again.

Step 1. Enable sip debugging

If you are using standard SIP:

myuser@myhost:~# asterisk -r
myhost*CLI> sip set debug on

If you are using PJSIP, as I am:

myuser@myhost:~# asterisk -r
myhost*CLI> pjsip set logger on

Step 2. Attempt to make a call, look out for “no funds” in the resulting output.

<--- Received SIP response (506 bytes) from UDP:195.189.173.27:5060 --->
SIP/2.0 603 No Funds
Via: SIP/2.0/UDP 81.81.81.201:5060;branch=z9hG4bKPjtWSYFBs-zTgo2KBlXF9F-P6g9ZK.vxV4;received=81.81.81.201;rport=55789
From: <sip:+441234567890@192.168.12.1>;tag=NF.2onpp6RwXWwzv5EZ1AEhPqYg5ZWRc
To: <sip:07979123456@sip.voipfone.net>;tag=VF833277c221dd5bcb746022eee871
Call-ID: lRNbTh5BCdgKXFxUUtXOQXNAzO5dkcIq
CSeq: 2697 INVITE
User-Agent: Voipfone Sip Network
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER
Contact: <sip:07979123456@195.189.173.27>
Content-Length: 0

Step 3: Fix the From Header

As outlined in the NewsPaint link at the top, it is the From header with which Voipfone take issue.  They require the bit before the @ to be your Voipfone username.  In a standard SIP setup, as outlined in NewsPaint, just change your fromuser and all will be well.  With PJSIP, and specifically in my case PJSIP with FreePBX, I found that changing the Outbound CallerID to be my Voipfone username was the golden ticket.  Once that’s done, rerun your test and you should be able to make calls and see the following in the PJSIP debug:

<--- Transmitting SIP request (424 bytes) to UDP:195.189.173.27:5060 --->
ACK sip:07979123456@sip.voipfone.net:5060 SIP/2.0
Via: SIP/2.0/UDP 81.81.81.201:5060;rport;branch=z9hG4bKPjhqy0-4Ze4JfeuCuHTJfyohKk3hWEY72A
From: <sip:30119522@192.168.12.1>;tag=46qJcC9IEiSdoi3e6hg.RTJ7.cmlvyAM
To: <sip:07979123456@sip.voipfone.net>;tag=VF3e77bf499c95471cab435113528a
Call-ID: WsaWl2hr828RYQTo0F4hZgQSnmvP9T2h
CSeq: 30 ACK
Max-Forwards: 70
User-Agent: FPBX-12.0.76.2(13.9.1)
Content-Length:  0

All done!

Apache 200 OK Internal Server Error / Misconfiguration Caused By Infinitely Recursive PHP Function

*Sigh*!

So, I’ve just spent about 3 hours troubleshooting a weird bug with a PHP application that we’re currently writing.  The symptom was the following, rather odd, error message:

200 OK – The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, <email>, and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Ok, so I’ve seen plenty of internal server errors before (those thrown by Apache HTTPD), but never one thrown with a 200 OK status code (you’d expect a 500 error code instead).

200 OK - Internal Server Error - Displayed

Weirdly, I was only seeing this error in my application because the offending access was an AJAX call which displays the result in a div on my page.  If I was to submit my POST data directly to the page in question, I get prompted to download a file matching the name of the page I tried to access.  The error is actually contained inside this text file.

200 OK - Internal Server Error - Download File

Another top tip there then, if your web app unexpectedly asks you to download a file, do so and check it out in notepad to see if it contains clues!

A cursory read around suggests that this implies that the error occured AFTER the status code was sent.  That should have been my first clue, I suppose.

It turns out that, in my case, I had written an infinitely recursive function into some PHP code and this was causing Apache to throw its toys out of the pram, rather than causing PHP to throw an out of memory or maximum execution time error as I would expect.

The culprit function was as follows:

public function getTax($recursive=false)
{
    $tax = $this->getTax();

    if($recursive) {
        foreach($this->getItems() as $item) {
            $tax += $item->getTax($recursive);
        }
    }
    return $tax;
}

Yes… what I meant to say on line 3 was:

 $tax = $this->tax;

A fairly straightforward bug, a silly mistake, but a cryptic result – an Apache 200 OK Internal Server Error!  Fix the bug et voilà:

200 OK - Internal Server Error - Expected

So if you see this error yourself, it could be a mistake with your PHP code – check it out (save and revert to a previous version if you can – Git is awesome for that)!

Synology DiskStation and Asterisk – Voicemail Hangs Up After Greeting, Before Taking Message

Recently, I had cause to set up an Asterisk server at home to handle a couple of VoIP SIP numbers that I have.  What better chance, I thought, to try out the Asterisk package for my Synology NAS.

The install from the Synology package manager was a breeze, but I immediately hit an issue when I tried to implement voicemail.  Essentially, callers were played the greeting, but given no opportunity to leave a message.  The line just dropped.

The Asterisk command line was throwing messages similar to the following:

Auto fallthrough, channel 'SIP/**********' status is 'NOANSWER'

And I could see the following messages in /var/packages/Asterisk/target/var/log/asterisk/messages:

[Jul  3 17:08:59] WARNING[18808] app_voicemail.c: Invalid max message time length
[Jul  3 17:08:59] WARNING[18808] app_voicemail.c: Invalid min message time length
[Jul  3 17:08:59] WARNING[18808] app_voicemail.c: Invalid max message greeting length

It turns out that the values under “Voicemail” in the Asterisk GUI (at http://nas:8088/asterisk/static/config/index.html, by the way) for “Maximum Messages Per Folder”, “Max Message Time” and “Min Message Time” are left blank by default.

You might assume that these can be left blank if you do not want to impose limits.  You would assume wrongly.

Set the values and voicemail will now take your messages!

Git Stash Can Delete Ignored Files (git stash -u)

If you’ve arrived here from a search engine, I only hope that this is a pre-emptive search on your behalf and that you haven’t lost work.

Sadly, I have.

The background – I’m using TortoiseGit on Windows, with msysgit sitting beneath it (a standard setup).  For the sake of this explanation, assume I have the following Git repository structure.

./my-tracked-directory/
 --> my-first-tracked-file.txt

./my-untracked-directory/
 --> my-untracked-file.txt

./my-ignored-directory/
 --> my-ignored-file.txt

./my-second-tracked-file.txt
./.gitignore

Recently, I ran the following command from TortoiseGit:  TortoiseGit -> Stash Save (Tick “Include Untracked Files”).

This is the equivalent of running git stash save -u (or git stash -u which defaults to a save) from an msysgit command line.

To cut a long story short, if you run git stash save -u (whether from TortoiseGit or the command line) and you have a directory which is untracked and not ignored, but which has files within it that are, the entire directory and all files will be removed.  Yikes!

To put it another way, if you have the following in your .gitignore:

/my-ignored-directory/*

Then you’re screwed – after a git stash save -umy-ignored-file.txt will be gone (and sorry, it’s not in the stash you just created either).  Break out the undelete packages and hope for the best.  Alternatively, if you have the following in your .gitignore:

/my-ignored-directory

Then you’re golden – no worries, kick back, relax, my-ignored-file.txt will stay exactly where it was prior to the git stash save -u.

Oh and one last tip.  If you actually want to stash your ignored files, git stash save -a is the command you’re looking for.  As far as I’m aware, TortoiseGit does not yet offer this option.

UPDATE:

There are suggestions that this might be a bug in Git: msysgit: stash -u deletes ignored files

Which may have been experience by other TortoiseGit users: Ignored folders can be destroyed by TortoiseGit.

And may also have been experienced in the gitextensions tool: Stash removes ignored files

Though in that last link, the words “expected behaviour” are mentioned so I guess we’ll wait and see…!

UPDATE 2:

It seems that this might be the behaviour of git clean -d (the -d indicating “delete untracked directories”).  git stash save -u issues a git clean command after stashing files.  If this command includes the `-d` option (as I suspect it does) then this is what causes the deletion of an untracked directory containing ignored files.

It seems that others have noticed the issue with git clean -d: Clean bug on ignored subdirectories with no tracked files

To summarise:

git clean -d will delete all untracked directories including those containing ignored files.

Hyper-V Configuration Tool (Blue Window)

Just a quick one today – we run a Hyper-V Server to host our Virtual Machines (VMs).  The interface to Hyper-V server is a command line.  When you first start a Hyper-V Server up, you are presented with two windows: a standard black command window and an additional blue window which has some useful configuration commands.

If you accidentally (or deliberately) close the blue window, you might be at a loss as to how to get it back again.  A search of the Web proved that it can be somewhat difficult to find the solution!  So here it is – hopefully the Google Bots will make this nice and easy to find.

On Hyper-V Server 2008: C:\Windows\System32\hvconfig.cmd

On Hyper-V Server 2008 R2: C:\Windows\System32\sconfig.cmd

As C:\windows\System32 is in the path, you actually just need to type hvconfig or sconfig but I thought I’d leave the path in for completeness.

Hope that helps!

CyanogenMod and Link2SD –

I’m a big fan of smartphones – have been ever since the first Windows PDAs.  I guess it must have been the well styled user interface (!), or the convenient portability of a house brick! Well, how things have progressed since then…

I’m definitely a fan of Android – the move from Windows Mobile to Android was not a difficult one, and I feel I chose a great phone on which to make the move, the Google Nexus One.  To this day, I’ve still got the Nexus One and there’s very little I want for.  Yes, it would be nice to have a front-facing camera; perhaps an HDMI-out; NFC looks to be gaining speed too…  By far the most frustrating thing about the Nexus One, however, is its tiny internal memory.  You can barely fit any apps on its swiss-cheese of a brain.

That’s where Link2SD comes in – essentially a more configurable version of Apps2SD, allowing you to move all apps to the SD card, but to do this selectively.  For instance, I leave my important apps on the internal memory, but move anything that’s not quite so important to the SD card.  Oh, and by the way, this is to a separate space on the SD card so even widgets will work when you move the associated apps.  Remember that annoying artefact of using the built in “Move to SD” functionality only to find that you can no longer use the associated widget?

Anyway, installation is relatively easy.  You’ll need a rooted device, I’m afraid, and you’ll need to partition your SD card, so that you have a space in which the apps can live.  If you’ve rooted, you likely have ClockworkMOD Recovery.  Boot yourself into that, by holding volume-down whilst turning on the phone.  In the advanced menu, you’ll find an option to partition sd card.  Select it – remember that this will wipe everything from your SD card so be sure to have a backup.  I suggest selecting 1024MB ext size and 0mb cache from the options.

Once you’re done, reboot into android and download Link2SD from the android market.  Once you have it, launch it and it will attempt to create a script to make the new partition you created on your SD card available at boot.  This is where, if you have CyanogenMod (as you likely do), you’ll hit the first stumbling block.

Link2SD wants to create a folder at /data/sdext2 that links to the partition on your SD card.  By default, however, CyanogenMOD has already mounted your new partition at /sd-ext.  As soon as Link2SD attempts to mount this already mounted partition an error is thrown (you can’t mount a partition to two locations like this):

Mount script error
Mount script cannot be created.
mount: mounting /dev/block/vold/179:2 on /data/sdext2 failed: Device or resource busy

To solve this, you’re going to need to go into the Terminal application available in the app drawer (you could also use ADB, which will allow you to do this on a computer rather than your tiny android phone, but you don’t have to do this).  The easiest fix is to manually create the script that Link2SD requires.  Linux (and Android, which is based on Linux) looks in /etc/init.d/ for scripts that run at bootup, so this is where you’ll be looking to place the script that will mount the sd card partition in the location that Link2SD expects it.  So, let’s get going – in terminal, type the following:

cd /etc/init.d/
su
mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
echo “#!/system/bin/sh” > ./11link2sd
echo “mount -t ext3 -o bind /sd-ext/ /data/sdext2/” >> ./11link2sd
chmod 750 ./11link2sd

Reboot your phone and you can start using Link2SD.  Check it’s working by going into Link2SD and choosing Storage Info from the menu.  If you can see space available on “SD Card 2nd Part”, you’re golden.

Enjoy Link2SD!

VPS.Net – The Future of Web Hosting?

I’ve been meaning to write this review for some time now, but a rather long night battling with Galera MySQL Database replication last night has encouraged me to finally put pen to paper (or pixel to screen?).

It’s not the ins-and-outs of database replication that I want to share with you today, however, it’s the web hosting which has been the home of both my personal and my business web applications for the past 14+ months.

So, VPS.net – what is it and why is it different?  Well, it’s based in “the cloud”, if buzzwords are your thing!  All that means to us on the ground, though, is that it is immensely scalable and flexible.  Say, for example, I have a site hosted with VPS.net and one day I send out an email and am expecting an influx of visitors… I don’t want my site to crash under the weight of traffic, but I also don’t want to permanently upgrade the hardware on which it is running for the sake of one day (my typical traffic level is much lower).  No problem with VPS.net, I can buy “daily nodes” to upgrade the power of my hosting for just the time I need.  And what’s more, the upgrade happens without a single minute of downtime – it’s a completely online process!  Making it happen is just a case of dragging a slider and clicking “Go”!  Then once I’m done, I simply drag the slider in the other direction to remove the daily nodes.  Easy peasy.  How many sites have you seen that could use this kind of technology to avoid crashing under a totally predictable increase in traffic.  But what about unpredictable traffic?  Well, you’re covered there too.  Thanks to an integration with the folks at ServerDensity monitoring, you can set your hosting to “auto-scale”, adding nodes as necessary, if an excessive load is detected.  So now you never have to worry about your site collapsing under the pressure of traffic, expected or otherwise.

So that’s why VPS.net is different, primarily, but it doesn’t stop there.  The guys are always looking for ways to add extra value to the product.  So, you can have free SSL certificates, free ISPManager PRO control panel, free Blesta billing system and a host of other goodies – did I mention they were free?

Sounds amazing, huh?  And it is – the philosophy and product offering are hard to beat.  It’s not all been plain sailing, though, and it would be remiss of me to pretend otherwise.  The last 12 months has been tough at times.  Reliability is not as good as it should be, and I’ve had websites down for an entire day at times.  If you decide to go with VPS.net, you MUST make sure that you have a regular and comprehensive backup plan.  I’m sorry to say that there has been a time when I would have lost nearly everything without my backup.  Also, whilst communication is great at times of relative calm, and the guys at VPS.net are amongst some of the friendliest I’ve encountered, when something goes wrong they’re simply too oversubscribed.  Tickets go unanswered, status pages are not updated and it can be a wholly frustrating (and costly) experience.

VPS.net know where their problems are, though, and that is reassuring.  Their team are regular visitors to the forum and they seem willing to engage in open discussion on the good, the bad and the ugly.  And to give credit where credit is due, things have improved over the last year.  Downtime has decreased and the team are making positive steps to improve communication.  We now have a telephone support number (UK and US) and the status blog is better than it used to be (albeit still not perfect).

If you’re thinking of giving them a go, I’d say this.  Try them out with something non-critical first (there are sometimes offers around for a free month etc.).  And when you have enough confidence to host something more important with them, make sure that you have backup plans, both for downtime and data loss (a good idea no matter who you’re with, to be honest).  I’m optimistic that the future is bright for VPS.net – I can see light at the end of the tunnel: a time when I can return to this post and tell you all that the service is now 100% stable!  If I was a betting man, my money would be on six months.

All things considered, though, I don’t regret staying with VPS.net through the good times and the bad (though on some late nights I would have cursed and told you otherwise!).  The truth is that, for all the difficulties, the positives are just so damn compelling that you want to stay, you need to stay.  And if you can put in place measures that mean that the negatives don’t hit so hard (database replication, backups, failover etc.) then the reasons not to stay seem to drift somewhat into the background.

Visit VPS Net

Welcome

Well, I’ve been threatening to do it for some time, but I’ve finally got myself together and created somewhere that I can store my thoughts, discoveries, tutorials as and when they occur to me!  Part aide memoir, part blog, only time will tell what future posts will hold!

Stay tuned!