From: hickert Date: Mon, 30 Apr 2007 13:45:23 +0000 (+0000) Subject: Added group migration. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=6ce9c303c568b659e7cac314f7e3211c55bfb4d1;p=gosa.git Added group migration. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@6216 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/setup/class_setupStep_Migrate.inc b/setup/class_setupStep_Migrate.inc index bffd1baa7..949cdbe03 100644 --- a/setup/class_setupStep_Migrate.inc +++ b/setup/class_setupStep_Migrate.inc @@ -337,6 +337,8 @@ class Step_Migrate extends setup_step $this->outside_groups = array(); while($attrs = $ldap->fetch()){ if(!preg_match("/^[^,]+,".normalizePreg($group_ou)."/",$attrs['dn'])){ + $attrs['selected'] = FALSE; + $attrs['ldif'] = ""; $this->outside_groups[base64_encode($attrs['dn'])] = $attrs; } } @@ -346,6 +348,7 @@ class Step_Migrate extends setup_step $this->checks['outside_groups']['STATUS_MSG']= _("Failed"); $this->checks['outside_groups']['ERROR_MSG'] = sprintf(_("Found %s groups outside the selected group ou '%s'."),count($this->outside_groups),$group_ou); + $this->checks['outside_groups']['ERROR_MSG'].= ""; return(false); }else{ $this->checks['outside_groups']['STATUS'] = TRUE; @@ -856,6 +859,54 @@ class Step_Migrate extends setup_step } + function migrate_outside_groups($perform = FALSE) + { + /* Establish ldap connection */ + $cv = $this->parent->captured_values; + $ldap = new LDAP($cv['admin'], + $cv['password'], + $cv['connection'], + FALSE, + $cv['tls']); + + $ldap->cd($cv['base']); + + /* Check if there was a destination department posted */ + if(isset($_POST['move_group_to'])){ + $destination_dep = $_POST['move_group_to']; + }else{ + print_red(_("Couldn't move users to specified department.")); + return(false); + } + + foreach($this->outside_groups as $b_dn => $data){ + $this->outside_groups[$b_dn]['ldif'] =""; + if($data['selected']){ + $dn = base64_decode($b_dn); + $d_dn = preg_replace("/,.*$/",",".base64_decode($destination_dep),$dn); + if(!$perform){ + $this->outside_groups[$b_dn]['ldif'] = _("Group will be moved from").":
\t".$dn."
"._("to").":
\t".$d_dn; + + + /* Check if there are references to this object */ + $ldap->search("(&(member=".$dn.")(|(objectClass=gosaGroupOfNames)(objectClass=groupOfNames)))",array('dn')); + $refs = ""; + while($attrs = $ldap->fetch()){ + $ref_dn = $attrs['dn']; + $refs .= "
\t".$ref_dn; + } + if(!empty($refs)){ + $this->outside_groups[$b_dn]['ldif'] .= "

"._("Updating following references too").":".$refs; + } + + }else{ + $this->move($dn,$d_dn); + } + } + } + } + + function migrate_outside_users($perform = FALSE) { /* Establish ldap connection */ @@ -882,14 +933,14 @@ class Step_Migrate extends setup_step $dn = base64_decode($b_dn); $d_dn = preg_replace("/,.*$/",",".base64_decode($destination_dep),$dn); if(!$perform){ - $this->outside_users[$b_dn]['ldif'] = $dn."
".$d_dn; + $this->outside_users[$b_dn]['ldif'] = _("User will be moved from").":
\t".$dn."
"._("to").":
\t".$d_dn; /* Check if there are references to this object */ $ldap->search("(&(member=".$dn.")(|(objectClass=gosaGroupOfNames)(objectClass=groupOfNames)))",array('dn')); $refs = ""; while($attrs = $ldap->fetch()){ $ref_dn = $attrs['dn']; - $refs .= "
".$ref_dn; + $refs .= "
\t".$ref_dn; } if(!empty($refs)){ $this->outside_users[$b_dn]['ldif'] .= "

"._("Updating following references too").":".$refs; @@ -911,6 +962,37 @@ class Step_Migrate extends setup_step $this->checks_initialised = TRUE; } + /************* + * Groups outside the group ou + *************/ + + if(isset($_POST['outside_groups_dialog_cancel'])){ + $this->outside_groups_dialog = FALSE; + $this->dialog = FALSE; + } + + if(isset($_POST['outside_groups_dialog_whats_done'])){ + $this->migrate_outside_groups(FALSE); + } + + if(isset($_POST['outside_groups_dialog_perform'])){ + $this->migrate_outside_groups(TRUE); + $this->search_outside_groups(); + } + + if(isset($_POST['outside_groups_dialog'])){ + $this->outside_groups_dialog = TRUE; + $this->dialog = TRUE; + } + + if($this->outside_groups_dialog){ + $smarty = get_smarty(); + $smarty->assign("ous",$this->get_all_group_ous()); + $smarty->assign("method","outside_groups"); + $smarty->assign("outside_groups",$this->outside_groups); + return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__)))); + } + /************* * User outside the people ou *************/ @@ -1091,6 +1173,17 @@ class Step_Migrate extends setup_step function save_object() { + /* Capture all selected groups from outside_groups_dialog */ + if($this->outside_groups_dialog){ + foreach($this->outside_groups as $dn => $data){ + if(isset($_POST['select_group_'.$dn])){ + $this->outside_groups[$dn]['selected'] = TRUE; + }else{ + $this->outside_groups[$dn]['selected'] = FALSE; + } + } + } + /* Capture all selected users from outside_users_dialog */ if($this->outside_users_dialog){ foreach($this->outside_users as $dn => $data){ @@ -1318,6 +1411,46 @@ class Step_Migrate extends setup_step } + function get_all_group_ous() + { + /* Get collected configuration settings */ + $cv = $this->parent->captured_values; + + /* Establish ldap connection */ + $ldap = new LDAP($cv['admin'], + $cv['password'], + $cv['connection'], + FALSE, + $cv['tls']); + + $ldap->cd($cv['base']); + $ldap->search("(".$cv['groupou'].")",array("dn")); + + if($ldap->count() == 0 ){ + $add_dn = $cv['groupou'].",".$cv['base']; + $naming_attr = preg_replace("/=.*$/","",$add_dn); + $naming_value = preg_replace("/^[^=]*+=([^,]*).*$/","\\1",$add_dn); + $add = array(); + $add['objectClass'] = array("organizationalUnit"); + $add[$naming_attr] = $naming_value; + + $ldap->cd($cv['base']); + $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$add_dn)); + $ldap->cd($add_dn); + $ldap->add($add); + } + + $ldap->search("(".$cv['groupou'].")",array("dn")); + $tmp = array(); + while($attrs= $ldap->fetch()){ + if(!preg_match("/ou=snapshots,/",$attrs['dn'])){ + $tmp[base64_encode($attrs['dn'])] = $ldap->fix($attrs['dn']); + } + } + return($tmp); + } + + function get_group_list() { /* Get collected configuration settings */ diff --git a/setup/setup_migrate.tpl b/setup/setup_migrate.tpl index ae25233d6..b726897c5 100644 --- a/setup/setup_migrate.tpl +++ b/setup/setup_migrate.tpl @@ -31,6 +31,54 @@
 
{/foreach} + {elseif $method == "outside_groups"} + +

{t}Move groups into valid group departments{/t}

+ + {t}This dialog allows you to move the displayed groups into a valid group department{/t} +
+ {t}Be careful with this tool, there may be references pointing to this group that can't be migrated.{/t} +
+
+ + {foreach from=$outside_groups item=val key=key} + {if $outside_groups.$key.selected} + + {else} + + {/if} + +  {$outside_groups.$key.dn} + {if $outside_groups.$key.ldif != ""} +
+
+
+{$outside_groups.$key.ldif}
+
+
+
+ {/if} +
+ {/foreach} + +

+ {t}Move selected group into the following GOsa people department{/t} : + +
+ + +

+ + +

 

+
+ +
+ + + {elseif $method == "create_acls"} {elseif $method == "outside_users"}

{t}Move users into valid user departments{/t}