1 <?php
3 class faiHookEntry 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("Object_cn","Object_description","Object_FAIscript","Object_FAItask");
13 var $objectclasses= array();
15 var $orig_cn = "";
17 var $Object_dn = "";
18 var $Object_cn = "";
19 var $Object_FAItask = "";
20 var $Object_FAIscript = "";
21 var $Object_description = "";
22 var $Object_status = "new";
24 function faiHookEntry ($config, $dn= NULL,$object=false)
25 {
26 plugin::plugin ($config, $dn);
27 if($dn != "new"){
28 $this->orig_cn= $object['cn'];
29 $this->dn=$object['dn'];
30 foreach($object as $name=>$value){
31 $oname = "Object_".$name;
32 $this->$oname=$value;
33 }
34 }else{
35 $this->Object_status = "new";
36 $this->orig_cn = false;
37 }
38 }
41 function execute()
42 {
43 /* Fill templating stuff */
44 $smarty = get_smarty();
45 $display = "";
47 if(isset($_POST['ImportUpload'])){
48 if(($_FILES['ImportFile']['error']!=0)){
49 print_red(_("Please select a valid file."));
50 }else
51 if(($_FILES['ImportFile']['size']==0)){
52 print_red(_("Selected file is empty."));
53 }else{
54 $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name']));
55 $this->Object_FAIscript = $str;
56 }
57 }
59 /* Magic quotes GPC, escapes every ' " \, to solve some security risks
60 * If we post the escaped strings they will be escaped again
61 */
62 foreach($this->attributes as $attrs){
63 if(get_magic_quotes_gpc()){
64 $smarty->assign($attrs,stripslashes($this->$attrs));
65 }else{
66 $smarty->assign($attrs,($this->$attrs));
67 }
68 }
70 $display.= $smarty->fetch(get_template_path('faiHookEntry.tpl', TRUE));
71 return($display);
72 }
74 /* Save data to object */
75 function save_object()
76 {
77 if(isset($_POST['SubObjectFormSubmitted'])){
78 foreach($this->attributes as $attrs){
79 if(isset($_POST[$attrs])){
80 $this->$attrs = $_POST[$attrs];
81 }else{
82 $this->$attrs = "";
83 }
84 }
85 }
86 }
88 /* Check supplied data */
89 function check()
90 {
91 $message= array();
92 if(empty($this->Object_FAItask)) {
93 $message[]=_("Please enter a value for task.");
94 }
95 if(empty($this->Object_FAIscript)) {
96 $message[]=_("Please enter a value for script.");
97 }
99 if(empty($this->Object_cn)){
100 $message[] = _("Please enter a name.");
101 }
103 if(preg_match("/[^0-9a-z]/i",$this->Object_cn)){
104 $message[] = _("Please enter a valid name. Only a-Z 0-9 are allowed.");
105 }
107 return ($message);
108 }
110 function save()
111 {
112 $tmp=array();
113 foreach($this->attributes as $attrs){
114 $attr = preg_replace("/^Object_/","",$attrs);
115 $tmp[$attr] = $this->$attrs;
116 }
118 if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
119 $tmp['remove']['from'] = $this->orig_cn;
120 $tmp['remove']['to'] = $tmp['cn'];
121 }
123 $tmp['dn'] = $this->dn;
124 $tmp['status'] = $this->Object_status;
125 return($tmp);
126 }
127 }
128 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
129 ?>