[asterisk-users] alphabetical extension patterns

Anselm Martin Hoffmeister anselm at hoffmeister-online.de
Sat Sep 15 04:45:44 CDT 2007


Am Dienstag, den 11.09.2007, 17:11 +0530 schrieb Benjamin Jacob:
> Thanks Anselm. This does clears a few things for me.
> Tho, I couldnt find the patterns you mentioned in the docs(do point me
> to the location if you know of it).

I started on
http://www.voip-info.org/wiki/index.php?page=Asterisk+Dialplan+Patterns

Patterns have to begin with "_", meaning it is a pattern. A "." stands
for "one or more characters", so I only allow three-and-more character
SIP phone numbers like anselm at example.com, but not an at example.com. This
is deliberate: I rather not have catchall-type phone numbers, I already
get enough mail spam on the few catchall-addresses I have (well, for
"historical" reasons - I once was small and stupid ;)

> About multiple domains, that is my target for sure.
> I think the "domain"(in sip.conf) thing should come into help here,
> where I associate a domain name to a context. I did try it once,
> worked fine for a couple of test domains. But it seems I can't
> associate one domain name to multple contexts. Am I correct?

You can specify one context for every domain your asterisk supports. On
one of my machines, a sip.conf might look like
8<==== sip.conf
[general]
bindport=5060
bindaddr=0.0.0.0
srvlookup=yes
domain=main.example.com,sip-in-examplecom
domain=private.example.org,sip-in-privateexampleorg
domain=customer.example.net,sip-in-customerexamplenet
====>8
So calls coming in for someone at main.example.com are going through the
sip.conf context "sip-in-examplecom".

In extensions.conf, I would configure like this:
8<==== extensions.conf
[sip-in-domains]
exten=>_...,1,Set(A=${DB(callroute/names/${EXTEN}@${DOMAIN})})
exten=>_...,2,GotoIf($["A" = "A${A}"]?900)
exten=>_...,3,Goto(localdialplan,${A},1)
[sip-in-examplecom]
exten=>_...,1,Set(DOMAIN=example.com)
exten=>_...,2,Goto(sip-in-domains,${EXTEN},1)	
[sip-in-privateexampleorg]
exten=>_...,1,Set(DOMAIN=private.example.org)
exten=>_...,2,Goto(sip-in-domains,${EXTEN},1)	
[sip-in-customerexamplenet]
exten=>_...,1,Set(DOMAIN=customer.example.net)
exten=>_...,2,Goto(sip-in-domains,${EXTEN},1)	
====>8

This would require database entries for users like
callroute/names/anselm at private.example.org => 201
callroute/names/tomjones at customer.example.net => 661

You can also have several domains map to the same users, e.g. you want
example.com and main.example.com to be equivalent, so you just add
another domain line to sip.conf, like
domain=example.com,sip-in-examplecom

You should be able to get around this multiple-context setup by using
the variable ${SIPDOMAIN} and only one context, but this somehow did not
work for me, so I came up with this solution. Play around, see if you
get it running. For me, it has been like this for a while, and then, I
try to avoid changing a running system. You could, for example, set all
your domains to
	domain=example.net,sip-in-domains
and use
exten=>_...,1,Set(A=${DB(callroute/names/${EXTEN}@${SIPDOMAIN})})

which _should_ work just as well.

You probably already found out that SRV records should be set for the
domains that asterisk is going to handle, let me give an example:

anselm at s2:~$ dig @localhost example.org any
; (1 server found)
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52979
;; flags: qr aa rd; QUERY: 1, ANSWER: 6, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;example.org.                        IN      ANY

;; ANSWER SECTION:
example-org.  604800  IN SOA ns1.example.net. root.example.org.
			 2007060504 21600 3600 1209600 21600
example.org.  604800  IN TXT "v=spf1 mx a:mxs.example.org -all"
example.org.         604800  IN   MX  10 example.org.
example.org.         604800  IN   A   81.12.999.999
example.org.         604800  IN   NS  ns1.example.net.
example.org.         604800  IN   NS  al25b.xi.yu.fiber.example.com.
example.org.         604800  IN   NAPTR 60 50 "s" "SIP+D2U" ""
                                        _sip._udp.example.org.
;; ADDITIONAL SECTION:
ns1.example.net.    604800  IN      A       81.12.999.999

;; Query time: 5 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Sat Sep 15 11:38:14 2007
;; MSG SIZE  rcvd: 269

Where
_sip._udp.example.org. 604800 IN SRV 10 10 5060 example.org.

This is a setup with all web, mail and sip running on the same machine
(IP addresses and domains changed, of course) - but you should be able
to move things around so that those services actually can be run on
different machines.

> Anything other to be done on Asterisk to support multiple domains?

Well, I think that is about enough ;-)

BR
Anselm





More information about the asterisk-users mailing list