Code

Updated FAI filter
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 31 Mar 2010 07:32:24 +0000 (07:32 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 31 Mar 2010 07:32:24 +0000 (07:32 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@17414 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/fai/admin/fai/class_filterFAI.inc
gosa-plugins/fai/admin/fai/class_filterOPSIPackages.inc
gosa-plugins/fai/admin/fai/fai-filter.xml

index 5524e0c1f9df1819a90424ddf407314b12323a44..155b95e4730772a9abb42af1a52db657c8940903 100644 (file)
@@ -4,18 +4,24 @@ class filterFAI extends filterLDAP{
 
   static function query($base, $scope, $filter, $attributes, $category, $objectStorage= "")
   {
-  /* Create a new list of FAI object
+    /* Create a new list of FAI object
      * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
      */
     $ObjectTypes = array(
-        "FAIpartitionTable"  => array("OU"=> get_ou('faiPartitionRDN') , "CHKBOX"=>"ShowPartitions"  ,"ACL" => "faiPartitionTable"),
-        "FAIpackageList"     => array("OU"=> get_ou('faiPackageRDN')   , "CHKBOX"=>"ShowPackages"    ,"ACL" => "faiPackage"),
-        "FAIscript"          => array("OU"=> get_ou('faiScriptRDN')    , "CHKBOX"=>"ShowScripts"     ,"ACL" => "faiScript"),
-        "FAIvariable"        => array("OU"=> get_ou('faiVariableRDN')  , "CHKBOX"=>"ShowVariables"   ,"ACL" => "faiVariable"),
-        "FAIhook"            => array("OU"=> get_ou('faiHookRDN')      , "CHKBOX"=>"ShowHooks"       ,"ACL" => "faiHook"),
-        "FAIprofile"         => array("OU"=> get_ou('faiProfileRDN')   , "CHKBOX"=>"ShowProfiles"    ,"ACL" => "faiProfile"),
-        "FAItemplate"        => array("OU"=> get_ou('faiTemplateRDN')  , "CHKBOX"=>"ShowTemplates"   ,"ACL" => "faiTemplate"));
-
+        "FAIpartitionTable"  => array("OU"=> get_ou('faiPartitionRDN') , "CHKBOX"=>"ShowPartitions"  ,
+          "ACL" => "faiPartitionTable"),
+        "FAIpackageList"     => array("OU"=> get_ou('faiPackageRDN')   , "CHKBOX"=>"ShowPackages"    ,
+          "ACL" => "faiPackage"),
+        "FAIscript"          => array("OU"=> get_ou('faiScriptRDN')    , "CHKBOX"=>"ShowScripts"     ,
+          "ACL" => "faiScript"),
+        "FAIvariable"        => array("OU"=> get_ou('faiVariableRDN')  , "CHKBOX"=>"ShowVariables"   ,
+          "ACL" => "faiVariable"),
+        "FAIhook"            => array("OU"=> get_ou('faiHookRDN')      , "CHKBOX"=>"ShowHooks"       ,
+          "ACL" => "faiHook"),
+        "FAIprofile"         => array("OU"=> get_ou('faiProfileRDN')   , "CHKBOX"=>"ShowProfiles"    ,
+          "ACL" => "faiProfile"),
+        "FAItemplate"        => array("OU"=> get_ou('faiTemplateRDN')  , "CHKBOX"=>"ShowTemplates"   ,
+          "ACL" => "faiTemplate"));
 
 
     global $config;
@@ -23,7 +29,7 @@ class filterFAI extends filterLDAP{
     $ui = get_userinfo();
     $ldap = $config->get_ldap_link();
     $ldap->cd($config->current['BASE']);
-
+   
     $result = array();
     foreach($tmp as $entry){
 
index 19de355b56410a5e09679442865513ae26371580..2a52389f18a34067cb19c80e3a8e4b5171fc5181 100644 (file)
@@ -8,6 +8,7 @@ class filterOPSIPackages extends filterLDAP{
     $ui = get_userinfo();
     $ldap = $config->get_ldap_link();
     $ldap->cd($config->current['BASE']);
+    $entries = array();
 
     // Append opsi stuff ...
     if(class_available('opsi') && $base == get_ou("faiBaseRDN").$config->current['BASE']){
@@ -40,19 +41,34 @@ class filterOPSIPackages extends filterLDAP{
           }
         }
       }
-      $cn_filter = "";
-      if(preg_match("/^.*cn=([^)]*).*/",$filter)){
-        $cn_filter = trim(preg_replace("/^.*cn=([^)]*).*/","\\1",$filter),"*");
+
+      // Parse filter string 
+      list($type,$filter) = preg_split("/;/",$filter);
+      $types = preg_split("/,/", $type);
+
+      // Remove automatically added '*' from filter 
+      $filter= trim(preg_replace("/\*/",'', $filter));
+      if(empty($filter)){
+        $filter = ".*";
+      }else{
+        $filter = preg_quote($filter,'/');
       }
 
+
+      // Build up ldap like object list.
       foreach($objects as $name => $data)
       {
         $data = array_pop($data);
-        if(!empty($cn_filter) && !preg_match("/".preg_quote($cn_filter,'/')."/",  $data['cn'])){
+
+        // Display only requested object types
+        if(!in_array($data['type'], $types)) continue;
+
+        // Filter out those entries that doesn't match the filter.
+        if(!preg_match("/".$filter."/i",  $data['cn'])){
           continue;
         }
-        $item =array();
 
+        $item =array();
         $item['objectClass']  = array('count' => 2, $data['type'],"FAKE_OC_OPSI");
         $item[] = 'objectClass';
         $item['cn']  = $data['cn'];
@@ -65,7 +81,6 @@ class filterOPSIPackages extends filterLDAP{
         $item[] = 'TYPES';
         $item['count'] = '5';
         $entries[] = $item;
-
       }
     }
     return($entries);
index 006a3d778c6fdf186f2b0c6e3e75a87f5ac27198..50f934be402e42dbc04d54c98910047cb7b87db8 100644 (file)
     <label>Default filter</label>
     <query>
       <backend>FAI</backend>
-      <filter>(&amp;
-                (|  
-                  (objectClass=FAIprofile)
-                  (objectClass=FAIhook)
-                  (objectClass=FAItemplate)
-                  (objectClass=FAIscript)
-                  (objectClass=FAIvariable)
-                  (objectClass=FAIpackageList)
-                  (objectClass=FAIpartitionTable)
-                )
-                (cn=$)
-              )
-      </filter>
+      <filter>(&amp;(|(objectClass=FAIprofile)(objectClass=FAIhook)(objectClass=FAItemplate)(objectClass=FAIscript)(objectClass=FAIvariable)(objectClass=FAIpackageList)(objectClass=FAIpartitionTable))(cn=$))</filter>
     </query>
     <query>
       <backend>OPSIPackages</backend>
-      <filter>cn=$</filter>
+      <filter>opsi_netboot,opsi_local;$</filter>
     </query>
     <autocomplete>
       <attribute>cn</attribute>