Code

Added group migration.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 30 Apr 2007 13:45:23 +0000 (13:45 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 30 Apr 2007 13:45:23 +0000 (13:45 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@6216 594d385d-05f5-0310-b6e9-bd551577e9d8

setup/class_setupStep_Migrate.inc
setup/setup_migrate.tpl

index bffd1baa7356ed2f9ce796e95a6740076b938bf0..949cdbe0378c7620918771f8567bcb02a111f0aa 100644 (file)
@@ -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'].= "<input type='submit' name='outside_groups_dialog' value='"._("Migrate")."'>";
       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").":<br>\t".$dn."<br>"._("to").":<br>\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 .= "<br />\t".$ref_dn;
+          } 
+          if(!empty($refs)){ 
+            $this->outside_groups[$b_dn]['ldif'] .= "<br /><br /><i>"._("Updating following references too").":</i>".$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."<br>".$d_dn;
+          $this->outside_users[$b_dn]['ldif'] = _("User will be moved from").":<br>\t".$dn."<br>"._("to").":<br>\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 .= "<br />".$ref_dn;
+            $refs .= "<br />\t".$ref_dn;
           } 
           if(!empty($refs)){ 
             $this->outside_users[$b_dn]['ldif'] .= "<br /><br /><i>"._("Updating following references too").":</i>".$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 */
index ae25233d624d7266faadb7438cb08f3a94d19a35..b726897c54992c914d1d4015e8638ba99d480660 100644 (file)
                                <div>&nbsp;</div>
                        {/foreach}
 
+               {elseif $method == "outside_groups"}
+
+                       <h2>{t}Move groups into valid group departments{/t}</h2>
+
+                       {t}This dialog allows you to move the displayed groups into a valid group department{/t}
+                       <br>
+                       {t}Be careful with this tool, there may be references pointing to this group that can't be migrated.{/t}
+                       <br>
+                       <br>    
+
+                       {foreach from=$outside_groups item=val key=key}
+                               {if $outside_groups.$key.selected}
+                                       <input type='checkbox' name='select_group_{$key}' checked>
+                               {else}
+                                       <input type='checkbox' name='select_group_{$key}'>
+                               {/if}
+
+                               &nbsp;{$outside_groups.$key.dn}
+                               {if $outside_groups.$key.ldif != ""}
+                      <div class="step2_entry_container_info" id="sol_8">
+<div style='padding-left:20px;'>
+<pre>
+{$outside_groups.$key.ldif}
+</pre>
+</div>
+</div>
+                               {/if}
+                               <br>
+                       {/foreach}
+
+                       <p>
+                       <b>{t}Move selected group into the following GOsa people department{/t} : </b>
+                       <select name='move_group_to'>
+                               {html_options options=$ous}
+                       </select>
+                       <br>
+                       <input type='submit' name='outside_groups_dialog_perform' value='{t}Move selected groups{/t}'>
+                       <input type='submit' name='outside_groups_dialog_whats_done' value='{t}What will be done here{/t}'>
+                       </p>
+                               
+
+                       <p class='seperator'>&nbsp;</p> 
+                       <div style='width:100%; text-align:right; padding:5px;'>
+                               <input type='submit' name='outside_groups_dialog_cancel' value='{t}Close{/t}'>
+                       </div>
+               
+
+               {elseif $method == "create_acls"}
                {elseif $method == "outside_users"}
 
                        <h2>{t}Move users into valid user departments{/t}</h2>