Code

Backport from trunk
[gosa.git] / gosa-plugins / fai / admin / fai / class_filterFAI.inc
1 <?php
3 class filterFAI extends filterLDAP{
5   static function query($base, $scope, $filter, $attributes, $category, $objectStorage= "")
6   {
7     /* Create a new list of FAI object
8      * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
9      */
10     $ObjectTypes = array(
11         "FAIpartitionTable"  => array("OU"=> get_ou("faiPartitionTable", "faiPartitionRDN") , "CHKBOX"=>"ShowPartitions"  ,
12           "ACL" => "faiPartitionTable"),
13         "FAIpackageList"     => array("OU"=> get_ou("faiPackage", "faiPackageRDN")   , "CHKBOX"=>"ShowPackages"    ,
14           "ACL" => "faiPackage"),
15         "FAIscript"          => array("OU"=> get_ou("faiScript", "faiScriptRDN")    , "CHKBOX"=>"ShowScripts"     ,
16           "ACL" => "faiScript"),
17         "FAIvariable"        => array("OU"=> get_ou("faiVariable", "faiVariableRDN")  , "CHKBOX"=>"ShowVariables"   ,
18           "ACL" => "faiVariable"),
19         "FAIhook"            => array("OU"=> get_ou("faiHook", "faiHookRDN")      , "CHKBOX"=>"ShowHooks"       ,
20           "ACL" => "faiHook"),
21         "FAIprofile"         => array("OU"=> get_ou("faiProfile", "faiProfileRDN")   , "CHKBOX"=>"ShowProfiles"    ,
22           "ACL" => "faiProfile"),
23         "FAItemplate"        => array("OU"=> get_ou("faiTemplate", "faiTemplateRDN")  , "CHKBOX"=>"ShowTemplates"   ,
24           "ACL" => "faiTemplate"));
27     global $config;
28     $tmp = FAI::get_all_objects_for_given_base($base,$filter);
29     $ui = get_userinfo();
30     $ldap = $config->get_ldap_link();
31     $ldap->cd($config->current['BASE']);
32    
33     $result = array();
34     foreach($tmp as $entry){
36       /* Get some more informations about the object */
37       $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
38       $object  = $ldap->fetch();
40       /* Walk through possible types */
41       foreach($ObjectTypes as $type => $rest){
43         $acl = $ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
45         if(in_array_strict($type,$object['objectClass']) && preg_match("/r/",$acl)){
47           /* Prepare object */
48           unset($object['objectClass']['count']);
49           if(!isset($object['description'][0])){
50             $object['description'][0]="";
51           }
53           $dn = preg_replace("/^[^,]*+,/","",$object['dn']);
55           /* Clean up object informations */
56           $obj                  = array();
57           $obj['cn']            = $object['cn'][0];
58           $obj['dn']            = $object['cn'][0].",".get_ou("faiManagement", "faiBaseRDN").$config->current['BASE'];
59           $obj['acl']           = $acl;
60           $obj['class']         = $rest ['ACL'];
61           $obj['FAIstate']      = $entry['FAIstate'];
62           $obj['description']   = $object['description'][0];
63           $obj['objectClass']   = $object['objectClass'];
64           $obj['objectClass'][] = 'FAKE_OC_FAI';
66           if(!preg_match("/freeze/i", $entry['FAIstate'])){
67             $obj['objectClass'][] = "FAKE_OC_IsBranch";
68           }
69           $object['FAIstate'] = $entry['FAIstate'];
71           $obj['TYPES'][]       = $type;
72           $obj['GROUPS'][$type]      = $object;
74           if(!isset($result[$obj['cn']])){
75             $result[$obj['cn']] = $obj;
76           }else{
77             $result[$obj['cn']]['TYPES'][]=$type;
78             $result[$obj['cn']]['GROUPS'][$type]=$object;
79           }
80         }
81       }
82     }
84     // Make results useable for the listing class.
85     $entries = array();
86     foreach($result as $entry){
87       $item=array('count' => count($entry) -1);
88       foreach($entry as $name => $value){
89         if($name != "GROUPS"){
90           $item[] = $name;
92           $item[$name] = $value ;       
93         }
94       }
95       $item['GROUPS'] = $entry['GROUPS'];
96       $entries[] = $item;
97     }
100     // Append opsi stuff ... 
101     if(class_available('opsi') && $base == get_ou("faiManagement", "faiBaseRDN").$config->current['BASE']){
102       $opsi = new opsi($config);
103       $objects = array();
104       if($opsi instanceof opsi && $opsi->enabled()){
105         $opsi_acl = $ui->get_permissions($base,"opsi/opsiProperties");
106         if(preg_match("/r/",$opsi_acl)){
107           $err = FALSE;
109           if(preg_match("/FAIstate=__NETBOOT__/", $filter)){
110             $n_pro = $opsi->get_netboot_products();
111             $err |= $opsi->is_error();
112             foreach($n_pro as $name => $data){
113               $entry = array(
114                   "cn" => $name,
115                   "description" => $data['DESC'],
116                   "type" => "opsi_netboot");
117               $objects[$name]['opsi_netboot'] = $entry;
118             }
119           }
120           if(preg_match("/FAIstate=__LOCALBOOT__/", $filter)){
121             $l_pro = $opsi->get_local_products();
122             $err |= $opsi->is_error();
123             foreach($l_pro as $name => $data){
124               $entry = array("cn" => $name,
125                   "description" => $data['DESC'],
126                   "type" => "opsi_local");
127               $objects[$name]["opsi_local"] = $entry;
128             }
129           }
130           if($err){
131             msg_dialog::display(_("Error"),msgPool::siError($opsi->get_error()),ERROR_DIALOG);
132           }
133         }
134       }
136       $cn_filter = "";
137       if(preg_match("/^.*cn=([^)]*).*/",$filter)){
138         $cn_filter = trim(preg_replace("/^.*cn=([^)]*).*/","\\1",$filter),"*");
139       }
141       foreach($objects as $name => $data)
142       {
143         $data = array_pop($data);
144         if(!empty($cn_filter) && !preg_match("/".preg_quote($cn_filter,'/')."/",  $data['cn'])){
145           continue;
146         }
147         $item =array();
149         $item['objectClass']  = array('count' => 2, $data['type'],"FAKE_OC_OPSI");
150         $item[] = 'objectClass';
151         $item['cn']  = $data['cn'];
152         $item[] = 'cn';
153         $item['description']  = $data['description'];
154         $item[] = 'description';
155         $item['dn']  = $data['cn'];
156         $item[] = 'dn';
157         $item['TYPES']  = array($data['type']);
158         $item[] = 'TYPES';
159         $item['count'] = '5';
160         $entries[] = $item;  
162       }
163     }
165     return($entries);
166   }
168 ?>