项目作者: kf1day

项目描述 :
FastCGI event provider for Asterisk
高级语言: C
项目地址: git://github.com/kf1day/asterisk-res-fastcgi.git
创建时间: 2017-10-24T07:04:09Z
项目社区:https://github.com/kf1day/asterisk-res-fastcgi

开源协议:BSD 2-Clause "Simplified" License

下载


res_fastcgi

FastCGI event provider for Asterisk

A small module which provides AMI messages directly to FastCGI server, such as PHP-FPM. It can be useful to process events in a custom way

Comparbility

Tested on Asterisk 13.13, 16.4 and 18.4

Compilation

Usual boring sequence:

./configure && make && make install

Data transfer

Module sends data to script through environment variables, and doesn`t care what data receives back.

Here is an example data of single script shot:

  1. $_SERVER = Array (
  2. 'USER' => 'asterisk',
  3. 'HOME' => '/var/lib/asterisk',
  4. 'RemoteAddress' => 'IPV4/UDP/1.2.3.4/60243',
  5. 'LocalAddress' => 'IPV4/UDP/5.6.7.8/5060',
  6. 'SessionID' => '485334176-1794503427-955328712',
  7. 'AccountID' => 1234,
  8. 'EventVersion' => 1,
  9. 'Service' => 'PJSIP',
  10. 'Severity' => 'Error',
  11. 'EventTV' => '2020-01-01T01:02:04.735+0000',
  12. 'Privilege' => 'security,all',
  13. 'Event' => 'InvalidAccountID',
  14. 'REQUEST_METHOD' => 'GET',
  15. 'SCRIPT_FILENAME' => '/var/lib/asterisk/manager.php',
  16. 'FCGI_ROLE' => 'RESPONDER',
  17. 'PHP_SELF' => '',
  18. 'REQUEST_TIME_FLOAT' => 1600001234.7358,
  19. 'REQUEST_TIME' => 1600001234
  20. );

Sample configuration with PHP-FPM

Make sure your listening socket is writeable by Asterisk’s running user. The good idea is to create a separate pool of PHP-FPM processes by creating a file (e.g. ast.conf) in you fpm pool config directory (e.g. /etc/php/7.0/fpm/pool.d/)

  1. [ast]
  2. user = nobody
  3. group = nogroup
  4. listen = /var/run/asterisk/php-fpm.sock
  5. listen.owner = asterisk
  6. listen.group = asterisk
  7. pm = static
  8. pm.max_children = 2

Then restart a service - systemctl restart php-fpm

Now configure module definitions in /etc/asterisk/res_fastcgi.conf

  1. [global]
  2. socket = /var/run/asterisk/php-fpm.sock
  3. script = /var/lib/asterisk/manager.php

Options are:

  • socket - UNIX domain socket path of FastCGI server, default is /var/run/asterisk/php-fpm.sock
  • script - Script name for FastCGI processor, default is /var/lib/asterisk/manager.php

Now we add some buisness-logic to a processing script (make sure it is readable by pool running user!)

  1. <?php
  2. if ( ! in_array( $_SERVER['Event'], [ 'ChallengeSent', 'SuccessfulAuth', 'RTCPSent', 'RTCPReceived' ] ) ) {
  3. file_put_contents( '/tmp/debug.out', print_r( $_SERVER, 1 ), FILE_APPEND );
  4. }

And finally load module via asterisk console - asterisk -x "module load res_fastcgi"

Now we can see file /tmp/debug.out populating by AMI events