webenabled
to
yes
in the [general]
section of
manager.conf
. Pay attention to
httptimeout
, which defines the inactivity timeout after which
the user is automatically logged out of the web interface. To activate the
web server, set these parameters in
http.conf
:[general] enabled=yes enablestatic=yes bindaddr=127.0.0.1 bindport=8088 prefix=asterisk
enablestatic
need only be
activated if the AJAM will be serving static files from
/var/lib/asterisk/static-http/
. Normally you would
set this to no
, but it is needed for the purposes of the
Asterisk-AJAM demo (the section called “AJAM Demo”).read
and write
(see Section 7.3, “The Asterisk Manager Interface (AMI)”)
simply don't offer sufficient granularity. Always assume that a user can
initiate actions other than those you have made available on the web
page. It is far better to let your application use a PHP script
containing only the specific AMI commands it needs to do its job, and to
restrict the AMI rights for the accessing user as extra
insurance.http://localhost:8088/asterisk/manager
http://localhost:8088/asterisk/manager?action=Login&username=admin&secret=secret5
http://localhost:8088/asterisk/manager?action=MailboxCount&mailbox=123
manager
in the URL with
rawman
, we get plain text output. To log in and get a
message count from the mailbox, then:http://localhost:8088/asterisk/rawman?action=Login&username=admin&secret=secret5
Response: Success Message: Authentication accepted
http://localhost:8088/asterisk/rawman?action=MailboxCount&mailbox=123
Response: Success Message: Mailbox Message Count Mailbox: 123 NewMessages: 0 OldMessages: 0
http://localhost:8088/asterisk/rawman?action=Logoff
Response: Goodbye Message: Thanks for all the fish.
mxml
instead. The
XML output is presented formatted for better readability. In practice,
AJAM does not put line breaks inside the XML tags. Either way, a
compliant XML parser won't care.http://localhost:8088/asterisk/mxml?action=Login&username=admin&secret=secret5
<ajax-response> <response type='object' id='unknown'> <generic response='Success' message='Authentication accepted' /> </response> </ajax-response>
http://localhost:8088/asterisk/mxml?action=MailboxCount&mailbox=123
<ajax-response> <response type='object' id='unknown'> <generic response='Success' message='Mailbox Message Count' mailbox='123' newmessages='0' oldmessages='0' /> </response> </ajax-response>
http://localhost:8088/asterisk/mxml?action=Logoff
<ajax-response> <response type='object' id='unknown'> <generic response='Goodbye' message='Thanks for all the fish.' /> </response> </ajax-response>
eval()
. There are countless
implementations for PHP, Perl, etc. but a JSON implementation for AJAM
does not yet exist. One can, however, convert the plain-text output
into JSON on the client side, if that turns out to be easier or if
it's easily done using available Javascript libraries. Here's an
example to get you thinking:// We assume the received response and // simulate it here: var responseText = 'Response: Success\n' +'Message: Mailbox Message Count\n' +'Mailbox: 123\n' +'NewMessages: 0\n' +'OldMessages: 0\n'; // Escape single quotation marks: responseText = responseText.replace( /\'/g, "\\'" ); // Wrap fields in quotes: responseText = responseText.replace( /^([a-z\d]*):\s*(.*)/gmi, "'$1':'$2'," ); // Convert to object: eval('var packet = {'+ responseText +'}'); // Now you can access the fields as you would with any object: alert( packet['NewMessages'] ); // returns "0"
http://localhost:8088/asterisk/rawman?action=Ping
Response: Pong
http://localhost:8088/asterisk/static/ajamdemo.html
Status
the currently active channels. You can use the
AJAM demo as a basis for your own AJAX applications.ProxyPass /ajam http://localhost:8088/asteriskin the appropriate place in
httpd.conf
, so that all
requests for /ajam
are passed on to AJAM instead of being
served by Apache.