5fd72d01dcd0ce6389dd8b28a46713b8d890f4fb
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 */
23 class Step_Migrate extends setup_step
24 {
25 var $languages = array();
26 var $attributes = array();
27 var $header_image = "images/monitoring.png";
28 var $checks = array();
30 /* Department migration attributes */
31 var $dep_migration_dialog = FALSE;
32 var $deps_to_migrate = array();
34 /* Department migration attributes */
35 var $users_migration_dialog= FALSE;
36 var $users_to_migrate = array();
38 /* Create Acl attributes */
39 var $acl_create_dialog = FALSE;
40 var $acl_create_type = "group";
41 var $acl_create_selected= ""; // Currently selected element, that should receive admin rights
42 var $acl_create_changes = ""; // Contains ldif information about changes
43 var $acl_create_confirmed= FALSE;
45 /* Checks initialised ? */
46 var $checks_initialised = FALSE;
48 function Step_Migrate()
49 {
50 $this->update_strings();
51 }
53 function update_strings()
54 {
55 $this->s_title = _("LDAP inspection");
56 $this->s_title_long = _("LDAP inspection");
57 $this->s_info = _("Analyze your current LDAP for GOsa compatibility");
58 }
60 function initialize_checks()
61 {
62 $this->checks = array();
63 $this->checks['root']['TITLE'] = _("Checking for root object");
64 $this->checks['root']['STATUS'] = FALSE;
65 $this->checks['root']['STATUS_MSG']= "";
66 $this->checks['root']['ERROR_MSG'] = "";
67 $this->checkBase();
69 $this->checks['permissions']['TITLE'] = _("Checking permissions on ldap database");
70 $this->checks['permissions']['STATUS'] = FALSE;
71 $this->checks['permissions']['STATUS_MSG']= "";
72 $this->checks['permissions']['ERROR_MSG'] = "";
73 $this->check_ldap_permissions();
75 $this->checks['deps_visible']['TITLE'] = _("Checking for invisible deparmtments");
76 $this->checks['deps_visible']['STATUS'] = FALSE;
77 $this->checks['deps_visible']['STATUS_MSG']= "";
78 $this->checks['deps_visible']['ERROR_MSG'] = "";
79 $this->check_visible_organizationalUnits();
81 $this->checks['users_visible']['TITLE'] = _("Checking for invisible user");
82 $this->checks['users_visible']['STATUS'] = FALSE;
83 $this->checks['users_visible']['STATUS_MSG']= "";
84 $this->checks['users_visible']['ERROR_MSG'] = "";
85 $this->check_invisible_gosaAccounts();
87 $this->checks['acls']['TITLE'] = _("Checking for administrational account");
88 $this->checks['acls']['STATUS'] = FALSE;
89 $this->checks['acls']['STATUS_MSG']= "";
90 $this->checks['acls']['ERROR_MSG'] = "";
91 $this->check_acls();
92 }
95 /* Check Acls if there is at least one object with acls defined
96 */
97 function check_acls()
98 {
99 /* Establish ldap connection */
100 $cv = $this->parent->captured_values;
101 $ldap = new LDAP($cv['admin'],
102 $cv['password'],
103 $cv['connection'],
104 FALSE,
105 $cv['tls']);
107 /* Search for gosaAcls */
108 $ldap->cd($cv['base']);
109 $res = $ldap->search("(&(objectClass=gosaAccount)(|(objectClass=posixAccount)".
110 "(objectClass=inetOrgPerson)(objectClass=organizationalPerson)))");
111 if(!$res){
112 $this->checks['acls']['STATUS'] = FALSE;
113 $this->checks['acls']['STATUS_MSG']= _("Ldap query failed.");
114 $this->checks['acls']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
115 }elseif($ldap->count() == 0){
116 $this->checks['acls']['STATUS'] = TRUE;
117 $this->checks['acls']['STATUS_MSG']= _("Ok");
118 }else{
119 $this->checks['acls']['STATUS'] = FALSE;
120 $this->checks['acls']['STATUS_MSG']= _("Failed");
121 $this->checks['acls']['ERROR_MSG'].= "<input type='submit' name='create_acls' value='"._("Create adminitrational account")."'>";
122 }
123 return($ldap->count()>=1);
124 }
127 /* Check ldap accessibility
128 * Create and remove a dummy object,
129 * to ensure that we have the necessary permissions
130 */
131 function check_ldap_permissions()
132 {
133 $cv = $this->parent->captured_values;
134 $ldap = new LDAP($cv['admin'],
135 $cv['password'],
136 $cv['connection'],
137 FALSE,
138 $cv['tls']);
140 /* Create dummy entry
141 */
142 $name = "GOsa_setup_text_entry_".session_id().rand(0,999999);
143 $dn = "ou=".$name.",".$cv['base'];
144 $testEntry= array();
145 $testEntry['objectClass'][]= "top";
146 $testEntry['objectClass'][]= "organizationalUnit";
147 $testEntry['objectClass'][]= "gosaDepartment";
148 $testEntry['description']= "Created by GOsa setup, this object can be removed.";
149 $testEntry['ou'] = $name;
151 /* check if simple ldap cat will be successful
152 */
153 $res = $ldap->cat($cv['base']);
154 if(!$res){
155 $this->checks['permissions']['STATUS'] = FALSE;
156 $this->checks['permissions']['STATUS_MSG']= _("Ldap query failed.");
157 $this->checks['permissions']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
158 return(false);
159 }
161 /* Try to create dummy object
162 */
163 $ldap->cd ($dn);
164 $ldap->create_missing_trees($dn);
165 $res = $ldap->add($testEntry);
166 if(!$res){
167 gosa_log($ldap->get_error());
168 $this->checks['permissions']['STATUS'] = FALSE;
169 $this->checks['permissions']['STATUS_MSG']= _("Failed");
170 $this->checks['permissions']['ERROR_MSG'] =
171 sprintf(_("The specified user '%s' does not have full access to your ldap database."),$cv['admin']);
172 return(false);
173 }
175 /* Try to remove created entry
176 */
177 $res = $ldap->rmDir($dn);
178 if(!$res){
179 gosa_log($ldap->get_error());
180 $this->checks['permissions']['STATUS'] = FALSE;
181 $this->checks['permissions']['STATUS_MSG']= _("Failed");
182 $this->checks['permissions']['ERROR_MSG'] =
183 sprintf(_("The specified user '%s' does not have full access to your ldap database."),$cv['admin']);
184 return(false);
185 }
187 /* Create & remove of dummy object was successful */
188 $this->checks['permissions']['STATUS'] = TRUE;
189 $this->checks['permissions']['STATUS_MSG']= _("Ok");
190 $this->checks['permissions']['ERROR_MSG'] = "";
191 return(true);
192 }
195 /* Check if there are users which will
196 * be invisible for GOsa
197 */
198 function check_invisible_gosaAccounts()
199 {
200 /* Remember old list of ivisible users, to be able to set
201 * the 'html checked' status for the checkboxes again
202 */
203 $cnt_ok = 0;
204 $old = $this->users_to_migrate;
205 $this->users_to_migrate = array();
207 /* Get collected configuration settings */
208 $cv = $this->parent->captured_values;
210 /* Establish ldap connection */
211 $ldap = new LDAP($cv['admin'],
212 $cv['password'],
213 $cv['connection'],
214 FALSE,
215 $cv['tls']);
217 /* Get all invisible users
218 */
219 $ldap->cd($cv['base']);
220 $res =$ldap->search("(&(|(objectClass=posixAccount)(objectClass=inetOrgPerson)(objectClass=organizationalPerson))(!(objectClass=gosaAccount)))",array("sn","givenName","cn","uid"));
221 while($attrs = $ldap->fetch()){
222 if(!preg_match("/,dc=addressbook,/",$attrs['dn'])){
223 $attrs['checked'] = FALSE;
224 $attrs['before'] = "";
225 $attrs['after'] = "";
227 /* Set objects to selected, that were selected before reload */
228 if(isset($old[base64_encode($attrs['dn'])])){
229 $attrs['checked'] = $old[base64_encode($attrs['dn'])]['checked'];
230 }
231 $this->users_to_migrate[base64_encode($attrs['dn'])] = $attrs;
232 }
233 }
235 /* No invisible */
236 if(!$res){
237 $this->checks['users_visible']['STATUS'] = FALSE;
238 $this->checks['users_visible']['STATUS_MSG']= _("Ldap query failed.");
239 $this->checks['users_visible']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
240 }elseif(count($this->users_to_migrate) == 0){
241 $this->checks['users_visible']['STATUS'] = TRUE;
242 $this->checks['users_visible']['STATUS_MSG']= _("Ok");
243 $this->checks['users_visible']['ERROR_MSG'] = "";
244 }else{
245 $this->checks['users_visible']['STATUS'] = FALSE;
246 $this->checks['users_visible']['STATUS_MSG']= "";
247 $this->checks['users_visible']['ERROR_MSG'] = sprintf(_("Found %s users that will not be visible in GOsa."),
248 count($this->users_to_migrate));
249 $this->checks['users_visible']['ERROR_MSG'] .= "<input type='submit' name='users_visible_migrate' value='"._("Migrate")."'>";
250 }
251 }
254 /* Start user account migration
255 */
256 function migrate_gosaAccounts($only_ldif = FALSE)
257 {
258 /* Get collected configuration settings */
259 $cv = $this->parent->captured_values;
261 /* Establish ldap connection */
262 $ldap = new LDAP($cv['admin'],
263 $cv['password'],
264 $cv['connection'],
265 FALSE,
266 $cv['tls']);
268 /* Add gosaAccount objectClass to the selected users
269 */
270 foreach($this->users_to_migrate as $key => $dep){
271 if($dep['checked']){
273 /* Get old objectClasses */
274 $ldap->cat($dep['dn'],array("objectClass"));
275 $attrs = $ldap->fetch();
277 /* Create new objectClass array */
278 $new_attrs = array();
279 $new_attrs['objectClass']= array("gosaAccount","inetOrgPerson","organizationalPerson");
280 for($i = 0 ; $i < $attrs['objectClass']['count']; $i ++ ){
281 if(!in_array_ics($attrs['objectClass'][$i], $new_attrs['objectClass'])){
282 $new_attrs['objectClass'][] = $attrs['objectClass'][$i];
283 }
284 }
286 /* Set info attributes for current object,
287 * or write changes to the ldap database
288 */
289 if($only_ldif){
290 $this->users_to_migrate[$key]['before'] = $this->array_to_ldif($attrs);
291 $this->users_to_migrate[$key]['after'] = $this->array_to_ldif($new_attrs);
292 }else{
293 $ldap->cd($attrs['dn']);
294 if(!$ldap->modify($new_attrs)){
295 print_red(sprintf(_("Failed to migrate the department '%s' into GOsa, error message is as follows '%s'."),$attrs['dn'],$ldap->get_error()));
296 return(false);
297 }
298 }
299 }
300 }
301 return(TRUE);
302 }
305 /* Check if there are invisible organizational Units
306 */
307 function check_visible_organizationalUnits()
308 {
309 $cnt_ok = 0;
310 $old = $this->deps_to_migrate;
311 $this->deps_to_migrate = array();
313 /* Get collected configuration settings */
314 $cv = $this->parent->captured_values;
316 /* Establish ldap connection */
317 $ldap = new LDAP($cv['admin'],
318 $cv['password'],
319 $cv['connection'],
320 FALSE,
321 $cv['tls']);
323 /* Skip GOsa internal departments */
324 $skip_dns = array("/^ou=people,/","/^ou=groups,/","/(,|)ou=configs,/","/(,|)ou=systems,/",
325 "/^ou=apps,/","/^ou=mime,/","/^ou=aclroles,/","/^ou=incoming,/",
326 "/ou=snapshots,/","/(,|)dc=addressbook,/","/^(,|)ou=machineaccounts,/",
327 "/(,|)ou=winstations,/");
330 /* Get all invisible departments */
331 $ldap->cd($cv['base']);
332 $res = $ldap->search("(&(objectClass=organizationalUnit)(!(objectClass=gosaDepartment)))",array("ou","description","dn"));
333 while($attrs = $ldap->fetch()){
334 $attrs['checked'] = FALSE;
335 $attrs['before'] = "";
336 $attrs['after'] = "";
338 /* Set objects to selected, that were selected before reload */
339 if(isset($old[base64_encode($attrs['dn'])])){
340 $attrs['checked'] = $old[base64_encode($attrs['dn'])]['checked'];
341 }
342 $this->deps_to_migrate[base64_encode($attrs['dn'])] = $attrs;
343 }
345 /* Filter returned list of departments and ensure that
346 * GOsa internal departments will not be listed
347 */
348 foreach($this->deps_to_migrate as $key => $attrs){
349 $dn = $attrs['dn'];
350 $skip = false;
351 foreach($skip_dns as $skip_dn){
352 if(preg_match($skip_dn,$dn)){
353 $skip = true;
354 }
355 }
356 if($skip){
357 unset($this->deps_to_migrate[$key]);
358 }
359 }
361 /* If we have no invisible departments found
362 * tell the user that everything is ok
363 */
364 if(!$res){
365 $this->checks['deps_visible']['STATUS'] = FALSE;
366 $this->checks['deps_visible']['STATUS_MSG']= _("Ldap query failed.");
367 $this->checks['deps_visible']['ERROR_MSG'] = _("Possibly the 'root object' is missing.");
368 }elseif(count($this->deps_to_migrate) == 0 ){
369 $this->checks['deps_visible']['STATUS'] = TRUE;
370 $this->checks['deps_visible']['STATUS_MSG']= _("Ok");
371 $this->checks['deps_visible']['ERROR_MSG'] = "";
372 }else{
373 $this->checks['deps_visible']['STATUS'] = FALSE;
374 $this->checks['deps_visible']['STATUS_MSG']= "";//sprintf(_("%s entries found"),count($this->deps_to_migrate));
375 $this->checks['deps_visible']['ERROR_MSG'] = sprintf(_("Found %s departments that will not be visible in GOsa."),count($this->deps_to_migrate));
376 $this->checks['deps_visible']['ERROR_MSG'] .= "<input type='submit' name='deps_visible_migrate' value='"._("Migrate")."'>";
377 }
378 }
382 /* Start deparmtment migration */
383 function migrate_organizationalUnits($only_ldif = FALSE)
384 {
385 /* Get collected configuration settings */
386 $cv = $this->parent->captured_values;
388 /* Establish ldap connection */
389 $ldap = new LDAP($cv['admin'],
390 $cv['password'],
391 $cv['connection'],
392 FALSE,
393 $cv['tls']);
395 /* Add gosaDepartment objectClass to each selected entry
396 */
397 foreach($this->deps_to_migrate as $key => $dep){
398 if($dep['checked']){
400 /* Get current objectClasses */
401 $ldap->cat($dep['dn'],array("objectClass","description"));
402 $attrs = $ldap->fetch();
404 /* Create new objectClass attribute including gosaDepartment*/
405 $new_attrs = array();
406 for($i = 0 ; $i < $attrs['objectClass']['count']; $i ++ ){
407 $new_attrs['objectClass'][] = $attrs['objectClass'][$i];
408 }
409 $new_attrs['objectClass'][] = "gosaDepartment";
411 /* Append description it is missing */
412 if(!isset($attrs['description'])){
413 $new_attrs['description'][] = "GOsa department";
414 }
416 /* Depending on the parameter >only_diff< we save the changes as ldif
417 * or we write our changes directly to the ldap database
418 */
419 if($only_ldif){
420 $this->deps_to_migrate[$key]['before'] = $this->array_to_ldif($attrs);
421 $this->deps_to_migrate[$key]['after'] = $this->array_to_ldif($new_attrs);
422 }else{
423 $ldap->cd($attrs['dn']);
424 if(!$ldap->modify($new_attrs)){
425 print_red(sprintf(_("Failed to migrate the department '%s' into GOsa, error message is as follows '%s'."),$attrs['dn'],$ldap->get_error()));
426 return(false);
427 }
428 }
429 }
430 }
431 return(TRUE);
432 }
435 function get_user_list()
436 {
437 /* Get collected configuration settings */
438 $cv = $this->parent->captured_values;
440 /* Establish ldap connection */
441 $ldap = new LDAP($cv['admin'],
442 $cv['password'],
443 $cv['connection'],
444 FALSE,
445 $cv['tls']);
447 $ldap->cd($cv['base']);
448 $ldap->search("(objectClass=gosaAccount)",array("dn"));
450 $tmp = array();
451 while($attrs = $ldap->fetch()){
452 $tmp[base64_encode($attrs['dn'])] = @LDAP::fix($attrs['dn']);
453 }
455 return($tmp);
456 }
458 function get_group_list()
459 {
460 /* Get collected configuration settings */
461 $cv = $this->parent->captured_values;
463 /* Establish ldap connection */
464 $ldap = new LDAP($cv['admin'],
465 $cv['password'],
466 $cv['connection'],
467 FALSE,
468 $cv['tls']);
470 $ldap->cd($cv['base']);
471 $ldap->search("(objectClass=posixGroup)",array("dn"));
473 $tmp = array();
474 while($attrs = $ldap->fetch()){
475 $tmp[base64_encode($attrs['dn'])] = @LDAP::fix($attrs['dn']);
476 }
478 return($tmp);
479 }
483 function create_admin($only_ldif = FALSE)
484 {
485 /* Reset '' */
486 $this->acl_create_changes="";
488 /* Object that should receive admin acls */
489 $dn = $this->acl_create_selected;
491 /* Get collected configuration settings */
492 $cv = $this->parent->captured_values;
494 /* Establish ldap connection */
495 $ldap = new LDAP($cv['admin'],
496 $cv['password'],
497 $cv['connection'],
498 FALSE,
499 $cv['tls']);
501 /* Get current base attributes */
502 $ldap->cd($cv['base']);
503 $ldap->cat($cv['base'],array("dn","objectClass","gosaAclEntry"));
504 $attrs = $ldap->fetch();
506 /* Add acls for the selcted user to the base */
507 $attrs_new['objectClass'] = array("gosaACL");
509 for($i = 0; $i < $attrs['objectClass']['count']; $i ++){
510 if(!in_array_ics($attrs['objectClass'][$i],$attrs_new['objectClass'])){
511 $attrs_new['objectClass'][] = $attrs['objectClass'][$i];
512 }
513 }
515 $acl = "0:sub:".base64_encode($dn).":all;cmdrw";
516 $attrs_new['gosaAclEntry'][] = $acl;
517 if(isset($attrs['gosaAclEntry'])){
518 for($i = 0 ; $i < $attrs['gosaAclEntry']['count']; $i ++){
520 $prio = preg_replace("/[:].*$/","",$attrs['gosaAclEntry'][$i]);
521 $rest = preg_replace("/^[^:]/","",$attrs['gosaAclEntry'][$i]);
523 $data = ($prio+1).$rest;
524 $attrs_new['gosaAclEntry'][] = $data;
525 }
526 }
528 if($only_ldif){
529 $this->acl_create_changes ="\n".$cv['base']."\n";
530 $this->acl_create_changes.=$this->array_to_ldif($attrs)."\n";
531 $this->acl_create_changes.="\n".$cv['base']."\n";
532 $this->acl_create_changes.=$this->array_to_ldif($attrs_new);
533 }else{
535 $ldap->cd($cv['base']);
536 if(!$ldap->modify($attrs_new)){
537 print_red(sprintf(_("Adding acls for user '%s' failed, ldap says '%s'."),$dn,$ldap->get_error()));
538 }
539 }
540 }
543 function execute()
544 {
545 /* Initialise checks if this is the first call */
546 if(!$this->checks_initialised || isset($_POST['reload'])){
547 $this->initialize_checks();
548 $this->checks_initialised = TRUE;
549 }
551 /* Permission check */
552 $this->check_ldap_permissions();
554 /*************
555 * Root object check
556 *************/
558 if(isset($_POST['retry_root_create'])){
559 $this->checkBase(FALSE);
560 }
562 /*************
563 * User Migration handling
564 *************/
566 if(isset($_POST['retry_acls'])){
567 $this->check_acls();
568 }
570 if(isset($_POST['create_acls'])){
571 $this->acl_create_dialog = TRUE;
572 $this->dialog = TRUE;
573 }
575 if(isset($_POST['create_acls_cancel'])){
576 $this->acl_create_dialog = FALSE;
577 $this->dialog = FALSE;
578 }
580 if(isset($_POST['create_acls_create_confirmed'])){
581 $this->create_admin();
582 }
584 if(isset($_POST['create_acls_create'])){
585 $this->create_admin(TRUE);
586 }
588 if($this->acl_create_dialog){
589 $smarty = get_smarty();
590 $smarty->assign("users" ,$this->get_user_list());
591 $smarty->assign("groups",$this->get_group_list());
592 $smarty->assign("type" ,$this->acl_create_type);
593 $smarty->assign("method","create_acls");
594 $smarty->assign("acl_create_selected",$this->acl_create_selected);
595 $smarty->assign("what_will_be_done_now",$this->acl_create_changes);
596 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
597 }
599 /*************
600 * User Migration handling
601 *************/
603 /* Refresh list of deparments */
604 if(isset($_POST['users_visible_migrate_refresh'])){
605 $this->check_invisible_gosaAccounts();
606 }
608 /* Open migration dialog */
609 if(isset($_POST['users_visible_migrate'])){
610 $this->users_migration_dialog = TRUE;
611 $this->dialog =TRUE;
612 }
614 /* Close migration dialog */
615 if(isset($_POST['users_visible_migrate_close'])){
616 $this->users_migration_dialog = FALSE;
617 $this->dialog =FALSE;
618 }
620 /* Start migration */
621 if(isset($_POST['users_visible_migrate_migrate'])){
622 if($this->migrate_gosaAccounts()){
623 $this->check_invisible_gosaAccounts();
624 }
625 }
627 /* Start migration */
628 if(isset($_POST['users_visible_migrate_whatsdone'])){
629 $this->migrate_gosaAccounts(TRUE);
630 }
632 /* Display migration dialog */
633 if($this->users_migration_dialog){
634 $smarty = get_smarty();
635 $smarty->assign("users_to_migrate",$this->users_to_migrate);
636 $smarty->assign("method","migrate_users");
637 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
638 }
641 /*************
642 * Department Migration handling
643 *************/
645 /* Refresh list of deparments */
646 if(isset($_POST['deps_visible_migrate_refresh'])){
647 $this->check_visible_organizationalUnits();
648 }
650 /* Open migration dialog */
651 if(isset($_POST['deps_visible_migrate'])){
652 $this->dep_migration_dialog = TRUE;
653 $this->dialog =TRUE;
654 }
656 /* Close migration dialog */
657 if(isset($_POST['deps_visible_migrate_close'])){
658 $this->dep_migration_dialog = FALSE;
659 $this->dialog =FALSE;
660 }
662 /* Start migration */
663 if(isset($_POST['deps_visible_migrate_migrate'])){
664 if($this->migrate_organizationalUnits()){
665 $this->check_visible_organizationalUnits();
666 }
667 }
669 /* Start migration */
670 if(isset($_POST['deps_visible_migrate_whatsdone'])){
671 $this->migrate_organizationalUnits(TRUE);
672 }
674 /* Display migration dialog */
675 if($this->dep_migration_dialog){
676 $smarty = get_smarty();
677 $smarty->assign("deps_to_migrate",$this->deps_to_migrate);
678 $smarty->assign("method","migrate_deps");
679 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
680 }
682 $smarty = get_smarty();
683 $smarty->assign("checks",$this->checks);
684 $smarty->assign("method","default");
685 return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
686 }
689 function save_object()
690 {
691 /* Get "create acl" dialog posts */
692 if($this->acl_create_dialog){
693 if(isset($_POST['create_acls_create'])){
694 if(isset($_POST['create_acls_selected'])){
695 $this->acl_create_selected = base64_decode($_POST['create_acls_selected']);
696 }else{
697 $this->acl_create_selected = "";
698 }
699 }
701 if(isset($_POST['create_acls_create_abort'])){
702 $this->acl_create_selected = "";
703 }
705 if(isset($_POST['acl_create_type'])){
706 $this->acl_create_type = $_POST['acl_create_type'];
707 }
708 }
710 /* Get selected departments */
711 if($this->dep_migration_dialog){
712 foreach($this->deps_to_migrate as $id => $data){
713 if(isset($_POST['migrate_'.$id])){
714 $this->deps_to_migrate[$id]['checked'] = TRUE;
715 }else{
716 $this->deps_to_migrate[$id]['checked'] = FALSE;
717 }
718 }
719 }
721 /* Get selected users */
722 if($this->users_migration_dialog){
723 foreach($this->users_to_migrate as $id => $data){
724 if(isset($_POST['migrate_'.$id])){
725 $this->users_to_migrate[$id]['checked'] = TRUE;
726 }else{
727 $this->users_to_migrate[$id]['checked'] = FALSE;
728 }
729 }
730 }
731 }
734 // checks for valid base entry
735 function checkBase($just_check = TRUE)
736 {
737 /* Get collected setup informations */
738 $cv = $this->parent->captured_values;
740 /* Establish ldap connection */
741 $ldap = new LDAP($cv['admin'],
742 $cv['password'],
743 $cv['connection'],
744 FALSE,
745 $cv['tls']);
747 /* Check if root object exists */
748 $ldap->cd($cv['base']);
749 $res = $ldap->search("(objectClass=*)");
750 $err = ldap_errno($ldap->cid);
752 if( !$res ||
753 $err == 0x20 || # LDAP_NO_SUCH_OBJECT
754 $err == 0x40) { # LDAP_NAMING_VIOLATION
756 /* Root object doesn't exists
757 */
758 if($just_check){
759 $this->checks['root']['STATUS'] = FALSE;
760 $this->checks['root']['STATUS_MSG']= _("Failed");
761 $this->checks['root']['ERROR_MSG'].= "<input type='submit' name='retry_root_create' value='"._("Try to create root object")."'>";
762 return(FALSE);
763 }else{
765 /* Add root object */
766 $ldap->cd($cv['base']);
767 $res = $ldap->create_missing_trees($cv['base']);
769 /* If adding failed, tell the user */
770 if(!$res){
771 $this->checks['root']['STATUS'] = FALSE;
772 $this->checks['root']['STATUS_MSG']= _("Failed");
773 $this->checks['root']['ERROR_MSG'] = _("Root object couldn't be created, you should try it on your own.");
774 $this->checks['root']['ERROR_MSG'].= "<input type='submit' name='retry_root_create' value='"._("Try to create root object")."'>";
775 return($res);;
776 }
777 }
778 }
780 /* Create & remove of dummy object was successful */
781 $this->checks['root']['STATUS'] = TRUE;
782 $this->checks['root']['STATUS_MSG']= _("Ok");
783 }
786 /* Return ldif information for a
787 * given attribute array
788 */
789 function array_to_ldif($atts)
790 {
791 $ret = "";
792 unset($atts['count']);
793 unset($atts['dn']);
794 foreach($atts as $name => $value){
795 if(is_numeric($name)) {
796 continue;
797 }
798 if(is_array($value)){
799 unset($value['count']);
800 foreach($value as $a_val){
801 $ret .= $name.": ". $a_val."\n";
802 }
803 }else{
804 $ret .= $name.": ". $value."\n";
805 }
806 }
807 return(preg_replace("/\n$/","",$ret));
808 }
809 }
811 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
812 ?>