30eedeb6cc1b51a7a461a2208c10c01124a91e35
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 $ObjectTypes = array(
24 "FAIpartitionTable" => array("OU"=>"ou=disk," ),
25 "FAIpackageList" => array("OU"=>"ou=packages," ),
26 "FAIscript" => array("OU"=>"ou=scripts," ),
27 "FAIvariable" => array("OU"=>"ou=variables," ),
28 "FAIhook" => array("OU"=>"ou=hooks," ),
29 "FAIprofile" => array("OU"=>"ou=profiles," ),
30 "FAItemplate" => array("OU"=>"ou=templates," ));
32 $base= "ou=fai,ou=configs,ou=systems,".$_SESSION['CurrentMainBase'];
33 if($_SESSION['faifilter']['branch']!="main"){
34 $base = $_SESSION['faifilter']['branch'];
35 }
37 /* Get ldap connection */
38 $ldap= $this->config->get_ldap_link();
39 $ldap->cd($base);
41 /* Capture objects from given base */
42 $result = array();
43 foreach($ObjectTypes as $oc => $data){
44 $ou = $data['OU'].$base;
46 $ldap->ls("(objectClass=".$oc.")",$ou,array("cn","objectClass","dn"));
47 while($res = $ldap->fetch()){
48 $result[] = $res;
49 }
50 }
52 /* Create array with categories to be able to sort different types of objects */
53 $categories = array("FAIscript","FAItemplate","FAIhook","FAIvariable","FAIpartitionTable","FAIpackageList");
54 $sort = array();
55 foreach($result as $attrs){
57 /* Only use objects which have cn set */
58 if((isset($attrs['cn'][0]))&&(!in_array($attrs['cn'][0],$used))){
59 foreach($categories as $cat){
60 if(in_array($cat,$attrs['objectClass'])){
62 /* Append different types of objects */
63 $this->FAIAllclasses[$attrs['cn'][0]]['objects'][$cat]=$cat;
65 /* Set selected status to false */
66 $this->FAIAllclasses[$attrs['cn'][0]]['status']=false;
68 $sort[strtolower($attrs['cn'][0])] = $attrs['cn'][0];
69 }
70 }
71 }
72 }
73 $tmp = array();
74 ksort($sort);
75 foreach($sort as $name){
76 $tmp[$name] =$this->FAIAllclasses[$name];
77 }
78 $this->FAIAllclasses = array();
79 $this->FAIAllclasses = $tmp;
82 /* If no search filter is set, create one */
83 if (!is_global("SUBfaifilter")){
84 $SUBfaifilter= array("base" => "ou=fai,ou=configs,ou=systems,".$_SESSION['CurrentMainBase'], "Sregex" => "*");
85 $SUBfaifilter['SShowTemplates'] = true;
86 $SUBfaifilter['SShowScripts'] = true;
87 $SUBfaifilter['SShowHooks'] = true;
88 $SUBfaifilter['SShowVariables'] = true;
89 $SUBfaifilter['SShowPackages'] = true;
90 $SUBfaifilter['SShowPartitions']= true;
91 register_global("SUBfaifilter", $SUBfaifilter);
92 }
93 }
95 function execute()
96 {
97 /* Call parent execute */
98 plugin::execute();
100 /* Fill templating stuff */
101 $smarty = get_smarty();
102 $display = "";
104 $SUBfaifilter = $_SESSION['SUBfaifilter'];
106 /* If someone used the apply button, update searchfilter */
107 if(isset($_POST['Sregex'])){
108 foreach($SUBfaifilter as $key => $val){
109 if(!isset($_POST[$key])){
110 $SUBfaifilter[$key] = false;
111 }else{
112 $SUBfaifilter[$key] =$_POST[$key];
113 }
114 }
115 $SUBfaifilter['Sregex']= $_POST['Sregex'];
116 if(!strstr($SUBfaifilter['Sregex'],"*")){
117 $SUBfaifilter['Sregex'] = $SUBfaifilter['Sregex']."*";
118 }
119 }
121 /* Save current searchfilter in session*/
122 $_SESSION['SUBfaifilter']= $SUBfaifilter;
124 /* Check if we used a checkboxe from the list, to select dselect an entry */
125 foreach($_POST as $name => $value){
126 foreach($this->FAIAllclasses as $class => $obj){
127 $bclass = base64_encode($class);
128 if(isset($_POST["ON_PAGE_".$bclass])){
129 if(isset($_POST['USE_'.$bclass])){
130 $this->FAIAllclasses[$class]['status']=true;
131 }else{
132 $this->FAIAllclasses[$class]['status']=false;
133 }
134 }
135 }
136 }
138 /* Create different picture for each object type */
139 $objTypes['FAIhook'] = "<img src='images/fai_hook.png' title='"._("Hook bundle")."' alt=''> ";
140 $objTypes['FAItemplate'] = "<img src='images/fai_template.png' title='"._("Template bundle")."' alt=''> ";
141 $objTypes['FAIscript'] = "<img src='images/fai_script.png' title='"._("Script bundle")."' alt=''> ";
142 $objTypes['FAIvariable'] = "<img src='images/fai_variable.png' title='"._("Variable bundle")."' alt=''> ";
143 $objTypes['FAIpackageList'] = "<img src='images/fai_packages.png' title='"._("Package bundle")."' alt=''> ";
144 $objTypes['FAIpartitionTable'] = "<img src='images/fai_partitionTable.png' title='"._("Partition table")."' alt=''> ";
146 /* Magic quotes GPC, escapes every ' " \, to solve some security risks
147 * If we post the escaped strings they will be escaped again
148 */
149 foreach($this->attributes as $attrs){
150 if(get_magic_quotes_gpc()){
151 $smarty->assign($attrs,stripslashes($this->$attrs));
152 }else{
153 $smarty->assign($attrs,($this->$attrs));
154 }
155 }
157 /* Assign all filter attributes to smarty */
158 foreach($SUBfaifilter as $key => $val){
159 if(($key != "base")&&($key != "Sregex")){
160 if($val){
161 $smarty->assign($key."CHK", " checked ");
162 }else{
163 $smarty->assign($key."CHK", "");
164 }
165 }else{
166 $smarty->assign($key,$val);
167 }
168 }
170 /* Create a divlist to display all available class names with the depending object types */
171 $divlist = new divlist("ProfileEntry");
172 $divlist->SetSummary(_("This list displays all assigned class names for this profile."));
173 $divlist->SetEntriesPerPage(0);
174 $divlist->SetHeader(array(array("string"=> _("Class name")),
175 array("string"=> _("Objects"),"attach"=>"style='border-right:0px;'")));
177 /* Action button allows us to delete an entry */
178 $action = "<input type='hidden' name='ON_PAGE_%KEY%' value='1'>
179 <input type='checkbox' name='USE_%KEY%' value='%KEY%' onClick='document.mainform.submit();' %CHECK%>";
181 /* Check every single class name to match the current search filter */
182 foreach($this->FAIAllclasses as $usedClass => $classes){
184 $fi = str_replace("*",".*",$SUBfaifilter['Sregex']);
186 $abort = true;
187 if(!preg_match("/".$fi."/",$usedClass)){
188 $abort = false;
189 }
190 if((isset($classes['objects']['FAIscript']))&&($SUBfaifilter['SShowScripts'])){
191 $abort = false;
192 }
193 if((isset($classes['objects']['FAItemplate']))&&($SUBfaifilter['SShowTemplates'])){
194 $abort = false;
195 }
196 if((isset($classes['objects']['FAIhook']))&&($SUBfaifilter['SShowHooks'])){
197 $abort = false;
198 }
199 if((isset($classes['objects']['FAIvariable']))&&($SUBfaifilter['SShowVariables'])){
200 $abort = false;
201 }
202 if((isset($classes['objects']['FAIpartitionTable']))&&($SUBfaifilter['SShowPartitions'])){
203 $abort = false;
204 }
205 if((isset($classes['objects']['FAIpackageList']))&&($SUBfaifilter['SShowPackages'])){
206 $abort = false;
207 }
209 if(!$abort){
210 $str = "";
211 foreach($classes['objects'] as $class => $obj){
212 $str.= $objTypes[$obj];
213 }
215 /* Is this entry selected */
216 if($classes['status']==true){
217 $action_check = preg_replace("/%CHECK%/"," checked ",$action);
218 }else{
219 $action_check = preg_replace("/%CHECK%/","",$action);
220 }
222 /* Append to list */
223 $field1 = array("string"=> str_replace("%KEY%",base64_encode($usedClass),$action_check).$usedClass,"attach"=>"");
224 $field2 = array("string"=> $str,"attach"=>"style='border-right:0px;'");
225 $divlist->AddEntry(array($field1,$field2));
226 }
227 }
229 $smarty->assign("faihead" , "");
230 $smarty->assign("failist" , $divlist->DrawList());
231 $smarty->assign("infoimage" , get_template_path('images/info_small.png'));
232 $smarty->assign("launchimage" , get_template_path('images/small_filter.png'));
233 $smarty->assign("alphabet" , generate_alphabet());
234 $smarty->assign("apply" , apply_filter(TRUE));
235 $smarty->assign("search_image" , get_template_path('images/search.png'));
237 $display.= $smarty->fetch(get_template_path('faiProfileEntry.tpl', TRUE));
238 return($display);
239 }
241 /* Save data to object */
242 function save_object()
243 {
244 }
246 /* Check supplied data */
247 function check()
248 {
249 /* Call common method to give check the hook */
250 $message= plugin::check();
252 return ($message);
253 }
255 function save()
256 {
257 $tmp = array();
258 foreach($this->FAIAllclasses as $class => $obj){
259 if($obj['status']==true){
260 $tmp[$class]=$class;
261 }
262 }
263 return($tmp);
264 }
265 }
266 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
267 ?>