Archive for the ‘Tips or Tricks’ Category

The Default Ruby Dial Plan Demystified

Tuesday, August 5th, 2008

Default Ruby dial plan line by line.

When getting started, the default Ruby dial plan can be a bit hard to understand and many people don’t really know what to edit inside. This small article is aiming at explaining the basics so you can get started easier.

The first thing to mention is that with My SIP Switch there are 2 (very) different syntaxes for the dial plans. The “old one” is based on Asterisk syntax and using lines like that: “exten => …”. The new one is based on Ruby scripting and his much more powerful. You cannot use both syntaxes in the same dial plan! You need to pick one.

Here is the default Ruby dial plan (as of July 2008 and minus a few comments for clarity):

#Ruby

sys.Log(”call from #{req.Header.From.FromURI.ToString()} to #{req.URI.User}.”)

if sys.In then

# Do your incoming call processing customisations here.

sys.Dial(”#{sys.Username}@local”)

else

# Do your outgoing call processing customisations here.

case req.URI.User

when /^303$/ then sys.Dial(”303@sip.blueface.ie”)

when /^612$/ then sys.Dial(”612@fwd.pulver.com”)

when /^\*1/ then sys.Dial(”${dst:2}@provider1″)

when /^\*2/ then sys.Dial(”${dst:2}@provider2″)

when /^\*3/ then sys.Dial(”${dst:2}@provider3″)

else sys.Dial(”provider1″)

end

end

A Ruby dial plan must start with the line (Never remove that line):

#Ruby

The lines starting by # are comments. They are not interpreted as part of the dial plan. I removed most of them here.

The line:

sys.Log(”call from #{req.Header.From.FromURI.ToString()} to #{req.URI.User}.”)

will “log” all calls into the monitoring page. That allows to keep track of what’s going on and also to debug when you are testing the service.

The syntax is the following: sys.Log(” my log here “)

If you want to insert a variable into a log, you can use #{variable_name} for instance : #{req.URI.User}, as you’ve seen in the example above.

Then, starts the actual dial plan!

Inbound and outbound calls are clearly separated with the following structure:

if sys.In then

# INbound calls here

else

# OUTbound calls here

end

When you receive a call: sys.In will be equal to “True” and only the code between “then” and “else” will be interpreted.

The next line, starting with a #, is not interpreted. It’s a comment.

Incoming calls:

sys.Dial(”#{sys.Username}@local”)

That line, when interpreted, will call the phone which is registered to My SIP Switch.

sys.Username is a variable as is, it must not be changed! It will be equal to your actual username. Don’t do anything like that: sys.JohnSmith ; that would trigger an error.

If you want to receive your incoming calls on another phone, you can edit this line like that:

sys.Dial(”123456@myprovider”)

Where 123456 is the number you want to dial with the provider: myprovider (the provider’s name used here are the ones you set up when adding a new provider, in the 1st field).

That’s it of the incoming calls on this guide.

If you need further help, you can refer to this article:

Inbound Call Management with Ruby Dial Plans

You can also refer to these threads on the forum:

http://www.mysipswitch.com/forum/viewtopic.php?t=139

http://www.mysipswitch.com/forum/viewtopic.php?t=399


Then for the outgoing calls, by default we have:

case req.URI.User

when /^303$/ then sys.Dial(”303@sip.blueface.ie”)

when /^612$/ then sys.Dial(”612@fwd.pulver.com”)

when /^\*1/ then sys.Dial(”${dst:2}@provider1″)

when /^\*2/ then sys.Dial(”${dst:2}@provider2″)

when /^\*3/ then sys.Dial(”${dst:2}@provider3″)

else sys.Dial(”provider1″)

end

case req.URI.User is another test based on “pattern” which include several possibilities: each when represent a different situation if the outgoing call can’t be match to any of those cases then my SIP switch will follow the else rules.

As pattern match tool, we are using Regular Expressions (everything between /^ and / is a regular expression).

when /^303$/ then sys.Dial(”303@sip.blueface.ie”) means that when you dial 303 on your SIP phone. You will hear Blueface speaking clock.

when /^612$/ then sys.Dial(”612@fwd.pulver.com”) means that when you dial 303 on your SIP phone. You will hear FWD speaking clock.

when /^\*1/ then sys.Dial(”${dst:2}@provider1″)

Any number starting by *1 will match this case. Note that the * is a special character so we need a \ before it. ${dst:2} is representing the number you dialed minus the 2 first digits (*1 here).

If you called your provider something different than “provider1″ you’ll need to modify this! It must be one of the names you set as provider. If you don’t do that, when calling, you’ll notice an error message in the monitoring page saying : “Cannot resolve provider1″.

when /^\*2/ then sys.Dial(”${dst:2}@provider2″)

when /^\*3/ then sys.Dial(”${dst:2}@provider3″)

Same thing with *2 and *3.

else sys.Dial(”provider1″) Forward outgoing calls to provider1.

If you dialed a number which doesn’t start by *1, *2 or *3 then this line will be used. That’s the provider by default. Note that there is not ${dst} involved, since here you don’t need to remove any digit but to dial the number as is.

If you wanted to match any UK number and dial them with a specific provider you can do something like that:

when /^0044.*/ then sys.Dial(”0${dst:4}@ukprovider”)

Any number starting by 0044 will match the case, and then we remove the 0044 and replace that by a 0 (to adjust to local dialing). Then the resulting number is called via the provider named: ukprovider.

Then we have the closing tags “end” of the IF and of the CASE. Make sure not to remove them!

Remember that, this is a basic guide so I mentioned only a few possibilities of the software. If you want to go further you can refer to our forum and blog; quite a few examples have been written there.

Guillaume

PS : Thanks Thomas for the draft you made about this article ;)

Change or Reset NT passwords

Monday, May 26th, 2008

This article is a bit off topic on this blog but I found the tool so powerful and easy to use that I wanted to share this.

I needed to start a computer running Windows XP SP2. The former user had a password on his account (account with admin rights) and I had no way to contact him.

I used a tool which allows editing or resenting the password of any of the user account on the computer.
That doesn’t recover the password (at least I don’t think so), that allows to reset or to allocate a new one. According to their website it works for Windows NT versions : 2000, XP, Vista.

Here is the link: http://home.eunet.no/~pnordahl/ntpasswd/

Basically you simply need to

  • Download the CD image (.iso file) and burn is as an image on a CD (or DVD) (it also work with a floppy disk)
  • Boot from that CD (you may need to modify the boot sequence in the Bios)
  • You will be asked a few question like which partition is Windows installed on, where is the registery with the SAM file … (some value are added by default and if your configuration is “classic”, they will be the correct ones)
  • Change or reset the password for a user (you can retreive the list of users)
  • Save the changes and restart the computer

You need less that 10 minutes all together. That’s brillant.

That also makes you realise a few security threats on a windows computer : get the boot sequence to start from the hard drive first (that will prevent anyone trying to boot your computer with that kind of software and change your password) and also lock the Bios changes with a password so that anyone cannot change the boot sequence.

Guillaume

How To compose a Transparent Dialplan

Tuesday, May 13th, 2008

A simple dialpan rule may look like this:

exten => _X.,1,Switch(VOIPBUSTER)

or:

exten => _X.,1,Switch(${EXTEN}@VOIPBUSTER)

(to set other $ and {EXTEN} values)

(at the bottom of this blog, you’ll find a Ruby translation)

This will dial all you dial (exactly) with provider VOIPBUSTER or any other, which you gave that name, When you registered that provider, with that particular “Provider Name”

But this would mean, you only can make a phonecall, when you dialed the complete International dialing sequence, also for someone that lives in your own city, that’s a bit clumbsy,

and you have to “instruct” the other people using your phone system, So, you want to overcome this, and it can !

Here comes the “transparent” part !

Say, you always have to dial: (i’m living in the Netherlands) 0031 for the Netherlands, and 020 for Amsterdam, and 1234567 for the subscriber, what should be dialed is: 0031201234567 (notice the first 0 of the city dial code should not be dialed, when dialing internationaly) Your dialplan rule could look like this:

exten => _ZX.,1,Switch(003120${EXTEN}@VOIPBUSTER)

The first part in the dialplan detects you are not dialing a zero, (expression letter is used, for a value in the 1 - 9 range) see the dialplan expressions list below.

Now, this will be dialed by MySIPSwitch: 003120 + what you have dialed in the first place.. For dialing nationaly/internationaly, you can figure out in the same way a “plan” detecting te amount of zero’s depending how “far” the call will go, nationaly:

exten => _0ZX.,1,Switch(0031${EXTEN:1}@VOIPBUSTER)

or internationaly:

exten => _0032X.,1,Switch(${EXTEN}@VOIPCHOICE)

and according to the country code, which provider you want to use for that destination, that is the cheapest way to do so…. you use one of the Provider (Name)’s, you have registered.

btw. keep in mind you ‘re using your dialplan at MySIPSwitch, so you do not do this in your ATA or SIP phone, these settings should be completely transparent, and accept all combinations, and do nothing with it, just pass it through, otherwise your dialplan at MySIPSwitch will not respond like here is mentioned.

A Ruby translation for outgoing only:

when /^06/ then sys.Dial(”00316${dst:2}@INTERVOIP”)

in the above sample, you see 06 is detected, 00316 plus what’s keyed in, minus the first two digits that where keyed in.  >  dst:2 with the INTERVOIP provider,  06 are the first digits dialed in the Netherlands, to dial a mobile phone, nationally, 0031 is the international code needed for VoIP, and the first zero shouldn’t be dialed, just like with the city dial code. you can edit this rule to your likings, edit the “06″ edit or remove the “00316″ or edit or remove the “:2″

TheFug.

btw: some dialplan expressions:

X - any digit from 0-9

Z - any digit from 1-9

N - any digit from 2-9

[1235-9] any digit in the brackets

. wildcard, matches anything remaining