import from HEAD
[freeradius.git] / dialup_admin / lib / ldap / defaults.php3
1 <?php
2 require_once('../lib/ldap/functions.php3');
3 if ($config[ldap_default_dn] != ''){
4         include('../lib/ldap/attrmap.php3');
5         $regular_profile_attr = $config[ldap_regular_profile_attr];
6         $ds=@ldap_connect("$config[ldap_server]");  // must be a valid ldap server!
7         if ($ds) {
8                 $r=@da_ldap_bind($ds,$config);
9                 if ($config[ldap_debug] == 'true')
10                         print "<b>DEBUG(LDAP): Search Query: BASE='$config[ldap_default_dn]',FILTER='objectclass=*'</b><br>\n";
11                 $sr=@ldap_search($ds,"$config[ldap_default_dn]", 'objectclass=*');
12                 if ($info = @ldap_get_entries($ds, $sr)){
13                         $dn = $info[0]['dn'];
14                         if ($dn != ''){
15                                 foreach($attrmap as $key => $val){
16                                                 if ($info[0]["$val"][0] != '' && $key != 'Dialup-Access'){
17                                                         if ($attrmap[generic]["$key"] == 'generic'){
18                                                                 for($i=0;$i<$info[0]["$val"][count];$i++)
19                                                                         $default_vals["$key"][] = $info[0]["$val"][$i];
20                                                                 $default_vals["$key"][count] += $info[0]["$val"][count];
21                                                         }
22                                                         else
23                                                                 $default_vals["$key"] = $info[0]["$val"];
24                                                 }
25                                 }
26                         }
27                 }
28                 if ($regular_profile_attr != ''){
29                         $get_attrs = array("$regular_profile_attr");
30                         if ($config[ldap_filter] != '')
31                                 $filter = ldap_xlat($config[ldap_filter],$login,$config);
32                         else
33                                 $filter = 'uid=' . $login;
34                         if ($config[ldap_debug] == 'true')
35                                 print "<b>DEBUG(LDAP): Search Query: BASE='$config[ldap_base]',FILTER='$filter'</b><br>\n";
36                         $sr=@ldap_search($ds,"$config[ldap_base]",$filter,$get_attrs);
37                         if ($info = @ldap_get_entries($ds,$sr)){
38                                 for($i=0;$i<$info[0][$regular_profile_attr]["count"];$i++){
39                                         $dn2 = $info[0][$regular_profile_attr][$i];
40                                         if ($dn2 != ''){
41                                                 if ($config[ldap_debug] == 'true')
42                                                         print "<b>DEBUG(LDAP): Search Query: BASE='$dn2',FILTER='objectclass=*'</b><br>\n";
43                                                 $sr2=@ldap_search($ds,"$dn2",'objectclass=*');
44                                                 if ($info2 = @ldap_get_entries($ds,$sr2)){
45                                                         $dn3 = $info2[0]['dn'];
46                                                         if ($dn3 != ''){
47                                                                 foreach($attrmap as $key => $val){
48                                                                         if ($info2[0]["$val"][0] != '' && $key != 'Dialup-Access'){
49                                                                                 if (!isset($default_vals["$key"]))
50                                                                                         $default_vals["$key"] = array();
51                                                                                 if ($attrmap[generic]["$key"] == 'generic'){
52                                                                                         for($j=0;$j<$info2[0]["$val"][count];$j++)
53                                                                                                 $default_vals["$key"][] = $info2[0]["$val"][$j];
54                                                                                         $default_vals["$key"][count] += $info2[0]["$val"][count];
55                                                                                 }
56                                                                                 else
57                                                                                         $default_vals["$key"] = $info2[0]["$val"];
58                                                                         }
59                                                                 }
60                                                         }
61                                                 }
62                                         }
63                                 }
64                         }
65                 }
66                 @ldap_close($ds);
67         }
68 }
69
70 ?>