import from HEAD:
[freeradius.git] / dialup_admin / lib / ldap / user_info.php3
1 <?php
2 require('../lib/ldap/attrmap.php3');
3 require_once('../lib/ldap/functions.php3');
4 if (is_file("../lib/lang/$config[general_prefered_lang]/utf8.php3"))
5         include_once("../lib/lang/$config[general_prefered_lang]/utf8.php3");
6 else
7         include_once('../lib/lang/default/utf8.php3');
8
9 $cn = '-';
10 $cn_lang = '-';
11 $address = '-';
12 $address_lang = '-';
13 $homeaddress = '-';
14 $homeaddress_lang = '-';
15 $fax = '-';
16 $url = '-';
17 $ou = '-';
18 $ou_lang = '-';
19 $title = '-';
20 $title_lang = '-';
21 $telephonenumber = '-';
22 $homephone = '-';
23 $mobile = '-';
24 $mail = '-';
25 $mailalt = '-';
26
27 if ($config[general_decode_normal_attributes] == 'yes')
28         $decode_normal = 1;
29
30 $ds=@ldap_connect("$config[ldap_server]");  // must be a valid ldap server!
31 if ($ds) {
32         $r=@da_ldap_bind($ds,$config);
33         if ($config[ldap_userdn] == ''){
34                 if ($config[ldap_filter] != '')
35                         $filter = ldap_xlat($config[ldap_filter],$login,$config);
36                 else
37                         $filter = 'uid=' . $login;
38         }
39         else
40                 $filter = ldap_xlat($config[ldap_userdn],$login,$config);
41         if ($config[ldap_debug] == 'true'){
42                 if ($config[ldap_userdn] == '')
43                         print "<b>DEBUG(LDAP): Search Query: BASE='$config[ldap_base]',FILTER='$filter'</b><br>\n";
44                 else
45                         print "<b>DEBUG(LDAP): Search Query: BASE='$filter',FILTER='(objectclass=radiusprofile)'</b><br>\n";
46         }
47         if ($config[ldap_userdn] == '')
48                 $sr=@ldap_search($ds,"$config[ldap_base]", $filter);
49         else
50                 $sr=@ldap_read($ds,$filter, '(objectclass=radiusprofile)');
51         $info = @ldap_get_entries($ds, $sr);
52         $dn = $info[0]['dn'];
53         if ($dn == '')
54                 $user_exists = 'no';
55         else{
56                 $user_exists = 'yes';
57                 $user_info = 1;
58                 unset($item_vals);
59                 $k = init_decoder();
60                 $cn = ($info[0]['cn'][0]) ? $info[0]['cn'][0] : '-';
61                 if ($decode_normal)
62                         $cn = decode_string($cn,$k);
63                 $cn_lang = $info[0]["cn;lang-$config[general_prefered_lang]"][0];
64                 $cn_lang = decode_string("$cn_lang", $k);
65                 $cn_lang = ($cn_lang) ? $cn_lang : '-';
66                 $telephonenumber = ($info[0]['telephonenumber'][0]) ? $info[0]['telephonenumber'][0] : '-';
67                 $homephone = ($info[0]['homephone'][0]) ? $info[0]['homephone'][0] : '-';
68                 $address = ($info[0]['postaladdress'][0]) ? $info[0]['postaladdress'][0] : '-';
69                 if ($decode_normal)
70                         $address = decode_string($address,$k);
71                 $address_lang = $info[0]["postaladdress;lang-$config[general_prefered_lang]"][0];
72                 $address_lang = decode_string("$address_lang",$k);
73                 $address_lang = ($address_lang) ? $address_lang : '-';
74                 $homeaddress = ($info[0]['homepostaladdress'][0]) ? $info[0]['homepostaladdress'][0] : '-';
75                 $homeaddress_lang = $info[0]["homepostaladdress;lang-$config[general_prefered_lang]"][0];
76                 $homeaddress_lang = decode_string("$homeaddress_lang", $k);
77                 $homeaddress_lang = ($homeaddress_lang) ? $homeaddress_lang : '-';
78                 $mobile = ($info[0]['mobile'][0]) ? $info[0]['mobile'][0] : '-';
79                 $fax = ($info[0]['facsimiletelephonenumber'][0]) ? $info[0]['facsimiletelephonenumber'][0] : '-';
80                 $url = ($info[0]['labeleduri'][0]) ? $info[0]['labeleduri'][0] : '-';
81                 $ou = $info[0]['ou'][0];
82                 if ($decode_normal)
83                         $ou = decode_string($ou,$k);
84                 $ou_lang = $info[0]["ou;lang-$config[general_prefered_lang]"][0];
85                 $ou_lang = decode_string("$ou_lang", $k);
86                 $ou_lang = ($ou_lang) ? $ou_lang : '-';
87                 $mail = ($info[0]['mail'][0]) ? $info[0]['mail'][0] : '-';
88                 $title = ($info[0]['title'][0]) ? $info[0]['title'][0] : '-';
89                 if ($decode_normal)
90                         $title = decode_string($title,$k);
91                 $title_lang = $info[0]["title;lang-$config[general_prefered_lang]"][0];
92                 $title_lang = decode_string("$title_lang", $k);
93                 $title_lang = ($title_lang) ? $title_lang : '-';
94                 $mailalt = ($info[0]['mailalternateaddress'][0]) ? $info[0]['mailalternateaddress'][0] : '-';
95                 $user_password_exists = ($info[0]['userpassword'][0] != '') ? 'yes' : 'no';
96                 foreach($attrmap as $key => $val){
97                         $item_vals["$key"] = $info[0]["$val"];
98                 }
99         }
100         @ldap_close($ds);
101 }
102 else
103         echo "<b>Could not connect to the LDAP server</b><br>\n";
104 ?>