Guys, is anybody using PHP sockets to connect to the Manager and send command like "show voicemail users" for example or any other? My question is, how to parse the return info in a way that can be shown back to the user via web (discard all the manager responses not needed)? Thx in advance for any help you can provide.
Anton Krall wrote:> Guys, is anybody using PHP sockets to connect to the Manager and send > command like "show voicemail users" for example or any other? > > My question is, how to parse the return info in a way that can be shown back > to the user via web (discard all the manager responses not needed)?Use preg_match() to match the lines you want the user to see on the website. $socket = fsockopen("localhost","5038", $errno, $errstr, 30); if(!$socket) { print "No socket"; exit(); } fputs($socket, "Action: Login\r\n"); fputs($socket, "Events: Off\r\n"); fputs($socket, "UserName: bleh\r\n"); fputs($socket, "Secret: bleh\r\n\r\n"); fputs($socket, "Action: Command\r\n"); fputs($socket, "Command: show channels\r\n\r\n"); fputs($socket, "Action: Logoff\r\n\r\n"); while(!feof($socket)) { $buff = fgets($socket,1024); if(preg_match("/SIP\/.*/", $buff)) { print "I found a SIP call"; } }
On 9/6/05, Anton Krall <akrall-lists@intruder.com.mx> wrote:> Guys, is anybody using PHP sockets to connect to the Manager and send > command like "show voicemail users" for example or any other? > > My question is, how to parse the return info in a way that can be shown back > to the user via web (discard all the manager responses not needed)? > > Thx in advance for any help you can provide.I had done it with a Perl script to pull call forwarding data, but it's the same basic idea. If you want a coding example, check out dialparties.agi, which has a nice example of how to do it. You can always use system() or exec() to do it with a perl script, as well, if you don't want to reinvent the wheel. Jeff
You'll wanna play with socket_read / socket_write.... Doing fsock_opens, fgets(), etc... Is clunky ->-----Original Message----- ->From: asterisk-users-bounces@lists.digium.com ->[mailto:asterisk-users-bounces@lists.digium.com] On Behalf Of ->Anton Krall ->Sent: Tuesday, September 06, 2005 1:06 PM ->To: 'Asterisk Users Mailing List - Non-Commercial Discussion' ->Subject: [Asterisk-Users] PHP and ASterisk Manager -> ->Guys, is anybody using PHP sockets to connect to the Manager ->and send command like "show voicemail users" for example or any other? -> ->My question is, how to parse the return info in a way that ->can be shown back to the user via web (discard all the ->manager responses not needed)? -> ->Thx in advance for any help you can provide. -> ->_______________________________________________ ->--Bandwidth and Colocation sponsored by Easynews.com -- -> ->Asterisk-Users mailing list ->Asterisk-Users@lists.digium.com ->http://lists.digium.com/mailman/listinfo/asterisk-users ->To UNSUBSCRIBE or update options visit: -> http://lists.digium.com/mailman/listinfo/asterisk-users ->
I was able to do and if and while loops to get the block of lines I want.. Now.. Another issue. I need to parse the line read to insert it into a table but seems Asterisk inserts TABS or SPACES inconsistantly.. For example: Xxx(TAB)xxx(5 spaces)xxx Next line Xxx(TAB)xxx(3 spaces)xxx Im having a hard time figuring out how Asterisk Manager returns the stuff :) Well..s o far so good... |-----Original Message----- |From: asterisk-users-bounces@lists.digium.com |[mailto:asterisk-users-bounces@lists.digium.com] On Behalf Of |Matthew Boehm |Sent: Martes, 06 de Septiembre de 2005 01:49 p.m. |To: Asterisk Users Mailing List - Non-Commercial Discussion |Subject: Re: [Asterisk-Users] PHP and ASterisk Manager | |Anton Krall wrote: |> Guys, is anybody using PHP sockets to connect to the Manager |and send |> command like "show voicemail users" for example or any other? |> |> My question is, how to parse the return info in a way that can be |> shown back to the user via web (discard all the manager |responses not needed)? | |Use preg_match() to match the lines you want the user to see |on the website. | |$socket = fsockopen("localhost","5038", $errno, $errstr, 30); | |if(!$socket) { | print "No socket"; | exit(); |} | |fputs($socket, "Action: Login\r\n"); |fputs($socket, "Events: Off\r\n"); |fputs($socket, "UserName: bleh\r\n"); |fputs($socket, "Secret: bleh\r\n\r\n"); | |fputs($socket, "Action: Command\r\n"); |fputs($socket, "Command: show channels\r\n\r\n"); | |fputs($socket, "Action: Logoff\r\n\r\n"); | |while(!feof($socket)) { | $buff = fgets($socket,1024); | if(preg_match("/SIP\/.*/", $buff)) { | print "I found a SIP call"; | } |} | |_______________________________________________ |--Bandwidth and Colocation sponsored by Easynews.com -- | |Asterisk-Users mailing list |Asterisk-Users@lists.digium.com |http://lists.digium.com/mailman/listinfo/asterisk-users |To UNSUBSCRIBE or update options visit: | http://lists.digium.com/mailman/listinfo/asterisk-users |