提交 49ccd87c authored 作者: Mathieu Parent's avatar Mathieu Parent

New tool XML Directory for Cisco IP Phones

上级 4dd63bab
差异被折叠。
== CREDITS ==
Copyright 2007-2010 Mairie de Paris, Service technique de l'eau et de l'assainissement
Copyright 2010 Mathieu Parent <math.parent@gmail.com>
XML Directory for Cisco IP Phones is free software: you can
redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
XML Directory for Cisco IP Phones is distributed in the hope that it
will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with XML Directory for Cisco IP Phones. If not, see
<http://www.gnu.org/licenses/>.
== AUTHOR AND CONTRIBUTORS ==
Author: Mathieu Parent
== INSTALLATION ==
* Web server (Apache2 tested)
* php5 with ldap
* put it in, so that URL is http://<your host>/xml-directory
* edit config.inc.php
* Change Cisco Call Manager Directory IP to http://<your host>/CCMCIP/
* Check
* Enjoy !
== INSPIRATIONS ==
* http://www.voip-info.org/wiki/view/Asterisk+Cisco+79XX+XML+Services
* http://www-rocq.inria.fr/who/Philippe.Sultan/iptelJavaCisco.html
* http://www.cisco.com/univercd/cc/td/doc/product/voice/vpdd/cdd/3_3/3_3_2/ipphs332.htm
<?php
/*
Copyright 2007-2010 Mairie de Paris, Service technique de l'eau et de l'assainissement
Copyright 2010 Mathieu Parent <math.parent@gmail.com>
This file is part of XML Directory for Cisco IP Phones.
XML Directory for Cisco IP Phones is free software: you can
redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
XML Directory for Cisco IP Phones is distributed in the hope that it
will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with XML Directory for Cisco IP Phones. If not, see
<http://www.gnu.org/licenses/>.
*/
/**
* @author Mathieu Parent
*/
$base_url = 'http://'.$_SERVER['SERVER_NAME'].'/xml-directory';
$links = Array(
"$base_url/directory.php?action=search"=>'Default directory',
"$base_url/directory.php?action=search&amp;directory=ldap2"=>'LDAP 2'
);
$directories = Array(
'default' => Array( // OpenLDAP example
'ldap_uri' => 'ldaps://ldap.example.org/',
'ldap_dn' => 'uid=proxyuser,ou=people,dc=example,dc=org',
'ldap_password' => 'proxypass',
'base_dn' => 'dc=example,dc=org',
'base_filter' =>
'(&(objectClass=person)'. // personne
'(!(cn=*$))'. // no winstations
'(!(objectClass=gosaUserTemplate))'. // no GOsa templates
'(!(uid=nobody))(!(uid=root))(!(uid=admin))(!(uid=joindom)))', // no nobody,root,admin,joindom
'sizelimit' => 20,
'search_fields' => Array(
//ldap attribute => Array(display [, filter])
//max 5
'sn' => Array('last name'),
'givenName' => Array('first name'),
'telephoneNumber' => Array('phone', '(telephoneNumber=*%s*)'),
//'o' => Array('organization'),
//'mobile' => Array('mobile'),
//'facsimileTelephoneNumber' => Array('fax'),
//'l' => Array('location'),
//'st' => Array('department'),
//'roomNumber' => Array('room number'),
),
'detail_fields' => Array(
//ldap attribute => display
'sn' => 'last name',
'givenName' => 'first name',
'telephoneNumber' => 'phone',
'mobile' =>'mobile',
'facsimileTelephoneNumber'=>'fax',
'o' =>'organization',
'st' =>'department',
'l' =>'location',
'postalAddress' =>'postal address',
'roomNumber' =>'room number',
'mail' => 'mail',
),
'phone_maps' => Array(
'/015368(\d{4})/' => '\1',
'/014475(\d{4})/' => '\1',
'/^(.*)$/' => '0\1',
),
'phone_fields' => Array(
'facsimileTelephoneNumber',
'mobile',
'pager',
'telephoneNumber',
),
'default_vm_password' => '12345',
),
'ldap2' => Array( // Another anonymous one
'ldap_uri' => 'ldap://10.11.12.13/',
//'ldap_dn' => '',
//'ldap_password' => '',
'base_dn' => 'o=example, o=directoryRoot',
'base_filter' =>
'(objectClass=person)',
'sizelimit' => 20,
'search_fields' => Array(
//ldap attribute => Array(display [, filter])
//max 5
'sn' => Array('last name'),
'givenName' => Array('first name'),
'misc15' => Array('direction', '(misc15=%s)'),
'internationalisdnnumber' => Array('phone', '(internationalisdnnumber=*%s)'),
),
'detail_fields' => Array(
//ldap attribute => display
'sn' => 'last name',
'givenName' => 'first name',
'internationalisdnnumber' => 'phone',
'misc15' => 'direction',
'misc16' => 'service',
'misc17' => 'affectation',
'misc37' => 'detail',
'postalAddress' => 'postal address',
),
'phone_maps' => Array(
'/^(.*)$/' => '0\1',
),
'phone_fields' => Array(
'internationalisdnnumber',
),
)
);
$translations = Array(
'fr' => Array(
'department'=>'dpartement',
'directory' => 'annuaire',
'fax' => 'tlcopie',
'first name' => 'prnom',
'last name' => 'nom',
'location'=> 'lieu',
'mail' => 'couriel',
'organization' => 'organisation',
'phone' => 'tlphone',
'postal address'=>'adresse',
'room number'=>'numro de bureau',
//
'Back' => 'Retour',
'Details' => 'Dtails',
'Dial' => 'Composer',
'Fill the fields' => 'Remplissez les champs',
'Results' => 'Rsultats',
'%d first' => '%d premiers',
)
);
function l10n($text) {
global $translations;
$locale = 'fr';
if (array_key_exists($text,$translations[$locale])) {
return $translations[$locale][$text];
} else {
return $text;
}
}
?>
<?php
/*
Copyright 2007-2010 Mairie de Paris, Service technique de l'eau et de l'assainissement
Copyright 2010 Mathieu Parent <math.parent@gmail.com>
This file is part of XML Directory for Cisco IP Phones.
XML Directory for Cisco IP Phones is free software: you can
redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
XML Directory for Cisco IP Phones is distributed in the hope that it
will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with XML Directory for Cisco IP Phones. If not, see
<http://www.gnu.org/licenses/>.
*/
/**
* @author Mathieu Parent
*/
require_once('config.inc.php');
require_once('ldap.class.php');
require_once('phone.class.php');
header("Content-type: text/xml");
header("Connection: close");
header("Expires: -1");
if(empty($_GET['directory']) || !isset($directories[$_GET['directory']])) {
$_GET['directory'] = 'default';
}
extract($directories[$_GET['directory']]);
switch(empty($_GET['action']) ? 'search' : $_GET['action']) {
## ############################################################################
##
case 'search' :
?>
<CiscoIPPhoneInput>
<Title><?php echo ucfirst(l10n('directory'));?></Title>
<Prompt><?php echo l10n('Fill the fields');?></Prompt>
<URL><?php echo "$base_url/directory.php?directory=".$_GET['directory']."&amp;action=result&amp;";?></URL>
<?php
foreach($search_fields AS $attribute_name=>$infos) {
?>
<InputItem>
<DisplayName><?php echo ucfirst(l10n($infos[0]));?></DisplayName>
<QueryStringParam><?php echo $attribute_name;?></QueryStringParam>
<InputFlags><?php echo in_array($attribute_name,$phone_fields) ? 'T' : 'A';?></InputFlags>
<DefaultValue><?php echo isset($_GET[$attribute_name]) ? $_GET[$attribute_name] : '' ?></DefaultValue>
</InputItem>
<?php
}
?>
</CiscoIPPhoneInput>
<?php
break;
## ############################################################################
##
case 'result' :
$ldap = new LDAPConnection();
$ldap->connect();
$filter=$base_filter;
foreach($search_fields as $attribute_name => $infos) {
if(!empty($_GET[$attribute_name])) {
if(empty($infos[1])) {
$filter="(&$filter($attribute_name=".$_GET[$attribute_name]."*))";
} else {
$filter="(&$filter".sprintf($infos[1], $_GET[$attribute_name]).")";
}
}
}
$sr= $ldap->search($base_dn,$filter,array('cn','uid'),0, $sizelimit);
$prompt = l10n('Results');
if($ldap->errno() == 4) { // LDAP_SIZELIMIT_EXCEEDED
$prompt.= " (".sprintf(l10n('%d first'), $sizelimit).")";
}
?>
<CiscoIPPhoneMenu>
<Title><?php echo ucfirst(l10n('directory'));?></Title>
<Prompt><?php echo $prompt;?></Prompt>
<?php
for ($entryID=$ldap->first_entry($sr);
$entryID!=false;
$entryID=$ldap->next_entry($entryID)) {
$dn= $ldap->get_dn($entryID);
$dn= preg_replace("/".strtr(preg_quote(', '.$base_dn), Array(' ' => '\s*'))."$/i","",$dn);
$cn = $ldap->get_values($entryID,'cn');
$uid = $ldap->get_values($entryID,'uid');
$uid= $uid[0];
#compte system, rt ou auditeur
if(preg_match('/^_.*$/', $uid) or ($uid == 'root') or ($uid == 'nobody')
or preg_match('/-rt$/', $uid)
or preg_match('/^[A-Z1-9]{1,3}_[A-Z]{1,8}$/', $uid)) {
continue;
}
?>
<MenuItem>
<Name><?php echo cisco_encode($cn[0]);?></Name>
<URL>QueryStringParam:<?php
$url="&amp;dn=".urlencode($dn);
foreach($search_fields as $k=>$v) {
if(!empty($_GET[$k])) {
$url.="&amp;$k=".urlencode($_GET[$k])."";
}
}
echo $url;?></URL>
</MenuItem>
<?php
}
?>
<SoftKeyItem>
<Name><?php echo l10n('Dial');?></Name>
<URL><?php echo "$base_url/directory.php?directory=".$_GET['directory']."&amp;action=call"; ?></URL>
<Position>1</Position>
</SoftKeyItem>
<SoftKeyItem>
<Name><?php echo l10n('Details');?></Name>
<URL><?php echo "$base_url/directory.php?directory=".$_GET['directory']."&amp;action=detail"; ?></URL>
<Position>2</Position>
</SoftKeyItem>
<SoftKeyItem>
<Name><?php echo l10n('Back');?></Name>
<URL><?php
$url="$base_url/directory.php?action=search";
$url.='&amp;directory='.$_GET['directory'];
foreach($search_fields as $k=>$v) {
if(!empty($_GET[$k])) {
$url.="&amp;$k=".urlencode($_GET[$k])."";
}
}
echo $url;?></URL>
<Position>3</Position>
</SoftKeyItem>
<SoftKeyItem>
<Name><?php echo l10n('Exit');?></Name>
<URL>SoftKey:Exit</URL>
<Position>4</Position>
</SoftKeyItem>
</CiscoIPPhoneMenu>
<?php
break;
## ############################################################################
##
case 'detail' :
case 'call':
$ldap = new LDAPConnection();
$ldap->connect();
$filter = "(objectClass=*)";
$dn = $_GET['dn'].", $base_dn";
$sr= $ldap->search($dn,$filter,array_keys($detail_fields));
?>
<CiscoIPPhoneMenu>
<Title><?php echo ucfirst(l10n('directory'));?></Title>
<Prompt><?php echo ucfirst(l10n('details'));?></Prompt>
<?php
$entry= $ldap->first_entry($sr);
$attrs = $ldap->get_attributes($entry);
for ($i=0; $i < $attrs["count"]; $i++) {
if($_GET['action']=='detail' || ($_GET['action']=='call' && in_array($attrs[$i],$phone_fields))) {
$value = $ldap->get_values($entry, $attrs[$i]);
?>
<MenuItem>
<?php
if(in_array($attrs[$i],$phone_fields)) {
echo ' <Name>'.ucfirst(l10n($detail_fields[$attrs[$i]]))." : ".
phone($value[0]).'</Name>'."\n";
echo ' <URL>Dial:'.phone($value[0]).'</URL>'."\n";
} else {
echo ' <Name>'.ucfirst(l10n($detail_fields[$attrs[$i]]))." : ".
cisco_encode($value[0]).'</Name>'."\n";
echo ' <URL></URL>'."\n";
}
?>
</MenuItem>
<?php
}
}
?>
<SoftKeyItem>
<Name><?php echo l10n('Dial');?></Name>
<URL>SoftKey:Select</URL>
<Position>1</Position>
</SoftKeyItem>
<SoftKeyItem>
<Name><?php echo l10n('Back');?></Name>
<URL><?php
$url="$base_url/directory.php?action=result";
$url.='&amp;directory='.$_GET['directory'];
foreach($search_fields as $k=>$v) {
if(!empty($_GET[$k])) {
$url.="&amp;$k=".urlencode($_GET[$k])."";
}
}
echo $url;?></URL>
<Position>3</Position>
</SoftKeyItem>
<SoftKeyItem>
<Name><?php echo l10n('Exit');?></Name>
<URL>SoftKey:Exit</URL>
<Position>4</Position>
</SoftKeyItem>
</CiscoIPPhoneMenu>
<?php
break;
## ############################################################################
##
default:
}
?>
<?php
/*
Copyright 2007-2010 Mairie de Paris, Service technique de l'eau et de l'assainissement
Copyright 2010 Mathieu Parent <math.parent@gmail.com>
This file is part of XML Directory for Cisco IP Phones.
XML Directory for Cisco IP Phones is free software: you can
redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
XML Directory for Cisco IP Phones is distributed in the hope that it
will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with XML Directory for Cisco IP Phones. If not, see
<http://www.gnu.org/licenses/>.
*/
/**
* @author Mathieu Parent
*/
require_once('config.inc.php');
header("Content-type: text/xml");
header("Connection: close");
header("Expires: -1");
header("Set-Cookie: ASPSESSIONIDCARBSTTC=ECJOLNNABLFHPLAFGEJMPNFP; path=/");
?>
<CiscoIPPhoneMenu>
<Prompt>Selectionner un repertoire</Prompt>
<?php
foreach($links as $k => $v) {
?>
<MenuItem>
<Name><?php echo ucfirst(l10n($v));?></Name>
<URL><?php echo $k;?></URL>
</MenuItem>
<?php
}
?>
</CiscoIPPhoneMenu>
<?php
/*
Copyright 2007-2010 Mairie de Paris, Service technique de l'eau et de l'assainissement
Copyright 2010 Mathieu Parent <math.parent@gmail.com>
This file is part of XML Directory for Cisco IP Phones.
XML Directory for Cisco IP Phones is free software: you can
redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
XML Directory for Cisco IP Phones is distributed in the hope that it
will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with XML Directory for Cisco IP Phones. If not, see
<http://www.gnu.org/licenses/>.
*/
/**
* @author Mathieu Parent
*/
class LDAPConnection {
private $ds;
function __contruct() {
}
function connect() {
global $ldap_uri, $ldap_dn, $ldap_password;
$this->ds = ldap_connect($ldap_uri);
ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($this->ds, LDAP_OPT_REFERRALS,0);
ldap_bind($this->ds, $ldap_dn, $ldap_password);
}
function search($base_dn,$filter,$attributes, $attrsonly = 0, $sizelimit = NULL, $timelimit = NULL, $deref = NULL) {
if($deref === NULL) {$deref = LDAP_DEREF_NEVER;}
return @ldap_search($this->ds,$base_dn,$filter,$attributes, $attrsonly, $sizelimit, $timelimit);
}
function first_entry($sr) {
return ldap_first_entry($this->ds, $sr);
}
function next_entry($entry) {
return ldap_next_entry($this->ds, $entry);
}
function get_dn($entry) {
return ldap_get_dn($this->ds, $entry);
}
function get_values($entry, $attribute) {
return @ldap_get_values($this->ds, $entry, $attribute);
}
function get_values_len($entry, $attribute) {
return @ldap_get_values_len($this->ds, $entry, $attribute);
}
function get_attributes($entry) {
return ldap_get_attributes($this->ds, $entry);
}
function errno() {
return ldap_errno($this->ds);
}
}
?>
<?php
/*
Copyright 2007-2010 Mairie de Paris, Service technique de l'eau et de l'assainissement
Copyright 2010 Mathieu Parent <math.parent@gmail.com>
This file is part of XML Directory for Cisco IP Phones.
XML Directory for Cisco IP Phones is free software: you can
redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
XML Directory for Cisco IP Phones is distributed in the hope that it
will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with XML Directory for Cisco IP Phones. If not, see
<http://www.gnu.org/licenses/>.
*/
/**
* @author Mathieu Parent
*/
function phone($num) {
global $phone_maps;
foreach($phone_maps as $pattern => $replacement) {
$num2 = preg_replace($pattern, $replacement, $num, -1, $count);
if($count > 0) {
return $num2;
}
}
return "?$num";
}
function cisco_encode($str) {
return utf8_decode($str);
}
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论