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('faiPartitionRDN') , "CHKBOX"=>"ShowPartitions" ,"ACL" => "faiPartitionTable"),
12 "FAIpackageList" => array("OU"=> get_ou('faiPackageRDN') , "CHKBOX"=>"ShowPackages" ,"ACL" => "faiPackage"),
13 "FAIscript" => array("OU"=> get_ou('faiScriptRDN') , "CHKBOX"=>"ShowScripts" ,"ACL" => "faiScript"),
14 "FAIvariable" => array("OU"=> get_ou('faiVariableRDN') , "CHKBOX"=>"ShowVariables" ,"ACL" => "faiVariable"),
15 "FAIhook" => array("OU"=> get_ou('faiHookRDN') , "CHKBOX"=>"ShowHooks" ,"ACL" => "faiHook"),
16 "FAIprofile" => array("OU"=> get_ou('faiProfileRDN') , "CHKBOX"=>"ShowProfiles" ,"ACL" => "faiProfile"),
17 "FAItemplate" => array("OU"=> get_ou('faiTemplateRDN') , "CHKBOX"=>"ShowTemplates" ,"ACL" => "faiTemplate"));
21 global $config;
22 $tmp = FAI::get_all_objects_for_given_base($base,$filter);
23 $ui = get_userinfo();
24 $ldap = $config->get_ldap_link();
25 $ldap->cd($config->current['BASE']);
27 $result = array();
28 foreach($tmp as $entry){
30 /* Get some more informations about the object */
31 $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
32 $object = $ldap->fetch();
34 /* Walk through possible types */
35 foreach($ObjectTypes as $type => $rest){
37 $acl = $ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
39 if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
41 /* Prepare object */
42 unset($object['objectClass']['count']);
43 if(!isset($object['description'][0])){
44 $object['description'][0]="";
45 }
47 $dn = preg_replace("/^[^,]*+,/","",$object['dn']);
49 /* Clean up object informations */
50 $obj = array();
51 $obj['cn'] = $object['cn'][0];
52 $obj['dn'] = $object['cn'][0];
53 $obj['acl'] = $acl;
54 $obj['class'] = $rest ['ACL'];
55 $obj['FAIstate'] = $entry['FAIstate'];
56 $obj['description'] = $object['description'][0];
57 $obj['objectClass'] = $object['objectClass'];
59 if(!preg_match("/freeze/i", $entry['FAIstate'])){
60 $obj['objectClass'][] = "FAKE_OC_IsBranch";
61 }
62 $object['FAIstate'] = $entry['FAIstate'];
64 $obj['TYPES'][] = $type;
65 $obj['GROUPS'][$type] = $object;
67 if(!isset($result[$obj['cn']])){
68 $result[$obj['cn']] = $obj;
69 }else{
70 $result[$obj['cn']]['TYPES'][]=$type;
71 $result[$obj['cn']]['GROUPS'][$type]=$object;
72 }
73 }
74 }
75 }
77 // Make results useable for the listing class.
78 $entries = array();
79 foreach($result as $entry){
80 $item=array('count' => count($entry) -1);
81 foreach($entry as $name => $value){
82 if($name != "GROUPS"){
83 $item[] = $name;
85 $item[$name] = $value ;
86 }
87 }
88 $item['GROUPS'] = $entry['GROUPS'];
89 $entries[] = $item;
90 }
93 // Append opsi stuff ...
94 if(class_available('opsi') && $base == get_ou("faiBaseRDN").$config->current['BASE']){
95 $opsi = new opsi($config);
96 $objects = array();
97 if($opsi instanceof opsi && $opsi->enabled()){
98 $opsi_acl = $ui->get_permissions($base,"opsi/opsiProperties");
99 if(preg_match("/r/",$opsi_acl)){
100 $err = FALSE;
102 if(preg_match("/FAIstate=__NETBOOT__/", $filter)){
103 $n_pro = $opsi->get_netboot_products();
104 $err |= $opsi->is_error();
105 foreach($n_pro as $name => $data){
106 $entry = array(
107 "cn" => $name,
108 "description" => $data['DESC'],
109 "type" => "opsi_netboot");
110 $objects[$name]['opsi_netboot'] = $entry;
111 }
112 }
113 if(preg_match("/FAIstate=__LOCALBOOT__/", $filter)){
114 $l_pro = $opsi->get_local_products();
115 $err |= $opsi->is_error();
116 foreach($l_pro as $name => $data){
117 $entry = array("cn" => $name,
118 "description" => $data['DESC'],
119 "type" => "opsi_local");
120 $objects[$name]["opsi_local"] = $entry;
121 }
122 }
123 if($err){
124 msg_dialog::display(_("Error"),msgPool::siError($opsi->get_error()),ERROR_DIALOG);
125 }
126 }
127 }
129 $cn_filter = "";
130 if(preg_match("/^.*cn=([^)]*).*/",$filter)){
131 $cn_filter = trim(preg_replace("/^.*cn=([^)]*).*/","\\1",$filter),"*");
132 }
134 foreach($objects as $name => $data)
135 {
136 $data = array_pop($data);
137 if(!empty($cn_filter) && !preg_match("/".preg_quote($cn_filter,'/')."/", $data['cn'])){
138 continue;
139 }
140 $item =array();
142 // FAKE_OC_IsBranch allows us to delete this entry (indicates NOT freezed state)
143 $item['objectClass'] = array('count' => 2, $data['type'], "FAKE_OC_IsBranch");
144 $item[] = 'objectClass';
145 $item['cn'] = $data['cn'];
146 $item[] = 'cn';
147 $item['description'] = $data['description'];
148 $item[] = 'description';
149 $item['dn'] = $data['cn'];
150 $item[] = 'dn';
151 $item['TYPES'] = array($data['type']);
152 $item[] = 'TYPES';
153 $item['count'] = '5';
154 $entries[] = $item;
156 }
157 }
159 return($entries);
160 }
161 }
162 ?>