2f7d34773450892951386dfc935343494794858d
1 <?php
3 class faiProfile extends plugin
4 {
5 /* attribute list for save action */
6 var $ignore_account = TRUE;
8 /* Attributes for this Object */
9 var $attributes = array("cn","description","FAIclass");
11 /* ObjectClasses for this Object*/
12 var $objectclasses = array("top","FAIclass","FAIprofile");
14 /* Specific attributes */
15 var $old_cn = "";
16 var $cn = ""; // The class name for this object
17 var $description = ""; // The description for this set of partitions
18 var $is_dialog = false; // specifies which buttons will be shown to save or abort
19 var $FAIclass = ""; // Classnames used for this profile
20 var $FAIclasses = array(); // Contains classname seperated in an array
21 var $FAIAllclasses = array(); // Contains all possible Classnames
22 var $ui ;
23 var $FAIstate = "";
24 var $view_logged = FALSE;
26 var $classSelect;
28 function faiProfile(&$config, $dn= NULL)
29 {
30 /* Load Attributes */
31 plugin::plugin ($config, $dn);
32 $ldap=$this->config->get_ldap_link();
34 $this->ui = get_userinfo();
36 /* Parse ldap attribute to get all assigned classes */
37 $tmp = explode(" ",$this->FAIclass);
38 $tmp2 = array();
39 foreach($tmp as $class){
40 if(!empty($class)){
41 $tmp2[trim($class)] = trim($class);
42 }
43 }
45 /* Sort assigned classes */
46 if(is_array($tmp2)){
47 foreach($tmp2 as $class){
48 $this->FAIclasses[$class]=$class;
49 }
50 }
52 $categories = array("FAIscript","FAItemplate","FAIhook","FAIvariable","FAIpartitionTable","FAIpackageList");
54 /* Build filter */
55 $filter= "";
56 foreach ($categories as $cat){
57 $filter.= "(objectClass=$cat)";
58 }
60 /* Get ldap connection */
61 $base = session::get('CurrentMainBase');
62 $ldap->cd($base);
63 $sort = array();
65 /* search all FAI classes */
66 $ldap->search("(|$filter)",array("*"));
67 while($attrs = $ldap->fetch()){
69 /* Sort by categorie */
70 foreach($categories as $cat){
71 if(in_array_strict($cat,$attrs['objectClass'])){
73 /* Append entry */
74 $this->FAIAllclasses[$attrs['cn'][0]][$cat]=$attrs;
76 /* Create sort array, because the array above is a multidimensional array, and can't be sorted by php sorting functions*/
77 $sort[strtolower($attrs['cn'][0])] = $attrs['cn'][0];
78 }
79 }
80 }
82 /* Sort the sort array */
83 //ksort($sort);
85 /* Reorder the FAIclasses array */
86 foreach($sort as $name){
87 $tmp[$name] =$this->FAIAllclasses[$name];
88 }
90 /* Assign sorted classes */
91 $this->FAIAllclasses = array();
92 $this->FAIAllclasses = $tmp;
94 if($dn != "new"){
95 $this->dn =$dn;
96 }
97 $this->old_cn = $this->cn;
99 // Prepare lists
100 $this->classList = new sortableListing(array(),array(), TRUE);
101 $this->classList->setDeleteable(true);
102 $this->classList->setEditable(false);
103 $this->classList->setWidth("100%");
104 $this->classList->setHeight("200px");
105 $this->classList->setHeader(array(_("Name"),_("Types")));
106 $this->classList->setDefaultSortColumn(0);
107 }
110 function acl_base_for_current_object($dn)
111 {
112 if($dn == "new" || $dn == ""){
113 if($this->dn == "new"){
114 $dn= $this->parent->parent->acl_base;
115 }else{
116 $dn = $this->dn;
117 }
118 }
119 return($dn);
120 }
123 function execute()
124 {
125 /* Call parent execute */
126 plugin::execute();
128 if($this->is_account && !$this->view_logged){
129 $this->view_logged = TRUE;
130 new log("view","fai/".get_class($this),$this->dn);
131 }
133 /* Fill templating stuff */
134 $smarty= get_smarty();
135 $display= "";
137 $s_entry = "";
138 $s_action = "";
140 /* Remove class name From list */
141 $sort_once = false;
142 if(!preg_match("/freeze/",$this->FAIstate)){
144 if(isset($_POST['AddClass']) && $this->acl_is_writeable("FAIclass")){
145 $this->classSelect = new classSelect($this->config, get_userinfo());
146 $this->dialog =true;
147 }
150 /* Save Dialog */
151 if(isset($_POST['classSelect_save']) && $this->classSelect instanceOf classSelect){
152 $list = $this->classSelect->save();
153 foreach($list as $entry){
154 $class = $entry['cn'][0];
155 $this->FAIclasses[$class] =$class;
156 }
157 $this->dialog=false;
158 $this->classSelect=FALSE;
159 }
160 }
162 /* Cancel Dialog */
163 if(isset($_POST['classSelect_cancel']) && $this->classSelect instanceOf classSelect){
164 $this->dialog=false;
165 $this->classSelect=FALSE;
166 }
168 if($this->classSelect instanceOf classSelect){
169 session::set('filterFAIClass_base',$this->parent->parent->fai_release);
170 session::set('filterBlacklist', array('cn' => array_values($this->FAIclasses)));
171 return($this->classSelect->execute());
172 }
174 /* item images */
175 $objTypes['FAIhook'] = image('plugins/fai/images/fai_hook.png','',_("Hook bundle"));
176 $objTypes['FAItemplate'] = image('plugins/fai/images/fai_template.png','',_("Template bundle"));
177 $objTypes['FAIscript'] = image('plugins/fai/images/fai_script.png','',_("Script bundle"));
178 $objTypes['FAIvariable'] = image('plugins/fai/images/fai_variable.png','',_("Variable bundle"));
179 $objTypes['FAIpackageList'] = image('plugins/fai/images/fai_packages.png','',_("Package bundle"));
180 $objTypes['FAIpartitionTable'] = image('plugins/fai/images/fai_partitionTable.png','',_("Partition table"));
182 $emp = image('images/empty.png');
184 /* Delete button */
185 $actions = image('images/lists/trash.png','DEL_%KEY%',_("Remove class from profile"));
187 /* Up down buttons */
188 $linkupdown = image('images/lists/sort-up.png','sortup_%s',_("Up"), 'top');
189 $linkupdown.= image('images/lists/sort-down.png','sortdown_%s',_("Down"), 'bottom');
191 $this->classList->setAcl($this->getacl('FAIclass',preg_match('/^freeze/', $this->FAIstate)));
192 $data = $lData = array();
193 foreach($this->FAIclasses as $usedClass){
194 $str = "";
195 if(isset($this->FAIAllclasses[$usedClass])){
196 foreach($this->FAIAllclasses[$usedClass] as $class => $obj){
197 $str.= $objTypes[$class];
198 }
199 }
200 $data[$usedClass] = $usedClass;
201 $lData[$usedClass] = array('data'=>array($usedClass,$str));
202 }
203 $this->classList->setListData($data,$lData);
204 $this->classList->update();
207 $smarty->assign("freeze", preg_match("/freeze/i",$this->FAIstate));
208 $smarty->assign("FAIclasses" ,$this->FAIclasses);
209 $smarty->assign("listing" ,$this->classList->render());
211 /* Magic quotes GPC, escapes every ' " \, to solve some security risks
212 * If we post the escaped strings they will be escaped again
213 */
214 foreach($this->attributes as $attrs){
215 $smarty->assign($attrs,set_post($this->$attrs));
216 }
219 $dn = $this->acl_base_for_current_object($this->dn);
220 $smarty->assign("sub_object_is_addable",
221 preg_match("/c/",$this->ui->get_permissions($dn,"fai/faiScriptEntry")) &&
222 !preg_match("/freeze/",$this->FAIstate));
224 $tmp = $this->plInfo();
225 foreach($tmp['plProvidedAcls'] as $name => $translated){
226 $smarty->assign($name."ACL",$this->getacl($name, preg_match("/freeze/",$this->FAIstate)));
227 }
229 $display.= $smarty->fetch(get_template_path('faiProfile.tpl', TRUE));
230 return($display);
231 }
233 function remove_from_parent()
234 {
235 $ldap = $this->config->get_ldap_link();
236 $ldap->cd ($this->dn);
237 $release = $this->parent->parent->fai_release;
238 $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $this->dn);
239 new log("remove","fai/".get_class($this),$use_dn,$this->attributes);
240 FAI::prepare_to_save_FAI_object($use_dn,array(),true);
241 $this->handle_post_events("remove");
242 }
245 /* Save data to object
246 */
247 function save_object()
248 {
249 if(!preg_match("/freeze/",$this->FAIstate)){
250 plugin::save_object();
252 $this->classList->save_object();
253 $action = $this->classList->getAction();
254 if($action['action'] == 'reorder'){
255 $this->FAIclasses = $this->classList->getMaintainedData();
256 }
257 if($action['action'] == 'delete'){
258 $s_entry = $this->classList->getKey($action['targets'][0]);
259 unset($this->FAIclasses[$s_entry]);
260 }
261 }
262 }
265 /* Check supplied data */
266 function check()
267 {
268 /* Call common method to give check the hook */
269 $message= plugin::check();
271 if(count($this->FAIclasses) == 0){
272 $message[]=_("No class specified for this profile!");
273 }
275 if($this->cn == ""){
276 $message[]= msgPool::required(_("Name"));
277 }
279 /* Ensure that we do not overwrite an allready existing entry
280 */
281 if($this->dn == "new" || $this->cn != $this->old_cn){
282 $release = $this->parent->parent->fai_release;
283 $new_dn= 'cn='.$this->cn.",".get_ou("faiProfile", "faiProfileRDN").get_ou("faiManagement", "faiBaseRDN").$release;
284 $res = faiManagement::check_class_name("FAIprofile",$this->cn,$new_dn);
285 if(isset($res[$this->cn])){
286 $message[] = msgPool::duplicated(_("Name"));
287 }
288 }
290 return ($message);
291 }
294 /* Save to LDAP */
295 function save()
296 {
297 plugin::save();
299 $ldap = $this->config->get_ldap_link();
301 $this->FAIclass = "";
302 foreach($this->FAIclasses as $class){
303 $this->FAIclass.=$class." ";
304 }
306 $this->attrs['FAIclass']=trim($this->FAIclass);
308 /* Remove the old FAI profile, if the dn has changed.
309 */
310 if($this->cn != $this->old_cn && $this->old_cn != ""){
312 $old_dn = preg_replace("/^cn=[^,]+,/","cn=".$this->old_cn.",",$this->dn);
313 FAI::prepare_to_save_FAI_object($old_dn,array(),TRUE);
314 }
315 FAI::prepare_to_save_FAI_object($this->dn,$this->attrs);
317 if($this->initially_was_account){
318 new log("modify","fai/".get_class($this),$this->dn,$this->attributes);
319 }else{
320 new log("create","fai/".get_class($this),$this->dn,$this->attributes);
321 }
322 }
325 function PrepareForCopyPaste($source)
326 {
327 plugin::PrepareForCopyPaste($source);
329 /* Parse ldap attribute to get all assigned classes */
330 $tmp = explode(" ",$this->FAIclass);
331 $tmp2 = array();
332 foreach($tmp as $class){
333 if(!empty($class)){
334 $tmp2[trim($class)] = trim($class);
335 }
336 }
338 /* Sort assigned classes */
339 if(is_array($tmp2)){
340 foreach($tmp2 as $class){
341 $this->FAIclasses[$class]=$class;
342 }
343 }
344 }
347 /* Return plugin informations for acl handling */
348 static function plInfo()
349 {
350 return (array(
351 "plShortName" => _("Profile"),
352 "plDescription" => _("FAI profile"),
353 "plSelfModify" => FALSE,
354 "plDepends" => array(),
355 "plPriority" => 30,
356 "plSection" => array("administration"),
357 "plCategory" => array("fai"),
359 "plProperties" =>
360 array(
361 array(
362 "name" => "faiProfileRDN",
363 "type" => "rdn",
364 "default" => "ou=profiles,",
365 "description" => _("RDN for FAI profile storage."),
366 "check" => "gosaProperty::isRdn",
367 "migrate" => "migrate_faiProfileRDN",
368 "group" => "plugin",
369 "mandatory" => TRUE)),
372 "plProvidedAcls" => array(
373 "cn" => _("Name"),
374 "description" => _("Description"),
375 "FAIclass" => _("FAI classes"))
376 ));
377 }
380 /*! \brief Used for copy & paste.
381 Returns a HTML input mask, which allows to change the cn of this entry.
382 @param Array Array containing current status && a HTML template.
383 */
384 function getCopyDialog()
385 {
386 $vars = array("cn");
387 $smarty = get_smarty();
388 $smarty->assign("cn", set_post($this->cn));
389 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
390 $ret = array();
391 $ret['string'] = $str;
392 $ret['status'] = "";
393 return($ret);
394 }
397 /*! \brief Used for copy & paste.
398 Some entries must be renamed to avaoid duplicate entries.
399 */
400 function saveCopyDialog()
401 {
402 if(isset($_POST['cn'])){
403 $this->cn = get_post('cn');
404 }
405 }
406 }
408 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
409 ?>