Code

Added scalix and nagios accounts.
[gosa.git] / gosa-core / setup / class_setupStep_Migrate.inc
index d6b486930b911baa287c807874b143347d34bf98..9f20ab6a24425da072d9f29020a91d6ded8081e6 100644 (file)
@@ -133,67 +133,67 @@ class Step_Migrate extends setup_step
     $this->checks['permissions']['STATUS']    = FALSE;
     $this->checks['permissions']['STATUS_MSG']= "";
     $this->checks['permissions']['ERROR_MSG'] = "";
-//    $this->check_ldap_permissions();
+    $this->check_ldap_permissions();
 
     $this->checks['deps_visible']['TITLE']     = _("Checking for invisible departments");
     $this->checks['deps_visible']['STATUS']    = FALSE;
     $this->checks['deps_visible']['STATUS_MSG']= "";
-//    $this->checks['deps_visible']['ERROR_MSG'] = "";
+    $this->checks['deps_visible']['ERROR_MSG'] = "";
 
     $this->checks['users_visible']['TITLE']     = _("Checking for invisible users");
     $this->checks['users_visible']['STATUS']    = FALSE;
     $this->checks['users_visible']['STATUS_MSG']= "";
     $this->checks['users_visible']['ERROR_MSG'] = "";
-//    $this->check_gosaAccounts();
+    $this->check_gosaAccounts();
 
     $this->checks['acls']['TITLE']     = _("Checking for super administrator");
     $this->checks['acls']['STATUS']    = FALSE;
     $this->checks['acls']['STATUS_MSG']= "";
     $this->checks['acls']['ERROR_MSG'] = "";
-//    $this->check_administrativeAccount();
+    $this->check_administrativeAccount();
 
     $this->checks['outside_users']['TITLE']     = _("Checking for users outside the people tree");
     $this->checks['outside_users']['STATUS']    = FALSE;
     $this->checks['outside_users']['STATUS_MSG']= "";
     $this->checks['outside_users']['ERROR_MSG'] = "";
-//    $this->search_outside_users();
+    $this->search_outside_users();
 
     $this->checks['outside_groups']['TITLE']     = _("Checking for groups outside the groups tree");
     $this->checks['outside_groups']['STATUS']    = FALSE;
     $this->checks['outside_groups']['STATUS_MSG']= "";
     $this->checks['outside_groups']['ERROR_MSG'] = "";
-//    $this->search_outside_groups();
-//    $this->check_organizationalUnits();
+    $this->search_outside_groups();
+    $this->check_organizationalUnits();
 
     $this->checks['outside_winstations']['TITLE']     = _("Checking for windows workstations outside the winstation tree");
     $this->checks['outside_winstations']['STATUS']    = FALSE;
     $this->checks['outside_winstations']['STATUS_MSG']= "";
     $this->checks['outside_winstations']['ERROR_MSG'] = "";
-//    $this->search_outside_winstations();
+    $this->search_outside_winstations();
 
     $this->checks['uidNumber_usage']['TITLE']     = _("Checking for duplicated UID numbers");
     $this->checks['uidNumber_usage']['STATUS']    = FALSE;
     $this->checks['uidNumber_usage']['STATUS_MSG']= "";
     $this->checks['uidNumber_usage']['ERROR_MSG'] = "";
-//    $this->check_uidNumber();
+    $this->check_uidNumber();
 
     $this->checks['gidNumber_usage']['TITLE']     = _("Checking for duplicate GID numbers");
     $this->checks['gidNumber_usage']['STATUS']    = FALSE;
     $this->checks['gidNumber_usage']['STATUS_MSG']= "";
     $this->checks['gidNumber_usage']['ERROR_MSG'] = "";
-//    $this->check_gidNumber();
+    $this->check_gidNumber();
 
     $this->checks['old_style_devices']['TITLE']     = _("Checking for old style USB devices");
     $this->checks['old_style_devices']['STATUS']    = FALSE;
     $this->checks['old_style_devices']['STATUS_MSG']= "";
     $this->checks['old_style_devices']['ERROR_MSG'] = "";
