80eccee5b8051cda64da86b2deeb74ccd836af08
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();
18 function faiProfileEntry ($config, $dn= NULL,$used=array(),$objects=false)
19 {
20 plugin::plugin ($config, $dn);
22 /* Search only in fai tree */
23 $base = "ou=fai,ou=configs,ou=systems,".$_SESSION['faifilter']['base'];
25 /* Create array with categories to be able to sort different types of objects */
26 $categories = array("FAIscript","FAItemplate","FAIhook","FAIvariable","FAIpartitionTable","FAIpackageList");
28 /* Read out all objects from fai tree */
29 $ldap= $this->config->get_ldap_link();
30 $ldap->cd($base);
31 $ldap->search("(| (objectClass=FAIscript)(objectClass=FAItemplate)(objectClass=FAIhook)(objectClass=FAIvariable)
32 (objectClass=FAIpartitionTable)(objectClass=FAIpackageList))",array("*"));
34 $sort=array();
35 while($attrs = $ldap->fetch()){
37 /* Only use objects which have cn set */
38 if((isset($attrs['cn'][0]))&&(!in_array($attrs['cn'][0],$used))){
39 foreach($categories as $cat){
40 if(in_array($cat,$attrs['objectClass'])){
42 /* Append different types of objects */
43 $this->FAIAllclasses[$attrs['cn'][0]]['objects'][$cat]=$cat;
45 /* Set selected status to false */
46 $this->FAIAllclasses[$attrs['cn'][0]]['status']=false;
48 $sort[strtolower($attrs['cn'][0])] = $attrs['cn'][0];
49 }
50 }
51 }
52 }
53 $tmp = array();
54 ksort($sort);
55 foreach($sort as $name){
56 $tmp[$name] =$this->FAIAllclasses[$name];
57 }
58 $this->FAIAllclasses = array();
59 $this->FAIAllclasses = $tmp;
62 /* If no search filter is set, create one */
63 if (!is_global("SUBfaifilter")){
64 $SUBfaifilter= array("base" => "ou=fai,ou=configs,ou=systems,".$base, "Sregex" => "*");
65 $SUBfaifilter['SShowTemplates'] = true;
66 $SUBfaifilter['SShowScripts'] = true;
67 $SUBfaifilter['SShowHooks'] = true;
68 $SUBfaifilter['SShowVariables'] = true;
69 $SUBfaifilter['SShowPackages'] = true;
70 $SUBfaifilter['SShowPartitions']= true;
71 register_global("SUBfaifilter", $SUBfaifilter);
72 }
73 }
75 function execute()
76 {
77 /* Call parent execute */
78 plugin::execute();
80 /* Fill templating stuff */
81 $smarty = get_smarty();
82 $display = "";
84 $SUBfaifilter = $_SESSION['SUBfaifilter'];
86 /* If someone used the apply button, update searchfilter */
87 if(isset($_POST['Sregex'])){
88 foreach($SUBfaifilter as $key => $val){
89 if(!isset($_POST[$key])){
90 $SUBfaifilter[$key] = false;
91 }else{
92 $SUBfaifilter[$key] =$_POST[$key];
93 }
94 }
95 $SUBfaifilter['Sregex']= $_POST['Sregex'];
96 if(!strstr($SUBfaifilter['Sregex'],"*")){
97 $SUBfaifilter['Sregex'] = $SUBfaifilter['Sregex']."*";
98 }
99 }
101 /* Save current searchfilter in session*/
102 $_SESSION['SUBfaifilter']= $SUBfaifilter;
104 /* Check if we used a checkboxe from the list, to select dselect an entry */
105 foreach($_POST as $name => $value){
106 foreach($this->FAIAllclasses as $class => $obj){
107 if(isset($_POST["ON_PAGE_".$class])){
108 if(isset($_POST['USE_'.$class])){
109 $this->FAIAllclasses[$class]['status']=true;
110 }else{
111 $this->FAIAllclasses[$class]['status']=false;
112 }
113 }
114 }
115 }
117 /* Create different picture for each object type */
118 $objTypes['FAIhook'] = "<img src='images/fai_hook.png' title='"._("Hook bundle")."' alt=''> ";
119 $objTypes['FAItemplate'] = "<img src='images/fai_template.png' title='"._("Template bundle")."' alt=''> ";
120 $objTypes['FAIscript'] = "<img src='images/fai_script.png' title='"._("Script bundle")."' alt=''> ";
121 $objTypes['FAIvariable'] = "<img src='images/fai_variable.png' title='"._("Variable bundle")."' alt=''> ";
122 $objTypes['FAIpackageList'] = "<img src='images/fai_packages.png' title='"._("Package bundle")."' alt=''> ";
123 $objTypes['FAIpartitionTable'] = "<img src='images/fai_partitionTable.png' title='"._("Partition table")."' alt=''> ";
125 /* Magic quotes GPC, escapes every ' " \, to solve some security risks
126 * If we post the escaped strings they will be escaped again
127 */
128 foreach($this->attributes as $attrs){
129 if(get_magic_quotes_gpc()){
130 $smarty->assign($attrs,stripslashes($this->$attrs));
131 }else{
132 $smarty->assign($attrs,($this->$attrs));
133 }
134 }
136 /* Assign all filter attributes to smarty */
137 foreach($SUBfaifilter as $key => $val){
138 if(($key != "base")&&($key != "Sregex")){
139 if($val){
140 $smarty->assign($key."CHK", " checked ");
141 }else{
142 $smarty->assign($key."CHK", "");
143 }
144 }else{
145 $smarty->assign($key,$val);
146 }
147 }
149 /* Create a divlist to display all available class names with the depending object types */
150 $divlist = new divlist("ProfileEntry");
151 $divlist->SetSummary(_("This list displays all assigned class names for this profile."));
152 $divlist->SetEntriesPerPage(0);
153 $divlist->SetHeader(array(array("string"=> _("Class name")),
154 array("string"=> _("Objects"),"attach"=>"style='border-right:0px;'")));
156 /* Action button allows us to delete an entry */
157 $action = "<input type='hidden' name='ON_PAGE_%KEY%' value='1'>
158 <input type='checkbox' name='USE_%KEY%' value='%KEY%' onClick='document.mainform.submit();' %CHECK%>";
160 /* Check every single class name to match the current search filter */
161 foreach($this->FAIAllclasses as $usedClass => $classes){
163 $fi = str_replace("*",".*",$SUBfaifilter['Sregex']);
165 $abort = true;
166 if(!preg_match("/".$fi."/",$usedClass)){
167 $abort = false;
168 }
169 if((isset($classes['objects']['FAIscript']))&&($SUBfaifilter['SShowScripts'])){
170 $abort = false;
171 }
172 if((isset($classes['objects']['FAItemplate']))&&($SUBfaifilter['SShowTemplates'])){
173 $abort = false;
174 }
175 if((isset($classes['objects']['FAIhook']))&&($SUBfaifilter['SShowHooks'])){
176 $abort = false;
177 }
178 if((isset($classes['objects']['FAIvariable']))&&($SUBfaifilter['SShowVariables'])){
179 $abort = false;
180 }
181 if((isset($classes['objects']['FAIpartitionTable']))&&($SUBfaifilter['SShowPartitions'])){
182 $abort = false;
183 }
184 if((isset($classes['objects']['FAIpackageList']))&&($SUBfaifilter['SShowPackages'])){
185 $abort = false;
186 }
188 if(!$abort){
189 $str = "";
190 foreach($classes['objects'] as $class => $obj){
191 $str.= $objTypes[$obj];
192 }
194 /* Is this entry selected */
195 if($classes['status']==true){
196 $action_check = preg_replace("/%CHECK%/"," checked ",$action);
197 }else{
198 $action_check = preg_replace("/%CHECK%/","",$action);
199 }
201 /* Append to list */
202 $field1 = array("string"=> preg_replace("/%KEY%/",$usedClass,$action_check).$usedClass,"attach"=>"");
203 $field2 = array("string"=> $str,"attach"=>"style='border-right:0px;'");
204 $divlist->AddEntry(array($field1,$field2));
205 }
206 }
208 $smarty->assign("faihead" , "");
209 $smarty->assign("failist" , $divlist->DrawList());
210 $smarty->assign("infoimage" , get_template_path('images/info_small.png'));
211 $smarty->assign("launchimage" , get_template_path('images/small_filter.png'));
212 $smarty->assign("alphabet" , generate_alphabet());
213 $smarty->assign("apply" , apply_filter(TRUE));
214 $smarty->assign("search_image" , get_template_path('images/search.png'));
216 $display.= $smarty->fetch(get_template_path('faiProfileEntry.tpl', TRUE));
217 return($display);
218 }
220 /* Save data to object */
221 function save_object()
222 {
223 }
225 /* Check supplied data */
226 function check()
227 {
228 $message= array();
229 return ($message);
230 }
232 function save()
233 {
234 $tmp = array();
235 foreach($this->FAIAllclasses as $class => $obj){
236 if($obj['status']==true){
237 $tmp[$class]=$class;
238 }
239 }
240 return($tmp);
241 }
242 }
243 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
244 ?>