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 gosaAcls */
751 $ldap->cd($cv['base']);
752 $res = $ldap->cat($cv['base']);
754 if(!$res){
755 $this->checks['acls']['STATUS'] = FALSE;
756 $this->checks['acls']['STATUS_MSG']= _("LDAP query failed");
757 $this->checks['acls']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
758 }else{
759 $found = false;
760 $username = "";
761 $attrs = $ldap->fetch();
762 if(isset($attrs['gosaAclEntry'])){
763 $acls = $attrs['gosaAclEntry'];
764 for($i = 0 ; $i < $acls['count'] ; $i++){
765 $acl = $acls[$i];
766 $tmp = split(":",$acl);
767 if($tmp[1] == "psub"){
768 $members = split(",",$tmp[2]);
769 foreach($members as $member){
770 $member = base64_decode($member);
772 /* Check if acl owner is a valid GOsa user account */
773 $ldap->cat($member,array("objectClass","uid","cn"));
774 $ret = $ldap->fetch();
776 if(isset($ret['objectClass']) && in_array("posixGroup",$ret['objectClass'])){
777 $found = TRUE;
778 $username .= "ACL-Group: ".$ret['cn'][0]."<br>";
779 }elseif(isset($ret['objectClass']) && in_array("gosaAccount",$ret['objectClass']) &&
780 in_array("organizationalPerson",$ret['objectClass']) &&
781 in_array("inetOrgPerson",$ret['objectClass'])){
782 $found = TRUE;
783 $username .= "ACL: ".$ret['uid'][0]."<br>";
784 }
785 }
786 }elseif($tmp[1] == "role"){
788 /* Check if acl owner is a valid GOsa user account */
789 $ldap->cat(base64_decode($tmp[2]),array("gosaAclTemplate"));
790 $ret = $ldap->fetch();
792 if(isset($ret['gosaAclTemplate'])){
793 $cnt = $ret['gosaAclTemplate']['count'];
794 for($e = 0 ; $e < $cnt ; $e++){
796 $a_str = $ret['gosaAclTemplate'][$e];
797 if(preg_match("/^[0-9]*:psub:/",$a_str) && preg_match("/:all;cmdrw$/",$a_str)){
799 $members = split(",",$tmp[3]);
800 foreach($members as $member){
801 $member = base64_decode($member);
803 /* Check if acl owner is a valid GOsa user account */
804 $ldap->cat($member,array("objectClass","uid"));
805 $ret = $ldap->fetch();
807 if(isset($ret['objectClass']) && in_array("gosaAccount",$ret['objectClass']) &&
808 in_array("organizationalPerson",$ret['objectClass']) &&
809 in_array("inetOrgPerson",$ret['objectClass'])){
810 $found = TRUE;
811 $username .= "ACL Role: ".$ret['uid'][0]."<br>";
812 }
813 }
814 }
815 }
816 }
817 }
818 }
819 }
821 # For debugging
822 #echo $username;
824 if($found){
825 $this->checks['acls']['STATUS'] = TRUE;
826 $this->checks['acls']['STATUS_MSG']= _("Ok");
827 $this->checks['acls']['ERROR_MSG'] = "";
828 }else{
829 $this->checks['acls']['STATUS'] = FALSE;
830 $this->checks['acls']['STATUS_MSG']= _("Failed");
831 $this->checks['acls']['ERROR_MSG']= _("There is no GOsa administrator account inside your LDAP.")." ";
832 $this->checks['acls']['ERROR_MSG'].= "<input type='submit' name='create_acls' value='"._("Create")."'>";
833 }
834 }
835 return($ldap->count()>=1);
836 }
840 function create_admin($only_ldif = FALSE)
841 {
842 /* Reset '' */
843 $this->acl_create_changes="";
845 /* Object that should receive admin acls */
846 $dn = $this->acl_create_selected;
848 /* Get collected configuration settings */
849 $cv = $this->parent->captured_values;
851 /* Establish ldap connection */
852 $ldap = new LDAP($cv['admin'],
853 $cv['password'],
854 $cv['connection'],
855 FALSE,
856 $cv['tls']);
858 /* Get current base attributes */
859 $ldap->cd($cv['base']);
860 $ldap->cat($cv['base'],array("dn","objectClass","gosaAclEntry"));
861 $attrs = $ldap->fetch();
863 /* Add acls for the selcted user to the base */
864 $attrs_new['objectClass'] = array("gosaACL");
866 for($i = 0; $i < $attrs['objectClass']['count']; $i ++){
867 if(!in_array_ics($attrs['objectClass'][$i],$attrs_new['objectClass'])){
868 $attrs_new['objectClass'][] = $attrs['objectClass'][$i];
869 }
870 }
872 $acl = "0:psub:".base64_encode($dn).":all;cmdrw";
873 $attrs_new['gosaAclEntry'][] = $acl;
874 if(isset($attrs['gosaAclEntry'])){
875 for($i = 0 ; $i < $attrs['gosaAclEntry']['count']; $i ++){
877 $prio = preg_replace("/[:].*$/","",$attrs['gosaAclEntry'][$i]);
878 $rest = preg_replace("/^[^:]/","",$attrs['gosaAclEntry'][$i]);
880 $data = ($prio+1).$rest;
881 $attrs_new['gosaAclEntry'][] = $data;
882 }
883 }
885 if($only_ldif){
886 $this->acl_create_changes ="\n".$cv['base']."\n";
887 $this->acl_create_changes.=$this->array_to_ldif($attrs)."\n";
888 $this->acl_create_changes.="\n".$cv['base']."\n";
889 $this->acl_create_changes.=$this->array_to_ldif($attrs_new);
890 }else{
892 $ldap->cd($cv['base']);
893 if(!$ldap->modify($attrs_new)){
894 print_red(sprintf(_("Adding acls for user '%s' failed, ldap says '%s'."),$dn,$ldap->get_error()));
895 return(FALSE);
896 }else{
897 return(TRUE);
898 }
899 }
900 }
903 function create_admin_user()
904 {
905 $pw1 = $pw2 = "";
906 $uid = "";
908 if(isset($_POST['new_user_uid'])){
909 $uid = $_POST['new_user_uid'];
910 }
911 if(isset($_POST['new_user_password'])){
912 $pw1 = $_POST['new_user_password'];
913 }
914 if(isset($_POST['new_user_password2'])){
915 $pw2 = $_POST['new_user_password2'];
916 }
918 if(empty($pw1) || empty($pw2) | ($pw1 != $pw2)){
919 print_red(_("Specified passwords are empty or not equal."));
920 return false;
921 }
923 if(!is_uid($uid) || empty($uid)){
924 print_red(_("Please specify a valid uid."));
925 return false;
926 }
929 /* Establish ldap connection */
930 $cv = $this->parent->captured_values;
931 $ldap = new LDAP($cv['admin'],
932 $cv['password'],
933 $cv['connection'],
934 FALSE,
935 $cv['tls']);
937 /* Get current base attributes */
938 $ldap->cd($cv['base']);
940 if($cv['peopledn'] == "cn"){
941 $dn = "cn=System Administrator,".$cv['peopleou'].",".$cv['base'];
942 }else{
943 $dn = "uid=".$uid.",".$cv['peopleou'].",".$cv['base'];
944 }
946 $methods = @passwordMethod::get_available_methods_if_not_loaded();
947 $p_m = $methods[$cv['encryption']];
948 $p_c = new $p_m(array());
949 $hash = $p_c->generate_hash($pw2);
951 $new_user=array();
952 $new_user['objectClass']= array("top","person","gosaAccount","organizationalPerson","inetOrgPerson");
953 $new_user['givenName'] = "System";
954 $new_user['sn'] = "Administrator";
955 $new_user['cn'] = "System Administrator";
956 $new_user['uid'] = $uid;
957 $new_user['userPassword'] = $hash;
959 $ldap->cd($cv['base']);
960 $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$dn));
961 $ldap->cd($dn);
962 $res = $ldap->add($new_user);
963 $this->acl_create_selected = $dn;
964 $this->create_admin();
966 if(!$res){
967 print_red($ldap->get_error());
968 return(FALSE);
969 }
971 $this->acl_create_dialog=FALSE;
972 $this->check_administrativeAccount();
973 return(TRUE);
974 }
977 function migrate_outside_winstations($perform = FALSE)
978 {
979 /* Establish ldap connection */
980 $cv = $this->parent->captured_values;
981 $ldap = new LDAP($cv['admin'],
982 $cv['password'],
983 $cv['connection'],
984 FALSE,
985 $cv['tls']);
987 $ldap->cd($cv['base']);
989 /* Check if there was a destination department posted */
990 if(isset($_POST['move_winstation_to'])){
991 $destination_dep = $_POST['move_winstation_to'];
992 }else{
993 print_red(_("Couldn't move users to specified department."));
994 return(false);
995 }
997 foreach($this->outside_winstations as $b_dn => $data){
998 $this->outside_winstations[$b_dn]['ldif'] ="";
999 if($data['selected']){
1000 $dn = base64_decode($b_dn);
1001 $d_dn = preg_replace("/,.*$/",",".base64_decode($destination_dep),$dn);
1002 if(!$perform){
1003 $this->outside_winstations[$b_dn]['ldif'] = _("Winstation will be moved from").":<br>\t".$dn."<br>"._("to").":<br>\t".$d_dn;
1006 /* Check if there are references to this object */
1007 $ldap->search("(&(member=".$dn.")(|(objectClass=gosaGroupOfNames)(objectClass=groupOfNames)))",array('dn'));
1008 $refs = "";
1009 while($attrs = $ldap->fetch()){
1010 $ref_dn = $attrs['dn'];
1011 $refs .= "<br />\t".$ref_dn;
1012 }
1013 if(!empty($refs)){
1014 $this->outside_winstations[$b_dn]['ldif'] .= "<br /><br /><i>"._("Updating following references too").":</i>".$refs;
1015 }
1017 }else{
1018 $this->move($dn,$d_dn);
1019 }
1020 }
1021 }
1022 }
1025 function migrate_outside_groups($perform = FALSE)
1026 {
1027 /* Establish ldap connection */
1028 $cv = $this->parent->captured_values;
1029 $ldap = new LDAP($cv['admin'],
1030 $cv['password'],
1031 $cv['connection'],
1032 FALSE,
1033 $cv['tls']);
1035 $ldap->cd($cv['base']);
1037 /* Check if there was a destination department posted */
1038 if(isset($_POST['move_group_to'])){
1039 $destination_dep = $_POST['move_group_to'];
1040 }else{
1041 print_red(_("Couldn't move users to specified department."));
1042 return(false);
1043 }
1045 foreach($this->outside_groups as $b_dn => $data){
1046 $this->outside_groups[$b_dn]['ldif'] ="";
1047 if($data['selected']){
1048 $dn = base64_decode($b_dn);
1049 $d_dn = preg_replace("/,.*$/",",".base64_decode($destination_dep),$dn);
1050 if(!$perform){
1051 $this->outside_groups[$b_dn]['ldif'] = _("Group will be moved from").":<br>\t".$dn."<br>"._("to").":<br>\t".$d_dn;
1054 /* Check if there are references to this object */
1055 $ldap->search("(&(member=".$dn.")(|(objectClass=gosaGroupOfNames)(objectClass=groupOfNames)))",array('dn'));
1056 $refs = "";
1057 while($attrs = $ldap->fetch()){
1058 $ref_dn = $attrs['dn'];
1059 $refs .= "<br />\t".$ref_dn;
1060 }
1061 if(!empty($refs)){
1062 $this->outside_groups[$b_dn]['ldif'] .= "<br /><br /><i>"._("Updating following references too").":</i>".$refs;
1063 }
1065 }else{
1066 $this->move($dn,$d_dn);
1067 }
1068 }
1069 }
1070 }
1073 function migrate_outside_users($perform = FALSE)
1074 {
1075 /* Establish ldap connection */
1076 $cv = $this->parent->captured_values;
1077 $ldap = new LDAP($cv['admin'],
1078 $cv['password'],
1079 $cv['connection'],
1080 FALSE,
1081 $cv['tls']);
1083 $ldap->cd($cv['base']);
1085 /* Check if there was a destination department posted */
1086 if(isset($_POST['move_user_to'])){
1087 $destination_dep = $_POST['move_user_to'];
1088 }else{
1089 print_red(_("Couldn't move users to specified department."));
1090 return(false);
1091 }
1093 foreach($this->outside_users as $b_dn => $data){
1094 $this->outside_users[$b_dn]['ldif'] ="";
1095 if($data['selected']){
1096 $dn = base64_decode($b_dn);
1097 $d_dn = preg_replace("/,.*$/",",".base64_decode($destination_dep),$dn);
1098 if(!$perform){
1099 $this->outside_users[$b_dn]['ldif'] = _("User will be moved from").":<br>\t".$dn."<br>"._("to").":<br>\t".$d_dn;
1101 /* Check if there are references to this object */
1102 $ldap->search("(&(member=".$dn.")(|(objectClass=gosaGroupOfNames)(objectClass=groupOfNames)))",array('dn'));
1103 $refs = "";
1104 while($attrs = $ldap->fetch()){
1105 $ref_dn = $attrs['dn'];
1106 $refs .= "<br />\t".$ref_dn;
1107 }
1108 if(!empty($refs)){
1109 $this->outside_users[$b_dn]['ldif'] .= "<br /><br /><i>"._("The following references will be updated").":</i>".$refs;
1110 }
1112 }else{
1113 $this->move($dn,$d_dn);
1114 }
1115 }
1116 }
1117 }
1120 function execute()
1121 {
1122 /* Initialise checks if this is the first call */
1123 if(!$this->checks_initialised || isset($_POST['reload'])){
1124 $this->initialize_checks();
1125 $this->checks_initialised = TRUE;
1126 }
1128 /*************
1129 * Winstations outside the group ou
1130 *************/
1132 if(isset($_POST['outside_winstations_dialog_cancel'])){
1133 $this->outside_winstations_dialog = FALSE;
1134 $this->dialog = FALSE;
1135 $this->show_details = FALSE;
1136 }
1138 if(isset($_POST['outside_winstations_dialog_whats_done'])){
1139 $this->migrate_outside_winstations(FALSE);
1140 }
1142 if(isset($_POST['outside_winstations_dialog_perform'])){
1143 $this->migrate_outside_winstations(TRUE);
1144 $this->search_outside_winstations();
1145 $this->dialog = FALSE;
1146 $this->show_details = FALSE;
1147 $this->outside_winstations_dialog = FALSE;
1148 }
1150 if(isset($_POST['outside_winstations_dialog'])){
1151 $this->outside_winstations_dialog = TRUE;
1152 $this->dialog = TRUE;
1153 }
1155 if($this->outside_winstations_dialog){
1156 $smarty = get_smarty();
1157 $smarty->assign("ous",$this->get_all_winstation_ous());
1158 $smarty->assign("method","outside_winstations");
1159 $smarty->assign("outside_winstations",$this->outside_winstations);
1160 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1161 }
1162 /*************
1163 * Groups outside the group ou
1164 *************/
1166 if(isset($_POST['outside_groups_dialog_cancel'])){
1167 $this->outside_groups_dialog = FALSE;
1168 $this->show_details = FALSE;
1169 $this->dialog = FALSE;
1170 }
1172 if(isset($_POST['outside_groups_dialog_whats_done'])){
1173 $this->show_details= TRUE;
1174 $this->migrate_outside_groups(FALSE);
1175 }
1177 if(isset($_POST['outside_groups_dialog_refresh'])){
1178 $this->show_details= FALSE;
1179 }
1181 if(isset($_POST['outside_groups_dialog_perform'])){
1182 $this->migrate_outside_groups(TRUE);
1183 $this->dialog = FALSE;
1184 $this->show_details = FALSE;
1185 $this->outside_groups_dialog = FALSE;
1186 $this->initialize_checks();
1187 }
1189 if(isset($_POST['outside_groups_dialog'])){
1190 $this->outside_groups_dialog = TRUE;
1191 $this->dialog = TRUE;
1192 }
1194 if($this->outside_groups_dialog){
1195 $smarty = get_smarty();
1196 $smarty->assign("ous",$this->get_all_group_ous());
1197 $smarty->assign("method","outside_groups");
1198 $smarty->assign("outside_groups",$this->outside_groups);
1199 $smarty->assign("group_details", $this->show_details);
1200 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1201 }
1203 /*************
1204 * User outside the people ou
1205 *************/
1207 if(isset($_POST['outside_users_dialog_cancel'])){
1208 $this->outside_users_dialog = FALSE;
1209 $this->dialog = FALSE;
1210 $this->show_details = FALSE;
1211 }
1213 if(isset($_POST['outside_users_dialog_whats_done'])){
1214 $this->show_details= TRUE;
1215 $this->migrate_outside_users(FALSE);
1216 }
1218 if(isset($_POST['outside_users_dialog_perform'])){
1219 $this->migrate_outside_users(TRUE);
1220 $this->initialize_checks();
1221 $this->dialog = FALSE;
1222 $this->show_details = FALSE;
1223 $this->outside_users_dialog = FALSE;
1224 }
1226 if (isset($_POST['outside_users_dialog_refresh'])){
1227 $this->show_details= FALSE;
1228 }
1230 if(isset($_POST['outside_users_dialog'])){
1231 $this->outside_users_dialog = TRUE;
1232 $this->dialog = TRUE;
1233 }
1235 if($this->outside_users_dialog){
1236 $smarty = get_smarty();
1237 $smarty->assign("ous",$this->get_all_people_ous());
1238 $smarty->assign("method","outside_users");
1239 $smarty->assign("outside_users",$this->outside_users);
1240 $smarty->assign("user_details", $this->show_details);
1241 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1242 }
1244 /*************
1245 * Root object check
1246 *************/
1248 if(isset($_POST['retry_root_create'])){
1250 $state = $this->checks['root']['STATUS'];
1251 $this->checkBase(FALSE);
1252 if($state != $this->checks['root']['STATUS']){
1253 $this->initialize_checks();
1254 }
1255 }
1257 /*************
1258 * User Migration handling
1259 *************/
1261 if(isset($_POST['retry_acls'])){
1262 $this->check_administrativeAccount();
1263 }
1265 if(isset($_POST['create_acls'])){
1266 $this->acl_create_dialog = TRUE;
1267 $this->dialog = TRUE;
1268 }
1270 if(isset($_POST['create_acls_cancel'])){
1271 $this->acl_create_dialog = FALSE;
1272 $this->dialog = FALSE;
1273 $this->show_details = FALSE;
1274 }
1276 # if(isset($_POST['create_acls_create_confirmed'])){
1277 # if($this->create_admin()){
1278 # $this->acl_create_dialog = FALSE;
1279 # $this->dialog = FALSE;
1280 # $this->show_details = FALSE;
1281 # $this->initialize_checks();
1282 # }
1283 # }
1285 if(isset($_POST['create_acls_create'])){
1286 $this->create_admin(TRUE);
1287 }
1289 if(isset($_POST['create_admin_user'])){
1290 if($this->create_admin_user()){
1291 $this->dialog = FALSE;
1292 $this->show_details = FALSE;
1293 }
1294 }
1296 if($this->acl_create_dialog){
1297 $smarty = get_smarty();
1299 $uid = "admin";
1300 if(isset($_POST['new_user_uid'])){
1301 $uid = $_POST['new_user_uid'];
1302 }
1304 $smarty->assign("new_user_uid",$uid);
1305 $smarty->assign("new_user_password",@$_POST['new_user_password']);
1306 $smarty->assign("new_user_password2",@$_POST['new_user_password2']);
1307 $smarty->assign("method","create_acls");
1308 $smarty->assign("acl_create_selected",$this->acl_create_selected);
1309 $smarty->assign("what_will_be_done_now",$this->acl_create_changes);
1310 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1311 }
1313 /*************
1314 * User Migration handling
1315 *************/
1317 /* Refresh list of deparments */
1318 if(isset($_POST['users_visible_migrate_refresh'])){
1319 $this->check_gosaAccounts();
1320 }
1322 /* Open migration dialog */
1323 if(isset($_POST['users_visible_migrate'])){
1324 $this->show_details= FALSE;
1325 $this->users_migration_dialog = TRUE;
1326 $this->dialog =TRUE;
1327 }
1329 /* Close migration dialog */
1330 if(isset($_POST['users_visible_migrate_close'])){
1331 $this->users_migration_dialog = FALSE;
1332 $this->dialog =FALSE;
1333 $this->show_details = FALSE;
1334 }
1336 /* Start migration */
1337 if(isset($_POST['users_visible_migrate_migrate'])){
1338 if($this->migrate_gosaAccounts()){
1339 $this->initialize_checks();
1340 $this->dialog = FALSE;
1341 $this->show_details = FALSE;
1342 $this->users_migration_dialog = FALSE;
1343 }
1344 }
1346 /* Start migration */
1347 if(isset($_POST['users_visible_migrate_whatsdone'])){
1348 $this->migrate_gosaAccounts(TRUE);
1349 }
1351 /* Display migration dialog */
1352 if($this->users_migration_dialog){
1353 $smarty = get_smarty();
1354 $smarty->assign("users_to_migrate",$this->users_to_migrate);
1355 $smarty->assign("method","migrate_users");
1356 $smarty->assign("user_details", $this->show_details);
1357 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1358 }
1361 /*************
1362 * Department Migration handling
1363 *************/
1365 /* Refresh list of deparments */
1366 if(isset($_POST['deps_visible_migrate_refresh'])){
1367 $this->check_organizationalUnits();
1368 $this->show_details= FALSE;
1369 }
1371 /* Open migration dialog */
1372 if(isset($_POST['deps_visible_migrate'])){
1373 $this->dep_migration_dialog = TRUE;
1374 $this->dialog =TRUE;
1375 }
1377 /* Close migration dialog */
1378 if(isset($_POST['deps_visible_migrate_close'])){
1379 $this->dep_migration_dialog = FALSE;
1380 $this->dialog =FALSE;
1381 $this->show_details = FALSE;
1382 }
1384 /* Start migration */
1385 if(isset($_POST['deps_visible_migrate_migrate'])){
1386 if($this->migrate_organizationalUnits()){
1387 $this->show_details= FALSE;
1388 $this->check_organizationalUnits();
1389 $this->dialog = FALSE;
1390 $this->dep_migration_dialog = FALSE;
1391 }
1392 }
1394 /* Start migration */
1395 if(isset($_POST['deps_visible_migrate_whatsdone'])){
1396 $this->migrate_organizationalUnits(TRUE);
1397 }
1399 /* Display migration dialog */
1400 if($this->dep_migration_dialog){
1401 $smarty = get_smarty();
1402 $smarty->assign("deps_to_migrate",$this->deps_to_migrate);
1403 $smarty->assign("method","migrate_deps");
1404 $smarty->assign("deps_details", $this->show_details);
1405 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1406 }
1408 $smarty = get_smarty();
1409 $smarty->assign("checks",$this->checks);
1410 $smarty->assign("method","default");
1411 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1412 }
1415 function save_object()
1416 {
1417 $this->is_completed= TRUE;
1419 /* Capture all selected winstations from outside_winstations_dialog */
1420 if($this->outside_winstations_dialog){
1421 foreach($this->outside_winstations as $dn => $data){
1422 if(isset($_POST['select_winstation_'.$dn])){
1423 $this->outside_winstations[$dn]['selected'] = TRUE;
1424 }else{
1425 $this->outside_winstations[$dn]['selected'] = FALSE;
1426 }
1427 }
1428 }
1430 /* Capture all selected groups from outside_groups_dialog */
1431 if($this->outside_groups_dialog){
1432 foreach($this->outside_groups as $dn => $data){
1433 if(isset($_POST['select_group_'.$dn])){
1434 $this->outside_groups[$dn]['selected'] = TRUE;
1435 }else{
1436 $this->outside_groups[$dn]['selected'] = FALSE;
1437 }
1438 }
1439 }
1441 /* Capture all selected users from outside_users_dialog */
1442 if($this->outside_users_dialog){
1443 foreach($this->outside_users as $dn => $data){
1444 if(isset($_POST['select_user_'.$dn])){
1445 $this->outside_users[$dn]['selected'] = TRUE;
1446 }else{
1447 $this->outside_users[$dn]['selected'] = FALSE;
1448 }
1449 }
1450 }
1452 /* Get "create acl" dialog posts */
1453 if($this->acl_create_dialog){
1455 if(isset($_POST['create_acls_create_abort'])){
1456 $this->acl_create_selected = "";
1457 }
1458 }
1460 /* Get selected departments */
1461 if($this->dep_migration_dialog){
1462 foreach($this->deps_to_migrate as $id => $data){
1463 if(isset($_POST['migrate_'.$id])){
1464 $this->deps_to_migrate[$id]['checked'] = TRUE;
1465 }else{
1466 $this->deps_to_migrate[$id]['checked'] = FALSE;
1467 }
1468 }
1469 }
1471 /* Get selected users */
1472 if($this->users_migration_dialog){
1473 foreach($this->users_to_migrate as $id => $data){
1474 if(isset($_POST['migrate_'.$id])){
1475 $this->users_to_migrate[$id]['checked'] = TRUE;
1476 }else{
1477 $this->users_to_migrate[$id]['checked'] = FALSE;
1478 }
1479 }
1480 }
1481 }
1484 /* Check if the root object exists.
1485 * If the parameter just_check is true, then just check if the
1486 * root object is missing and update the info messages.
1487 * If the Parameter is false, try to create a new root object.
1488 */
1489 function checkBase($just_check = TRUE)
1490 {
1491 /* Get collected setup informations */
1492 $cv = $this->parent->captured_values;
1494 /* Establish ldap connection */
1495 $ldap = new LDAP($cv['admin'],
1496 $cv['password'],
1497 $cv['connection'],
1498 FALSE,
1499 $cv['tls']);
1501 /* Check if root object exists */
1502 $ldap->cd($cv['base']);
1503 $res = $ldap->search("(objectClass=*)");
1504 $err = ldap_errno($ldap->cid);
1506 if( !$res ||
1507 $err == 0x20 || # LDAP_NO_SUCH_OBJECT
1508 $err == 0x40) { # LDAP_NAMING_VIOLATION
1510 /* Root object doesn't exists
1511 */
1512 if($just_check){
1513 $this->checks['root']['STATUS'] = FALSE;
1514 $this->checks['root']['STATUS_MSG']= _("Failed");
1515 $this->checks['root']['ERROR_MSG'] = _("The LDAP root object is missing. It is required to use your LDAP service.").' ';
1516 $this->checks['root']['ERROR_MSG'].= "<input type='submit' name='retry_root_create' value='"._("Try to create root object")."'>";
1517 return(FALSE);
1518 }else{
1520 /* Add root object */
1521 $ldap->cd($cv['base']);
1522 $res = $ldap->create_missing_trees($cv['base']);
1524 /* If adding failed, tell the user */
1525 if(!$res){
1526 $this->checks['root']['STATUS'] = FALSE;
1527 $this->checks['root']['STATUS_MSG']= _("Failed");
1528 $this->checks['root']['ERROR_MSG'] = _("Root object couldn't be created, you should try it on your own.");
1529 $this->checks['root']['ERROR_MSG'].= " <input type='submit' name='retry_root_create' value='"._("Try to create root object")."'>";
1530 return($res);;
1531 }
1532 }
1533 }
1535 /* Create & remove of dummy object was successful */
1536 $this->checks['root']['STATUS'] = TRUE;
1537 $this->checks['root']['STATUS_MSG']= _("Ok");
1538 }
1541 /* Return ldif information for a
1542 * given attribute array
1543 */
1544 function array_to_ldif($atts)
1545 {
1546 $ret = "";
1547 unset($atts['count']);
1548 unset($atts['dn']);
1549 foreach($atts as $name => $value){
1550 if(is_numeric($name)) {
1551 continue;
1552 }
1553 if(is_array($value)){
1554 unset($value['count']);
1555 foreach($value as $a_val){
1556 $ret .= $name.": ". $a_val."\n";
1557 }
1558 }else{
1559 $ret .= $name.": ". $value."\n";
1560 }
1561 }
1562 return(preg_replace("/\n$/","",$ret));
1563 }
1566 function get_user_list()
1567 {
1568 /* Get collected configuration settings */
1569 $cv = $this->parent->captured_values;
1571 /* Establish ldap connection */
1572 $ldap = new LDAP($cv['admin'],
1573 $cv['password'],
1574 $cv['connection'],
1575 FALSE,
1576 $cv['tls']);
1578 $ldap->cd($cv['base']);
1579 $ldap->search("(objectClass=gosaAccount)",array("dn"));
1581 $tmp = array();
1582 while($attrs = $ldap->fetch()){
1583 $tmp[base64_encode($attrs['dn'])] = @LDAP::fix($attrs['dn']);
1584 }
1585 return($tmp);
1586 }
1589 function get_all_people_ous()
1590 {
1591 /* Get collected configuration settings */
1592 $cv = $this->parent->captured_values;
1594 /* Establish ldap connection */
1595 $ldap = new LDAP($cv['admin'],
1596 $cv['password'],
1597 $cv['connection'],
1598 FALSE,
1599 $cv['tls']);
1601 $ldap->cd($cv['base']);
1602 $ldap->search("(".$cv['peopleou'].")",array("dn"));
1604 if($ldap->count() == 0 ){
1605 $add_dn = $cv['peopleou'].",".$cv['base'];
1606 $naming_attr = preg_replace("/=.*$/","",$add_dn);
1607 $naming_value = preg_replace("/^[^=]*+=([^,]*).*$/","\\1",$add_dn);
1608 $add = array();
1609 $add['objectClass'] = array("organizationalUnit");
1610 $add[$naming_attr] = $naming_value;
1612 $ldap->cd($cv['base']);
1613 $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$add_dn));
1614 $ldap->cd($add_dn);
1615 $ldap->add($add);
1616 }
1618 $ldap->search("(".$cv['peopleou'].")",array("dn"));
1619 $tmp = array();
1620 while($attrs= $ldap->fetch()){
1621 if(!preg_match("/ou=snapshots,/",$attrs['dn'])){
1622 $tmp[base64_encode($attrs['dn'])] = $ldap->fix($attrs['dn']);
1623 }
1624 }
1625 return($tmp);
1626 }
1628 function get_all_winstation_ous()
1629 {
1630 /* Get collected configuration settings */
1631 $cv = $this->parent->captured_values;
1633 /* Establish ldap connection */
1634 $ldap = new LDAP($cv['admin'],
1635 $cv['password'],
1636 $cv['connection'],
1637 FALSE,
1638 $cv['tls']);
1640 /* Get winstation ou */
1641 if($cv['generic_settings']['wws_ou_active']) {
1642 $winstation_ou = $cv['generic_settings']['ws_ou'];
1643 }else{
1644 $winstation_ou = "ou=winstations";
1645 }
1647 $ldap->cd($cv['base']);
1648 $ldap->search("(".$winstation_ou.")",array("dn"));
1650 if($ldap->count() == 0 ){
1651 $add_dn = $winstation_ou.",ou=systems,".$cv['base'];
1652 $naming_attr = preg_replace("/=.*$/","",$add_dn);
1653 $naming_value = preg_replace("/^[^=]*+=([^,]*).*$/","\\1",$add_dn);
1654 $add = array();
1655 $add['objectClass'] = array("organizationalUnit");
1656 $add[$naming_attr] = $naming_value;
1658 $ldap->cd($cv['base']);
1659 $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$add_dn));
1660 $ldap->cd($add_dn);
1661 $ldap->add($add);
1662 }
1664 $ldap->search("(".$winstation_ou.")",array("dn"));
1665 $tmp = array();
1666 while($attrs= $ldap->fetch()){
1667 if(!preg_match("/ou=snapshots,/",$attrs['dn'])){
1668 $tmp[base64_encode($attrs['dn'])] = $ldap->fix($attrs['dn']);
1669 }
1670 }
1671 return($tmp);
1672 }
1675 function get_all_group_ous()
1676 {
1677 /* Get collected configuration settings */
1678 $cv = $this->parent->captured_values;
1680 /* Establish ldap connection */
1681 $ldap = new LDAP($cv['admin'],
1682 $cv['password'],
1683 $cv['connection'],
1684 FALSE,
1685 $cv['tls']);
1687 $ldap->cd($cv['base']);
1688 $ldap->search("(".$cv['groupou'].")",array("dn"));
1690 if($ldap->count() == 0 ){
1691 $add_dn = $cv['groupou'].",".$cv['base'];
1692 $naming_attr = preg_replace("/=.*$/","",$add_dn);
1693 $naming_value = preg_replace("/^[^=]*+=([^,]*).*$/","\\1",$add_dn);
1694 $add = array();
1695 $add['objectClass'] = array("organizationalUnit");
1696 $add[$naming_attr] = $naming_value;
1698 $ldap->cd($cv['base']);
1699 $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$add_dn));
1700 $ldap->cd($add_dn);
1701 $ldap->add($add);
1702 }
1704 $ldap->search("(".$cv['groupou'].")",array("dn"));
1705 $tmp = array();
1706 while($attrs= $ldap->fetch()){
1707 if(!preg_match("/ou=snapshots,/",$attrs['dn'])){
1708 $tmp[base64_encode($attrs['dn'])] = $ldap->fix($attrs['dn']);
1709 }
1710 }
1711 return($tmp);
1712 }
1715 function get_group_list()
1716 {
1717 /* Get collected configuration settings */
1718 $cv = $this->parent->captured_values;
1720 /* Establish ldap connection */
1721 $ldap = new LDAP($cv['admin'],
1722 $cv['password'],
1723 $cv['connection'],
1724 FALSE,
1725 $cv['tls']);
1727 $ldap->cd($cv['base']);
1728 $ldap->search("(objectClass=posixGroup)",array("dn"));
1730 $tmp = array();
1731 while($attrs = $ldap->fetch()){
1732 $tmp[base64_encode($attrs['dn'])] = @LDAP::fix($attrs['dn']);
1733 }
1734 return($tmp);
1735 }
1738 function move($source,$destination)
1739 {
1740 /* Get collected configuration settings */
1741 $cv = $this->parent->captured_values;
1743 /* Establish ldap connection */
1744 $ldap = new LDAP($cv['admin'],
1745 $cv['password'],
1746 $cv['connection'],
1747 FALSE,
1748 $cv['tls']);
1750 /* Update object references in gosaGroupOfNames */
1751 $ogs_to_fix = array();
1752 $ldap->cd($cv['base']);
1753 $ldap->search('(&(objectClass=gosaGroupOfNames)(member='.@LDAP::fix($source).'))', array('cn','member'));
1754 while ($attrs= $ldap->fetch()){
1755 $dn = $attrs['dn'];
1756 $attrs = $this->cleanup_array($attrs);
1757 $member_new = array($destination);
1758 foreach($attrs['member'] as $member){
1759 if($member != $source){
1760 $member_new[] = $member;
1761 }
1762 }
1763 $attrs['member'] = $member_new;
1764 $ogs_to_fix[$dn] = $attrs;
1765 }
1767 /* Copy source to destination dn */
1768 $ldap->cat($source);
1769 $new_data = $this->cleanup_array($ldap->fetch());
1770 $ldap->cd($destination);
1771 $res = $ldap->add($new_data);
1773 /* Display warning if copy failed */
1774 if(!$res){
1775 print_red(_("Failed to copy '%s' to '%s'. LDAP says '%s'."),$source,$destination,$ldap->get_error());
1776 }else{
1777 $res = $ldap->rmDir($source);
1778 show_ldap_error($ldap->get_error(),_("Something went wrong while copying dns."));
1780 /* Object is copied, so update its references */
1781 foreach($ogs_to_fix as $dn => $data){
1782 $ldap->cd($dn);
1783 $ldap->modify($data);
1784 }
1785 }
1786 }
1789 /* Cleanup ldap result to be able to write it be to ldap */
1790 function cleanup_array($attrs)
1791 {
1792 foreach($attrs as $key => $value) {
1793 if(is_numeric($key) || in_array($key,array("count","dn"))){
1794 unset($attrs[$key]);
1795 }
1796 if(is_array($value) && isset($value['count'])){
1797 unset($attrs[$key]['count']);
1798 }
1799 }
1800 return($attrs);
1801 }
1802 }
1804 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1805 ?>