Asterisk dialplan configuration

From 탱이의 잡동사니
Jump to navigation Jump to search

개요

Asterisk Dialplan 설정 법 설명.

Dialplan syntax

Asterisk 에서 Dialplan 을 설정하는 파일 이름은 extensions.conf 이다.

  • extensions.conf
    • 보통은 /etc/asterisk/extensions.conf 에 위치해 있다.
    • 하지만 소스로 설치를 하거나 다른 방법으로 설치하게 되면 다른곳에 파일이 위치할 수도 있다.
    •  ex) /usr/local/etc/asterisk, /opt/etc/asterisk 

Dialplan 은 크게 4가지 컨셉으로 구성되어 있다.

contexts, extensions, priorities, applications

Context

Context 는 쉽게 말해서 객체지향의 Class 와 비슷한 개념으로 볼 수 있다.

Context 를 생성할 때는 Context 이름을 중괄호([])로 감싸야한다. 이름에 사용할 수 있는 문자는 A-Z, a-z, 0-9, -, _ 이다.

[incoming]
  • Context 생성시 사용가능한 문자 길이는 최대 79 자 이다. (80 characters - 1 terminating null).

Context 에는 특별히 사용되는 특수 Context 두 가지가 있는데, [general] 과 [globals] 이다. [general] 섹션은 일반적인 Dialplan 설정들, [globals] 섹션에는 전역 Dialplan 설정들이 있는 Context 이다. 새로운 Context 생성시 [general], [globals], [default] 이름은 피하도록 하자. 이 외의 다른 이름은 전부 사용 가능하다.

채널을 설정할 경우(sip.conf, iax.conf, chan_dahdi.conf 등등..) 필수 입력 항목중에 context 항목이 있다. Context 는 호간의 연결 성립시, 채널이 동작하게되는 Dialplan 의 시작점이다. 즉, Asterisk 에 등록된 채널 A 가 있을 경우, 만약 A 로 전화가 걸려왔을 때, 어떤 방식으로 전화가 흘러가게끔 할 것인지를 결정하게 되는 것이다.

  • 전화(Connection)가 걸려왔을 경우 정해진 수순에 따라 전화가 흘러가게끔 하는 것, 이것이 Dialplan 이다.
  • ex) 10초동안 응답이 없을 경우 자동 IVR 연결, 10초 동안 연결이 없을 경우 휴대폰 전화로 연결 등등..

Context 사용시 주의해야 할 점은 보안이다. 정확한 방법으로 Context 을 설정한다면 정해진 사용자에게 정해진 기능을 제공할 수 있다. 하지만 엉뚱한 방법으로 Context 를 설정하게 되면, 엉뚱한 기능들이 동작할 수 있다. 게다가 Asterisk 를 위시한 많은 IP-PBX 시스템은 주요 해킹 공격 대상이 된다. 일반적인 Web 과 달리 통화요금 과금과 같이 돈이 관련된 부분이기 때문이다. 때문에 Context 와 같은 Dialplan 설정시 많은 주의를 요한다.

  • ex) 국제전화 사용

Extensions

Extensions 흔히 전화번호로도 번역이 된다. 하지만 Asterisk 에서의 Extensions 는 더 강력한 기능을 가진다.

Asterisk 에서는 각각의 Context 마다 하나 혹은 다수의 Extensions 를 가질 수 있다. 해당 Extension 이 동작할 경우(전화가 걸려온 경우), Asterisk 는 해당 Extension 에 설정된 Dialplan 을 수행하는 것이다.

Extension 설정시, exten 구문으로 시작하게 된다.

exten =>

Extension 은 세가지 구성요소들을 가진다.

  • name(or number)
  • priority
  • application

이 구성 요소들은 쉼표(,)로 구분된다.

exten => name, priority, application()

Pattern Matching

원문은 이곳<ref>https://wiki.asterisk.org/wiki/display/AST/Pattern+Matching</ref>에서 확인할 수 있다.

패턴 매칭은 항상 "_" 기호로 시작한다. 해당 기호로 시작해야지만 Asterisk 에서 패턴 매칭을 사용한다는 것을 인식할 수 있기 때문이다.

X, Z, N

X, Z, N 은 가장 흔히 사용하는 패턴 매칭 기호이다.

  • X
