import from branch_1_1:
[freeradius.git] / dialup_admin / lib / ldap / change_attrs.php3
1 <?php
2 require_once('../lib/functions.php3');
3 require_once('../lib/ldap/functions.php3');
4         if ($config[ldap_write_server])
5                 $ds = @ldap_connect($config[ldap_write_server]);
6         else
7                 $ds = @ldap_connect($config[ldap_server]);
8         if ($ds){
9                 $r = @da_ldap_bind($ds,$config);
10                 if ($r){
11
12                         foreach($show_attrs as $key => $attr){
13                                 if ($attrmap["$key"] == 'none')
14                                         continue;
15                                 $i = 0;
16                                 $j = -1;
17                                 $name = $attrmap["$key"] . $i;
18
19                                 while (isset($$name)){
20                                         $val = $$name;
21                                         $i++;
22                                         $j++;
23                                         $name = $attrmap["$key"] . $i;
24 //
25 //      if value is the same as the default and the corresponding attribute in ldap does not exist or
26 //      the value is the same as that in ldap then continue
27 //
28                                         if ( (check_defaults($val,'',$default_vals["$key"]) && !isset($item_vals["$key"][$j])) || $val == $item_vals["$key"][$j])
29                                                 continue;
30 //
31 //      if value is null and ldap attribute does not exist then continue
32 //
33                                         if ($val == '' && !isset($item_vals["$key"][$j]))
34                                                 continue;
35 //
36 //      if values is the same as the default or if the value is null and the ldap attribute exists
37 //      then delete them
38 //
39                                         if ((check_defaults($val,'',$default_vals["$key"]) || $val == '') &&
40                                                 isset($item_vals["$key"][$j]))
41                                                 $del[$attrmap["$key"]][] = $item_vals["$key"][$j];
42 //
43 //      else modify the ldap attribute
44 //
45                                         else{
46                                                 if (isset($item_vals["$key"][$j])){
47                                                         $del[$attrmap["$key"]][] = $item_vals["$key"][$j];
48                                                         $add_r[$attrmap["$key"]][] = $val;
49                                                 }
50                                                 else{
51                                                         $add_r[$attrmap["$key"]][] = $val;
52                                                 }
53                                         }
54                                 }
55                         }
56                         if (isset($del)){
57                                if ($config[ldap_debug] == 'true'){
58                                         print "<b>DEBUG(LDAP): ldap_mod_del(): DN='$dn'</b><br>\n";
59                                         print "<b>DEBUG(LDAP): ldap_mod_del(): Data:";
60                                         print_r($del);
61                                         print "</b><br>\n";
62                                 }
63                                 @ldap_mod_del($ds,$dn,$del);
64                         }
65                         if (isset($add_r)){
66                                if ($config[ldap_debug] == 'true'){
67                                         print "<b>DEBUG(LDAP): ldap_mod_add(): DN='$dn'</b><br>\n";
68                                         print "<b>DEBUG(LDAP): ldap_mod_add(): Data:";
69                                         print_r($add_r);
70                                         print "</b><br>\n";
71                                 }
72                                 @ldap_mod_add($ds,$dn,$add_r);
73                         }
74                 }
75                 if (@ldap_error($ds) == 'Success')
76                         echo "<b>The changes were successfully commited to the directory</b><br>\n";
77                 else
78                         echo "<b>LDAP ERROR: " . ldap_error($ds) . "</b><br>\n";
79                 @ldap_close($ds);
80         }
81 ?>