Overview

Packages

  • Horde
    • Data
  • None
  • Turba

Classes

  • Turba
  • Turba_Api
  • Turba_Driver
  • Turba_Driver_Facebook
  • Turba_Driver_Favourites
  • Turba_Driver_Group
  • Turba_Driver_Imsp
  • Turba_Driver_Kolab
  • Turba_Driver_Ldap
  • Turba_Driver_Prefs
  • Turba_Driver_Share
  • Turba_Driver_Sql
  • Turba_Driver_Vbook
  • Turba_Exception
  • Turba_Factory_Driver
  • Turba_Form_AddContact
  • Turba_Form_Contact
  • Turba_Form_ContactBase
  • Turba_Form_CreateAddressBook
  • Turba_Form_DeleteAddressBook
  • Turba_Form_EditAddressBook
  • Turba_Form_EditContact
  • Turba_Form_EditContactGroup
  • Turba_List
  • Turba_LoginTasks_SystemTask_Upgrade
  • Turba_Object
  • Turba_Object_Group
  • Turba_Test
  • Turba_View_Browse
  • Turba_View_Contact
  • Turba_View_DeleteContact
  • Turba_View_Duplicates
  • Turba_View_EditContact
  • Turba_View_List
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * This class provides the Turba configuration for the test script.
  4:  *
  5:  * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * See the enclosed file LICENSE for license information (ASL).  If you
  8:  * did not receive this file, see http://www.horde.org/licenses/apache.
  9:  *
 10:  * @author  Michael Slusarz <slusarz@horde.org>
 11:  * @package Turba
 12:  */
 13: class Turba_Test extends Horde_Test
 14: {
 15:     /**
 16:      * The module list
 17:      *
 18:      * @var array
 19:      */
 20:     protected $_moduleList = array();
 21: 
 22:     /**
 23:      * PHP settings list.
 24:      *
 25:      * @var array
 26:      */
 27:     protected $_settingsList = array();
 28: 
 29:     /**
 30:      * PEAR modules list.
 31:      *
 32:      * @var array
 33:      */
 34:     protected $_pearList = array(
 35:         'Net_LDAP' => array(
 36:             'error' => 'Net_LDAP is required when doing schema checks with LDAP address books.',
 37:         )
 38:     );
 39: 
 40:     /**
 41:      * Required configuration files.
 42:      *
 43:      * @var array
 44:      */
 45:     protected $_fileList = array(
 46:         'config/conf.php' => null,
 47:     );
 48: 
 49:     /**
 50:      * Inter-Horde application dependencies.
 51:      *
 52:      * @var array
 53:      */
 54:     protected $_appList = array();
 55: 
 56:     /**
 57:      * Any application specific tests that need to be done.
 58:      *
 59:      * @return string  HTML output.
 60:      */
 61:     public function appTests()
 62:     {
 63:         $ret = '<h1>LDAP Support Test</h1>';
 64: 
 65:         $params = array(
 66:             'server' => Horde_Util::getPost('server'),
 67:             'port' => Horde_Util::getPost('port', 389),
 68:             'basedn' => Horde_Util::getPost('basedn'),
 69:             'user' => Horde_Util::getPost('user'),
 70:             'passwd' => Horde_Util::getPost('passwd'),
 71:             'filter' => Horde_Util::getPost('filter'),
 72:             'proto' => Horde_Util::getPost('proto')
 73:         );
 74: 
 75:         if (!empty($params['server']) &&
 76:             !empty($params['basedn']) &&
 77:             !empty($params['filter'])) {
 78:             $ret .= $this->_doConnectionTest($params);
 79:         }
 80: 
 81:         $self_url = Horde::selfUrl()->add('app', 'turba');
 82: 
 83:         Horde::startBuffer();
 84:         require TURBA_TEMPLATES . '/test/ldapserver.inc';
 85: 
 86:         return $ret . Horde::endBuffer();
 87:     }
 88: 
 89:     /**
 90:      * Perform LDAP server support test.
 91:      *
 92:      * @param array $params  Connection parameters.
 93:      *
 94:      * @return string  HTML output.
 95:      */
 96:     protected function _doConnectionTest($params)
 97:     {
 98:         $ret .= 'server="' . htmlspecialchars($params['server']) . '" ' .
 99:             'basedn="' . htmlspecialchars($params['basedn']) . '" ' .
100:             'filter="' . htmlspecialchars($params['filter']) . '"<br />';
101: 
102:         if (!empty($params['user'])) {
103:             $ret .= 'bind as user="' . htmlspecialchars($params['user']) . '"<br />';
104:         } else {
105:             $ret .= 'bind anonymously<br />';
106:         }
107: 
108:         $ldap = ldap_connect($params['server'], $params['port']);
109:         if ($ldap) {
110:             if (!empty($params['proto']) && ($params['proto'] == '3')) {
111:                 ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
112:             }
113: 
114:             if (!empty($params['user']) && !ldap_bind($ldap, $params['user'], $params['passwd'])) {
115:                 $ret .= '<p>unable to bind as ' . htmlspecialchars($params['user']) . ' to LDAP server</p>';
116:                 ldap_close($ldap);
117:                 $ldap = '';
118:             } elseif (empty($params['user']) && !ldap_bind($ldap)) {
119:                 $ret .= "<p>unable to bind anonymously to LDAP server</p>\n";
120:                 ldap_close($ldap);
121:                 $ldap = '';
122:             }
123: 
124:             if ($ldap) {
125:                 $result = ldap_search($ldap, $params['basedn'], $params['filter']);
126:                 if ($result) {
127:                     $ret .= '<p>search returned ' . ldap_count_entries($ldap, $result) . " entries</p>\n";
128:                     $info = ldap_get_entries($ldap, $result);
129:                     for ($i = 0; $i < $info['count']; ++$i) {
130:                         $ret .= '<p>dn is: ' . $info[$i]['dn'] . '<br />' .
131:                             'first cn entry is: ' . $info[$i]['cn'][0] . '<br />' .
132:                             'first mail entry is: ' . $info[$i]['mail'][0] . '</p>';
133: 
134:                         if ($i >= 10) {
135:                             $ret .= '<p>(only first 10 entries displayed)</p>';
136:                             break;
137:                         }
138:                     }
139:                 } else {
140:                     $ret .= '<p>unable to search LDAP server</p>';
141:                 }
142:             }
143:         } else {
144:             $ret .= '<p>unable to connect to LDAP server</p>';
145:         }
146: 
147:         return $ret;
148:     }
149: 
150: }
151: 
API documentation generated by ApiGen