X/x 대/소문자 구분이 없다. 0 ~ 9 까지의 하나의 숫자를 의미한다.
  • Z
Z/z 대/소문자 구분이 없다. 1 ~ 9 까지의 하나의 숫자를 의미한다.
  • N
N/n 대/소문자 구분이 없다. 2 ~ 9 까지의 하나의 숫자를 의미한다.
  • Example
예제를 들어보자. 다음은 6400 부터 6499 까지 의 번호를 매칭하는 패턴이다.
exten => _64XX,1,SayDigits(${EXTEN})

Character Sets

만약 특정 숫자의 범위를 지정하고자 한다면, "[]" 기호안에 숫자의 범위를 입력하여 지정할 수 있다. 예를 들어, 6300 번 부터 6400 번까지의 번호를 지정하고 싶다면 어떻게 해야 할까? (_64XX, _63XX) 과 같이 두개의 번호를 지정하여 사용할 수 있다. 하지만 범위지정 방식으로 사용할 경우 (_6[34]XX) 으로 설정이 가능하다.

만약 [1-468] 과 같이 지정을 했다면, 이는 1 부터 468 까지의 숫자가 아니라, 4, 6, 8 의 숫자를 의미하는 것이다.

Other Special Characters

Within Asterisk patterns, we can also use a couple of other characters to represent ranges of numbers. The period character (.) at the end of a pattern matches one or more remaining characters. You put it at the end of a pattern when you want to match extensions of an indeterminate length. As an example, the pattern _9876. would match any number that began with 9876 and had at least one more character or digit.

The exclamation mark (!) character is similar to the period and matches zero or more remaining characters. It is used in overlap dialing to dial through Asterisk. For example, _9876! would match any number that began with 9876 including 9876, and would respond that the number was complete as soon as there was an unambiguous match.

Asterisk treats a period or exclamation mark as the end of a pattern. If you want a period or exclamation mark in your pattern as a plain character you should put it into a character set: [.] or [!].

Using the CONTEXT, EXTEN, PRIORITY, UNIQUEID, and CHANNEL Variables

원문은 이곳<ref>https://wiki.asterisk.org/wiki/display/AST/Using+the+CONTEXT%2C+EXTEN%2C+PRIORITY%2C+UNIQUEID%2C+and+CHANNEL+Variables</ref>에서 확인할 수 있다. Asterisk dialplan 에서 채널을 생성하고 사용할 때 필요한 정보는 CONTEXT, EXTEN, PRIORITY 이다. 즉 다음과 같이 사용한다.

exten=>6123,1,SayNumber(${EXTEN})

그런데, 만약 extension 정보를 수정하고 다시 reload 를 했다면 어떻게 될까? 만약 채널에서 현재 사용중인 EXTEN 정보가 변경이 되었다면 문제가 발생할 것이다. 그래서 이를 위해 Asterisk 내부적으로 생성되고 관리되는 키 정보가 있는데, 이것이 바로 UNIQUEID 이다. 모든 채널들은 고유의 Unique 값들을 가지게 된다. UNIQUEID 값은 흔히 다음과 같이 표현된다.

1267568856.11

Dialplan 에서 채널을 생성할 경우, UniqueID 값은 자동생성되며, 만약 AMI 등과 같은 명령으로 채널을 생성할 경우, 이를 지정해줄 수도 있다.

Asterisk 에서 자동생성되는 Unique ID 값은 다음과 같이 구성되어 있다.

1267568856.11
채널_생성_당시의_유닉스_타임.Asterisk_재시작_이후_만들어진_채널_갯수

CHANNEL 변수 역시 각 채널마다 중복되지 않는 키 정보로 사용될 수 있다. Hex number 값으로 구성되며, 해당 Exten 으로 채널을 생성할 경우, 1씩 올라가는 방식이다. 하지만 Asterisk 재시작시, 모든 채널 값들이 0으로 초기화되기 때문에 재시작을 하게 된다면, 재시작 이전의 CHANNEL 변수 값과 중복되는 현상이 발생한다.

Variables

Standard channel variables

"*" 가 붙은 변수들은 dialplan 에서 write 가 불가능하고 오직 read 만 가능한 변수들이다. 만약 write 를 할 경우, 경고나 에러 메시지 없이 무시된다.

