Koozali.org: home of the SME Server

Caller Info and EGroupware

Offline soprom

  • *
  • 589
  • +0/-0
    • www.logiciel-libre.org
Caller Info and EGroupware
« on: April 12, 2008, 10:42:33 PM »
I would like to share my caller info script...

I use YAACID on my workstations to monitor phone.
- individual usernames are required in manager.conf if I don't thrust some users
- http://www.shatterit.com/opensource/yaacid/
- l prefer to disable as many options as possible, because YAACID has many options when triggered

When the phone rings, YAACID monitoring deamon will trigger the link to the script.
http://<server&path>/callerinfo.php?userid=<egw>&callerid=$CALLERID&id=$UNIQUEID&calltime=$TIME&callername=$CALLERIDNAME
- userid is a valid user account in egroupware

The script "callerinfo.php" is installed on the intranet:

Code: [Select]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Caller Info</title>

<?php 

// Credentials and path to adapt to your setup
# =======================================================
# Connection to egroupware database
$hostname_egw "10.10.10.10";
$database_egw "egroupware";
$username_egw "egroupwarelanuser";
$password_egw "zasdfaseradfadf";
// path to your egroupware
$egwhost="https://sme-server/egroupware";
# =======================================================

// path to view contact in egroupware
$egwlink=$egwhost."/index.php?menuaction=addressbook.uicontacts.view&contact_id=";

// functions:
# =======================================================

// Strip non-numeric data in phone number
function stripit ($number){ return (ereg_replace("[^A-Za-z0-9]"""$number));}

// Callerid matches addressbook number?
function goodnumber($number,$tested){ return ($number==$tested);}

// Format number like (555) 555-1234 (does not work yet !)
function formatnumber($number){
$number=stripit($number);
if (strlen($number)<10){
return ("(".substr($number,0,3).")".substr($number,4,3)."-".substr($number,7,4));
}else{
return ($number);
        }
}

// retreive parameters from YAACID
# =======================================================

$id=$_GET['id']; // id=$UNIQUEID
$userid=$_GET['userid']; // userid=<username known to egroupware>
$calltime=$_GET['calltime']; // calltime=$TIME
$callerid=stripit($_GET['callerid']); // callerid=$CALLERID

// used for click-to-call eventually
$pbxext=$_GET['pbxext']; // pbxext=<extension for username>
$pbxpwd=$_GET['pbxpwd']; // pbxpwd=<password for extension>

# Caller name / callername=$CALLERIDNAME (does not work yet!)
$callername "(inconnu)";
if (
strlen(trim($_GET['callername']))>0) {$callername "[".$_GET['callername']."]";}

// Create recordsets from egroupware
# =======================================================

$egw mysql_pconnect($hostname_egw$username_egw$password_egw) or trigger_error(mysql_error(),E_USER_ERROR); 
mysql_select_db($database_egw$egw);

// Make a list of all phones numbers in the address book

$query_rsAllphones "
      SELECT egw_addressbook.contact_id, egw_addressbook.tel_work as PhoneNumber, 'tel_work' as PhoneType, egw_addressbook.n_fn, egw_addressbook.org_name,contact_email FROM egw_addressbook WHERE trim(egw_addressbook.tel_work) <> '' 
UNION SELECT egw_addressbook.contact_id, egw_addressbook.tel_home as PhoneNumber, 'tel_home' as PhoneType, egw_addressbook.n_fn, egw_addressbook.org_name, contact_email FROM egw_addressbook WHERE trim(egw_addressbook.tel_home) <> ''  
UNION SELECT egw_addressbook.contact_id, egw_addressbook.tel_cell as PhoneNumber, 'tel_cell' as PhoneType, egw_addressbook.n_fn, egw_addressbook.org_name, contact_email FROM egw_addressbook WHERE trim(egw_addressbook.tel_cell) <> '' 
UNION SELECT egw_addressbook.contact_id, egw_addressbook.tel_fax as PhoneNumber, 'tel_fax' as PhoneType, egw_addressbook.n_fn, egw_addressbook.org_name, contact_email FROM egw_addressbook WHERE trim(egw_addressbook.tel_fax) <> '' 
UNION SELECT egw_addressbook.contact_id, egw_addressbook.tel_assistent as PhoneNumber, 'tel_assistent' as PhoneType, egw_addressbook.n_fn, egw_addressbook.org_name, contact_email FROM egw_addressbook WHERE trim(egw_addressbook.tel_assistent) <> '' 
UNION SELECT egw_addressbook.contact_id, egw_addressbook.tel_car as PhoneNumber, 'tel_car' as PhoneType, egw_addressbook.n_fn, egw_addressbook.org_name, contact_email FROM egw_addressbook WHERE trim(egw_addressbook.tel_car) <> '' 
UNION SELECT egw_addressbook.contact_id, egw_addressbook.tel_pager as PhoneNumber, 'tel_pager' as PhoneType, egw_addressbook.n_fn, egw_addressbook.org_name, contact_email FROM egw_addressbook WHERE trim(egw_addressbook.tel_pager) <> '' 
UNION SELECT egw_addressbook.contact_id, egw_addressbook.tel_fax_home as PhoneNumber, 'tel_fax_home' as PhoneType, egw_addressbook.n_fn, egw_addressbook.org_name, contact_email FROM egw_addressbook WHERE trim(egw_addressbook.tel_fax_home) <> '' 
UNION SELECT egw_addressbook.contact_id, egw_addressbook.tel_cell_private as PhoneNumber, 'tel_cell_private' as PhoneType, egw_addressbook.n_fn, egw_addressbook.org_name, contact_email FROM egw_addressbook WHERE trim(egw_addressbook.tel_cell_private) <> '' 
UNION SELECT egw_addressbook.contact_id, egw_addressbook.tel_other as PhoneNumber, 'tel_other' as PhoneType, egw_addressbook.n_fn, egw_addressbook.org_name, contact_email FROM egw_addressbook WHERE trim(egw_addressbook.tel_other) <> '' 
UNION SELECT egw_addressbook.contact_id, egw_addressbook.tel_prefer as PhoneNumber, 'tel_prefer' as PhoneType, egw_addressbook.n_fn, egw_addressbook.org_name, contact_email FROM egw_addressbook WHERE trim(egw_addressbook.tel_prefer) <> '' ;"
;

