Jump to content

Get active/current call list


Ryan
 Share

Recommended Posts

Hello,

 

I would like to grab a list of current calls from pbxnsip. I don't care how I get it, even if I just have to read from an XML file or anything like that. I do have my CDR tied into MySQL, but I am not sure if the current calls get written to the database; maybe someone can clear that up.

 

I will be using a PHP script to parse whatever info I can find, just fyi.

 

Ryan

Link to comment
Share on other sites

Seem like using cURL could be an issue as the page is ajax-updated and lags about a second before it checks, so the page is loaded, but the background is still going.

 

Right. There is this small blind spot when using AJAX! That's why multipart/mime (like MJPEG) would be better or CSTA. Anyway, what is there today is CSTA, "M-XML" might be an option later.

Link to comment
Share on other sites

Right. There is this small blind spot when using AJAX! That's why multipart/mime (like MJPEG) would be better or CSTA. Anyway, what is there today is CSTA, "M-XML" might be an option later.

 

Alright....so, any way you can point me in the right direction? Like a specific page to query or how I can try and use this CSTA with pbxnsip? I'm going to need this as since we're switching from Asterisk (which has active call list working), and I'll need a current active call list from pbxnsip.

Link to comment
Share on other sites

I got it!

 

I viewed the source of the "reg_calls.htm" page. It's making AJAX calls to the "ajax.htm" page. This page will return an XML response with the current calls. At least that's how it seems to be. Open the page like this (replace mydomain.com with your domain of course):

 

http://mydomain.com/ajax.htm?action=call_list&domain=mydomain.com&token=whatever

 

With no active calls, the response was:

 

<ResultSet>
<Token>74</Token>
<Calls/>
</ResultSet>

 

When I made a phone call, I refreshed and got:

 

<ResultSet>
<Token>73</Token>
-
<Calls>
-
<Call>
<Start>2010/10/19 11:54:43</Start>
<From>Ryan G (107@mydomain.com)</From>
<To>xxxxxxx@mydomain.com</To>
<State>connected</State>
<Index>7</Index>
<Gain/>
<Trunk>gxw</Trunk>
</Call>
</Calls>
</ResultSet>

 

And voila! (I replaced the number with xxxxxxx and domain with mydomain.com fyi).

 

So obviously you could just Curl request this page and anytime you need it you have a current call list.

Link to comment
Share on other sites

I got it!

 

I viewed the source of the "reg_calls.htm" page. It's making AJAX calls to the "ajax.htm" page. This page will return an XML response with the current calls. At least that's how it seems to be. Open the page like this (replace mydomain.com with your domain of course):

 

http://mydomain.com/ajax.htm?action=call_list&domain=mydomain.com&token=whatever

 

With no active calls, the response was:

 

<ResultSet>
<Token>74</Token>
<Calls/>
</ResultSet>

 

When I made a phone call, I refreshed and got:

 

<ResultSet>
<Token>73</Token>
-
<Calls>
-
<Call>
<Start>2010/10/19 11:54:43</Start>
<From>Ryan G (107@mydomain.com)</From>
<To>xxxxxxx@mydomain.com</To>
<State>connected</State>
<Index>7</Index>
<Gain/>
<Trunk>gxw</Trunk>
</Call>
</Calls>
</ResultSet>

 

And voila! (I replaced the number with xxxxxxx and domain with mydomain.com fyi).

 

So obviously you could just Curl request this page and anytime you need it you have a current call list.

 

 

I tested it here and that information may be handy... the authentication may be a problem though... in my brief testing you have to run it twice for it to work... once to login and then a 2nd time to get the information...

Link to comment
Share on other sites

I tested it here and that information may be handy... the authentication may be a problem though... in my brief testing you have to run it twice for it to work... once to login and then a 2nd time to get the information...

 

You are correct. But with Curl with PHP, you simply do 3 steps. Set your first curl URL to login.htm (set the login POST params), then hit the ajax.htm page, then logout.htm.

 

Here is the code I wrote to make this work. I hope someone finds it useful.

 

 

<?php
/*
* Pbxnsip Current Active Calls list
*
* Requires PHP 5+ because of simplexml functions
*
* Written by Ryan Gehrig
*
*/

//
// Set these to your server specifics
//

// Admin username/pass
$pbx_user = 'admin';
$pbx_pass = 'pass123';

// Set server info
$pbx_domain	   = 'http://mydomain.com'; // Main pbxnsip domain
$pbx_phone_domain = 'ca.mydomain.com'; // Domain of your actual calls


################################################################################
##########################


// Ajax URL
$pbx_ajax_url	= $pbx_domain . '/ajax.htm?action=call_list&domain=' . $pbx_phone_domain . '&token=xxxxxxxx';

// Logout page
$pbx_logout_url = $pbx_domain . '/logout.htm';

// Fields to pass for Login
$postfields = "login_account=$pbx_user&login_password=$pbx_pass&login_type=auto&dom_link=dom_index.htm&usr_link=usr_index.htm";


