1 <?php
3 class faiProfileEntry extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary= "Manage server basic objects";
7 var $cli_description= "Some longer text\nfor help";
8 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10 /* attribute list for save action */
11 var $ignore_account= TRUE;
12 var $attributes = array();
13 var $objectclasses= array();
15 /* Array with available class names */
16 var $FAIAllclasses = array();
17 var $ui;
19 function faiProfileEntry (&$config, $dn= NULL,$used=array(),$objects=false)
20 {
21 plugin::plugin ($config, $dn);
23 /* Search only in fai tree */
24 $base = get_ou('faiou').$_SESSION['CurrentMainBase'];
25 if($_SESSION['faifilter']['branch']!="main"){
26 $base = $_SESSION['faifilter']['branch'];
27 }
29 $this->ui = get_userinfo();
31 $filter = "(|(objectClass=FAIscript)(objectClass=FAItemplate)(objectClass=FAIhook)".
32 "(objectClass=FAIvariable)(objectClass=FAIpartitionTable)(objectClass=FAIpackageList))";
34 $FAI_objects = get_all_objects_for_given_base($base,$filter,true);
36 /* Create array with categories to be able to sort different types of objects */
37 $categories = array("FAIscript" => "faiScript",
38 "FAItemplate" => "faiTemplate",
39 "FAIhook" => "faiHook",
40 "FAIvariable" => "faiVariable",
41 "FAIpartitionTable" => "faiPartitionTable",
42 "FAIpackageList" => "faiPackageList");
44 /* Read out all objects from fai tree */
45 $ldap= $this->config->get_ldap_link();
46 $ldap->cd($base);
47 $sort=array();
48 foreach($FAI_objects as $obj){
50 $ldap->cat($obj['dn']);
51 $attrs = $ldap->fetch();
53 /* Only use objects which have cn set */
54 if((isset($attrs['cn'][0]))&&(!in_array($attrs['cn'][0],$used))){
55 foreach($categories as $cat => $acl){
56 if(in_array($cat,$attrs['objectClass'])){
58 $acl = $this->ui->get_permissions($attrs['dn'],"fai/".$acl);
60 /* Append different types of objects */
61 $this->FAIAllclasses[$attrs['cn'][0]]['objects'][$cat]=$cat;
63 if(!isset($this->FAIAllclasses[$attrs['cn'][0]]['acl'])){
64 $this->FAIAllclasses[$attrs['cn'][0]]['acl']="";
65 }
66 $this->FAIAllclasses[$attrs['cn'][0]]['acl'].=$acl;
68 /* Set selected status to false */
69 $this->FAIAllclasses[$attrs['cn'][0]]['status']=false;
71 $sort[strtolower($attrs['cn'][0])] = $attrs['cn'][0];
72 }
73 }
74 }
75 }
78 $tmp = array();
79 ksort($sort);
80 foreach($sort as $name){
81 $tmp[$name] =$this->FAIAllclasses[$name];
82 }
83 $this->FAIAllclasses = array();
84 $this->FAIAllclasses = $tmp;
86 /* If no search filter is set, create one */
87 if (!is_global("SUBfaifilter")){
88 $SUBfaifilter= array("base" => get_ou('faiou').$_SESSION['CurrentMainBase'], "Sregex" => "*");
89 $SUBfaifilter['SShowTemplates'] = true;
90 $SUBfaifilter['SShowScripts'] = true;
91 $SUBfaifilter['SShowHooks'] = true;
92 $SUBfaifilter['SShowVariables'] = true;
93 $SUBfaifilter['SShowPackages'] = true;
94 $SUBfaifilter['SShowPartitions']= true;
95 register_global("SUBfaifilter", $SUBfaifilter);
96 }
97 }
99 function execute()
100 {
101 /* Call parent execute */
102 plugin::execute();
104 /* Fill templating stuff */
105 $smarty = get_smarty();
106 $display = "";
108 $SUBfaifilter = session::get('SUBfaifilter');
110 /* If someone used the apply button, update searchfilter */
111 if(isset($_POST['Sregex'])){
112 foreach($SUBfaifilter as $key => $val){
113 if(!isset($_POST[$key])){
114 $SUBfaifilter[$key] = false;
115 }else{
116 $SUBfaifilter[$key] =$_POST[$key];
117 }
118 }
119 $SUBfaifilter['Sregex']= $_POST['Sregex'];
120 if(!strstr($SUBfaifilter['Sregex'],"*")){
121 $SUBfaifilter['Sregex'] = $SUBfaifilter['Sregex']."*";
122 }
123 }
125 /* Save current searchfilter in session*/
126 session::set('SUBfaifilter',$SUBfaifilter);
128 /* Check if we used a checkboxe from the list, to select dselect an entry */
129 foreach($_POST as $name => $value){
130 foreach($this->FAIAllclasses as $class => $obj){
131 $bclass = base64_encode($class);
132 if(isset($_POST["ON_PAGE_".$bclass])){
133 if(isset($_POST['USE_'.$bclass])){
134 $this->FAIAllclasses[$class]['status']=true;
135 }else{
136 $this->FAIAllclasses[$class]['status']=false;
137 }
138 }
139 }
140 }
142 /* Create different picture for each object type */
143 $objTypes['FAIhook'] = "<img src='images/fai_hook.png' title='"._("Hook bundle")."' alt=''> ";
144 $objTypes['FAItemplate'] = "<img src='images/fai_template.png' title='"._("Template bundle")."' alt=''> ";
145 $objTypes['FAIscript'] = "<img src='images/fai_script.png' title='"._("Script bundle")."' alt=''> ";
146 $objTypes['FAIvariable'] = "<img src='images/fai_variable.png' title='"._("Variable bundle")."' alt=''> ";
147 $objTypes['FAIpackageList'] = "<img src='images/fai_packages.png' title='"._("Package bundle")."' alt=''> ";
148 $objTypes['FAIpartitionTable'] = "<img src='images/fai_partitionTable.png' title='"._("Partition table")."' alt=''> ";
150 /* Magic quotes GPC, escapes every ' " \, to solve some security risks
151 * If we post the escaped strings they will be escaped again
152 */
153 foreach($this->attributes as $attrs){
154 if(get_magic_quotes_gpc()){
155 $smarty->assign($attrs,stripslashes($this->$attrs));
156 }else{
157 $smarty->assign($attrs,($this->$attrs));
158 }
159 }
161 /* Assign all filter attributes to smarty */
162 foreach($SUBfaifilter as $key => $val){
163 if(($key != "base")&&($key != "Sregex")){
164 if($val){
165 $smarty->assign($key."CHK", " checked ");
166 }else{
167 $smarty->assign($key."CHK", "");
168 }
169 }else{
170 $smarty->assign($key,$val);
171 }
172 }
174 /* Create a divlist to display all available class names with the depending object types */
175 $divlist = new divlist("ProfileEntry");
176 $divlist->SetPluginMode();
177 $divlist->SetSummary(_("This list displays all assigned class names for this profile."));
178 $divlist->SetEntriesPerPage(0);
179 $divlist->SetHeader(array(array("string"=> _("Class name")),
180 array("string"=> _("Objects"),"attach"=>"style='border-right:0px;'")));
182 /* Action button allows us to delete an entry */
183 $action = "<input type='hidden' name='ON_PAGE_%KEY%' value='1'>
184 <input type='checkbox' name='USE_%KEY%' value='%KEY%' onClick='document.mainform.submit();' %CHECK%>";
186 /* Check every single class name to match the current search filter */
187 foreach($this->FAIAllclasses as $usedClass => $classes){
189 /* Skip those entries that we are not allowed to read. */
190 if(!preg_match("/r/",$classes['acl'])){
191 continue;
192 }
194 $fi = str_replace("*",".*",$SUBfaifilter['Sregex']);
196 $abort = true;
197 if(!preg_match("/".$fi."/",$usedClass)){
198 $abort = false;
199 }
200 if((isset($classes['objects']['FAIscript']))&&($SUBfaifilter['SShowScripts'])){
201 $abort = false;
202 }
203 if((isset($classes['objects']['FAItemplate']))&&($SUBfaifilter['SShowTemplates'])){
204 $abort = false;
205 }
206 if((isset($classes['objects']['FAIhook']))&&($SUBfaifilter['SShowHooks'])){
207 $abort = false;
208 }
209 if((isset($classes['objects']['FAIvariable']))&&($SUBfaifilter['SShowVariables'])){
210 $abort = false;
211 }
212 if((isset($classes['objects']['FAIpartitionTable']))&&($SUBfaifilter['SShowPartitions'])){
213 $abort = false;
214 }
215 if((isset($classes['objects']['FAIpackageList']))&&($SUBfaifilter['SShowPackages'])){
216 $abort = false;
217 }
219 if(!$abort){
220 $str = "";
221 foreach($classes['objects'] as $class => $obj){
222 $str.= $objTypes[$obj];
223 }
225 /* Is this entry selected */
226 if($classes['status']==true){
227 $action_check = preg_replace("/%CHECK%/"," checked ",$action);
228 }else{
229 $action_check = preg_replace("/%CHECK%/","",$action);
230 }
232 /* Append to list */
233 $field1 = array("string"=> str_replace("%KEY%",base64_encode($usedClass),$action_check).$usedClass,"attach"=>"");
234 $field2 = array("string"=> $str,"attach"=>"style='border-right:0px;'");
235 $divlist->AddEntry(array($field1,$field2));
236 }
237 }
239 $smarty->assign("faihead" , "");
240 $smarty->assign("failist" , $divlist->DrawList());
241 $smarty->assign("infoimage" , get_template_path('images/info_small.png'));
242 $smarty->assign("launchimage" , get_template_path('images/small_filter.png'));
243 $smarty->assign("alphabet" , generate_alphabet());
244 $smarty->assign("apply" , apply_filter(TRUE));
245 $smarty->assign("search_image" , get_template_path('images/search.png'));
247 $display.= $smarty->fetch(get_template_path('faiProfileEntry.tpl', TRUE));
248 return($display);
249 }
251 /* Save data to object */
252 function save_object()
253 {
254 }
256 /* Check supplied data */
257 function check()
258 {
259 /* Call common method to give check the hook */
260 $message= plugin::check();
262 return ($message);
263 }
265 function save()
266 {
267 $tmp = array();
268 foreach($this->FAIAllclasses as $class => $obj){
269 if($obj['status']==true){
270 $tmp[$class]=$class;
271 }
272 }
273 return($tmp);
274 }
275 }
276 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
277 ?>