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']);
345 /***********
346 * Get all gosaDepartments to be able to
347 * validate correct ldap tree position of every single user
348 ***********/
349 $valid_deps = array();
350 $valid_deps['/'] = $cv['base'];
351 $ldap->search("(&(objectClass=gosaDepartment)(ou=*))",array("dn","ou"));
352 while($attrs = $ldap->fetch()){
353 $valid_deps[$attrs['ou'][0]] = $attrs['dn'];
354 }
356 /***********
357 * Get all groups
358 ***********/
359 $res = $ldap->search("(objectClass=posixGroup)",array("dn"));
360 if(!$res){
361 $this->checks['outside_groups']['STATUS'] = FALSE;
362 $this->checks['outside_groups']['STATUS_MSG']= _("LDAP query failed");
363 $this->checks['outside_groups']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
364 return(false);
365 }
367 $this->outside_groups = array();
368 while($attrs = $ldap->fetch()){
369 $group_db_base = preg_replace("/^[^,]+,".normalizePreg($group_ou)."+,/i","",$attrs['dn']);
371 /* Check if entry is not an addressbook only user
372 * and verify that he is in a valid department
373 */
374 if( !preg_match("/".normalizePreg("dc=addressbook,")."/",$group_db_base) &&
375 !in_array($group_db_base,$valid_deps)
376 ){
377 $attrs['selected'] = FALSE;
378 $attrs['ldif'] = "";
379 $this->outside_groups[base64_encode($attrs['dn'])] = $attrs;
380 }
381 }
383 if(count($this->outside_groups)){
384 $this->checks['outside_groups']['STATUS'] = FALSE;
385 $this->checks['outside_groups']['STATUS_MSG']= "<font style='color:#F0A500'>"._("Warning")."</font>";
386 $this->checks['outside_groups']['ERROR_MSG'] =
387 sprintf(_("Found %s groups outside the configured tree '%s'."),count($this->outside_groups),$group_ou);
388 $this->checks['outside_groups']['ERROR_MSG'].= " <input type='submit' name='outside_groups_dialog' value='"._("Move")."...'>";
389 return(false);
390 }else{
391 $this->checks['outside_groups']['STATUS'] = TRUE;
392 $this->checks['outside_groups']['STATUS_MSG']= _("Ok");
393 $this->checks['outside_groups']['ERROR_MSG'] = "";
394 return(TRUE);
395 }
396 }
399 /* Search for users outside the people ou
400 */
401 function search_outside_users()
402 {
403 $cv = $this->parent->captured_values;
404 $ldap = new LDAP($cv['admin'],
405 $cv['password'],
406 $cv['connection'],
407 FALSE,
408 $cv['tls']);
410 $ldap->cd($cv['base']);
413 /***********
414 * Get all gosaDepartments to be able to
415 * validate correct ldap tree position of every single user
416 ***********/
417 $valid_deps = array();
418 $valid_deps['/'] = $cv['base'];
419 $ldap->search("(&(objectClass=gosaDepartment)(ou=*))",array("dn","ou"));
420 while($attrs = $ldap->fetch()){
421 $valid_deps[$attrs['ou'][0]] = $attrs['dn'];
422 }
424 /***********
425 * Search for all users
426 ***********/
427 $res = $ldap->search("(&(objectClass=gosaAccount)(!(uid=*$)))",array("dn"));
428 if(!$res){
429 $this->checks['outside_users']['STATUS'] = FALSE;
430 $this->checks['outside_users']['STATUS_MSG']= _("LDAP query failed");
431 $this->checks['outside_users']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
432 return(false);
433 }
435 /***********
436 * Check if returned users are within a valid GOsa deparmtment. (peopleou,gosaDepartment,base)
437 ***********/
438 $this->outside_users = array();
439 $people_ou = trim($cv['peopleou']);
440 if(!empty($people_ou)){
441 $people_ou = $people_ou.",";
442 }
444 while($attrs = $ldap->fetch()){
445 $people_db_base = preg_replace("/^[^,]+,".normalizePreg($people_ou)."/i","",$attrs['dn']);
447 /* Check if entry is not an addressbook only user
448 * and verify that he is in a valid department
449 */
450 if( !preg_match("/".normalizePreg("dc=addressbook,")."/",$people_db_base) &&
451 !in_array($people_db_base,$valid_deps)
452 ){
453 $attrs['selected'] = FALSE;
454 $attrs['ldif'] = "";
455 $this->outside_users[base64_encode($attrs['dn'])] = $attrs;
456 }
457 }
459 if(count($this->outside_users)){
460 $this->checks['outside_users']['STATUS'] = FALSE;
461 $this->checks['outside_users']['STATUS_MSG']= "<font style='color:#F0A500'>"._("Warning")."</font>";
462 $this->checks['outside_users']['ERROR_MSG'] =
463 sprintf(_("Found %s user(s) outside the configured tree '%s'."),count($this->outside_users),$people_ou);
464 $this->checks['outside_users']['ERROR_MSG'].= "<input type='submit' name='outside_users_dialog' value='"._("Move")."...'>";
465 return(false);
466 }else{
467 $this->checks['outside_users']['STATUS'] = TRUE;
468 $this->checks['outside_users']['STATUS_MSG']= _("Ok");
469 $this->checks['outside_users']['ERROR_MSG'] = "";
470 return(TRUE);
471 }
472 }
475 /* Check ldap accessibility
476 * Create and remove a dummy object,
477 * to ensure that we have the necessary permissions
478 */
479 function check_ldap_permissions()
480 {
481 $cv = $this->parent->captured_values;
482 $ldap = new LDAP($cv['admin'],
483 $cv['password'],
484 $cv['connection'],
485 FALSE,
486 $cv['tls']);
488 /* Create dummy entry
489 */
490 $name = "GOsa_setup_text_entry_".session_id().rand(0,999999);
491 $dn = "ou=".$name.",".$cv['base'];
492 $testEntry= array();
493 $testEntry['objectClass'][]= "top";
494 $testEntry['objectClass'][]= "organizationalUnit";
495 $testEntry['objectClass'][]= "gosaDepartment";
496 $testEntry['description']= "Created by GOsa setup, this object can be removed.";
497 $testEntry['ou'] = $name;
499 /* check if simple ldap cat will be successful
500 */
501 $res = $ldap->cat($cv['base']);
502 if(!$res){
503 $this->checks['permissions']['STATUS'] = FALSE;
504 $this->checks['permissions']['STATUS_MSG']= _("LDAP query failed");
505 $this->checks['permissions']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
506 return(false);
507 }
509 /* Try to create dummy object
510 */
511 $ldap->cd ($dn);
512 $ldap->create_missing_trees($dn);
513 $res = $ldap->add($testEntry);
514 $ldap->cat($dn);
515 if(!$ldap->count()){
516 gosa_log($ldap->get_error());
517 $this->checks['permissions']['STATUS'] = FALSE;
518 $this->checks['permissions']['STATUS_MSG']= _("Failed");
519 $this->checks['permissions']['ERROR_MSG'] =
520 sprintf(_("The specified user '%s' does not have full access to your ldap database."),$cv['admin']);
521 return(false);
522 }
524 /* Try to remove created entry
525 */
526 $res = $ldap->rmDir($dn);
527 $ldap->cat($dn);
528 if($ldap->count()){
529 gosa_log($ldap->get_error());
530 $this->checks['permissions']['STATUS'] = FALSE;
531 $this->checks['permissions']['STATUS_MSG']= _("Failed");
532 $this->checks['permissions']['ERROR_MSG'] =
533 sprintf(_("The specified user '%s' does not have full access to your ldap database."),$cv['admin']);
534 return(false);
535 }
537 /* Create & remove of dummy object was successful */
538 $this->checks['permissions']['STATUS'] = TRUE;
539 $this->checks['permissions']['STATUS_MSG']= _("Ok");
540 $this->checks['permissions']['ERROR_MSG'] = "";
541 return(true);
542 }
545 /* Check if there are users which will
546 * be invisible for GOsa
547 */
548 function check_gosaAccounts()
549 {
550 /* Remember old list of ivisible users, to be able to set
551 * the 'html checked' status for the checkboxes again
552 */
553 $cnt_ok = 0;
554 $old = $this->users_to_migrate;
555 $this->users_to_migrate = array();
557 /* Get collected configuration settings */
558 $cv = $this->parent->captured_values;
560 /* Establish ldap connection */
561 $ldap = new LDAP($cv['admin'],
562 $cv['password'],
563 $cv['connection'],
564 FALSE,
565 $cv['tls']);
567 /* Get all invisible users
568 */
569 $ldap->cd($cv['base']);
570 $res =$ldap->search("(&(|(objectClass=posixAccount)(&(objectClass=inetOrgPerson)(objectClass=organizationalPerson)))(!(objectClass=gosaAccount))(uid=*))",array("sn","givenName","cn","uid"));
571 while($attrs = $ldap->fetch()){
572 if(!preg_match("/,dc=addressbook,/",$attrs['dn'])){
573 $attrs['checked'] = FALSE;
574 $attrs['before'] = "";
575 $attrs['after'] = "";
577 /* Set objects to selected, that were selected before reload */
578 if(isset($old[base64_encode($attrs['dn'])])){
579 $attrs['checked'] = $old[base64_encode($attrs['dn'])]['checked'];
580 }
581 $this->users_to_migrate[base64_encode($attrs['dn'])] = $attrs;
582 }
583 }
585 /* No invisible */
586 if(!$res){
587 $this->checks['users_visible']['STATUS'] = FALSE;
588 $this->checks['users_visible']['STATUS_MSG']= _("LDAP query failed");
589 $this->checks['users_visible']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
590 }elseif(count($this->users_to_migrate) == 0){
591 $this->checks['users_visible']['STATUS'] = TRUE;
592 $this->checks['users_visible']['STATUS_MSG']= _("Ok");
593 $this->checks['users_visible']['ERROR_MSG'] = "";
594 }else{
595 $this->checks['users_visible']['STATUS'] = FALSE;
596 $this->checks['users_visible']['STATUS_MSG']= "<font style='color:#F0A500'>"._("Warning")."</font>";
597 $this->checks['users_visible']['ERROR_MSG'] = sprintf(_("Found %s user(s) that will not be visible in GOsa."),
598 count($this->users_to_migrate));
599 $this->checks['users_visible']['ERROR_MSG'] .= "<input type='submit' name='users_visible_migrate' value='"._("Migrate")."...'>";
600 }
601 }
604 /* Start user account migration
605 */
606 function migrate_gosaAccounts($only_ldif = FALSE)
607 {
608 $this->show_details= $only_ldif;
610 /* Get collected configuration settings */
611 $cv = $this->parent->captured_values;
613 /* Establish ldap connection */
614 $ldap = new LDAP($cv['admin'],
615 $cv['password'],
616 $cv['connection'],
617 FALSE,
618 $cv['tls']);
620 /* Add gosaAccount objectClass to the selected users
621 */
622 foreach($this->users_to_migrate as $key => $dep){
623 if($dep['checked']){
625 /* Get old objectClasses */
626 $ldap->cat($dep['dn'],array("objectClass"));
627 $attrs = $ldap->fetch();
629 /* Create new objectClass array */
630 $new_attrs = array();
631 $new_attrs['objectClass']= array("gosaAccount","inetOrgPerson","organizationalPerson");
632 for($i = 0 ; $i < $attrs['objectClass']['count']; $i ++ ){
633 if(!in_array_ics($attrs['objectClass'][$i], $new_attrs['objectClass'])){
634 $new_attrs['objectClass'][] = $attrs['objectClass'][$i];
635 }
636 }
638 /* Set info attributes for current object,
639 * or write changes to the ldap database
640 */
641 if($only_ldif){
642 $this->users_to_migrate[$key]['before'] = $this->array_to_ldif($attrs);
643 $this->users_to_migrate[$key]['after'] = $this->array_to_ldif($new_attrs);
644 }else{
645 $ldap->cd($attrs['dn']);
646 if(!$ldap->modify($new_attrs)){
647 print_red(sprintf(_("Failed to migrate the department '%s' into GOsa, error message is as follows '%s'."),$attrs['dn'],$ldap->get_error()));
648 return(false);
649 }
650 }
651 }
652 }
653 return(TRUE);
654 }
657 /* Check if there are invisible organizational Units
658 */
659 function check_organizationalUnits()
660 {
661 $cnt_ok = 0;
662 $old = $this->deps_to_migrate;
663 $this->deps_to_migrate = array();
665 /* Get collected configuration settings */
666 $cv = $this->parent->captured_values;
668 /* Establish ldap connection */
669 $ldap = new LDAP($cv['admin'],
670 $cv['password'],
671 $cv['connection'],
672 FALSE,
673 $cv['tls']);
675 /* Skip GOsa internal departments */
676 $skip_dns = array("/".$cv['peopleou']."/","/".$cv['groupou']."/","/^ou=people,/",
677 "/^ou=groups,/","/(,|)ou=configs,/","/(,|)ou=systems,/",
678 "/(,|)ou=apps,/","/(,|)ou=mime,/","/^ou=aclroles,/","/^ou=incoming,/",
679 "/ou=snapshots,/","/(,|)dc=addressbook,/","/^(,|)ou=machineaccounts,/",
680 "/(,|)ou=winstations,/");
682 /* Get all invisible departments */
683 $ldap->cd($cv['base']);
684 $res = $ldap->search("(&(objectClass=organizationalUnit)(!(objectClass=gosaDepartment)))",array("ou","description","dn"));
685 while($attrs = $ldap->fetch()){
686 $attrs['checked'] = FALSE;
687 $attrs['before'] = "";
688 $attrs['after'] = "";
690 /* Set objects to selected, that were selected before reload */
691 if(isset($old[base64_encode($attrs['dn'])])){
692 $attrs['checked'] = $old[base64_encode($attrs['dn'])]['checked'];
693 }
694 $this->deps_to_migrate[base64_encode($attrs['dn'])] = $attrs;
695 }
697 /* Filter returned list of departments and ensure that
698 * GOsa internal departments will not be listed
699 */
700 foreach($this->deps_to_migrate as $key => $attrs){
701 $dn = $attrs['dn'];
702 $skip = false;
703 foreach($skip_dns as $skip_dn){
704 if(preg_match($skip_dn,$dn)){
705 $skip = true;
706 }
707 }
708 if($skip){
709 unset($this->deps_to_migrate[$key]);
710 }
711 }
713 /* If we have no invisible departments found
714 * tell the user that everything is ok
715 */
716 if(!$res){
717 $this->checks['deps_visible']['STATUS'] = FALSE;
718 $this->checks['deps_visible']['STATUS_MSG']= _("LDAP query failed");
719 $this->checks['deps_visible']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
720 }elseif(count($this->deps_to_migrate) == 0 ){
721 $this->checks['deps_visible']['STATUS'] = TRUE;
722 $this->checks['deps_visible']['STATUS_MSG']= _("Ok");
723 $this->checks['deps_visible']['ERROR_MSG'] = "";
724 }else{
725 $this->checks['deps_visible']['STATUS'] = TRUE;
726 $this->checks['deps_visible']['STATUS_MSG']= '<font style="color:#FFA500">'._("Warning").'</font>';
727 $this->checks['deps_visible']['ERROR_MSG'] = sprintf(_("Found %s department(s) that will not be visible in GOsa."),count($this->deps_to_migrate));
728 $this->checks['deps_visible']['ERROR_MSG'] .= " <input type='submit' name='deps_visible_migrate' value='"._("Migrate")."...'>";
729 }
730 }
734 /* Start deparmtment migration */
735 function migrate_organizationalUnits($only_ldif = FALSE)
736 {
737 $this->show_details= $only_ldif;
739 /* Get collected configuration settings */
740 $cv = $this->parent->captured_values;
742 /* Establish ldap connection */
743 $ldap = new LDAP($cv['admin'],
744 $cv['password'],
745 $cv['connection'],
746 FALSE,
747 $cv['tls']);
749 /* Add gosaDepartment objectClass to each selected entry
750 */
751 foreach($this->deps_to_migrate as $key => $dep){
752 if($dep['checked']){
754 /* Get current objectClasses */
755 $ldap->cat($dep['dn'],array("objectClass","description"));
756 $attrs = $ldap->fetch();
758 /* Create new objectClass attribute including gosaDepartment*/
759 $new_attrs = array();
760 for($i = 0 ; $i < $attrs['objectClass']['count']; $i ++ ){
761 $new_attrs['objectClass'][] = $attrs['objectClass'][$i];
762 }
763 $new_attrs['objectClass'][] = "gosaDepartment";
765 /* Append description it is missing */
766 if(!isset($attrs['description'])){
767 $new_attrs['description'][] = "GOsa department";
768 }
770 /* Depending on the parameter >only_diff< we save the changes as ldif
771 * or we write our changes directly to the ldap database
772 */
773 if($only_ldif){
774 $this->deps_to_migrate[$key]['before'] = $this->array_to_ldif($attrs);
775 $this->deps_to_migrate[$key]['after'] = $this->array_to_ldif($new_attrs);
776 }else{
777 $ldap->cd($attrs['dn']);
778 if(!$ldap->modify($new_attrs)){
779 print_red(sprintf(_("Failed to migrate the department '%s' into GOsa, error message is as follows '%s'."),$attrs['dn'],$ldap->get_error()));
780 return(false);
781 }
782 }
783 }
784 }
785 return(TRUE);
786 }
789 /* Check Acls if there is at least one object with acls defined
790 */
791 function check_administrativeAccount()
792 {
793 /* Establish ldap connection */
794 $cv = $this->parent->captured_values;
795 $ldap = new LDAP($cv['admin'],
796 $cv['password'],
797 $cv['connection'],
798 FALSE,
799 $cv['tls']);
801 /* Search for groups that have complete permissions */
802 $ldap->cd($cv['base']);
803 $res = $ldap->search("(&(objectClass=posixGroup)(gosaSubtreeACL=:all)(memberUid=*))",array("memberUid","cn"));
805 /* If ldap search failed, set error message */
806 if(!$res){
807 $this->checks['acls']['STATUS'] = FALSE;
808 $this->checks['acls']['STATUS_MSG']= _("LDAP query failed");
809 $this->checks['acls']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
810 }else{
812 /* */
813 $found = FALSE;
814 $debug = "";
815 $admin_groups = array();
817 /* Get all returned groups */
818 while($attrs = $ldap->fetch()){
819 $admin_groups[]= $attrs;
820 }
822 /* Walk through groups and check if memberUid exists in ldap database */
823 foreach($admin_groups as $group){
825 $debug .= "<b>".$group['cn'][0].":</b><br>";
827 $count_member = $group['memberUid']['count'];
829 /* Check every single group member */
830 for($i = 0 ; $i < $count_member ; $i++){
831 $debug .= $group['memberUid'][$i];
833 /* Check if user exists */
834 $ldap->search("(&(objectClass=gosaAccount)(uid=".$group['memberUid'][$i]."))",array("dn"));
835 $cnt= $ldap->count();
837 /* Update found-status if there is a member available */
838 if($cnt == 1){
839 $debug .= " <i>->Found</i><br>";
840 $found = TRUE;
841 }elseif($cnt == 0 ){
842 $debug .= " <font color='red'>-> NOT Found</font><br>";
843 }else{
844 $debug .= " <font color='red'>-> Found more than once -.- </font><br>";
845 }
846 }
848 }
849 # For debugging
850 # echo $debug."<br>----------------<br>";
852 if($found){
853 $this->checks['acls']['STATUS'] = TRUE;
854 $this->checks['acls']['STATUS_MSG']= _("Ok");
855 $this->checks['acls']['ERROR_MSG'] = "";
856 }else{
857 $this->checks['acls']['STATUS'] = FALSE;
858 $this->checks['acls']['STATUS_MSG']= _("Failed");
859 $this->checks['acls']['ERROR_MSG']= _("There is no GOsa administrator account inside your LDAP.")." ";
860 $this->checks['acls']['ERROR_MSG'].= "<input type='submit' name='create_acls' value='"._("Create")."'>";
861 }
862 }
863 return($ldap->count()>=1);
864 }
868 function create_admin($only_ldif = FALSE)
869 {
870 /* Reset '' */
871 $this->acl_create_changes="";
873 /* Object that should receive admin acls */
874 $dn = $this->acl_create_selected;
876 /* Get collected configuration settings */
877 $cv = $this->parent->captured_values;
879 /* Establish ldap connection */
880 $ldap = new LDAP($cv['admin'],
881 $cv['password'],
882 $cv['connection'],
883 FALSE,
884 $cv['tls']);
886 $ldap->cd($cv['base']);
887 $ldap->cat($dn,array("objectClass","cn","uid"));
888 $object_attrs = $ldap->fetch();
889 $type = "none";
891 /* Check object that should receive admin acls */
892 if(in_array("gosaAccount",$object_attrs['objectClass'])){
893 $type = "user";
894 }elseif(in_array("posixGroup",$object_attrs['objectClass'])){
895 $type = "group";
896 }
898 /* If a user should get administrative acls, we
899 * should check if there is an administrational group
900 * and just assign the user to it.
901 * If there is no such group, we must create one.
902 */
903 if($type == "user"){
905 $ldap->search("(&(objectClass=posixGroup)(gosaSubtreeACL=:all)(memberUid=*))",array("memberUid"));
906 if($ldap->count()){
907 $fetched_attrs = $ldap->fetch();
908 $attrs_admin_group = $this->cleanup_array($fetched_attrs);
909 $attrs_admin_group_new = $attrs_admin_group;
911 if(!isset($attrs_admin_group_new['memberUid'])){
912 $attrs_admin_group_new['memberUid'] = array();
913 }
914 if(!in_array($object_attrs['uid'][0],$attrs_admin_group_new['memberUid'])){
915 $attrs_admin_group_new['memberUid'][] = $object_attrs['uid'][0];
916 }
918 if($only_ldif){
919 $this->acl_create_changes = _("Appending user to group administrational group:")." \n";
920 $this->acl_create_changes.= "\n"._("Before").":\n";
921 $this->acl_create_changes.= $fetched_attrs['dn']."\n";
922 $this->acl_create_changes.= $this->array_to_ldif($attrs_admin_group)."\n";
923 $this->acl_create_changes.= "\n"._("After").":\n";
924 $this->acl_create_changes.= $fetched_attrs['dn']."\n";
925 $this->acl_create_changes.= $this->array_to_ldif($attrs_admin_group_new)."\n";
926 }else{
927 $ldap->cd($fetched_attrs['dn']);
928 $ldap->modify($attrs_admin_group_new);
929 if(!preg_match("/success/i",$ldap->get_error())){
930 print_red(sprintf(_("Adding acls for user '%s' failed, ldap says '%s'."),$dn,$ldap->get_error()));
931 return(FALSE);
932 }
933 }
935 }else{
937 $group_ou = trim($cv['groupou']);
938 if(!empty($group_ou)){
939 $group_ou = trim($group_ou).",";
940 }
942 $new_group_dn = "cn=GOsa Administrators,".$group_ou.$cv['base'];
943 $new_group_attrs['objectClass'] = array("gosaObject","posixGroup");
944 $new_group_attrs['cn'] = "GOsa Administrators";
945 $new_group_attrs['gosaSubtreeACL'] = ":all";
946 $new_group_attrs['gidNumber'] = "999";
947 $new_group_attrs['memberUid'] = array($object_attrs['uid'][0]);
949 if($only_ldif){
950 $this->acl_create_changes = _("Creating new administrational group:")." \n\n";
951 $this->acl_create_changes.= $new_group_dn."\n";
952 $this->acl_create_changes.= $this->array_to_ldif($new_group_attrs);
953 }else{
954 $ldap->cd($cv['base']);
955 $ldap->create_missing_trees($group_ou.$cv['base']);
956 $ldap->cd($new_group_dn);
957 $res = $ldap->add($new_group_attrs);
958 if(!$res){
959 print_red(sprintf(_("Adding acls for user '%s' failed, ldap says '%s'."),$dn,$ldap->get_error()));
960 return(FALSE);
961 }
962 }
963 }
964 }
965 return(TRUE);
966 }
969 function create_admin_user()
970 {
971 $pw1 = $pw2 = "";
972 $uid = "";
974 if(isset($_POST['new_user_uid'])){
975 $uid = $_POST['new_user_uid'];
976 }
978 if(isset($_POST['new_user_password'])){
979 $pw1 = $_POST['new_user_password'];
980 }
981 if(isset($_POST['new_user_password2'])){
982 $pw2 = $_POST['new_user_password2'];
983 }
985 if(empty($pw1) || empty($pw2) | ($pw1 != $pw2)){
986 print_red(_("Specified passwords are empty or not equal."));
987 return false;
988 }
990 if(!is_uid($uid) || empty($uid)){
991 print_red(_("Please specify a valid uid."));
992 return false;
993 }
995 /* Establish ldap connection */
996 $cv = $this->parent->captured_values;
997 $ldap = new LDAP($cv['admin'],
998 $cv['password'],
999 $cv['connection'],
1000 FALSE,
1001 $cv['tls']);
1003 /* Get current base attributes */
1004 $ldap->cd($cv['base']);
1006 $people_ou = trim($cv['peopleou']);
1007 if(!empty($people_ou)){
1008 $people_ou = trim($people_ou).",";
1009 }
1011 if($cv['peopledn'] == "cn"){
1012 $dn = "cn=System Administrator,".$people_ou.$cv['base'];
1013 }else{
1014 $dn = "uid=".$uid.",".$people_ou.$cv['base'];
1015 }
1017 $methods = @passwordMethod::get_available_methods_if_not_loaded();
1018 $p_m = $methods[$cv['encryption']];
1019 $p_c = new $p_m(array());
1020 $hash = $p_c->generate_hash($pw2);
1022 $new_user=array();
1023 $new_user['objectClass']= array("top","person","gosaAccount","organizationalPerson","inetOrgPerson");
1024 $new_user['givenName'] = "System";
1025 $new_user['sn'] = "Administrator";
1026 $new_user['cn'] = "System Administrator";
1027 $new_user['uid'] = $uid;
1028 $new_user['userPassword'] = $hash;
1030 $ldap->cd($cv['base']);
1031 $ldap->cat($dn,array("dn"));
1032 if($ldap->count()){
1033 print_red(sprintf(_("Could not add administrative user, there is already an object with the same dn '%s' in your ldap database."),
1034 $dn));
1035 return(FALSE);
1036 }
1038 $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$dn));
1039 $ldap->cd($dn);
1040 $res = $ldap->add($new_user);
1041 $this->acl_create_selected = $dn;
1042 $this->create_admin();
1044 if(!$res){
1045 print_red($ldap->get_error());
1046 return(FALSE);
1047 }
1049 $this->acl_create_dialog=FALSE;
1050 $this->check_administrativeAccount();
1051 return(TRUE);
1052 }
1055 function migrate_outside_winstations($perform = FALSE)
1056 {
1057 /* Establish ldap connection */
1058 $cv = $this->parent->captured_values;
1059 $ldap = new LDAP($cv['admin'],
1060 $cv['password'],
1061 $cv['connection'],
1062 FALSE,
1063 $cv['tls']);
1065 $ldap->cd($cv['base']);
1067 /* Check if there was a destination department posted */
1068 if(isset($_POST['move_winstation_to'])){
1069 $destination_dep = $_POST['move_winstation_to'];
1070 }else{
1071 print_red(_("Couldn't move users to specified department."));
1072 return(false);
1073 }
1075 foreach($this->outside_winstations as $b_dn => $data){
1076 $this->outside_winstations[$b_dn]['ldif'] ="";
1077 if($data['selected']){
1078 $dn = base64_decode($b_dn);
1079 $d_dn = preg_replace("/,.*$/",",".base64_decode($destination_dep),$dn);
1080 if(!$perform){
1081 $this->outside_winstations[$b_dn]['ldif'] = _("Winstation will be moved from").":<br>\t".$dn."<br>"._("to").":<br>\t".$d_dn;
1084 /* Check if there are references to this object */
1085 $ldap->search("(&(member=".$dn.")(|(objectClass=gosaGroupOfNames)(objectClass=groupOfNames)))",array('dn'));
1086 $refs = "";
1087 while($attrs = $ldap->fetch()){
1088 $ref_dn = $attrs['dn'];
1089 $refs .= "<br />\t".$ref_dn;
1090 }
1091 if(!empty($refs)){
1092 $this->outside_winstations[$b_dn]['ldif'] .= "<br /><br /><i>"._("Updating following references too").":</i>".$refs;
1093 }
1095 }else{
1096 $this->move($dn,$d_dn);
1097 }
1098 }
1099 }
1100 }
1103 function migrate_outside_groups($perform = FALSE)
1104 {
1105 /* Establish ldap connection */
1106 $cv = $this->parent->captured_values;
1107 $ldap = new LDAP($cv['admin'],
1108 $cv['password'],
1109 $cv['connection'],
1110 FALSE,
1111 $cv['tls']);
1113 $ldap->cd($cv['base']);
1115 /* Check if there was a destination department posted */
1116 if(isset($_POST['move_group_to'])){
1117 $destination_dep = $_POST['move_group_to'];
1118 }else{
1119 print_red(_("Couldn't move users to specified department."));
1120 return(false);
1121 }
1123 foreach($this->outside_groups as $b_dn => $data){
1124 $this->outside_groups[$b_dn]['ldif'] ="";
1125 if($data['selected']){
1126 $dn = base64_decode($b_dn);
1127 $d_dn = preg_replace("/,.*$/",",".base64_decode($destination_dep),$dn);
1128 if(!$perform){
1129 $this->outside_groups[$b_dn]['ldif'] = _("Group will be moved from").":<br>\t".$dn."<br>"._("to").":<br>\t".$d_dn;
1132 /* Check if there are references to this object */
1133 $ldap->search("(&(member=".$dn.")(|(objectClass=gosaGroupOfNames)(objectClass=groupOfNames)))",array('dn'));
1134 $refs = "";
1135 while($attrs = $ldap->fetch()){
1136 $ref_dn = $attrs['dn'];
1137 $refs .= "<br />\t".$ref_dn;
1138 }
1139 if(!empty($refs)){
1140 $this->outside_groups[$b_dn]['ldif'] .= "<br /><br /><i>"._("Updating following references too").":</i>".$refs;
1141 }
1143 }else{
1144 $this->move($dn,$d_dn);
1145 }
1146 }
1147 }
1148 }
1151 function migrate_outside_users($perform = FALSE)
1152 {
1153 /* Establish ldap connection */
1154 $cv = $this->parent->captured_values;
1155 $ldap = new LDAP($cv['admin'],
1156 $cv['password'],
1157 $cv['connection'],
1158 FALSE,
1159 $cv['tls']);
1161 $ldap->cd($cv['base']);
1163 /* Check if there was a destination department posted */
1164 if(isset($_POST['move_user_to'])){
1165 $destination_dep = $_POST['move_user_to'];
1166 }else{
1167 print_red(_("Couldn't move users to specified department."));
1168 return(false);
1169 }
1171 foreach($this->outside_users as $b_dn => $data){
1172 $this->outside_users[$b_dn]['ldif'] ="";
1173 if($data['selected']){
1174 $dn = base64_decode($b_dn);
1175 $d_dn = preg_replace("/,.*$/",",".base64_decode($destination_dep),$dn);
1176 if(!$perform){
1177 $this->outside_users[$b_dn]['ldif'] = _("User will be moved from").":<br>\t".$dn."<br>"._("to").":<br>\t".$d_dn;
1179 /* Check if there are references to this object */
1180 $ldap->search("(&(member=".$dn.")(|(objectClass=gosaGroupOfNames)(objectClass=groupOfNames)))",array('dn'));
1181 $refs = "";
1182 while($attrs = $ldap->fetch()){
1183 $ref_dn = $attrs['dn'];
1184 $refs .= "<br />\t".$ref_dn;
1185 }
1186 if(!empty($refs)){
1187 $this->outside_users[$b_dn]['ldif'] .= "<br /><br /><i>"._("The following references will be updated").":</i>".$refs;
1188 }
1190 }else{
1191 $this->move($dn,$d_dn);
1192 }
1193 }
1194 }
1195 }
1198 function execute()
1199 {
1200 /* Initialise checks if this is the first call */
1201 if(!$this->checks_initialised || isset($_POST['reload'])){
1202 $this->initialize_checks();
1203 $this->checks_initialised = TRUE;
1204 }
1206 /*************
1207 * Winstations outside the group ou
1208 *************/
1210 if(isset($_POST['outside_winstations_dialog_cancel'])){
1211 $this->outside_winstations_dialog = FALSE;
1212 $this->dialog = FALSE;
1213 $this->show_details = FALSE;
1214 }
1216 if(isset($_POST['outside_winstations_dialog_whats_done'])){
1217 $this->migrate_outside_winstations(FALSE);
1218 }
1220 if(isset($_POST['outside_winstations_dialog_perform'])){
1221 $this->migrate_outside_winstations(TRUE);
1222 $this->search_outside_winstations();
1223 $this->dialog = FALSE;
1224 $this->show_details = FALSE;
1225 $this->outside_winstations_dialog = FALSE;
1226 }
1228 if(isset($_POST['outside_winstations_dialog'])){
1229 $this->outside_winstations_dialog = TRUE;
1230 $this->dialog = TRUE;
1231 }
1233 if($this->outside_winstations_dialog){
1234 $smarty = get_smarty();
1235 $smarty->assign("ous",$this->get_all_winstation_ous());
1236 $smarty->assign("method","outside_winstations");
1237 $smarty->assign("outside_winstations",$this->outside_winstations);
1238 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1239 }
1240 /*************
1241 * Groups outside the group ou
1242 *************/
1244 if(isset($_POST['outside_groups_dialog_cancel'])){
1245 $this->outside_groups_dialog = FALSE;
1246 $this->show_details = FALSE;
1247 $this->dialog = FALSE;
1248 }
1250 if(isset($_POST['outside_groups_dialog_whats_done'])){
1251 $this->show_details= TRUE;
1252 $this->migrate_outside_groups(FALSE);
1253 }
1255 if(isset($_POST['outside_groups_dialog_refresh'])){
1256 $this->show_details= FALSE;
1257 }
1259 if(isset($_POST['outside_groups_dialog_perform'])){
1260 $this->migrate_outside_groups(TRUE);
1261 $this->dialog = FALSE;
1262 $this->show_details = FALSE;
1263 $this->outside_groups_dialog = FALSE;
1264 $this->initialize_checks();
1265 }
1267 if(isset($_POST['outside_groups_dialog'])){
1268 $this->outside_groups_dialog = TRUE;
1269 $this->dialog = TRUE;
1270 }
1272 if($this->outside_groups_dialog){
1273 $smarty = get_smarty();
1274 $smarty->assign("ous",$this->get_all_group_ous());
1275 $smarty->assign("method","outside_groups");
1276 $smarty->assign("outside_groups",$this->outside_groups);
1277 $smarty->assign("group_details", $this->show_details);
1278 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1279 }
1281 /*************
1282 * User outside the people ou
1283 *************/
1285 if(isset($_POST['outside_users_dialog_cancel'])){
1286 $this->outside_users_dialog = FALSE;
1287 $this->dialog = FALSE;
1288 $this->show_details = FALSE;
1289 }
1291 if(isset($_POST['outside_users_dialog_whats_done'])){
1292 $this->show_details= TRUE;
1293 $this->migrate_outside_users(FALSE);
1294 }
1296 if(isset($_POST['outside_users_dialog_perform'])){
1297 $this->migrate_outside_users(TRUE);
1298 $this->initialize_checks();
1299 $this->dialog = FALSE;
1300 $this->show_details = FALSE;
1301 $this->outside_users_dialog = FALSE;
1302 }
1304 if (isset($_POST['outside_users_dialog_refresh'])){
1305 $this->show_details= FALSE;
1306 }
1308 if(isset($_POST['outside_users_dialog'])){
1309 $this->outside_users_dialog = TRUE;
1310 $this->dialog = TRUE;
1311 }
1313 if($this->outside_users_dialog){
1314 $smarty = get_smarty();
1315 $smarty->assign("ous",$this->get_all_people_ous());
1316 $smarty->assign("method","outside_users");
1317 $smarty->assign("outside_users",$this->outside_users);
1318 $smarty->assign("user_details", $this->show_details);
1319 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1320 }
1322 /*************
1323 * Root object check
1324 *************/
1326 if(isset($_POST['retry_root_create'])){
1328 $state = $this->checks['root']['STATUS'];
1329 $this->checkBase(FALSE);
1330 if($state != $this->checks['root']['STATUS']){
1331 $this->initialize_checks();
1332 }
1333 }
1335 /*************
1336 * User Migration handling
1337 *************/
1339 if(isset($_POST['retry_acls'])){
1340 $this->check_administrativeAccount();
1341 }
1343 if(isset($_POST['create_acls'])){
1344 $this->acl_create_dialog = TRUE;
1345 $this->dialog = TRUE;
1346 }
1348 if(isset($_POST['create_acls_cancel'])){
1349 $this->acl_create_dialog = FALSE;
1350 $this->dialog = FALSE;
1351 $this->show_details = FALSE;
1352 }
1354 # if(isset($_POST['create_acls_create_confirmed'])){
1355 # if($this->create_admin()){
1356 # $this->acl_create_dialog = FALSE;
1357 # $this->dialog = FALSE;
1358 # $this->show_details = FALSE;
1359 # $this->initialize_checks();
1360 # }
1361 # }
1363 if(isset($_POST['create_acls_create'])){
1364 $this->create_admin(TRUE);
1365 }
1367 if(isset($_POST['create_admin_user'])){
1368 if($this->create_admin_user()){
1369 $this->dialog = FALSE;
1370 $this->show_details = FALSE;
1371 }
1372 }
1374 if($this->acl_create_dialog){
1375 $smarty = get_smarty();
1377 $uid = "admin";
1378 if(isset($_POST['new_user_uid'])){
1379 $uid = $_POST['new_user_uid'];
1380 }
1382 $smarty->assign("new_user_uid",$uid);
1383 $smarty->assign("new_user_password",@$_POST['new_user_password']);
1384 $smarty->assign("new_user_password2",@$_POST['new_user_password2']);
1385 $smarty->assign("method","create_acls");
1386 $smarty->assign("acl_create_selected",$this->acl_create_selected);
1387 $smarty->assign("what_will_be_done_now",$this->acl_create_changes);
1388 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1389 }
1391 /*************
1392 * User Migration handling
1393 *************/
1395 /* Refresh list of deparments */
1396 if(isset($_POST['users_visible_migrate_refresh'])){
1397 $this->check_gosaAccounts();
1398 }
1400 /* Open migration dialog */
1401 if(isset($_POST['users_visible_migrate'])){
1402 $this->show_details= FALSE;
1403 $this->users_migration_dialog = TRUE;
1404 $this->dialog =TRUE;
1405 }
1407 /* Close migration dialog */
1408 if(isset($_POST['users_visible_migrate_close'])){
1409 $this->users_migration_dialog = FALSE;
1410 $this->dialog =FALSE;
1411 $this->show_details = FALSE;
1412 }
1414 /* Start migration */
1415 if(isset($_POST['users_visible_migrate_migrate'])){
1416 if($this->migrate_gosaAccounts()){
1417 $this->initialize_checks();
1418 $this->dialog = FALSE;
1419 $this->show_details = FALSE;
1420 $this->users_migration_dialog = FALSE;
1421 }
1422 }
1424 /* Start migration */
1425 if(isset($_POST['users_visible_migrate_whatsdone'])){
1426 $this->migrate_gosaAccounts(TRUE);
1427 }
1429 /* Display migration dialog */
1430 if($this->users_migration_dialog){
1431 $smarty = get_smarty();
1432 $smarty->assign("users_to_migrate",$this->users_to_migrate);
1433 $smarty->assign("method","migrate_users");
1434 $smarty->assign("user_details", $this->show_details);
1435 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1436 }
1439 /*************
1440 * Department Migration handling
1441 *************/
1443 /* Refresh list of deparments */
1444 if(isset($_POST['deps_visible_migrate_refresh'])){
1445 $this->check_organizationalUnits();
1446 $this->show_details= FALSE;
1447 }
1449 /* Open migration dialog */
1450 if(isset($_POST['deps_visible_migrate'])){
1451 $this->dep_migration_dialog = TRUE;
1452 $this->dialog =TRUE;
1453 }
1455 /* Close migration dialog */
1456 if(isset($_POST['deps_visible_migrate_close'])){
1457 $this->dep_migration_dialog = FALSE;
1458 $this->dialog =FALSE;
1459 $this->show_details = FALSE;
1460 }
1462 /* Start migration */
1463 if(isset($_POST['deps_visible_migrate_migrate'])){
1464 if($this->migrate_organizationalUnits()){
1465 $this->show_details= FALSE;
1466 $this->check_organizationalUnits();
1467 $this->dialog = FALSE;
1468 $this->dep_migration_dialog = FALSE;
1469 }
1470 }
1472 /* Start migration */
1473 if(isset($_POST['deps_visible_migrate_whatsdone'])){
1474 $this->migrate_organizationalUnits(TRUE);
1475 }
1477 /* Display migration dialog */
1478 if($this->dep_migration_dialog){
1479 $smarty = get_smarty();
1480 $smarty->assign("deps_to_migrate",$this->deps_to_migrate);
1481 $smarty->assign("method","migrate_deps");
1482 $smarty->assign("deps_details", $this->show_details);
1483 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1484 }
1486 $smarty = get_smarty();
1487 $smarty->assign("checks",$this->checks);
1488 $smarty->assign("method","default");
1489 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1490 }
1493 function save_object()
1494 {
1495 $this->is_completed= TRUE;
1497 /* Capture all selected winstations from outside_winstations_dialog */
1498 if($this->outside_winstations_dialog){
1499 foreach($this->outside_winstations as $dn => $data){
1500 if(isset($_POST['select_winstation_'.$dn])){
1501 $this->outside_winstations[$dn]['selected'] = TRUE;
1502 }else{
1503 $this->outside_winstations[$dn]['selected'] = FALSE;
1504 }
1505 }
1506 }
1508 /* Capture all selected groups from outside_groups_dialog */
1509 if($this->outside_groups_dialog){
1510 foreach($this->outside_groups as $dn => $data){
1511 if(isset($_POST['select_group_'.$dn])){
1512 $this->outside_groups[$dn]['selected'] = TRUE;
1513 }else{
1514 $this->outside_groups[$dn]['selected'] = FALSE;
1515 }
1516 }
1517 }
1519 /* Capture all selected users from outside_users_dialog */
1520 if($this->outside_users_dialog){
1521 foreach($this->outside_users as $dn => $data){
1522 if(isset($_POST['select_user_'.$dn])){
1523 $this->outside_users[$dn]['selected'] = TRUE;
1524 }else{
1525 $this->outside_users[$dn]['selected'] = FALSE;
1526 }
1527 }
1528 }
1530 /* Get "create acl" dialog posts */
1531 if($this->acl_create_dialog){
1533 if(isset($_POST['create_acls_create_abort'])){
1534 $this->acl_create_selected = "";
1535 }
1536 }
1538 /* Get selected departments */
1539 if($this->dep_migration_dialog){
1540 foreach($this->deps_to_migrate as $id => $data){
1541 if(isset($_POST['migrate_'.$id])){
1542 $this->deps_to_migrate[$id]['checked'] = TRUE;
1543 }else{
1544 $this->deps_to_migrate[$id]['checked'] = FALSE;
1545 }
1546 }
1547 }
1549 /* Get selected users */
1550 if($this->users_migration_dialog){
1551 foreach($this->users_to_migrate as $id => $data){
1552 if(isset($_POST['migrate_'.$id])){
1553 $this->users_to_migrate[$id]['checked'] = TRUE;
1554 }else{
1555 $this->users_to_migrate[$id]['checked'] = FALSE;
1556 }
1557 }
1558 }
1559 }
1562 /* Check if the root object exists.
1563 * If the parameter just_check is true, then just check if the
1564 * root object is missing and update the info messages.
1565 * If the Parameter is false, try to create a new root object.
1566 */
1567 function checkBase($just_check = TRUE)
1568 {
1569 /* Get collected setup informations */
1570 $cv = $this->parent->captured_values;
1572 /* Establish ldap connection */
1573 $ldap = new LDAP($cv['admin'],
1574 $cv['password'],
1575 $cv['connection'],
1576 FALSE,
1577 $cv['tls']);
1579 /* Check if root object exists */
1580 $ldap->cd($cv['base']);
1581 $res = $ldap->search("(objectClass=*)");
1582 $err = ldap_errno($ldap->cid);
1584 if( !$res ||
1585 $err == 0x20 || # LDAP_NO_SUCH_OBJECT
1586 $err == 0x40) { # LDAP_NAMING_VIOLATION
1588 /* Root object doesn't exists
1589 */
1590 if($just_check){
1591 $this->checks['root']['STATUS'] = FALSE;
1592 $this->checks['root']['STATUS_MSG']= _("Failed");
1593 $this->checks['root']['ERROR_MSG'] = _("The LDAP root object is missing. It is required to use your LDAP service.").' ';
1594 $this->checks['root']['ERROR_MSG'].= "<input type='submit' name='retry_root_create' value='"._("Try to create root object")."'>";
1595 return(FALSE);
1596 }else{
1598 /* Add root object */
1599 $ldap->cd($cv['base']);
1600 $res = $ldap->create_missing_trees($cv['base']);
1602 /* If adding failed, tell the user */
1603 if(!$res){
1604 $this->checks['root']['STATUS'] = FALSE;
1605 $this->checks['root']['STATUS_MSG']= _("Failed");
1606 $this->checks['root']['ERROR_MSG'] = _("Root object couldn't be created, you should try it on your own.");
1607 $this->checks['root']['ERROR_MSG'].= " <input type='submit' name='retry_root_create' value='"._("Try to create root object")."'>";
1608 return($res);;
1609 }
1610 }
1611 }
1613 /* Create & remove of dummy object was successful */
1614 $this->checks['root']['STATUS'] = TRUE;
1615 $this->checks['root']['STATUS_MSG']= _("Ok");
1616 }
1619 /* Return ldif information for a
1620 * given attribute array
1621 */
1622 function array_to_ldif($atts)
1623 {
1624 $ret = "";
1625 unset($atts['count']);
1626 unset($atts['dn']);
1627 foreach($atts as $name => $value){
1628 if(is_numeric($name)) {
1629 continue;
1630 }
1631 if(is_array($value)){
1632 unset($value['count']);
1633 foreach($value as $a_val){
1634 $ret .= $name.": ". $a_val."\n";
1635 }
1636 }else{
1637 $ret .= $name.": ". $value."\n";
1638 }
1639 }
1640 return(preg_replace("/\n$/","",$ret));
1641 }
1644 function get_user_list()
1645 {
1646 /* Get collected configuration settings */
1647 $cv = $this->parent->captured_values;
1649 /* Establish ldap connection */
1650 $ldap = new LDAP($cv['admin'],
1651 $cv['password'],
1652 $cv['connection'],
1653 FALSE,
1654 $cv['tls']);
1656 $ldap->cd($cv['base']);
1657 $ldap->search("(objectClass=gosaAccount)",array("dn"));
1659 $tmp = array();
1660 while($attrs = $ldap->fetch()){
1661 $tmp[base64_encode($attrs['dn'])] = @LDAP::fix($attrs['dn']);
1662 }
1663 return($tmp);
1664 }
1667 function get_all_people_ous()
1668 {
1669 /* Get collected configuration settings */
1670 $cv = $this->parent->captured_values;
1671 $people_ou = trim($cv['peopleou']);
1673 /* Establish ldap connection */
1674 $ldap = new LDAP($cv['admin'],
1675 $cv['password'],
1676 $cv['connection'],
1677 FALSE,
1678 $cv['tls']);
1681 /*****************
1682 * If people ou is NOT empty
1683 * search for for all objects matching the given container
1684 *****************/
1685 if(!empty($people_ou)){
1686 $ldap->search("(".$people_ou.")",array("dn"));
1688 /* Create people ou if there is currently none */
1689 if($ldap->count() == 0 ){
1690 $add_dn = $cv['peopleou'].",".$cv['base'];
1691 $naming_attr = preg_replace("/=.*$/","",$add_dn);
1692 $naming_value = preg_replace("/^[^=]*+=([^,]*).*$/","\\1",$add_dn);
1693 $add = array();
1694 $add['objectClass'] = array("organizationalUnit");
1695 $add[$naming_attr] = $naming_value;
1696 $ldap->cd($cv['base']);
1697 $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$add_dn));
1698 $ldap->cd($add_dn);
1699 $ldap->add($add);
1700 }
1702 /* Create result */
1703 $ldap->search("(".$cv['peopleou'].")",array("dn"));
1704 $tmp = array();
1705 while($attrs= $ldap->fetch()){
1706 if(!preg_match("/ou=snapshots,/",$attrs['dn'])){
1707 $tmp[base64_encode($attrs['dn'])] = $ldap->fix($attrs['dn']);
1708 }
1709 }
1710 } else{
1712 /************
1713 * If people ou is empty
1714 * Get all valid gosaDepartments
1715 ************/
1716 $ldap->cd($cv['base']);
1717 $tmp = array();
1718 $ldap->search("(&(objectClass=gosaDepartment)(ou=*))",array("dn"));
1719 $tmp[base64_encode($cv['base'])] = $ldap->fix($cv['base']);
1720 while($attrs = $ldap->fetch()){
1721 $tmp[base64_encode($attrs['dn'])] = $ldap->fix($attrs['dn']);;
1722 }
1723 }
1724 return($tmp);
1725 }
1728 function get_all_winstation_ous()
1729 {
1730 /* Get collected configuration settings */
1731 $cv = $this->parent->captured_values;
1733 /* Establish ldap connection */
1734 $ldap = new LDAP($cv['admin'],
1735 $cv['password'],
1736 $cv['connection'],
1737 FALSE,
1738 $cv['tls']);
1740 /* Get winstation ou */
1741 if($cv['generic_settings']['wws_ou_active']) {
1742 $winstation_ou = $cv['generic_settings']['ws_ou'];
1743 }else{
1744 $winstation_ou = "ou=winstations";
1745 }
1747 $ldap->cd($cv['base']);
1748 $ldap->search("(".$winstation_ou.")",array("dn"));
1750 if($ldap->count() == 0 ){
1751 $add_dn = $winstation_ou.",ou=systems,".$cv['base'];
1752 $naming_attr = preg_replace("/=.*$/","",$add_dn);
1753 $naming_value = preg_replace("/^[^=]*+=([^,]*).*$/","\\1",$add_dn);
1754 $add = array();
1755 $add['objectClass'] = array("organizationalUnit");
1756 $add[$naming_attr] = $naming_value;
1758 $ldap->cd($cv['base']);
1759 $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$add_dn));
1760 $ldap->cd($add_dn);
1761 $ldap->add($add);
1762 }
1764 $ldap->search("(".$winstation_ou.")",array("dn"));
1765 $tmp = array();
1766 while($attrs= $ldap->fetch()){
1767 if(!preg_match("/ou=snapshots,/",$attrs['dn'])){
1768 $tmp[base64_encode($attrs['dn'])] = $ldap->fix($attrs['dn']);
1769 }
1770 }
1771 return($tmp);
1772 }
1775 function get_all_group_ous()
1776 {
1777 /* Get collected configuration settings */
1778 $cv = $this->parent->captured_values;
1780 /* Establish ldap connection */
1781 $ldap = new LDAP($cv['admin'],
1782 $cv['password'],
1783 $cv['connection'],
1784 FALSE,
1785 $cv['tls']);
1787 $group_ou = trim($cv['groupou']);
1788 if(!empty($group_ou)){
1789 $group_ou = trim($group_ou);
1790 }
1792 /************
1793 * If group ou is NOT empty
1794 * Get all valid group ous, create one if necessary
1795 ************/
1796 $ldap->cd($cv['base']);
1797 if(!empty($group_ou)){
1798 $ldap->search("(".$group_ou.")",array("dn"));
1799 if($ldap->count() == 0 ){
1800 $add_dn = $group_ou.$cv['base'];
1801 $naming_attr = preg_replace("/=.*$/","",$add_dn);
1802 $naming_value = preg_replace("/^[^=]*+=([^,]*).*$/","\\1",$add_dn);
1803 $add = array();
1804 $add['objectClass'] = array("organizationalUnit");
1805 $add[$naming_attr] = $naming_value;
1807 $ldap->cd($cv['base']);
1808 $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$add_dn));
1809 $ldap->cd($add_dn);
1810 $ldap->add($add);
1811 }
1812 $ldap->search("(".$group_ou.")",array("dn"));
1813 $tmp = array();
1814 while($attrs= $ldap->fetch()){
1815 if(!preg_match("/ou=snapshots,/",$attrs['dn'])){
1816 $tmp[base64_encode($attrs['dn'])] = $ldap->fix($attrs['dn']);
1817 }
1818 }
1819 }else{
1820 /************
1821 * If group ou is empty
1822 * Get all valid gosaDepartments
1823 ************/
1824 $ldap->cd($cv['base']);
1825 $tmp = array();
1826 $ldap->search("(&(objectClass=gosaDepartment)(ou=*))",array("dn"));
1827 $tmp[base64_encode($cv['base'])] = $ldap->fix($cv['base']);
1828 while($attrs = $ldap->fetch()){
1829 $tmp[base64_encode($attrs['dn'])] = $ldap->fix($attrs['dn']);;
1830 }
1831 }
1832 return($tmp);
1833 }
1836 function get_group_list()
1837 {
1838 /* Get collected configuration settings */
1839 $cv = $this->parent->captured_values;
1841 /* Establish ldap connection */
1842 $ldap = new LDAP($cv['admin'],
1843 $cv['password'],
1844 $cv['connection'],
1845 FALSE,
1846 $cv['tls']);
1848 $ldap->cd($cv['base']);
1849 $ldap->search("(objectClass=posixGroup)",array("dn"));
1851 $tmp = array();
1852 while($attrs = $ldap->fetch()){
1853 $tmp[base64_encode($attrs['dn'])] = @LDAP::fix($attrs['dn']);
1854 }
1855 return($tmp);
1856 }
1859 function move($source,$destination)
1860 {
1861 /* Get collected configuration settings */
1862 $cv = $this->parent->captured_values;
1864 /* Establish ldap connection */
1865 $ldap = new LDAP($cv['admin'],
1866 $cv['password'],
1867 $cv['connection'],
1868 FALSE,
1869 $cv['tls']);
1871 /* Update object references in gosaGroupOfNames */
1872 $ogs_to_fix = array();
1873 $ldap->cd($cv['base']);
1874 $ldap->search('(&(objectClass=gosaGroupOfNames)(member='.@LDAP::fix($source).'))', array('cn','member'));
1875 while ($attrs= $ldap->fetch()){
1876 $dn = $attrs['dn'];
1877 $attrs = $this->cleanup_array($attrs);
1878 $member_new = array($destination);
1879 foreach($attrs['member'] as $member){
1880 if($member != $source){
1881 $member_new[] = $member;
1882 }
1883 }
1884 $attrs['member'] = $member_new;
1885 $ogs_to_fix[$dn] = $attrs;
1886 }
1888 /* Copy source to destination dn */
1889 $ldap->cat($source);
1890 $new_data = $this->cleanup_array($ldap->fetch());
1891 $ldap->cd($destination);
1892 $res = $ldap->add($new_data);
1894 /* Display warning if copy failed */
1895 if(!$res){
1896 print_red(_("Failed to copy '%s' to '%s'. LDAP says '%s'."),$source,$destination,$ldap->get_error());
1897 }else{
1898 $res = $ldap->rmDir($source);
1899 show_ldap_error($ldap->get_error(),_("Something went wrong while copying dns."));
1901 /* Object is copied, so update its references */
1902 foreach($ogs_to_fix as $dn => $data){
1903 $ldap->cd($dn);
1904 $ldap->modify($data);
1905 }
1906 }
1907 }
1910 /* Cleanup ldap result to be able to write it be to ldap */
1911 function cleanup_array($attrs)
1912 {
1913 foreach($attrs as $key => $value) {
1914 if(is_numeric($key) || in_array($key,array("count","dn"))){
1915 unset($attrs[$key]);
1916 }
1917 if(is_array($value) && isset($value['count'])){
1918 unset($attrs[$key]['count']);
1919 }
1920 }
1921 return($attrs);
1922 }
1923 }
1925 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1926 ?>