$rsAllphones mysql_query($query_rsAllphones$egw) or die(mysql_error());
$row_rsAllphones mysql_fetch_assoc($rsAllphones);


// Make a recordset for the usename's account to get the account_id

$query_rsAccounts "SELECT egw_accounts.account_id, egw_accounts.account_lid FROM egw_accounts WHERE egw_accounts.account_lid='".$userid."';";
$rsAccounts mysql_query($query_rsAccounts$egw) or die(mysql_error());
$row_rsAccounts mysql_fetch_assoc($rsAccounts);
$account_id=$row_rsAccounts ['account_id'];

// portion of link to use later
$egw_ref='<a href="'.$egwlink;

?>



<style type="text/css">
<!--
body,td,th {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
}
-->
</style>
</head>

<body>
<h2><strong>Appel entrant : <?php echo $_GET['callerid']; ?> / Heure: <?php echo $_GET['calltime']; ?> / Appelant : <?php echo $callername?></strong></h2>
<table width="100%" border="1" cellpadding="1" cellspacing="1">
  <tr>
    <td width="57"><strong>Contact</strong></td>
    <td width="142"><strong>Numéro</strong></td>
    <td width="157"><strong>Nom</strong></td>
    <td width="171"><strong>Compagnie</strong></td>
    <td width="180"><strong>Courriel</strong></td>
  </tr>
  <?php 

   do { 
   // display rows only if numbers match
    
   if (stripit($row_rsAllphones['PhoneNumber']) == $callerid){?>

<tr>
  <td>
  <?php echo $egw_ref.$row_rsAllphones['contact_id'].'">Contact</a>'?>
  </td>
  <td><?php echo $row_rsAllphones['PhoneType']; ?></td>
  <td><?php echo $row_rsAllphones['n_fn']; ?></td>
  <td><?php echo $row_rsAllphones['org_name']; ?></td>
  <td>
  <a href="mailto:<?php echo $row_rsAllphones['contact_email']; ?>">
  <?php echo $row_rsAllphones['contact_email']; ?></a>
</td>
</tr>
       <?php //endif
//end do
while ($row_rsAllphones mysql_fetch_assoc($rsAllphones)); 
   
?>

</table>
<p>account_id= <?php echo $row_rsAccounts['account_id']; ?> | Contact = <?php echo $row_rsAccounts['account_lid']; ?> |Userid = <?php echo $_GET['userid']; ?> | Extension = <?php echo $_GET['pbxext']; ?> </p>
</body>
</html>

<?php
mysql_free_result
($rsAllphones);
mysql_free_result($rsAccounts);
?>

Being a script kiddy, I don't pretend this code is well written...
But the full script (not this one) allows me to add an infolog on the fly and uses the click-to-call to return missed calls.
« Last Edit: April 13, 2008, 07:42:19 AM by soprom »
Sophie from Montréal

Offline SARK devs

  • *****
  • 2,806
  • +1/-0
    • http://sarkpbx.com
Re: Caller Info and EGroupware
« Reply #1 on: April 12, 2008, 11:05:29 PM »
Hi Sophie,

Do you mind if we publish this in the SARK/SAIL manual?

Thanks

Jeff

Offline soprom

  • *
  • 589
  • +0/-0
    • www.logiciel-libre.org
Re: Caller Info and EGroupware
« Reply #2 on: April 12, 2008, 11:25:21 PM »
Be my guest !!
Sophie from Montréal

Offline soprom

  • *
  • 589
  • +0/-0
    • www.logiciel-libre.org
Re: Caller Info and EGroupware
« Reply #3 on: April 13, 2008, 10:27:41 PM »
Notes on YAACID options:

Call notification methods
- deselect all

Advanced Event Setup:
- Event type = Dial
- Channel type = Destination

Manager user = remote_mgr
Secret = 0chanc3yo
Port = 5038
Hostname = <pbx ip>
channel = SIP/5XXX

URL:
http://server/pbx/callerinfo.php?userid=<egw_account>&pbxext=5XXX&pbxpwd=5XXX&callerid=$CALLERID&id=$UNIQUEID&calltime=$TIME&callername=$CALLERIDNAME
-userid : valid user account in egroupware
-pbxext : not used, so fill with dummy value
-pbxpwd : not used, so fill with dummy value
-id : not used (trixbox didn't used it neither)

-callername:
unfortunatly, I did not find how to get this with Selintra. It is usefull to help in creating a new contact in Egroupware. If it were available, a simple action would add a new contact in EGW based on the phone and the callername

When config is done, click set changes, then save config as default, then Press to logon. Sometime, YAACID crashes when doing this. Restart it...

You can save registry key and make different versions of it for other machines ou other accounts. The key is [HKEY_LOCAL_MACHINE\SOFTWARE\Shatter It\YAACID]

You must also add a shortcut to YAACID in autostart menu.
Sophie from Montréal