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 = "ou=fai,ou=configs,ou=systems,".$_SESSION['CurrentMainBase'];
26 $this->ui = get_userinfo();
28 /* Create array with categories to be able to sort different types of objects */
29 $categories = array("FAIscript" => "faiScript",
30 "FAItemplate" => "faiTemplate",
31 "FAIhook" => "faiHook",
32 "FAIvariable" => "faiVariable",
33 "FAIpartitionTable" => "faiPartitionTable",
34 "FAIpackageList" => "faiPackageList");
36 /* Read out all objects from fai tree */
37 $ldap= $this->config->get_ldap_link();
38 $ldap->cd($base);
39 $ldap->search("(| (objectClass=FAIscript)(objectClass=FAItemplate)(objectClass=FAIhook)(objectClass=FAIvariable)
40 (objectClass=FAIpartitionTable)(objectClass=FAIpackageList))",array("*"));
42 $sort=array();
43 while($attrs = $ldap->fetch()){
45 /* Only use objects which have cn set */
46 if((isset($attrs['cn'][0]))&&(!in_array($attrs['cn'][0],$used))){
47 foreach($categories as $cat => $acl){
48 if(in_array($cat,$attrs['objectClass'])){
50 $acl = $this->ui->get_permissions($attrs['dn'],"fai/".$acl);
52 /* Append different types of objects */
53 $this->FAIAllclasses[$attrs['cn'][0]]['objects'][$cat]=$cat;
55 if(!isset($this->FAIAllclasses[$attrs['cn'][0]]['acl'])){
56 $this->FAIAllclasses[$attrs['cn'][0]]['acl']="";
57 }
58 $this->FAIAllclasses[$attrs['cn'][0]]['acl'].=$acl;
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 }
70 $tmp = array();
71 ksort($sort);
72 foreach($sort as $name){
73 $tmp[$name] =$this->FAIAllclasses[$name];
74 }
75 $this->FAIAllclasses = array();
76 $this->FAIAllclasses = $tmp;
78 /* If no search filter is set, create one */
79 if (!is_global("SUBfaifilter")){
80 $SUBfaifilter= array("base" => "ou=fai,ou=configs,ou=systems,".$_SESSION['CurrentMainBase'], "Sregex" => "*");
81 $SUBfaifilter['SShowTemplates'] = true;
82 $SUBfaifilter['SShowScripts'] = true;
83 $SUBfaifilter['SShowHooks'] = true;
84 $SUBfaifilter['SShowVariables'] = true;
85 $SUBfaifilter['SShowPackages'] = true;
86 $SUBfaifilter['SShowPartitions']= true;
87 register_global("SUBfaifilter", $SUBfaifilter);
88 }
89 }
91 function execute()
92 {
93 /* Call parent execute */
94 plugin::execute();
96 /* Fill templating stuff */
97 $smarty = get_smarty();
98 $display = "";
100 $SUBfaifilter = $_SESSION['SUBfaifilter'];
102 /* If someone used the apply button, update searchfilter */
103 if(isset($_POST['Sregex'])){
104 foreach($SUBfaifilter as $key => $val){
105 if(!isset($_POST[$key])){
106 $SUBfaifilter[$key] = false;
107 }else{
108 $SUBfaifilter[$key] =$_POST[$key];
109 }
110 }
111 $SUBfaifilter['Sregex']= $_POST['Sregex'];
112 if(!strstr($SUBfaifilter['Sregex'],"*")){
113 $SUBfaifilter['Sregex'] = $SUBfaifilter['Sregex']."*";
114 }
115 }
117 /* Save current searchfilter in session*/
118 $_SESSION['SUBfaifilter']= $SUBfaifilter;
120 /* Check if we used a checkboxe from the list, to select dselect an entry */
121 foreach($_POST as $name => $value){
122 foreach($this->FAIAllclasses as $class => $obj){
123 $bclass = base64_encode($class);
124 if(isset($_POST["ON_PAGE_".$bclass])){
125 if(isset($_POST['USE_'.$bclass])){
126 $this->FAIAllclasses[$class]['status']=true;
127 }else{
128 $this->FAIAllclasses[$class]['status']=false;
129 }
130 }
131 }
132 }
134 /* Create different picture for each object type */
135 $objTypes['FAIhook'] = "<img src='images/fai_hook.png' title='"._("Hook bundle")."' alt=''> ";
136 $objTypes['FAItemplate'] = "<img src='images/fai_template.png' title='"._("Template bundle")."' alt=''> ";
137 $objTypes['FAIscript'] = "<img src='images/fai_script.png' title='"._("Script bundle")."' alt=''> ";
138 $objTypes['FAIvariable'] = "<img src='images/fai_variable.png' title='"._("Variable bundle")."' alt=''> ";
139 $objTypes['FAIpackageList'] = "<img src='images/fai_packages.png' title='"._("Package bundle")."' alt=''> ";
140 $objTypes['FAIpartitionTable'] = "<img src='images/fai_partitionTable.png' title='"._("Partition table")."' alt=''> ";
142 /* Magic quotes GPC, escapes every ' " \, to solve some security risks
143 * If we post the escaped strings they will be escaped again
144 */
145 foreach($this->attributes as $attrs){
146 if(get_magic_quotes_gpc()){
147 $smarty->assign($attrs,stripslashes($this->$attrs));
148 }else{
149 $smarty->assign($attrs,($this->$attrs));
150 }
151 }
153 /* Assign all filter attributes to smarty */
154 foreach($SUBfaifilter as $key => $val){
155 if(($key != "base")&&($key != "Sregex")){
156 if($val){
157 $smarty->assign($key."CHK", " checked ");
158 }else{
159 $smarty->assign($key."CHK", "");
160 }
161 }else{
162 $smarty->assign($key,$val);
163 }
164 }
166 /* Create a divlist to display all available class names with the depending object types */
167 $divlist = new divlist("ProfileEntry");
168 $divlist->SetPluginMode();
169 $divlist->SetSummary(_("This list displays all assigned class names for this profile."));
170 $divlist->SetEntriesPerPage(0);
171 $divlist->SetHeader(array(array("string"=> _("Class name")),
172 array("string"=> _("Objects"),"attach"=>"style='border-right:0px;'")));
174 /* Action button allows us to delete an entry */
175 $action = "<input type='hidden' name='ON_PAGE_%KEY%' value='1'>
176 <input type='checkbox' name='USE_%KEY%' value='%KEY%' onClick='document.mainform.submit();' %CHECK%>";
178 /* Check every single class name to match the current search filter */
179 foreach($this->FAIAllclasses as $usedClass => $classes){
181 /* Skip those entries that we are not allowed to read. */
182 if(!preg_match("/r/",$classes['acl'])){
183 continue;
184 }
186 $fi = str_replace("*",".*",$SUBfaifilter['Sregex']);
188 $abort = true;
189 if(!preg_match("/".$fi."/",$usedClass)){
190 $abort = false;
191 }
192 if((isset($classes['objects']['FAIscript']))&&($SUBfaifilter['SShowScripts'])){
193 $abort = false;
194 }
195 if((isset($classes['objects']['FAItemplate']))&&($SUBfaifilter['SShowTemplates'])){
196 $abort = false;
197 }
198 if((isset($classes['objects']['FAIhook']))&&($SUBfaifilter['SShowHooks'])){
199 $abort = false;
200 }
201 if((isset($classes['objects']['FAIvariable']))&&($SUBfaifilter['SShowVariables'])){
202 $abort = false;
203 }
204 if((isset($classes['objects']['FAIpartitionTable']))&&($SUBfaifilter['SShowPartitions'])){
205 $abort = false;
206 }
207 if((isset($classes['objects']['FAIpackageList']))&&($SUBfaifilter['SShowPackages'])){
208 $abort = false;
209 }
211 if(!$abort){
212 $str = "";
213 foreach($classes['objects'] as $class => $obj){
214 $str.= $objTypes[$obj];
215 }
217 /* Is this entry selected */
218 if($classes['status']==true){
219 $action_check = preg_replace("/%CHECK%/"," checked ",$action);
220 }else{
221 $action_check = preg_replace("/%CHECK%/","",$action);
222 }
224 /* Append to list */
225 $field1 = array("string"=> str_replace("%KEY%",base64_encode($usedClass),$action_check).$usedClass,"attach"=>"");
226 $field2 = array("string"=> $str,"attach"=>"style='border-right:0px;'");
227 $divlist->AddEntry(array($field1,$field2));
228 }
229 }
231 $smarty->assign("faihead" , "");
232 $smarty->assign("failist" , $divlist->DrawList());
233 $smarty->assign("infoimage" , get_template_path('images/info_small.png'));
234 $smarty->assign("launchimage" , get_template_path('images/small_filter.png'));
235 $smarty->assign("alphabet" , generate_alphabet());
236 $smarty->assign("apply" , apply_filter(TRUE));
237 $smarty->assign("search_image" , get_template_path('images/search.png'));
239 $display.= $smarty->fetch(get_template_path('faiProfileEntry.tpl', TRUE));
240 return($display);
241 }
243 /* Save data to object */
244 function save_object()
245 {
246 }
248 /* Check supplied data */
249 function check()
250 {
251 /* Call common method to give check the hook */
252 $message= plugin::check();
254 return ($message);
255 }
257 function save()
258 {
259 $tmp = array();
260 foreach($this->FAIAllclasses as $class => $obj){
261 if($obj['status']==true){
262 $tmp[$class]=$class;
263 }
264 }
265 return($tmp);
266 }
267 }
268 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
269 ?>