[asterisk-users] To Asterisk AMI Gurus - Tacking issue with originate

Bruce Nik brucevoip at gmail.com
Fri Dec 18 10:31:25 CST 2009


Thanks for the input.

Once the form is submitted the variables obtain a value which is the phone
number, dial number, and spoof number. I did the telnet and it works fine.

Now, I am really not a php coder and just stealing code from here and there
to make this working. Here is what I noticed that kind of works. If I do
this, I see an attempt to connect:

$oSocket = fsockopen($sys_ip, 5038, $errnum, $errdesc) or die("Connection to
host failed");
if ($_POST['x']) {

But I keep it like the normal way (connecting after form is submitted):

if ($_POST['x']) {
$oSocket = fsockopen($sys_ip, 5038, $errnum, $errdesc) or die("Connection to
host failed");

I am amazed that there is absolutely no proper documentation on how to
connect to Asterisk AMI with PHP. All tutuorial just mention:   pass Action:
originate Channel: SIP/1234, blah blah blah and never give a simple example
of php.

Thanks a lot for your inputs guys.



On Fri, Dec 18, 2009 at 8:33 AM, Prince Singh <prince at drishti-soft.com>wrote:

> Obvious debugging steps at this point:-
>
>    1. Manually connecting to AMI and testing the commands
>     1. telnet 127.0.0.1 5038
>       2. Login command
>       3. Originate command
>    2. Use a dummy AMI listener instead of actual asterisk to see if the
>    events are going through
>       1. Stop asterisk (or change the manager port)
>       2. nc -l -k 127.0.0.1 5038
>       3. Confirm that 'nc' has taken the tcp port 5038
>       netstat -nlp | grep 5038
>       4. Test the php application to see if the login request can be seen
>       on the console from where 'nc' was started
>    3. Edit /etc/php.ini (or similar file) to enable logging and then check
>    the log file :)
>
>
>
>
>
>   On Fri, Dec 18, 2009 at 6:59 AM, Bruce Nik <brucevoip at gmail.com> wrote:
>
>>  Hello Everyone,
>>
>> I am making a simple index.php file which will allow a web user to enter
>> his $phoneNumb, $dialNumb, and callerID ($spoofNumb) and get the call
>> bridged. Following is the index.php and the contents of
>> extensions_custom.conf. When I submit the form nothing happens. I don't even
>> see Manager Connected msg. Your input will be much appreciated. I am
>> thinking I have some syntax problem.
>>
>> /etc/asterisk/extensions_custom.conf
>> *[testphp]
>> exten => _X.,1,Answer()
>> exten => _X.,n,Dial(SIP/testTrunk/${EXTEN})
>> exten => _X.,n,Hangup()*
>>
>> *
>> *
>> *
>> *
>> *
>> *****************************************************************************************************
>> *
>> /var/www/html/clickncall/index.php
>> <html>
>> <head>
>> <title>ClicknCall</title>
>> </head>
>> <body><br><br>
>> <div align="center">
>>
>> <?php
>>
>> $sys_ip = "127.0.0.1";
>> $User_str = "testphp";
>> $Secret_str = "testphp";
>>
>> if ($_POST['x']) {
>> $oSocket = fsockopen($sys_ip, 5038, $errnum, $errdesc) or die("Connection
>> to host failed");
>>
>> fputs($oSocket, "Action: login\r\n");
>> fputs($oSocket, "Username: $User_str\r\n");
>> fputs($oSocket, "Secret: $Secret_str\r\n\r\n");
>> fputs($oSocket, "Events: off\r\n\r\n");
>> fputs($oSocket, "Action: originate\r\n");
>> fputs($oSocket, "Channel: SIP/testTrunk/$phoneNumb\r\n");
>> fputs($oSocket, "Exten: $dialNumb\r\n");
>> fputs($oSocket, "Context: testphp\r\n");
>> fputs($oSocket, "Priority: 1\r\n\r\n");
>> fputs($oSocket, "Timeout: 10000\r\n");
>> fputs($oSocket, "CallerId: $spoofNumb\r\n");
>> fputs($oSocket, "Async: true\r\n");
>> fputs($oSocket, "Action: Logoff\r\n\r\n");
>>
>> fclose($oSocket);
>>
>> print $_POST['x'];
>>
>> } else {
>>   print "<form method=\"post\"action=\"$_SERVER[PHP_SELF]\">";
>>   print "<br>";
>>   print "PHONE Number: <input type=\"text\"name=\"phoneNumb\">";
>>   print "<br>";
>>   print "PARTY Number: <input type=\"text\"name=\"dialNumb\">";
>>   print "<br>";
>>   print "FORGE Number: <input type=\"text\"name=\"spoofNumb\">";
>>   print "<br>";
>>   print "<input type=\"Submit\" value=\"                         Dial
>>                        \">";
>>   print "</form>";
>>
>> } ?>
>>
>> </div>
>> </body>
>> </html>
>>
>>
>> ************************************************************************************
>> */etc/asterisk/manager_custom.conf*
>>  [testphp]
>> secret = testphp
>> deny=0.0.0.0/0.0.0.0
>> permit=127.0.0.1/255.255.255.0
>> read = system,call,log,verbose,command,agent,user
>> write = system,call,log,verbose,command,agent,user
>>
>>
>> Thanks,
>>
>>
>>
>> _______________________________________________
>> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
>>
>> asterisk-users mailing list
>> To UNSUBSCRIBE or update options visit:
>>   http://lists.digium.com/mailman/listinfo/asterisk-users
>>
>
>
>
> --
> Regards,
> Prince Singh
>
> Drishti-Soft Solutions Pvt Ltd
> 62-A, First Floor,
> Maruti Industrial Area,
> Sector - 18, Gurgaon - 122016
> Haryana, India.
>
> P: 91 124 4771000
> F: 91 124 4039120
> W: http://www.drishti-soft.com
> B: http://blog.drishti-soft.com
> ----
> DISCLAIMER
>
> This message may contain confidential, proprietary or legally Privileged
> information. In case you are not the original intended Recipient of the
> message, you must not, directly or indirectly, use, disclose, distribute,
> print, or copy any part of this message and you are requested to delete it
> and inform the sender.
> Any views expressed in this message are those of the individual sender
> unless otherwise stated. Nothing contained in this message shall be
> construed as an offer or acceptance of any offer by Drishti-Soft Solutions
> Pvt Ltd ("Drishti") unless sent with that express intent and with due
> authority of Drishti.
> Drishti has taken enough precautions to prevent the spread of viruses.
> However the company accepts no liability for any damage caused by any virus
> transmitted by this email.
>
> _______________________________________________
> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
>
> asterisk-users mailing list
> To UNSUBSCRIBE or update options visit:
>   http://lists.digium.com/mailman/listinfo/asterisk-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20091218/4fd64574/attachment.htm 


More information about the asterisk-users mailing list