1

I have an Asterisk server working perfectly fine in a payment environment. Now, there is need for me to separate the business logics from the Asterisk Server for efficiency, and protecting the AGI scripts for obvious reasons.

The question is, how do I convert the existing working AGI scripts to FASTAGI scripts, or how do I call the existing AGI scripts from a FASTAGI server?

I have red some post with answers on this platform, but none have stated clearly how to do this from scratch. Will be glad to have clear understanding on how to achieve this using PHP.

CEDOC
  • 21
  • 1
  • 5

1 Answers1

0

You can use xinetd for this. From your dialplan on each asterisk box, call agi with a fast agi parameter, substituting your IP address of the fastagi server:

AGI(agi://192.168.1.100/)

Make sure you have in /etc/services something like:

agi             4573/tcp                        # FAST AGI entry

On the FastAGI server: In a file called /etc/xinetd.d/agi (make sure /etc/xinetd.conf is loading modules from /etc/xinetd.d/) have a definition which calls your agi script.

# description: agi service for PHP fastagi interaction
service agi
{
        socket_type  = stream
        user         = root
        group        = nobody
        server       = /path/to/agiLaunch.sh
        wait         = no
        protocol     = tcp
        bind         = 127.0.0.1
        disable      = no
        per_source   = UNLIMITED
        instances    = UNLIMITED
        cps          = 1000 0
}

In your AGI script, you can now just do as you normally would, by reading STDIN or STDOUT.

dougBTV
  • 1,883
  • 1
  • 15
  • 18
  • Okay, thanks for the response. Have red about this somewhere on this platform, and have tried it. So, if I have say 10 AGI scripts already working, how do I use this method to have all AGI scripts called with this approach? – CEDOC Apr 09 '15 at 13:07
  • You could have a diffferent port for each one with xinetd. But! I would likely use the "network script" feature, e.g. if you call `AGI(agi://hostname[:port][/script],args)` what you put in `/script` part will be in a variable passed to the script as a channel variable `agi_network_script`. So, make a script that handles which AGI script of the 10 to hand it to, using the network script. Also the book "asterisk: the future of telephony" uses xinetd with their fastagi examples, for what it's worth. – dougBTV Apr 09 '15 at 14:19
  • Thanks alot dougBTV, you have been so helpful. Do you have any idea on how authentication can be done to allow ONLY authenticated person or users to call the FASTAGI scripts from their dialplan? Am planning to extend the service to anyone willing to use the AGI scripts inside their dialplan. – CEDOC Apr 10 '15 at 09:20
  • Hello dougBTV, have done everything and its seems to be fine, except that I keep getting this error "xinetd[5587]: EXIT: fastagi status=255 pid=5644 duration=0(sec)". Is there clue to why the failure happening? Also before this error that message was "[asmanager] => Apr 13 15:54:55 cpgserver php: [in] => Resource id #1 Apr 13 15:54:55 cpgserver php: [out] => Resource id #2 Apr 13 15:54:55 cpgserver php: [audio] => Apr 13 15:54:55 cpgserver php: [option_delim] => , Apr 13 15:54:55 cpgserver php: ) " – CEDOC Apr 14 '15 at 09:43
  • @CEDOC -- have you tried issuing at the Asterisk CLI: `agi set debug on` --> this might give you some more insight. As for the authentication (sorry I missed that message) -- You might want to put an authentication string in the `/networkscript` maybe? I haven't had this requirement before personally. So I'm taking a guess. – dougBTV Apr 14 '15 at 12:23
  • Yes, I have agi debugging turned on, and the last message from the CLI says this "AGI Tx >> HANGUP" – CEDOC Apr 14 '15 at 21:42