Code

Bugfix for Trac #2870
authorpsc <psc@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 16 Oct 2009 13:30:26 +0000 (13:30 +0000)
committerpsc <psc@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 16 Oct 2009 13:30:26 +0000 (13:30 +0000)
- Filter servers by the unittag of the user
- Filter classes by the unittag of the user by generating
  a list of bad classes and comparing the classes to it.

git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6-lhm@14596 594d385d-05f5-0310-b6e9-bd551577e9d8

trunk/gosa-plugins/goto/admin/systems/goto/class_workstationStartup.inc

index 0e372ddefbd29d2127ec8217ee5a88eca7aaf4ad..1460629097d3757677d1313780411bb1f15c4da3 100644 (file)
@@ -1044,6 +1044,44 @@ class workstartup extends plugin
           ));
   }
 
+  /* Function to find bad classes */
+  function update_bad_classes($release)
+  {
+
+    if(!isset($this->cache['BAD_CLASSES'][$release])) {
+      /* Find "bad" classes */
+      $ui = get_userinfo();
+      $ldap = $this->config->get_ldap_link();
+
+      /* Convert release name to a valid ldap uri component */
+      $release_components = split('/', $release);
+      $release_components = array_reverse($release_components);
+      for($i=0;$i<sizeof($release_components);$i++) {
+        $release_components[$i] = "ou=" . $release_components[$i];
+      }
+      $release_dn_part = join(',', $release_components);
+
+      /* Limit the base to the release in the faiBase */
+      $base = sprintf("%s,%s%s", $release_dn_part, get_ou('faiBaseRDN'), $this->config->current['BASE']);
+
+      /* Build a list of all fai classes, that don't have the unittag of the user
+       * and are not freezed or removed. The classes will be filtered by this
+       * list. Its needed to specify each objectClass (FAIpackageList etc.) because
+       * FAIClass would match sub-objects, too, which would lead to an array that
+       * is much bigger then needed */
+      $filter = sprintf('(&(|(objectClass=FAItemplate)(objectClass=FAIpackageList)(objectClass=FAIprofile)(objectClass=FAIscript)(objectClass=FAIpartitionTable)(objectClass=FAIHook)(objectClass=FAIvariable)(objectClass=FAItemplate))(&(!(gosaUnitTag=%s))(&(!(FAIstate=*removed*))(!(FAIstate=*freeze*)))))', $ui->gosaUnitTag);
+      $ldap->cd($base);
+      $ldap->search(sprintf("$filter", $ui->gosaUnitTag));
+        
+      $this->cache['BAD_CLASSES'][$release] = array(); 
+      while ($entry = $ldap->fetch()) {
+        $classname = $entry['cn'][0];
+        if (!in_array($classname, $this->cache['BAD_CLASSES'][$release])) {
+          array_push($this->cache['BAD_CLASSES'][$release], $classname);
+        }
+      }
+    } 
+   }
 
   /* Updates release dns 
    *  and reads all classes for the current release, 
@@ -1072,7 +1110,15 @@ class workstartup extends plugin
         return;
       }else{
 
+        $base = $this->config->current['BASE'];
+        $ldap = $this->config->get_ldap_link();
         foreach($servers as $server){
+          /* Dont show servers that have a different unittag as the user*/
+          $ui = get_userinfo();
+          if ($ui->gosaUnitTag != $server['TAG']) {
+            continue;
+          }
+        
           $rel = $server['FAI_RELEASE'];
           $this->cache['SERVERS']['auto'][$rel] = $rel;
           $this->cache['SERVERS'][$server['SERVER']][$rel] = $rel;
@@ -1133,6 +1179,13 @@ class workstartup extends plugin
       }else{
         foreach($classes as $class){
           $classname = $class['CLASS'];
+          $this->update_bad_classes($release);
+          if(isset($this->cache['BAD_CLASSES'][$release])){
+            /* Skip classes that are in the array of bad classes */
+            if (in_array($classname, $this->cache['BAD_CLASSES'][$release])) {
+              continue;
+            }
+          }
           if (!isset($this->cache['CLASSES'][$release][$classname])) {
             $this->cache['CLASSES'][$release][$classname] = array();
           }