1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: class Turba_Test extends Horde_Test
14: {
15: 16: 17: 18: 19:
20: protected $_moduleList = array();
21:
22: 23: 24: 25: 26:
27: protected $_settingsList = array();
28:
29: 30: 31: 32: 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: 42: 43: 44:
45: protected $_fileList = array(
46: 'config/conf.php' => null,
47: );
48:
49: 50: 51: 52: 53:
54: protected $_appList = array();
55:
56: 57: 58: 59: 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: 91: 92: 93: 94: 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: