-
Notifications
You must be signed in to change notification settings - Fork 1
/
config_ldaptest.php
497 lines (427 loc) · 18 KB
/
config_ldaptest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
<?php
// make some simple tests on ldap connection
// $Id: config_ldaptest.php,v 2.45 2007-02-26 10:04:18 turbo Exp $
//
require("./include/pql_session.inc");
require($_SESSION["path"]."/include/pql_config.inc");
require($_SESSION["path"]."/include/pql_control.inc");
// {{{ Check a domain value
function check_domain_value($dn, $attrib, $value) {
global $_pql; $LANG;
if(pql_get_define("PQL_CONF_DEBUG_ME")) {
// Debugging enabled - temporarily disable it!
pql_set_define("PQL_CONF_DEBUG_ME", 'FALSE');
$debugging = 1;
}
$entry[$attrib] = $value;
if(!$_pql->modify($dn, $entry, "config_ldaptest.php:check_domain_value()/1")) {
if(ldap_errno($linkid) == 21)
// Invalid syntax
$msg = $LANG->_('No. Reason:\n')."<b>".$LANG->_('Old phpQLAdmin schema')."</b>";
else {
$LDIF = pql_create_ldif('config_ldaptest.php:pql_write_mod', $dn, $entry, 1);
$msg = "<a href=\"javascript:ldifWindow('".$LDIF."')\">".
$LANG->_('No. Reason:\n')."<b>'".ldap_error($linkid)."'</b></a>";
}
} else {
// Success - delete it again
unset($entry);
$entry['test'] = array();
$_pql->modify($dn, $entry, "config_ldaptest.php:check_domain_value()/2");
$msg = 0;
}
if($debugging)
// Debugging have been temporarily disabled - enable it again!
pql_set_define("PQL_CONF_DEBUG_ME", 'TRUE');
return($msg);
}
// }}}
// {{{ Check some extension modules
if(class_exists('Memcache') and function_exists("memcache_connect")) {
$memcache_ext = $LANG->_('Built in (loaded)');
} else {
$memcache_ext = $LANG->_('Not available');
}
if(function_exists("idn_to_utf8")) {
$idn_ext = $LANG->_('Built in (loaded)');
} else {
$idn_ext = $LANG->_('Not available');
}
if(function_exists("mhash")) {
$mhash_ext = $LANG->_('Built in (loaded)');
} else {
$mhash_ext = $LANG->_('Not available');
}
if(extension_loaded('kadm5') and function_exists("kadm5_init_with_password")) {
$krb5_ext = $LANG->_('Built in (loaded)');
} else {
$krb5_ext = $LANG->_('Not available');
}
if((function_exists('ImageCreateFromPng') && (imagetypes() & IMG_PNG)) or
(function_exists('ImageCreateFromGif') && (imagetypes() & IMG_GIF)) or
(function_exists('ImageCreateFromJpeg') && (imagetypes() & IMG_JPG)))
{
$gd_ext = $LANG->_('Built in (loaded)');
} else {
$gd_ext = $LANG->_('Not available');
}
// }}}
if(!function_exists("ldap_connect")){
// {{{ Not availible
$ldap_ext = '<font color="red">'.$LANG->_('Not available')."</font>";
$connection = "-";
$connection_control = "-";
// }}}
} else {
$ldap_ext = $LANG->_('Built in (loaded)');
// {{{ User directory connection
$_pql = new pql($_SESSION["USER_HOST"], '', '', true);
if(!$_pql->connect($_SESSION["USER_HOST"])) {
$connection = $LANG->_('Failed');
$server = explode(';', $_SESSION["USER_HOST"]);
$server = urldecode($server[0]); // If it's an LDAP URI, replace "%2f" with "/" -> URLdecode
// do additional tests
if(!preg_match('/^ldap/i', $_SESSION["USER_HOST"])) {
if(!gethostbyname($_SESSION["USER_HOST"]))
// not resolved
$connection .= ", " . pql_complete_constant($LANG->_('The hostname %host% could not be resolved'),
array("host" => $_SESSION["USER_HOST"] ));
else {
// try to open a connection
if(!fsockopen($_SESSION["USER_HOST"], 389))
// impossible to connect
$connection .= ", " . pql_complete_constant($LANG->_('Could not connect to port 389 at %host%, please make sure the service is up and that it\'s not blocked by a firewall'),
array("host" => $_SESSION["USER_HOST"] ));
}
}
} else {
if(!$_pql->bind())
$connection = $LANG->_('Connection ok, but could not bind to the directory anonymously');
else
$connection = $LANG->_('Yes');
}
// }}}
// {{{ Control directory connection
if(pql_get_define("PQL_CONF_CONTROL_USE")) {
$_pql_control = new pql_control($_SESSION["USER_HOST"], '', '', true);
if(!$_pql_control->connect($_SESSION["USER_HOST"])) {
$connection_control = $LANG->_('Failed');
$host = explode('\+', pql_get_define("PQL_CONF_HOST"));
$host = explode(';', $host[0]);
$fqdn = $host[0];
$port = $host[1];
// do additional tests
if(!preg_match('/^ldap/i', $_SESSION["USER_HOST"])) {
if(!gethostbyname($fqdn)) {
// not resolved
$connection_control .= ", " . pql_complete_constant($LANG->_('The hostname %host% could not be resolved'),
array("host" => $fqdn ));
} else {
// try to open a connection
if(!fsockopen($fqdn, $port)) {
// impossible to connect
$connection_control .= ", " . pql_complete_constant($LANG->_('Could not connect to port 389 at %host%, please make sure the service is up and it is not blocked by a firewall'),
array("host" => $_SESSION["USER_HOST"]));
}
}
}
} else {
if(!$_pql_control->bind())
$connection_control = $LANG->_('Connection ok, but could not bind to the directory anonymously');
else
$connection_control = $LANG->_('Yes');
}
} else
$connection_control = $LANG->_('Control extension deactivated');
// }}}
// {{{ Access rights
if($_SESSION["USER_DN"] and $_SESSION["USER_PASS"]) {
$_pql = new pql($_SESSION["USER_HOST"], $_SESSION["USER_DN"], $_SESSION["USER_PASS"]);
foreach($_SESSION["BASE_DN"] as $basedn) {
// {{{ Try to set the attribute 'test' in the top DN
$fail = check_domain_value($basedn, 'test', 'TRUE');
if($fail)
$TEST["basedn"][$basedn] = $fail;
else
$TEST["basedn"][$basedn] = $LANG->_('Yes');
// }}}
// {{{ Test to see if we have access to create domain/branches by creating a subbranch
unset($entry);
$entry[pql_get_define("PQL_ATTR_OBJECTCLASS")][] = "top";
if(pql_get_define("PQL_CONF_REFERENCE_DOMAINS_WITH", $basedn) == "dc") {
$entry[pql_get_define("PQL_ATTR_OBJECTCLASS")][] = "domain";
$entry[pql_get_define("PQL_ATTR_DC")] = "test";
} elseif(pql_get_define("PQL_CONF_REFERENCE_DOMAINS_WITH", $basedn) == "ou") {
$entry[pql_get_define("PQL_ATTR_OBJECTCLASS")][] = "organizationalUnit";
$entry[pql_get_define("PQL_ATTR_OU")] = "test";
} elseif(pql_get_define("PQL_CONF_REFERENCE_DOMAINS_WITH", $basedn) == "o") {
$entry[pql_get_define("PQL_ATTR_OBJECTCLASS")][] = "organization";
$entry[pql_get_define("PQL_ATTR_O")] = "test";
}
$entry[pql_get_define("PQL_CONF_REFERENCE_DOMAINS_WITH", $basedn)] = "phpQLAdmin_Branch_Test";
// Setup the DN
$dn = pql_get_define("PQL_CONF_REFERENCE_DOMAINS_WITH", $basedn)."=phpQLAdmin_Branch_Test,".$basedn;
if(!@ldap_add($_pql->ldap_linkid, $dn, $entry)) {
$LDIF = pql_create_ldif("config_ldaptest.php:ldap_add", $dn, $entry, 1);
$TEST["branches"][$basedn] = "<a href=\"javascript:ldifWindow('".$LDIF."')\">".
$LANG->_('No. Reason:\n')."<b>'".ldap_error($_pql->ldap_linkid)."'</b>";
$TEST_simple["branches"][$basedn] = 0;
} else {
// Success - delete it again
ldap_delete($_pql->ldap_linkid, $dn);
$TEST["branches"][$basedn] = $LANG->_('Yes');
$TEST_simple["branches"][$basedn] = 1;
}
// }}}
// {{{ Check write access (w/o ACI's)
$filter = "(&";
if(pql_get_define("PQL_CONF_REFERENCE_DOMAINS_WITH", $basedn) == "dc")
$filter .= "(objectClass=domain)(objectClass=dcOrganizationNameForm)";
elseif(pql_get_define("PQL_CONF_REFERENCE_DOMAINS_WITH", $basedn) == "ou")
$filter .= "(objectClass=organizationalUnit)";
elseif(pql_get_define("PQL_CONF_REFERENCE_DOMAINS_WITH", $basedn) == "o")
$filter .= "(objectClass=organization)";
$filter .= "(" . pql_get_define("PQL_CONF_REFERENCE_DOMAINS_WITH", $basedn) . "=*))";
$sr = @ldap_list($_pql->ldap_linkid, $basedn, $filter)
or pql_format_error(1);
$info = @ldap_get_entries($_pql->ldap_linkid, $sr)
or pql_format_error(1);
if(! $info["count"]) {
// Didn't find anything on a one-level search, try a global one...
$sr = @ldap_search($_pql->ldap_linkid, $basedn, $filter)
or pql_format_error(1);
$info = @ldap_get_entries($_pql->ldap_linkid, $sr)
or pql_format_error(1);
}
for ($i=0; $i<$info["count"]; $i++) {
$domains[] = $info[$i]["dn"];
}
// }}}
}
if(is_array($domains)) {
foreach($domains as $domain) {
// Check write access
$fail = check_domain_value($domain, 'test', 'TRUE');
if($fail) {
$TEST["branches"][$domain] = $fail;
} else {
$TEST["branches"][$domain] = $LANG->_('Yes');
}
}
}
// {{{ Check write access (w/ ACI's)
if(!empty($_SESSION["ACI_SUPPORT_ENABLED"])) {
foreach($_SESSION["BASE_DN"] as $basedn) {
// Setup the LDIF we're adding
unset($entry);
$entry[pql_get_define("PQL_ATTR_OBJECTCLASS")][] = "top";
if(pql_get_define("PQL_CONF_REFERENCE_DOMAINS_WITH", $basedn) == "dc") {
$entry[pql_get_define("PQL_ATTR_OBJECTCLASS")][] = "domain";
$entry[pql_get_define("PQL_ATTR_DC")] = "test";
} elseif(pql_get_define("PQL_CONF_REFERENCE_DOMAINS_WITH", $basedn) == "ou") {
$entry[pql_get_define("PQL_ATTR_OBJECTCLASS")][] = "organizationalUnit";
$entry[pql_get_define("PQL_ATTR_OU")] = "test";
} elseif(pql_get_define("PQL_CONF_REFERENCE_DOMAINS_WITH", $basedn) == "o") {
$entry[pql_get_define("PQL_ATTR_OBJECTCLASS")][] = "organization";
$entry[pql_get_define("PQL_ATTR_O")] = "test";
}
$entry[pql_get_define("PQL_CONF_REFERENCE_DOMAINS_WITH", $basedn)] = "phpQLAdmin_Branch_Test";
// Add the ACI entries to the object
$ol_ver = $_pql->find_ldap_version();
if(preg_match('/^2\.[34]/', $ol_ver))
// Actually this is a little wrong. There was a bug on <2.3.32 which was
// fixed 20070214 (re23), so it should be ok in 2.3.33 when/if that is
// released. Also 2.4 will use this format (fix actually backported from 2.4)...
$entry[pql_get_define("PQL_ATTR_LDAPACI")][] = "0#entry#grant;w,r,s,c;entry#access-id#".$_SESSION["USER_DN"];
else
$entry[pql_get_define("PQL_ATTR_LDAPACI")][] = "0#entry#grant;w,r,s,c;[entry]#access-id#".$_SESSION["USER_DN"];
$entry[pql_get_define("PQL_ATTR_LDAPACI")][] = "1#entry#grant;w,r,s,c;[all]#access-id#".$_SESSION["USER_DN"];
// Setup the DN
$dn = pql_get_define("PQL_CONF_REFERENCE_DOMAINS_WITH", $basedn)."=phpQLAdmin_Branch_Test,".$basedn;
if(!@ldap_add($_pql->ldap_linkid, $dn, $entry)) {
$LDIF = pql_create_ldif("config_ldaptest.php:ldap_add", $dn, $entry, 1);
$TEST["acis"][$basedn] = "<a href=\"javascript:ldifWindow('".$LDIF."')\">".
$LANG->_('No. Reason:\n')."<b>'".ldap_error($_pql->ldap_linkid)."'</b>";
$TEST_simple["acis"][$basedn] = 0;
} else {
// Success - delete it again
ldap_delete($_pql->ldap_linkid, $dn);
$TEST["acis"][$basedn] = $LANG->_('Yes');
$TEST_simple["acis"][$basedn] = 1;
}
}
} else {
foreach($_SESSION["BASE_DN"] as $basedn) {
$TEST["acis"][$basedn] = "".$LANG->_("ACI's deactivated")."";
$TEST_simple["acis"][$basedn] = 0;
}
}
// }}}
}
// }}}
} // end if(function_exists...
include($_SESSION["path"]."/header.html");
?>
<script type="text/javascript" language="javascript"><!--
function ldifWindow(string) {
myWindow = window.open("", "LDIFWindow", 'toolbar=no,menubar=no,status=no,dependent=yes,width=350,height=200');
myWindow.document.write('<html>\n <head>\n <title>phpQLAdmin LDIF</title>\n </head>\n');
myWindow.document.write(' <body>\n');
myWindow.document.write(' '+string+'\n');
myWindow.document.write(' </body>\n</html>');
myWindow.document.bgColor="white";
myWindow.document.close();
}
//--></script>
<span class="title1"><?php echo $LANG->_('phpQLAdmin ldap connection')?></span>
<br><br>
<table cellspacing="0" cellpadding="3" border="0">
<th colspan="3" align="left"><?php echo $LANG->_('PHP Extensions needed')?>
<tr>
<td class="title"><?php echo $LANG->_('LDAP')?></td>
<td class="<?php pql_format_table(); ?>"><?php echo $ldap_ext?> </td>
</tr>
<tr>
<td class="title"><?php echo $LANG->_('IDN')?></td>
<td class="<?php pql_format_table(); ?>"><?php echo $idn_ext?> </td>
</tr>
<tr>
<td class="title"><?php echo $LANG->_('MHASH')?></td>
<td class="<?php pql_format_table(); ?>"><?php echo $idn_ext?> </td>
</tr>
<tr>
<td class="title"><?php echo $LANG->_('MemCache')?></td>
<td class="<?php pql_format_table(); ?>"><?php echo $memcache_ext?> </td>
</tr>
<tr>
<td class="title"><?php echo $LANG->_('GD')?></td>
<td class="<?php pql_format_table(); ?>"><?php echo $gd_ext?> </td>
</tr>
<tr>
<td class="title"><?php echo $LANG->_('KRB5')?></td>
<td class="<?php pql_format_table(); ?>"><?php echo $krb5_ext?> </td>
</tr>
</th>
<?php echo pql_format_table_empty(2)?>
<th colspan="3" align="left"><?php echo $LANG->_('LDAP server connection and setup tests')?>
<tr>
<td class="title"><?php echo $LANG->_('User directory connection')?></td>
<td class="<?php pql_format_table(); ?>"><?php echo $connection?> </td>
</tr>
<tr>
<td class="title"><?php echo $LANG->_('Control directory connection')?></td>
<td class="<?php pql_format_table(); ?>"><?php echo $connection_control?> </td>
</tr>
<?php if($_SESSION["ADVANCED_MODE"] == 1) {
// Just so that we don't have to call pql_get_subschemas() multiple times here - takes time!
$ldap = pql_get_subschemas();
?>
<tr></tr>
<tr>
<td class="title"><?php echo $LANG->_('LDAP server contains phpQLAdminConfig objectclass')?></td>
<?php if($ldap["objectclasses"]["phpqladminconfig"]) { ?>
<td class="<?php pql_format_table(); ?>"><?php echo $LANG->_('Yes')?></td>
<?php } else { ?>
<td class="<?php pql_format_table(); ?>"><?php echo $LANG->_('No')?>. <?php echo $LANG->_('Please load file')?> <a href="phpQLAdmin.schema">phpQLAdmin.schema</a> </td>
<?php } ?>
</tr>
<tr>
<td class="title"><?php echo $LANG->_('LDAP server contains phpQLAdminBranch objectclass')?></td>
<?php if($ldap["objectclasses"]["phpqladminbranch"]) { ?>
<td class="<?php pql_format_table(); ?>"><?php echo $LANG->_('Yes')?></td>
<?php } else { ?>
<td class="<?php pql_format_table(); ?>"><?php echo $LANG->_('No')?>. <?php echo $LANG->_('Please load file')?> <a href="phpQLAdmin.schema">phpQLAdmin.schema</a> </td>
<?php } ?>
</tr>
<tr>
<td class="title">LDAP server contains schema for <a href="http://www.ietf.org/rfc/rfc2377.txt" target="_new">RFC 2377</a></td>
<?php if($ldap["objectclasses"]["dcorganizationnameform"]) { ?>
<td class="<?php pql_format_table(); ?>"><?php echo $LANG->_('Yes')?></td>
<?php } else { ?>
<td class="<?php pql_format_table(); ?>"><?php echo $LANG->_('No')?>. <?php echo $LANG->_('Please load file')?> <a href="rfc2377.schema">rfc2377.schema</a> </td>
<?php }
}
?>
</tr>
</th>
<?php if($basedn) { ?>
<?php echo pql_format_table_empty(2)?>
<th colspan="3" align="left"><?php echo $LANG->_('Modification access - phpQLAdmin configuration')?>
<?php foreach($_SESSION["BASE_DN"] as $dn) { ?>
<tr>
<td class="title"><?php echo pql_complete_constant($LANG->_('Access to write phpQLAdmin configuration in DN %dn%'), array('dn' => $dn)); ?></td>
<?php $class=pql_format_table(0); ?>
<td class="<?php echo $class?>"><?php echo $TEST["basedn"][$dn]?></td>
</tr>
<?php } ?>
</th>
<?php echo pql_format_table_empty(2)?>
<th colspan="3" align="left"><?php echo $LANG->_('Branch creation access')?>
<?php foreach($_SESSION["BASE_DN"] as $dn) { ?>
<tr>
<td class="title"><?php echo pql_complete_constant($LANG->_('Access to create branches in DN %dn%'), array('dn' => $dn)); ?></td>
<?php $class=pql_format_table(0); ?>
<td class="<?php echo $class?>"><?php echo $TEST["branches"][$dn]?></td>
</tr>
<tr>
<td class="title"><?php echo pql_complete_constant($LANG->_('Access to create branch with ACIs in DN %dn%'), array('dn' => $dn)); ?></td>
<?php $class=pql_format_table(0); ?>
<td class="<?php echo $class?>"><?php echo $TEST["acis"][$dn]?></td>
</tr>
<?php if(!$TEST_simple["branches"][$dn] and $TEST_simple["acis"][$dn] and !pql_get_define("PQL_CONF_ACI_USE")) { ?>
<tr>
<td class="title" align="right"><img src="images/info.png" width="16" height="16" border="0" align="right"></td>
<?php $class=pql_format_table(0); ?>
<td class="<?php echo $class?>"><?php echo $LANG->_("WARNING: You do not have access<br>without ACI's but ACI's is disabled.<br>Please enable ACI's in the configuration!")?></td>
</tr>
<?php } ?>
<tr></tr>
<?php } ?>
</th>
<?php echo pql_format_table_empty(2)?>
<th colspan="3" align="left"><?php echo $LANG->_('DN modification access - domain DN\'s')?>
<?php if(is_array($domains)) {
asort($domains);
foreach($domains as $key => $domain) {
?>
<tr>
<td class="title"><?php echo pql_complete_constant($LANG->_('Access to modify DN \b%dn%\B'), array('dn' => $domain)); ?></b></td>
<?php $class=pql_format_table(0); ?>
<td class="<?php echo $class?>"><?php echo $TEST["branches"][$domain]?></td>
</tr>
<?php }
}
}
?>
</th>
<th colspan="3" align="left">
<tr class="subtitle">
<td>
<table>
<th>
<tr>
<td><img src="images/info.png" width="16" height="16" border="0" align="right"></td>
<td>
<ul>
<li><?php echo $LANG->_('This is a simple test to show if the ldap extension is loaded\nand that the connections are working. It also does some\nrudimentary ACL tests')?>.</li>
<li><?php echo $LANG->_("NOTE: If you get denied access to create branches but when<br>trying with ACIs, it works. This doesn't mean that you don't<br>have access to create branches, it means that you \umust\U use<br>ACIs, otherwise you will not be allowed to create an object<br>(you will receive 'Insufficient access').")?></li>
</ul>
</td>
</tr>
</table>
</td>
<td></td>
</tr>
</th>
</table>
</body>
</html>
<?php
pql_flush();
/*
* Local variables:
* mode: php
* tab-width: 4
* End:
*/
?>