From: hickert Date: Wed, 25 Apr 2007 12:26:49 +0000 (+0000) Subject: Added user account migration X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ea3893f525fd8115812896ff39072ace34ac49fd;p=gosa.git Added user account migration git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@6192 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/setup/class_setupStep_Migrate.inc b/setup/class_setupStep_Migrate.inc index 5259803af..cf289a263 100644 --- a/setup/class_setupStep_Migrate.inc +++ b/setup/class_setupStep_Migrate.inc @@ -28,10 +28,12 @@ class Step_Migrate extends setup_step var $checks = array(); /* Department migration attributes */ - var $migration_dialog = FALSE; - var $deps_to_migrate = array(); + var $dep_migration_dialog = FALSE; + var $deps_to_migrate = array(); - + /* Department migration attributes */ + var $users_migration_dialog= FALSE; + var $users_to_migrate = array(); function Step_Migrate() { @@ -60,6 +62,12 @@ class Step_Migrate extends setup_step $this->checks['deps_visible']['STATUS_MSG']= ""; $this->checks['deps_visible']['ERROR_MSG'] = ""; $this->check_visible_organizationalUnits(); + + $this->checks['users_visible']['TITLE'] = _("Checking for invisible user"); + $this->checks['users_visible']['STATUS'] = FALSE; + $this->checks['users_visible']['STATUS_MSG']= ""; + $this->checks['users_visible']['ERROR_MSG'] = ""; + $this->check_visible_gosaAccounts(); } @@ -114,8 +122,103 @@ class Step_Migrate extends setup_step } + + function check_visible_gosaAccounts() + { + $old = $this->users_to_migrate; + $this->users_to_migrate = array(); + $cnt_ok = 0; + + /* Get collected configuration settings */ + $cv = $this->parent->captured_values; + + /* Establish ldap connection */ + $ldap = new LDAP($cv['admin'], + $cv['password'], + $cv['connection'], + FALSE, + $cv['tls']); + + /* Get all invisible departments */ + $ldap->cd($cv['base']); + $ldap->search("(&(|(objectClass=posixAccount)(objectClass=inetOrgPerson)(objectClass=organizationalPerson))(!(objectClass=gosaAccount)))",array("sn","givenName","cn","uid")); + while($attrs = $ldap->fetch()){ + + if(!preg_match("/,dc=addressbook,/",$attrs['dn'])){ + + $attrs['checked'] = FALSE; + $attrs['before'] = ""; + $attrs['after'] = ""; + + /* Set objects to selected, that were selected before reload */ + if(isset($old[base64_encode($attrs['dn'])])){ + $attrs['checked'] = $old[base64_encode($attrs['dn'])]['checked']; + } + $this->users_to_migrate[base64_encode($attrs['dn'])] = $attrs; + } + } + + /* No invisible */ + if(count($this->users_to_migrate) == 0){ + $this->checks['users_visible']['STATUS'] = TRUE; + $this->checks['users_visible']['STATUS_MSG']= _("Ok"); + $this->checks['users_visible']['ERROR_MSG'] = ""; + $this->checks['users_visible']['ERROR_MSG'] .= ""; + }else{ + $this->checks['users_visible']['STATUS'] = FALSE; + $this->checks['users_visible']['STATUS_MSG']= ""; + $this->checks['users_visible']['ERROR_MSG'] = sprintf(_("Found %s users that will not be visible in GOsa."), + count($this->users_to_migrate)); + $this->checks['users_visible']['ERROR_MSG'] .= ""; + $this->checks['users_visible']['ERROR_MSG'] .= ""; + } + + } + + /* Start deparmtment migration */ + function migrate_gosaAccounts($only_ldif = FALSE) + { + /* Get collected configuration settings */ + $cv = $this->parent->captured_values; + + /* Establish ldap connection */ + $ldap = new LDAP($cv['admin'], + $cv['password'], + $cv['connection'], + FALSE, + $cv['tls']); + + foreach($this->users_to_migrate as $key => $dep){ + if($dep['checked']){ + + $ldap->cat($dep['dn'],array("objectClass")); + $attrs = $ldap->fetch(); + $new_attrs = array(); + + for($i = 0 ; $i < $attrs['objectClass']['count']; $i ++ ){ + $new_attrs['objectClass'][] = $attrs['objectClass'][$i]; + } + $new_attrs['objectClass'][] = "gosaAccount"; + + if($only_ldif){ + $this->users_to_migrate[$key]['before'] = $this->array_to_ldif($attrs); + $this->users_to_migrate[$key]['after'] = $this->array_to_ldif($new_attrs); + }else{ + $ldap->cd($attrs['dn']); + if(!$ldap->modify($new_attrs)){ + print_red(sprintf(_("Failed to migrate the department '%s' into GOsa, error message is as follows '%s'."),$attrs['dn'],$ldap->get_error())); + return(false); + } + } + } + } + return(TRUE); + } + + function check_visible_organizationalUnits() { + $old = $this->deps_to_migrate; $this->deps_to_migrate = array(); $cnt_ok = 0; @@ -144,7 +247,11 @@ class Step_Migrate extends setup_step $attrs['before'] = ""; $attrs['after'] = ""; - $this->deps_to_migrate[] = $attrs; + /* Set objects to selected, that were selected before reload */ + if(isset($old[base64_encode($attrs['dn'])])){ + $attrs['checked'] = $old[base64_encode($attrs['dn'])]['checked']; + } + $this->deps_to_migrate[base64_encode($attrs['dn'])] = $attrs; } /* Filter returned list of departments */ @@ -232,8 +339,50 @@ class Step_Migrate extends setup_step /* Permission check */ $this->check_ldap_permissions(); - /* Migration options + /* User Migration + */ + + /* Refresh list of deparments */ + if(isset($_POST['users_visible_migrate_refresh'])){ + $this->check_visible_gosaAccounts(); + } + + /* Open migration dialog */ + if(isset($_POST['users_visible_migrate'])){ + $this->users_migration_dialog = TRUE; + $this->dialog =TRUE; + } + + /* Close migration dialog */ + if(isset($_POST['users_visible_migrate_close'])){ + $this->users_migration_dialog = FALSE; + $this->dialog =FALSE; + } + + /* Start migration */ + if(isset($_POST['users_visible_migrate_migrate'])){ + if($this->migrate_gosaAccounts()){ + $this->check_visible_gosaAccounts(); + } + } + + /* Start migration */ + if(isset($_POST['users_visible_migrate_whatsdone'])){ + $this->migrate_gosaAccounts(TRUE); + } + + /* Display migration dialog */ + if($this->users_migration_dialog){ + $smarty = get_smarty(); + $smarty->assign("users_to_migrate",$this->users_to_migrate); + $smarty->assign("method","migrate_users"); + return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__)))); + } + + + /* Department migration options */ + /* Refresh list of deparments */ if(isset($_POST['deps_visible_migrate_refresh'])){ $this->check_visible_organizationalUnits(); @@ -241,13 +390,13 @@ class Step_Migrate extends setup_step /* Open migration dialog */ if(isset($_POST['deps_visible_migrate'])){ - $this->migration_dialog = TRUE; + $this->dep_migration_dialog = TRUE; $this->dialog =TRUE; } /* Close migration dialog */ if(isset($_POST['deps_visible_migrate_close'])){ - $this->migration_dialog = FALSE; + $this->dep_migration_dialog = FALSE; $this->dialog =FALSE; } @@ -264,10 +413,10 @@ class Step_Migrate extends setup_step } /* Display migration dialog */ - if($this->migration_dialog){ + if($this->dep_migration_dialog){ $smarty = get_smarty(); $smarty->assign("deps_to_migrate",$this->deps_to_migrate); - $smarty->assign("method","migrate"); + $smarty->assign("method","migrate_deps"); return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__)))); } @@ -279,9 +428,8 @@ class Step_Migrate extends setup_step function save_object() { - if($this->migration_dialog){ + if($this->dep_migration_dialog){ foreach($this->deps_to_migrate as $id => $data){ - if(isset($_POST['migrate_'.$id])){ $this->deps_to_migrate[$id]['checked'] = TRUE; }else{ @@ -289,6 +437,15 @@ class Step_Migrate extends setup_step } } } + if($this->users_migration_dialog){ + foreach($this->users_to_migrate as $id => $data){ + if(isset($_POST['migrate_'.$id])){ + $this->users_to_migrate[$id]['checked'] = TRUE; + }else{ + $this->users_to_migrate[$id]['checked'] = FALSE; + } + } + } } diff --git a/setup/setup_migrate.tpl b/setup/setup_migrate.tpl index a35e4b0e9..845e24f2c 100644 --- a/setup/setup_migrate.tpl +++ b/setup/setup_migrate.tpl @@ -19,7 +19,7 @@ {/if}
 
{/foreach} - {elseif $method == "migrate"} + {elseif $method == "migrate_deps"}

Department migration

@@ -72,6 +72,59 @@ dn: {$deps_to_migrate.$key.dn}
+ {elseif $method == "migrate_users"} + +

User migration

+ + {t}The listed deparmtents below are currenlty invisble in the GOsa user interface. If you want to migrate a set of departments, just select them and use the migrate button below.{/t}
+ {t}If you want to know what will be done when migrating the selected entries, just use the 'What will be done here' button and you will see a list of changes.{/t} + + +

+ {foreach from=$users_to_migrate item=val key=key} + + {if $users_to_migrate.$key.checked} + + {$users_to_migrate.$key.dn} + {if $users_to_migrate.$key.after != ""} +
+ +{t}Current{/t} +
+
+dn: {$users_to_migrate.$key.dn}
+{$users_to_migrate.$key.before}
+
+
+{t}After migration{/t} +
+
+dn: {$users_to_migrate.$key.dn}
+{$users_to_migrate.$key.after}
+
+
+
+ {/if} + {else} + + {$users_to_migrate.$key.dn} + {/if} + +
+ + + {/foreach} +
+ + + + + +

 

+ +
+ +
{else} * Create a test department with some objects to check for correct permissions