Monday 9 February 2009

Asterisk: A Bare-Bones VoIP Example p:3

Configuration

The following configs are going to put an extremely basic configuration in place, and we will pretty much going to throw out the sample files that came with Asterisk and pare down things to an absolute minimum. If you need to find out more information about additional options, the original demonstration files are located in /usr/src/asterisk/configs for your reference. Leave everything in place that Asterisk's "make samples" puts in for you, except for the three files below; those are the only three that need to be touched for our sample to work.

After configuration, you will have the ability to dial between your two phones, and voicemail will end up stored in the system for each extension, and will also be sent as an email attachment to the email address specified in the mailbox configurations.
Since only SIP channels are being used, we only need to modify three files for our mini-PBX two-line system: sip.conf (this defines the SIP peers, which are the software or hardware SIP phones), extensions.conf (this is where the dialplans are kept -- the meat of the system), and voicemail.conf (where we define the voice mailboxes for each user).

Perform a cd /etc/asterisk, move the existing sip.conf, extensions.conf, and voicemail.conf somewhere safe, and create new files with the following contents:

sip.conf

[general]

port = 5060 ; Port to bind to (SIP is 5060)
bindaddr = 0.0.0.0 ; Address to bind to (all addresses on machine)
allow=all ; Allow all codecs
context = bogon-calls ; Send SIP callers that we don't know about here

[2000]

type=friend ; This device takes and makes calls
username=2000 ; Username on device
secret=9overthruster7 ; Password for device
host=dynamic ; This host is not on the same IP addr every time
context=from-sip ; Inbound calls from this host go here
mailbox=100 ; Activate the message waiting light if this
; voicemailbox has messages in it

[2001] ; Duplicate of 2000, except with different auth data

type=friend
username=2001
secret=11bbanzai9
host=dynamic
context=from-sip
mailbox=101

extensions.conf

[general]

static=yes ; These two lines prevent the command-line interface
writeprotect=yes ; from overwriting the config file. Leave them here.

[bogon-calls]

;
; Take unknown callers that may have found
; our system, and send them to a re-order tone.
; The string "_." matches any dialed sequence, so all
; calls will result in the Congestion tone application
; being called. They'll get bored and hang up eventually.
;

exten => _.,1,Congestion

[from-sip]

;
; If the number dialed by the calling party was "2000", then
; Dial the user "2000" via the SIP channel driver. Let the number
; ring for 20 seconds, and if no answer, proceed to priority 2.
; If the number gives a "busy" result, then jump to priority 102
;

exten => 2000,1,Dial(SIP/2000,20)

;
; Priority 2 send the caller to voicemail, and gives the "u"navailable
; message for user 2000, as recorded previously. The only way out
; of voicemail in this instance is to hang up, so we have reached
; the end of our priority list.
;

exten => 2000,2,Voicemail(u2000)

;
; If the Dialed number in priority 1 above results in
; a "busy" code, then Dial will jump to 101 + (current priority)
; which in our case will be 101+1=102. This +101 jump is built
; into Asterisk and does not need to be defined.
;

exten => 2000,102,Voicemail(b2000)
exten => 2000,103,Hangup

;
; Now, what if the number dialed was "2001"?
;

exten => 2001,1,Dial(SIP/2001,20)
exten => 2001,2,Voicemail(u2001)
exten => 2001,102,Voicemail(b2001)
exten => 2001,103,Hangup

;
; Define a way so that users can dial a number to reach
; voicemail. Call the VoicemailMain application with the
; number of the caller already passed as a variable, so
; all the user needs to do is type in the password.
;

exten => 2999,1,VoicemailMain(${CALLERIDNUM})

Now, we're almost ready to go. Actually, we've completed everything that is required for two phones to call each other, but we still need to assemble the configuration files that will know how to save messages in case a line is busy or "unavailable." Note that Asterisk treats phones that are turned off or are otherwise not registered as "Busy" and not "Unavailable" -- the status of "Unavailable" usually refers to a situation where nobody has answered the phone in the given number of seconds.

Before we can use our voicemail system, we need to create empty voicemail boxes for each user. This is done using the script located at /usr/src/asterisk/addmailbox, which is simply a small shell script that creates a directory and puts some default greetings into place. Run addmailbox twice, specifying "2000" and "2001" as the mailboxes that you wish to create.

voicemail.conf

[general]

format=wav

[local]

;
; format: password, name, email address for attached voicemail msgs
;

2000 => 4321,John Whorfin,jwhorfin@planet10.com
2001 => 8383,Sidney Zweibel,newjersey@banzaiinstitute.com

No comments: