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 $opsi = new opsi($config);
96 if($opsi instanceof opsi && $opsi->enabled()){
97 $opsi_acl = $ui->get_permissions($base,"opsi/opsiProperties");
98 if(preg_match("/r/",$opsi_acl)){
99 $err = FALSE;
100 $n_pro = $opsi->get_netboot_products();
101 $err |= $opsi->is_error();
102 foreach($n_pro as $name => $data){
103 $entry = array(
104 "cn" => $name,
105 "description" => $data['DESC'],
106 "type" => "opsi_netboot");
107 $objects[$name]['opsi_netboot'] = $entry;
108 }
109 $l_pro = $opsi->get_local_products();
110 $err |= $opsi->is_error();
111 foreach($l_pro as $name => $data){
112 $entry = array("cn" => $name,
113 "description" => $data['DESC'],
114 "type" => "opsi_local");
115 $objects[$name]["opsi_local"] = $entry;
116 }
117 if($err){
118 msg_dialog::display(_("Error"),msgPool::siError($opsi->get_error()),ERROR_DIALOG);
119 }
120 }
121 }
123 foreach($objects as $name => $data)
124 {
125 $data = array_pop($data);
126 $item =array();
128 // FAKE_OC_IsBranch allows us to delete this entry (indicates NOT freezed state)
129 $item['objectClass'] = array('count' => 2, $data['type'], "FAKE_OC_IsBranch");
130 $item[] = 'objectClass';
131 $item['cn'] = $data['cn'];
132 $item[] = 'cn';
133 $item['description'] = $data['description'];
134 $item[] = 'description';
135 $item['dn'] = $data['cn'];
136 $item[] = 'dn';
137 $item['TYPES'] = array($data['type']);
138 $item[] = 'TYPES';
139 $item['count'] = '5';
140 $entries[] = $item;
142 }
144 return($entries);
145 }
146 }
147 ?>