1 <?php
3 /*
4 This code is part of GOsa (https://gosa.gonicus.de)
5 Copyright (C) 2007 Fabian Hickert
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
24 /****************
25 * FUNCTIONS
27 Step_Migrate - Constructor.
28 update_strings - Used to update the displayed step informations.
29 initialize_checks - Initialize migration steps.
30 check_ldap_permissions - Check if the used admin account has full access to the ldap database.
31 check_gosaAccounts - Check if there are users without the required objectClasses.
32 migrate_gosaAccounts - Migrate selected users to GOsa user accounts.
33 check_organizationalUnits - Check if there are departments, that are not visible for GOsa
34 migrate_organizationalUnits - Migrate selected departments
35 check_administrativeAccount - Check if there is at least one acl entry available
36 checkBase - Check if there is a root object available
38 get_user_list - Get list of available users
39 get_group_list - Get list of groups
41 create_admin
42 create_admin_user
44 execute - Generate html output of this plugin
45 save_object - Save posts
46 array_to_ldif - Create ldif output of an ldap result array
48 ****************/
52 class Step_Migrate extends setup_step
53 {
54 var $languages = array();
55 var $attributes = array();
56 var $header_image = "images/monitoring.png";
57 var $checks = array();
59 /* Department migration attributes */
60 var $dep_migration_dialog = FALSE;
61 var $deps_to_migrate = array();
63 /* Department migration attributes */
64 var $users_migration_dialog= FALSE;
65 var $users_to_migrate = array();
67 /* Create Acl attributes */
68 var $acl_create_dialog = FALSE;
69 var $acl_create_type = "group";
70 var $acl_create_selected= ""; // Currently selected element, that should receive admin rights
71 var $acl_create_changes = ""; // Contains ldif information about changes
72 var $acl_create_confirmed= FALSE;
74 /* Checks initialised ? */
75 var $checks_initialised = FALSE;
77 /* Users outside to people ou */
78 var $outside_users = array();
79 var $outside_users_dialog = FALSE;
81 /* Users outside to groups ou */
82 var $outside_groups = array();
83 var $outside_groups_dialog = FALSE;
85 /* Win-Workstations outside to reserved ou */
86 var $outside_winstations = array();
87 var $outside_winstations_dialog = FALSE;
89 /* check for multiple use of same uidNumber */
90 var $check_uidNumbers = array();
91 var $check_uidNumbers_dialog = FALSE;
93 /* check for multiple use of same gidNumber */
94 var $check_gidNumbers = array();
95 var $check_gidNumbers_dialog = FALSE;
98 function Step_Migrate()
99 {
100 $this->update_strings();
101 }
103 function update_strings()
104 {
105 $this->s_title = _("LDAP inspection");
106 $this->s_title_long = _("LDAP inspection");
107 $this->s_info = _("Analyze your current LDAP for GOsa compatibility");
108 }
110 function initialize_checks()
111 {
112 $this->checks = array();
113 $this->checks['root']['TITLE'] = _("Checking for root object");
114 $this->checks['root']['STATUS'] = FALSE;
115 $this->checks['root']['STATUS_MSG']= "";
116 $this->checks['root']['ERROR_MSG'] = "";
117 $this->checkBase();
119 $this->checks['permissions']['TITLE'] = _("Checking permissions on ldap database");
120 $this->checks['permissions']['STATUS'] = FALSE;
121 $this->checks['permissions']['STATUS_MSG']= "";
122 $this->checks['permissions']['ERROR_MSG'] = "";
123 $this->check_ldap_permissions();
125 $this->checks['deps_visible']['TITLE'] = _("Checking for invisible deparmtments");
126 $this->checks['deps_visible']['STATUS'] = FALSE;
127 $this->checks['deps_visible']['STATUS_MSG']= "";
128 $this->checks['deps_visible']['ERROR_MSG'] = "";
129 $this->check_organizationalUnits();
131 $this->checks['users_visible']['TITLE'] = _("Checking for invisible user");
132 $this->checks['users_visible']['STATUS'] = FALSE;
133 $this->checks['users_visible']['STATUS_MSG']= "";
134 $this->checks['users_visible']['ERROR_MSG'] = "";
135 $this->check_gosaAccounts();
137 $this->checks['acls']['TITLE'] = _("Checking for administrational account");
138 $this->checks['acls']['STATUS'] = FALSE;
139 $this->checks['acls']['STATUS_MSG']= "";
140 $this->checks['acls']['ERROR_MSG'] = "";
141 $this->check_administrativeAccount();
143 $this->checks['outside_users']['TITLE'] = _("Checking for users outside the people department.");
144 $this->checks['outside_users']['STATUS'] = FALSE;
145 $this->checks['outside_users']['STATUS_MSG']= "";
146 $this->checks['outside_users']['ERROR_MSG'] = "";
147 $this->search_outside_users();
149 $this->checks['outside_groups']['TITLE'] = _("Checking for groups outside the groups department.");
150 $this->checks['outside_groups']['STATUS'] = FALSE;
151 $this->checks['outside_groups']['STATUS_MSG']= "";
152 $this->checks['outside_groups']['ERROR_MSG'] = "";
153 $this->search_outside_groups();
155 $this->checks['outside_winstations']['TITLE'] = _("Checking for windows workstations outside the winstation department.");
156 $this->checks['outside_winstations']['STATUS'] = FALSE;
157 $this->checks['outside_winstations']['STATUS_MSG']= "";
158 $this->checks['outside_winstations']['ERROR_MSG'] = "";
159 $this->search_outside_winstations();
161 $this->checks['uidNumber_usage']['TITLE'] = _("Checking for multiple use of same uidNumber value.");
162 $this->checks['uidNumber_usage']['STATUS'] = FALSE;
163 $this->checks['uidNumber_usage']['STATUS_MSG']= "";
164 $this->checks['uidNumber_usage']['ERROR_MSG'] = "";
165 $this->check_uidNumber();
167 $this->checks['gidNumber_usage']['TITLE'] = _("Checking for multiple use of same gidNumber value.");
168 $this->checks['gidNumber_usage']['STATUS'] = FALSE;
169 $this->checks['gidNumber_usage']['STATUS_MSG']= "";
170 $this->checks['gidNumber_usage']['ERROR_MSG'] = "";
171 $this->check_gidNumber();
172 }
175 /* 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']= _("Failed");
212 $this->checks['uidNumber_usage']['ERROR_MSG'] =
213 sprintf(_("Found %s duplicated uidNumber values."),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("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']= _("Failed");
261 $this->checks['gidNumber_usage']['ERROR_MSG'] =
262 sprintf(_("Found %s duplicated gidNumber values."),count($this->check_gidNumbers));
263 return(false);
264 }else{
265 $this->checks['gidNumber_usage']['STATUS'] = TRUE;
266 $this->checks['gidNumber_usage']['STATUS_MSG']= _("Ok");
267 $this->checks['gidNumber_usage']['ERROR_MSG'] = "";
268 return(TRUE);
269 }
270 }
273 /* Search for winstations outside the winstation ou
274 */
275 function search_outside_winstations()
276 {
277 $cv = $this->parent->captured_values;
278 $ldap = new LDAP($cv['admin'],
279 $cv['password'],
280 $cv['connection'],
281 FALSE,
282 $cv['tls']);
284 /* Get winstation ou */
285 if($cv['generic_settings']['wws_ou_active']) {
286 $winstation_ou = $cv['generic_settings']['ws_ou'];
287 }else{
288 $winstation_ou = "ou=winstations";
289 }
291 if($cv['samba_version'] == 3){
292 $oc = "sambaSamAccount";
293 }else{
294 $oc = "sambaAccount";
295 }
297 $ldap->cd($cv['base']);
298 $res = $ldap->search("(&(objectClass=".$oc.")(uid=*$))",array("dn","sambaSID"));
299 if(!$res){
300 $this->checks['outside_winstations']['STATUS'] = FALSE;
301 $this->checks['outside_winstations']['STATUS_MSG']= _("Ldap query failed.");
302 $this->checks['outside_winstations']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
303 return(false);
304 }
306 $this->outside_winstations = array();
307 while($attrs = $ldap->fetch()){
308 if((!preg_match("/^[^,]+,".normalizePreg($winstation_ou)."/",$attrs['dn'])) && !preg_match("/,dc=addressbook,/",$attrs['dn'])){
309 $attrs['selected'] = FALSE;
310 $attrs['ldif'] = "";
311 $this->outside_winstations[base64_encode($attrs['dn'])] = $attrs;
312 }
313 }
315 if(count($this->outside_winstations)){
316 $this->checks['outside_winstations']['STATUS'] = FALSE;
317 $this->checks['outside_winstations']['STATUS_MSG']= _("Failed");
318 $this->checks['outside_winstations']['ERROR_MSG'] =
319 sprintf(_("Found %s winstations outside the predefined winstation department ou '%s'."),count($this->outside_winstations),$winstation_ou);
320 $this->checks['outside_winstations']['ERROR_MSG'].= "<input type='submit' name='outside_winstations_dialog' value='"._("Migrate")."'>";
321 return(false);
322 }else{
323 $this->checks['outside_winstations']['STATUS'] = TRUE;
324 $this->checks['outside_winstations']['STATUS_MSG']= _("Ok");
325 $this->checks['outside_winstations']['ERROR_MSG'] = "";
326 return(TRUE);
327 }
328 }
331 /* Search for groups outside the group ou
332 */
333 function search_outside_groups()
334 {
335 $cv = $this->parent->captured_values;
336 $ldap = new LDAP($cv['admin'],
337 $cv['password'],
338 $cv['connection'],
339 FALSE,
340 $cv['tls']);
342 $group_ou = $cv['groupou'];
343 $ldap->cd($cv['base']);
344 $res = $ldap->search("(objectClass=posixGroup)",array("dn"));
345 if(!$res){
346 $this->checks['outside_groups']['STATUS'] = FALSE;
347 $this->checks['outside_groups']['STATUS_MSG']= _("Ldap query failed.");
348 $this->checks['outside_groups']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
349 return(false);
350 }
353 $this->outside_groups = array();
354 while($attrs = $ldap->fetch()){
355 if((!preg_match("/^[^,]+,".normalizePreg($group_ou)."/",$attrs['dn'])) && !preg_match("/,dc=addressbook,/",$attrs['dn'])){
356 $attrs['selected'] = FALSE;
357 $attrs['ldif'] = "";
358 $this->outside_groups[base64_encode($attrs['dn'])] = $attrs;
359 }
360 }
362 if(count($this->outside_groups)){
363 $this->checks['outside_groups']['STATUS'] = FALSE;
364 $this->checks['outside_groups']['STATUS_MSG']= _("Failed");
365 $this->checks['outside_groups']['ERROR_MSG'] =
366 sprintf(_("Found %s groups outside the selected group ou '%s'."),count($this->outside_groups),$group_ou);
367 $this->checks['outside_groups']['ERROR_MSG'].= "<input type='submit' name='outside_groups_dialog' value='"._("Migrate")."'>";
368 return(false);
369 }else{
370 $this->checks['outside_groups']['STATUS'] = TRUE;
371 $this->checks['outside_groups']['STATUS_MSG']= _("Ok");
372 $this->checks['outside_groups']['ERROR_MSG'] = "";
373 return(TRUE);
374 }
375 }
378 /* Search for users outside the people ou
379 */
380 function search_outside_users()
381 {
382 $cv = $this->parent->captured_values;
383 $ldap = new LDAP($cv['admin'],
384 $cv['password'],
385 $cv['connection'],
386 FALSE,
387 $cv['tls']);
388 $people_ou = $cv['peopleou'];
389 $ldap->cd($cv['base']);
390 $res = $ldap->search("(&(objectClass=gosaAccount)(!(uid=*$)))",array("dn"));
391 if(!$res){
392 $this->checks['outside_users']['STATUS'] = FALSE;
393 $this->checks['outside_users']['STATUS_MSG']= _("Ldap query failed.");
394 $this->checks['outside_users']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
395 return(false);
396 }
399 $this->outside_users = array();
400 while($attrs = $ldap->fetch()){
401 if((!preg_match("/^[^,]+,".normalizePreg($people_ou)."/",$attrs['dn']) && !preg_match("/,dc=addressbook,/",$attrs['dn']))){
402 $attrs['selected'] = FALSE;
403 $attrs['ldif'] = "";
404 $this->outside_users[base64_encode($attrs['dn'])] = $attrs;
405 }
406 }
408 if(count($this->outside_users)){
409 $this->checks['outside_users']['STATUS'] = FALSE;
410 $this->checks['outside_users']['STATUS_MSG']= _("Failed");
411 $this->checks['outside_users']['ERROR_MSG'] =
412 sprintf(_("Found %s users outside the selected user ou '%s'."),count($this->outside_users),$people_ou);
413 $this->checks['outside_users']['ERROR_MSG'].= "<input type='submit' name='outside_users_dialog' value='"._("Migrate")."'>";
414 return(false);
415 }else{
416 $this->checks['outside_users']['STATUS'] = TRUE;
417 $this->checks['outside_users']['STATUS_MSG']= _("Ok");
418 $this->checks['outside_users']['ERROR_MSG'] = "";
419 return(TRUE);
420 }
421 }
424 /* Check ldap accessibility
425 * Create and remove a dummy object,
426 * to ensure that we have the necessary permissions
427 */
428 function check_ldap_permissions()
429 {
430 $cv = $this->parent->captured_values;
431 $ldap = new LDAP($cv['admin'],
432 $cv['password'],
433 $cv['connection'],
434 FALSE,
435 $cv['tls']);
437 /* Create dummy entry
438 */
439 $name = "GOsa_setup_text_entry_".session_id().rand(0,999999);
440 $dn = "ou=".$name.",".$cv['base'];
441 $testEntry= array();
442 $testEntry['objectClass'][]= "top";
443 $testEntry['objectClass'][]= "organizationalUnit";
444 $testEntry['objectClass'][]= "gosaDepartment";
445 $testEntry['description']= "Created by GOsa setup, this object can be removed.";
446 $testEntry['ou'] = $name;
448 /* check if simple ldap cat will be successful
449 */
450 $res = $ldap->cat($cv['base']);
451 if(!$res){
452 $this->checks['permissions']['STATUS'] = FALSE;
453 $this->checks['permissions']['STATUS_MSG']= _("Ldap query failed.");
454 $this->checks['permissions']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
455 return(false);
456 }
458 /* Try to create dummy object
459 */
460 $ldap->cd ($dn);
461 $ldap->create_missing_trees($dn);
462 $res = $ldap->add($testEntry);
463 $ldap->cat($dn);
464 if(!$ldap->count()){
465 gosa_log($ldap->get_error());
466 $this->checks['permissions']['STATUS'] = FALSE;
467 $this->checks['permissions']['STATUS_MSG']= _("Failed");
468 $this->checks['permissions']['ERROR_MSG'] =
469 sprintf(_("The specified user '%s' does not have full access to your ldap database."),$cv['admin']);
470 return(false);
471 }
473 /* Try to remove created entry
474 */
475 $res = $ldap->rmDir($dn);
476 $ldap->cat($dn);
477 if($ldap->count()){
478 gosa_log($ldap->get_error());
479 $this->checks['permissions']['STATUS'] = FALSE;
480 $this->checks['permissions']['STATUS_MSG']= _("Failed");
481 $this->checks['permissions']['ERROR_MSG'] =
482 sprintf(_("The specified user '%s' does not have full access to your ldap database."),$cv['admin']);
483 return(false);
484 }
486 /* Create & remove of dummy object was successful */
487 $this->checks['permissions']['STATUS'] = TRUE;
488 $this->checks['permissions']['STATUS_MSG']= _("Ok");
489 $this->checks['permissions']['ERROR_MSG'] = "";
490 return(true);
491 }
494 /* Check if there are users which will
495 * be invisible for GOsa
496 */
497 function check_gosaAccounts()
498 {
499 /* Remember old list of ivisible users, to be able to set
500 * the 'html checked' status for the checkboxes again
501 */
502 $cnt_ok = 0;
503 $old = $this->users_to_migrate;
504 $this->users_to_migrate = array();
506 /* Get collected configuration settings */
507 $cv = $this->parent->captured_values;
509 /* Establish ldap connection */
510 $ldap = new LDAP($cv['admin'],
511 $cv['password'],
512 $cv['connection'],
513 FALSE,
514 $cv['tls']);
516 /* Get all invisible users
517 */
518 $ldap->cd($cv['base']);
519 $res =$ldap->search("(&(|(objectClass=posixAccount)(objectClass=inetOrgPerson)(objectClass=organizationalPerson))(!(objectClass=gosaAccount)))",array("sn","givenName","cn","uid"));
520 while($attrs = $ldap->fetch()){
521 if(!preg_match("/,dc=addressbook,/",$attrs['dn'])){
522 $attrs['checked'] = FALSE;
523 $attrs['before'] = "";
524 $attrs['after'] = "";
526 /* Set objects to selected, that were selected before reload */
527 if(isset($old[base64_encode($attrs['dn'])])){
528 $attrs['checked'] = $old[base64_encode($attrs['dn'])]['checked'];
529 }
530 $this->users_to_migrate[base64_encode($attrs['dn'])] = $attrs;
531 }
532 }
534 /* No invisible */
535 if(!$res){
536 $this->checks['users_visible']['STATUS'] = FALSE;
537 $this->checks['users_visible']['STATUS_MSG']= _("Ldap query failed.");
538 $this->checks['users_visible']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
539 }elseif(count($this->users_to_migrate) == 0){
540 $this->checks['users_visible']['STATUS'] = TRUE;
541 $this->checks['users_visible']['STATUS_MSG']= _("Ok");
542 $this->checks['users_visible']['ERROR_MSG'] = "";
543 }else{
544 $this->checks['users_visible']['STATUS'] = FALSE;
545 $this->checks['users_visible']['STATUS_MSG']= "";
546 $this->checks['users_visible']['ERROR_MSG'] = sprintf(_("Found %s users that will not be visible in GOsa."),
547 count($this->users_to_migrate));
548 $this->checks['users_visible']['ERROR_MSG'] .= "<input type='submit' name='users_visible_migrate' value='"._("Migrate")."'>";
549 }
550 }
553 /* Start user account migration
554 */
555 function migrate_gosaAccounts($only_ldif = FALSE)
556 {
557 /* 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 /* Add gosaAccount objectClass to the selected users
568 */
569 foreach($this->users_to_migrate as $key => $dep){
570 if($dep['checked']){
572 /* Get old objectClasses */
573 $ldap->cat($dep['dn'],array("objectClass"));
574 $attrs = $ldap->fetch();
576 /* Create new objectClass array */
577 $new_attrs = array();
578 $new_attrs['objectClass']= array("gosaAccount","inetOrgPerson","organizationalPerson");
579 for($i = 0 ; $i < $attrs['objectClass']['count']; $i ++ ){
580 if(!in_array_ics($attrs['objectClass'][$i], $new_attrs['objectClass'])){
581 $new_attrs['objectClass'][] = $attrs['objectClass'][$i];
582 }
583 }
585 /* Set info attributes for current object,
586 * or write changes to the ldap database
587 */
588 if($only_ldif){
589 $this->users_to_migrate[$key]['before'] = $this->array_to_ldif($attrs);
590 $this->users_to_migrate[$key]['after'] = $this->array_to_ldif($new_attrs);
591 }else{
592 $ldap->cd($attrs['dn']);
593 if(!$ldap->modify($new_attrs)){
594 print_red(sprintf(_("Failed to migrate the department '%s' into GOsa, error message is as follows '%s'."),$attrs['dn'],$ldap->get_error()));
595 return(false);
596 }
597 }
598 }
599 }
600 return(TRUE);
601 }
604 /* Check if there are invisible organizational Units
605 */
606 function check_organizationalUnits()
607 {
608 $cnt_ok = 0;
609 $old = $this->deps_to_migrate;
610 $this->deps_to_migrate = array();
612 /* Get collected configuration settings */
613 $cv = $this->parent->captured_values;
615 /* Establish ldap connection */
616 $ldap = new LDAP($cv['admin'],
617 $cv['password'],
618 $cv['connection'],
619 FALSE,
620 $cv['tls']);
622 /* Skip GOsa internal departments */
623 $skip_dns = array("/^ou=people,/","/^ou=groups,/","/(,|)ou=configs,/","/(,|)ou=systems,/",
624 "/^ou=apps,/","/^ou=mime,/","/^ou=aclroles,/","/^ou=incoming,/",
625 "/ou=snapshots,/","/(,|)dc=addressbook,/","/^(,|)ou=machineaccounts,/",
626 "/(,|)ou=winstations,/");
629 /* Get all invisible departments */
630 $ldap->cd($cv['base']);
631 $res = $ldap->search("(&(objectClass=organizationalUnit)(!(objectClass=gosaDepartment)))",array("ou","description","dn"));
632 while($attrs = $ldap->fetch()){
633 $attrs['checked'] = FALSE;
634 $attrs['before'] = "";
635 $attrs['after'] = "";
637 /* Set objects to selected, that were selected before reload */
638 if(isset($old[base64_encode($attrs['dn'])])){
639 $attrs['checked'] = $old[base64_encode($attrs['dn'])]['checked'];
640 }
641 $this->deps_to_migrate[base64_encode($attrs['dn'])] = $attrs;
642 }
644 /* Filter returned list of departments and ensure that
645 * GOsa internal departments will not be listed
646 */
647 foreach($this->deps_to_migrate as $key => $attrs){
648 $dn = $attrs['dn'];
649 $skip = false;
650 foreach($skip_dns as $skip_dn){
651 if(preg_match($skip_dn,$dn)){
652 $skip = true;
653 }
654 }
655 if($skip){
656 unset($this->deps_to_migrate[$key]);
657 }
658 }
660 /* If we have no invisible departments found
661 * tell the user that everything is ok
662 */
663 if(!$res){
664 $this->checks['deps_visible']['STATUS'] = FALSE;
665 $this->checks['deps_visible']['STATUS_MSG']= _("Ldap query failed.");
666 $this->checks['deps_visible']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
667 }elseif(count($this->deps_to_migrate) == 0 ){
668 $this->checks['deps_visible']['STATUS'] = TRUE;
669 $this->checks['deps_visible']['STATUS_MSG']= _("Ok");
670 $this->checks['deps_visible']['ERROR_MSG'] = "";
671 }else{
672 $this->checks['deps_visible']['STATUS'] = FALSE;
673 $this->checks['deps_visible']['STATUS_MSG']= "";//sprintf(_("%s entries found"),count($this->deps_to_migrate));
674 $this->checks['deps_visible']['ERROR_MSG'] = sprintf(_("Found %s departments that will not be visible in GOsa."),count($this->deps_to_migrate));
675 $this->checks['deps_visible']['ERROR_MSG'] .= "<input type='submit' name='deps_visible_migrate' value='"._("Migrate")."'>";
676 }
677 }
681 /* Start deparmtment migration */
682 function migrate_organizationalUnits($only_ldif = FALSE)
683 {
684 /* Get collected configuration settings */
685 $cv = $this->parent->captured_values;
687 /* Establish ldap connection */
688 $ldap = new LDAP($cv['admin'],
689 $cv['password'],
690 $cv['connection'],
691 FALSE,
692 $cv['tls']);
694 /* Add gosaDepartment objectClass to each selected entry
695 */
696 foreach($this->deps_to_migrate as $key => $dep){
697 if($dep['checked']){
699 /* Get current objectClasses */
700 $ldap->cat($dep['dn'],array("objectClass","description"));
701 $attrs = $ldap->fetch();
703 /* Create new objectClass attribute including gosaDepartment*/
704 $new_attrs = array();
705 for($i = 0 ; $i < $attrs['objectClass']['count']; $i ++ ){
706 $new_attrs['objectClass'][] = $attrs['objectClass'][$i];
707 }
708 $new_attrs['objectClass'][] = "gosaDepartment";
710 /* Append description it is missing */
711 if(!isset($attrs['description'])){
712 $new_attrs['description'][] = "GOsa department";
713 }
715 /* Depending on the parameter >only_diff< we save the changes as ldif
716 * or we write our changes directly to the ldap database
717 */
718 if($only_ldif){
719 $this->deps_to_migrate[$key]['before'] = $this->array_to_ldif($attrs);
720 $this->deps_to_migrate[$key]['after'] = $this->array_to_ldif($new_attrs);
721 }else{
722 $ldap->cd($attrs['dn']);
723 if(!$ldap->modify($new_attrs)){
724 print_red(sprintf(_("Failed to migrate the department '%s' into GOsa, error message is as follows '%s'."),$attrs['dn'],$ldap->get_error()));
725 return(false);
726 }
727 }
728 }
729 }
730 return(TRUE);
731 }
734 /* Check Acls if there is at least one object with acls defined
735 */
736 function check_administrativeAccount()
737 {
738 /* Establish ldap connection */
739 $cv = $this->parent->captured_values;
740 $ldap = new LDAP($cv['admin'],
741 $cv['password'],
742 $cv['connection'],
743 FALSE,
744 $cv['tls']);
746 /* Search for gosaAcls */
747 $ldap->cd($cv['base']);
748 $res = $ldap->search("(&(objectClass=gosaAccount)(|(objectClass=posixAccount)".
749 "(objectClass=inetOrgPerson)(objectClass=organizationalPerson)))");
750 if(!$res){
751 $this->checks['acls']['STATUS'] = FALSE;
752 $this->checks['acls']['STATUS_MSG']= _("Ldap query failed.");
753 $this->checks['acls']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
754 }elseif($ldap->count()){
755 $this->checks['acls']['STATUS'] = TRUE;
756 $this->checks['acls']['STATUS_MSG']= _("Ok");
757 $this->checks['acls']['ERROR_MSG'] = "";
758 }else{
759 $this->checks['acls']['STATUS'] = FALSE;
760 $this->checks['acls']['STATUS_MSG']= _("Failed");
761 $this->checks['acls']['ERROR_MSG'].= "<input type='submit' name='create_acls' value='"._("Create adminitrational account")."'>";
762 }
763 return($ldap->count()>=1);
764 }
768 function create_admin($only_ldif = FALSE)
769 {
770 /* Reset '' */
771 $this->acl_create_changes="";
773 /* Object that should receive admin acls */
774 $dn = $this->acl_create_selected;
776 /* Get collected configuration settings */
777 $cv = $this->parent->captured_values;
779 /* Establish ldap connection */
780 $ldap = new LDAP($cv['admin'],
781 $cv['password'],
782 $cv['connection'],
783 FALSE,
784 $cv['tls']);
786 /* Get current base attributes */
787 $ldap->cd($cv['base']);
788 $ldap->cat($cv['base'],array("dn","objectClass","gosaAclEntry"));
789 $attrs = $ldap->fetch();
791 /* Add acls for the selcted user to the base */
792 $attrs_new['objectClass'] = array("gosaACL");
794 for($i = 0; $i < $attrs['objectClass']['count']; $i ++){
795 if(!in_array_ics($attrs['objectClass'][$i],$attrs_new['objectClass'])){
796 $attrs_new['objectClass'][] = $attrs['objectClass'][$i];
797 }
798 }
800 $acl = "0:psub:".base64_encode($dn).":all;cmdrw";
801 $attrs_new['gosaAclEntry'][] = $acl;
802 if(isset($attrs['gosaAclEntry'])){
803 for($i = 0 ; $i < $attrs['gosaAclEntry']['count']; $i ++){
805 $prio = preg_replace("/[:].*$/","",$attrs['gosaAclEntry'][$i]);
806 $rest = preg_replace("/^[^:]/","",$attrs['gosaAclEntry'][$i]);
808 $data = ($prio+1).$rest;
809 $attrs_new['gosaAclEntry'][] = $data;
810 }
811 }
813 if($only_ldif){
814 $this->acl_create_changes ="\n".$cv['base']."\n";
815 $this->acl_create_changes.=$this->array_to_ldif($attrs)."\n";
816 $this->acl_create_changes.="\n".$cv['base']."\n";
817 $this->acl_create_changes.=$this->array_to_ldif($attrs_new);
818 }else{
820 $ldap->cd($cv['base']);
821 if(!$ldap->modify($attrs_new)){
822 print_red(sprintf(_("Adding acls for user '%s' failed, ldap says '%s'."),$dn,$ldap->get_error()));
823 }
824 }
825 }
828 function create_admin_user()
829 {
830 $pw1 = $pw2 = "";
832 if(isset($_POST['new_user_password'])){
833 $pw1 = $_POST['new_user_password'];
834 }
835 if(isset($_POST['new_user_password2'])){
836 $pw2 = $_POST['new_user_password2'];
837 }
839 if(empty($pw1) || empty($pw2) | ($pw1 != $pw2)){
840 print_red(_("Specified passwords are empty or not equal."));
841 return false;
842 }
844 /* Establish ldap connection */
845 $cv = $this->parent->captured_values;
846 $ldap = new LDAP($cv['admin'],
847 $cv['password'],
848 $cv['connection'],
849 FALSE,
850 $cv['tls']);
852 /* Get current base attributes */
853 $ldap->cd($cv['base']);
855 if($cv['peopledn'] == "cn"){
856 $dn = "cn=System Administrator,".$cv['peopleou'].",".$cv['base'];
857 }else{
858 $dn = "uid=admin,".$cv['peopleou'].",".$cv['base'];
859 }
861 $methods = @passwordMethod::get_available_methods_if_not_loaded();
862 $p_m = $methods[$cv['encryption']];
863 $p_c = new $p_m(array());
864 $hash = $p_c->generate_hash($pw2);
866 $new_user=array();
867 $new_user['objectClass']= array("top","person","gosaAccount","organizationalPerson","inetOrgPerson");
868 $new_user['givenName'] = "System";
869 $new_user['sn'] = "Administrator";
870 $new_user['cn'] = "System Administrator";
871 $new_user['uid'] = "admin";
872 $new_user['userPassword'] = $hash;
874 $ldap->cd($cv['base']);
875 $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$dn));
876 $ldap->cd($dn);
877 $res = $ldap->add($new_user);
878 $this->acl_create_selected = $dn;
879 $this->create_admin();
881 if(!$res){
882 print_red($ldap->get_error());
883 return(FALSE);
884 }
886 $this->acl_create_dialog=FALSE;
887 $this->check_administrativeAccount();
888 return(TRUE);
889 }
892 function migrate_outside_winstations($perform = FALSE)
893 {
894 /* Establish ldap connection */
895 $cv = $this->parent->captured_values;
896 $ldap = new LDAP($cv['admin'],
897 $cv['password'],
898 $cv['connection'],
899 FALSE,
900 $cv['tls']);
902 $ldap->cd($cv['base']);
904 /* Check if there was a destination department posted */
905 if(isset($_POST['move_winstation_to'])){
906 $destination_dep = $_POST['move_winstation_to'];
907 }else{
908 print_red(_("Couldn't move users to specified department."));
909 return(false);
910 }
912 foreach($this->outside_winstations as $b_dn => $data){
913 $this->outside_winstations[$b_dn]['ldif'] ="";
914 if($data['selected']){
915 $dn = base64_decode($b_dn);
916 $d_dn = preg_replace("/,.*$/",",".base64_decode($destination_dep),$dn);
917 if(!$perform){
918 $this->outside_winstations[$b_dn]['ldif'] = _("Winstation will be moved from").":<br>\t".$dn."<br>"._("to").":<br>\t".$d_dn;
921 /* Check if there are references to this object */
922 $ldap->search("(&(member=".$dn.")(|(objectClass=gosaGroupOfNames)(objectClass=groupOfNames)))",array('dn'));
923 $refs = "";
924 while($attrs = $ldap->fetch()){
925 $ref_dn = $attrs['dn'];
926 $refs .= "<br />\t".$ref_dn;
927 }
928 if(!empty($refs)){
929 $this->outside_winstations[$b_dn]['ldif'] .= "<br /><br /><i>"._("Updating following references too").":</i>".$refs;
930 }
932 }else{
933 $this->move($dn,$d_dn);
934 }
935 }
936 }
937 }
940 function migrate_outside_groups($perform = FALSE)
941 {
942 /* Establish ldap connection */
943 $cv = $this->parent->captured_values;
944 $ldap = new LDAP($cv['admin'],
945 $cv['password'],
946 $cv['connection'],
947 FALSE,
948 $cv['tls']);
950 $ldap->cd($cv['base']);
952 /* Check if there was a destination department posted */
953 if(isset($_POST['move_group_to'])){
954 $destination_dep = $_POST['move_group_to'];
955 }else{
956 print_red(_("Couldn't move users to specified department."));
957 return(false);
958 }
960 foreach($this->outside_groups as $b_dn => $data){
961 $this->outside_groups[$b_dn]['ldif'] ="";
962 if($data['selected']){
963 $dn = base64_decode($b_dn);
964 $d_dn = preg_replace("/,.*$/",",".base64_decode($destination_dep),$dn);
965 if(!$perform){
966 $this->outside_groups[$b_dn]['ldif'] = _("Group will be moved from").":<br>\t".$dn."<br>"._("to").":<br>\t".$d_dn;
969 /* Check if there are references to this object */
970 $ldap->search("(&(member=".$dn.")(|(objectClass=gosaGroupOfNames)(objectClass=groupOfNames)))",array('dn'));
971 $refs = "";
972 while($attrs = $ldap->fetch()){
973 $ref_dn = $attrs['dn'];
974 $refs .= "<br />\t".$ref_dn;
975 }
976 if(!empty($refs)){
977 $this->outside_groups[$b_dn]['ldif'] .= "<br /><br /><i>"._("Updating following references too").":</i>".$refs;
978 }
980 }else{
981 $this->move($dn,$d_dn);
982 }
983 }
984 }
985 }
988 function migrate_outside_users($perform = FALSE)
989 {
990 /* Establish ldap connection */
991 $cv = $this->parent->captured_values;
992 $ldap = new LDAP($cv['admin'],
993 $cv['password'],
994 $cv['connection'],
995 FALSE,
996 $cv['tls']);
998 $ldap->cd($cv['base']);
1000 /* Check if there was a destination department posted */
1001 if(isset($_POST['move_user_to'])){
1002 $destination_dep = $_POST['move_user_to'];
1003 }else{
1004 print_red(_("Couldn't move users to specified department."));
1005 return(false);
1006 }
1008 foreach($this->outside_users as $b_dn => $data){
1009 $this->outside_users[$b_dn]['ldif'] ="";
1010 if($data['selected']){
1011 $dn = base64_decode($b_dn);
1012 $d_dn = preg_replace("/,.*$/",",".base64_decode($destination_dep),$dn);
1013 if(!$perform){
1014 $this->outside_users[$b_dn]['ldif'] = _("User will be moved from").":<br>\t".$dn."<br>"._("to").":<br>\t".$d_dn;
1016 /* Check if there are references to this object */
1017 $ldap->search("(&(member=".$dn.")(|(objectClass=gosaGroupOfNames)(objectClass=groupOfNames)))",array('dn'));
1018 $refs = "";
1019 while($attrs = $ldap->fetch()){
1020 $ref_dn = $attrs['dn'];
1021 $refs .= "<br />\t".$ref_dn;
1022 }
1023 if(!empty($refs)){
1024 $this->outside_users[$b_dn]['ldif'] .= "<br /><br /><i>"._("Updating following references too").":</i>".$refs;
1025 }
1027 }else{
1028 $this->move($dn,$d_dn);
1029 }
1030 }
1031 }
1032 }
1035 function execute()
1036 {
1037 /* Initialise checks if this is the first call */
1038 if(!$this->checks_initialised || isset($_POST['reload'])){
1039 $this->initialize_checks();
1040 $this->checks_initialised = TRUE;
1041 }
1043 /*************
1044 * Winstations outside the group ou
1045 *************/
1047 if(isset($_POST['outside_winstations_dialog_cancel'])){
1048 $this->outside_winstations_dialog = FALSE;
1049 $this->dialog = FALSE;
1050 }
1052 if(isset($_POST['outside_winstations_dialog_whats_done'])){
1053 $this->migrate_outside_winstations(FALSE);
1054 }
1056 if(isset($_POST['outside_winstations_dialog_perform'])){
1057 $this->migrate_outside_winstations(TRUE);
1058 $this->search_outside_winstations();
1059 }
1061 if(isset($_POST['outside_winstations_dialog'])){
1062 $this->outside_winstations_dialog = TRUE;
1063 $this->dialog = TRUE;
1064 }
1066 if($this->outside_winstations_dialog){
1067 $smarty = get_smarty();
1068 $smarty->assign("ous",$this->get_all_winstation_ous());
1069 $smarty->assign("method","outside_winstations");
1070 $smarty->assign("outside_winstations",$this->outside_winstations);
1071 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1072 }
1073 /*************
1074 * Groups outside the group ou
1075 *************/
1077 if(isset($_POST['outside_groups_dialog_cancel'])){
1078 $this->outside_groups_dialog = FALSE;
1079 $this->dialog = FALSE;
1080 }
1082 if(isset($_POST['outside_groups_dialog_whats_done'])){
1083 $this->migrate_outside_groups(FALSE);
1084 }
1086 if(isset($_POST['outside_groups_dialog_perform'])){
1087 $this->migrate_outside_groups(TRUE);
1088 $this->search_outside_groups();
1089 }
1091 if(isset($_POST['outside_groups_dialog'])){
1092 $this->outside_groups_dialog = TRUE;
1093 $this->dialog = TRUE;
1094 }
1096 if($this->outside_groups_dialog){
1097 $smarty = get_smarty();
1098 $smarty->assign("ous",$this->get_all_group_ous());
1099 $smarty->assign("method","outside_groups");
1100 $smarty->assign("outside_groups",$this->outside_groups);
1101 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1102 }
1104 /*************
1105 * User outside the people ou
1106 *************/
1108 if(isset($_POST['outside_users_dialog_cancel'])){
1109 $this->outside_users_dialog = FALSE;
1110 $this->dialog = FALSE;
1111 }
1113 if(isset($_POST['outside_users_dialog_whats_done'])){
1114 $this->migrate_outside_users(FALSE);
1115 }
1117 if(isset($_POST['outside_users_dialog_perform'])){
1118 $this->migrate_outside_users(TRUE);
1119 $this->search_outside_users();
1120 }
1122 if(isset($_POST['outside_users_dialog'])){
1123 $this->outside_users_dialog = TRUE;
1124 $this->dialog = TRUE;
1125 }
1127 if($this->outside_users_dialog){
1128 $smarty = get_smarty();
1129 $smarty->assign("ous",$this->get_all_people_ous());
1130 $smarty->assign("method","outside_users");
1131 $smarty->assign("outside_users",$this->outside_users);
1132 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1133 }
1135 /*************
1136 * Root object check
1137 *************/
1139 if(isset($_POST['retry_root_create'])){
1141 $state = $this->checks['root']['STATUS'];
1142 $this->checkBase(FALSE);
1143 if($state != $this->checks['root']['STATUS']){
1144 $this->initialize_checks();
1145 }
1146 }
1148 /*************
1149 * User Migration handling
1150 *************/
1152 if(isset($_POST['retry_acls'])){
1153 $this->check_administrativeAccount();
1154 }
1156 if(isset($_POST['create_acls'])){
1157 $this->acl_create_dialog = TRUE;
1158 $this->dialog = TRUE;
1159 }
1161 if(isset($_POST['create_acls_cancel'])){
1162 $this->acl_create_dialog = FALSE;
1163 $this->dialog = FALSE;
1164 }
1166 if(isset($_POST['create_acls_create_confirmed'])){
1167 $this->create_admin();
1168 }
1170 if(isset($_POST['create_acls_create'])){
1171 $this->create_admin(TRUE);
1172 }
1174 if(isset($_POST['create_admin_user'])){
1175 if($this->create_admin_user()){
1176 $this->dialog = FALSE;
1177 }
1178 }
1180 if($this->acl_create_dialog){
1181 $smarty = get_smarty();
1182 $smarty->assign("new_user_password",@$_POST['new_user_password']);
1183 $smarty->assign("new_user_password2",@$_POST['new_user_password2']);
1184 $smarty->assign("users" ,$this->get_user_list());
1185 $smarty->assign("users_cnt" ,count($this->get_user_list()));
1186 $smarty->assign("groups",$this->get_group_list());
1187 $smarty->assign("groups_cnt",count($this->get_group_list()));
1188 $smarty->assign("type" ,$this->acl_create_type);
1189 $smarty->assign("method","create_acls");
1190 $smarty->assign("acl_create_selected",$this->acl_create_selected);
1191 $smarty->assign("what_will_be_done_now",$this->acl_create_changes);
1192 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1193 }
1195 /*************
1196 * User Migration handling
1197 *************/
1199 /* Refresh list of deparments */
1200 if(isset($_POST['users_visible_migrate_refresh'])){
1201 $this->check_gosaAccounts();
1202 }
1204 /* Open migration dialog */
1205 if(isset($_POST['users_visible_migrate'])){
1206 $this->users_migration_dialog = TRUE;
1207 $this->dialog =TRUE;
1208 }
1210 /* Close migration dialog */
1211 if(isset($_POST['users_visible_migrate_close'])){
1212 $this->users_migration_dialog = FALSE;
1213 $this->dialog =FALSE;
1214 }
1216 /* Start migration */
1217 if(isset($_POST['users_visible_migrate_migrate'])){
1218 if($this->migrate_gosaAccounts()){
1219 $this->check_gosaAccounts();
1220 }
1221 }
1223 /* Start migration */
1224 if(isset($_POST['users_visible_migrate_whatsdone'])){
1225 $this->migrate_gosaAccounts(TRUE);
1226 }
1228 /* Display migration dialog */
1229 if($this->users_migration_dialog){
1230 $smarty = get_smarty();
1231 $smarty->assign("users_to_migrate",$this->users_to_migrate);
1232 $smarty->assign("method","migrate_users");
1233 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1234 }
1237 /*************
1238 * Department Migration handling
1239 *************/
1241 /* Refresh list of deparments */
1242 if(isset($_POST['deps_visible_migrate_refresh'])){
1243 $this->check_organizationalUnits();
1244 }
1246 /* Open migration dialog */
1247 if(isset($_POST['deps_visible_migrate'])){
1248 $this->dep_migration_dialog = TRUE;
1249 $this->dialog =TRUE;
1250 }
1252 /* Close migration dialog */
1253 if(isset($_POST['deps_visible_migrate_close'])){
1254 $this->dep_migration_dialog = FALSE;
1255 $this->dialog =FALSE;
1256 }
1258 /* Start migration */
1259 if(isset($_POST['deps_visible_migrate_migrate'])){
1260 if($this->migrate_organizationalUnits()){
1261 $this->check_organizationalUnits();
1262 }
1263 }
1265 /* Start migration */
1266 if(isset($_POST['deps_visible_migrate_whatsdone'])){
1267 $this->migrate_organizationalUnits(TRUE);
1268 }
1270 /* Display migration dialog */
1271 if($this->dep_migration_dialog){
1272 $smarty = get_smarty();
1273 $smarty->assign("deps_to_migrate",$this->deps_to_migrate);
1274 $smarty->assign("method","migrate_deps");
1275 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1276 }
1278 $smarty = get_smarty();
1279 $smarty->assign("checks",$this->checks);
1280 $smarty->assign("method","default");
1281 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
1282 }
1285 function save_object()
1286 {
1287 $this->is_completed= TRUE;
1289 /* Capture all selected winstations from outside_winstations_dialog */
1290 if($this->outside_winstations_dialog){
1291 foreach($this->outside_winstations as $dn => $data){
1292 if(isset($_POST['select_winstation_'.$dn])){
1293 $this->outside_winstations[$dn]['selected'] = TRUE;
1294 }else{
1295 $this->outside_winstations[$dn]['selected'] = FALSE;
1296 }
1297 }
1298 }
1300 /* Capture all selected groups from outside_groups_dialog */
1301 if($this->outside_groups_dialog){
1302 foreach($this->outside_groups as $dn => $data){
1303 if(isset($_POST['select_group_'.$dn])){
1304 $this->outside_groups[$dn]['selected'] = TRUE;
1305 }else{
1306 $this->outside_groups[$dn]['selected'] = FALSE;
1307 }
1308 }
1309 }
1311 /* Capture all selected users from outside_users_dialog */
1312 if($this->outside_users_dialog){
1313 foreach($this->outside_users as $dn => $data){
1314 if(isset($_POST['select_user_'.$dn])){
1315 $this->outside_users[$dn]['selected'] = TRUE;
1316 }else{
1317 $this->outside_users[$dn]['selected'] = FALSE;
1318 }
1319 }
1320 }
1322 /* Get "create acl" dialog posts */
1323 if($this->acl_create_dialog){
1324 if(isset($_POST['create_acls_create'])){
1325 if(isset($_POST['create_acls_selected'])){
1326 $this->acl_create_selected = base64_decode($_POST['create_acls_selected']);
1327 }else{
1328 $this->acl_create_selected = "";
1329 }
1330 }
1332 if(isset($_POST['create_acls_create_abort'])){
1333 $this->acl_create_selected = "";
1334 }
1336 if(isset($_POST['acl_create_type'])){
1337 $this->acl_create_type = $_POST['acl_create_type'];
1338 }
1339 }
1341 /* Get selected departments */
1342 if($this->dep_migration_dialog){
1343 foreach($this->deps_to_migrate as $id => $data){
1344 if(isset($_POST['migrate_'.$id])){
1345 $this->deps_to_migrate[$id]['checked'] = TRUE;
1346 }else{
1347 $this->deps_to_migrate[$id]['checked'] = FALSE;
1348 }
1349 }
1350 }
1352 /* Get selected users */
1353 if($this->users_migration_dialog){
1354 foreach($this->users_to_migrate as $id => $data){
1355 if(isset($_POST['migrate_'.$id])){
1356 $this->users_to_migrate[$id]['checked'] = TRUE;
1357 }else{
1358 $this->users_to_migrate[$id]['checked'] = FALSE;
1359 }
1360 }
1361 }
1362 }
1365 /* Check if the root object exists.
1366 * If the parameter just_check is true, then just check if the
1367 * root object is missing and update the info messages.
1368 * If the Parameter is false, try to create a new root object.
1369 */
1370 function checkBase($just_check = TRUE)
1371 {
1372 /* Get collected setup informations */
1373 $cv = $this->parent->captured_values;
1375 /* Establish ldap connection */
1376 $ldap = new LDAP($cv['admin'],
1377 $cv['password'],
1378 $cv['connection'],
1379 FALSE,
1380 $cv['tls']);
1382 /* Check if root object exists */
1383 $ldap->cd($cv['base']);
1384 $res = $ldap->search("(objectClass=*)");
1385 $err = ldap_errno($ldap->cid);
1387 if( !$res ||
1388 $err == 0x20 || # LDAP_NO_SUCH_OBJECT
1389 $err == 0x40) { # LDAP_NAMING_VIOLATION
1391 /* Root object doesn't exists
1392 */
1393 if($just_check){
1394 $this->checks['root']['STATUS'] = FALSE;
1395 $this->checks['root']['STATUS_MSG']= _("Failed");
1396 $this->checks['root']['ERROR_MSG'] = "The ldap root object is missing, but it is required to use GOsa. ";
1397 $this->checks['root']['ERROR_MSG'].= "<input type='submit' name='retry_root_create' value='"._("Try to create root object")."'>";
1398 return(FALSE);
1399 }else{
1401 /* Add root object */
1402 $ldap->cd($cv['base']);
1403 $res = $ldap->create_missing_trees($cv['base']);
1405 /* If adding failed, tell the user */
1406 if(!$res){
1407 $this->checks['root']['STATUS'] = FALSE;
1408 $this->checks['root']['STATUS_MSG']= _("Failed");
1409 $this->checks['root']['ERROR_MSG'] = _("Root object couldn't be created, you should try it on your own.");
1410 $this->checks['root']['ERROR_MSG'].= "<input type='submit' name='retry_root_create' value='"._("Try to create root object")."'>";
1411 return($res);;
1412 }
1413 }
1414 }
1416 /* Create & remove of dummy object was successful */
1417 $this->checks['root']['STATUS'] = TRUE;
1418 $this->checks['root']['STATUS_MSG']= _("Ok");
1419 }
1422 /* Return ldif information for a
1423 * given attribute array
1424 */
1425 function array_to_ldif($atts)
1426 {
1427 $ret = "";
1428 unset($atts['count']);
1429 unset($atts['dn']);
1430 foreach($atts as $name => $value){
1431 if(is_numeric($name)) {
1432 continue;
1433 }
1434 if(is_array($value)){
1435 unset($value['count']);
1436 foreach($value as $a_val){
1437 $ret .= $name.": ". $a_val."\n";
1438 }
1439 }else{
1440 $ret .= $name.": ". $value."\n";
1441 }
1442 }
1443 return(preg_replace("/\n$/","",$ret));
1444 }
1447 function get_user_list()
1448 {
1449 /* Get collected configuration settings */
1450 $cv = $this->parent->captured_values;
1452 /* Establish ldap connection */
1453 $ldap = new LDAP($cv['admin'],
1454 $cv['password'],
1455 $cv['connection'],
1456 FALSE,
1457 $cv['tls']);
1459 $ldap->cd($cv['base']);
1460 $ldap->search("(objectClass=gosaAccount)",array("dn"));
1462 $tmp = array();
1463 while($attrs = $ldap->fetch()){
1464 $tmp[base64_encode($attrs['dn'])] = @LDAP::fix($attrs['dn']);
1465 }
1466 return($tmp);
1467 }
1470 function get_all_people_ous()
1471 {
1472 /* Get collected configuration settings */
1473 $cv = $this->parent->captured_values;
1475 /* Establish ldap connection */
1476 $ldap = new LDAP($cv['admin'],
1477 $cv['password'],
1478 $cv['connection'],
1479 FALSE,
1480 $cv['tls']);
1482 $ldap->cd($cv['base']);
1483 $ldap->search("(".$cv['peopleou'].")",array("dn"));
1485 if($ldap->count() == 0 ){
1486 $add_dn = $cv['peopleou'].",".$cv['base'];
1487 $naming_attr = preg_replace("/=.*$/","",$add_dn);
1488 $naming_value = preg_replace("/^[^=]*+=([^,]*).*$/","\\1",$add_dn);
1489 $add = array();
1490 $add['objectClass'] = array("organizationalUnit");
1491 $add[$naming_attr] = $naming_value;
1493 $ldap->cd($cv['base']);
1494 $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$add_dn));
1495 $ldap->cd($add_dn);
1496 $ldap->add($add);
1497 }
1499 $ldap->search("(".$cv['peopleou'].")",array("dn"));
1500 $tmp = array();
1501 while($attrs= $ldap->fetch()){
1502 if(!preg_match("/ou=snapshots,/",$attrs['dn'])){
1503 $tmp[base64_encode($attrs['dn'])] = $ldap->fix($attrs['dn']);
1504 }
1505 }
1506 return($tmp);
1507 }
1509 function get_all_winstation_ous()
1510 {
1511 /* Get collected configuration settings */
1512 $cv = $this->parent->captured_values;
1514 /* Establish ldap connection */
1515 $ldap = new LDAP($cv['admin'],
1516 $cv['password'],
1517 $cv['connection'],
1518 FALSE,
1519 $cv['tls']);
1521 /* Get winstation ou */
1522 if($cv['generic_settings']['wws_ou_active']) {
1523 $winstation_ou = $cv['generic_settings']['ws_ou'];
1524 }else{
1525 $winstation_ou = "ou=winstations";
1526 }
1528 $ldap->cd($cv['base']);
1529 $ldap->search("(".$winstation_ou.")",array("dn"));
1531 if($ldap->count() == 0 ){
1532 $add_dn = $winstation_ou.",ou=systems,".$cv['base'];
1533 $naming_attr = preg_replace("/=.*$/","",$add_dn);
1534 $naming_value = preg_replace("/^[^=]*+=([^,]*).*$/","\\1",$add_dn);
1535 $add = array();
1536 $add['objectClass'] = array("organizationalUnit");
1537 $add[$naming_attr] = $naming_value;
1539 $ldap->cd($cv['base']);
1540 $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$add_dn));
1541 $ldap->cd($add_dn);
1542 $ldap->add($add);
1543 }
1545 $ldap->search("(".$winstation_ou.")",array("dn"));
1546 $tmp = array();
1547 while($attrs= $ldap->fetch()){
1548 if(!preg_match("/ou=snapshots,/",$attrs['dn'])){
1549 $tmp[base64_encode($attrs['dn'])] = $ldap->fix($attrs['dn']);
1550 }
1551 }
1552 return($tmp);
1553 }
1556 function get_all_group_ous()
1557 {
1558 /* Get collected configuration settings */
1559 $cv = $this->parent->captured_values;
1561 /* Establish ldap connection */
1562 $ldap = new LDAP($cv['admin'],
1563 $cv['password'],
1564 $cv['connection'],
1565 FALSE,
1566 $cv['tls']);
1568 $ldap->cd($cv['base']);
1569 $ldap->search("(".$cv['groupou'].")",array("dn"));
1571 if($ldap->count() == 0 ){
1572 $add_dn = $cv['groupou'].",".$cv['base'];
1573 $naming_attr = preg_replace("/=.*$/","",$add_dn);
1574 $naming_value = preg_replace("/^[^=]*+=([^,]*).*$/","\\1",$add_dn);
1575 $add = array();
1576 $add['objectClass'] = array("organizationalUnit");
1577 $add[$naming_attr] = $naming_value;
1579 $ldap->cd($cv['base']);
1580 $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$add_dn));
1581 $ldap->cd($add_dn);
1582 $ldap->add($add);
1583 }
1585 $ldap->search("(".$cv['groupou'].")",array("dn"));
1586 $tmp = array();
1587 while($attrs= $ldap->fetch()){
1588 if(!preg_match("/ou=snapshots,/",$attrs['dn'])){
1589 $tmp[base64_encode($attrs['dn'])] = $ldap->fix($attrs['dn']);
1590 }
1591 }
1592 return($tmp);
1593 }
1596 function get_group_list()
1597 {
1598 /* Get collected configuration settings */
1599 $cv = $this->parent->captured_values;
1601 /* Establish ldap connection */
1602 $ldap = new LDAP($cv['admin'],
1603 $cv['password'],
1604 $cv['connection'],
1605 FALSE,
1606 $cv['tls']);
1608 $ldap->cd($cv['base']);
1609 $ldap->search("(objectClass=posixGroup)",array("dn"));
1611 $tmp = array();
1612 while($attrs = $ldap->fetch()){
1613 $tmp[base64_encode($attrs['dn'])] = @LDAP::fix($attrs['dn']);
1614 }
1615 return($tmp);
1616 }
1619 function move($source,$destination)
1620 {
1621 /* Get collected configuration settings */
1622 $cv = $this->parent->captured_values;
1624 /* Establish ldap connection */
1625 $ldap = new LDAP($cv['admin'],
1626 $cv['password'],
1627 $cv['connection'],
1628 FALSE,
1629 $cv['tls']);
1631 /* Update object references in gosaGroupOfNames */
1632 $ogs_to_fix = array();
1633 $ldap->cd($cv['base']);
1634 $ldap->search('(&(objectClass=gosaGroupOfNames)(member='.@LDAP::fix($source).'))', array('cn','member'));
1635 while ($attrs= $ldap->fetch()){
1636 $dn = $attrs['dn'];
1637 $attrs = $this->cleanup_array($attrs);
1638 $member_new = array($destination);
1639 foreach($attrs['member'] as $member){
1640 if($member != $source){
1641 $member_new[] = $member;
1642 }
1643 }
1644 $attrs['member'] = $member_new;
1645 $ogs_to_fix[$dn] = $attrs;
1646 }
1648 /* Copy source to destination dn */
1649 $ldap->cat($source);
1650 $new_data = $this->cleanup_array($ldap->fetch());
1651 $ldap->cd($destination);
1652 $res = $ldap->add($new_data);
1654 /* Display warning if copy failed */
1655 if(!$res){
1656 print_red(_("Failed to copy '%s' to '%s'. Ldap says '%s'."),$source,$destination,$ldap->get_error());
1657 }else{
1658 $res = $ldap->rmDir($source);
1659 show_ldap_error($ldap->get_error(),_("Something went wrong while copying dns."));
1661 /* Object is copied, so update its references */
1662 foreach($ogs_to_fix as $dn => $data){
1663 $ldap->cd($dn);
1664 $ldap->modify($data);
1665 }
1666 }
1667 }
1670 /* Cleanup ldap result to be able to write it be to ldap */
1671 function cleanup_array($attrs)
1672 {
1673 foreach($attrs as $key => $value) {
1674 if(is_numeric($key) || in_array($key,array("count","dn"))){
1675 unset($attrs[$key]);
1676 }
1677 if(is_array($value) && isset($value['count'])){
1678 unset($attrs[$key]['count']);
1679 }
1680 }
1681 return($attrs);
1682 }
1683 }
1685 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1686 ?>