// Setup cookies for login
$cookies  = 'cookies.txt';
if (!file_exists($cookies))
{
  $fp = fopen($cookies, 'w');
  fwrite($fp, '');
  fclose($fp);
}


//
// Connect to pbxnsip interface
//

// Login first
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
curl_setopt($ch, CURLOPT_URL, $pbx_domain);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_exec($ch);

// Get Ajax page
curl_setopt($ch, CURLOPT_URL, $pbx_ajax_url);
$content = curl_exec ($ch);

// Logout
curl_setopt($ch, CURLOPT_URL, $pbx_logout_url);
curl_exec ($ch);

// Close up
curl_close($ch); 

#####################################################

//
// Get XML response from Pbxnsip
//
$xml = simplexml_load_string($content);
$ret_token  = $xml->Token;
$ret_calls  = count($xml->Calls->Call);
$call_start = $xml->Calls->Call->Start;
$call_from  = $xml->Calls->Call->From;
$call_to	= $xml->Calls->Call->To;
$call_state = $xml->Calls->Call->State;
$call_index = $xml->Calls->Call->Index; // Not sure what this is
$call_gain  = $xml->Calls->Call->Gain;  // Not sure what this is either
$call_trunk = $xml->Calls->Call->Trunk;


?>

 

After this you could simply echo the variables, or use some kind of XML to PHP Array function (there are a million of them) and parse it that way.

 

Ryan

Link to comment
Share on other sites

I tested it here and that information may be handy... the authentication may be a problem though... in my brief testing you have to run it twice for it to work... once to login and then a 2nd time to get the information...

 

I am using VB so what I did was just pass the string twice but putting the admin username/password in the URL:

 

http://admin:pass123@mydomain.com/ajax.htm...;token=whatever

 

$call_index = $xml->Calls->Call->Index; // Not sure what this is

 

This is the call identifier which now that I know I can pull this I am planning on building a front end for our receptions to force pages to stop paging... (ie you can pass that ID to http://admin:pass123@mydomani.com/dom_call...lete_call={ID})

 

I was looking for a way to do this without giving the receptionist full access to the PBX system.

 

 

$call_gain = $xml->Calls->Call->Gain; // Not sure what this is either

 

Mine never showed anything in Gain put typically means something do to with volume amplification...

 

-Adam

Link to comment
Share on other sites

I am using VB so what I did was just pass the string twice but putting the admin username/password in the URL:

 

http://admin:pass123@mydomain.com/ajax.htm...;token=whatever

 

$call_index = $xml->Calls->Call->Index; // Not sure what this is

 

This is the call identifier which now that I know I can pull this I am planning on building a front end for our receptions to force pages to stop paging... (ie you can pass that ID to http://admin:pass123@mydomani.com/dom_call...lete_call={ID})

 

I was looking for a way to do this without giving the receptionist full access to the PBX system.

 

 

$call_gain = $xml->Calls->Call->Gain; // Not sure what this is either

 

Mine never showed anything in Gain put typically means something do to with volume amplification...

 

-Adam

 

I see. The index could be very useful then, for call barging, recording etc. I didn't even think of that.

 

One other thing I wanted to note, is that when getting the XML data back and converting into an array, the XML response from pbxnsip isn't in a numbered format until there is more than 1 call connected/alerting. What that means is if you have 1 connected call, the response is like:

 

Calls->Call->Start;

Calls->Call->From;

 

etc. But if there's more than 1 call coming in, it becomes numbered, like this:

 

Calls->Call->0->Start;

Calls->Call->0->From;

 

Calls->Call->1->Start;

Calls->Call->1->From;

 

etc etc. So if you want a foreach loop or a for loop, you can only use it if there is more than 1 call. Otherwise you simply call the data like $xml['Calls']['Call']['Start'] etc.

Link to comment
Share on other sites

  • 1 year later...
  • 2 weeks later...

Hi,

when I call this link

http://10.200.2.123:8089/ajax.htm?action=call_list&domain=pbx.centricall.com&token=whatever

without login to web page I get:

 

<Call>

<Start>12/22 16:58</Start>

<From>05374435533</From>

<To>70@10.200.2.123</To>

<State>connected</State>

<Index>14307</Index>

<Gain/>

<Trunk>CC GELEN</Trunk>

</Call>

 

But I login

<Call>

<Start>12/22 16:58</Start>

<From>05374435533</From>

<To>70 (6021)</To>

<State>connected</State>

<Index>14307</Index>

<Gain/>

<Trunk>CC GELEN</Trunk>

</Call>

 

Only Difference between "To" Tags

<To>70@10.200.2.123</To>

<To>70 (6021)</To>

 

I have tried lots of thing.

We could not keep sessions for login with .Net code (HttpWebRequest).

Is there a way to get "<To>70 (6021)</To>" information without login.

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...