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 }
39 if(isset($this->Object_FAIscript)){
40 $ds= ldap_connect($this->config->current['SERVER']);
41 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
42 if(function_exists("ldap_set_rebind_proc") && isset($this->config->current['RECURSIVE']) && $this->config->current['RECURSIVE'] == "true") {
43 ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
44 ldap_set_rebind_proc($ds, array(&$this, "rebind"));
45 }
47 if(isset($this->config->current['TLS']) && $this->config->current['TLS'] == "true"){
48 ldap_start_tls($ds);
49 }
51 $r = ldap_bind($ds);
52 $sr= @ldap_read($ds, $this->dn, "FAIscript=*", array("FAIscript"));
53 if ($sr) {
54 $ei=ldap_first_entry($ds, $sr);
55 if ($ei) {
56 if ($info = ldap_get_values_len($ds, $ei, "FAIscript")){
57 $this->Object_FAIscript = base64_decode($info[0]);
58 }
59 }
60 }
62 /* close conncetion */
63 ldap_unbind($ds);
64 }
66 }
68 function execute()
69 {
70 /* Fill templating stuff */
71 $smarty = get_smarty();
72 $display = "";
74 if(isset($_POST['ImportUpload'])){
75 if(($_FILES['ImportFile']['error']!=0)){
76 print_red(_("Please select a valid file."));
77 }else
78 if(($_FILES['ImportFile']['size']==0)){
79 print_red(_("Selected file is empty."));
80 }else{
81 $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name']));
82 $this->Object_FAIscript = $str;
83 }
84 }
86 foreach($this->attributes as $attrs){
87 $smarty->assign($attrs,stripslashes($this->$attrs));
88 }
90 for($i =1 ; $i <= 100 ; $i++){
91 $Object_FAIprioritys[$i]=$i;
92 }
93 $smarty->assign("Object_FAIprioritys",$Object_FAIprioritys);
94 $display.= $smarty->fetch(get_template_path('faiHookEntry.tpl', TRUE));
95 return($display);
96 }
98 /* Save data to object */
99 function save_object()
100 {
101 if(isset($_POST['SubObjectFormSubmitted'])){
102 foreach($this->attributes as $attrs){
103 if(isset($_POST[$attrs])){
104 $this->$attrs = $_POST[$attrs];
105 }else{
106 $this->$attrs = "";
107 }
108 }
109 }
110 }
112 /* Check supplied data */
113 function check()
114 {
115 $message= array();
116 if(empty($this->Object_FAItask)) {
117 $message[]=_("Please enter a value for task.");
118 }
119 if(empty($this->Object_FAIscript)) {
120 $message[]=_("Please enter a value for script.");
121 }
123 $str = utf8_encode("üöä");
125 if(preg_match("/[^a-z0-9".$str."\.,;:\-_\? ]/i",$this->Object_description)){
126 $message[] = _("Invalid character in description. Please enter a valid description.");
127 }
129 if(empty($this->Object_cn)){
130 $message[] = _("Please enter a name.");
131 }
133 if(preg_match("/[^0-9a-z]/i",$this->Object_cn)){
134 $message[] = _("Please enter a valid name. Only a-Z 0-9 are allowed.");
135 }
137 return ($message);
138 }
140 function save()
141 {
142 $tmp=array();
143 foreach($this->attributes as $attrs){
144 $attr = preg_replace("/^Object_/","",$attrs);
145 $tmp[$attr] = $this->$attrs;
146 }
148 if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
149 $tmp['remove']['from'] = $this->orig_cn;
150 $tmp['remove']['to'] = $tmp['cn'];
151 }
153 $tmp['dn'] = $this->dn;
154 $tmp['status'] = $this->Object_status;
155 return($tmp);
156 }
157 }
158 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
159 ?>