· 11 years ago · May 04, 2015, 08:06 PM
1; -----------------------------------------------------------
2; /etc/asterisk/sip.conf
3;
4; Note: If your SIP devices are behind a NAT and your Asterisk
5; server isn't, try adding "nat=1" to each peer definition to
6; solve translation problems.
7;
8[general]
9port=5060 ; Port to bind to (SIP is 5060)
10bindaddr=0.0.0.0 ; Address to bind to (all addresses on machine)
11context=from-sip-external ; Send unknown SIP callers to this context
12disallow=all
13allow=ulaw
14allow=alaw
15;
16register=xx:xx@fwd.pulver.com/dinesh-fwd
17register=xx:xx@sipgate.co.uk/dinesh-sipgate
18register => xx:xx@proxy01.sipphone.com/dinesh-sip ; in from these services.
19;
20;
21; Dial out to fwdnet
22;
23[fwd.pulver.com]
24;fromuser=xxxx
25type=friend
26;dtmfmode=inband
27username=eeeeee
28secret=eeeee
29host=fwd.pulver.com
30;fromdomain=fwd.pulver.com
31;dtmfmode=inband
32insecure=very ; needed if we want to allow incoming FWD calls to bypass authentication
33;context=from-sip
34
35;
36;
37
38;
39;
40; Dial out to Sipgate
41;
42;
43[sipgate]
44type=peer
45secret=eeeeee
46username=eeeeeee
47host=sipgate.co.uk
48insecure=very ; needed if we want to allow incoming FWD calls to bypass authentication
49
50;
51;
52; Dial out to sipphone.com
53;
54[sipphone]
55fromuser=xxxxx
56username=xxxxx
57type=friend
58secret=4215
59host=proxy01.sipphone.com
60dtmfmode=inband
61context=from-sip ;or your context which includes the dialing rules
62;
63
64[2202]
65callerid=("Dinesh Birlasekaran 7905" <2202>)
66type=friend
67username=2202
68secret=xxxxx
69host=dynamic
70context=from-sip-internal
71mailbox=2201
72nat=yes
73canreinvite=no ; "canreinvite=no" is needed, so that all calls allways go through asterisk. This is
74; needed, when you have the SIP client on the LAN and want to use asterisk as a proxy.
75;
76
77
78extensions.conf
79
80[general]
81static=yes
82writeprotect=no
83
84[globals]
85;
86; The name to use on callerid
87;
88
89PHONE1=SIP/2201 ; the phone to ring
90PHONE1VM=2201 ; the VM box for this user
91
92PHONE2=SIP/2202 ; the phone to ring
93PHONE2VM=2202 ; the VM box for this user
94
95PHONE3=SIP/2203 ; the phone to ring
96PHONE3VM=2203 ; the VM box for this user
97
98PHONE4=SIP/2204 ; the phone to ring
99PHONE4VM=2204 ; the VM box for this user
100
101
102[bogon-calls]
103
104;
105; Take unknown callers that may have found
106; our system, and send them to a re-order tone.
107; The string "_." matches any dialed sequence, so all
108; calls will result in the Congestion tone application
109; being called. They'll get bored and hang up eventually.
110;
111
112exten => _.,1,Congestion
113
114
115;
116[from-sip-external]
117;
118; Take unknown callers that are sending calls to our system,
119; and send them to the appropriate extension. It is in this
120; area that we do name-to-number mapping for SIP extensions.
121;
122; This context will allow calls to "2000@this.host.com" or calls
123; to "2001@this.host.com" to be answered on the relevant SIP
124; phones. We also do some name-to-number mapping here; see below.
125;
126; The SIP URI of sip://sidney@this.host.com will be handled here.
127; Note that we assume Sidney is on the SIP phone described as
128; extension "2000" in sip.conf, so this short routine just
129; re-directs the call flow recursively back into the same
130; context, but we change the extension and priority. Since
131; we're including [local-extensions], this will get picked up
132; by the dialplan contained in local-extensions.
133; I could be more space-efficient and put all these lines into
134; a single regexp, but for clarity I put them each on their
135; own lines.
136;
137; Here are Dinesh's aliases
138;
139exten => dinesh,1,Goto(2201,1)
140exten => dinesh.softphone,1,Goto(2201,1)
141exten => info,1,Goto(2201,1)
142;
143exten => cisco_one,1,Goto(2202,1)
144exten => dinesh_cisco_two.7905,1,Goto(2202,1)
145exten => sales,1,Goto(2202,1)
146;
147exten => cisco_two,1,Goto(2203,1)
148exten => dinesh_cisco_three.7905,1,Goto(2203,1)
149exten => marketting,1,Goto(2203,1)
150;
151exten => cisco_three,1,Goto(2204,1)
152exten => dinesh_cisco_three.7905,1,Goto(2204,1)
153exten => support,1,Goto(2204,1)
154
155[from-pstn-external]
156;
157; Incoming calls with no destination land here (usually from the PSTN)
158;
159;
160exten => s,1,Answer
161exten => s,2,DigitTimeout(10) ; Set Digit Timeout to 10 seconds
162exten => s,3,ResponseTimeout(20) ; Set Response Timeout to 20 seconds
163exten => s,4,Background(vm-extension) ; Ask them for the extension they want
164exten => t,1,Hangup
165
166;
167;
168; Include the numbers which we have defined in local-extensions
169; and allow them to be accessed from within this context. This
170; is how we are able to use the "Goto" commands above, since
171; we will be including extensions 2000 and 2001 (and 0 and 2999)
172; as available extensions to which we may re-route calls within
173; this context.
174;
175include => local-extensions
176;
177;
178; If the line hangs up, it's always good to have the "h"
179; extension in each context that is the "master" handler
180; for calls. This cleanly exits and closes dial path routes.
181;
182exten => h,1,Hangup
183;
184; The user has dialed an "i"nvalid number, which means that
185; there was no match by any other matching routines. Set an
186; absolute timeout on the call (15 seconds), play a Congestion
187; tone, and hangup. We set the absolute timeout to prevent easy
188; DoS attacks from consuming too much bandwidth. However, it
189; is possible that we could still be attacked in some fashion
190; by someone making many calls to bogus numbers on our server.
191; We could reduce this threat by removing the Congestion
192; playback and going straight to hangup, but that is very
193; difficult to debug at the remote end, so we are good VoIP
194; citizens and we create some audio if the call reaches us.
195;
196exten => i,1,AbsoluteTimeout(15)
197exten => i,2,Congestion
198exten => i,3,Hangup
199;
200;
201
202[from-sip-internal]
203; Calls that come in from our two SIP phones will land here
204; first and match against extensions listed below.
205;
206; The context [from-sip-internal] is really just a collection
207; of include statements that pull the extension matching lists
208; in from other contexts. A well-designed dialplan segregates
209; extensions with similar functions into contexts, and then
210; uses the "include" referencer. This should be a familiar
211; concept to anyone who does programming - segmenting a block
212; of phone numbers makes them more re-usable in a generic way
213; so that the administrator can avoid re-typing the same configs
214; over and over.
215;
216; First, we include [local-extensions], since that's what
217; we should try matching on first. If anyone on one of our
218; local SIP phones dials an extension that appears in
219; [local-extensions], then send the call to whatever priority
220; list exists for that number. This is for local-to-local call
221; termination.
222;
223include => local-extensions
224;
225; Next, we include and try to match against extensions contained
226; in [always-out-pots]. These are mostly wildcarded matches,
227; so we make sure to put them second when we list our "include"
228; statements, since Asterisk will process the matching lists in
229; a predictable way ONLY based on the order in which multiple
230; contexts are included in some other context. This is an important
231; point, since often dialplans will contain a "catch-all" at the
232; bottom of the matching list. If that "catch-all" (usually
233; something like "_X." or "_.") is just jumbled in with the rest
234; of the extensions, then it may be matched FIRST, which would
235; be opposite of the desired effect. Any time it is the case that
236; you have possible overlapping extension matches in a context,
237; you should order them by creating multiple sub-contexts and
238; using the "include =>" method to order them in the right sequence.
239;
240include => always-out-pots
241;
242; Include the "local" numbers which we want to send out our
243; POTS line since they don't cost us anything.
244;
245include => local-calls-pots
246
247; Include the long-distance matching lines to hand off calls to non-
248; local area codes and international dialing.
249;
250include => ld-calls
251include => tf-calls
252include => fwd-calls
253include => sipphone-calls
254
255;
256; As usual, include "h"angup and "i"nvalid extensions to allow for
257; appropriate handling of those two cases.
258;
259exten => h,1,Hangup
260exten => i,1,Congestion
261exten => i,2,Hangup
262;
263;
264;
265[always-out-pots]
266;
267; The [always-out-pots] context is where we store numbers that will
268; always go out the local analog POTS connection. When working
269; with any priority list for these numbers, it is important to
270; remember that if the POTS line is unavailable for some reason
271; (such as the line not being connected to the card) then the
272; Zap drivers will force the call to go to the next priority.
273; In our case, there is no "next-best-path" for things like 911
274; or 411, so play a congestion tone which should indicate to the
275; caller that the system is unavailable for their use. Just
276; like any other PBX, if it's not connected to the outside world,
277; calls outbound won't work.
278;
279; In all of the examples below, we use the "Zap" technology
280; specifyer (analog) and select channel "1", since we only have
281; one channel in this particular computer (a single Digium X100P
282; FXO card.) In a situation where there are multiple cards or
283; channels, a "group" could be created in the zapata.conf file
284; that allows the call to be sent to the group, and Asterisk will
285; choose the first available channel automatically.
286;
287; Calls to 911, 411, 511, etc. are all handed off to the local
288; analog channel. The "X" matches any digit, so 911/411/511 etc.
289; are handed to the local provider of those services.
290;
291; Each number matching sequence contains an priority chain at
292; priority 102. See the explanation in section [local-calls-pots]
293;
294; We NEVER fail these calls over to the IPCSP account, since the
295; IPCSP almost never has the correct location to which to send calls
296; for 911, 411, etc. There is work towards solving this problem, but
297; most IPCSP's are still some months away from implementation. In
298; the meantime, always hand these numbers off to the POTS line.
299;
300exten => _X11,1,Dial(Zap/1/$EXTEN)
301exten => _X11,2,Congestion
302exten => _X11,3,Hangup
303exten => _X11,102,Congestion
304exten => _X11,103,Hangup
305;
306; Make sure if the user dials the external line seizure number that
307; the calls is handled in the same way, but strip off the leading
308; "9" from the $EXTEN variable because the local POTS system
309; won't know how to deal with it.
310exten => _9X11,1,Dial(Zap/1/$EXTEN:1)
311exten => _9X11,2,Congestion
312exten => _9X11,3,Hangup
313exten => _9X11,102,Congestion
314exten => _9X11,103,Hangup
315;
316; Send calls out to the operator if the user has indicated that they
317; want to talk to the PSTN operator. Note that we grab "0" by itself
318; in the [local-extensions] context; this is for outside operator
319; requests only.
320;
321exten => _90,1,Dial(Zap/1/$EXTEN:1)
322exten => _90,2,Congestion
323exten => _90,3,Hangup
324exten => _90,102,Congestion
325exten => _90,103,Hangup
326;
327;
328; So, we should also always provide an "escape" route for our
329; users so that they can call out on the local analog line in
330; the way that they expect. Most office phone systems have "9"
331; as the "seize external line" prefix. Since SIP phones
332; take their dial strings all at one time, there is no secondary
333; dialtone that the user will hear; they should just dial the
334; number like "914155551212" on their SIP phones, without waiting
335
336; for a second dialtone.
337;
338; We match on any number that begins with a "9" and is 7 or more digits,
339; which is the minimum we need for a standard phone call. The "."
340; stands for "zero or more digits"
341;
342exten => _9XXXXXXX.,1,Dial(Zap/1/$EXTEN:1)
343;
344; If we get an "out of service" or busy signal error on the
345; attempt, send a fast busy to the user and hangup.
346;
347exten => _9XXXXXXX.,2,Goto(102)
348;
349exten => _9XXXXXXX.,102,Congestion
350exten => _9XXXXXXX.,103,Hangup
351;
352;
353;
354[local-calls-pots]
355; This next section is a tricky part. Each phone company in the US
356; seems to have different rules about how you can or cannot dial
357; a local number. The concept of local numbers is one that is
358; going the way of the dinosaur, and only in rural areas does
359; the concept of a single non-overlapping area code still exist.
360; That being said, our imaginary example here has a phone company
361; that requires all local numbers to be ten digits (area code plus
362; seven digit prefix/subscriber number.) HOWEVER, we are going to
363; be responsible members of the e.164 world community, and force
364; users to dial a "1" in front of all numbers. This will make
365; some people complain, especially if they're used to just dialing
366; the seven-digit prefix/subscriber number (123-4567) or if they
367; aren't used to dialing the "1" in front of the area code. Well,
368; they should get used to it - that is the way the dialing plan
369; in North America is moving, and it eliminates huge tables for
370; the phone administrator.
371;
372;
373; First, we want to hand off numbers that are "local" to our POTS
374; line to the X100P board and subsequently to the local phone system.
375; Our area code in this hypothetical example is "609", so we'll
376; match any numbers dialed that start with 1609 and strip off the
377; leading digit (:1) and pass it to the Zap channel driver (POTS line.)
378; We don't have a dial time limit on this, nor are we passing any
379; special settings to the Dial statement; this is an extremely simple
380
381; invocation of "Dial".
382;
383; If we get a "Busy", jump to 102 - see notes there for why and how
384; this jump happens.
385;
386exten => _1609XXXXXXX,1,Dial(Zap/1/$EXTEN:1)
387;
388;
389; Now, what if the Zap line is showing an error? Asterisk has some
390; error routines that allow for failover if a particular channel
391; is unavailable due to an error. If the line is disconnected,
392; then Asterisk will increment the priority counter by 1, and
393; continue.
394;
395; In the case of a failure on our first dial attempt, we'll try handing
396; off the call to the IPCSP account, since something is wrong with
397; our local POTS line. Note that we hand off the whole number,
398; including the leading '1', since iconnecthere expects a fully
399; qualified e164 address (country code, area code, prefix, subscriber)
400; such as 16095551212
401;
402; If this second attempt results in an error, jump to 103
403;
404; If we get a "Busy", jump to 102 - see notes there for why and how
405; this jump happens.
406;
407exten => _1609XXXXXXX,1,Dial(Zap/1/$EXTEN:1)
408;
409;
410; Now, what if the Zap line is showing an error? Asterisk has some
411; error routines that allow for failover if a particular channel
412; is unavailable due to an error. If the line is disconnected,
413; then Asterisk will increment the priority counter by 1, and
414; continue.
415;
416; In the case of a failure on our first dial attempt, we'll try handing
417; off the call to the IPCSP account, since something is wrong with
418; our local POTS line. Note that we hand off the whole number,
419; including the leading '1', since iconnecthere expects a fully
420; qualified e164 address (country code, area code, prefix, subscriber)
421; such as 16095551212
422;
423; If this second attempt results in an error, jump to 103
424;
425exten => _1609XXXXXXX,2,Dial(SIP/$EXTEN@fwd.pulver.com)
426;
427; If we get an error on the dial to the IPCSP, just give up.
428; This means we've tried both the analog like and the IPCSP,
429; but both have given us "out of service" errors.
430;
431exten => _1609XXXXXXX,3,Goto(203)
432;
433;
434; There are two kinds of errors that may be given back by the Dial
435; statement. The first is a generic error, which jumps to +1 in
436; the priority list. The second type of error is the "Busy" error
437; which will jump to +101 from the current priority. "Busy" may
438; is a misleading term - if there is no dialtone on the line, that
439; is considered "Busy", along with several other circumstances.
440;
441; We are faced with the problem that if the statement at priority 1
442; gets a busy, it will jump to 102, and now also if priority 2 gets
443; a busy, it will jump to 103.
444;
445; I personally dislike the +101 auto-jump syntax; it's a kludge, but to this
446; point nobody has submitted a better patch to handle Dial results.
447;
448;
449exten => _1609XXXXXXX,102,Dial(SIP/$EXTEN@fwd.pulver.com)
450;
451; We get to priority 103 either because priority 2 got a "busy"
452; error, or because priority 102 got a "not in service" error.
453; In either case, we want to jump to 203, which is the end of
454; the road.
455;
456exten => _1609XXXXXXX,103,Goto(203)
457;
458;
459; Priority 203 is where we go if we've tried everything and it all
460; didn't work. Jumps get to 203 via a +101 leap from priority 102,
461; or from explicit "Goto" calls elsewhere.
462; We play a congestion tone (fast busy) then hang up.
463;
464exten => _1609XXXXXXX,203,Congestion
465exten => _1609XXXXXXX,204,Hangup
466;
467;
468;
469;
470;
471; We re-do the prior match, but slightly modify it for those very
472; annoying phone companies that force you to dial a "1" in front
473; of only certain exchanges. The user would dial "116093334444" to
474; call those exchanges. This sounds pretty unpleasant, and it is.
475; However, until all phone companies standardize on 1+ten-digit
476; dialing, this will be an issue. Really, the only difference
477; between this small matching set and the "1609XXXXXXX" matching
478; set is that we clip a digit off of the dialed strings when
479; we send the call to our IPCSP. When we dial via the Zap analog
480; interface, we clip off only one of the two leading "1"'s when
481; we pass the $EXTEN to the channel.
482;
483; Another way to get around this would be to build a big table
484; of all "non-local" exchanges and then match on those exchanges,
485; and add a "1" to the dialing string. That is beyond the
486; scope of this example...
487;
488exten => _11609XXXXXXX,1,Dial(SIP/$EXTEN:1@fwd.pulver.com)
489exten => _11609XXXXXXX,2,Goto(203)
490exten => _11609XXXXXXX,102,Dial(SIP/$EXTEN:1@fwd.pulver.com)
491exten => _11609XXXXXXX,103,Goto(203)
492exten => _11609XXXXXXX,203,Congestion
493exten => _11609XXXXXXX,204,Hangup
494;
495;
496;
497;
498[ld-calls]
499;
500; Here is where we define any other calls outbound from the system
501; that seem to be using NANP numbers. If the iconnecthere.com
502; system fails, then send the call out the analog line. It is
503; perhaps the case that an audio hint should be played if the call
504; fails to go out via the SIP long distance provider and uses the
505; more expensive analog line, but that can be added later if desired.
506;
507;
508; Here is where we define any other calls outbound from the system
509; that seem to be using NANP numbers. If the iconnecthere.com
510; system fails, then send the call out the analog line. It is
511; perhaps the case that an audio hint should be played if the call
512; fails to go out via the SIP long distance provider and uses the
513; more expensive analog line, but that can be added later if desired.
514;
515exten => _1XXXXXXXXXX,1,Dial(SIP/$EXTEN@fwd.pulver.com)
516exten => _1XXXXXXXXXX,2,Dial(Zap/1/$EXTEN)
517exten => _1XXXXXXXXXX,3,Hangup
518exten => _1XXXXXXXXXX,102,Dial(Zap/1/$EXTEN)
519exten => _1XXXXXXXXXX,103,Hangup
520exten => _1XXXXXXXXXX,203,Hangup
521
522[fwd-calls]
523
524;
525; fwdnet extensions
526;
527exten => _1393.,1,SetCallerID(${DBFWDUSERNAME} <${DBFWDNUMBER}>) ; set my callerid & name for FWD
528exten => _1393.,2,Dial,SIP/${EXTEN:4}@fwd ; dial the number i wish to dial on FWD
529exten => _1393.,3,Playback(invalid) ; this did not work out
530exten => _1393.,4,Hangup
531exten => _1393.,103,Busy ; the destination was busy
532
533[sipphone-calls]
534;
535; Sip Phone Extensions
536;
537; SIPphone.com
538exten =>> _1747XXXXXXX,1,SetCallerID(${DB_SIPPHONE})
539exten =>> _1747XXXXXXX,2,SetCIDName(${DB_SIPPHONE})
540exten =>> _1747XXXXXXX,3,Dial(SIP/${EXTEN}@sipphone)
541exten =>> _1747XXXXXXX,4,Hangup
542
543
544[tf-calls]
545;
546; Here is where we define any other calls outbound from the system
547; that seem to be toll free. If the fwd.com
548; system fails, then send the call out the analog line. It is
549; perhaps the case that an audio hint should be played if the call
550; fails to go out via the SIP long distance provider and uses the
551; more expensive analog line, but that can be added later if desired.
552;
553; terminate toll-free no.'s via fwdnet
554;
555
556;
557; US toll free access
558;
559; +1-800
560exten => _1800.,1,SetCallerID(${DBFWDNUMBER})
561exten => _1800.,1,SetCIDName(${DBFWDNUMBER})
562exten => _1800.,2,Dial,SIP/*${EXTEN}@fwd.pulver.com
563exten => _1800.,3,Playback(invalid)
564exten => _1800.,4,Hangup
565
566;
567;
568; And do the same for calls that are prefixed with the international
569; dialing code of "011"
570;
571exten => _011XXXXXXXXXX,1,Dial(SIP/$EXTEN@fwd.pulver.com)
572exten => _011XXXXXXXXXX,2,Dial(Zap/1/$EXTEN)
573exten => _011XXXXXXXXXX,3,Hangup
574exten => _011XXXXXXXXXX,102,Dial(Zap/1/$EXTEN)
575exten => _011XXXXXXXXXX,103,Hangup
576exten => _011XXXXXXXXXX,203,Hangup
577;
578;
579;
580
581[local-extensions]
582; The "local-extensions" context used to be called "from-sip" in
583; the first example article. Other than the name change, it is
584; identical. The comments have been removed for brevity.
585;
586exten => 2201,1,Dial(SIP/2201,20)
587exten => 2201,2,Voicemail(u2201)
588exten => 2201,102,Voicemail(b2201)
589exten => 2201,103,Hangup
590;
591exten => 2202,1,Dial(SIP/2202,20)
592exten => 2202,2,Voicemail(u2202)
593exten => 2202,102,Voicemail(b2202)
594exten => 2202,103,Hangup
595;
596exten => 2203,1,Dial(SIP/2203,20)
597exten => 2203,2,Voicemail(u2203)
598exten => 2203,102,Voicemail(b2203)
599exten => 2203,103,Hangup
600;
601exten => 2204,1,Dial(SIP/2204,20)
602exten => 2204,2,Voicemail(u2204)
603exten => 2204,102,Voicemail(b2204)
604;
605;
606; Say Current Date and Time
607;
608exten => 3000,1,DateTime()
609exten => 3000,2,Wait(1)
610exten => 3000,3,DateTime()
611exten => 3000,4,Hangup
612;
613; Read back caller's number
614;
615exten => 3001,1,Wait(1)
616exten => 3001,2,SayDigits(${CALLERIDNUM})
617exten => 3001,3,Wait(1)
618exten => 3001,4,SayDigits(${CALLERIDNUM})
619exten => 3001,5,Hangup
620;
621
622exten => 2999,1,VoicemailMain($CALLERIDNUM)
623;
624exten => 0,1,Goto(2201,1)
625