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();
63 /* Department migration attributes */
64 var $users_migration_dialog= FALSE;
65 var $users_to_migrate = array();
67 /* Create Acl attributes */
68 var $acl_create_dialog = FALSE;
69 var $acl_create_type = "group";
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 user");
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 administrational account");
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 department.");
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 department.");
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 department.");
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 multiple use of same uidNumber value.");
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 multiple use of same gidNumber value.");
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 function check_uidNumber()
176 {
177 $cv = $this->parent->captured_values;
178 $ldap = new LDAP($cv['admin'],
179 $cv['password'],
180 $cv['connection'],
181 FALSE,
182 $cv['tls']);
184 $ldap->cd($cv['base']);
185 $res = $ldap->search("uidNumber=*",array("dn","uidNumber"));
186 if(!$res){
187 $this->checks['uidNumber_usage']['STATUS'] = FALSE;
188 $this->checks['uidNumber_usage']['STATUS_MSG']= _("Ldap query failed.");
189 $this->checks['uidNumber_usage']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
190 return(false);
191 }
193 $this->check_uidNumbers= array();
194 $tmp = array();
195 while($attrs = $ldap->fetch()){
196 $tmp[$attrs['uidNumber'][0]][] = $attrs;
197 }
199 foreach($tmp as $id => $entries){
200 if(count($entries) > 1){
201 foreach($entries as $entry){
202 $this->check_uidNumbers[base64_encode($entry['dn'])] = $entry;
203 }
204 }
205 }
207 if($this->check_uidNumbers){
208 $this->checks['uidNumber_usage']['STATUS'] = FALSE;
209 $this->checks['uidNumber_usage']['STATUS_MSG']= _("Failed");
210 $this->checks['uidNumber_usage']['ERROR_MSG'] =
211 sprintf(_("Found %s duplicated uidNumber values."),count($this->check_uidNumbers));
212 return(false);
213 }else{
214 $this->checks['uidNumber_usage']['STATUS'] = TRUE;
215 $this->checks['uidNumber_usage']['STATUS_MSG']= _("Ok");
216 $this->checks['uidNumber_usage']['ERROR_MSG'] = "";
217 return(TRUE);
218 }
219 }
221 function check_gidNumber()
222 {
223 $cv = $this->parent->captured_values;
224 $ldap = new LDAP($cv['admin'],
225 $cv['password'],
226 $cv['connection'],
227 FALSE,
228 $cv['tls']);
230 $ldap->cd($cv['base']);
231 $res = $ldap->search("gidNumber=*",array("dn","gidNumber"));
232 if(!$res){
233 $this->checks['gidNumber_usage']['STATUS'] = FALSE;
234 $this->checks['gidNumber_usage']['STATUS_MSG']= _("Ldap query failed.");
235 $this->checks['gidNumber_usage']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
236 return(false);
237 }
239 $this->check_gidNumbers= array();
240 $tmp = array();
241 while($attrs = $ldap->fetch()){
242 $tmp[$attrs['gidNumber'][0]][] = $attrs;
243 }
245 foreach($tmp as $id => $entries){
246 if(count($entries) > 1){
247 foreach($entries as $entry){
248 $this->check_gidNumbers[base64_encode($entry['dn'])] = $entry;
249 }
250 }
251 }
253 if($this->check_gidNumbers){
254 $this->checks['gidNumber_usage']['STATUS'] = FALSE;
255 $this->checks['gidNumber_usage']['STATUS_MSG']= _("Failed");
256 $this->checks['gidNumber_usage']['ERROR_MSG'] =
257 sprintf(_("Found %s duplicated gidNumber values."),count($this->check_gidNumbers));
258 return(false);
259 }else{
260 $this->checks['gidNumber_usage']['STATUS'] = TRUE;
261 $this->checks['gidNumber_usage']['STATUS_MSG']= _("Ok");
262 $this->checks['gidNumber_usage']['ERROR_MSG'] = "";
263 return(TRUE);
264 }
265 }
268 /* Search for winstations outside the winstation ou */
269 function search_outside_winstations()
270 {
271 $cv = $this->parent->captured_values;
272 $ldap = new LDAP($cv['admin'],
273 $cv['password'],
274 $cv['connection'],
275 FALSE,
276 $cv['tls']);
280 /* Get winstation ou */
281 if($cv['generic_settings']['wws_ou_active']) {
282 $winstation_ou = $cv['generic_settings']['ws_ou'];
283 }else{
284 $winstation_ou = "ou=winstations";
285 }
287 if($cv['samba_version'] == 3){
288 $oc = "sambaSamAccount";
289 }else{
290 $oc = "sambaAccount";
291 }
293 $ldap->cd($cv['base']);
294 $res = $ldap->search("(&(objectClass=".$oc.")(uid=*$))",array("dn","sambaSID"));
295 if(!$res){
296 $this->checks['outside_winstations']['STATUS'] = FALSE;
297 $this->checks['outside_winstations']['STATUS_MSG']= _("Ldap query failed.");
298 $this->checks['outside_winstations']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
299 return(false);
300 }
302 $this->outside_winstations = array();
303 while($attrs = $ldap->fetch()){
304 if((!preg_match("/^[^,]+,".normalizePreg($winstation_ou)."/",$attrs['dn'])) && !preg_match("/,dc=addressbook,/",$attrs['dn'])){
305 $attrs['selected'] = FALSE;
306 $attrs['ldif'] = "";
307 $this->outside_winstations[base64_encode($attrs['dn'])] = $attrs;
308 }
309 }
311 if(count($this->outside_winstations)){
312 $this->checks['outside_winstations']['STATUS'] = FALSE;
313 $this->checks['outside_winstations']['STATUS_MSG']= _("Failed");
314 $this->checks['outside_winstations']['ERROR_MSG'] =
315 sprintf(_("Found %s winstations outside the predefined winstation department ou '%s'."),count($this->outside_winstations),$winstation_ou);
316 $this->checks['outside_winstations']['ERROR_MSG'].= "<input type='submit' name='outside_winstations_dialog' value='"._("Migrate")."'>";
317 return(false);
318 }else{
319 $this->checks['outside_winstations']['STATUS'] = TRUE;
320 $this->checks['outside_winstations']['STATUS_MSG']= _("Ok");
321 $this->checks['outside_winstations']['ERROR_MSG'] = "";
322 return(TRUE);
323 }
324 }
327 /* Search for groups outside the group ou */
328 function search_outside_groups()
329 {
330 $cv = $this->parent->captured_values;
331 $ldap = new LDAP($cv['admin'],
332 $cv['password'],
333 $cv['connection'],
334 FALSE,
335 $cv['tls']);
337 $group_ou = $cv['groupou'];
338 $ldap->cd($cv['base']);
339 $res = $ldap->search("(objectClass=posixGroup)",array("dn"));
340 if(!$res){
341 $this->checks['outside_groups']['STATUS'] = FALSE;
342 $this->checks['outside_groups']['STATUS_MSG']= _("Ldap query failed.");
343 $this->checks['outside_groups']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
344 return(false);
345 }
348 $this->outside_groups = array();
349 while($attrs = $ldap->fetch()){
350 if((!preg_match("/^[^,]+,".normalizePreg($group_ou)."/",$attrs['dn'])) && !preg_match("/,dc=addressbook,/",$attrs['dn'])){
351 $attrs['selected'] = FALSE;
352 $attrs['ldif'] = "";
353 $this->outside_groups[base64_encode($attrs['dn'])] = $attrs;
354 }
355 }
357 if(count($this->outside_groups)){
358 $this->checks['outside_groups']['STATUS'] = FALSE;
359 $this->checks['outside_groups']['STATUS_MSG']= _("Failed");
360 $this->checks['outside_groups']['ERROR_MSG'] =
361 sprintf(_("Found %s groups outside the selected group ou '%s'."),count($this->outside_groups),$group_ou);
362 $this->checks['outside_groups']['ERROR_MSG'].= "<input type='submit' name='outside_groups_dialog' value='"._("Migrate")."'>";
363 return(false);
364 }else{
365 $this->checks['outside_groups']['STATUS'] = TRUE;
366 $this->checks['outside_groups']['STATUS_MSG']= _("Ok");
367 $this->checks['outside_groups']['ERROR_MSG'] = "";
368 return(TRUE);
369 }
370 }
372 /* Search for users outside the people ou */
373 function search_outside_users()
374 {
375 $cv = $this->parent->captured_values;
376 $ldap = new LDAP($cv['admin'],
377 $cv['password'],
378 $cv['connection'],
379 FALSE,
380 $cv['tls']);
381 $people_ou = $cv['peopleou'];
382 $ldap->cd($cv['base']);
383 $res = $ldap->search("(&(objectClass=gosaAccount)(!(uid=*$)))",array("dn"));
384 if(!$res){
385 $this->checks['outside_users']['STATUS'] = FALSE;
386 $this->checks['outside_users']['STATUS_MSG']= _("Ldap query failed.");
387 $this->checks['outside_users']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
388 return(false);
389 }
392 $this->outside_users = array();
393 while($attrs = $ldap->fetch()){
394 if((!preg_match("/^[^,]+,".normalizePreg($people_ou)."/",$attrs['dn']) && !preg_match("/,dc=addressbook,/",$attrs['dn']))){
395 $attrs['selected'] = FALSE;
396 $attrs['ldif'] = "";
397 $this->outside_users[base64_encode($attrs['dn'])] = $attrs;
398 }
399 }
401 if(count($this->outside_users)){
402 $this->checks['outside_users']['STATUS'] = FALSE;
403 $this->checks['outside_users']['STATUS_MSG']= _("Failed");
404 $this->checks['outside_users']['ERROR_MSG'] =
405 sprintf(_("Found %s users outside the selected user ou '%s'."),count($this->outside_users),$people_ou);
406 $this->checks['outside_users']['ERROR_MSG'].= "<input type='submit' name='outside_users_dialog' value='"._("Migrate")."'>";
407 return(false);
408 }else{
409 $this->checks['outside_users']['STATUS'] = TRUE;
410 $this->checks['outside_users']['STATUS_MSG']= _("Ok");
411 $this->checks['outside_users']['ERROR_MSG'] = "";
412 return(TRUE);
413 }
414 }
417 /* Check ldap accessibility
418 * Create and remove a dummy object,
419 * to ensure that we have the necessary permissions
420 */
421 function check_ldap_permissions()
422 {
423 $cv = $this->parent->captured_values;
424 $ldap = new LDAP($cv['admin'],
425 $cv['password'],
426 $cv['connection'],
427 FALSE,
428 $cv['tls']);
430 /* Create dummy entry
431 */
432 $name = "GOsa_setup_text_entry_".session_id().rand(0,999999);
433 $dn = "ou=".$name.",".$cv['base'];
434 $testEntry= array();
435 $testEntry['objectClass'][]= "top";
436 $testEntry['objectClass'][]= "organizationalUnit";
437 $testEntry['objectClass'][]= "gosaDepartment";
438 $testEntry['description']= "Created by GOsa setup, this object can be removed.";
439 $testEntry['ou'] = $name;
441 /* check if simple ldap cat will be successful
442 */
443 $res = $ldap->cat($cv['base']);
444 if(!$res){
445 $this->checks['permissions']['STATUS'] = FALSE;
446 $this->checks['permissions']['STATUS_MSG']= _("Ldap query failed.");
447 $this->checks['permissions']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
448 return(false);
449 }
451 /* Try to create dummy object
452 */
453 $ldap->cd ($dn);
454 $ldap->create_missing_trees($dn);
455 $res = $ldap->add($testEntry);
456 $ldap->cat($dn);
457 if(!$ldap->count()){
458 gosa_log($ldap->get_error());
459 $this->checks['permissions']['STATUS'] = FALSE;
460 $this->checks['permissions']['STATUS_MSG']= _("Failed");
461 $this->checks['permissions']['ERROR_MSG'] =
462 sprintf(_("The specified user '%s' does not have full access to your ldap database."),$cv['admin']);
463 return(false);
464 }
466 /* Try to remove created entry
467 */
468 $res = $ldap->rmDir($dn);
469 $ldap->cat($dn);
470 if($ldap->count()){
471 gosa_log($ldap->get_error());
472 $this->checks['permissions']['STATUS'] = FALSE;
473 $this->checks['permissions']['STATUS_MSG']= _("Failed");
474 $this->checks['permissions']['ERROR_MSG'] =
475 sprintf(_("The specified user '%s' does not have full access to your ldap database."),$cv['admin']);
476 return(false);
477 }
479 /* Create & remove of dummy object was successful */
480 $this->checks['permissions']['STATUS'] = TRUE;
481 $this->checks['permissions']['STATUS_MSG']= _("Ok");
482 $this->checks['permissions']['ERROR_MSG'] = "";
483 return(true);
484 }
487 /* Check if there are users which will
488 * be invisible for GOsa
489 */
490 function check_gosaAccounts()
491 {
492 /* Remember old list of ivisible users, to be able to set
493 * the 'html checked' status for the checkboxes again
494 */
495 $cnt_ok = 0;
496 $old = $this->users_to_migrate;
497 $this->users_to_migrate = array();
499 /* Get collected configuration settings */
500 $cv = $this->parent->captured_values;
502 /* Establish ldap connection */
503 $ldap = new LDAP($cv['admin'],
504 $cv['password'],
505 $cv['connection'],
506 FALSE,
507 $cv['tls']);
509 /* Get all invisible users
510 */
511 $ldap->cd($cv['base']);
512 $res =$ldap->search("(&(|(objectClass=posixAccount)(objectClass=inetOrgPerson)(objectClass=organizationalPerson))(!(objectClass=gosaAccount)))",array("sn","givenName","cn","uid"));
513 while($attrs = $ldap->fetch()){
514 if(!preg_match("/,dc=addressbook,/",$attrs['dn'])){
515 $attrs['checked'] = FALSE;
516 $attrs['before'] = "";
517 $attrs['after'] = "";
519 /* Set objects to selected, that were selected before reload */
520 if(isset($old[base64_encode($attrs['dn'])])){
521 $attrs['checked'] = $old[base64_encode($attrs['dn'])]['checked'];
522 }
523 $this->users_to_migrate[base64_encode($attrs['dn'])] = $attrs;
524 }
525 }
527 /* No invisible */
528 if(!$res){
529 $this->checks['users_visible']['STATUS'] = FALSE;
530 $this->checks['users_visible']['STATUS_MSG']= _("Ldap query failed.");
531 $this->checks['users_visible']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
532 }elseif(count($this->users_to_migrate) == 0){
533 $this->checks['users_visible']['STATUS'] = TRUE;
534 $this->checks['users_visible']['STATUS_MSG']= _("Ok");
535 $this->checks['users_visible']['ERROR_MSG'] = "";
536 }else{
537 $this->checks['users_visible']['STATUS'] = FALSE;
538 $this->checks['users_visible']['STATUS_MSG']= "";
539 $this->checks['users_visible']['ERROR_MSG'] = sprintf(_("Found %s users that will not be visible in GOsa."),
540 count($this->users_to_migrate));
541 $this->checks['users_visible']['ERROR_MSG'] .= "<input type='submit' name='users_visible_migrate' value='"._("Migrate")."'>";
542 }
543 }
546 /* Start user account migration
547 */
548 function migrate_gosaAccounts($only_ldif = FALSE)
549 {
550 /* Get collected configuration settings */
551 $cv = $this->parent->captured_values;
553 /* Establish ldap connection */
554 $ldap = new LDAP($cv['admin'],
555 $cv['password'],
556 $cv['connection'],
557 FALSE,
558 $cv['tls']);
560 /* Add gosaAccount objectClass to the selected users
561 */
562 foreach($this->users_to_migrate as $key => $dep){
563 if($dep['checked']){
565 /* Get old objectClasses */
566 $ldap->cat($dep['dn'],array("objectClass"));
567 $attrs = $ldap->fetch();
569 /* Create new objectClass array */
570 $new_attrs = array();
571 $new_attrs['objectClass']= array("gosaAccount","inetOrgPerson","organizationalPerson");
572 for($i = 0 ; $i < $attrs['objectClass']['count']; $i ++ ){
573 if(!in_array_ics($attrs['objectClass'][$i], $new_attrs['objectClass'])){
574 $new_attrs['objectClass'][] = $attrs['objectClass'][$i];
575 }
576 }
578 /* Set info attributes for current object,
579 * or write changes to the ldap database
580 */
581 if($only_ldif){
582 $this->users_to_migrate[$key]['before'] = $this->array_to_ldif($attrs);
583 $this->users_to_migrate[$key]['after'] = $this->array_to_ldif($new_attrs);
584 }else{
585 $ldap->cd($attrs['dn']);
586 if(!$ldap->modify($new_attrs)){
587 print_red(sprintf(_("Failed to migrate the department '%s' into GOsa, error message is as follows '%s'."),$attrs['dn'],$ldap->get_error()));
588 return(false);
589 }
590 }
591 }
592 }
593 return(TRUE);
594 }
597 /* Check if there are invisible organizational Units
598 */
599 function check_organizationalUnits()
600 {
601 $cnt_ok = 0;
602 $old = $this->deps_to_migrate;
603 $this->deps_to_migrate = array();
605 /* Get collected configuration settings */
606 $cv = $this->parent->captured_values;
608 /* Establish ldap connection */
609 $ldap = new LDAP($cv['admin'],
610 $cv['password'],
611 $cv['connection'],
612 FALSE,
613 $cv['tls']);
615 /* Skip GOsa internal departments */
616 $skip_dns = array("/^ou=people,/","/^ou=groups,/","/(,|)ou=configs,/","/(,|)ou=systems,/",
617 "/^ou=apps,/","/^ou=mime,/","/^ou=aclroles,/","/^ou=incoming,/",
618 "/ou=snapshots,/","/(,|)dc=addressbook,/","/^(,|)ou=machineaccounts,/",
619 "/(,|)ou=winstations,/");
622 /* Get all invisible departments */
623 $ldap->cd($cv['base']);
624 $res = $ldap->search("(&(objectClass=organizationalUnit)(!(objectClass=gosaDepartment)))",array("ou","description","dn"));
625 while($attrs = $ldap->fetch()){
626 $attrs['checked'] = FALSE;
627 $attrs['before'] = "";
628 $attrs['after'] = "";
630 /* Set objects to selected, that were selected before reload */
631 if(isset($old[base64_encode($attrs['dn'])])){
632 $attrs['checked'] = $old[base64_encode($attrs['dn'])]['checked'];
633 }
634 $this->deps_to_migrate[base64_encode($attrs['dn'])] = $attrs;
635 }
637 /* Filter returned list of departments and ensure that
638 * GOsa internal departments will not be listed
639 */
640 foreach($this->deps_to_migrate as $key => $attrs){
641 $dn = $attrs['dn'];
642 $skip = false;
643 foreach($skip_dns as $skip_dn){
644 if(preg_match($skip_dn,$dn)){
645 $skip = true;
646 }
647 }
648 if($skip){
649 unset($this->deps_to_migrate[$key]);
650 }
651 }
653 /* If we have no invisible departments found
654 * tell the user that everything is ok
655 */
656 if(!$res){
657 $this->checks['deps_visible']['STATUS'] = FALSE;
658 $this->checks['deps_visible']['STATUS_MSG']= _("Ldap query failed.");
659 $this->checks['deps_visible']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
660 }elseif(count($this->deps_to_migrate) == 0 ){
661 $this->checks['deps_visible']['STATUS'] = TRUE;
662 $this->checks['deps_visible']['STATUS_MSG']= _("Ok");
663 $this->checks['deps_visible']['ERROR_MSG'] = "";
664 }else{
665 $this->checks['deps_visible']['STATUS'] = FALSE;
666 $this->checks['deps_visible']['STATUS_MSG']= "";//sprintf(_("%s entries found"),count($this->deps_to_migrate));
667 $this->checks['deps_visible']['ERROR_MSG'] = sprintf(_("Found %s departments that will not be visible in GOsa."),count($this->deps_to_migrate));
668 $this->checks['deps_visible']['ERROR_MSG'] .= "<input type='submit' name='deps_visible_migrate' value='"._("Migrate")."'>";
669 }
670 }
674 /* Start deparmtment migration */
675 function migrate_organizationalUnits($only_ldif = FALSE)
676 {
677 /* Get collected configuration settings */
678 $cv = $this->parent->captured_values;
680 /* Establish ldap connection */
681 $ldap = new LDAP($cv['admin'],
682 $cv['password'],
683 $cv['connection'],
684 FALSE,
685 $cv['tls']);
687 /* Add gosaDepartment objectClass to each selected entry
688 */
689 foreach($this->deps_to_migrate as $key => $dep){
690 if($dep['checked']){
692 /* Get current objectClasses */
693 $ldap->cat($dep['dn'],array("objectClass","description"));
694 $attrs = $ldap->fetch();
696 /* Create new objectClass attribute including gosaDepartment*/
697 $new_attrs = array();
698 for($i = 0 ; $i < $attrs['objectClass']['count']; $i ++ ){
699 $new_attrs['objectClass'][] = $attrs['objectClass'][$i];
700 }
701 $new_attrs['objectClass'][] = "gosaDepartment";
703 /* Append description it is missing */
704 if(!isset($attrs['description'])){
705 $new_attrs['description'][] = "GOsa department";
706 }
708 /* Depending on the parameter >only_diff< we save the changes as ldif
709 * or we write our changes directly to the ldap database
710 */
711 if($only_ldif){
712 $this->deps_to_migrate[$key]['before'] = $this->array_to_ldif($attrs);
713 $this->deps_to_migrate[$key]['after'] = $this->array_to_ldif($new_attrs);
714 }else{
715 $ldap->cd($attrs['dn']);
716 if(!$ldap->modify($new_attrs)){
717 print_red(sprintf(_("Failed to migrate the department '%s' into GOsa, error message is as follows '%s'."),$attrs['dn'],$ldap->get_error()));
718 return(false);
719 }
720 }
721 }
722 }
723 return(TRUE);
724 }
727 /* Check Acls if there is at least one object with acls defined
728 */
729 function check_administrativeAccount()
730 {
731 /* Establish ldap connection */
732 $cv = $this->parent->captured_values;
733 $ldap = new LDAP($cv['admin'],
734 $cv['password'],
735 $cv['connection'],
736 FALSE,
737 $cv['tls']);
739 /* Search for gosaAcls */
740 $ldap->cd($cv['base']);
741 $res = $ldap->search("(&(objectClass=gosaAccount)(|(objectClass=posixAccount)".
742 "(objectClass=inetOrgPerson)(objectClass=organizationalPerson)))");
743 if(!$res){
744 $this->checks['acls']['STATUS'] = FALSE;
745 $this->checks['acls']['STATUS_MSG']= _("Ldap query failed.");
746 $this->checks['acls']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
747 }elseif($ldap->count()){
748 $this->checks['acls']['STATUS'] = TRUE;
749 $this->checks['acls']['STATUS_MSG']= _("Ok");
750 }else{
751 $this->checks['acls']['STATUS'] = FALSE;
752 $this->checks['acls']['STATUS_MSG']= _("Failed");
753 $this->checks['acls']['ERROR_MSG'].= "<input type='submit' name='create_acls' value='"._("Create adminitrational account")."'>";
754 }
755 return($ldap->count()>=1);
756 }
760 function create_admin($only_ldif = FALSE)
761 {
762 /* Reset '' */
763 $this->acl_create_changes="";
765 /* Object that should receive admin acls */
766 $dn = $this->acl_create_selected;
768 /* Get collected configuration settings */
769 $cv = $this->parent->captured_values;
771 /* Establish ldap connection */
772 $ldap = new LDAP($cv['admin'],
773 $cv['password'],
774 $cv['connection'],
775 FALSE,
776 $cv['tls']);
778 /* Get current base attributes */
779 $ldap->cd($cv['base']);
780 $ldap->cat($cv['base'],array("dn","objectClass","gosaAclEntry"));
781 $attrs = $ldap->fetch();
783 /* Add acls for the selcted user to the base */
784 $attrs_new['objectClass'] = array("gosaACL");
786 for($i = 0; $i < $attrs['objectClass']['count']; $i ++){
787 if(!in_array_ics($attrs['objectClass'][$i],$attrs_new['objectClass'])){
788 $attrs_new['objectClass'][] = $attrs['objectClass'][$i];
789 }
790 }
792 $acl = "0:sub:".base64_encode($dn).":all;cmdrw";
793 $attrs_new['gosaAclEntry'][] = $acl;
794 if(isset($attrs['gosaAclEntry'])){
795 for($i = 0 ; $i < $attrs['gosaAclEntry']['count']; $i ++){
797 $prio = preg_replace("/[:].*$/","",$attrs['gosaAclEntry'][$i]);
798 $rest = preg_replace("/^[^:]/","",$attrs['gosaAclEntry'][$i]);
800 $data = ($prio+1).$rest;
801 $attrs_new['gosaAclEntry'][] = $data;
802 }
803 }
805 if($only_ldif){
806 $this->acl_create_changes ="\n".$cv['base']."\n";
807 $this->acl_create_changes.=$this->array_to_ldif($attrs)."\n";
808 $this->acl_create_changes.="\n".$cv['base']."\n";
809 $this->acl_create_changes.=$this->array_to_ldif($attrs_new);
810 }else{
812 $ldap->cd($cv['base']);
813 if(!$ldap->modify($attrs_new)){
814 print_red(sprintf(_("Adding acls for user '%s' failed, ldap says '%s'."),$dn,$ldap->get_error()));
815 }
816 }
817 }
820 function create_admin_user()
821 {
822 if(isset($_POST['new_user_password']) && !empty($_POST['new_user_password'])){
823 $pwd = $_POST['new_user_password'];
824 }else{
825 print_red(_("Please specify a valid password for the new GOsa admin user."));
826 return(FALSE);
827 }
829 /* Establish ldap connection */
830 $cv = $this->parent->captured_values;
831 $ldap = new LDAP($cv['admin'],
832 $cv['password'],
833 $cv['connection'],
834 FALSE,
835 $cv['tls']);
837 /* Get current base attributes */
838 $ldap->cd($cv['base']);
840 if($cv['peopledn'] == "cn"){
841 $dn = "cn=System Administrator,".$cv['peopleou'].",".$cv['base'];
842 }else{
843 $dn = "uid=admin,".$cv['peopleou'].",".$cv['base'];
844 }
846 $methods = @passwordMethod::get_available_methods_if_not_loaded();
847 $p_m = $methods[$cv['encryption']];
848 $p_c = new $p_m(array());
849 $hash = $p_c->generate_hash($pwd);
851 $new_user=array();
852 $new_user['objectClass']= array("top","person","gosaAccount","organizationalPerson","inetOrgPerson");
853 $new_user['givenName'] = "System";
854 $new_user['sn'] = "Administrator";
855 $new_user['cn'] = "System Administrator";
856 $new_user['uid'] = "admin";
857 $new_user['userPassword'] = $hash;
859 $ldap->cd($cv['base']);
860 $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$dn));
861 $ldap->cd($dn);
862 $res = $ldap->add($new_user);
863 $this->acl_create_selected = $dn;
864 $this->create_admin();
866 if(!$res){
867 print_red($ldap->get_error());
868 }
870 $this->acl_create_dialog=FALSE;
871 $this->check_administrativeAccount();
872 }
875 function migrate_outside_winstations($perform = FALSE)
876 {
877 /* Establish ldap connection */
878 $cv = $this->parent->captured_values;
879 $ldap = new LDAP($cv['admin'],
880 $cv['password'],
881 $cv['connection'],
882 FALSE,
883 $cv['tls']);
885 $ldap->cd($cv['base']);
887 /* Check if there was a destination department posted */
888 if(isset($_POST['move_winstation_to'])){
889 $destination_dep = $_POST['move_winstation_to'];
890 }else{
891 print_red(_("Couldn't move users to specified department."));
892 return(false);
893 }
895 foreach($this->outside_winstations as $b_dn => $data){
896 $this->outside_winstations[$b_dn]['ldif'] ="";
897 if($data['selected']){
898 $dn = base64_decode($b_dn);
899 $d_dn = preg_replace("/,.*$/",",".base64_decode($destination_dep),$dn);
900 if(!$perform){
901 $this->outside_winstations[$b_dn]['ldif'] = _("Winstation will be moved from").":<br>\t".$dn."<br>"._("to").":<br>\t".$d_dn;
904 /* Check if there are references to this object */
905 $ldap->search("(&(member=".$dn.")(|(objectClass=gosaGroupOfNames)(objectClass=groupOfNames)))",array('dn'));
906 $refs = "";
907 while($attrs = $ldap->fetch()){
908 $ref_dn = $attrs['dn'];
909 $refs .= "<br />\t".$ref_dn;
910 }
911 if(!empty($refs)){
912 $this->outside_winstations[$b_dn]['ldif'] .= "<br /><br /><i>"._("Updating following references too").":</i>".$refs;
913 }
915 }else{
916 $this->move($dn,$d_dn);
917 }
918 }
919 }
920 }
923 function migrate_outside_groups($perform = FALSE)
924 {
925 /* Establish ldap connection */
926 $cv = $this->parent->captured_values;
927 $ldap = new LDAP($cv['admin'],
928 $cv['password'],
929 $cv['connection'],
930 FALSE,
931 $cv['tls']);
933 $ldap->cd($cv['base']);
935 /* Check if there was a destination department posted */
936 if(isset($_POST['move_group_to'])){
937 $destination_dep = $_POST['move_group_to'];
938 }else{
939 print_red(_("Couldn't move users to specified department."));
940 return(false);
941 }
943 foreach($this->outside_groups as $b_dn => $data){
944 $this->outside_groups[$b_dn]['ldif'] ="";
945 if($data['selected']){
946 $dn = base64_decode($b_dn);
947 $d_dn = preg_replace("/,.*$/",",".base64_decode($destination_dep),$dn);
948 if(!$perform){
949 $this->outside_groups[$b_dn]['ldif'] = _("Group will be moved from").":<br>\t".$dn."<br>"._("to").":<br>\t".$d_dn;
952 /* Check if there are references to this object */
953 $ldap->search("(&(member=".$dn.")(|(objectClass=gosaGroupOfNames)(objectClass=groupOfNames)))",array('dn'));
954 $refs = "";
955 while($attrs = $ldap->fetch()){
956 $ref_dn = $attrs['dn'];
957 $refs .= "<br />\t".$ref_dn;
958 }
959 if(!empty($refs)){
960 $this->outside_groups[$b_dn]['ldif'] .= "<br /><br /><i>"._("Updating following references too").":</i>".$refs;
961 }
963 }else{
964 $this->move($dn,$d_dn);
965 }
966 }
967 }
968 }
971 function migrate_outside_users($perform = FALSE)
972 {
973 /* Establish ldap connection */
974 $cv = $this->parent->captured_values;
975 $ldap = new LDAP($cv['admin'],
976 $cv['password'],
977 $cv['connection'],
978 FALSE,
979 $cv['tls']);
981 $ldap->cd($cv['base']);
983 /* Check if there was a destination department posted */
984 if(isset($_POST['move_user_to'])){
985 $destination_dep = $_POST['move_user_to'];
986 }else{
987 print_red(_("Couldn't move users to specified department."));
988 return(false);
989 }
991 foreach($this->outside_users as $b_dn => $data){
992 $this->outside_users[$b_dn]['ldif'] ="";
993 if($data['selected']){
994 $dn = base64_decode($b_dn);
995 $d_dn = preg_replace("/,.*$/",",".base64_decode($destination_dep),$dn);
996 if(!$perform){
997 $this->outside_users[$b_dn]['ldif'] = _("User will be moved from").":<br>\t".$dn."<br>"._("to").":<br>\t".$d_dn;
999 /* Check if there are references to this object */
1000 $ldap->search("(&(member=".$dn.")(|(objectClass=gosaGroupOfNames)(objectClass=groupOfNames)))",array('dn'));
1001 $refs = "";
1002 while($attrs = $ldap->fetch()){
1003 $ref_dn = $attrs['dn'];
1004 $refs .= "<br />\t".$ref_dn;
1005 }
1006 if(!empty($refs)){
1007 $this->outside_users[$b_dn]['ldif'] .= "<br /><br /><i>"._("Updating following references too").":</i>".$refs;
1008 }
1010 }else{
1011 $this->move($dn,$d_dn);
1012 }
1013 }
1014 }
1015 }
1018 function execute()
1019 {
1020 /* Initialise checks if this is the first call */
1021 if(!$this->checks_initialised || isset($_POST['reload'])){
1022 $this->initialize_checks();
1023 $this->checks_initialised = TRUE;
1024 }
1026 /*************
1027 * Winstations outside the group ou
1028 *************/
1030 if(isset($_POST['outside_winstations_dialog_cancel'])){
1031 $this->outside_winstations_dialog = FALSE;
1032 $this->dialog = FALSE;
1033 }
1035 if(isset($_POST['outside_winstations_dialog_whats_done'])){
1036 $this->migrate_outside_winstations(FALSE);
1037 }
1039 if(isset($_POST['outside_winstations_dialog_perform'])){
1040 $this->migrate_outside_winstations(TRUE);
1041 $this->search_outside_winstations();
1042 }
1044 if(isset($_POST['outside_winstations_dialog'])){
1045 $this->outside_winstations_dialog = TRUE;
1046 $this->dialog = TRUE;
1047 }
1049 if($this->outside_winstations_dialog){
1050 $smarty = get_smarty();
1051 $smarty->assign("ous",$this->get_all_winstation_ous());
1052 $smarty->assign("method","outside_winstations");
1053 $smarty->assign("outside_winstations",$this->outside_winstations);
1054 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1055 }
1056 /*************
1057 * Groups outside the group ou
1058 *************/
1060 if(isset($_POST['outside_groups_dialog_cancel'])){
1061 $this->outside_groups_dialog = FALSE;
1062 $this->dialog = FALSE;
1063 }
1065 if(isset($_POST['outside_groups_dialog_whats_done'])){
1066 $this->migrate_outside_groups(FALSE);
1067 }
1069 if(isset($_POST['outside_groups_dialog_perform'])){
1070 $this->migrate_outside_groups(TRUE);
1071 $this->search_outside_groups();
1072 }
1074 if(isset($_POST['outside_groups_dialog'])){
1075 $this->outside_groups_dialog = TRUE;
1076 $this->dialog = TRUE;
1077 }
1079 if($this->outside_groups_dialog){
1080 $smarty = get_smarty();
1081 $smarty->assign("ous",$this->get_all_group_ous());
1082 $smarty->assign("method","outside_groups");
1083 $smarty->assign("outside_groups",$this->outside_groups);
1084 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1085 }
1087 /*************
1088 * User outside the people ou
1089 *************/
1091 if(isset($_POST['outside_users_dialog_cancel'])){
1092 $this->outside_users_dialog = FALSE;
1093 $this->dialog = FALSE;
1094 }
1096 if(isset($_POST['outside_users_dialog_whats_done'])){
1097 $this->migrate_outside_users(FALSE);
1098 }
1100 if(isset($_POST['outside_users_dialog_perform'])){
1101 $this->migrate_outside_users(TRUE);
1102 $this->search_outside_users();
1103 }
1105 if(isset($_POST['outside_users_dialog'])){
1106 $this->outside_users_dialog = TRUE;
1107 $this->dialog = TRUE;
1108 }
1110 if($this->outside_users_dialog){
1111 $smarty = get_smarty();
1112 $smarty->assign("ous",$this->get_all_people_ous());
1113 $smarty->assign("method","outside_users");
1114 $smarty->assign("outside_users",$this->outside_users);
1115 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1116 }
1118 /*************
1119 * Root object check
1120 *************/
1122 if(isset($_POST['retry_root_create'])){
1124 $state = $this->checks['root']['STATUS'];
1125 $this->checkBase(FALSE);
1126 if($state != $this->checks['root']['STATUS']){
1127 $this->initialize_checks();
1128 }
1129 }
1131 /*************
1132 * User Migration handling
1133 *************/
1135 if(isset($_POST['retry_acls'])){
1136 $this->check_administrativeAccount();
1137 }
1139 if(isset($_POST['create_acls'])){
1140 $this->acl_create_dialog = TRUE;
1141 $this->dialog = TRUE;
1142 }
1144 if(isset($_POST['create_acls_cancel'])){
1145 $this->acl_create_dialog = FALSE;
1146 $this->dialog = FALSE;
1147 }
1149 if(isset($_POST['create_acls_create_confirmed'])){
1150 $this->create_admin();
1151 }
1153 if(isset($_POST['create_acls_create'])){
1154 $this->create_admin(TRUE);
1155 }
1157 if(isset($_POST['create_admin_user'])){
1158 $this->create_admin_user();
1159 }
1161 if($this->acl_create_dialog){
1162 $smarty = get_smarty();
1163 $smarty->assign("new_user_password",@$_POST['new_user_password']);
1164 $smarty->assign("users" ,$this->get_user_list());
1165 $smarty->assign("users_cnt" ,count($this->get_user_list()));
1166 $smarty->assign("groups",$this->get_group_list());
1167 $smarty->assign("groups_cnt",count($this->get_group_list()));
1168 $smarty->assign("type" ,$this->acl_create_type);
1169 $smarty->assign("method","create_acls");
1170 $smarty->assign("acl_create_selected",$this->acl_create_selected);
1171 $smarty->assign("what_will_be_done_now",$this->acl_create_changes);
1172 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1173 }
1175 /*************
1176 * User Migration handling
1177 *************/
1179 /* Refresh list of deparments */
1180 if(isset($_POST['users_visible_migrate_refresh'])){
1181 $this->check_gosaAccounts();
1182 }
1184 /* Open migration dialog */
1185 if(isset($_POST['users_visible_migrate'])){
1186 $this->users_migration_dialog = TRUE;
1187 $this->dialog =TRUE;
1188 }
1190 /* Close migration dialog */
1191 if(isset($_POST['users_visible_migrate_close'])){
1192 $this->users_migration_dialog = FALSE;
1193 $this->dialog =FALSE;
1194 }
1196 /* Start migration */
1197 if(isset($_POST['users_visible_migrate_migrate'])){
1198 if($this->migrate_gosaAccounts()){
1199 $this->check_gosaAccounts();
1200 }
1201 }
1203 /* Start migration */
1204 if(isset($_POST['users_visible_migrate_whatsdone'])){
1205 $this->migrate_gosaAccounts(TRUE);
1206 }
1208 /* Display migration dialog */
1209 if($this->users_migration_dialog){
1210 $smarty = get_smarty();
1211 $smarty->assign("users_to_migrate",$this->users_to_migrate);
1212 $smarty->assign("method","migrate_users");
1213 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1214 }
1217 /*************
1218 * Department Migration handling
1219 *************/
1221 /* Refresh list of deparments */
1222 if(isset($_POST['deps_visible_migrate_refresh'])){
1223 $this->check_organizationalUnits();
1224 }
1226 /* Open migration dialog */
1227 if(isset($_POST['deps_visible_migrate'])){
1228 $this->dep_migration_dialog = TRUE;
1229 $this->dialog =TRUE;
1230 }
1232 /* Close migration dialog */
1233 if(isset($_POST['deps_visible_migrate_close'])){
1234 $this->dep_migration_dialog = FALSE;
1235 $this->dialog =FALSE;
1236 }
1238 /* Start migration */
1239 if(isset($_POST['deps_visible_migrate_migrate'])){
1240 if($this->migrate_organizationalUnits()){
1241 $this->check_organizationalUnits();
1242 }
1243 }
1245 /* Start migration */
1246 if(isset($_POST['deps_visible_migrate_whatsdone'])){
1247 $this->migrate_organizationalUnits(TRUE);
1248 }
1250 /* Display migration dialog */
1251 if($this->dep_migration_dialog){
1252 $smarty = get_smarty();
1253 $smarty->assign("deps_to_migrate",$this->deps_to_migrate);
1254 $smarty->assign("method","migrate_deps");
1255 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1256 }
1258 $smarty = get_smarty();
1259 $smarty->assign("checks",$this->checks);
1260 $smarty->assign("method","default");
1261 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1262 }
1265 function save_object()
1266 {
1267 /* Capture all selected winstations from outside_winstations_dialog */
1268 if($this->outside_winstations_dialog){
1269 foreach($this->outside_winstations as $dn => $data){
1270 if(isset($_POST['select_winstation_'.$dn])){
1271 $this->outside_winstations[$dn]['selected'] = TRUE;
1272 }else{
1273 $this->outside_winstations[$dn]['selected'] = FALSE;
1274 }
1275 }
1276 }
1278 /* Capture all selected groups from outside_groups_dialog */
1279 if($this->outside_groups_dialog){
1280 foreach($this->outside_groups as $dn => $data){
1281 if(isset($_POST['select_group_'.$dn])){
1282 $this->outside_groups[$dn]['selected'] = TRUE;
1283 }else{
1284 $this->outside_groups[$dn]['selected'] = FALSE;
1285 }
1286 }
1287 }
1289 /* Capture all selected users from outside_users_dialog */
1290 if($this->outside_users_dialog){
1291 foreach($this->outside_users as $dn => $data){
1292 if(isset($_POST['select_user_'.$dn])){
1293 $this->outside_users[$dn]['selected'] = TRUE;
1294 }else{
1295 $this->outside_users[$dn]['selected'] = FALSE;
1296 }
1297 }
1298 }
1300 /* Get "create acl" dialog posts */
1301 if($this->acl_create_dialog){
1302 if(isset($_POST['create_acls_create'])){
1303 if(isset($_POST['create_acls_selected'])){
1304 $this->acl_create_selected = base64_decode($_POST['create_acls_selected']);
1305 }else{
1306 $this->acl_create_selected = "";
1307 }
1308 }
1310 if(isset($_POST['create_acls_create_abort'])){
1311 $this->acl_create_selected = "";
1312 }
1314 if(isset($_POST['acl_create_type'])){
1315 $this->acl_create_type = $_POST['acl_create_type'];
1316 }
1317 }
1319 /* Get selected departments */
1320 if($this->dep_migration_dialog){
1321 foreach($this->deps_to_migrate as $id => $data){
1322 if(isset($_POST['migrate_'.$id])){
1323 $this->deps_to_migrate[$id]['checked'] = TRUE;
1324 }else{
1325 $this->deps_to_migrate[$id]['checked'] = FALSE;
1326 }
1327 }
1328 }
1330 /* Get selected users */
1331 if($this->users_migration_dialog){
1332 foreach($this->users_to_migrate as $id => $data){
1333 if(isset($_POST['migrate_'.$id])){
1334 $this->users_to_migrate[$id]['checked'] = TRUE;
1335 }else{
1336 $this->users_to_migrate[$id]['checked'] = FALSE;
1337 }
1338 }
1339 }
1340 }
1343 /* Check if the root object exists.
1344 * If the parameter just_check is true, then just check if the
1345 * root object is missing and update the info messages.
1346 * If the Parameter is false, try to create a new root object.
1347 */
1348 function checkBase($just_check = TRUE)
1349 {
1350 /* Get collected setup informations */
1351 $cv = $this->parent->captured_values;
1353 /* Establish ldap connection */
1354 $ldap = new LDAP($cv['admin'],
1355 $cv['password'],
1356 $cv['connection'],
1357 FALSE,
1358 $cv['tls']);
1360 /* Check if root object exists */
1361 $ldap->cd($cv['base']);
1362 $res = $ldap->search("(objectClass=*)");
1363 $err = ldap_errno($ldap->cid);
1365 if( !$res ||
1366 $err == 0x20 || # LDAP_NO_SUCH_OBJECT
1367 $err == 0x40) { # LDAP_NAMING_VIOLATION
1369 /* Root object doesn't exists
1370 */
1371 if($just_check){
1372 $this->checks['root']['STATUS'] = FALSE;
1373 $this->checks['root']['STATUS_MSG']= _("Failed");
1374 $this->checks['root']['ERROR_MSG'].= "<input type='submit' name='retry_root_create' value='"._("Try to create root object")."'>";
1375 return(FALSE);
1376 }else{
1378 /* Add root object */
1379 $ldap->cd($cv['base']);
1380 $res = $ldap->create_missing_trees($cv['base']);
1382 /* If adding failed, tell the user */
1383 if(!$res){
1384 $this->checks['root']['STATUS'] = FALSE;
1385 $this->checks['root']['STATUS_MSG']= _("Failed");
1386 $this->checks['root']['ERROR_MSG'] = _("Root object couldn't be created, you should try it on your own.");
1387 $this->checks['root']['ERROR_MSG'].= "<input type='submit' name='retry_root_create' value='"._("Try to create root object")."'>";
1388 return($res);;
1389 }
1390 }
1391 }
1393 /* Create & remove of dummy object was successful */
1394 $this->checks['root']['STATUS'] = TRUE;
1395 $this->checks['root']['STATUS_MSG']= _("Ok");
1396 }
1399 /* Return ldif information for a
1400 * given attribute array
1401 */
1402 function array_to_ldif($atts)
1403 {
1404 $ret = "";
1405 unset($atts['count']);
1406 unset($atts['dn']);
1407 foreach($atts as $name => $value){
1408 if(is_numeric($name)) {
1409 continue;
1410 }
1411 if(is_array($value)){
1412 unset($value['count']);
1413 foreach($value as $a_val){
1414 $ret .= $name.": ". $a_val."\n";
1415 }
1416 }else{
1417 $ret .= $name.": ". $value."\n";
1418 }
1419 }
1420 return(preg_replace("/\n$/","",$ret));
1421 }
1424 function get_user_list()
1425 {
1426 /* Get collected configuration settings */
1427 $cv = $this->parent->captured_values;
1429 /* Establish ldap connection */
1430 $ldap = new LDAP($cv['admin'],
1431 $cv['password'],
1432 $cv['connection'],
1433 FALSE,
1434 $cv['tls']);
1436 $ldap->cd($cv['base']);
1437 $ldap->search("(objectClass=gosaAccount)",array("dn"));
1439 $tmp = array();
1440 while($attrs = $ldap->fetch()){
1441 $tmp[base64_encode($attrs['dn'])] = @LDAP::fix($attrs['dn']);
1442 }
1443 return($tmp);
1444 }
1447 function get_all_people_ous()
1448 {
1449 /* Get collected configuration settings */
1450 $cv = $this->parent->captured_values;
1452 /* Establish ldap connection */
1453 $ldap = new LDAP($cv['admin'],
1454 $cv['password'],
1455 $cv['connection'],
1456 FALSE,
1457 $cv['tls']);
1459 $ldap->cd($cv['base']);
1460 $ldap->search("(".$cv['peopleou'].")",array("dn"));
1462 if($ldap->count() == 0 ){
1463 $add_dn = $cv['peopleou'].",".$cv['base'];
1464 $naming_attr = preg_replace("/=.*$/","",$add_dn);
1465 $naming_value = preg_replace("/^[^=]*+=([^,]*).*$/","\\1",$add_dn);
1466 $add = array();
1467 $add['objectClass'] = array("organizationalUnit");
1468 $add[$naming_attr] = $naming_value;
1470 $ldap->cd($cv['base']);
1471 $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$add_dn));
1472 $ldap->cd($add_dn);
1473 $ldap->add($add);
1474 }
1476 $ldap->search("(".$cv['peopleou'].")",array("dn"));
1477 $tmp = array();
1478 while($attrs= $ldap->fetch()){
1479 if(!preg_match("/ou=snapshots,/",$attrs['dn'])){
1480 $tmp[base64_encode($attrs['dn'])] = $ldap->fix($attrs['dn']);
1481 }
1482 }
1483 return($tmp);
1484 }
1486 function get_all_winstation_ous()
1487 {
1488 /* Get collected configuration settings */
1489 $cv = $this->parent->captured_values;
1491 /* Establish ldap connection */
1492 $ldap = new LDAP($cv['admin'],
1493 $cv['password'],
1494 $cv['connection'],
1495 FALSE,
1496 $cv['tls']);
1498 /* Get winstation ou */
1499 if($cv['generic_settings']['wws_ou_active']) {
1500 $winstation_ou = $cv['generic_settings']['ws_ou'];
1501 }else{
1502 $winstation_ou = "ou=winstations";
1503 }
1505 $ldap->cd($cv['base']);
1506 $ldap->search("(".$winstation_ou.")",array("dn"));
1508 if($ldap->count() == 0 ){
1509 $add_dn = $winstation_ou.",ou=systems,".$cv['base'];
1510 $naming_attr = preg_replace("/=.*$/","",$add_dn);
1511 $naming_value = preg_replace("/^[^=]*+=([^,]*).*$/","\\1",$add_dn);
1512 $add = array();
1513 $add['objectClass'] = array("organizationalUnit");
1514 $add[$naming_attr] = $naming_value;
1516 $ldap->cd($cv['base']);
1517 $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$add_dn));
1518 $ldap->cd($add_dn);
1519 $ldap->add($add);
1520 }
1522 $ldap->search("(".$winstation_ou.")",array("dn"));
1523 $tmp = array();
1524 while($attrs= $ldap->fetch()){
1525 if(!preg_match("/ou=snapshots,/",$attrs['dn'])){
1526 $tmp[base64_encode($attrs['dn'])] = $ldap->fix($attrs['dn']);
1527 }
1528 }
1529 return($tmp);
1530 }
1534 function get_all_group_ous()
1535 {
1536 /* Get collected configuration settings */
1537 $cv = $this->parent->captured_values;
1539 /* Establish ldap connection */
1540 $ldap = new LDAP($cv['admin'],
1541 $cv['password'],
1542 $cv['connection'],
1543 FALSE,
1544 $cv['tls']);
1546 $ldap->cd($cv['base']);
1547 $ldap->search("(".$cv['groupou'].")",array("dn"));
1549 if($ldap->count() == 0 ){
1550 $add_dn = $cv['groupou'].",".$cv['base'];
1551 $naming_attr = preg_replace("/=.*$/","",$add_dn);
1552 $naming_value = preg_replace("/^[^=]*+=([^,]*).*$/","\\1",$add_dn);
1553 $add = array();
1554 $add['objectClass'] = array("organizationalUnit");
1555 $add[$naming_attr] = $naming_value;
1557 $ldap->cd($cv['base']);
1558 $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$add_dn));
1559 $ldap->cd($add_dn);
1560 $ldap->add($add);
1561 }
1563 $ldap->search("(".$cv['groupou'].")",array("dn"));
1564 $tmp = array();
1565 while($attrs= $ldap->fetch()){
1566 if(!preg_match("/ou=snapshots,/",$attrs['dn'])){
1567 $tmp[base64_encode($attrs['dn'])] = $ldap->fix($attrs['dn']);
1568 }
1569 }
1570 return($tmp);
1571 }
1574 function get_group_list()
1575 {
1576 /* Get collected configuration settings */
1577 $cv = $this->parent->captured_values;
1579 /* Establish ldap connection */
1580 $ldap = new LDAP($cv['admin'],
1581 $cv['password'],
1582 $cv['connection'],
1583 FALSE,
1584 $cv['tls']);
1586 $ldap->cd($cv['base']);
1587 $ldap->search("(objectClass=posixGroup)",array("dn"));
1589 $tmp = array();
1590 while($attrs = $ldap->fetch()){
1591 $tmp[base64_encode($attrs['dn'])] = @LDAP::fix($attrs['dn']);
1592 }
1593 return($tmp);
1594 }
1597 function move($source,$destination)
1598 {
1599 /* Get collected configuration settings */
1600 $cv = $this->parent->captured_values;
1602 /* Establish ldap connection */
1603 $ldap = new LDAP($cv['admin'],
1604 $cv['password'],
1605 $cv['connection'],
1606 FALSE,
1607 $cv['tls']);
1609 /* Update object references in gosaGroupOfNames */
1610 $ogs_to_fix = array();
1611 $ldap->cd($cv['base']);
1612 $ldap->search('(&(objectClass=gosaGroupOfNames)(member='.@LDAP::fix($source).'))', array('cn','member'));
1613 while ($attrs= $ldap->fetch()){
1614 $dn = $attrs['dn'];
1615 $attrs = $this->cleanup_array($attrs);
1616 $member_new = array($destination);
1617 foreach($attrs['member'] as $member){
1618 if($member != $source){
1619 $member_new[] = $member;
1620 }
1621 }
1622 $attrs['member'] = $member_new;
1623 $ogs_to_fix[$dn] = $attrs;
1624 }
1626 /* Copy source to destination dn */
1627 $ldap->cat($source);
1628 $new_data = $this->cleanup_array($ldap->fetch());
1629 $ldap->cd($destination);
1630 $res = $ldap->add($new_data);
1632 /* Display warning if copy failed */
1633 if(!$res){
1634 print_red(_("Failed to copy '%s' to '%s'. Ldap says '%s'."),$source,$destination,$ldap->get_error());
1635 }else{
1636 $res = $ldap->rmDir($source);
1637 show_ldap_error($ldap->get_error(),_("Something went wrong while copying dns."));
1639 /* Object is copied, so update its references */
1640 foreach($ogs_to_fix as $dn => $data){
1641 $ldap->cd($dn);
1642 $ldap->modify($data);
1643 }
1644 }
1645 }
1648 /* Cleanup ldap result to be able to write it be to ldap */
1649 function cleanup_array($attrs)
1650 {
1651 foreach($attrs as $key => $value) {
1652 if(is_numeric($key) || in_array($key,array("count","dn"))){
1653 unset($attrs[$key]);
1654 }
1655 if(is_array($value) && isset($value['count'])){
1656 unset($attrs[$key]['count']);
1657 }
1658 }
1659 return($attrs);
1660 }
1661 }
1663 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1664 ?>