-//    $this->check_usb_devices();
+    $this->check_usb_devices();
 
     $this->checks['old_style_services']['TITLE']     = _("Checking for old services that have to be migrated");
     $this->checks['old_style_services']['STATUS']    = FALSE;
     $this->checks['old_style_services']['STATUS_MSG']= "";
     $this->checks['old_style_services']['ERROR_MSG'] = "";
-//    $this->check_services();
+    $this->check_services();
 
     $this->checks['old_style_menus']['TITLE']     = _("Checking for old style application menus");
     $this->checks['old_style_menus']['STATUS']    = FALSE;
@@ -323,7 +323,7 @@ class Step_Migrate extends setup_step
 
     /* Get winstation ou */
     if($cv['generic_settings']['wws_ou_active']) {
-      $winstation_ou = $cv['generic_settings']['ws_ou'];
+      $winstation_ou = $cv['generic_settings']['wws_ou'];
     }else{
       $winstation_ou = "ou=winstations";
     }
@@ -1019,6 +1019,16 @@ class Step_Migrate extends setup_step
   {
     $pw1 = $pw2 = "";
     $uid = "";
+
+    /* On first call check for rid/sid base */
+    $cv = $this->parent->captured_values;
+    $ldap_l = new LDAP($cv['admin'],
+        $cv['password'],
+        $cv['connection'],
+        FALSE,
+        $cv['tls']);
+
+    $ldap = new ldapMultiplexer($ldap_l);
   
     if(isset($_POST['new_user_uid'])){
       $uid = $_POST['new_user_uid'];
@@ -1030,6 +1040,14 @@ class Step_Migrate extends setup_step
       $pw2 = $_POST['new_user_password2'];
     }
   
+    
+    $ldap->cd($cv['base']);
+    $ldap->search("(uid=".$uid.")");
+    if($ldap->count()){
+      msg_dialog::display(_("Input error"),msgPool::duplicated(_("Uid")), ERROR_DIALOG);
+      return false;
+    }
+    
     if(empty($pw1) || empty($pw2) | ($pw1 != $pw2)){
       msg_dialog::display(_("Password error"), _("Provided passwords do not match!"), ERROR_DIALOG);
       return false;
@@ -1039,17 +1057,8 @@ class Step_Migrate extends setup_step
       msg_dialog::display(_("Input error"), _("Specify a valid user ID!"), ERROR_DIALOG);
       return false;
     }
-    
-    /* On first call check for rid/sid base */
-    $cv = $this->parent->captured_values;
-    $ldap_l = new LDAP($cv['admin'],
-        $cv['password'],
-        $cv['connection'],
-        FALSE,
-        $cv['tls']);
-
-    $ldap = new ldapMultiplexer($ldap_l);
-
     /* Get current base attributes */
     $ldap->cd($cv['base']);
   
@@ -1637,7 +1646,7 @@ class Step_Migrate extends setup_step
     }
 
     if(isset($_POST['migrate_services'])){
-      $this->migrate_usb_services();
+      $this->migrate_services();
 #      $this->dialog = FALSE;
  #     $this->show_details = FALSE;
   #    $this->service_dialog = FALSE;
@@ -1681,7 +1690,7 @@ class Step_Migrate extends setup_step
     }
 
     if(isset($_POST['migrate_menus'])){
-      $this->migrate_usb_menus();
+      $this->migrate_menus();
 #      $this->dialog = FALSE;
  #     $this->show_details = FALSE;
   #    $this->menu_dialog = FALSE;
@@ -1960,7 +1969,7 @@ class Step_Migrate extends setup_step
 
     /* Get winstation ou */
     if($cv['generic_settings']['wws_ou_active']) {
-      $winstation_ou = $cv['generic_settings']['ws_ou'];
+      $winstation_ou = $cv['generic_settings']['wws_ou'];
     }else{
       $winstation_ou = "ou=winstations";
     }
@@ -2145,6 +2154,8 @@ class Step_Migrate extends setup_step
   }
 
 
