3729141b80d197f34de51cbec317eb935df0a277
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['CurrentMainBase'];
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,".$_SESSION['CurrentMainBase'], "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 $bclass = base64_encode($class);
108 if(isset($_POST["ON_PAGE_".$bclass])){
109 if(isset($_POST['USE_'.$bclass])){
110 $this->FAIAllclasses[$class]['status']=true;
111 }else{
112 $this->FAIAllclasses[$class]['status']=false;
113 }
114 }
115 }
116 }
118 /* Create different picture for each object type */
119 $objTypes['FAIhook'] = "<img src='images/fai_hook.png' title='"._("Hook bundle")."' alt=''> ";
120 $objTypes['FAItemplate'] = "<img src='images/fai_template.png' title='"._("Template bundle")."' alt=''> ";
121 $objTypes['FAIscript'] = "<img src='images/fai_script.png' title='"._("Script bundle")."' alt=''> ";
122 $objTypes['FAIvariable'] = "<img src='images/fai_variable.png' title='"._("Variable bundle")."' alt=''> ";
123 $objTypes['FAIpackageList'] = "<img src='images/fai_packages.png' title='"._("Package bundle")."' alt=''> ";
124 $objTypes['FAIpartitionTable'] = "<img src='images/fai_partitionTable.png' title='"._("Partition table")."' alt=''> ";
126 /* Magic quotes GPC, escapes every ' " \, to solve some security risks
127 * If we post the escaped strings they will be escaped again
128 */
129 foreach($this->attributes as $attrs){
130 if(get_magic_quotes_gpc()){
131 $smarty->assign($attrs,stripslashes($this->$attrs));
132 }else{
133 $smarty->assign($attrs,($this->$attrs));
134 }
135 }
137 /* Assign all filter attributes to smarty */
138 foreach($SUBfaifilter as $key => $val){
139 if(($key != "base")&&($key != "Sregex")){
140 if($val){
141 $smarty->assign($key."CHK", " checked ");
142 }else{
143 $smarty->assign($key."CHK", "");
144 }
145 }else{
146 $smarty->assign($key,$val);
147 }
148 }
150 /* Create a divlist to display all available class names with the depending object types */
151 $divlist = new divlist("ProfileEntry");
152 $divlist->SetSummary(_("This list displays all assigned class names for this profile."));
153 $divlist->SetEntriesPerPage(0);
154 $divlist->SetHeader(array(array("string"=> _("Class name")),
155 array("string"=> _("Objects"),"attach"=>"style='border-right:0px;'")));
157 /* Action button allows us to delete an entry */
158 $action = "<input type='hidden' name='ON_PAGE_%KEY%' value='1'>
159 <input type='checkbox' name='USE_%KEY%' value='%KEY%' onClick='document.mainform.submit();' %CHECK%>";
161 /* Check every single class name to match the current search filter */
162 foreach($this->FAIAllclasses as $usedClass => $classes){
164 $fi = str_replace("*",".*",$SUBfaifilter['Sregex']);
166 $abort = true;
167 if(!preg_match("/".$fi."/",$usedClass)){
168 $abort = false;
169 }
170 if((isset($classes['objects']['FAIscript']))&&($SUBfaifilter['SShowScripts'])){
171 $abort = false;
172 }
173 if((isset($classes['objects']['FAItemplate']))&&($SUBfaifilter['SShowTemplates'])){
174 $abort = false;
175 }
176 if((isset($classes['objects']['FAIhook']))&&($SUBfaifilter['SShowHooks'])){
177 $abort = false;
178 }
179 if((isset($classes['objects']['FAIvariable']))&&($SUBfaifilter['SShowVariables'])){
180 $abort = false;
181 }
182 if((isset($classes['objects']['FAIpartitionTable']))&&($SUBfaifilter['SShowPartitions'])){
183 $abort = false;
184 }
185 if((isset($classes['objects']['FAIpackageList']))&&($SUBfaifilter['SShowPackages'])){
186 $abort = false;
187 }
189 if(!$abort){
190 $str = "";
191 foreach($classes['objects'] as $class => $obj){
192 $str.= $objTypes[$obj];
193 }
195 /* Is this entry selected */
196 if($classes['status']==true){
197 $action_check = preg_replace("/%CHECK%/"," checked ",$action);
198 }else{
199 $action_check = preg_replace("/%CHECK%/","",$action);
200 }
202 /* Append to list */
203 $field1 = array("string"=> str_replace("%KEY%",base64_encode($usedClass),$action_check).$usedClass,"attach"=>"");
204 $field2 = array("string"=> $str,"attach"=>"style='border-right:0px;'");
205 $divlist->AddEntry(array($field1,$field2));
206 }
207 }
209 $smarty->assign("faihead" , "");
210 $smarty->assign("failist" , $divlist->DrawList());
211 $smarty->assign("infoimage" , get_template_path('images/info_small.png'));
212 $smarty->assign("launchimage" , get_template_path('images/small_filter.png'));
213 $smarty->assign("alphabet" , generate_alphabet());
214 $smarty->assign("apply" , apply_filter(TRUE));
215 $smarty->assign("search_image" , get_template_path('images/search.png'));
217 $display.= $smarty->fetch(get_template_path('faiProfileEntry.tpl', TRUE));
218 return($display);
219 }
221 /* Save data to object */
222 function save_object()
223 {
224 }
226 /* Check supplied data */
227 function check()
228 {
229 /* Call common method to give check the hook */
230 $message= plugin::check();
232 return ($message);
233 }
235 function save()
236 {
237 $tmp = array();
238 foreach($this->FAIAllclasses as $class => $obj){
239 if($obj['status']==true){
240 $tmp[$class]=$class;
241 }
242 }
243 return($tmp);
244 }
245 }
246 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
247 ?>