1 <?php
3 class faiProfileEntry extends plugin
4 {
5 /* attribute list for save action */
6 var $ignore_account= TRUE;
7 var $attributes = array();
8 var $objectclasses= array();
10 /* Array with available class names */
11 var $FAIAllclasses = array();
13 function faiProfileEntry ($config, $dn= NULL,$used=array(),$objects=false)
14 {
15 plugin::plugin ($config, $dn);
17 /* Search only in fai tree */
18 $ObjectTypes = array(
19 "FAIpartitionTable" => array("OU"=>"ou=disk," ),
20 "FAIpackageList" => array("OU"=>"ou=packages," ),
21 "FAIscript" => array("OU"=>"ou=scripts," ),
22 "FAIvariable" => array("OU"=>"ou=variables," ),
23 "FAIhook" => array("OU"=>"ou=hooks," ),
24 "FAIprofile" => array("OU"=>"ou=profiles," ),
25 "FAItemplate" => array("OU"=>"ou=templates," ));
27 $base= "ou=fai,ou=configs,ou=systems,".$_SESSION['CurrentMainBase'];
28 if($_SESSION['faifilter']['branch']!="main"){
29 $base = $_SESSION['faifilter']['branch'];
30 }
32 /* Get ldap connection */
33 $ldap= $this->config->get_ldap_link();
34 $ldap->cd($base);
36 /* Capture objects from given base */
37 $result = array();
38 foreach($ObjectTypes as $oc => $data){
39 $ou = $data['OU'].$base;
41 $ldap->ls("(objectClass=".$oc.")",$ou,array("cn","objectClass","dn"));
42 while($res = $ldap->fetch()){
43 $result[] = $res;
44 }
45 }
47 /* Create array with categories to be able to sort different types of objects */
48 $categories = array("FAIscript","FAItemplate","FAIhook","FAIvariable","FAIpartitionTable","FAIpackageList");
49 $sort = array();
50 foreach($result as $attrs){
52 /* Only use objects which have cn set */
53 if((isset($attrs['cn'][0]))&&(!in_array($attrs['cn'][0],$used))){
54 foreach($categories as $cat){
55 if(in_array($cat,$attrs['objectClass'])){
57 /* Append different types of objects */
58 $this->FAIAllclasses[$attrs['cn'][0]]['objects'][$cat]=$cat;
60 /* Set selected status to false */
61 $this->FAIAllclasses[$attrs['cn'][0]]['status']=false;
63 $sort[strtolower($attrs['cn'][0])] = $attrs['cn'][0];
64 }
65 }
66 }
67 }
68 $tmp = array();
69 ksort($sort);
70 foreach($sort as $name){
71 $tmp[$name] =$this->FAIAllclasses[$name];
72 }
73 $this->FAIAllclasses = array();
74 $this->FAIAllclasses = $tmp;
77 /* If no search filter is set, create one */
78 if (!is_global("SUBfaifilter")){
79 $SUBfaifilter= array("base" => "ou=fai,ou=configs,ou=systems,".$_SESSION['CurrentMainBase'], "Sregex" => "*");
80 $SUBfaifilter['SShowTemplates'] = true;
81 $SUBfaifilter['SShowScripts'] = true;
82 $SUBfaifilter['SShowHooks'] = true;
83 $SUBfaifilter['SShowVariables'] = true;
84 $SUBfaifilter['SShowPackages'] = true;
85 $SUBfaifilter['SShowPartitions']= true;
86 register_global("SUBfaifilter", $SUBfaifilter);
87 }
88 }
90 function execute()
91 {
92 /* Call parent execute */
93 plugin::execute();
95 /* Fill templating stuff */
96 $smarty = get_smarty();
97 $display = "";
99 $SUBfaifilter = $_SESSION['SUBfaifilter'];
101 /* If someone used the apply button, update searchfilter */
102 if(isset($_POST['Sregex'])){
103 foreach($SUBfaifilter as $key => $val){
104 if(!isset($_POST[$key])){
105 $SUBfaifilter[$key] = false;
106 }else{
107 $SUBfaifilter[$key] =$_POST[$key];
108 }
109 }
110 $SUBfaifilter['Sregex']= $_POST['Sregex'];
111 if(!strstr($SUBfaifilter['Sregex'],"*")){
112 $SUBfaifilter['Sregex'] = $SUBfaifilter['Sregex']."*";
113 }
114 }
116 /* Save current searchfilter in session*/
117 $_SESSION['SUBfaifilter']= $SUBfaifilter;
119 /* Check if we used a checkboxe from the list, to select dselect an entry */
120 foreach($_POST as $name => $value){
121 foreach($this->FAIAllclasses as $class => $obj){
122 $bclass = base64_encode($class);
123 if(isset($_POST["ON_PAGE_".$bclass])){
124 if(isset($_POST['USE_'.$bclass])){
125 $this->FAIAllclasses[$class]['status']=true;
126 }else{
127 $this->FAIAllclasses[$class]['status']=false;
128 }
129 }
130 }
131 }
133 /* Create different picture for each object type */
134 $objTypes['FAIhook'] = "<img src='images/fai_hook.png' title='"._("Hook bundle")."' alt=''> ";
135 $objTypes['FAItemplate'] = "<img src='images/fai_template.png' title='"._("Template bundle")."' alt=''> ";
136 $objTypes['FAIscript'] = "<img src='images/fai_script.png' title='"._("Script bundle")."' alt=''> ";
137 $objTypes['FAIvariable'] = "<img src='images/fai_variable.png' title='"._("Variable bundle")."' alt=''> ";
138 $objTypes['FAIpackageList'] = "<img src='images/fai_packages.png' title='"._("Package bundle")."' alt=''> ";
139 $objTypes['FAIpartitionTable'] = "<img src='images/fai_partitionTable.png' title='"._("Partition table")."' alt=''> ";
141 /* Magic quotes GPC, escapes every ' " \, to solve some security risks
142 * If we post the escaped strings they will be escaped again
143 */
144 foreach($this->attributes as $attrs){
145 if(get_magic_quotes_gpc()){
146 $smarty->assign($attrs,stripslashes($this->$attrs));
147 }else{
148 $smarty->assign($attrs,($this->$attrs));
149 }
150 }
152 /* Assign all filter attributes to smarty */
153 foreach($SUBfaifilter as $key => $val){
154 if(($key != "base")&&($key != "Sregex")){
155 if($val){
156 $smarty->assign($key."CHK", " checked ");
157 }else{
158 $smarty->assign($key."CHK", "");
159 }
160 }else{
161 $smarty->assign($key,$val);
162 }
163 }
165 /* Create a divlist to display all available class names with the depending object types */
166 $divlist = new divlist("ProfileEntry");
167 $divlist->SetSummary(_("This list displays all assigned class names for this profile."));
168 $divlist->SetEntriesPerPage(0);
169 $divlist->SetHeader(array(array("string"=> _("Class name")),
170 array("string"=> _("Objects"),"attach"=>"style='border-right:0px;'")));
172 /* Action button allows us to delete an entry */
173 $action = "<input type='hidden' name='ON_PAGE_%KEY%' value='1'>
174 <input type='checkbox' name='USE_%KEY%' value='%KEY%' onClick='document.mainform.submit();' %CHECK%>";
176 /* Check every single class name to match the current search filter */
177 foreach($this->FAIAllclasses as $usedClass => $classes){
179 $fi = str_replace("*",".*",$SUBfaifilter['Sregex']);
181 $abort = true;
182 if(!preg_match("/".$fi."/",$usedClass)){
183 $abort = false;
184 }
185 if((isset($classes['objects']['FAIscript']))&&($SUBfaifilter['SShowScripts'])){
186 $abort = false;
187 }
188 if((isset($classes['objects']['FAItemplate']))&&($SUBfaifilter['SShowTemplates'])){
189 $abort = false;
190 }
191 if((isset($classes['objects']['FAIhook']))&&($SUBfaifilter['SShowHooks'])){
192 $abort = false;
193 }
194 if((isset($classes['objects']['FAIvariable']))&&($SUBfaifilter['SShowVariables'])){
195 $abort = false;
196 }
197 if((isset($classes['objects']['FAIpartitionTable']))&&($SUBfaifilter['SShowPartitions'])){
198 $abort = false;
199 }
200 if((isset($classes['objects']['FAIpackageList']))&&($SUBfaifilter['SShowPackages'])){
201 $abort = false;
202 }
204 if(!$abort){
205 $str = "";
206 foreach($classes['objects'] as $class => $obj){
207 $str.= $objTypes[$obj];
208 }
210 /* Is this entry selected */
211 if($classes['status']==true){
212 $action_check = preg_replace("/%CHECK%/"," checked ",$action);
213 }else{
214 $action_check = preg_replace("/%CHECK%/","",$action);
215 }
217 /* Append to list */
218 $field1 = array("string"=> str_replace("%KEY%",base64_encode($usedClass),$action_check).$usedClass,"attach"=>"");
219 $field2 = array("string"=> $str,"attach"=>"style='border-right:0px;'");
220 $divlist->AddEntry(array($field1,$field2));
221 }
222 }
224 $smarty->assign("faihead" , "");
225 $smarty->assign("failist" , $divlist->DrawList());
226 $smarty->assign("infoimage" , get_template_path('images/info_small.png'));
227 $smarty->assign("launchimage" , get_template_path('images/small_filter.png'));
228 $smarty->assign("alphabet" , generate_alphabet());
229 $smarty->assign("apply" , apply_filter(TRUE));
230 $smarty->assign("search_image" , get_template_path('images/search.png'));
232 $display.= $smarty->fetch(get_template_path('faiProfileEntry.tpl', TRUE));
233 return($display);
234 }
236 /* Save data to object */
237 function save_object()
238 {
239 }
241 /* Check supplied data */
242 function check()
243 {
244 /* Call common method to give check the hook */
245 $message= plugin::check();
247 return ($message);
248 }
250 function save()
251 {
252 $tmp = array();
253 foreach($this->FAIAllclasses as $class => $obj){
254 if($obj['status']==true){
255 $tmp[$class]=$class;
256 }
257 }
258 return($tmp);
259 }
260 }
261 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
262 ?>