+  /*! \brief  Act in posts from the device migration dialog 
+   */
   function check_device_posts()
   {
     foreach($this->device as $key => $device){
@@ -2157,6 +2168,10 @@ class Step_Migrate extends setup_step
   }
 
 
+  /*! \brief  Check for old style (gosa-2.5) devices.
+              Save readable informations and a list of migratable devices 
+               in $this->devices.
+   */
   function check_usb_devices ()
   {
     /* Establish ldap connection */
@@ -2241,7 +2256,7 @@ class Step_Migrate extends setup_step
       }
 
       $this->checks['old_style_devices']['STATUS']    = FALSE;
-      $this->checks['old_style_devices']['STATUS_MSG']= _("Failed");
+      $this->checks['old_style_devices']['STATUS_MSG']= "<font style='color:#F0A500'>"._("Warning")."</font>";
       $this->checks['old_style_devices']['ERROR_MSG'] = 
         sprintf(_("There are %s devices that need to be migrated."),count($this->device)).
           "<input type='submit' name='device_dialog' value='"._("Migrate")."'>";
@@ -2252,6 +2267,11 @@ class Step_Migrate extends setup_step
     }
   }
 
+
+  /*! \brief  Migrate all selected devices. 
+              Execute all required ldap actions to migrate the 
+               selected devices.
+   */
   function migrate_usb_devices ()
   {
     /* Establish ldap connection */
@@ -2293,12 +2313,18 @@ class Step_Migrate extends setup_step
           $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$newdn));
           $ldap->cd($newdn);
           $ldap->add($new_attr);
