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 */
25 class Step_Migrate extends setup_step
26 {
27 var $languages = array();
28 var $attributes = array();
29 var $header_image = "images/monitoring.png";
30 var $checks = array();
32 /* Department migration attributes */
33 var $dep_migration_dialog = FALSE;
34 var $deps_to_migrate = array();
36 /* Department migration attributes */
37 var $users_migration_dialog= FALSE;
38 var $users_to_migrate = array();
40 /* Create Acl attributes */
41 var $acl_create_dialog = FALSE;
42 var $acl_create_type = "group";
43 var $acl_create_selected= ""; // Currently selected element, that should receive admin rights
44 var $acl_create_changes = ""; // Contains ldif information about changes
45 var $acl_create_confirmed= FALSE;
47 /* Checks initialised ? */
48 var $checks_initialised = FALSE;
50 function Step_Migrate()
51 {
52 $this->update_strings();
53 }
55 function update_strings()
56 {
57 $this->s_title = _("LDAP inspection");
58 $this->s_title_long = _("LDAP inspection");
59 $this->s_info = _("Analyze your current LDAP for GOsa compatibility");
60 }
62 function initialize_checks()
63 {
64 $this->checks = array();
65 $this->checks['root']['TITLE'] = _("Checking for root object");
66 $this->checks['root']['STATUS'] = FALSE;
67 $this->checks['root']['STATUS_MSG']= "";
68 $this->checks['root']['ERROR_MSG'] = "";
69 $this->checkBase();
71 $this->checks['permissions']['TITLE'] = _("Checking permissions on ldap database");
72 $this->checks['permissions']['STATUS'] = FALSE;
73 $this->checks['permissions']['STATUS_MSG']= "";
74 $this->checks['permissions']['ERROR_MSG'] = "";
75 $this->check_ldap_permissions();
77 $this->checks['deps_visible']['TITLE'] = _("Checking for invisible deparmtments");
78 $this->checks['deps_visible']['STATUS'] = FALSE;
79 $this->checks['deps_visible']['STATUS_MSG']= "";
80 $this->checks['deps_visible']['ERROR_MSG'] = "";
81 $this->check_visible_organizationalUnits();
83 $this->checks['users_visible']['TITLE'] = _("Checking for invisible user");
84 $this->checks['users_visible']['STATUS'] = FALSE;
85 $this->checks['users_visible']['STATUS_MSG']= "";
86 $this->checks['users_visible']['ERROR_MSG'] = "";
87 $this->check_invisible_gosaAccounts();
89 $this->checks['acls']['TITLE'] = _("Checking for administrational account");
90 $this->checks['acls']['STATUS'] = FALSE;
91 $this->checks['acls']['STATUS_MSG']= "";
92 $this->checks['acls']['ERROR_MSG'] = "";
93 $this->check_acls();
94 }
98 /* Check ldap accessibility
99 * Create and remove a dummy object,
100 * to ensure that we have the necessary permissions
101 */
102 function check_ldap_permissions()
103 {
104 $cv = $this->parent->captured_values;
105 $ldap = new LDAP($cv['admin'],
106 $cv['password'],
107 $cv['connection'],
108 FALSE,
109 $cv['tls']);
111 /* Create dummy entry
112 */
113 $name = "GOsa_setup_text_entry_".session_id().rand(0,999999);
114 $dn = "ou=".$name.",".$cv['base'];
115 $testEntry= array();
116 $testEntry['objectClass'][]= "top";
117 $testEntry['objectClass'][]= "organizationalUnit";
118 $testEntry['objectClass'][]= "gosaDepartment";
119 $testEntry['description']= "Created by GOsa setup, this object can be removed.";
120 $testEntry['ou'] = $name;
122 /* check if simple ldap cat will be successful
123 */
124 $res = $ldap->cat($cv['base']);
125 if(!$res){
126 $this->checks['permissions']['STATUS'] = FALSE;
127 $this->checks['permissions']['STATUS_MSG']= _("Ldap query failed.");
128 $this->checks['permissions']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
129 return(false);
130 }
132 /* Try to create dummy object
133 */
134 $ldap->cd ($dn);
135 $ldap->create_missing_trees($dn);
136 $res = $ldap->add($testEntry);
137 if(!$res){
138 gosa_log($ldap->get_error());
139 $this->checks['permissions']['STATUS'] = FALSE;
140 $this->checks['permissions']['STATUS_MSG']= _("Failed");
141 $this->checks['permissions']['ERROR_MSG'] =
142 sprintf(_("The specified user '%s' does not have full access to your ldap database."),$cv['admin']);
143 return(false);
144 }
146 /* Try to remove created entry
147 */
148 $res = $ldap->rmDir($dn);
149 if(!$res){
150 gosa_log($ldap->get_error());
151 $this->checks['permissions']['STATUS'] = FALSE;
152 $this->checks['permissions']['STATUS_MSG']= _("Failed");
153 $this->checks['permissions']['ERROR_MSG'] =
154 sprintf(_("The specified user '%s' does not have full access to your ldap database."),$cv['admin']);
155 return(false);
156 }
158 /* Create & remove of dummy object was successful */
159 $this->checks['permissions']['STATUS'] = TRUE;
160 $this->checks['permissions']['STATUS_MSG']= _("Ok");
161 $this->checks['permissions']['ERROR_MSG'] = "";
162 return(true);
163 }
166 /* Check if there are users which will
167 * be invisible for GOsa
168 */
169 function check_invisible_gosaAccounts()
170 {
171 /* Remember old list of ivisible users, to be able to set
172 * the 'html checked' status for the checkboxes again
173 */
174 $cnt_ok = 0;
175 $old = $this->users_to_migrate;
176 $this->users_to_migrate = array();
178 /* Get collected configuration settings */
179 $cv = $this->parent->captured_values;
181 /* Establish ldap connection */
182 $ldap = new LDAP($cv['admin'],
183 $cv['password'],
184 $cv['connection'],
185 FALSE,
186 $cv['tls']);
188 /* Get all invisible users
189 */
190 $ldap->cd($cv['base']);
191 $res =$ldap->search("(&(|(objectClass=posixAccount)(objectClass=inetOrgPerson)(objectClass=organizationalPerson))(!(objectClass=gosaAccount)))",array("sn","givenName","cn","uid"));
192 while($attrs = $ldap->fetch()){
193 if(!preg_match("/,dc=addressbook,/",$attrs['dn'])){
194 $attrs['checked'] = FALSE;
195 $attrs['before'] = "";
196 $attrs['after'] = "";
198 /* Set objects to selected, that were selected before reload */
199 if(isset($old[base64_encode($attrs['dn'])])){
200 $attrs['checked'] = $old[base64_encode($attrs['dn'])]['checked'];
201 }
202 $this->users_to_migrate[base64_encode($attrs['dn'])] = $attrs;
203 }
204 }
206 /* No invisible */
207 if(!$res){
208 $this->checks['users_visible']['STATUS'] = FALSE;
209 $this->checks['users_visible']['STATUS_MSG']= _("Ldap query failed.");
210 $this->checks['users_visible']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
211 }elseif(count($this->users_to_migrate) == 0){
212 $this->checks['users_visible']['STATUS'] = TRUE;
213 $this->checks['users_visible']['STATUS_MSG']= _("Ok");
214 $this->checks['users_visible']['ERROR_MSG'] = "";
215 }else{
216 $this->checks['users_visible']['STATUS'] = FALSE;
217 $this->checks['users_visible']['STATUS_MSG']= "";
218 $this->checks['users_visible']['ERROR_MSG'] = sprintf(_("Found %s users that will not be visible in GOsa."),
219 count($this->users_to_migrate));
220 $this->checks['users_visible']['ERROR_MSG'] .= "<input type='submit' name='users_visible_migrate' value='"._("Migrate")."'>";
221 }
222 }
225 /* Start user account migration
226 */
227 function migrate_gosaAccounts($only_ldif = FALSE)
228 {
229 /* Get collected configuration settings */
230 $cv = $this->parent->captured_values;
232 /* Establish ldap connection */
233 $ldap = new LDAP($cv['admin'],
234 $cv['password'],
235 $cv['connection'],
236 FALSE,
237 $cv['tls']);
239 /* Add gosaAccount objectClass to the selected users
240 */
241 foreach($this->users_to_migrate as $key => $dep){
242 if($dep['checked']){
244 /* Get old objectClasses */
245 $ldap->cat($dep['dn'],array("objectClass"));
246 $attrs = $ldap->fetch();
248 /* Create new objectClass array */
249 $new_attrs = array();
250 $new_attrs['objectClass']= array("gosaAccount","inetOrgPerson","organizationalPerson");
251 for($i = 0 ; $i < $attrs['objectClass']['count']; $i ++ ){
252 if(!in_array_ics($attrs['objectClass'][$i], $new_attrs['objectClass'])){
253 $new_attrs['objectClass'][] = $attrs['objectClass'][$i];
254 }
255 }
257 /* Set info attributes for current object,
258 * or write changes to the ldap database
259 */
260 if($only_ldif){
261 $this->users_to_migrate[$key]['before'] = $this->array_to_ldif($attrs);
262 $this->users_to_migrate[$key]['after'] = $this->array_to_ldif($new_attrs);
263 }else{
264 $ldap->cd($attrs['dn']);
265 if(!$ldap->modify($new_attrs)){
266 print_red(sprintf(_("Failed to migrate the department '%s' into GOsa, error message is as follows '%s'."),$attrs['dn'],$ldap->get_error()));
267 return(false);
268 }
269 }
270 }
271 }
272 return(TRUE);
273 }
276 /* Check if there are invisible organizational Units
277 */
278 function check_visible_organizationalUnits()
279 {
280 $cnt_ok = 0;
281 $old = $this->deps_to_migrate;
282 $this->deps_to_migrate = array();
284 /* Get collected configuration settings */
285 $cv = $this->parent->captured_values;
287 /* Establish ldap connection */
288 $ldap = new LDAP($cv['admin'],
289 $cv['password'],
290 $cv['connection'],
291 FALSE,
292 $cv['tls']);
294 /* Skip GOsa internal departments */
295 $skip_dns = array("/^ou=people,/","/^ou=groups,/","/(,|)ou=configs,/","/(,|)ou=systems,/",
296 "/^ou=apps,/","/^ou=mime,/","/^ou=aclroles,/","/^ou=incoming,/",
297 "/ou=snapshots,/","/(,|)dc=addressbook,/","/^(,|)ou=machineaccounts,/",
298 "/(,|)ou=winstations,/");
301 /* Get all invisible departments */
302 $ldap->cd($cv['base']);
303 $res = $ldap->search("(&(objectClass=organizationalUnit)(!(objectClass=gosaDepartment)))",array("ou","description","dn"));
304 while($attrs = $ldap->fetch()){
305 $attrs['checked'] = FALSE;
306 $attrs['before'] = "";
307 $attrs['after'] = "";
309 /* Set objects to selected, that were selected before reload */
310 if(isset($old[base64_encode($attrs['dn'])])){
311 $attrs['checked'] = $old[base64_encode($attrs['dn'])]['checked'];
312 }
313 $this->deps_to_migrate[base64_encode($attrs['dn'])] = $attrs;
314 }
316 /* Filter returned list of departments and ensure that
317 * GOsa internal departments will not be listed
318 */
319 foreach($this->deps_to_migrate as $key => $attrs){
320 $dn = $attrs['dn'];
321 $skip = false;
322 foreach($skip_dns as $skip_dn){
323 if(preg_match($skip_dn,$dn)){
324 $skip = true;
325 }
326 }
327 if($skip){
328 unset($this->deps_to_migrate[$key]);
329 }
330 }
332 /* If we have no invisible departments found
333 * tell the user that everything is ok
334 */
335 if(!$res){
336 $this->checks['deps_visible']['STATUS'] = FALSE;
337 $this->checks['deps_visible']['STATUS_MSG']= _("Ldap query failed.");
338 $this->checks['deps_visible']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
339 }elseif(count($this->deps_to_migrate) == 0 ){
340 $this->checks['deps_visible']['STATUS'] = TRUE;
341 $this->checks['deps_visible']['STATUS_MSG']= _("Ok");
342 $this->checks['deps_visible']['ERROR_MSG'] = "";
343 }else{
344 $this->checks['deps_visible']['STATUS'] = FALSE;
345 $this->checks['deps_visible']['STATUS_MSG']= "";//sprintf(_("%s entries found"),count($this->deps_to_migrate));
346 $this->checks['deps_visible']['ERROR_MSG'] = sprintf(_("Found %s departments that will not be visible in GOsa."),count($this->deps_to_migrate));
347 $this->checks['deps_visible']['ERROR_MSG'] .= "<input type='submit' name='deps_visible_migrate' value='"._("Migrate")."'>";
348 }
349 }
353 /* Start deparmtment migration */
354 function migrate_organizationalUnits($only_ldif = FALSE)
355 {
356 /* Get collected configuration settings */
357 $cv = $this->parent->captured_values;
359 /* Establish ldap connection */
360 $ldap = new LDAP($cv['admin'],
361 $cv['password'],
362 $cv['connection'],
363 FALSE,
364 $cv['tls']);
366 /* Add gosaDepartment objectClass to each selected entry
367 */
368 foreach($this->deps_to_migrate as $key => $dep){
369 if($dep['checked']){
371 /* Get current objectClasses */
372 $ldap->cat($dep['dn'],array("objectClass","description"));
373 $attrs = $ldap->fetch();
375 /* Create new objectClass attribute including gosaDepartment*/
376 $new_attrs = array();
377 for($i = 0 ; $i < $attrs['objectClass']['count']; $i ++ ){
378 $new_attrs['objectClass'][] = $attrs['objectClass'][$i];
379 }
380 $new_attrs['objectClass'][] = "gosaDepartment";
382 /* Append description it is missing */
383 if(!isset($attrs['description'])){
384 $new_attrs['description'][] = "GOsa department";
385 }
387 /* Depending on the parameter >only_diff< we save the changes as ldif
388 * or we write our changes directly to the ldap database
389 */
390 if($only_ldif){
391 $this->deps_to_migrate[$key]['before'] = $this->array_to_ldif($attrs);
392 $this->deps_to_migrate[$key]['after'] = $this->array_to_ldif($new_attrs);
393 }else{
394 $ldap->cd($attrs['dn']);
395 if(!$ldap->modify($new_attrs)){
396 print_red(sprintf(_("Failed to migrate the department '%s' into GOsa, error message is as follows '%s'."),$attrs['dn'],$ldap->get_error()));
397 return(false);
398 }
399 }
400 }
401 }
402 return(TRUE);
403 }
406 /* Check Acls if there is at least one object with acls defined
407 */
408 function check_acls()
409 {
410 /* Establish ldap connection */
411 $cv = $this->parent->captured_values;
412 $ldap = new LDAP($cv['admin'],
413 $cv['password'],
414 $cv['connection'],
415 FALSE,
416 $cv['tls']);
418 /* Search for gosaAcls */
419 $ldap->cd($cv['base']);
420 $res = $ldap->search("(&(objectClass=gosaAccount)(|(objectClass=posixAccount)".
421 "(objectClass=inetOrgPerson)(objectClass=organizationalPerson)))");
422 if(!$res){
423 $this->checks['acls']['STATUS'] = FALSE;
424 $this->checks['acls']['STATUS_MSG']= _("Ldap query failed.");
425 $this->checks['acls']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
426 }elseif($ldap->count()){
427 $this->checks['acls']['STATUS'] = TRUE;
428 $this->checks['acls']['STATUS_MSG']= _("Ok");
429 }else{
430 $this->checks['acls']['STATUS'] = FALSE;
431 $this->checks['acls']['STATUS_MSG']= _("Failed");
432 $this->checks['acls']['ERROR_MSG'].= "<input type='submit' name='create_acls' value='"._("Create adminitrational account")."'>";
433 }
434 return($ldap->count()>=1);
435 }
438 function get_user_list()
439 {
440 /* Get collected configuration settings */
441 $cv = $this->parent->captured_values;
443 /* Establish ldap connection */
444 $ldap = new LDAP($cv['admin'],
445 $cv['password'],
446 $cv['connection'],
447 FALSE,
448 $cv['tls']);
450 $ldap->cd($cv['base']);
451 $ldap->search("(objectClass=gosaAccount)",array("dn"));
453 $tmp = array();
454 while($attrs = $ldap->fetch()){
455 $tmp[base64_encode($attrs['dn'])] = @LDAP::fix($attrs['dn']);
456 }
458 return($tmp);
459 }
461 function get_group_list()
462 {
463 /* Get collected configuration settings */
464 $cv = $this->parent->captured_values;
466 /* Establish ldap connection */
467 $ldap = new LDAP($cv['admin'],
468 $cv['password'],
469 $cv['connection'],
470 FALSE,
471 $cv['tls']);
473 $ldap->cd($cv['base']);
474 $ldap->search("(objectClass=posixGroup)",array("dn"));
476 $tmp = array();
477 while($attrs = $ldap->fetch()){
478 $tmp[base64_encode($attrs['dn'])] = @LDAP::fix($attrs['dn']);
479 }
481 return($tmp);
482 }
486 function create_admin($only_ldif = FALSE)
487 {
488 /* Reset '' */
489 $this->acl_create_changes="";
491 /* Object that should receive admin acls */
492 $dn = $this->acl_create_selected;
494 /* Get collected configuration settings */
495 $cv = $this->parent->captured_values;
497 /* Establish ldap connection */
498 $ldap = new LDAP($cv['admin'],
499 $cv['password'],
500 $cv['connection'],
501 FALSE,
502 $cv['tls']);
504 /* Get current base attributes */
505 $ldap->cd($cv['base']);
506 $ldap->cat($cv['base'],array("dn","objectClass","gosaAclEntry"));
507 $attrs = $ldap->fetch();
509 /* Add acls for the selcted user to the base */
510 $attrs_new['objectClass'] = array("gosaACL");
512 for($i = 0; $i < $attrs['objectClass']['count']; $i ++){
513 if(!in_array_ics($attrs['objectClass'][$i],$attrs_new['objectClass'])){
514 $attrs_new['objectClass'][] = $attrs['objectClass'][$i];
515 }
516 }
518 $acl = "0:sub:".base64_encode($dn).":all;cmdrw";
519 $attrs_new['gosaAclEntry'][] = $acl;
520 if(isset($attrs['gosaAclEntry'])){
521 for($i = 0 ; $i < $attrs['gosaAclEntry']['count']; $i ++){
523 $prio = preg_replace("/[:].*$/","",$attrs['gosaAclEntry'][$i]);
524 $rest = preg_replace("/^[^:]/","",$attrs['gosaAclEntry'][$i]);
526 $data = ($prio+1).$rest;
527 $attrs_new['gosaAclEntry'][] = $data;
528 }
529 }
531 if($only_ldif){
532 $this->acl_create_changes ="\n".$cv['base']."\n";
533 $this->acl_create_changes.=$this->array_to_ldif($attrs)."\n";
534 $this->acl_create_changes.="\n".$cv['base']."\n";
535 $this->acl_create_changes.=$this->array_to_ldif($attrs_new);
536 }else{
538 $ldap->cd($cv['base']);
539 if(!$ldap->modify($attrs_new)){
540 print_red(sprintf(_("Adding acls for user '%s' failed, ldap says '%s'."),$dn,$ldap->get_error()));
541 }
542 }
543 }
546 function create_admin_user()
547 {
548 if(isset($_POST['new_user_password']) && !empty($_POST['new_user_password'])){
549 $pwd = $_POST['new_user_password'];
550 }else{
551 print_red(_("Please specify a valid password for the new GOsa admin user."));
552 return(FALSE);
553 }
555 /* Establish ldap connection */
556 $cv = $this->parent->captured_values;
557 $ldap = new LDAP($cv['admin'],
558 $cv['password'],
559 $cv['connection'],
560 FALSE,
561 $cv['tls']);
563 /* Get current base attributes */
564 $ldap->cd($cv['base']);
566 if($cv['peopledn'] == "cn"){
567 $dn = "cn=System Administrator,".$cv['peopleou'].",".$cv['base'];
568 }else{
569 $dn = "uid=admin,".$cv['peopleou'].",".$cv['base'];
570 }
572 $methods = @passwordMethod::get_available_methods_if_not_loaded();
573 $p_m = $methods[$cv['encryption']];
574 $p_c = new $p_m(array());
575 $hash = $p_c->generate_hash($pwd);
577 $new_user=array();
578 $new_user['objectClass']= array("gosaAccount","organizationalPerson","inetOrgPerson");
579 $new_user['givenName'] = "System";
580 $new_user['sn'] = "Administrator";
581 $new_user['cn'] = "System Administrator";
582 $new_user['uid'] = "admin";
583 $new_user['userPassword'] = $hash;
585 $ldap->cd($cv['base']);
586 $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$dn));
587 $ldap->cd($dn);
588 $res = $ldap->add($new_user);
589 $this->acl_create_selected = $dn;
590 $this->create_admin();
592 if(!$res){
593 print_red($ldap->get_error());
594 }
596 $this->acl_create_dialog=FALSE;
597 $this->check_acls();
598 }
601 function execute()
602 {
603 /* Initialise checks if this is the first call */
604 if(!$this->checks_initialised || isset($_POST['reload'])){
605 $this->initialize_checks();
606 $this->checks_initialised = TRUE;
607 }
609 /*************
610 * Root object check
611 *************/
613 if(isset($_POST['retry_root_create'])){
614 $this->checkBase(FALSE);
615 }
617 /*************
618 * User Migration handling
619 *************/
621 if(isset($_POST['retry_acls'])){
622 $this->check_acls();
623 }
625 if(isset($_POST['create_acls'])){
626 $this->acl_create_dialog = TRUE;
627 $this->dialog = TRUE;
628 }
630 if(isset($_POST['create_acls_cancel'])){
631 $this->acl_create_dialog = FALSE;
632 $this->dialog = FALSE;
633 }
635 if(isset($_POST['create_acls_create_confirmed'])){
636 $this->create_admin();
637 }
639 if(isset($_POST['create_acls_create'])){
640 $this->create_admin(TRUE);
641 }
643 if(isset($_POST['create_admin_user'])){
644 $this->create_admin_user();
645 }
647 if($this->acl_create_dialog){
648 $smarty = get_smarty();
649 $smarty->assign("new_user_password",@$_POST['new_user_password']);
650 $smarty->assign("users" ,$this->get_user_list());
651 $smarty->assign("users_cnt" ,count($this->get_user_list()));
652 $smarty->assign("groups",$this->get_group_list());
653 $smarty->assign("groups_cnt",count($this->get_group_list()));
654 $smarty->assign("type" ,$this->acl_create_type);
655 $smarty->assign("method","create_acls");
656 $smarty->assign("acl_create_selected",$this->acl_create_selected);
657 $smarty->assign("what_will_be_done_now",$this->acl_create_changes);
658 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
659 }
661 /*************
662 * User Migration handling
663 *************/
665 /* Refresh list of deparments */
666 if(isset($_POST['users_visible_migrate_refresh'])){
667 $this->check_invisible_gosaAccounts();
668 }
670 /* Open migration dialog */
671 if(isset($_POST['users_visible_migrate'])){
672 $this->users_migration_dialog = TRUE;
673 $this->dialog =TRUE;
674 }
676 /* Close migration dialog */
677 if(isset($_POST['users_visible_migrate_close'])){
678 $this->users_migration_dialog = FALSE;
679 $this->dialog =FALSE;
680 }
682 /* Start migration */
683 if(isset($_POST['users_visible_migrate_migrate'])){
684 if($this->migrate_gosaAccounts()){
685 $this->check_invisible_gosaAccounts();
686 }
687 }
689 /* Start migration */
690 if(isset($_POST['users_visible_migrate_whatsdone'])){
691 $this->migrate_gosaAccounts(TRUE);
692 }
694 /* Display migration dialog */
695 if($this->users_migration_dialog){
696 $smarty = get_smarty();
697 $smarty->assign("users_to_migrate",$this->users_to_migrate);
698 $smarty->assign("method","migrate_users");
699 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
700 }
703 /*************
704 * Department Migration handling
705 *************/
707 /* Refresh list of deparments */
708 if(isset($_POST['deps_visible_migrate_refresh'])){
709 $this->check_visible_organizationalUnits();
710 }
712 /* Open migration dialog */
713 if(isset($_POST['deps_visible_migrate'])){
714 $this->dep_migration_dialog = TRUE;
715 $this->dialog =TRUE;
716 }
718 /* Close migration dialog */
719 if(isset($_POST['deps_visible_migrate_close'])){
720 $this->dep_migration_dialog = FALSE;
721 $this->dialog =FALSE;
722 }
724 /* Start migration */
725 if(isset($_POST['deps_visible_migrate_migrate'])){
726 if($this->migrate_organizationalUnits()){
727 $this->check_visible_organizationalUnits();
728 }
729 }
731 /* Start migration */
732 if(isset($_POST['deps_visible_migrate_whatsdone'])){
733 $this->migrate_organizationalUnits(TRUE);
734 }
736 /* Display migration dialog */
737 if($this->dep_migration_dialog){
738 $smarty = get_smarty();
739 $smarty->assign("deps_to_migrate",$this->deps_to_migrate);
740 $smarty->assign("method","migrate_deps");
741 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
742 }
744 $smarty = get_smarty();
745 $smarty->assign("checks",$this->checks);
746 $smarty->assign("method","default");
747 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
748 }
751 function save_object()
752 {
753 /* Get "create acl" dialog posts */
754 if($this->acl_create_dialog){
755 if(isset($_POST['create_acls_create'])){
756 if(isset($_POST['create_acls_selected'])){
757 $this->acl_create_selected = base64_decode($_POST['create_acls_selected']);
758 }else{
759 $this->acl_create_selected = "";
760 }
761 }
763 if(isset($_POST['create_acls_create_abort'])){
764 $this->acl_create_selected = "";
765 }
767 if(isset($_POST['acl_create_type'])){
768 $this->acl_create_type = $_POST['acl_create_type'];
769 }
770 }
772 /* Get selected departments */
773 if($this->dep_migration_dialog){
774 foreach($this->deps_to_migrate as $id => $data){
775 if(isset($_POST['migrate_'.$id])){
776 $this->deps_to_migrate[$id]['checked'] = TRUE;
777 }else{
778 $this->deps_to_migrate[$id]['checked'] = FALSE;
779 }
780 }
781 }
783 /* Get selected users */
784 if($this->users_migration_dialog){
785 foreach($this->users_to_migrate as $id => $data){
786 if(isset($_POST['migrate_'.$id])){
787 $this->users_to_migrate[$id]['checked'] = TRUE;
788 }else{
789 $this->users_to_migrate[$id]['checked'] = FALSE;
790 }
791 }
792 }
793 }
796 // checks for valid base entry
797 function checkBase($just_check = TRUE)
798 {
799 /* Get collected setup informations */
800 $cv = $this->parent->captured_values;
802 /* Establish ldap connection */
803 $ldap = new LDAP($cv['admin'],
804 $cv['password'],
805 $cv['connection'],
806 FALSE,
807 $cv['tls']);
809 /* Check if root object exists */
810 $ldap->cd($cv['base']);
811 $res = $ldap->search("(objectClass=*)");
812 $err = ldap_errno($ldap->cid);
814 if( !$res ||
815 $err == 0x20 || # LDAP_NO_SUCH_OBJECT
816 $err == 0x40) { # LDAP_NAMING_VIOLATION
818 /* Root object doesn't exists
819 */
820 if($just_check){
821 $this->checks['root']['STATUS'] = FALSE;
822 $this->checks['root']['STATUS_MSG']= _("Failed");
823 $this->checks['root']['ERROR_MSG'].= "<input type='submit' name='retry_root_create' value='"._("Try to create root object")."'>";
824 return(FALSE);
825 }else{
827 /* Add root object */
828 $ldap->cd($cv['base']);
829 $res = $ldap->create_missing_trees($cv['base']);
831 /* If adding failed, tell the user */
832 if(!$res){
833 $this->checks['root']['STATUS'] = FALSE;
834 $this->checks['root']['STATUS_MSG']= _("Failed");
835 $this->checks['root']['ERROR_MSG'] = _("Root object couldn't be created, you should try it on your own.");
836 $this->checks['root']['ERROR_MSG'].= "<input type='submit' name='retry_root_create' value='"._("Try to create root object")."'>";
837 return($res);;
838 }
839 }
840 }
842 /* Create & remove of dummy object was successful */
843 $this->checks['root']['STATUS'] = TRUE;
844 $this->checks['root']['STATUS_MSG']= _("Ok");
845 }
848 /* Return ldif information for a
849 * given attribute array
850 */
851 function array_to_ldif($atts)
852 {
853 $ret = "";
854 unset($atts['count']);
855 unset($atts['dn']);
856 foreach($atts as $name => $value){
857 if(is_numeric($name)) {
858 continue;
859 }
860 if(is_array($value)){
861 unset($value['count']);
862 foreach($value as $a_val){
863 $ret .= $name.": ". $a_val."\n";
864 }
865 }else{
866 $ret .= $name.": ". $value."\n";
867 }
868 }
869 return(preg_replace("/\n$/","",$ret));
870 }
871 }
873 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
874 ?>