[Asterisk-Users] Webui to show registered phones

Sherwood McGowan madprofzero at yahoo.com
Fri Oct 28 06:56:28 MST 2005


You could always (I'll actually do it, I have similar scripts written) just
whip up a php script that connects to a Asterisk Manager Proxy (to limit the
possibility of crashing the server by making too many Manager API
connections), and have it issue the following commands:

Action: Command
Command: Sipshowpeers

And read the socket stream back using a loop and the flush() command. 

Here's an example of the code, only this one is using "sip show peer
<number>" to get the status of a single customer (If you use qualify=yes for
a customer, the server will send requests for an ack to the UA every so many
minutes, to ensure that it's reachable)


Here ya go, hope you guys enjoy it! There's going to be a lot of this
functionality being put in ARTCP and SACP (Asterisk RealTime Control Panel
and Static Asterisk Control Panel, respectively). That way, non-technical
people can get output that they can understand (just do a str_replace() with
some arrays for the $needle, $haystack, and $replacment) without possibly
killing your server.

<?php
/* 
	Performs a "sip show peer" on the passed number
	to get the status information of the customer's UA
	and other information about their connection
				(great for troubleshooting)
	Uses astmanproxy on localhost to pass command
*/

$number = $_GET['number'];
// $socket = fsockopen("127.0.0.1", 1234, $errno, $errstr, 5);
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket < 0) {
   echo "socket_create() failed: reason: " . socket_strerror($socket) .
"\n";
}

$result = socket_connect($socket, '127.0.0.1', 1234);
if ($result < 0) {
   echo "socket_connect() failed.\nReason: ($result) " .
socket_strerror($result) . "\n";
}

if (!$socket) {
	echo "$errstr ($errno)<br />\n";
} else {
	echo "";
	socket_write($socket, "Action: SIPshowpeer\r\n");
	socket_write($socket, "Peer: " . trim($number) ."\r\n\r\n");
	echo "<pre>";
	while($buffer = socket_read($socket, 512, PHP_NORMAL_READ)){
		if(trim($buffer) == "Response: Error") {
			echo "Received error - <b>".trim($buffer)."</b>.
<br>Number probably not found";
			break;
		}
		if(trim($buffer) == "--END COMMAND--"||substr_count($buffer,
"Server:") >0) { 
			echo $buffer;
			break;
		}
		echo $buffer;
		flush();
	}
	echo "</pre>";
	socket_write($socket, "Action: Logoff\r\n\r\n");
	socket_close($socket);
}
?>



->-----Original Message-----
->From: asterisk-users-bounces at lists.digium.com 
->[mailto:asterisk-users-bounces at lists.digium.com] On Behalf Of 
->Adam Moffett
->Sent: Friday, October 28, 2005 9:46 AM
->To: Asterisk Users Mailing List - Non-Commercial Discussion
->Subject: Re: [Asterisk-Users] Webui to show registered phones
->
->
->> Hi all, does anyone know if there is any app/webui that can show 
->> phones that are currently registered to *.  I guess this sort of 
->> funcionality counld be grabbed from the CLI with iax2 show 
->peers and 
->> sip show peers, but having little programming knowledge 
->wouldn't know 
->> where to start.
->>
->> I'm asking because we currently have several sip phones onsite and 
->> lots of remote iax2 users who would like to see 
->availability without 
->> dialing.
->>
->> Bails
->
->P.S.:
->
->show peers will show you the devices that are registered.  If 
->you're interested in how many active calls there are I think 
->you want iax2 show channels and sip show channels.
->_______________________________________________
->--Bandwidth and Colocation sponsored by Easynews.com --
->
->Asterisk-Users mailing list
->Asterisk-Users at 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
->





More information about the asterisk-users mailing list