+
+          /* Throw an error message if the action failed. 
+           */
           if(!$ldap->success()){
             msg_dialog::display(_("LDAP error"), 
-                sprintf(_("Ldap add failed for %s with error %s"),
+                sprintf(_("Adding '%s' to the LDAP failed: %s"),
                   "<b>".LDAP::fix($newdn)."</b>", 
                   "<br><br><i>".$ldap->get_error()."</i>"), ERROR_DIALOG);
           }else{
+
+            /* Remove old style device definition from source object. 
+             */
             $update['gotoHotplugDevice'] = array();
             for($i = 0 ; $i < $attrs['gotoHotplugDevice']['count'] ; $i++){
               if($attrs['gotoHotplugDevice'][$i] == $device['OLD_DEVICE']){
@@ -2312,7 +2338,7 @@ class Step_Migrate extends setup_step
             $ldap->cat($device['DN'],array("gotoHotplugDevice"));
             if(!$ldap->success()){
               msg_dialog::display(_("LDAP error"), 
-                  sprintf(_("Ldap update failed for %s with error %s"),
+                  sprintf(_("Updating '%s' failed: %s"),
                     "<b>".LDAP::fix($device['DN'])."</b>", 
                     "<br><br><i>".$ldap->get_error()."</b>"), ERROR_DIALOG);
             }else{
@@ -2322,10 +2348,16 @@ class Step_Migrate extends setup_step
         }
       }
     }
+    $this->check_usb_devices();
   }
 
 
-
+  /*! \brief  Check for old style (gosa-2.5) services that have to be migrated
+               to be useable in gosa-2.6.
+              All required changes are stored in $this->service, also some
+               readable informations describing the actions required 
+               to migrate the service
+   */
   function check_services()
   {
     /* Establish ldap connection */
@@ -2377,7 +2409,7 @@ class Step_Migrate extends setup_step
      */
     if(count($this->service)){
       $this->checks['old_style_services']['STATUS']    = FALSE;
-      $this->checks['old_style_services']['STATUS_MSG']= _("Failed");
+      $this->checks['old_style_services']['STATUS_MSG']= "<font style='color:#F0A500'>"._("Warning")."</font>";
       $this->checks['old_style_services']['ERROR_MSG'] =
         sprintf(_("There are %s services that need to be migrated."),
             count($this->service)).
@@ -2390,7 +2422,12 @@ class Step_Migrate extends setup_step
   }
 
 
-  function migrate_usb_services()
+  
+  /*! \brief  Migrate selected services.
+              This function executes the commands collected by the 
+               service_check() function.
+   */
+  function migrate_services()
   {
     /* Establish ldap connection 
      */
@@ -2418,7 +2455,7 @@ class Step_Migrate extends setup_step
            */
           if(!$ldap->success()){
             msg_dialog::display(_("LDAP error"), 
-                sprintf(_("Ldap update failed for %s with error %s"),
+                sprintf(_("Updating '%s' failed: %s"),
                   "<b>".LDAP::fix($service['DN'])."</b>", 
                   "<br><br><i>".$ldap->get_error()."</b>"), ERROR_DIALOG);
           }else{
@@ -2430,9 +2467,16 @@ class Step_Migrate extends setup_step
         }
       }
     }
+
+    /* Update the service migration status 
+     */
+    $this->check_services();
   }
 
 
+  /*! \brief  Ensure that posts made on the service migration dialog 
+               are processed.
+   */
   function check_service_posts()
   {
     foreach($this->service as $key => $service){
@@ -2482,6 +2526,7 @@ class Step_Migrate extends setup_step
         which configured parameter belongs to which application entry.
      */
     $amap= array();
+    $todo = array();
     $ldap->cd($cv['base']);
     $ldap->search("(objectClass=gosaApplication)", array("cn", "gosaApplicationParameter"));
     while($info = $ldap->fetch()){
@@ -2507,8 +2552,8 @@ class Step_Migrate extends setup_step
 
     /* Create readable prefix for "What will be done" infos 
      */
-    $s_add = "<i>"._("add")."</i>\t";
-    $s_del = "<i>"._("remove")."</i>\t";
+    $s_add = "<i>"._("Add")."</i>\t";
+    $s_del = "<i>"._("Remove")."</i>\t";
 
     /* Walk through all found old-style menu configurations.
         -Prepare ldap update list     $data   
@@ -2697,7 +2742,7 @@ class Step_Migrate extends setup_step
     if(count($this->menu)){
       $this->checks['old_style_menus']['STATUS']    = FALSE;
       $this->checks['old_style_menus']['STATUS_MSG']= "<font style='color:#F0A500'>"._("Warning")."</font>";
-      $this->checks['old_style_menus']['ERROR_MSG'] = sprintf(_("There are %s application menus which have to be converted."),
+      $this->checks['old_style_menus']['ERROR_MSG'] = sprintf(_("There are %s application menus which have to be migrated."),
                                                       count($this->menu))."<input type='submit' name='menu_dialog' value='"._("Migrate")."'>";
     }else{
       $this->checks['old_style_menus']['STATUS']    = TRUE;
@@ -2727,7 +2772,7 @@ class Step_Migrate extends setup_step
               All selected menus will be converted (DETAILS = TRUE). 
               The ldap actions collected by check_menus() will be executed. 
    */
-  function migrate_usb_menus()
+  function migrate_menus()
   {
 
     /* Establish ldap connection
@@ -2752,7 +2797,6 @@ class Step_Migrate extends setup_step
         $success = TRUE;
         foreach($menu['TODO']['ADD'] as $dn => $data){
           $ldap->cd($cv['base']);
-          $base = preg_replace("/^[^,]+,/","",$dn);
           if(!$ldap->dn_exists($dn)){
             $ldap->cd($dn);
             $ldap->add($data);
@@ -2767,7 +2811,7 @@ class Step_Migrate extends setup_step
          */
         foreach($menu['TODO']['MODIFY'] as $dn => $data){
           $ldap->cd($cv['base']);
-          if(!$ldap->dn_exists($dn)){
+          if($ldap->dn_exists($dn)){
             $ldap->cd($dn);
             $ldap->modify($data);
             if (!$ldap->success()){