1 <?php
3 /*
4 This code is part of GOsa (https://gosa.gonicus.de)
5 Copyright (C) 2007 Fabian Hickert
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
24 /****************
25 * FUNCTIONS
27 Step_Migrate - Constructor.
28 update_strings - Used to update the displayed step informations.
29 initialize_checks - Initialize migration steps.
30 check_ldap_permissions - Check if the used admin account has full access to the ldap database.
31 check_gosaAccounts - Check if there are users without the required objectClasses.
32 migrate_gosaAccounts - Migrate selected users to GOsa user accounts.
33 check_organizationalUnits - Check if there are departments, that are not visible for GOsa
34 migrate_organizationalUnits - Migrate selected departments
35 check_administrativeAccount - Check if there is at least one acl entry available
36 checkBase - Check if there is a root object available
38 get_user_list - Get list of available users
39 get_group_list - Get list of groups
41 create_admin
42 create_admin_user
44 execute - Generate html output of this plugin
45 save_object - Save posts
46 array_to_ldif - Create ldif output of an ldap result array
48 ****************/
52 class Step_Migrate extends setup_step
53 {
54 var $languages = array();
55 var $attributes = array();
56 var $header_image = "images/monitoring.png";
57 var $checks = array();
59 /* Department migration attributes */
60 var $dep_migration_dialog = FALSE;
61 var $deps_to_migrate = array();
62 var $show_details = FALSE;
64 /* Department migration attributes */
65 var $users_migration_dialog= FALSE;
66 var $users_to_migrate = array();
68 /* Create Acl attributes */
69 var $acl_create_dialog = FALSE;
70 var $acl_create_selected= ""; // Currently selected element, that should receive admin rights
71 var $acl_create_changes = ""; // Contains ldif information about changes
72 var $acl_create_confirmed= FALSE;
74 /* Checks initialised ? */
75 var $checks_initialised = FALSE;
77 /* Users outside to people ou */
78 var $outside_users = array();
79 var $outside_users_dialog = FALSE;
81 /* Users outside to groups ou */
82 var $outside_groups = array();
83 var $outside_groups_dialog = FALSE;
85 /* Win-Workstations outside to reserved ou */
86 var $outside_winstations = array();
87 var $outside_winstations_dialog = FALSE;
89 /* check for multiple use of same uidNumber */
90 var $check_uidNumbers = array();
91 var $check_uidNumbers_dialog = FALSE;
93 /* check for multiple use of same gidNumber */
94 var $check_gidNumbers = array();
95 var $check_gidNumbers_dialog = FALSE;
98 function Step_Migrate()
99 {
100 $this->update_strings();
101 }
103 function update_strings()
104 {
105 $this->s_title = _("LDAP inspection");
106 $this->s_title_long = _("LDAP inspection");
107 $this->s_info = _("Analyze your current LDAP for GOsa compatibility");
108 }
110 function initialize_checks()
111 {
112 $this->checks = array();
113 $this->checks['root']['TITLE'] = _("Checking for root object");
114 $this->checks['root']['STATUS'] = FALSE;
115 $this->checks['root']['STATUS_MSG']= "";
116 $this->checks['root']['ERROR_MSG'] = "";
117 $this->checkBase();
119 $this->checks['permissions']['TITLE'] = _("Checking permissions on LDAP database");
120 $this->checks['permissions']['STATUS'] = FALSE;
121 $this->checks['permissions']['STATUS_MSG']= "";
122 $this->checks['permissions']['ERROR_MSG'] = "";
123 $this->check_ldap_permissions();
125 $this->checks['deps_visible']['TITLE'] = _("Checking for invisible deparmtments");
126 $this->checks['deps_visible']['STATUS'] = FALSE;
127 $this->checks['deps_visible']['STATUS_MSG']= "";
128 $this->checks['deps_visible']['ERROR_MSG'] = "";
129 $this->check_organizationalUnits();
131 $this->checks['users_visible']['TITLE'] = _("Checking for invisible users");
132 $this->checks['users_visible']['STATUS'] = FALSE;
133 $this->checks['users_visible']['STATUS_MSG']= "";
134 $this->checks['users_visible']['ERROR_MSG'] = "";
135 $this->check_gosaAccounts();
137 $this->checks['acls']['TITLE'] = _("Checking for super administrator");
138 $this->checks['acls']['STATUS'] = FALSE;
139 $this->checks['acls']['STATUS_MSG']= "";
140 $this->checks['acls']['ERROR_MSG'] = "";
141 $this->check_administrativeAccount();
143 $this->checks['outside_users']['TITLE'] = _("Checking for users outside the people tree");
144 $this->checks['outside_users']['STATUS'] = FALSE;
145 $this->checks['outside_users']['STATUS_MSG']= "";
146 $this->checks['outside_users']['ERROR_MSG'] = "";
147 $this->search_outside_users();
149 $this->checks['outside_groups']['TITLE'] = _("Checking for groups outside the groups tree");
150 $this->checks['outside_groups']['STATUS'] = FALSE;
151 $this->checks['outside_groups']['STATUS_MSG']= "";
152 $this->checks['outside_groups']['ERROR_MSG'] = "";
153 $this->search_outside_groups();
155 $this->checks['outside_winstations']['TITLE'] = _("Checking for windows workstations outside the winstation tree");
156 $this->checks['outside_winstations']['STATUS'] = FALSE;
157 $this->checks['outside_winstations']['STATUS_MSG']= "";
158 $this->checks['outside_winstations']['ERROR_MSG'] = "";
159 $this->search_outside_winstations();
161 $this->checks['uidNumber_usage']['TITLE'] = _("Checking for duplicate uid numbers");
162 $this->checks['uidNumber_usage']['STATUS'] = FALSE;
163 $this->checks['uidNumber_usage']['STATUS_MSG']= "";
164 $this->checks['uidNumber_usage']['ERROR_MSG'] = "";
165 $this->check_uidNumber();
167 $this->checks['gidNumber_usage']['TITLE'] = _("Checking for duplicate gid numbers");
168 $this->checks['gidNumber_usage']['STATUS'] = FALSE;
169 $this->checks['gidNumber_usage']['STATUS_MSG']= "";
170 $this->checks['gidNumber_usage']['ERROR_MSG'] = "";
171 $this->check_gidNumber();
172 }
175 /* Check if there are uidNumbers which are used more than once.
176 */
177 function check_uidNumber()
178 {
179 $cv = $this->parent->captured_values;
180 $ldap = new LDAP($cv['admin'],
181 $cv['password'],
182 $cv['connection'],
183 FALSE,
184 $cv['tls']);
186 $ldap->cd($cv['base']);
187 $res = $ldap->search("uidNumber=*",array("dn","uidNumber"));
188 if(!$res){
189 $this->checks['uidNumber_usage']['STATUS'] = FALSE;
190 $this->checks['uidNumber_usage']['STATUS_MSG']= _("LDAP query failed");
191 $this->checks['uidNumber_usage']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
192 return(false);
193 }
195 $this->check_uidNumbers= array();
196 $tmp = array();
197 while($attrs = $ldap->fetch()){
198 $tmp[$attrs['uidNumber'][0]][] = $attrs;
199 }
201 foreach($tmp as $id => $entries){
202 if(count($entries) > 1){
203 foreach($entries as $entry){
204 $this->check_uidNumbers[base64_encode($entry['dn'])] = $entry;
205 }
206 }
207 }
209 if($this->check_uidNumbers){
210 $this->checks['uidNumber_usage']['STATUS'] = FALSE;
211 $this->checks['uidNumber_usage']['STATUS_MSG']= "<font style='color:#F0A500'>"._("Warning")."</font>";
212 $this->checks['uidNumber_usage']['ERROR_MSG'] =
213 sprintf(_("Found %s duplicate values for attribute 'uidNumber'."),count($this->check_uidNumbers));
214 return(false);
215 }else{
216 $this->checks['uidNumber_usage']['STATUS'] = TRUE;
217 $this->checks['uidNumber_usage']['STATUS_MSG']= _("Ok");
218 $this->checks['uidNumber_usage']['ERROR_MSG'] = "";
219 return(TRUE);
220 }
221 }
224 /* Check if there are duplicated gidNumbers present in ldap
225 */
226 function check_gidNumber()
227 {
228 $cv = $this->parent->captured_values;
229 $ldap = new LDAP($cv['admin'],
230 $cv['password'],
231 $cv['connection'],
232 FALSE,
233 $cv['tls']);
235 $ldap->cd($cv['base']);
236 $res = $ldap->search("(&(objectClass=posixGroup)(gidNumber=*))",array("dn","gidNumber"));
237 if(!$res){
238 $this->checks['gidNumber_usage']['STATUS'] = FALSE;
239 $this->checks['gidNumber_usage']['STATUS_MSG']= _("LDAP query failed");
240 $this->checks['gidNumber_usage']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
241 return(false);
242 }
244 $this->check_gidNumbers= array();
245 $tmp = array();
246 while($attrs = $ldap->fetch()){
247 $tmp[$attrs['gidNumber'][0]][] = $attrs;
248 }
250 foreach($tmp as $id => $entries){
251 if(count($entries) > 1){
252 foreach($entries as $entry){
253 $this->check_gidNumbers[base64_encode($entry['dn'])] = $entry;
254 }
255 }
256 }
258 if($this->check_gidNumbers){
259 $this->checks['gidNumber_usage']['STATUS'] = FALSE;
260 $this->checks['gidNumber_usage']['STATUS_MSG']= "<font style='color:#F0A500'>"._("Warning")."</font>";
261 $this->checks['gidNumber_usage']['ERROR_MSG'] =
262 sprintf(_("Found %s duplicate values for attribute 'gidNumber'."),count($this->check_gidNumbers));
263 return(false);
264 }else{
265 $this->checks['gidNumber_usage']['STATUS'] = TRUE;
266 $this->checks['gidNumber_usage']['STATUS_MSG']= _("Ok");
267 $this->checks['gidNumber_usage']['ERROR_MSG'] = "";
268 return(TRUE);
269 }
270 }
273 /* Search for winstations outside the winstation ou
274 */
275 function search_outside_winstations()
276 {
277 $cv = $this->parent->captured_values;
278 $ldap = new LDAP($cv['admin'],
279 $cv['password'],
280 $cv['connection'],
281 FALSE,
282 $cv['tls']);
284 /* Get winstation ou */
285 if($cv['generic_settings']['wws_ou_active']) {
286 $winstation_ou = $cv['generic_settings']['ws_ou'];
287 }else{
288 $winstation_ou = "ou=winstations";
289 }
291 if($cv['samba_version'] == 3){
292 $oc = "sambaSamAccount";
293 }else{
294 $oc = "sambaAccount";
295 }
297 $ldap->cd($cv['base']);
298 $res = $ldap->search("(&(objectClass=".$oc.")(uid=*$))",array("dn","sambaSID"));
299 if(!$res){
300 $this->checks['outside_winstations']['STATUS'] = FALSE;
301 $this->checks['outside_winstations']['STATUS_MSG']= _("LDAP query failed");
302 $this->checks['outside_winstations']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
303 return(false);
304 }
306 $this->outside_winstations = array();
307 while($attrs = $ldap->fetch()){
308 if((!preg_match("/^[^,]+,".normalizePreg($winstation_ou)."/",$attrs['dn'])) && !preg_match("/,dc=addressbook,/",$attrs['dn'])){
309 $attrs['selected'] = FALSE;
310 $attrs['ldif'] = "";
311 $this->outside_winstations[base64_encode($attrs['dn'])] = $attrs;
312 }
313 }
315 if(count($this->outside_winstations)){
316 $this->checks['outside_winstations']['STATUS'] = FALSE;
317 $this->checks['outside_winstations']['STATUS_MSG']= _("Failed");
318 $this->checks['outside_winstations']['ERROR_MSG'] =
319 sprintf(_("Found %s winstations outside the predefined winstation department ou '%s'."),count($this->outside_winstations),$winstation_ou);
320 $this->checks['outside_winstations']['ERROR_MSG'].= "<input type='submit' name='outside_winstations_dialog' value='"._("Migrate")."...'>";
321 return(false);
322 }else{
323 $this->checks['outside_winstations']['STATUS'] = TRUE;
324 $this->checks['outside_winstations']['STATUS_MSG']= _("Ok");
325 $this->checks['outside_winstations']['ERROR_MSG'] = "";
326 return(TRUE);
327 }
328 }
331 /* Search for groups outside the group ou
332 */
333 function search_outside_groups()
334 {
335 $cv = $this->parent->captured_values;
336 $ldap = new LDAP($cv['admin'],
337 $cv['password'],
338 $cv['connection'],
339 FALSE,
340 $cv['tls']);
342 $group_ou = $cv['groupou'];
343 $ldap->cd($cv['base']);
344 $res = $ldap->search("(objectClass=posixGroup)",array("dn"));
345 if(!$res){
346 $this->checks['outside_groups']['STATUS'] = FALSE;
347 $this->checks['outside_groups']['STATUS_MSG']= _("LDAP query failed");
348 $this->checks['outside_groups']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
349 return(false);
350 }
353 $this->outside_groups = array();
354 while($attrs = $ldap->fetch()){
355 if((!preg_match("/^[^,]+,".normalizePreg($group_ou)."/",$attrs['dn'])) && !preg_match("/,dc=addressbook,/",$attrs['dn'])){
356 $attrs['selected'] = FALSE;
357 $attrs['ldif'] = "";
358 $this->outside_groups[base64_encode($attrs['dn'])] = $attrs;
359 }
360 }
362 if(count($this->outside_groups)){
363 $this->checks['outside_groups']['STATUS'] = FALSE;
364 $this->checks['outside_groups']['STATUS_MSG']= "<font style='color:#F0A500'>"._("Warning")."</font>";
365 $this->checks['outside_groups']['ERROR_MSG'] =
366 sprintf(_("Found %s groups outside the configured tree '%s'."),count($this->outside_groups),$group_ou);
367 $this->checks['outside_groups']['ERROR_MSG'].= " <input type='submit' name='outside_groups_dialog' value='"._("Move")."...'>";
368 return(false);
369 }else{
370 $this->checks['outside_groups']['STATUS'] = TRUE;
371 $this->checks['outside_groups']['STATUS_MSG']= _("Ok");
372 $this->checks['outside_groups']['ERROR_MSG'] = "";
373 return(TRUE);
374 }
375 }
378 /* Search for users outside the people ou
379 */
380 function search_outside_users()
381 {
382 $cv = $this->parent->captured_values;
383 $ldap = new LDAP($cv['admin'],
384 $cv['password'],
385 $cv['connection'],
386 FALSE,
387 $cv['tls']);
388 $people_ou = $cv['peopleou'];
389 $ldap->cd($cv['base']);
390 $res = $ldap->search("(&(objectClass=gosaAccount)(!(uid=*$)))",array("dn"));
391 if(!$res){
392 $this->checks['outside_users']['STATUS'] = FALSE;
393 $this->checks['outside_users']['STATUS_MSG']= _("LDAP query failed");
394 $this->checks['outside_users']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
395 return(false);
396 }
399 $this->outside_users = array();
400 while($attrs = $ldap->fetch()){
401 if((!preg_match("/^[^,]+,".normalizePreg($people_ou)."/",$attrs['dn']) && !preg_match("/,dc=addressbook,/",$attrs['dn']))){
402 $attrs['selected'] = FALSE;
403 $attrs['ldif'] = "";
404 $this->outside_users[base64_encode($attrs['dn'])] = $attrs;
405 }
406 }
408 if(count($this->outside_users)){
409 $this->checks['outside_users']['STATUS'] = FALSE;
410 $this->checks['outside_users']['STATUS_MSG']= "<font style='color:#F0A500'>"._("Warning")."</font>";
411 $this->checks['outside_users']['ERROR_MSG'] =
412 sprintf(_("Found %s user(s) outside the configured tree '%s'."),count($this->outside_users),$people_ou);
413 $this->checks['outside_users']['ERROR_MSG'].= "<input type='submit' name='outside_users_dialog' value='"._("Move")."...'>";
414 return(false);
415 }else{
416 $this->checks['outside_users']['STATUS'] = TRUE;
417 $this->checks['outside_users']['STATUS_MSG']= _("Ok");
418 $this->checks['outside_users']['ERROR_MSG'] = "";
419 return(TRUE);
420 }
421 }
424 /* Check ldap accessibility
425 * Create and remove a dummy object,
426 * to ensure that we have the necessary permissions
427 */
428 function check_ldap_permissions()
429 {
430 $cv = $this->parent->captured_values;
431 $ldap = new LDAP($cv['admin'],
432 $cv['password'],
433 $cv['connection'],
434 FALSE,
435 $cv['tls']);
437 /* Create dummy entry
438 */
439 $name = "GOsa_setup_text_entry_".session_id().rand(0,999999);
440 $dn = "ou=".$name.",".$cv['base'];
441 $testEntry= array();
442 $testEntry['objectClass'][]= "top";
443 $testEntry['objectClass'][]= "organizationalUnit";
444 $testEntry['objectClass'][]= "gosaDepartment";
445 $testEntry['description']= "Created by GOsa setup, this object can be removed.";
446 $testEntry['ou'] = $name;
448 /* check if simple ldap cat will be successful
449 */
450 $res = $ldap->cat($cv['base']);
451 if(!$res){
452 $this->checks['permissions']['STATUS'] = FALSE;
453 $this->checks['permissions']['STATUS_MSG']= _("LDAP query failed");
454 $this->checks['permissions']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
455 return(false);
456 }
458 /* Try to create dummy object
459 */
460 $ldap->cd ($dn);
461 $ldap->create_missing_trees($dn);
462 $res = $ldap->add($testEntry);
463 $ldap->cat($dn);
464 if(!$ldap->count()){
465 gosa_log($ldap->get_error());
466 $this->checks['permissions']['STATUS'] = FALSE;
467 $this->checks['permissions']['STATUS_MSG']= _("Failed");
468 $this->checks['permissions']['ERROR_MSG'] =
469 sprintf(_("The specified user '%s' does not have full access to your ldap database."),$cv['admin']);
470 return(false);
471 }
473 /* Try to remove created entry
474 */
475 $res = $ldap->rmDir($dn);
476 $ldap->cat($dn);
477 if($ldap->count()){
478 gosa_log($ldap->get_error());
479 $this->checks['permissions']['STATUS'] = FALSE;
480 $this->checks['permissions']['STATUS_MSG']= _("Failed");
481 $this->checks['permissions']['ERROR_MSG'] =
482 sprintf(_("The specified user '%s' does not have full access to your ldap database."),$cv['admin']);
483 return(false);
484 }
486 /* Create & remove of dummy object was successful */
487 $this->checks['permissions']['STATUS'] = TRUE;
488 $this->checks['permissions']['STATUS_MSG']= _("Ok");
489 $this->checks['permissions']['ERROR_MSG'] = "";
490 return(true);
491 }
494 /* Check if there are users which will
495 * be invisible for GOsa
496 */
497 function check_gosaAccounts()
498 {
499 /* Remember old list of ivisible users, to be able to set
500 * the 'html checked' status for the checkboxes again
501 */
502 $cnt_ok = 0;
503 $old = $this->users_to_migrate;
504 $this->users_to_migrate = array();
506 /* Get collected configuration settings */
507 $cv = $this->parent->captured_values;
509 /* Establish ldap connection */
510 $ldap = new LDAP($cv['admin'],
511 $cv['password'],
512 $cv['connection'],
513 FALSE,
514 $cv['tls']);
516 /* Get all invisible users
517 */
518 $ldap->cd($cv['base']);
519 $res =$ldap->search("(&(|(objectClass=posixAccount)(&(objectClass=inetOrgPerson)(objectClass=organizationalPerson)))(!(objectClass=gosaAccount))(uid=*))",array("sn","givenName","cn","uid"));
520 while($attrs = $ldap->fetch()){
521 if(!preg_match("/,dc=addressbook,/",$attrs['dn'])){
522 $attrs['checked'] = FALSE;
523 $attrs['before'] = "";
524 $attrs['after'] = "";
526 /* Set objects to selected, that were selected before reload */
527 if(isset($old[base64_encode($attrs['dn'])])){
528 $attrs['checked'] = $old[base64_encode($attrs['dn'])]['checked'];
529 }
530 $this->users_to_migrate[base64_encode($attrs['dn'])] = $attrs;
531 }
532 }
534 /* No invisible */
535 if(!$res){
536 $this->checks['users_visible']['STATUS'] = FALSE;
537 $this->checks['users_visible']['STATUS_MSG']= _("LDAP query failed");
538 $this->checks['users_visible']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
539 }elseif(count($this->users_to_migrate) == 0){
540 $this->checks['users_visible']['STATUS'] = TRUE;
541 $this->checks['users_visible']['STATUS_MSG']= _("Ok");
542 $this->checks['users_visible']['ERROR_MSG'] = "";
543 }else{
544 $this->checks['users_visible']['STATUS'] = FALSE;
545 $this->checks['users_visible']['STATUS_MSG']= "<font style='color:#F0A500'>"._("Warning")."</font>";
546 $this->checks['users_visible']['ERROR_MSG'] = sprintf(_("Found %s user(s) that will not be visible in GOsa."),
547 count($this->users_to_migrate));
548 $this->checks['users_visible']['ERROR_MSG'] .= "<input type='submit' name='users_visible_migrate' value='"._("Migrate")."...'>";
549 }
550 }
553 /* Start user account migration
554 */
555 function migrate_gosaAccounts($only_ldif = FALSE)
556 {
557 $this->show_details= $only_ldif;
559 /* Get collected configuration settings */
560 $cv = $this->parent->captured_values;
562 /* Establish ldap connection */
563 $ldap = new LDAP($cv['admin'],
564 $cv['password'],
565 $cv['connection'],
566 FALSE,
567 $cv['tls']);
569 /* Add gosaAccount objectClass to the selected users
570 */
571 foreach($this->users_to_migrate as $key => $dep){
572 if($dep['checked']){
574 /* Get old objectClasses */
575 $ldap->cat($dep['dn'],array("objectClass"));
576 $attrs = $ldap->fetch();
578 /* Create new objectClass array */
579 $new_attrs = array();
580 $new_attrs['objectClass']= array("gosaAccount","inetOrgPerson","organizationalPerson");
581 for($i = 0 ; $i < $attrs['objectClass']['count']; $i ++ ){
582 if(!in_array_ics($attrs['objectClass'][$i], $new_attrs['objectClass'])){
583 $new_attrs['objectClass'][] = $attrs['objectClass'][$i];
584 }
585 }
587 /* Set info attributes for current object,
588 * or write changes to the ldap database
589 */
590 if($only_ldif){
591 $this->users_to_migrate[$key]['before'] = $this->array_to_ldif($attrs);
592 $this->users_to_migrate[$key]['after'] = $this->array_to_ldif($new_attrs);
593 }else{
594 $ldap->cd($attrs['dn']);
595 if(!$ldap->modify($new_attrs)){
596 print_red(sprintf(_("Failed to migrate the department '%s' into GOsa, error message is as follows '%s'."),$attrs['dn'],$ldap->get_error()));
597 return(false);
598 }
599 }
600 }
601 }
602 return(TRUE);
603 }
606 /* Check if there are invisible organizational Units
607 */
608 function check_organizationalUnits()
609 {
610 $cnt_ok = 0;
611 $old = $this->deps_to_migrate;
612 $this->deps_to_migrate = array();
614 /* Get collected configuration settings */
615 $cv = $this->parent->captured_values;
617 /* Establish ldap connection */
618 $ldap = new LDAP($cv['admin'],
619 $cv['password'],
620 $cv['connection'],
621 FALSE,
622 $cv['tls']);
624 /* Skip GOsa internal departments */
625 $skip_dns = array("/^ou=people,/","/^ou=groups,/","/(,|)ou=configs,/","/(,|)ou=systems,/",
626 "/^ou=apps,/","/^ou=mime,/","/^ou=aclroles,/","/^ou=incoming,/",
627 "/ou=snapshots,/","/(,|)dc=addressbook,/","/^(,|)ou=machineaccounts,/",
628 "/(,|)ou=winstations,/");
631 /* Get all invisible departments */
632 $ldap->cd($cv['base']);
633 $res = $ldap->search("(&(objectClass=organizationalUnit)(!(objectClass=gosaDepartment)))",array("ou","description","dn"));
634 while($attrs = $ldap->fetch()){
635 $attrs['checked'] = FALSE;
636 $attrs['before'] = "";
637 $attrs['after'] = "";
639 /* Set objects to selected, that were selected before reload */
640 if(isset($old[base64_encode($attrs['dn'])])){
641 $attrs['checked'] = $old[base64_encode($attrs['dn'])]['checked'];
642 }
643 $this->deps_to_migrate[base64_encode($attrs['dn'])] = $attrs;
644 }
646 /* Filter returned list of departments and ensure that
647 * GOsa internal departments will not be listed
648 */
649 foreach($this->deps_to_migrate as $key => $attrs){
650 $dn = $attrs['dn'];
651 $skip = false;
652 foreach($skip_dns as $skip_dn){
653 if(preg_match($skip_dn,$dn)){
654 $skip = true;
655 }
656 }
657 if($skip){
658 unset($this->deps_to_migrate[$key]);
659 }
660 }
662 /* If we have no invisible departments found
663 * tell the user that everything is ok
664 */
665 if(!$res){
666 $this->checks['deps_visible']['STATUS'] = FALSE;
667 $this->checks['deps_visible']['STATUS_MSG']= _("LDAP query failed");
668 $this->checks['deps_visible']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
669 }elseif(count($this->deps_to_migrate) == 0 ){
670 $this->checks['deps_visible']['STATUS'] = TRUE;
671 $this->checks['deps_visible']['STATUS_MSG']= _("Ok");
672 $this->checks['deps_visible']['ERROR_MSG'] = "";
673 }else{
674 $this->checks['deps_visible']['STATUS'] = TRUE;
675 $this->checks['deps_visible']['STATUS_MSG']= '<font style="color:#FFA500">'._("Warning").'</font>';
676 $this->checks['deps_visible']['ERROR_MSG'] = sprintf(_("Found %s department(s) that will not be visible in GOsa."),count($this->deps_to_migrate));
677 $this->checks['deps_visible']['ERROR_MSG'] .= " <input type='submit' name='deps_visible_migrate' value='"._("Migrate")."...'>";
678 }
679 }
683 /* Start deparmtment migration */
684 function migrate_organizationalUnits($only_ldif = FALSE)
685 {
686 $this->show_details= $only_ldif;
688 /* Get collected configuration settings */
689 $cv = $this->parent->captured_values;
691 /* Establish ldap connection */
692 $ldap = new LDAP($cv['admin'],
693 $cv['password'],
694 $cv['connection'],
695 FALSE,
696 $cv['tls']);
698 /* Add gosaDepartment objectClass to each selected entry
699 */
700 foreach($this->deps_to_migrate as $key => $dep){
701 if($dep['checked']){
703 /* Get current objectClasses */
704 $ldap->cat($dep['dn'],array("objectClass","description"));
705 $attrs = $ldap->fetch();
707 /* Create new objectClass attribute including gosaDepartment*/
708 $new_attrs = array();
709 for($i = 0 ; $i < $attrs['objectClass']['count']; $i ++ ){
710 $new_attrs['objectClass'][] = $attrs['objectClass'][$i];
711 }
712 $new_attrs['objectClass'][] = "gosaDepartment";
714 /* Append description it is missing */
715 if(!isset($attrs['description'])){
716 $new_attrs['description'][] = "GOsa department";
717 }
719 /* Depending on the parameter >only_diff< we save the changes as ldif
720 * or we write our changes directly to the ldap database
721 */
722 if($only_ldif){
723 $this->deps_to_migrate[$key]['before'] = $this->array_to_ldif($attrs);
724 $this->deps_to_migrate[$key]['after'] = $this->array_to_ldif($new_attrs);
725 }else{
726 $ldap->cd($attrs['dn']);
727 if(!$ldap->modify($new_attrs)){
728 print_red(sprintf(_("Failed to migrate the department '%s' into GOsa, error message is as follows '%s'."),$attrs['dn'],$ldap->get_error()));
729 return(false);
730 }
731 }
732 }
733 }
734 return(TRUE);
735 }
738 /* Check Acls if there is at least one object with acls defined
739 */
740 function check_administrativeAccount()
741 {
742 /* Establish ldap connection */
743 $cv = $this->parent->captured_values;
744 $ldap = new LDAP($cv['admin'],
745 $cv['password'],
746 $cv['connection'],
747 FALSE,
748 $cv['tls']);
750 /* Search for groups that have complete permissions */
751 $ldap->cd($cv['base']);
752 $res = $ldap->search("(&(objectClass=posixGroup)(gosaSubtreeACL=:all)(memberUid=*))",array("memberUid","cn"));
754 /* If ldap search failed, set error message */
755 if(!$res){
756 $this->checks['acls']['STATUS'] = FALSE;
757 $this->checks['acls']['STATUS_MSG']= _("LDAP query failed");
758 $this->checks['acls']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
759 }else{
761 /* */
762 $found = FALSE;
763 $debug = "";
764 $admin_groups = array();
766 /* Get all returned groups */
767 while($attrs = $ldap->fetch()){
768 $admin_groups[]= $attrs;
769 }
771 /* Walk through groups and check if memberUid exists in ldap database */
772 foreach($admin_groups as $group){
774 $debug .= "<b>".$group['cn'][0].":</b><br>";
776 $count_member = $group['memberUid']['count'];
778 /* Check every single group member */
779 for($i = 0 ; $i < $count_member ; $i++){
780 $debug .= $group['memberUid'][$i];
782 /* Check if user exists */
783 $ldap->search("(&(objectClass=gosaAccount)(uid=".$group['memberUid'][$i]."))",array("dn"));
784 $cnt= $ldap->count();
786 /* Update found-status if there is a member available */
787 if($cnt == 1){
788 $debug .= " <i>->Found</i><br>";
789 $found = TRUE;
790 }elseif($cnt == 0 ){
791 $debug .= " <font color='red'>-> NOT Found</font><br>";
792 }else{
793 $debug .= " <font color='red'>-> Found more than once -.- </font><br>";
794 }
795 }
797 }
798 # For debugging
799 # echo $debug."<br>----------------<br>";
801 if($found){
802 $this->checks['acls']['STATUS'] = TRUE;
803 $this->checks['acls']['STATUS_MSG']= _("Ok");
804 $this->checks['acls']['ERROR_MSG'] = "";
805 }else{
806 $this->checks['acls']['STATUS'] = FALSE;
807 $this->checks['acls']['STATUS_MSG']= _("Failed");
808 $this->checks['acls']['ERROR_MSG']= _("There is no GOsa administrator account inside your LDAP.")." ";
809 $this->checks['acls']['ERROR_MSG'].= "<input type='submit' name='create_acls' value='"._("Create")."'>";
810 }
811 }
812 return($ldap->count()>=1);
813 }
817 function create_admin($only_ldif = FALSE)
818 {
819 /* Reset '' */
820 $this->acl_create_changes="";
822 /* Object that should receive admin acls */
823 $dn = $this->acl_create_selected;
825 /* Get collected configuration settings */
826 $cv = $this->parent->captured_values;
828 /* Establish ldap connection */
829 $ldap = new LDAP($cv['admin'],
830 $cv['password'],
831 $cv['connection'],
832 FALSE,
833 $cv['tls']);
835 $ldap->cd($cv['base']);
836 $ldap->cat($dn,array("objectClass","cn","uid"));
837 $object_attrs = $ldap->fetch();
838 $type = "none";
840 /* Check object that should receive admin acls */
841 if(in_array("gosaAccount",$object_attrs['objectClass'])){
842 $type = "user";
843 }elseif(in_array("posixGroup",$object_attrs['objectClass'])){
844 $type = "group";
845 }
847 /* If a user should get administrative acls, we
848 * should check if there is an administrational group
849 * and just assign the user to it.
850 * If there is no such group, we must create one.
851 */
852 if($type == "user"){
854 $ldap->search("(&(objectClass=posixGroup)(gosaSubtreeACL=:all)(memberUid=*))",array("memberUid"));
855 if($ldap->count()){
856 $fetched_attrs = $ldap->fetch();
857 $attrs_admin_group = $this->cleanup_array($fetched_attrs);
858 $attrs_admin_group_new = $attrs_admin_group;
860 if(!isset($attrs_admin_group_new['memberUid'])){
861 $attrs_admin_group_new['memberUid'] = array();
862 }
863 if(!in_array($object_attrs['uid'][0],$attrs_admin_group_new['memberUid'])){
864 $attrs_admin_group_new['memberUid'][] = $object_attrs['uid'][0];
865 }
867 if($only_ldif){
868 $this->acl_create_changes = _("Appending user to to group administrational group: \n");
869 $this->acl_create_changes.= "\n"._("Before").":\n";
870 $this->acl_create_changes.= $fetched_attrs['dn']."\n";
871 $this->acl_create_changes.= $this->array_to_ldif($attrs_admin_group)."\n";
872 $this->acl_create_changes.= "\n"._("After").":\n";
873 $this->acl_create_changes.= $fetched_attrs['dn']."\n";
874 $this->acl_create_changes.= $this->array_to_ldif($attrs_admin_group_new)."\n";
875 }else{
876 $ldap->cd($fetched_attrs['dn']);
877 $ldap->modify($attrs_admin_group_new);
878 if(!preg_match("/success/i",$ldap->get_error())){
879 print_red(sprintf(_("Adding acls for user '%s' failed, ldap says '%s'."),$dn,$ldap->get_error()));
880 return(FALSE);
881 }
882 }
884 }else{
885 $new_group_dn = "cn=GOsa Administrators,".$cv['groupou'].",".$cv['base'];
886 $new_group_attrs['objectClass'] = array("gosaObject","posixGroup");
887 $new_group_attrs['cn'] = "GOsa Administrators";
888 $new_group_attrs['gosaSubtreeACL'] = ":all";
889 $new_group_attrs['gidNumber'] = "999";
890 $new_group_attrs['memberUid'] = array($object_attrs['uid'][0]);
892 if($only_ldif){
893 $this->acl_create_changes = _("Creating new administrational group: \n\n");
894 $this->acl_create_changes.= $new_group_dn."\n";
895 $this->acl_create_changes.= $this->array_to_ldif($new_group_attrs);
896 }else{
897 $ldap->cd($cv['base']);
898 $ldap->create_missing_trees($cv['groupou'].",".$cv['base']);
899 $ldap->cd($new_group_dn);
900 $res = $ldap->add($new_group_attrs);
901 if(!$res){
902 print_red(sprintf(_("Adding acls for user '%s' failed, ldap says '%s'."),$dn,$ldap->get_error()));
903 return(FALSE);
904 }
905 }
906 }
907 }
908 return(TRUE);
909 }
912 function create_admin_user()
913 {
914 $pw1 = $pw2 = "";
915 $uid = "";
917 if(isset($_POST['new_user_uid'])){
918 $uid = $_POST['new_user_uid'];
919 }
921 if(isset($_POST['new_user_password'])){
922 $pw1 = $_POST['new_user_password'];
923 }
924 if(isset($_POST['new_user_password2'])){
925 $pw2 = $_POST['new_user_password2'];
926 }
928 if(empty($pw1) || empty($pw2) | ($pw1 != $pw2)){
929 print_red(_("Specified passwords are empty or not equal."));
930 return false;
931 }
933 if(!is_uid($uid) || empty($uid)){
934 print_red(_("Please specify a valid uid."));
935 return false;
936 }
938 /* Establish ldap connection */
939 $cv = $this->parent->captured_values;
940 $ldap = new LDAP($cv['admin'],
941 $cv['password'],
942 $cv['connection'],
943 FALSE,
944 $cv['tls']);
946 /* Get current base attributes */
947 $ldap->cd($cv['base']);
949 if($cv['peopledn'] == "cn"){
950 $dn = "cn=System Administrator,".$cv['peopleou'].",".$cv['base'];
951 }else{
952 $dn = "uid=".$uid.",".$cv['peopleou'].",".$cv['base'];
953 }
955 $methods = @passwordMethod::get_available_methods_if_not_loaded();
956 $p_m = $methods[$cv['encryption']];
957 $p_c = new $p_m(array());
958 $hash = $p_c->generate_hash($pw2);
960 $new_user=array();
961 $new_user['objectClass']= array("top","person","gosaAccount","organizationalPerson","inetOrgPerson");
962 $new_user['givenName'] = "System";
963 $new_user['sn'] = "Administrator";
964 $new_user['cn'] = "System Administrator";
965 $new_user['uid'] = $uid;
966 $new_user['userPassword'] = $hash;
968 $ldap->cd($cv['base']);
970 $ldap->cat($dn,array("dn"));
971 if($ldap->count()){
972 print_red(sprintf(_("Could not add administrative user, there is already an object with the same dn '%s' in your ldap database."),
973 $dn));
974 return(FALSE);
975 }
977 $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$dn));
978 $ldap->cd($dn);
979 $res = $ldap->add($new_user);
980 $this->acl_create_selected = $dn;
981 $this->create_admin();
983 if(!$res){
984 print_red($ldap->get_error());
985 return(FALSE);
986 }
988 $this->acl_create_dialog=FALSE;
989 $this->check_administrativeAccount();
990 return(TRUE);
991 }
994 function migrate_outside_winstations($perform = FALSE)
995 {
996 /* Establish ldap connection */
997 $cv = $this->parent->captured_values;
998 $ldap = new LDAP($cv['admin'],
999 $cv['password'],
1000 $cv['connection'],
1001 FALSE,
1002 $cv['tls']);
1004 $ldap->cd($cv['base']);
1006 /* Check if there was a destination department posted */
1007 if(isset($_POST['move_winstation_to'])){
1008 $destination_dep = $_POST['move_winstation_to'];
1009 }else{
1010 print_red(_("Couldn't move users to specified department."));
1011 return(false);
1012 }
1014 foreach($this->outside_winstations as $b_dn => $data){
1015 $this->outside_winstations[$b_dn]['ldif'] ="";
1016 if($data['selected']){
1017 $dn = base64_decode($b_dn);
1018 $d_dn = preg_replace("/,.*$/",",".base64_decode($destination_dep),$dn);
1019 if(!$perform){
1020 $this->outside_winstations[$b_dn]['ldif'] = _("Winstation will be moved from").":<br>\t".$dn."<br>"._("to").":<br>\t".$d_dn;
1023 /* Check if there are references to this object */
1024 $ldap->search("(&(member=".$dn.")(|(objectClass=gosaGroupOfNames)(objectClass=groupOfNames)))",array('dn'));
1025 $refs = "";
1026 while($attrs = $ldap->fetch()){
1027 $ref_dn = $attrs['dn'];
1028 $refs .= "<br />\t".$ref_dn;
1029 }
1030 if(!empty($refs)){
1031 $this->outside_winstations[$b_dn]['ldif'] .= "<br /><br /><i>"._("Updating following references too").":</i>".$refs;
1032 }
1034 }else{
1035 $this->move($dn,$d_dn);
1036 }
1037 }
1038 }
1039 }
1042 function migrate_outside_groups($perform = FALSE)
1043 {
1044 /* Establish ldap connection */
1045 $cv = $this->parent->captured_values;
1046 $ldap = new LDAP($cv['admin'],
1047 $cv['password'],
1048 $cv['connection'],
1049 FALSE,
1050 $cv['tls']);
1052 $ldap->cd($cv['base']);
1054 /* Check if there was a destination department posted */
1055 if(isset($_POST['move_group_to'])){
1056 $destination_dep = $_POST['move_group_to'];
1057 }else{
1058 print_red(_("Couldn't move users to specified department."));
1059 return(false);
1060 }
1062 foreach($this->outside_groups as $b_dn => $data){
1063 $this->outside_groups[$b_dn]['ldif'] ="";
1064 if($data['selected']){
1065 $dn = base64_decode($b_dn);
1066 $d_dn = preg_replace("/,.*$/",",".base64_decode($destination_dep),$dn);
1067 if(!$perform){
1068 $this->outside_groups[$b_dn]['ldif'] = _("Group will be moved from").":<br>\t".$dn."<br>"._("to").":<br>\t".$d_dn;
1071 /* Check if there are references to this object */
1072 $ldap->search("(&(member=".$dn.")(|(objectClass=gosaGroupOfNames)(objectClass=groupOfNames)))",array('dn'));
1073 $refs = "";
1074 while($attrs = $ldap->fetch()){
1075 $ref_dn = $attrs['dn'];
1076 $refs .= "<br />\t".$ref_dn;
1077 }
1078 if(!empty($refs)){
1079 $this->outside_groups[$b_dn]['ldif'] .= "<br /><br /><i>"._("Updating following references too").":</i>".$refs;
1080 }
1082 }else{
1083 $this->move($dn,$d_dn);
1084 }
1085 }
1086 }
1087 }
1090 function migrate_outside_users($perform = FALSE)
1091 {
1092 /* Establish ldap connection */
1093 $cv = $this->parent->captured_values;
1094 $ldap = new LDAP($cv['admin'],
1095 $cv['password'],
1096 $cv['connection'],
1097 FALSE,
1098 $cv['tls']);
1100 $ldap->cd($cv['base']);
1102 /* Check if there was a destination department posted */
1103 if(isset($_POST['move_user_to'])){
1104 $destination_dep = $_POST['move_user_to'];
1105 }else{
1106 print_red(_("Couldn't move users to specified department."));
1107 return(false);
1108 }
1110 foreach($this->outside_users as $b_dn => $data){
1111 $this->outside_users[$b_dn]['ldif'] ="";
1112 if($data['selected']){
1113 $dn = base64_decode($b_dn);
1114 $d_dn = preg_replace("/,.*$/",",".base64_decode($destination_dep),$dn);
1115 if(!$perform){
1116 $this->outside_users[$b_dn]['ldif'] = _("User will be moved from").":<br>\t".$dn."<br>"._("to").":<br>\t".$d_dn;
1118 /* Check if there are references to this object */
1119 $ldap->search("(&(member=".$dn.")(|(objectClass=gosaGroupOfNames)(objectClass=groupOfNames)))",array('dn'));
1120 $refs = "";
1121 while($attrs = $ldap->fetch()){
1122 $ref_dn = $attrs['dn'];
1123 $refs .= "<br />\t".$ref_dn;
1124 }
1125 if(!empty($refs)){
1126 $this->outside_users[$b_dn]['ldif'] .= "<br /><br /><i>"._("The following references will be updated").":</i>".$refs;
1127 }
1129 }else{
1130 $this->move($dn,$d_dn);
1131 }
1132 }
1133 }
1134 }
1137 function execute()
1138 {
1139 /* Initialise checks if this is the first call */
1140 if(!$this->checks_initialised || isset($_POST['reload'])){
1141 $this->initialize_checks();
1142 $this->checks_initialised = TRUE;
1143 }
1145 /*************
1146 * Winstations outside the group ou
1147 *************/
1149 if(isset($_POST['outside_winstations_dialog_cancel'])){
1150 $this->outside_winstations_dialog = FALSE;
1151 $this->dialog = FALSE;
1152 $this->show_details = FALSE;
1153 }
1155 if(isset($_POST['outside_winstations_dialog_whats_done'])){
1156 $this->migrate_outside_winstations(FALSE);
1157 }
1159 if(isset($_POST['outside_winstations_dialog_perform'])){
1160 $this->migrate_outside_winstations(TRUE);
1161 $this->search_outside_winstations();
1162 $this->dialog = FALSE;
1163 $this->show_details = FALSE;
1164 $this->outside_winstations_dialog = FALSE;
1165 }
1167 if(isset($_POST['outside_winstations_dialog'])){
1168 $this->outside_winstations_dialog = TRUE;
1169 $this->dialog = TRUE;
1170 }
1172 if($this->outside_winstations_dialog){
1173 $smarty = get_smarty();
1174 $smarty->assign("ous",$this->get_all_winstation_ous());
1175 $smarty->assign("method","outside_winstations");
1176 $smarty->assign("outside_winstations",$this->outside_winstations);
1177 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1178 }
1179 /*************
1180 * Groups outside the group ou
1181 *************/
1183 if(isset($_POST['outside_groups_dialog_cancel'])){
1184 $this->outside_groups_dialog = FALSE;
1185 $this->show_details = FALSE;
1186 $this->dialog = FALSE;
1187 }
1189 if(isset($_POST['outside_groups_dialog_whats_done'])){
1190 $this->show_details= TRUE;
1191 $this->migrate_outside_groups(FALSE);
1192 }
1194 if(isset($_POST['outside_groups_dialog_refresh'])){
1195 $this->show_details= FALSE;
1196 }
1198 if(isset($_POST['outside_groups_dialog_perform'])){
1199 $this->migrate_outside_groups(TRUE);
1200 $this->dialog = FALSE;
1201 $this->show_details = FALSE;
1202 $this->outside_groups_dialog = FALSE;
1203 $this->initialize_checks();
1204 }
1206 if(isset($_POST['outside_groups_dialog'])){
1207 $this->outside_groups_dialog = TRUE;
1208 $this->dialog = TRUE;
1209 }
1211 if($this->outside_groups_dialog){
1212 $smarty = get_smarty();
1213 $smarty->assign("ous",$this->get_all_group_ous());
1214 $smarty->assign("method","outside_groups");
1215 $smarty->assign("outside_groups",$this->outside_groups);
1216 $smarty->assign("group_details", $this->show_details);
1217 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1218 }
1220 /*************
1221 * User outside the people ou
1222 *************/
1224 if(isset($_POST['outside_users_dialog_cancel'])){
1225 $this->outside_users_dialog = FALSE;
1226 $this->dialog = FALSE;
1227 $this->show_details = FALSE;
1228 }
1230 if(isset($_POST['outside_users_dialog_whats_done'])){
1231 $this->show_details= TRUE;
1232 $this->migrate_outside_users(FALSE);
1233 }
1235 if(isset($_POST['outside_users_dialog_perform'])){
1236 $this->migrate_outside_users(TRUE);
1237 $this->initialize_checks();
1238 $this->dialog = FALSE;
1239 $this->show_details = FALSE;
1240 $this->outside_users_dialog = FALSE;
1241 }
1243 if (isset($_POST['outside_users_dialog_refresh'])){
1244 $this->show_details= FALSE;
1245 }
1247 if(isset($_POST['outside_users_dialog'])){
1248 $this->outside_users_dialog = TRUE;
1249 $this->dialog = TRUE;
1250 }
1252 if($this->outside_users_dialog){
1253 $smarty = get_smarty();
1254 $smarty->assign("ous",$this->get_all_people_ous());
1255 $smarty->assign("method","outside_users");
1256 $smarty->assign("outside_users",$this->outside_users);
1257 $smarty->assign("user_details", $this->show_details);
1258 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1259 }
1261 /*************
1262 * Root object check
1263 *************/
1265 if(isset($_POST['retry_root_create'])){
1267 $state = $this->checks['root']['STATUS'];
1268 $this->checkBase(FALSE);
1269 if($state != $this->checks['root']['STATUS']){
1270 $this->initialize_checks();
1271 }
1272 }
1274 /*************
1275 * User Migration handling
1276 *************/
1278 if(isset($_POST['retry_acls'])){
1279 $this->check_administrativeAccount();
1280 }
1282 if(isset($_POST['create_acls'])){
1283 $this->acl_create_dialog = TRUE;
1284 $this->dialog = TRUE;
1285 }
1287 if(isset($_POST['create_acls_cancel'])){
1288 $this->acl_create_dialog = FALSE;
1289 $this->dialog = FALSE;
1290 $this->show_details = FALSE;
1291 }
1293 # if(isset($_POST['create_acls_create_confirmed'])){
1294 # if($this->create_admin()){
1295 # $this->acl_create_dialog = FALSE;
1296 # $this->dialog = FALSE;
1297 # $this->show_details = FALSE;
1298 # $this->initialize_checks();
1299 # }
1300 # }
1302 if(isset($_POST['create_acls_create'])){
1303 $this->create_admin(TRUE);
1304 }
1306 if(isset($_POST['create_admin_user'])){
1307 if($this->create_admin_user()){
1308 $this->dialog = FALSE;
1309 $this->show_details = FALSE;
1310 }
1311 }
1313 if($this->acl_create_dialog){
1314 $smarty = get_smarty();
1316 $uid = "admin";
1317 if(isset($_POST['new_user_uid'])){
1318 $uid = $_POST['new_user_uid'];
1319 }
1321 $smarty->assign("new_user_uid",$uid);
1322 $smarty->assign("new_user_password",@$_POST['new_user_password']);
1323 $smarty->assign("new_user_password2",@$_POST['new_user_password2']);
1324 $smarty->assign("method","create_acls");
1325 $smarty->assign("acl_create_selected",$this->acl_create_selected);
1326 $smarty->assign("what_will_be_done_now",$this->acl_create_changes);
1327 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1328 }
1330 /*************
1331 * User Migration handling
1332 *************/
1334 /* Refresh list of deparments */
1335 if(isset($_POST['users_visible_migrate_refresh'])){
1336 $this->check_gosaAccounts();
1337 }
1339 /* Open migration dialog */
1340 if(isset($_POST['users_visible_migrate'])){
1341 $this->show_details= FALSE;
1342 $this->users_migration_dialog = TRUE;
1343 $this->dialog =TRUE;
1344 }
1346 /* Close migration dialog */
1347 if(isset($_POST['users_visible_migrate_close'])){
1348 $this->users_migration_dialog = FALSE;
1349 $this->dialog =FALSE;
1350 $this->show_details = FALSE;
1351 }
1353 /* Start migration */
1354 if(isset($_POST['users_visible_migrate_migrate'])){
1355 if($this->migrate_gosaAccounts()){
1356 $this->initialize_checks();
1357 $this->dialog = FALSE;
1358 $this->show_details = FALSE;
1359 $this->users_migration_dialog = FALSE;
1360 }
1361 }
1363 /* Start migration */
1364 if(isset($_POST['users_visible_migrate_whatsdone'])){
1365 $this->migrate_gosaAccounts(TRUE);
1366 }
1368 /* Display migration dialog */
1369 if($this->users_migration_dialog){
1370 $smarty = get_smarty();
1371 $smarty->assign("users_to_migrate",$this->users_to_migrate);
1372 $smarty->assign("method","migrate_users");
1373 $smarty->assign("user_details", $this->show_details);
1374 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1375 }
1378 /*************
1379 * Department Migration handling
1380 *************/
1382 /* Refresh list of deparments */
1383 if(isset($_POST['deps_visible_migrate_refresh'])){
1384 $this->check_organizationalUnits();
1385 $this->show_details= FALSE;
1386 }
1388 /* Open migration dialog */
1389 if(isset($_POST['deps_visible_migrate'])){
1390 $this->dep_migration_dialog = TRUE;
1391 $this->dialog =TRUE;
1392 }
1394 /* Close migration dialog */
1395 if(isset($_POST['deps_visible_migrate_close'])){
1396 $this->dep_migration_dialog = FALSE;
1397 $this->dialog =FALSE;
1398 $this->show_details = FALSE;
1399 }
1401 /* Start migration */
1402 if(isset($_POST['deps_visible_migrate_migrate'])){
1403 if($this->migrate_organizationalUnits()){
1404 $this->show_details= FALSE;
1405 $this->check_organizationalUnits();
1406 $this->dialog = FALSE;
1407 $this->dep_migration_dialog = FALSE;
1408 }
1409 }
1411 /* Start migration */
1412 if(isset($_POST['deps_visible_migrate_whatsdone'])){
1413 $this->migrate_organizationalUnits(TRUE);
1414 }
1416 /* Display migration dialog */
1417 if($this->dep_migration_dialog){
1418 $smarty = get_smarty();
1419 $smarty->assign("deps_to_migrate",$this->deps_to_migrate);
1420 $smarty->assign("method","migrate_deps");
1421 $smarty->assign("deps_details", $this->show_details);
1422 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1423 }
1425 $smarty = get_smarty();
1426 $smarty->assign("checks",$this->checks);
1427 $smarty->assign("method","default");
1428 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1429 }
1432 function save_object()
1433 {
1434 $this->is_completed= TRUE;
1436 /* Capture all selected winstations from outside_winstations_dialog */
1437 if($this->outside_winstations_dialog){
1438 foreach($this->outside_winstations as $dn => $data){
1439 if(isset($_POST['select_winstation_'.$dn])){
1440 $this->outside_winstations[$dn]['selected'] = TRUE;
1441 }else{
1442 $this->outside_winstations[$dn]['selected'] = FALSE;
1443 }
1444 }
1445 }
1447 /* Capture all selected groups from outside_groups_dialog */
1448 if($this->outside_groups_dialog){
1449 foreach($this->outside_groups as $dn => $data){
1450 if(isset($_POST['select_group_'.$dn])){
1451 $this->outside_groups[$dn]['selected'] = TRUE;
1452 }else{
1453 $this->outside_groups[$dn]['selected'] = FALSE;
1454 }
1455 }
1456 }
1458 /* Capture all selected users from outside_users_dialog */
1459 if($this->outside_users_dialog){
1460 foreach($this->outside_users as $dn => $data){
1461 if(isset($_POST['select_user_'.$dn])){
1462 $this->outside_users[$dn]['selected'] = TRUE;
1463 }else{
1464 $this->outside_users[$dn]['selected'] = FALSE;
1465 }
1466 }
1467 }
1469 /* Get "create acl" dialog posts */
1470 if($this->acl_create_dialog){
1472 if(isset($_POST['create_acls_create_abort'])){
1473 $this->acl_create_selected = "";
1474 }
1475 }
1477 /* Get selected departments */
1478 if($this->dep_migration_dialog){
1479 foreach($this->deps_to_migrate as $id => $data){
1480 if(isset($_POST['migrate_'.$id])){
1481 $this->deps_to_migrate[$id]['checked'] = TRUE;
1482 }else{
1483 $this->deps_to_migrate[$id]['checked'] = FALSE;
1484 }
1485 }
1486 }
1488 /* Get selected users */
1489 if($this->users_migration_dialog){
1490 foreach($this->users_to_migrate as $id => $data){
1491 if(isset($_POST['migrate_'.$id])){
1492 $this->users_to_migrate[$id]['checked'] = TRUE;
1493 }else{
1494 $this->users_to_migrate[$id]['checked'] = FALSE;
1495 }
1496 }
1497 }
1498 }
1501 /* Check if the root object exists.
1502 * If the parameter just_check is true, then just check if the
1503 * root object is missing and update the info messages.
1504 * If the Parameter is false, try to create a new root object.
1505 */
1506 function checkBase($just_check = TRUE)
1507 {
1508 /* Get collected setup informations */
1509 $cv = $this->parent->captured_values;
1511 /* Establish ldap connection */
1512 $ldap = new LDAP($cv['admin'],
1513 $cv['password'],
1514 $cv['connection'],
1515 FALSE,
1516 $cv['tls']);
1518 /* Check if root object exists */
1519 $ldap->cd($cv['base']);
1520 $res = $ldap->search("(objectClass=*)");
1521 $err = ldap_errno($ldap->cid);
1523 if( !$res ||
1524 $err == 0x20 || # LDAP_NO_SUCH_OBJECT
1525 $err == 0x40) { # LDAP_NAMING_VIOLATION
1527 /* Root object doesn't exists
1528 */
1529 if($just_check){
1530 $this->checks['root']['STATUS'] = FALSE;
1531 $this->checks['root']['STATUS_MSG']= _("Failed");
1532 $this->checks['root']['ERROR_MSG'] = _("The LDAP root object is missing. It is required to use your LDAP service.").' ';
1533 $this->checks['root']['ERROR_MSG'].= "<input type='submit' name='retry_root_create' value='"._("Try to create root object")."'>";
1534 return(FALSE);
1535 }else{
1537 /* Add root object */
1538 $ldap->cd($cv['base']);
1539 $res = $ldap->create_missing_trees($cv['base']);
1541 /* If adding failed, tell the user */
1542 if(!$res){
1543 $this->checks['root']['STATUS'] = FALSE;
1544 $this->checks['root']['STATUS_MSG']= _("Failed");
1545 $this->checks['root']['ERROR_MSG'] = _("Root object couldn't be created, you should try it on your own.");
1546 $this->checks['root']['ERROR_MSG'].= " <input type='submit' name='retry_root_create' value='"._("Try to create root object")."'>";
1547 return($res);;
1548 }
1549 }
1550 }
1552 /* Create & remove of dummy object was successful */
1553 $this->checks['root']['STATUS'] = TRUE;
1554 $this->checks['root']['STATUS_MSG']= _("Ok");
1555 }
1558 /* Return ldif information for a
1559 * given attribute array
1560 */
1561 function array_to_ldif($atts)
1562 {
1563 $ret = "";
1564 unset($atts['count']);
1565 unset($atts['dn']);
1566 foreach($atts as $name => $value){
1567 if(is_numeric($name)) {
1568 continue;
1569 }
1570 if(is_array($value)){
1571 unset($value['count']);
1572 foreach($value as $a_val){
1573 $ret .= $name.": ". $a_val."\n";
1574 }
1575 }else{
1576 $ret .= $name.": ". $value."\n";
1577 }
1578 }
1579 return(preg_replace("/\n$/","",$ret));
1580 }
1583 function get_user_list()
1584 {
1585 /* Get collected configuration settings */
1586 $cv = $this->parent->captured_values;
1588 /* Establish ldap connection */
1589 $ldap = new LDAP($cv['admin'],
1590 $cv['password'],
1591 $cv['connection'],
1592 FALSE,
1593 $cv['tls']);
1595 $ldap->cd($cv['base']);
1596 $ldap->search("(objectClass=gosaAccount)",array("dn"));
1598 $tmp = array();
1599 while($attrs = $ldap->fetch()){
1600 $tmp[base64_encode($attrs['dn'])] = @LDAP::fix($attrs['dn']);
1601 }
1602 return($tmp);
1603 }
1606 function get_all_people_ous()
1607 {
1608 /* Get collected configuration settings */
1609 $cv = $this->parent->captured_values;
1611 /* Establish ldap connection */
1612 $ldap = new LDAP($cv['admin'],
1613 $cv['password'],
1614 $cv['connection'],
1615 FALSE,
1616 $cv['tls']);
1618 $ldap->cd($cv['base']);
1619 $ldap->search("(".$cv['peopleou'].")",array("dn"));
1621 if($ldap->count() == 0 ){
1622 $add_dn = $cv['peopleou'].",".$cv['base'];
1623 $naming_attr = preg_replace("/=.*$/","",$add_dn);
1624 $naming_value = preg_replace("/^[^=]*+=([^,]*).*$/","\\1",$add_dn);
1625 $add = array();
1626 $add['objectClass'] = array("organizationalUnit");
1627 $add[$naming_attr] = $naming_value;
1629 $ldap->cd($cv['base']);
1630 $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$add_dn));
1631 $ldap->cd($add_dn);
1632 $ldap->add($add);
1633 }
1635 $ldap->search("(".$cv['peopleou'].")",array("dn"));
1636 $tmp = array();
1637 while($attrs= $ldap->fetch()){
1638 if(!preg_match("/ou=snapshots,/",$attrs['dn'])){
1639 $tmp[base64_encode($attrs['dn'])] = $ldap->fix($attrs['dn']);
1640 }
1641 }
1642 return($tmp);
1643 }
1645 function get_all_winstation_ous()
1646 {
1647 /* Get collected configuration settings */
1648 $cv = $this->parent->captured_values;
1650 /* Establish ldap connection */
1651 $ldap = new LDAP($cv['admin'],
1652 $cv['password'],
1653 $cv['connection'],
1654 FALSE,
1655 $cv['tls']);
1657 /* Get winstation ou */
1658 if($cv['generic_settings']['wws_ou_active']) {
1659 $winstation_ou = $cv['generic_settings']['ws_ou'];
1660 }else{
1661 $winstation_ou = "ou=winstations";
1662 }
1664 $ldap->cd($cv['base']);
1665 $ldap->search("(".$winstation_ou.")",array("dn"));
1667 if($ldap->count() == 0 ){
1668 $add_dn = $winstation_ou.",ou=systems,".$cv['base'];
1669 $naming_attr = preg_replace("/=.*$/","",$add_dn);
1670 $naming_value = preg_replace("/^[^=]*+=([^,]*).*$/","\\1",$add_dn);
1671 $add = array();
1672 $add['objectClass'] = array("organizationalUnit");
1673 $add[$naming_attr] = $naming_value;
1675 $ldap->cd($cv['base']);
1676 $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$add_dn));
1677 $ldap->cd($add_dn);
1678 $ldap->add($add);
1679 }
1681 $ldap->search("(".$winstation_ou.")",array("dn"));
1682 $tmp = array();
1683 while($attrs= $ldap->fetch()){
1684 if(!preg_match("/ou=snapshots,/",$attrs['dn'])){
1685 $tmp[base64_encode($attrs['dn'])] = $ldap->fix($attrs['dn']);
1686 }
1687 }
1688 return($tmp);
1689 }
1692 function get_all_group_ous()
1693 {
1694 /* Get collected configuration settings */
1695 $cv = $this->parent->captured_values;
1697 /* Establish ldap connection */
1698 $ldap = new LDAP($cv['admin'],
1699 $cv['password'],
1700 $cv['connection'],
1701 FALSE,
1702 $cv['tls']);
1704 $ldap->cd($cv['base']);
1705 $ldap->search("(".$cv['groupou'].")",array("dn"));
1707 if($ldap->count() == 0 ){
1708 $add_dn = $cv['groupou'].",".$cv['base'];
1709 $naming_attr = preg_replace("/=.*$/","",$add_dn);
1710 $naming_value = preg_replace("/^[^=]*+=([^,]*).*$/","\\1",$add_dn);
1711 $add = array();
1712 $add['objectClass'] = array("organizationalUnit");
1713 $add[$naming_attr] = $naming_value;
1715 $ldap->cd($cv['base']);
1716 $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$add_dn));
1717 $ldap->cd($add_dn);
1718 $ldap->add($add);
1719 }
1721 $ldap->search("(".$cv['groupou'].")",array("dn"));
1722 $tmp = array();
1723 while($attrs= $ldap->fetch()){
1724 if(!preg_match("/ou=snapshots,/",$attrs['dn'])){
1725 $tmp[base64_encode($attrs['dn'])] = $ldap->fix($attrs['dn']);
1726 }
1727 }
1728 return($tmp);
1729 }
1732 function get_group_list()
1733 {
1734 /* Get collected configuration settings */
1735 $cv = $this->parent->captured_values;
1737 /* Establish ldap connection */
1738 $ldap = new LDAP($cv['admin'],
1739 $cv['password'],
1740 $cv['connection'],
1741 FALSE,
1742 $cv['tls']);
1744 $ldap->cd($cv['base']);
1745 $ldap->search("(objectClass=posixGroup)",array("dn"));
1747 $tmp = array();
1748 while($attrs = $ldap->fetch()){
1749 $tmp[base64_encode($attrs['dn'])] = @LDAP::fix($attrs['dn']);
1750 }
1751 return($tmp);
1752 }
1755 function move($source,$destination)
1756 {
1757 /* Get collected configuration settings */
1758 $cv = $this->parent->captured_values;
1760 /* Establish ldap connection */
1761 $ldap = new LDAP($cv['admin'],
1762 $cv['password'],
1763 $cv['connection'],
1764 FALSE,
1765 $cv['tls']);
1767 /* Update object references in gosaGroupOfNames */
1768 $ogs_to_fix = array();
1769 $ldap->cd($cv['base']);
1770 $ldap->search('(&(objectClass=gosaGroupOfNames)(member='.@LDAP::fix($source).'))', array('cn','member'));
1771 while ($attrs= $ldap->fetch()){
1772 $dn = $attrs['dn'];
1773 $attrs = $this->cleanup_array($attrs);
1774 $member_new = array($destination);
1775 foreach($attrs['member'] as $member){
1776 if($member != $source){
1777 $member_new[] = $member;
1778 }
1779 }
1780 $attrs['member'] = $member_new;
1781 $ogs_to_fix[$dn] = $attrs;
1782 }
1784 /* Copy source to destination dn */
1785 $ldap->cat($source);
1786 $new_data = $this->cleanup_array($ldap->fetch());
1787 $ldap->cd($destination);
1788 $res = $ldap->add($new_data);
1790 /* Display warning if copy failed */
1791 if(!$res){
1792 print_red(_("Failed to copy '%s' to '%s'. LDAP says '%s'."),$source,$destination,$ldap->get_error());
1793 }else{
1794 $res = $ldap->rmDir($source);
1795 show_ldap_error($ldap->get_error(),_("Something went wrong while copying dns."));
1797 /* Object is copied, so update its references */
1798 foreach($ogs_to_fix as $dn => $data){
1799 $ldap->cd($dn);
1800 $ldap->modify($data);
1801 }
1802 }
1803 }
1806 /* Cleanup ldap result to be able to write it be to ldap */
1807 function cleanup_array($attrs)
1808 {
1809 foreach($attrs as $key => $value) {
1810 if(is_numeric($key) || in_array($key,array("count","dn"))){
1811 unset($attrs[$key]);
1812 }
1813 if(is_array($value) && isset($value['count'])){
1814 unset($attrs[$key]['count']);
1815 }
1816 }
1817 return($attrs);
1818 }
1819 }
1821 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1822 ?>