Overview
ARI有很多部分 - Asterisk服务请求的HTTP server,将channel的控制权交给连接的client的dialplan应用,在asterisk和外呼应用之间共享状态的websocket。这里提供asterisk的配置文件:对其修改以满足开发的要求。
此页面没有涵盖系统管理员可用的所有选项,但是它涵盖了为ARI配置asterisk的一些基础知识。
Asterisk Configuration Options for ARI
HTTP Server
asterisk中的HTTP server是通过http.conf配置的。请注意,这里并没有描述了http.conf中所有选项 - 相反,他它列出了ARI最有用的选项。
Section | Parameter | Type | Default | Description |
---|---|---|---|---|
general | ||||
enabled | Boolean | False | Enable the HTTP server. The HTTP server in Asterisk is disabled by default. Unless it is enabled, ARI will not function! | |
bindaddr | IP Address | The IP address to bind the HTTP server to. This can either be an explicit local address, or 0.0.0.0 to bind to all available interfaces. | ||
prefix | String | A prefix to require for all requests. If specified, requests must begin with the specified prefix. | ||
tlsenable | Boolean | False | Enable HTTPS | |
tlsbindaddr | IP Address/Port | The IP address and port to bind the HTTPS server to. This should be an IP address and port, e.g., 0.0.0.0:8089 | ||
tlscertfie | Path | The full path to the certificate file to use. Asterisk only supports the .pem format. | ||
tlsprivatekey | Path | The full path to the private key file. Asterisk only supports the .pem format. If this is not specified, the certificate specified in tlscertfile will be searched for the private key. |
http.conf示例
[general]
enabled = yes
bindaddr = 0.0.0.0
bindport = 8088
TLS
强烈建议使用TLS加密HTTP信令,使用安全的websocket接收事件。这需要在http.conf配置TLS信息,从你的ARI应用创建安全的websocket/HTTP连接。
ARI Configuration
ARI users和properties通过ari.conf配置。请注意,这里并没有罗列所有的选项;此列表包含ARI中配置users的最有用的选项。有关完整说明,请参阅ARI configuration文档。
Section | Parameter | Type | Default | Description |
---|---|---|---|---|
general | ||||
enabled | Boolean | False | Enable/disable ARI. | |
pretty | Boolean | No | Format JSON responses and events in a human readable form. This makes the output easier to read, at the cost of some additional bytes. | |
allowed_origins | String | A comma separated list of allowed origins for Cross-Origin Resource Sharing. | ||
[user_name] | ||||
type | String | Must be user. Specifies that this configuration section defines a user for ARI. | ||
read_only | Boolean | No | Whether or not the user can issue requests that alter the Asterisk system. If set to Yes, then only GET and OPTIONS HTTP requests will be serviced. | |
password_format | String | plain | Can be either plain or crypt. When the password is plain, Asterisk will expect the user’s password to be in plain text in the password field. When set to crypt, Asterisk will use crypt(3) to decrypt the password. A crypted password can be generated using mkpasswd -m sha-512. | |
password | String | The password for the user. |
ari.conf示例
[general]
enabled = yes
pretty = yes
allowed_origins = localhost:8088,http://ari.asterisk.org
[asterisk]
type = user
read_only = no
password = asterisk
; password_format may be set to plain (the default) or crypt. When set to crypt,
; crypt(3) is used to validate the password. A crypted password can be generated
; using mkpasswd -m sha-512.
;
[asterisk-supersecret]
type = user
read_only = no
password = $6$nqvAB8Bvs1dJ4V$8zCUygFXuXXp8EU3t2M8i.N8iCsY4WRchxe2AYgGOzHAQrmjIPif3DYrvdj5U2CilLLMChtmFyvFa3XHSxBlB/
password_format = crypt
Configuring the Dialplan for ARI
默认情况下,ARI不能asteirsk中的任意channel。channel可能在一个长期运行的dialplan应用;也可能由AGI控制;可能已经挂断。如果asteirsk没有以安全的方式将信道控制权交给ARI,那么ARI暴露的很多操作根本就不安全。
为了将channel交给ARI,asterisk使用名为Stasis的dialplan应用。Stasis 和asterisk的其他dialplan应用一样,除了安全的将控制权交给ARI应用之外不做任何事情。Stasis dialplan应用有两个参数:
- channel移交的ARI应用的名称。在单个asterisk实例可以存在多个ARI应用,每个ARI应用只能操作他控制的channels。
- 移交ARI时传递给ARI应用的参数
Example: Two ARI Applications
extension.conf中dialplan的片段,说明了两个ARI应用。第一个channel到ARI的"Intro-IVR"的ARI应用没有任何附加参数,第二个channel到ARI应用的"Super-Conference"带有一个参数:指定进入的会议室。
[default]
exten => ivr,1,NoOp()
same => n,Stasis(Intro-IVR)
same => n,Hangup()
exten => conference,1,NoOp()
same => n,Stasis(Super-Conference,100)
same => n,Hangup()
当channel进入Stasis应用时,asterisk将检查是否为该应用建立websocket连接。如果是,将channel移交给ARI控制,为websocekt订阅channel事件,并向websocket发送StasisStart事件,通知它channel已经进入应用。
websocket连接是必须的。
如果你没有为特定应用创建到asterisk的websocket连接,当一个channel进入应用的Stasis时,asterisk将立即从应用中获取channel并返给dialplan。This is to prevent channels from entering into an application before something is ready to handle them.
请注意,如果连接断开,asterisk将知道之前存在的连接,并允许channel进入(尽管你收到告警:事件丢失);