- •Table of Contents
- •Introduction
- •What This Book Covers
- •Conventions
- •Reader Feedback
- •Customer Support
- •Errata
- •Questions
- •What is Asterisk?
- •Asterisk is a PBX
- •Station-To-Station Calls
- •Line Trunking
- •Telco Features
- •Advanced Call Distribution
- •Call Detail Records
- •Call Recording
- •Asterisk is an IVR System
- •Asterisk is a Voicemail System
- •Asterisk is a Voice over IP (VoIP) System
- •What Asterisk Isn't
- •Asterisk is Not an Off-the-Shelf Phone System
- •Asterisk is Not a SIP Proxy
- •Asterisk Does Not Run on Windows
- •Is Asterisk a Good Fit for Me?
- •Trade-Offs
- •Flexibility versus Ease of Use
- •Graphical versus Configuration File Management
- •Calculating Total Cost of Ownership
- •Return on Investment
- •Summary
- •The Public Switched Telephony Network (PSTN)
- •Connection Methods
- •Plain Old Telephone Service (POTS) Line
- •Integrated Services Digital Network (ISDN)
- •Voice over IP Connections
- •Determining Our Needs
- •Terminal Equipment
- •Types of Terminal Devices
- •Hard Phones
- •Soft Phones
- •Communications Devices
- •Another PBX
- •Choosing a Device
- •Features, Features, and More Features…
- •Determining True Cost
- •Compatibility with Asterisk
- •Sound Quality Analysis
- •Usability Issues
- •Recording Decisions
- •How Much Hardware do I Need?
- •Choosing the Extension Length
- •Summary
- •Preparing to Install Asterisk
- •Obtaining the Source Files
- •Installing Zaptel
- •Installing libpri
- •Installing Asterisk
- •Getting to Know Asterisk
- •Summary
- •Zaptel Interfaces
- •zaptel.conf
- •Lines
- •Terminals
- •zapata.conf
- •Lines
- •Terminals
- •SIP Interfaces
- •IAX Interfaces
- •Voicemail
- •Music On Hold
- •Queues
- •Conference Rooms
- •Summary
- •Creating a Context
- •Creating an Extension
- •Creating Outgoing Extensions
- •Advanced Call Distribution
- •Call Queues
- •Call Parking
- •Direct Inward Dialing (DID)
- •Automated Attendants
- •System Services
- •Summary
- •Call Detail Records
- •Flat-File CDR Logging
- •Database CDR Logging
- •Monitoring Calls
- •Recording Calls
- •Legal Concerns
- •Summary
- •CentOS
- •Preparation and Installation
- •The Asterisk Management Portal (AMP)
- •Maintenance
- •Setup
- •Flash Operator Panel (FOP)
- •Flash Operator Configuration Files
- •Web MeetMe
- •Flexibility When Needed
- •A Simple One-to-One PBX
- •Extensions
- •Trunks
- •Routes
- •Customer Relationship Management/SugarCRM
- •Adding Contacts
- •Call Scheduling
- •Administration of SugarCRM
- •Configure Settings
- •User Management
- •User Roles
- •Summary
- •Small Office/Home Office
- •The Scenario
- •The Discussion
- •The Configuration
- •zaptel.conf
- •zapata.conf
- •musiconhold.conf
- •voicemail.conf
- •modules.conf
- •extensions.conf
- •Conclusions
- •Small Business
- •The Scenario
- •The Discussion
- •The Configuration
- •zaptel.conf
- •zapata.conf
- •musiconhold.conf
- •agents.conf
- •queues.conf
- •sip.conf
- •meetme.conf
- •voicemail.conf
- •extensions.conf
- •Conclusions
- •Hosted PBX
- •The Scenario
- •The Discussion
- •The Configuration
- •zaptel.conf
- •zapata.conf
- •musiconhold.conf
- •sip.conf
- •voicemail.conf
- •extensions.conf
- •Conclusions
- •Summary
- •Backup and System Maintenance
- •Backing Up Configurations
- •Backing Up Log Files
- •Backup Scripts
- •Time Synchronization
- •Adding It All to cron
- •Rebuilding and Restoring the Asterisk Server
- •Disaster Recovery Plan (DRP)
- •Asterisk Server Security
- •Internal Access Control
- •Host Security Hardening for Asterisk
- •Integrity Checker
- •Root-Kit Detection
- •Automated Hardening
- •Role Based Access Control (RBAC)
- •Network Security for Asterisk
- •Firewalling the Asterisk Protocols
- •SIP (Session Initiation Protocol)
- •RTP—The Real-Time Transport Protocol
- •Controlling Administration of Asterisk
- •Asterisk Scalability
- •Load Balancing with DNS
- •Support Channels for Asterisk
- •Mailing Lists
- •Forums
- •IRC (Internet Relay Chat)
- •Digium
- •Summary
- •Index
Chapter 5
Using the underscore (_) character warns Asterisk that the extension number will include pattern matching. When matching patterns, the X character represents any number (0-9), the Z character will match the numbers 1-9, the N character represents numbers 2-9, and the period (.) represents a string of any number of digits.
Also, we can use certain variables in our dialplan. One such variable is ${exten}, which represents the extension that was used.
So, for this example, we could use the following definition:
exten => _1XXX,1,Macro(normal|${exten}|SIP/${exten})
This one line of code has now defined 1000 extensions, from 1000 to 1999. All we have to do is ensure that our voicemail user, extension, and SIP user are all the same number. Pretty cool, huh?
One other note: if we wish to modify the behavior of all extensions, all we have to do is modify the macro. This should help us quite a bit as we tweak Asterisk to fit our business needs.
Creating Outgoing Extensions
With this dialplan, we have only catered for incoming calls. Of course we will want to create extensions to dial out.
How these outgoing extensions look depends on the plan we made earlier. It also depends on how you want the switch to act for your users. We always want to make it as similar to any old system as possible to reduce the need to retrain users.
Most phone systems require a user to dial a certain digit to designate the call as one that has a destination outside the switch. In our legacy PBX, we accessed outgoing lines by dialing a 9. To copy this behavior, we could do something like:
[outgoing]
exten => _9.,1,Dial(Zap/g1/${EXTEN:1})
Notice that we are using pattern matching as we did before. Notice also that we used g1 as the Zaptel interface. This is a good use for a group. This simply means "any free interface in group 1". Thus, if we put all of our outgoing lines in group 1, then when we dial an outside number, we do not have to guess which channel is free.
Remember that the variable exten represents the extension that we are in. If a user dials 95555555, then exten is equal to 95555555. By using ${EXTEN:1}, we instruct Asterisk to strip the first (leftmost) digit. Thus, ${EXTEN:1} equals 5555555. If we wanted to strip the two leftmost digits, it would be ${EXTEN:2}.
Many discount long distance carriers will charge the same for local calls as long distance. In a case like that, we would want to make sure that local and toll-free calls went out on lines connected to the local telephone company, while calls destined for long-distance
75
Creating a Dialplan
locations should go out through our discount carrier. For this example, we will assume that the discount carrier is Zaptel group 1, and the local telephone company is Zaptel group 2.
[outgoing]
exten => _9N.,1,Dial(Zap/g2/${EXTEN:1}) exten => _91.,1,Dial(Zap/g1/${EXTEN:1})
Therefore, if the number dialed is preceded with a 9 and a 1, then the call will go out through our Zaptel group 1 lines, and if it does not have a 1, it will go out through our group 2 lines.
What if we had used:
[outgoing]
exten => _9X.,1,Dial(Zap/g2/${EXTEN:1}) exten => _91.,1,Dial(Zap/g1/${EXTEN:1})
Notice that this is a problem. When we dial 9, followed by 1, we have two statements that match. When you start Asterisk, you will notice that the system parses the extensions.conf (and included files) and immediately reorders all of the extensions before building a database file. Therefore, it is ambiguous as to which statement it will execute.
While this method is technically functional, it is not the best way to do it. A better way would be:
[outgoing]
exten => _9NXXXXXX,1,Dial(Zap/g2/${EXTEN:1}) exten => _91NXXNXXXXXX,1,Dial(Zap/g1/${EXTEN:1})
This does not allow for medium distance dialing. It also does not handle the case of all lines being busy in one of the groups. Let's see how we could take care of that:
[outgoing]
exten => _9NXXXXXX,1,Dial(Zap/g2/${EXTEN:1}) exten => _9NXXXXXX,2,Dial(Zap/g1/${EXTEN:1}) exten => _91NXXNXXXXXX,1,Dial(Zap/g1/${EXTEN:1}) exten => _91NXXNXXXXXX,2,Dial(Zap/g2/${EXTEN:1}) exten => _91NXXXXXX,1,Dial(Zap/g1/${EXTEN:1}) exten => _91NXXXXXX,2,Dial(Zap/g2/${EXTEN:1})
This is getting much better, but what about when all of our lines are busy, for both groups? We should probably notify the user that their call didn't go through because all lines are in use. We could do something like this:
[outgoing]
exten => _9NXXXXXX,1,Dial(Zap/g2/${EXTEN:1}) exten => _9NXXXXXX,2,Dial(Zap/g1/${EXTEN:1}) exten => _9NXXXXXX,3,Congestion
exten => _91NXXNXXXXXX,1,Dial(Zap/g1/${EXTEN:1}) exten => _91NXXNXXXXXX,2,Dial(Zap/g2/${EXTEN:1}) exten => _91NXXNXXXXXX,3,Congestion
exten => _91NXXXXXX,1,Dial(Zap/g1/${EXTEN:1}) exten => _91NXXXXXX,2,Dial(Zap/g2/${EXTEN:1}) exten => _91NXXXXXX,3,Congestion
76
Chapter 5
Imagine a phone switch in which all extensions were exactly four digits long. How would this knowledge affect our outgoing lines? Perhaps the fundamental question is whether we really need to dial the 9 at all. While people generally expect to dial a 9 at work, they do not seem to care to do so from home. Maybe we should do this:
[outgoing]
exten => _NXXXXXX,1,Dial(Zap/g2/${EXTEN:1}) exten => _NXXXXXX,2,Dial(Zap/g1/${EXTEN:1}) exten => _NXXXXXX,3,Congestion
exten => _1NXXNXXXXXX,1,Dial(Zap/g1/${EXTEN:1}) exten => _1NXXNXXXXXX,2,Dial(Zap/g2/${EXTEN:1}) exten => _1NXXNXXXXXX,3,Congestion
exten => _1NXXXXXX,1,Dial(Zap/g1/${EXTEN:1}) exten => _1NXXXXXX,2,Dial(Zap/g2/${EXTEN:1}) exten => _1NXXXXXX,3,Congestion
There is a drawback to this configuration. If you are using Zaptel interfaces, and people are touch-tone dialing, Asterisk will have to wait for a timeout period to complete dialing some four-digit extensions. The reason for this is simple. Any extension number that partially matches the beginning of the patterns above will have to be held to see if more digits are coming. However, SIP and IAX phones do not seem to suffer the same issue.
Because of this issue, from here forward we will assume that all outgoing calls are preceded with the digit 9.
We have already discussed that contexts can provide security for outgoing phone calls, but this example fails to describe such security. Suppose you have two groups of employees, those who may make toll calls, and those who may not. All employees have an individual handset. The most logical choice is to make two contexts:
[longdistance]
exten => _9NXXXXXX,1,Dial(Zap/g2/${EXTEN:1}) exten => _9NXXXXXX,2,Dial(Zap/g1/${EXTEN:1}) exten => _9NXXXXXX,3,Congestion
exten => _91NXXNXXXXXX,1,Dial(Zap/g1/${EXTEN:1}) exten => _91NXXNXXXXXX,2,Dial(Zap/g2/${EXTEN:1}) exten => _91NXXNXXXXXX,3,Congestion
exten => _91NXXXXXX,1,Dial(Zap/g1/${EXTEN:1}) exten => _91NXXXXXX,2,Dial(Zap/g2/${EXTEN:1}) exten => _91NXXXXXX,3,Congestion
[local]
exten => _9NXXXXXX,1,Dial(Zap/g2/${EXTEN:1}) exten => _9NXXXXXX,2,Dial(Zap/g1/${EXTEN:1}) exten => _9NXXXXXX,3,Congestion
We simply place each handset into one of the two contexts, based upon what numbers we want them to be able to dial. While this would work, we duplicated three lines between the contexts. Remember when we discussed contexts, and I mentioned that we can use the include directive? Here's a good place to do so. So now, we have:
[longdistance]
exten => _91NXXNXXXXXX,1,Dial(Zap/g1/${EXTEN:1}) exten => _91NXXNXXXXXX,2,Dial(Zap/g2/${EXTEN:1})
77