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_type = "group";
71 var $acl_create_selected= ""; // Currently selected element, that should receive admin rights
72 var $acl_create_changes = ""; // Contains ldif information about changes
73 var $acl_create_confirmed= FALSE;
75 /* Checks initialised ? */
76 var $checks_initialised = FALSE;
78 /* Users outside to people ou */
79 var $outside_users = array();
80 var $outside_users_dialog = FALSE;
82 /* Users outside to groups ou */
83 var $outside_groups = array();
84 var $outside_groups_dialog = FALSE;
86 /* Win-Workstations outside to reserved ou */
87 var $outside_winstations = array();
88 var $outside_winstations_dialog = FALSE;
90 /* check for multiple use of same uidNumber */
91 var $check_uidNumbers = array();
92 var $check_uidNumbers_dialog = FALSE;
94 /* check for multiple use of same gidNumber */
95 var $check_gidNumbers = array();
96 var $check_gidNumbers_dialog = FALSE;
99 function Step_Migrate()
100 {
101 $this->update_strings();
102 }
104 function update_strings()
105 {
106 $this->s_title = _("LDAP inspection");
107 $this->s_title_long = _("LDAP inspection");
108 $this->s_info = _("Analyze your current LDAP for GOsa compatibility");
109 }
111 function initialize_checks()
112 {
113 $this->checks = array();
114 $this->checks['root']['TITLE'] = _("Checking for root object");
115 $this->checks['root']['STATUS'] = FALSE;
116 $this->checks['root']['STATUS_MSG']= "";
117 $this->checks['root']['ERROR_MSG'] = "";
118 $this->checkBase();
120 $this->checks['permissions']['TITLE'] = _("Checking permissions on LDAP database");
121 $this->checks['permissions']['STATUS'] = FALSE;
122 $this->checks['permissions']['STATUS_MSG']= "";
123 $this->checks['permissions']['ERROR_MSG'] = "";
124 $this->check_ldap_permissions();
126 $this->checks['deps_visible']['TITLE'] = _("Checking for invisible deparmtments");
127 $this->checks['deps_visible']['STATUS'] = FALSE;
128 $this->checks['deps_visible']['STATUS_MSG']= "";
129 $this->checks['deps_visible']['ERROR_MSG'] = "";
130 $this->check_organizationalUnits();
132 $this->checks['users_visible']['TITLE'] = _("Checking for invisible users");
133 $this->checks['users_visible']['STATUS'] = FALSE;
134 $this->checks['users_visible']['STATUS_MSG']= "";
135 $this->checks['users_visible']['ERROR_MSG'] = "";
136 $this->check_gosaAccounts();
138 $this->checks['acls']['TITLE'] = _("Checking for super administrator");
139 $this->checks['acls']['STATUS'] = FALSE;
140 $this->checks['acls']['STATUS_MSG']= "";
141 $this->checks['acls']['ERROR_MSG'] = "";
142 $this->check_administrativeAccount();
144 $this->checks['outside_users']['TITLE'] = _("Checking for users outside the people tree");
145 $this->checks['outside_users']['STATUS'] = FALSE;
146 $this->checks['outside_users']['STATUS_MSG']= "";
147 $this->checks['outside_users']['ERROR_MSG'] = "";
148 $this->search_outside_users();
150 $this->checks['outside_groups']['TITLE'] = _("Checking for groups outside the groups tree");
151 $this->checks['outside_groups']['STATUS'] = FALSE;
152 $this->checks['outside_groups']['STATUS_MSG']= "";
153 $this->checks['outside_groups']['ERROR_MSG'] = "";
154 $this->search_outside_groups();
156 $this->checks['outside_winstations']['TITLE'] = _("Checking for windows workstations outside the winstation tree");
157 $this->checks['outside_winstations']['STATUS'] = FALSE;
158 $this->checks['outside_winstations']['STATUS_MSG']= "";
159 $this->checks['outside_winstations']['ERROR_MSG'] = "";
160 $this->search_outside_winstations();
162 $this->checks['uidNumber_usage']['TITLE'] = _("Checking for duplicate uid numbers");
163 $this->checks['uidNumber_usage']['STATUS'] = FALSE;
164 $this->checks['uidNumber_usage']['STATUS_MSG']= "";
165 $this->checks['uidNumber_usage']['ERROR_MSG'] = "";
166 $this->check_uidNumber();
168 $this->checks['gidNumber_usage']['TITLE'] = _("Checking for duplicate gid numbers");
169 $this->checks['gidNumber_usage']['STATUS'] = FALSE;
170 $this->checks['gidNumber_usage']['STATUS_MSG']= "";
171 $this->checks['gidNumber_usage']['ERROR_MSG'] = "";
172 $this->check_gidNumber();
173 }
176 /* Check if there are uidNumbers which are used more than once.
177 */
178 function check_uidNumber()
179 {
180 $cv = $this->parent->captured_values;
181 $ldap = new LDAP($cv['admin'],
182 $cv['password'],
183 $cv['connection'],
184 FALSE,
185 $cv['tls']);
187 $ldap->cd($cv['base']);
188 $res = $ldap->search("uidNumber=*",array("dn","uidNumber"));
189 if(!$res){
190 $this->checks['uidNumber_usage']['STATUS'] = FALSE;
191 $this->checks['uidNumber_usage']['STATUS_MSG']= _("LDAP query failed");
192 $this->checks['uidNumber_usage']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
193 return(false);
194 }
196 $this->check_uidNumbers= array();
197 $tmp = array();
198 while($attrs = $ldap->fetch()){
199 $tmp[$attrs['uidNumber'][0]][] = $attrs;
200 }
202 foreach($tmp as $id => $entries){
203 if(count($entries) > 1){
204 foreach($entries as $entry){
205 $this->check_uidNumbers[base64_encode($entry['dn'])] = $entry;
206 }
207 }
208 }
210 if($this->check_uidNumbers){
211 $this->checks['uidNumber_usage']['STATUS'] = FALSE;
212 $this->checks['uidNumber_usage']['STATUS_MSG']= "<font style='color:#F0A500'>"._("Warning")."</font>";
213 $this->checks['uidNumber_usage']['ERROR_MSG'] =
214 sprintf(_("Found %s duplicate values for attribute 'uidNumber'."),count($this->check_uidNumbers));
215 return(false);
216 }else{
217 $this->checks['uidNumber_usage']['STATUS'] = TRUE;
218 $this->checks['uidNumber_usage']['STATUS_MSG']= _("Ok");
219 $this->checks['uidNumber_usage']['ERROR_MSG'] = "";
220 return(TRUE);
221 }
222 }
225 /* Check if there are duplicated gidNumbers present in ldap
226 */
227 function check_gidNumber()
228 {
229 $cv = $this->parent->captured_values;
230 $ldap = new LDAP($cv['admin'],
231 $cv['password'],
232 $cv['connection'],
233 FALSE,
234 $cv['tls']);
236 $ldap->cd($cv['base']);
237 $res = $ldap->search("(&(objectClass=posixGroup)(gidNumber=*))",array("dn","gidNumber"));
238 if(!$res){
239 $this->checks['gidNumber_usage']['STATUS'] = FALSE;
240 $this->checks['gidNumber_usage']['STATUS_MSG']= _("LDAP query failed");
241 $this->checks['gidNumber_usage']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
242 return(false);
243 }
245 $this->check_gidNumbers= array();
246 $tmp = array();
247 while($attrs = $ldap->fetch()){
248 $tmp[$attrs['gidNumber'][0]][] = $attrs;
249 }
251 foreach($tmp as $id => $entries){
252 if(count($entries) > 1){
253 foreach($entries as $entry){
254 $this->check_gidNumbers[base64_encode($entry['dn'])] = $entry;
255 }
256 }
257 }
259 if($this->check_gidNumbers){
260 $this->checks['gidNumber_usage']['STATUS'] = FALSE;
261 $this->checks['gidNumber_usage']['STATUS_MSG']= "<font style='color:#F0A500'>"._("Warning")."</font>";
262 $this->checks['gidNumber_usage']['ERROR_MSG'] =
263 sprintf(_("Found %s duplicate values for attribute 'gidNumber'."),count($this->check_gidNumbers));
264 return(false);
265 }else{
266 $this->checks['gidNumber_usage']['STATUS'] = TRUE;
267 $this->checks['gidNumber_usage']['STATUS_MSG']= _("Ok");
268 $this->checks['gidNumber_usage']['ERROR_MSG'] = "";
269 return(TRUE);
270 }
271 }
274 /* Search for winstations outside the winstation ou
275 */
276 function search_outside_winstations()
277 {
278 $cv = $this->parent->captured_values;
279 $ldap = new LDAP($cv['admin'],
280 $cv['password'],
281 $cv['connection'],
282 FALSE,
283 $cv['tls']);
285 /* Get winstation ou */
286 if($cv['generic_settings']['wws_ou_active']) {
287 $winstation_ou = $cv['generic_settings']['ws_ou'];
288 }else{
289 $winstation_ou = "ou=winstations";
290 }
292 if($cv['samba_version'] == 3){
293 $oc = "sambaSamAccount";
294 }else{
295 $oc = "sambaAccount";
296 }
298 $ldap->cd($cv['base']);
299 $res = $ldap->search("(&(objectClass=".$oc.")(uid=*$))",array("dn","sambaSID"));
300 if(!$res){
301 $this->checks['outside_winstations']['STATUS'] = FALSE;
302 $this->checks['outside_winstations']['STATUS_MSG']= _("LDAP query failed");
303 $this->checks['outside_winstations']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
304 return(false);
305 }
307 $this->outside_winstations = array();
308 while($attrs = $ldap->fetch()){
309 if((!preg_match("/^[^,]+,".normalizePreg($winstation_ou)."/",$attrs['dn'])) && !preg_match("/,dc=addressbook,/",$attrs['dn'])){
310 $attrs['selected'] = FALSE;
311 $attrs['ldif'] = "";
312 $this->outside_winstations[base64_encode($attrs['dn'])] = $attrs;
313 }
314 }
316 if(count($this->outside_winstations)){
317 $this->checks['outside_winstations']['STATUS'] = FALSE;
318 $this->checks['outside_winstations']['STATUS_MSG']= _("Failed");
319 $this->checks['outside_winstations']['ERROR_MSG'] =
320 sprintf(_("Found %s winstations outside the predefined winstation department ou '%s'."),count($this->outside_winstations),$winstation_ou);
321 $this->checks['outside_winstations']['ERROR_MSG'].= "<input type='submit' name='outside_winstations_dialog' value='"._("Migrate")."...'>";
322 return(false);
323 }else{
324 $this->checks['outside_winstations']['STATUS'] = TRUE;
325 $this->checks['outside_winstations']['STATUS_MSG']= _("Ok");
326 $this->checks['outside_winstations']['ERROR_MSG'] = "";
327 return(TRUE);
328 }
329 }
332 /* Search for groups outside the group ou
333 */
334 function search_outside_groups()
335 {
336 $cv = $this->parent->captured_values;
337 $ldap = new LDAP($cv['admin'],
338 $cv['password'],
339 $cv['connection'],
340 FALSE,
341 $cv['tls']);
343 $group_ou = $cv['groupou'];
344 $ldap->cd($cv['base']);
345 $res = $ldap->search("(objectClass=posixGroup)",array("dn"));
346 if(!$res){
347 $this->checks['outside_groups']['STATUS'] = FALSE;
348 $this->checks['outside_groups']['STATUS_MSG']= _("LDAP query failed");
349 $this->checks['outside_groups']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
350 return(false);
351 }
354 $this->outside_groups = array();
355 while($attrs = $ldap->fetch()){
356 if((!preg_match("/^[^,]+,".normalizePreg($group_ou)."/",$attrs['dn'])) && !preg_match("/,dc=addressbook,/",$attrs['dn'])){
357 $attrs['selected'] = FALSE;
358 $attrs['ldif'] = "";
359 $this->outside_groups[base64_encode($attrs['dn'])] = $attrs;
360 }
361 }
363 if(count($this->outside_groups)){
364 $this->checks['outside_groups']['STATUS'] = FALSE;
365 $this->checks['outside_groups']['STATUS_MSG']= "<font style='color:#F0A500'>"._("Warning")."</font>";
366 $this->checks['outside_groups']['ERROR_MSG'] =
367 sprintf(_("Found %s groups outside the configured tree '%s'."),count($this->outside_groups),$group_ou);
368 $this->checks['outside_groups']['ERROR_MSG'].= " <input type='submit' name='outside_groups_dialog' value='"._("Move")."...'>";
369 return(false);
370 }else{
371 $this->checks['outside_groups']['STATUS'] = TRUE;
372 $this->checks['outside_groups']['STATUS_MSG']= _("Ok");
373 $this->checks['outside_groups']['ERROR_MSG'] = "";
374 return(TRUE);
375 }
376 }
379 /* Search for users outside the people ou
380 */
381 function search_outside_users()
382 {
383 $cv = $this->parent->captured_values;
384 $ldap = new LDAP($cv['admin'],
385 $cv['password'],
386 $cv['connection'],
387 FALSE,
388 $cv['tls']);
389 $people_ou = $cv['peopleou'];
390 $ldap->cd($cv['base']);
391 $res = $ldap->search("(&(objectClass=gosaAccount)(!(uid=*$)))",array("dn"));
392 if(!$res){
393 $this->checks['outside_users']['STATUS'] = FALSE;
394 $this->checks['outside_users']['STATUS_MSG']= _("LDAP query failed");
395 $this->checks['outside_users']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
396 return(false);
397 }
400 $this->outside_users = array();
401 while($attrs = $ldap->fetch()){
402 if((!preg_match("/^[^,]+,".normalizePreg($people_ou)."/",$attrs['dn']) && !preg_match("/,dc=addressbook,/",$attrs['dn']))){
403 $attrs['selected'] = FALSE;
404 $attrs['ldif'] = "";
405 $this->outside_users[base64_encode($attrs['dn'])] = $attrs;
406 }
407 }
409 if(count($this->outside_users)){
410 $this->checks['outside_users']['STATUS'] = FALSE;
411 $this->checks['outside_users']['STATUS_MSG']= "<font style='color:#F0A500'>"._("Warning")."</font>";
412 $this->checks['outside_users']['ERROR_MSG'] =
413 sprintf(_("Found %s user(s) outside the configured tree '%s'."),count($this->outside_users),$people_ou);
414 $this->checks['outside_users']['ERROR_MSG'].= "<input type='submit' name='outside_users_dialog' value='"._("Move")."...'>";
415 return(false);
416 }else{
417 $this->checks['outside_users']['STATUS'] = TRUE;
418 $this->checks['outside_users']['STATUS_MSG']= _("Ok");
419 $this->checks['outside_users']['ERROR_MSG'] = "";
420 return(TRUE);
421 }
422 }
425 /* Check ldap accessibility
426 * Create and remove a dummy object,
427 * to ensure that we have the necessary permissions
428 */
429 function check_ldap_permissions()
430 {
431 $cv = $this->parent->captured_values;
432 $ldap = new LDAP($cv['admin'],
433 $cv['password'],
434 $cv['connection'],
435 FALSE,
436 $cv['tls']);
438 /* Create dummy entry
439 */
440 $name = "GOsa_setup_text_entry_".session_id().rand(0,999999);
441 $dn = "ou=".$name.",".$cv['base'];
442 $testEntry= array();
443 $testEntry['objectClass'][]= "top";
444 $testEntry['objectClass'][]= "organizationalUnit";
445 $testEntry['objectClass'][]= "gosaDepartment";
446 $testEntry['description']= "Created by GOsa setup, this object can be removed.";
447 $testEntry['ou'] = $name;
449 /* check if simple ldap cat will be successful
450 */
451 $res = $ldap->cat($cv['base']);
452 if(!$res){
453 $this->checks['permissions']['STATUS'] = FALSE;
454 $this->checks['permissions']['STATUS_MSG']= _("LDAP query failed");
455 $this->checks['permissions']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
456 return(false);
457 }
459 /* Try to create dummy object
460 */
461 $ldap->cd ($dn);
462 $ldap->create_missing_trees($dn);
463 $res = $ldap->add($testEntry);
464 $ldap->cat($dn);
465 if(!$ldap->count()){
466 gosa_log($ldap->get_error());
467 $this->checks['permissions']['STATUS'] = FALSE;
468 $this->checks['permissions']['STATUS_MSG']= _("Failed");
469 $this->checks['permissions']['ERROR_MSG'] =
470 sprintf(_("The specified user '%s' does not have full access to your ldap database."),$cv['admin']);
471 return(false);
472 }
474 /* Try to remove created entry
475 */
476 $res = $ldap->rmDir($dn);
477 $ldap->cat($dn);
478 if($ldap->count()){
479 gosa_log($ldap->get_error());
480 $this->checks['permissions']['STATUS'] = FALSE;
481 $this->checks['permissions']['STATUS_MSG']= _("Failed");
482 $this->checks['permissions']['ERROR_MSG'] =
483 sprintf(_("The specified user '%s' does not have full access to your ldap database."),$cv['admin']);
484 return(false);
485 }
487 /* Create & remove of dummy object was successful */
488 $this->checks['permissions']['STATUS'] = TRUE;
489 $this->checks['permissions']['STATUS_MSG']= _("Ok");
490 $this->checks['permissions']['ERROR_MSG'] = "";
491 return(true);
492 }
495 /* Check if there are users which will
496 * be invisible for GOsa
497 */
498 function check_gosaAccounts()
499 {
500 /* Remember old list of ivisible users, to be able to set
501 * the 'html checked' status for the checkboxes again
502 */
503 $cnt_ok = 0;
504 $old = $this->users_to_migrate;
505 $this->users_to_migrate = array();
507 /* Get collected configuration settings */
508 $cv = $this->parent->captured_values;
510 /* Establish ldap connection */
511 $ldap = new LDAP($cv['admin'],
512 $cv['password'],
513 $cv['connection'],
514 FALSE,
515 $cv['tls']);
517 /* Get all invisible users
518 */
519 $ldap->cd($cv['base']);
520 $res =$ldap->search("(&(|(objectClass=posixAccount)(&(objectClass=inetOrgPerson)(objectClass=organizationalPerson)))(!(objectClass=gosaAccount))(uid=*))",array("sn","givenName","cn","uid"));
521 while($attrs = $ldap->fetch()){
522 if(!preg_match("/,dc=addressbook,/",$attrs['dn'])){
523 $attrs['checked'] = FALSE;
524 $attrs['before'] = "";
525 $attrs['after'] = "";
527 /* Set objects to selected, that were selected before reload */
528 if(isset($old[base64_encode($attrs['dn'])])){
529 $attrs['checked'] = $old[base64_encode($attrs['dn'])]['checked'];
530 }
531 $this->users_to_migrate[base64_encode($attrs['dn'])] = $attrs;
532 }
533 }
535 /* No invisible */
536 if(!$res){
537 $this->checks['users_visible']['STATUS'] = FALSE;
538 $this->checks['users_visible']['STATUS_MSG']= _("LDAP query failed");
539 $this->checks['users_visible']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
540 }elseif(count($this->users_to_migrate) == 0){
541 $this->checks['users_visible']['STATUS'] = TRUE;
542 $this->checks['users_visible']['STATUS_MSG']= _("Ok");
543 $this->checks['users_visible']['ERROR_MSG'] = "";
544 }else{
545 $this->checks['users_visible']['STATUS'] = FALSE;
546 $this->checks['users_visible']['STATUS_MSG']= "<font style='color:#F0A500'>"._("Warning")."</font>";
547 $this->checks['users_visible']['ERROR_MSG'] = sprintf(_("Found %s user(s) that will not be visible in GOsa."),
548 count($this->users_to_migrate));
549 $this->checks['users_visible']['ERROR_MSG'] .= "<input type='submit' name='users_visible_migrate' value='"._("Migrate")."...'>";
550 }
551 }
554 /* Start user account migration
555 */
556 function migrate_gosaAccounts($only_ldif = FALSE)
557 {
558 $this->show_details= $only_ldif;
560 /* Get collected configuration settings */
561 $cv = $this->parent->captured_values;
563 /* Establish ldap connection */
564 $ldap = new LDAP($cv['admin'],
565 $cv['password'],
566 $cv['connection'],
567 FALSE,
568 $cv['tls']);
570 /* Add gosaAccount objectClass to the selected users
571 */
572 foreach($this->users_to_migrate as $key => $dep){
573 if($dep['checked']){
575 /* Get old objectClasses */
576 $ldap->cat($dep['dn'],array("objectClass"));
577 $attrs = $ldap->fetch();
579 /* Create new objectClass array */
580 $new_attrs = array();
581 $new_attrs['objectClass']= array("gosaAccount","inetOrgPerson","organizationalPerson");
582 for($i = 0 ; $i < $attrs['objectClass']['count']; $i ++ ){
583 if(!in_array_ics($attrs['objectClass'][$i], $new_attrs['objectClass'])){
584 $new_attrs['objectClass'][] = $attrs['objectClass'][$i];
585 }
586 }
588 /* Set info attributes for current object,
589 * or write changes to the ldap database
590 */
591 if($only_ldif){
592 $this->users_to_migrate[$key]['before'] = $this->array_to_ldif($attrs);
593 $this->users_to_migrate[$key]['after'] = $this->array_to_ldif($new_attrs);
594 }else{
595 $ldap->cd($attrs['dn']);
596 if(!$ldap->modify($new_attrs)){
597 print_red(sprintf(_("Failed to migrate the department '%s' into GOsa, error message is as follows '%s'."),$attrs['dn'],$ldap->get_error()));
598 return(false);
599 }
600 }
601 }
602 }
603 return(TRUE);
604 }
607 /* Check if there are invisible organizational Units
608 */
609 function check_organizationalUnits()
610 {
611 $cnt_ok = 0;
612 $old = $this->deps_to_migrate;
613 $this->deps_to_migrate = array();
615 /* Get collected configuration settings */
616 $cv = $this->parent->captured_values;
618 /* Establish ldap connection */
619 $ldap = new LDAP($cv['admin'],
620 $cv['password'],
621 $cv['connection'],
622 FALSE,
623 $cv['tls']);
625 /* Skip GOsa internal departments */
626 $skip_dns = array("/^ou=people,/","/^ou=groups,/","/(,|)ou=configs,/","/(,|)ou=systems,/",
627 "/^ou=apps,/","/^ou=mime,/","/^ou=aclroles,/","/^ou=incoming,/",
628 "/ou=snapshots,/","/(,|)dc=addressbook,/","/^(,|)ou=machineaccounts,/",
629 "/(,|)ou=winstations,/");
632 /* Get all invisible departments */
633 $ldap->cd($cv['base']);
634 $res = $ldap->search("(&(objectClass=organizationalUnit)(!(objectClass=gosaDepartment)))",array("ou","description","dn"));
635 while($attrs = $ldap->fetch()){
636 $attrs['checked'] = FALSE;
637 $attrs['before'] = "";
638 $attrs['after'] = "";
640 /* Set objects to selected, that were selected before reload */
641 if(isset($old[base64_encode($attrs['dn'])])){
642 $attrs['checked'] = $old[base64_encode($attrs['dn'])]['checked'];
643 }
644 $this->deps_to_migrate[base64_encode($attrs['dn'])] = $attrs;
645 }
647 /* Filter returned list of departments and ensure that
648 * GOsa internal departments will not be listed
649 */
650 foreach($this->deps_to_migrate as $key => $attrs){
651 $dn = $attrs['dn'];
652 $skip = false;
653 foreach($skip_dns as $skip_dn){
654 if(preg_match($skip_dn,$dn)){
655 $skip = true;
656 }
657 }
658 if($skip){
659 unset($this->deps_to_migrate[$key]);
660 }
661 }
663 /* If we have no invisible departments found
664 * tell the user that everything is ok
665 */
666 if(!$res){
667 $this->checks['deps_visible']['STATUS'] = FALSE;
668 $this->checks['deps_visible']['STATUS_MSG']= _("LDAP query failed");
669 $this->checks['deps_visible']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
670 }elseif(count($this->deps_to_migrate) == 0 ){
671 $this->checks['deps_visible']['STATUS'] = TRUE;
672 $this->checks['deps_visible']['STATUS_MSG']= _("Ok");
673 $this->checks['deps_visible']['ERROR_MSG'] = "";
674 }else{
675 $this->checks['deps_visible']['STATUS'] = TRUE;
676 $this->checks['deps_visible']['STATUS_MSG']= '<font style="color:#FFA500">'._("Warning").'</font>';
677 $this->checks['deps_visible']['ERROR_MSG'] = sprintf(_("Found %s department(s) that will not be visible in GOsa."),count($this->deps_to_migrate));
678 $this->checks['deps_visible']['ERROR_MSG'] .= " <input type='submit' name='deps_visible_migrate' value='"._("Migrate")."...'>";
679 }
680 }
684 /* Start deparmtment migration */
685 function migrate_organizationalUnits($only_ldif = FALSE)
686 {
687 $this->show_details= $only_ldif;
689 /* Get collected configuration settings */
690 $cv = $this->parent->captured_values;
692 /* Establish ldap connection */
693 $ldap = new LDAP($cv['admin'],
694 $cv['password'],
695 $cv['connection'],
696 FALSE,
697 $cv['tls']);
699 /* Add gosaDepartment objectClass to each selected entry
700 */
701 foreach($this->deps_to_migrate as $key => $dep){
702 if($dep['checked']){
704 /* Get current objectClasses */
705 $ldap->cat($dep['dn'],array("objectClass","description"));
706 $attrs = $ldap->fetch();
708 /* Create new objectClass attribute including gosaDepartment*/
709 $new_attrs = array();
710 for($i = 0 ; $i < $attrs['objectClass']['count']; $i ++ ){
711 $new_attrs['objectClass'][] = $attrs['objectClass'][$i];
712 }
713 $new_attrs['objectClass'][] = "gosaDepartment";
715 /* Append description it is missing */
716 if(!isset($attrs['description'])){
717 $new_attrs['description'][] = "GOsa department";
718 }
720 /* Depending on the parameter >only_diff< we save the changes as ldif
721 * or we write our changes directly to the ldap database
722 */
723 if($only_ldif){
724 $this->deps_to_migrate[$key]['before'] = $this->array_to_ldif($attrs);
725 $this->deps_to_migrate[$key]['after'] = $this->array_to_ldif($new_attrs);
726 }else{
727 $ldap->cd($attrs['dn']);
728 if(!$ldap->modify($new_attrs)){
729 print_red(sprintf(_("Failed to migrate the department '%s' into GOsa, error message is as follows '%s'."),$attrs['dn'],$ldap->get_error()));
730 return(false);
731 }
732 }
733 }
734 }
735 return(TRUE);
736 }
739 /* Check Acls if there is at least one object with acls defined
740 */
741 function check_administrativeAccount()
742 {
743 /* Establish ldap connection */
744 $cv = $this->parent->captured_values;
745 $ldap = new LDAP($cv['admin'],
746 $cv['password'],
747 $cv['connection'],
748 FALSE,
749 $cv['tls']);
751 /* Search for gosaAcls */
752 $ldap->cd($cv['base']);
753 $res = $ldap->cat($cv['base']);
755 if(!$res){
756 $this->checks['acls']['STATUS'] = FALSE;
757 $this->checks['acls']['STATUS_MSG']= _("LDAP query failed");
758 $this->checks['acls']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
759 }else{
760 $found = false;
761 $username = "";
762 $attrs = $ldap->fetch();
763 if(isset($attrs['gosaAclEntry'])){
764 $acls = $attrs['gosaAclEntry'];
765 for($i = 0 ; $i < $acls['count'] ; $i++){
766 $acl = $acls[$i];
767 $tmp = split(":",$acl);
768 if($tmp[1] == "psub"){
769 $members = split(",",$tmp[2]);
770 foreach($members as $member){
771 $member = base64_decode($member);
773 /* Check if acl owner is a valid GOsa user account */
774 $ldap->cat($member,array("objectClass","uid","cn"));
775 $ret = $ldap->fetch();
777 if(isset($ret['objectClass']) && in_array("posixGroup",$ret['objectClass'])){
778 $found = TRUE;
779 $username .= _("ACL-Group").": ".$ret['cn'][0]."<br>";
780 }elseif(isset($ret['objectClass']) && in_array("gosaAccount",$ret['objectClass']) &&
781 in_array("organizationalPerson",$ret['objectClass']) &&
782 in_array("inetOrgPerson",$ret['objectClass'])){
783 $found = TRUE;
784 $username .= _("ACL").": ".$ret['uid'][0]."<br>";
785 }
786 }
787 }elseif($tmp[1] == "role"){
789 /* Check if acl owner is a valid GOsa user account */
790 $ldap->cat(base64_decode($tmp[2]),array("gosaAclTemplate"));
791 $ret = $ldap->fetch();
793 if(isset($ret['gosaAclTemplate'])){
794 $cnt = $ret['gosaAclTemplate']['count'];
795 for($e = 0 ; $e < $cnt ; $e++){
797 $a_str = $ret['gosaAclTemplate'][$e];
798 if(preg_match("/^[0-9]*:psub:/",$a_str) && preg_match("/:all;cmdrw$/",$a_str)){
800 $members = split(",",$tmp[3]);
801 foreach($members as $member){
802 $member = base64_decode($member);
804 /* Check if acl owner is a valid GOsa user account */
805 $ldap->cat($member,array("objectClass","uid"));
806 $ret = $ldap->fetch();
808 if(isset($ret['objectClass']) && in_array("gosaAccount",$ret['objectClass']) &&
809 in_array("organizationalPerson",$ret['objectClass']) &&
810 in_array("inetOrgPerson",$ret['objectClass'])){
811 $found = TRUE;
812 $username .= _("ACL Role").": ".$ret['uid'][0]."<br>";
813 }
814 }
815 }
816 }
817 }
818 }
819 }
820 }
822 # For debugging
823 #echo $username;
825 if($found){
826 $this->checks['acls']['STATUS'] = TRUE;
827 $this->checks['acls']['STATUS_MSG']= _("Ok")." ";
828 $this->checks['acls']['ERROR_MSG'] = "";
829 }else{
830 $this->checks['acls']['STATUS'] = FALSE;
831 $this->checks['acls']['STATUS_MSG']= _("Failed");
832 $this->checks['acls']['ERROR_MSG']= _("There is no GOsa administrator account inside your LDAP.")." ";
833 $this->checks['acls']['ERROR_MSG'].= "<input type='submit' name='create_acls' value='"._("Create")."'>";
834 }
835 }
836 return($ldap->count()>=1);
837 }
841 function create_admin($only_ldif = FALSE)
842 {
843 /* Reset '' */
844 $this->acl_create_changes="";
846 /* Object that should receive admin acls */
847 $dn = $this->acl_create_selected;
849 /* Get collected configuration settings */
850 $cv = $this->parent->captured_values;
852 /* Establish ldap connection */
853 $ldap = new LDAP($cv['admin'],
854 $cv['password'],
855 $cv['connection'],
856 FALSE,
857 $cv['tls']);
859 /* Get current base attributes */
860 $ldap->cd($cv['base']);
861 $ldap->cat($cv['base'],array("dn","objectClass","gosaAclEntry"));
862 $attrs = $ldap->fetch();
864 /* Add acls for the selcted user to the base */
865 $attrs_new['objectClass'] = array("gosaACL");
867 for($i = 0; $i < $attrs['objectClass']['count']; $i ++){
868 if(!in_array_ics($attrs['objectClass'][$i],$attrs_new['objectClass'])){
869 $attrs_new['objectClass'][] = $attrs['objectClass'][$i];
870 }
871 }
873 $acl = "0:psub:".base64_encode($dn).":all;cmdrw";
874 $attrs_new['gosaAclEntry'][] = $acl;
875 if(isset($attrs['gosaAclEntry'])){
876 for($i = 0 ; $i < $attrs['gosaAclEntry']['count']; $i ++){
878 $prio = preg_replace("/[:].*$/","",$attrs['gosaAclEntry'][$i]);
879 $rest = preg_replace("/^[^:]/","",$attrs['gosaAclEntry'][$i]);
881 $data = ($prio+1).$rest;
882 $attrs_new['gosaAclEntry'][] = $data;
883 }
884 }
886 if($only_ldif){
887 $this->acl_create_changes ="\n".$cv['base']."\n";
888 $this->acl_create_changes.=$this->array_to_ldif($attrs)."\n";
889 $this->acl_create_changes.="\n".$cv['base']."\n";
890 $this->acl_create_changes.=$this->array_to_ldif($attrs_new);
891 }else{
893 $ldap->cd($cv['base']);
894 if(!$ldap->modify($attrs_new)){
895 print_red(sprintf(_("Adding acls for user '%s' failed, ldap says '%s'."),$dn,$ldap->get_error()));
896 return(FALSE);
897 }else{
898 return(TRUE);
899 }
900 }
901 }
904 function create_admin_user()
905 {
906 $pw1 = $pw2 = "";
908 if(isset($_POST['new_user_password'])){
909 $pw1 = $_POST['new_user_password'];
910 }
911 if(isset($_POST['new_user_password2'])){
912 $pw2 = $_POST['new_user_password2'];
913 }
915 if(empty($pw1) || empty($pw2) | ($pw1 != $pw2)){
916 print_red(_("Specified passwords are empty or not equal."));
917 return false;
918 }
920 /* Establish ldap connection */
921 $cv = $this->parent->captured_values;
922 $ldap = new LDAP($cv['admin'],
923 $cv['password'],
924 $cv['connection'],
925 FALSE,
926 $cv['tls']);
928 /* Get current base attributes */
929 $ldap->cd($cv['base']);
931 if($cv['peopledn'] == "cn"){
932 $dn = "cn=System Administrator,".$cv['peopleou'].",".$cv['base'];
933 }else{
934 $dn = "uid=admin,".$cv['peopleou'].",".$cv['base'];
935 }
937 $methods = @passwordMethod::get_available_methods_if_not_loaded();
938 $p_m = $methods[$cv['encryption']];
939 $p_c = new $p_m(array());
940 $hash = $p_c->generate_hash($pw2);
942 $new_user=array();
943 $new_user['objectClass']= array("top","person","gosaAccount","organizationalPerson","inetOrgPerson");
944 $new_user['givenName'] = "System";
945 $new_user['sn'] = "Administrator";
946 $new_user['cn'] = "System Administrator";
947 $new_user['uid'] = "admin";
948 $new_user['userPassword'] = $hash;
950 $ldap->cd($cv['base']);
951 $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$dn));
952 $ldap->cd($dn);
953 $res = $ldap->add($new_user);
954 $this->acl_create_selected = $dn;
955 $this->create_admin();
957 if(!$res){
958 print_red($ldap->get_error());
959 return(FALSE);
960 }
962 $this->acl_create_dialog=FALSE;
963 $this->check_administrativeAccount();
964 return(TRUE);
965 }
968 function migrate_outside_winstations($perform = FALSE)
969 {
970 /* Establish ldap connection */
971 $cv = $this->parent->captured_values;
972 $ldap = new LDAP($cv['admin'],
973 $cv['password'],
974 $cv['connection'],
975 FALSE,
976 $cv['tls']);
978 $ldap->cd($cv['base']);
980 /* Check if there was a destination department posted */
981 if(isset($_POST['move_winstation_to'])){
982 $destination_dep = $_POST['move_winstation_to'];
983 }else{
984 print_red(_("Couldn't move users to specified department."));
985 return(false);
986 }
988 foreach($this->outside_winstations as $b_dn => $data){
989 $this->outside_winstations[$b_dn]['ldif'] ="";
990 if($data['selected']){
991 $dn = base64_decode($b_dn);
992 $d_dn = preg_replace("/,.*$/",",".base64_decode($destination_dep),$dn);
993 if(!$perform){
994 $this->outside_winstations[$b_dn]['ldif'] = _("Winstation will be moved from").":<br>\t".$dn."<br>"._("to").":<br>\t".$d_dn;
997 /* Check if there are references to this object */
998 $ldap->search("(&(member=".$dn.")(|(objectClass=gosaGroupOfNames)(objectClass=groupOfNames)))",array('dn'));
999 $refs = "";
1000 while($attrs = $ldap->fetch()){
1001 $ref_dn = $attrs['dn'];
1002 $refs .= "<br />\t".$ref_dn;
1003 }
1004 if(!empty($refs)){
1005 $this->outside_winstations[$b_dn]['ldif'] .= "<br /><br /><i>"._("Updating following references too").":</i>".$refs;
1006 }
1008 }else{
1009 $this->move($dn,$d_dn);
1010 }
1011 }
1012 }
1013 }
1016 function migrate_outside_groups($perform = FALSE)
1017 {
1018 /* Establish ldap connection */
1019 $cv = $this->parent->captured_values;
1020 $ldap = new LDAP($cv['admin'],
1021 $cv['password'],
1022 $cv['connection'],
1023 FALSE,
1024 $cv['tls']);
1026 $ldap->cd($cv['base']);
1028 /* Check if there was a destination department posted */
1029 if(isset($_POST['move_group_to'])){
1030 $destination_dep = $_POST['move_group_to'];
1031 }else{
1032 print_red(_("Couldn't move users to specified department."));
1033 return(false);
1034 }
1036 foreach($this->outside_groups as $b_dn => $data){
1037 $this->outside_groups[$b_dn]['ldif'] ="";
1038 if($data['selected']){
1039 $dn = base64_decode($b_dn);
1040 $d_dn = preg_replace("/,.*$/",",".base64_decode($destination_dep),$dn);
1041 if(!$perform){
1042 $this->outside_groups[$b_dn]['ldif'] = _("Group will be moved from").":<br>\t".$dn."<br>"._("to").":<br>\t".$d_dn;
1045 /* Check if there are references to this object */
1046 $ldap->search("(&(member=".$dn.")(|(objectClass=gosaGroupOfNames)(objectClass=groupOfNames)))",array('dn'));
1047 $refs = "";
1048 while($attrs = $ldap->fetch()){
1049 $ref_dn = $attrs['dn'];
1050 $refs .= "<br />\t".$ref_dn;
1051 }
1052 if(!empty($refs)){
1053 $this->outside_groups[$b_dn]['ldif'] .= "<br /><br /><i>"._("Updating following references too").":</i>".$refs;
1054 }
1056 }else{
1057 $this->move($dn,$d_dn);
1058 }
1059 }
1060 }
1061 }
1064 function migrate_outside_users($perform = FALSE)
1065 {
1066 /* Establish ldap connection */
1067 $cv = $this->parent->captured_values;
1068 $ldap = new LDAP($cv['admin'],
1069 $cv['password'],
1070 $cv['connection'],
1071 FALSE,
1072 $cv['tls']);
1074 $ldap->cd($cv['base']);
1076 /* Check if there was a destination department posted */
1077 if(isset($_POST['move_user_to'])){
1078 $destination_dep = $_POST['move_user_to'];
1079 }else{
1080 print_red(_("Couldn't move users to specified department."));
1081 return(false);
1082 }
1084 foreach($this->outside_users as $b_dn => $data){
1085 $this->outside_users[$b_dn]['ldif'] ="";
1086 if($data['selected']){
1087 $dn = base64_decode($b_dn);
1088 $d_dn = preg_replace("/,.*$/",",".base64_decode($destination_dep),$dn);
1089 if(!$perform){
1090 $this->outside_users[$b_dn]['ldif'] = _("User will be moved from").":<br>\t".$dn."<br>"._("to").":<br>\t".$d_dn;
1092 /* Check if there are references to this object */
1093 $ldap->search("(&(member=".$dn.")(|(objectClass=gosaGroupOfNames)(objectClass=groupOfNames)))",array('dn'));
1094 $refs = "";
1095 while($attrs = $ldap->fetch()){
1096 $ref_dn = $attrs['dn'];
1097 $refs .= "<br />\t".$ref_dn;
1098 }
1099 if(!empty($refs)){
1100 $this->outside_users[$b_dn]['ldif'] .= "<br /><br /><i>"._("The following references will be updated").":</i>".$refs;
1101 }
1103 }else{
1104 $this->move($dn,$d_dn);
1105 }
1106 }
1107 }
1108 }
1111 function execute()
1112 {
1113 /* Initialise checks if this is the first call */
1114 if(!$this->checks_initialised || isset($_POST['reload'])){
1115 $this->initialize_checks();
1116 $this->checks_initialised = TRUE;
1117 }
1119 /*************
1120 * Winstations outside the group ou
1121 *************/
1123 if(isset($_POST['outside_winstations_dialog_cancel'])){
1124 $this->outside_winstations_dialog = FALSE;
1125 $this->dialog = FALSE;
1126 $this->show_details = FALSE;
1127 }
1129 if(isset($_POST['outside_winstations_dialog_whats_done'])){
1130 $this->migrate_outside_winstations(FALSE);
1131 }
1133 if(isset($_POST['outside_winstations_dialog_perform'])){
1134 $this->migrate_outside_winstations(TRUE);
1135 $this->search_outside_winstations();
1136 $this->dialog = FALSE;
1137 $this->show_details = FALSE;
1138 $this->outside_winstations_dialog = FALSE;
1139 }
1141 if(isset($_POST['outside_winstations_dialog'])){
1142 $this->outside_winstations_dialog = TRUE;
1143 $this->dialog = TRUE;
1144 }
1146 if($this->outside_winstations_dialog){
1147 $smarty = get_smarty();
1148 $smarty->assign("ous",$this->get_all_winstation_ous());
1149 $smarty->assign("method","outside_winstations");
1150 $smarty->assign("outside_winstations",$this->outside_winstations);
1151 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1152 }
1153 /*************
1154 * Groups outside the group ou
1155 *************/
1157 if(isset($_POST['outside_groups_dialog_cancel'])){
1158 $this->outside_groups_dialog = FALSE;
1159 $this->show_details = FALSE;
1160 $this->dialog = FALSE;
1161 }
1163 if(isset($_POST['outside_groups_dialog_whats_done'])){
1164 $this->show_details= TRUE;
1165 $this->migrate_outside_groups(FALSE);
1166 }
1168 if(isset($_POST['outside_groups_dialog_refresh'])){
1169 $this->show_details= FALSE;
1170 }
1172 if(isset($_POST['outside_groups_dialog_perform'])){
1173 $this->migrate_outside_groups(TRUE);
1174 $this->dialog = FALSE;
1175 $this->show_details = FALSE;
1176 $this->outside_groups_dialog = FALSE;
1177 $this->initialize_checks();
1178 }
1180 if(isset($_POST['outside_groups_dialog'])){
1181 $this->outside_groups_dialog = TRUE;
1182 $this->dialog = TRUE;
1183 }
1185 if($this->outside_groups_dialog){
1186 $smarty = get_smarty();
1187 $smarty->assign("ous",$this->get_all_group_ous());
1188 $smarty->assign("method","outside_groups");
1189 $smarty->assign("outside_groups",$this->outside_groups);
1190 $smarty->assign("group_details", $this->show_details);
1191 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1192 }
1194 /*************
1195 * User outside the people ou
1196 *************/
1198 if(isset($_POST['outside_users_dialog_cancel'])){
1199 $this->outside_users_dialog = FALSE;
1200 $this->dialog = FALSE;
1201 $this->show_details = FALSE;
1202 }
1204 if(isset($_POST['outside_users_dialog_whats_done'])){
1205 $this->show_details= TRUE;
1206 $this->migrate_outside_users(FALSE);
1207 }
1209 if(isset($_POST['outside_users_dialog_perform'])){
1210 $this->migrate_outside_users(TRUE);
1211 $this->initialize_checks();
1212 $this->dialog = FALSE;
1213 $this->show_details = FALSE;
1214 $this->outside_users_dialog = FALSE;
1215 }
1217 if (isset($_POST['outside_users_dialog_refresh'])){
1218 $this->show_details= FALSE;
1219 }
1221 if(isset($_POST['outside_users_dialog'])){
1222 $this->outside_users_dialog = TRUE;
1223 $this->dialog = TRUE;
1224 }
1226 if($this->outside_users_dialog){
1227 $smarty = get_smarty();
1228 $smarty->assign("ous",$this->get_all_people_ous());
1229 $smarty->assign("method","outside_users");
1230 $smarty->assign("outside_users",$this->outside_users);
1231 $smarty->assign("user_details", $this->show_details);
1232 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1233 }
1235 /*************
1236 * Root object check
1237 *************/
1239 if(isset($_POST['retry_root_create'])){
1241 $state = $this->checks['root']['STATUS'];
1242 $this->checkBase(FALSE);
1243 if($state != $this->checks['root']['STATUS']){
1244 $this->initialize_checks();
1245 }
1246 }
1248 /*************
1249 * User Migration handling
1250 *************/
1252 if(isset($_POST['retry_acls'])){
1253 $this->check_administrativeAccount();
1254 }
1256 if(isset($_POST['create_acls'])){
1257 $this->acl_create_dialog = TRUE;
1258 $this->dialog = TRUE;
1259 }
1261 if(isset($_POST['create_acls_cancel'])){
1262 $this->acl_create_dialog = FALSE;
1263 $this->dialog = FALSE;
1264 $this->show_details = FALSE;
1265 }
1267 if(isset($_POST['create_acls_create_confirmed'])){
1268 if($this->create_admin()){
1269 $this->acl_create_dialog = FALSE;
1270 $this->dialog = FALSE;
1271 $this->show_details = FALSE;
1272 $this->initialize_checks();
1273 }
1274 }
1276 if(isset($_POST['create_acls_create'])){
1277 $this->create_admin(TRUE);
1278 }
1280 if(isset($_POST['create_admin_user'])){
1281 if($this->create_admin_user()){
1282 $this->dialog = FALSE;
1283 $this->show_details = FALSE;
1284 }
1285 }
1287 if($this->acl_create_dialog){
1288 $smarty = get_smarty();
1289 $smarty->assign("new_user_password",@$_POST['new_user_password']);
1290 $smarty->assign("new_user_password2",@$_POST['new_user_password2']);
1291 $smarty->assign("users" ,$this->get_user_list());
1292 $smarty->assign("users_cnt" ,count($this->get_user_list()));
1293 $smarty->assign("groups",$this->get_group_list());
1294 $smarty->assign("groups_cnt",count($this->get_group_list()));
1295 $smarty->assign("type" ,$this->acl_create_type);
1296 $smarty->assign("method","create_acls");
1297 $smarty->assign("acl_create_selected",$this->acl_create_selected);
1298 $smarty->assign("what_will_be_done_now",$this->acl_create_changes);
1299 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1300 }
1302 /*************
1303 * User Migration handling
1304 *************/
1306 /* Refresh list of deparments */
1307 if(isset($_POST['users_visible_migrate_refresh'])){
1308 $this->check_gosaAccounts();
1309 }
1311 /* Open migration dialog */
1312 if(isset($_POST['users_visible_migrate'])){
1313 $this->show_details= FALSE;
1314 $this->users_migration_dialog = TRUE;
1315 $this->dialog =TRUE;
1316 }
1318 /* Close migration dialog */
1319 if(isset($_POST['users_visible_migrate_close'])){
1320 $this->users_migration_dialog = FALSE;
1321 $this->dialog =FALSE;
1322 $this->show_details = FALSE;
1323 }
1325 /* Start migration */
1326 if(isset($_POST['users_visible_migrate_migrate'])){
1327 if($this->migrate_gosaAccounts()){
1328 $this->initialize_checks();
1329 $this->dialog = FALSE;
1330 $this->show_details = FALSE;
1331 $this->users_migration_dialog = FALSE;
1332 }
1333 }
1335 /* Start migration */
1336 if(isset($_POST['users_visible_migrate_whatsdone'])){
1337 $this->migrate_gosaAccounts(TRUE);
1338 }
1340 /* Display migration dialog */
1341 if($this->users_migration_dialog){
1342 $smarty = get_smarty();
1343 $smarty->assign("users_to_migrate",$this->users_to_migrate);
1344 $smarty->assign("method","migrate_users");
1345 $smarty->assign("user_details", $this->show_details);
1346 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1347 }
1350 /*************
1351 * Department Migration handling
1352 *************/
1354 /* Refresh list of deparments */
1355 if(isset($_POST['deps_visible_migrate_refresh'])){
1356 $this->check_organizationalUnits();
1357 $this->show_details= FALSE;
1358 }
1360 /* Open migration dialog */
1361 if(isset($_POST['deps_visible_migrate'])){
1362 $this->dep_migration_dialog = TRUE;
1363 $this->dialog =TRUE;
1364 }
1366 /* Close migration dialog */
1367 if(isset($_POST['deps_visible_migrate_close'])){
1368 $this->dep_migration_dialog = FALSE;
1369 $this->dialog =FALSE;
1370 $this->show_details = FALSE;
1371 }
1373 /* Start migration */
1374 if(isset($_POST['deps_visible_migrate_migrate'])){
1375 if($this->migrate_organizationalUnits()){
1376 $this->show_details= FALSE;
1377 $this->check_organizationalUnits();
1378 $this->dialog = FALSE;
1379 $this->dep_migration_dialog = FALSE;
1380 }
1381 }
1383 /* Start migration */
1384 if(isset($_POST['deps_visible_migrate_whatsdone'])){
1385 $this->migrate_organizationalUnits(TRUE);
1386 }
1388 /* Display migration dialog */
1389 if($this->dep_migration_dialog){
1390 $smarty = get_smarty();
1391 $smarty->assign("deps_to_migrate",$this->deps_to_migrate);
1392 $smarty->assign("method","migrate_deps");
1393 $smarty->assign("deps_details", $this->show_details);
1394 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1395 }
1397 $smarty = get_smarty();
1398 $smarty->assign("checks",$this->checks);
1399 $smarty->assign("method","default");
1400 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1401 }
1404 function save_object()
1405 {
1406 $this->is_completed= TRUE;
1408 /* Capture all selected winstations from outside_winstations_dialog */
1409 if($this->outside_winstations_dialog){
1410 foreach($this->outside_winstations as $dn => $data){
1411 if(isset($_POST['select_winstation_'.$dn])){
1412 $this->outside_winstations[$dn]['selected'] = TRUE;
1413 }else{
1414 $this->outside_winstations[$dn]['selected'] = FALSE;
1415 }
1416 }
1417 }
1419 /* Capture all selected groups from outside_groups_dialog */
1420 if($this->outside_groups_dialog){
1421 foreach($this->outside_groups as $dn => $data){
1422 if(isset($_POST['select_group_'.$dn])){
1423 $this->outside_groups[$dn]['selected'] = TRUE;
1424 }else{
1425 $this->outside_groups[$dn]['selected'] = FALSE;
1426 }
1427 }
1428 }
1430 /* Capture all selected users from outside_users_dialog */
1431 if($this->outside_users_dialog){
1432 foreach($this->outside_users as $dn => $data){
1433 if(isset($_POST['select_user_'.$dn])){
1434 $this->outside_users[$dn]['selected'] = TRUE;
1435 }else{
1436 $this->outside_users[$dn]['selected'] = FALSE;
1437 }
1438 }
1439 }
1441 /* Get "create acl" dialog posts */
1442 if($this->acl_create_dialog){
1443 if(isset($_POST['create_acls_create'])){
1444 if(isset($_POST['create_acls_selected'])){
1445 $this->acl_create_selected = base64_decode($_POST['create_acls_selected']);
1446 }else{
1447 $this->acl_create_selected = "";
1448 }
1449 }
1451 if(isset($_POST['create_acls_create_abort'])){
1452 $this->acl_create_selected = "";
1453 }
1455 if(isset($_POST['acl_create_type'])){
1456 $this->acl_create_type = $_POST['acl_create_type'];
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 ?>