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->SetSummary(_("This list displays all assigned class names for this profile."));
169 $divlist->SetEntriesPerPage(0);
170 $divlist->SetHeader(array(array("string"=> _("Class name")),
171 array("string"=> _("Objects"),"attach"=>"style='border-right:0px;'")));
173 /* Action button allows us to delete an entry */
174 $action = "<input type='hidden' name='ON_PAGE_%KEY%' value='1'>
175 <input type='checkbox' name='USE_%KEY%' value='%KEY%' onClick='document.mainform.submit();' %CHECK%>";
177 /* Check every single class name to match the current search filter */
178 foreach($this->FAIAllclasses as $usedClass => $classes){
180 /* Skip those entries that we are not allowed to read. */
181 if(!preg_match("/r/",$classes['acl'])){
182 continue;
183 }
185 $fi = str_replace("*",".*",$SUBfaifilter['Sregex']);
187 $abort = true;
188 if(!preg_match("/".$fi."/",$usedClass)){
189 $abort = false;
190 }
191 if((isset($classes['objects']['FAIscript']))&&($SUBfaifilter['SShowScripts'])){
192 $abort = false;
193 }
194 if((isset($classes['objects']['FAItemplate']))&&($SUBfaifilter['SShowTemplates'])){
195 $abort = false;
196 }
197 if((isset($classes['objects']['FAIhook']))&&($SUBfaifilter['SShowHooks'])){
198 $abort = false;
199 }
200 if((isset($classes['objects']['FAIvariable']))&&($SUBfaifilter['SShowVariables'])){
201 $abort = false;
202 }
203 if((isset($classes['objects']['FAIpartitionTable']))&&($SUBfaifilter['SShowPartitions'])){
204 $abort = false;
205 }
206 if((isset($classes['objects']['FAIpackageList']))&&($SUBfaifilter['SShowPackages'])){
207 $abort = false;
208 }
210 if(!$abort){
211 $str = "";
212 foreach($classes['objects'] as $class => $obj){
213 $str.= $objTypes[$obj];
214 }
216 /* Is this entry selected */
217 if($classes['status']==true){
218 $action_check = preg_replace("/%CHECK%/"," checked ",$action);
219 }else{
220 $action_check = preg_replace("/%CHECK%/","",$action);
221 }
223 /* Append to list */
224 $field1 = array("string"=> str_replace("%KEY%",base64_encode($usedClass),$action_check).$usedClass,"attach"=>"");
225 $field2 = array("string"=> $str,"attach"=>"style='border-right:0px;'");
226 $divlist->AddEntry(array($field1,$field2));
227 }
228 }
230 $smarty->assign("faihead" , "");
231 $smarty->assign("failist" , $divlist->DrawList());
232 $smarty->assign("infoimage" , get_template_path('images/info_small.png'));
233 $smarty->assign("launchimage" , get_template_path('images/small_filter.png'));
234 $smarty->assign("alphabet" , generate_alphabet());
235 $smarty->assign("apply" , apply_filter(TRUE));
236 $smarty->assign("search_image" , get_template_path('images/search.png'));
238 $display.= $smarty->fetch(get_template_path('faiProfileEntry.tpl', TRUE));
239 return($display);
240 }
242 /* Save data to object */
243 function save_object()
244 {
245 }
247 /* Check supplied data */
248 function check()
249 {
250 /* Call common method to give check the hook */
251 $message= plugin::check();
253 return ($message);
254 }
256 function save()
257 {
258 $tmp = array();
259 foreach($this->FAIAllclasses as $class => $obj){
260 if($obj['status']==true){
261 $tmp[$class]=$class;
262 }
263 }
264 return($tmp);
265 }
266 }
267 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
268 ?>