Archive for the ‘asterisk’ Category

Asterisk Dual Servers with SIP

Tuesday, July 15th, 2008

I have found about a million articles on the net for connecting 2 asterisk boxes using IAX2. What I have not found is many describing how to do this with SIP, so thats what Im going to talk about. Now since I am a FreePBX user I am going to talk about how to do this using the FreePBX web GUI. You can use this method if you use TrixBox, or Elastix, or PBX In A Flash, or if you just use FreePBX with your own distro.

I have 2 systems. To make this simple Im going to call them pbx1 (which for this example is in San Antonio) and pbx2 (which we will pretend is in our Houston office). First we need to log into the web interface on pbx1 and then get to the section where you configure trunks. Click Add SIP Trunk. Im not going to mess with any of the General Settings, or the Dial Rules. I am going to go straight to the Outgoing Rules. In trunk name Im going to call this trunk-hou-peer. Next I jump into the PEER Details box. I put the following into the box:


Next, Remove all the settings from the Incoming Section. Hit submit, and then apply the changes.

Next we need to log on the web gui for pbx2. Now we are going to go from Houston back to San Antonio with this trunk. We need to add a new SIP trunk here. Follow the same steps as before, but now name this trunk: trunk-sa-peer You may notice that the name of this trunk is the username we used in the peer details on pbx1. Now in the Peer details on pbx2 add the following:


Now you will notice that the username on this peer is what we named our trunk on pbx1. The context used in both is the same. This will give you access from pbx2 to dial an extension that is on pbx1 and vise versa. Now all we need to do is submit this and apply the changes.

Next all we need to do is create an outbound route to use our new trunk. For the sake of keeping it super simple lets assume you have extension 100-199 on pbx1 and 200-299 on pbx2. We need to go to the outbound route section and create a route on pbx1, name it toHouston and it needs a dial pattern that looks like this:


Click on the Intra Company Route. Then select our Houston trunk. Next submit and apply changes. Now head over to the pbx2 web gui and do the same steps only name this route toSanAntonio and for its dial pattern use:


Click Intra Company Route select the San Antonio Trunk, hit submit and apply. Now from extension 100 in San Antonio dial 200 and bamo thats it. You can take this a step further and even do toll-by-pass now.

My New Cell Phone – Nokia n95 8GB

Tuesday, July 1st, 2008

Yeah, hate me.. I got one. Its so freakin awesome. here are a few things that really kick ass so far about this phone:

  • I am able to sync music to the phone via amarok using Linux
  • I am able to browse the web using WIFI or my 3g data service.
  • I have configured my n95 as a sip client and have it registered with my Asterisk server.
  • The phone supports mobile bar codes
  • The camera takes WONDERFUL pictures. The quality is very high!! And you can export them directly to flickr!!
  • The phone takes really great video
  • Did I mention I didnt need windows to add music to this thing??

Im sure there are other really great things about this phone too but I have only had it a couple days so I havent had time to check all the features out yet.

My trip to Houston

Monday, July 2nd, 2007

Well I just got home from a week long trip to Houston to deploy the last of our PBX servers to complete the rolling out of our new Asterisk phone system. I had a great time there and got to eat at some really good places. Im just glad to be done rolling out the system, next comes the fun part… managing it 🙂 I will do my best to keep you posted from time to time as I hit any snags. I did happen to have one problem with our voicemail system that I will be covering later once I have a more elegant fix for it. It involves being able to hit 0 and get back to an IVR which will allow for direct extension dialing. For now my fix is kinda crappy and only involves hitting 0 and it ringing our operator ring group.

Centralized Voicemail server for multiple Asterisk systems using FreePBX and IAX2

Sunday, May 13th, 2007

Well I never really finished up my asterisk tips posts… I’m lazy and most of the free time I do have I dont like to spend on the computer anymore (what can I say). Im going to make it up to you though by sharing with you how to make a very slick asterisk setup.

So why would anyone want to have a stand alone voicemail server anyway?? Well thats pretty simple. Lets pretend you have a small to medium sized company. Maybe 100-500 employees, maybe more maybe less… You have 3 or 4 office locations, they span several cities or maybe even other states.. It doesnt really matter where they are. The important thing is that they all need to be connected. You need to be able to call from one office to another, and at times you will even need to forward voicemails from one location to another. Asterisk does not just automaticly support this. Even if you have routes in place that make it so you can call each person on your network with a SIP call if their voicemail box isnt on the same server as yours you cant forward them a message. This can become a big problem real fast. Infact at our company we were considering not using asterisk because of this. The good news is that its really simple to do.

First off Im not going to cover how to connect the multiple servers. This has been articled to friggin death. Its covered on many sites, one of them not being this one. Next Im going to assume you have figured out how to make connections from 1 asterisk system to another using IAX2. If not please check out this guide. It works great.

Now on to the fun stuff. I used FreePBX on our 3 PBX servers to get our dial plan setup and have a nice easy to manage user interface. I kept thinking that this would keep me from being able to customize my dial plan like i needed to but I was all wrong about that. Im now going to point you over to the guide I followed: Click me!!!