Variables present in Asterisk 1.8 and forward

Asterisk-1.8 부터 계속 사용되고 있는 channel variable 내용 정리.

  • ${CDR(accountcode)}* : Account code(if specified).
  • ${BLINDTRANSFER} : The name of the channel on the other side of a blind transfer.
  • ${BRIDGEPEER} : Bridged peer.
  • ${BRIDGEPVTCALLID} : Bridged peer PVT call ID(SIP call ID if a SIP call).
  • ${CALLERID(ani)}* : Caller ANI(PRI channels).
  • ${CALLERID(ani2)}* : ANI2(info digits) also called Originating line information or OLI.
  • ${CALLERID(all)} : Caller ID.
  • ${CALLERID(dnid)}* : Dialed Number Identifer.
  • ${CALLERID(name)}* : Caller ID Name only.
  • ${CALLERID(rdnis)}* : Redirected Dial Number ID Service.
  • ${CALLINGANI2}* : Caller ANI2(PRI channels).
  • ${CALLINGPRES}* : Caller ID presentation for incoming calls(PRI channels).
  • ${CALLINGTNS}* : Transit network Selector(PRI channels).
  • ${CALLINGTON}* : Caller Type of Number(PRI channels).
  • ${CHANNEL}* : Current channel name.
  • ${CONTEXT}* : Current context.
  • ${DATETIME}* : Current date time in the format: DDMMYYYY-HH:MM:SS(Deprecated; use ${STRFTIME(${EPOCH},,%d%m%Y-%H:%M:%S)}).
  • ${DB_RESULT} : Result value of DB_EXISTS() dial plan function.
  • ${EPOCH}* : Current unix style epoch.
  • ${EXTEN}* : Current extension.
  • ${ENV(VAR)} : Environmental variable VAR.
  • ${GOTO_ON_BLINDXFR} : Transfer to the specified context/extension/priority after a blind transfer(use ^ characters in place of | to separate context/extension/prioirty when setting this variable from the dialplan).
  • ${HANGUPCAUSE}* : Asterisk cause of hangup(inbound/outbound).
  • ${HINT}* : Channel hints for this extension.
  • ${HINTNAME}* : Suggested Caller ID name for this extension.
  • ${INVALID_EXTEN} : The invalid called extension(used in the "i" extension).
  • ${LANGUAGE}* : Current language(Deprecated; use ${CHANNEL(language)}).
  • ${LEN(VAR)} : String length of VAR(integer).
  • ${PRIORITY}* : Current language(Deprecated; use ${CHANNEL(language)}).
  • ${PRIREDIRECTREASON} : Reason for redirect on PRI, if a call was directed.
  • ${TIMESTAMP}* : Current date time in the format: YYYYMMDD-HHMMSS(Deprecated; use ${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}).
  • ${TRANSFER_CONTEXT} : Context for transferred calls.
  • ${FORWARD_CONTEXT} : Context for forwarded calls.
  • ${DYNAMIC_PEERNAME} : The name of the channel on the other side when a dynamic feature is used.
  • ${DYNAMIC_FEATURENAME} : The name of the last triggered dynamic feature.
  • ${UNIQUEID}* : Current call unique identifier.
  • ${SYSTEMNAME}* : Value of the systemname option of asterisk.conf.
  • ${ENTITYID}* : Global Entity ID set automatically, or from asterisk.conf.

Variables present in Asterisk 11 and forward

Asterisk-11 부터 계속 사용되고 있는 channel variable 내용 정리.

  • ${AGIEXITONHANGUP} : Set to 1 to force the behavior of a call to AGI to behave as it did in 1.4, where the AGI script would exit immediately on detecting a channel hangup.
  • ${CALENDAR_SUCCESS} * : Status of the CALENDAR_WRITE function. Set to 1 if the function completed successfully; 0 otherwise.
  • ${SIP_RECVADDR} * : The address a SIP MESSAGE request was received from.
  • ${VOICEMAIL_PLAYBACKSTATUS} * : Status of the VoiceMailPlayMsg application. SUCCESS if the voicemail was played back successfully, FAILED otherwise.

Books

  • Asterisk: The Definitive Guide, 4th Edition

References

<references />