Wednesday, July 21, 2010

Asterisk Dialplan

How to write dialplan to restrict a user to call only predefine extensions.

;--------------------------------------------------------------------------------
; Context for allow ext-100 to call only ext-200,201,202,203,204
; and any extension begins with number 3 and contains 3 digits.
;If he get a call to any other number, it will hangup by the context.

[from-restricted]
exten => _200,1,Goto(from-internal,${EXTEN},1)
exten => _201,1,Goto(from-internal,${EXTEN},1)
exten => _202,1,Goto(from-internal,${EXTEN},1)
exten => _203,1,Goto(from-internal,${EXTEN},1)
exten => _204,1,Goto(from-internal,${EXTEN},1)
exten => _3XX,1,Goto(from-internal,${EXTEN},1)
;--------------------------------------------------------------------------------
  1. You have to include above context in
    extension.conf file(in CentOS file location is /etc/asterisk/extension.conf).
  2. Then you can change the context of
    extension 100 to from-restricted. (in Asterisk 1.6 file location is /etc/asterisk/user.conf)