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","FAIpackage");
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=FAIpackage))",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 /* Fill templating stuff */
78 $smarty = get_smarty();
79 $display = "";
81 $SUBfaifilter = $_SESSION['SUBfaifilter'];
83 /* If someone used the apply button, update searchfilter */
84 if(isset($_POST['Sregex'])){
85 foreach($SUBfaifilter as $key => $val){
86 if(!isset($_POST[$key])){
87 $SUBfaifilter[$key] = false;
88 }else{
89 $SUBfaifilter[$key] =$_POST[$key];
90 }
91 }
92 $SUBfaifilter['Sregex']= $_POST['Sregex'];
93 if(!strstr($SUBfaifilter['Sregex'],"*")){
94 $SUBfaifilter['Sregex'] = $SUBfaifilter['Sregex']."*";
95 }
96 }
98 /* Save current searchfilter in session*/
99 $_SESSION['SUBfaifilter']= $SUBfaifilter;
101 /* Check if we used a checkboxe from the list, to select dselect an entry */
102 foreach($_POST as $name => $value){
103 foreach($this->FAIAllclasses as $class => $obj){
104 if(isset($_POST["ON_PAGE_".$class])){
105 if(isset($_POST['USE_'.$class])){
106 $this->FAIAllclasses[$class]['status']=true;
107 }else{
108 $this->FAIAllclasses[$class]['status']=false;
109 }
110 }
111 }
112 }
114 /* Create different picture for each object type */
115 $objTypes['FAIhook'] = "<image src='images/fai_hook.png' title='"._("Hook bundle")."' alt=''> ";
116 $objTypes['FAItemplate'] = "<image src='images/fai_template.png' title='"._("Template bundle")."' alt=''> ";
117 $objTypes['FAIscript'] = "<image src='images/fai_script.png' title='"._("Script bundle")."' alt=''> ";
118 $objTypes['FAIvariable'] = "<image src='images/fai_variable.png' title='"._("Variable bundle")."' alt=''> ";
119 $objTypes['FAIpackage'] = "<image src='images/fai_packages.png' title='"._("Package bundle")."' alt=''> ";
120 $objTypes['FAIpartitionTable'] = "<image src='images/fai_partitionTable.png' title='"._("Partition table")."' alt=''> ";
122 /* Magic quotes GPC, escapes every ' " \, to solve some security risks
123 * If we post the escaped strings they will be escaped again
124 */
125 foreach($this->attributes as $attrs){
126 if(get_magic_quotes_gpc()){
127 $smarty->assign($attrs,stripslashes($this->$attrs));
128 }else{
129 $smarty->assign($attrs,($this->$attrs));
130 }
131 }
133 /* Assign all filter attributes to smarty */
134 foreach($SUBfaifilter as $key => $val){
135 if(($key != "base")&&($key != "Sregex")){
136 if($val){
137 $smarty->assign($key."CHK", " checked ");
138 }else{
139 $smarty->assign($key."CHK", "");
140 }
141 }else{
142 $smarty->assign($key,$val);
143 }
144 }
146 /* Create a divlist to display all available class names with the depending object types */
147 $divlist = new divlist("ProfileEntry");
148 $divlist->SetSummary(_("This list displays all assigned class names for this profile."));
149 $divlist->SetEntriesPerPage(20);
150 $divlist->SetHeader(array(array("string"=>"Class name"),
151 array("string"=>"Objects","attach"=>"style='border-right:0px;'")));
153 /* Action button allows us to delete an entry */
154 $action = "<input type='hidden' name='ON_PAGE_%KEY%' value='1'>
155 <input type='checkbox' name='USE_%KEY%' value='%KEY%' onChange='document.mainform.submit();' %CHECK%>";
157 /* Check every single class name to match the current search filter */
158 foreach($this->FAIAllclasses as $usedClass => $classes){
160 $fi = str_replace("*",".*",$SUBfaifilter['Sregex']);
162 $abort = true;
163 if(!preg_match("/".$fi."/",$usedClass)){
164 $abort = false;
165 }
166 if((isset($classes['objects']['FAIscript']))&&($SUBfaifilter['SShowScripts'])){
167 $abort = false;
168 }
169 if((isset($classes['objects']['FAItemplate']))&&($SUBfaifilter['SShowTemplates'])){
170 $abort = false;
171 }
172 if((isset($classes['objects']['FAIhook']))&&($SUBfaifilter['SShowHooks'])){
173 $abort = false;
174 }
175 if((isset($classes['objects']['FAIvariable']))&&($SUBfaifilter['SShowVariables'])){
176 $abort = false;
177 }
178 if((isset($classes['objects']['FAIpartitionTable']))&&($SUBfaifilter['SShowPartitions'])){
179 $abort = false;
180 }
181 if((isset($classes['objects']['FAIpackage']))&&($SUBfaifilter['SShowPackages'])){
182 $abort = false;
183 }
185 if(!$abort){
186 $str = "";
187 foreach($classes['objects'] as $class => $obj){
188 $str.= $objTypes[$obj];
189 }
191 /* Is this entry selected */
192 if($classes['status']==true){
193 $action_check = preg_replace("/%CHECK%/"," checked ",$action);
194 }else{
195 $action_check = preg_replace("/%CHECK%/","",$action);
196 }
198 /* Append to list */
199 $field1 = array("string"=> preg_replace("/%KEY%/",$usedClass,$action_check).$usedClass,"attach"=>"");
200 $field2 = array("string"=> $str,"attach"=>"style='border-right:0px;'");
201 $divlist->AddEntry(array($field1,$field2));
202 }
203 }
205 $smarty->assign("faihead" , "");
206 $smarty->assign("failist" , $divlist->DrawList());
207 $smarty->assign("infoimage" , get_template_path('images/info.png'));
208 $smarty->assign("launchimage" , get_template_path('images/launch.png'));
209 $smarty->assign("alphabet" , generate_alphabet());
210 $smarty->assign("apply" , apply_filter(TRUE));
211 $smarty->assign("search_image" , get_template_path('images/search.png'));
213 $display.= $smarty->fetch(get_template_path('faiProfileEntry.tpl', TRUE));
214 return($display);
215 }
217 /* Save data to object */
218 function save_object()
219 {
220 }
222 /* Check supplied data */
223 function check()
224 {
225 $message= array();
226 return ($message);
227 }
229 function save()
230 {
231 $tmp = array();
232 foreach($this->FAIAllclasses as $class => $obj){
233 if($obj['status']==true){
234 $tmp[$class]=$class;
235 }
236 }
237 return($tmp);
238 }
239 }
240 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
241 ?>