This guide is fairly good. It doesnt cover doing it with FreePBX though. If you use FreePBX you may have found that if you edit one of its config files you lost your changes once you entered the gui, or made an update to FreePBX. I went to the IRC and asked how to get around this. It was simple, at the top of the config files you see a line that says #include somefile_custom.conf All you have to do is edit that custom.conf file and over ride the context you need to edit. So if you have in your sip.conf file a [foo] context you go to sip_custom.conf and make [foo] in there and then the settings for the [foo] context from your sip_custom.conf file will be whats used instead of the [foo] from sip.conf

In the article I asked you to click to see how to do the setup it said you needed to edit a macro in extensions.conf. The context you need to edit is called [macro-vm] First what I did was copy and pasted the [macro-vm] context from extensions.conf and pasted it into extensions_custom.conf then I edited the following:

; over riding the below for our central voicemail server
exten => s-BUSY,n,Dial(IAX2/toVMail/b${ARG1})
exten => s-BUSY,n,Goto(exit-${VMSTATUS},1)

exten => s-DIRECTDIAL,1,NoOp(DIRECTDIAL voicemail)
exten => s-DIRECTDIAL,n,Macro(get-vmcontext,${ARG1})
; over riding the below for our central voicemail server
exten => s-DIRECTDIAL,n,Dial(IAX2/toVMail/${ARG1})
exten => s-DIRECTDIAL,n,Goto(exit-${VMSTATUS},1)

From there I just followed the rest of the guide the other nice fellow provided and saved my settings, then setup a plain jane asterisk server for my voicemail server. I didnt use FreePBX on it at all. Managing that server is braindead simple so I didnt see the need. I hope this little tidbit will help others out there who have to set this up.

using php mail() with postfix

Monday, April 16th, 2007

First, let me give a short history… I had to make a script at work that would get fired off by our hylafax server when ever an incoming fax was recieved. This script needed to check the caller id info and see what number was dialed, then based on that either move the file into a dir for the department it was intended for, or if it was ment for a person then to convert the tiff file into a pdf then email them the fax. Sounds simple enough… So for what ever reason my boss is hung up on using php for everything so I start working on this thing in php. We are using asterisk at work with IAXmodem to make asterisk and hylafax work happy like.. We have given all 90+ users we have their own DID as well as their own FaxDID. What I do with this script is lookup the number that was passed with callerid info in a mysql database to see whos umber it is, I get their username and their email as well as some other info, then mail the user the fax. I decided to use Pear for this because I like to reuse code when ever possible. I made a simple script to get the job done and damn to hell if it wouldnt work. I would get an email with the headers all screwed up. I knew they were not getting messed up in the php because I could print the email (headers and all) to the command line and it was perfect. I tried this same script on another box (that happened to have sendmail) and it woked perfect. I spent all damn day trying to figure out why my emails were not being sent correctly today. Then along came my good buddy Caleb. The first words from his mouth were ” I bet the working servers are sendmail and the nonworking are postfix” Sure enough that was the case. For what ever reason postfix is adding 2 new lines to my stuff. The fix was really extremely trivial.

$body = $mime->get();
$body = str_replace(“\r”,”,$body);
$headers = $mime->headers($headers);
$headers = str_replace(“\r”,”,$headers);

The full script can be found here. This script is not the best work ever, and it could be improved for sure. But this is what I am using. I hope someone can find it useful someday.

Asterisk tips #1

Thursday, March 15th, 2007

I have been building an asterisk system at work for testing stuff. I started with a Fedora Core 6 box and then installed asterisk from source. Since we will be using a PRI we had to buy a T-1 card. We decided to go with sangoma. For our testing purpose we just got an A102. I installed the card and then went to the sangoma site for the latest wanpipe drivers. After installing them and setting up my zaptel.conf and zapata.conf I found nothing worked. I found out I needed to compile the wanpipe stuff first, and install zaptel from source instead of using the Fedora RPM because the wanpipe package needs to patch the zaptel stuff. Once I finished this and loaded the wanpipe modules and loaded ztdummy and then rebuilt asterisk I had a working sangoma card. I started with a very very basic config for asterisk. I just wanted to have 2 extensions and make them able to call each other using SIP, then I wanted to take 2 of the DID’s provided to me by our phone company and have them ring into the extensions. The SIP part of this was just plain simple. Here is what my sip.conf looks like for asterisk.

;Test Guy1

;Test Guy2

The important thing to note here is the context=local_test Next to get this working completely we need a very basic extension.conf file. Mine looks like this:

; SIP extensions
;Test Guy1
exten => 231,1,Dial(SIP/231)
;Test Guy2
exten => 205,1,Dial(SIP/205,10)
exten => 205,2,PlayBack(vm-goodbye)
exten => 205,3,HangUp()

Thats it, this simple example will now make it so from 231 we can dial 205 then if after 10 seconds we dont answer the phone system will automaticly pick up and play the message vm-goodbye.gsm and then hangup the phone. Remember I said to note the context=local_test Well in our extensions.conf file if we had named our context block something else it wouldnt have worked because the context wouldnt have matched. You can name your context blocks what ever you want, but keep in mind they must match or nothing will work.

Now we need to expand on this just a little bit to get our calls from the outside to ring in. I will cover that later today or Friday. Its very simple so check back soon for the tip.