0eaa262c77ff4873f655ee8c3ee133c198132902
1 <?php
3 class servkolab extends plugin {
4 /* CLI vars */
5 var $cli_summary = "Manage server basic objects";
6 var $cli_description = "Some longer text\nfor help";
7 var $cli_parameters = array("eins"=>"Eins ist toll", "zwei"=>"Zwei ist noch besser");
9 var $postfix_mydomain = "\$domain";//<<<<<<<<<<<<<
10 var $postfix_mydestination = "\$domain";//<<<<<<<<<<<<<
11 var $postfix_mynetworks = "127.0.0.1/8";//ok
12 var $postfix_enable_virus_scan = "TRUE";//ok
13 var $cyrus_quotawarn = "999";//ok
14 var $kolabFreeBusyFuture = "1";// ok
15 var $cyrus_admins = "TRUE";//<<<<<<<<<<<<<<<<
16 var $cyrus_imap = "TRUE";//ok
17 var $cyrus_pop3 = "TRUE";//ok
18 var $cyrus_imaps = "TRUE";//ok
19 var $cyrus_pop3s = "TRUE";//ok
20 var $cyrus_sieve = "TRUE";//ok
21 var $apache_allow_unauthenticated_fb = "TRUE";//<<<<<<<<<<<<
22 var $proftpd_ftp = "TRUE";//pk
23 var $apache_http = "TRUE";//ok
24 var $kolabHost = array();
25 var $added = false;
26 var $remove = false;
27 var $attributes = array("postfix_mydomain", "postfix_mydestination",
28 "postfix_mynetworks", "postfix_enable_virus_scan",
29 "cyrus_admins", "cyrus_imap","kolabFreeBusyFuture",
30 "cyrus_pop3", "cyrus_imaps", "cyrus_pop3s", "cyrus_sieve",
31 "apache_allow_unauthenticated_fb", "proftpd_ftp",
32 "apache_http", "cyrus_quotawarn", "kolabHost");
34 var $objectclasses = array("top", "kolab");
36 function servkolab($config, $dn = NULL)
37 {
40 /* Setting the hostname and tell this Plugin that we are the kolab extension*/
41 $this->hostname= preg_replace('/^cn=([^,]+),.*$/', '\1', $dn);
42 $this->dn = "k=kolab,".$config->current['BASE'];
44 /* Load variables, if given*/
45 plugin::plugin($config, $this->dn);
47 /* Copy needed attributes */
48 foreach($this->attributes as $val) {
49 $name = preg_replace('/_/', '-', $val);
50 if (isset($this->attrs["$name"][0])) {
51 $this->$val = $this->attrs["$name"][0];
52 }
53 }
55 /* Is this Server a member of the Kolab extension or not ?*/
56 if(in_array($this->hostname,$this->attrs['kolabHost'])) {
57 $this->is_account=true;
58 } else {
59 $this->is_account=false; }
60 }
63 function execute()
64 {
65 /* Fill templating stuff */
66 $smarty = get_smarty();
67 $display = "";
69 /* Lets get all Host that are member of the Kolab extension, but don't catch count */
70 if(is_array($this->attrs['kolabHost']))
71 {
72 unset($this->attrs['kolabHost']['count']);
73 $this->kolabHost = $this->attrs['kolabHost'];
74 }
75 else
76 {
77 $this->attrs['kolabHost']=array();
78 $this->kolabHost = $this->attrs['kolabHost'];
79 }
81 /* Tell the script the dn, we are using */
82 $this->kolabdn = "k=kolab,".$this->config->current['BASE'];
84 /* The Ldap link is needed to ask ldap some questions */
85 $ldap = $this->config->get_ldap_link();
87 /* Do we need to flip is_account state? */
88 if (isset($_POST['modify_state'])) {
89 $this->is_account = !$this->is_account;
92 /*if we flip to true, we'll have to create a new account, so lets do that*/
93 if($this->is_account==true)
94 {
95 /* Only add the given Hostname to the existing hosts*/
96 $this->kolabHost[]=$this->hostname;
97 $this->attrs['kolabHost'][]=$this->hostname;
98 }
99 else
100 {
101 /* First we have to find the Host we want to delete, take the index and delete em*/
102 foreach($this->kolabHost as $key=>$host)
103 {
104 /* Delete only if the Host is the in the array*/
105 if($host == $this->hostname)
106 {
107 unset($this->kolabHost[$key]);
108 unset($this->attrs['kolabHost'][$key]);
109 }
110 }
111 /* We deletet an Entry so we must reorder the index of the array */
112 $tmp = $this->kolabHost;
113 $this->kolabHost=array();
114 $this->attrs['kolabHost']=array();
116 /* reorder reorder ...*/
117 foreach($tmp as $host){
118 $this->kolabHost[]=$host;
119 $this->attrs['kolabHost'][]=$host;
120 }
121 /* Tell Save that we want to delete someone*/
122 $this->remove = true;
123 }
125 }
127 /* Show tab dialog headers */
128 if ($this->is_account) {
129 /* call Add Acoount to add account */
130 $display = $this->show_header(_("Remove Kolab extension"), _("This server has kolab features enabled. You can disable them by clicking below."));
131 } else {
132 /* call remove Account */
133 $display = $this->show_header(_("Add Kolab service"), _("This server has kolab features disabled. You can enable them by clicking below."));
134 return ($display);
135 }
137 /* Initialize all attributes, that were submitted */
138 foreach($this->attributes as $val)
139 {
140 /* If theres a button pressed, we need to check all attributes */
141 if ((isset($_POST['NewHost'])) || (isset($_POST['DelHost'])))
142 {
143 /* Set var to value or to zero */
144 if (isset($_POST[$val]))
145 {
147 $this->$val = $_POST[$val];
148 } else {
149 $this->$val = 0;
150 }
151 }
152 /* Tell smarty which variables we are useing */
153 $smarty->assign($val, $this->$val);
154 if (($this->$val != "FALSE") && (!empty($this->$val)))
155 $smarty->assign($val."Check", "checked");
156 else
157 $smarty->assign($val."Check", "");
158 }
160 /* Load Template */
161 $display.=$smarty->fetch(get_template_path('servkolab.tpl', TRUE));
162 return ($display);
163 }
165 function remove_from_parent()
166 {
167 }
170 function save_object()
171 {
172 plugin::save_object();
173 }
176 function check()
177 {
178 $message = array();
181 if(!is_int((int)($this->cyrus_quotawarn))) {
182 $message[] = "The given Quota settings value must be a number";
183 }elseif(!(($this->cyrus_quotawarn<=100)&&($this->cyrus_quotawarn>=1))){
184 $message[] = "Please choose a value between 1 and 100 for Quota settings";
185 }
188 return ($message);
189 }
192 /* Save to LDAP */
193 function save()
194 {
195 /* Set ldap connection */
196 $ldap = $this->config->get_ldap_link();
198 /* Open current dn*/
199 $ldap->cd($this->dn);
202 /* Setup Attributes to save */
203 $newattrs = array();
205 /* Set vars with correct - _ - */
206 foreach($this->attributes as $key) {
207 $key2 = str_replace("_", "-", $key);
208 $newattrs[$key2] = $this->$key;
209 }
213 /* Set bool vars */
214 if ($newattrs['postfix-enable-virus-scan'] == 0)
215 $newattrs['postfix-enable-virus-scan'] = "FALSE";
216 else
217 $newattrs['postfix-enable-virus-scan'] = "TRUE";
218 if ($newattrs['cyrus-imap'] == 0)
219 $newattrs['cyrus-imap'] = "FALSE";
220 else
221 $newattrs['cyrus-imap'] = "TRUE";
222 if ($newattrs['cyrus-imaps'] == 0)
223 $newattrs['cyrus-imaps'] = "FALSE";
224 else
225 $newattrs['cyrus-imaps'] = "TRUE";
226 if ($newattrs['cyrus-pop3'] == 0)
227 $newattrs['cyrus-pop3'] = "FALSE";
228 else
229 $newattrs['cyrus-pop3'] = "TRUE";
230 if ($newattrs['cyrus-pop3s'] == 0)
231 $newattrs['cyrus-pop3s'] = "FALSE";
232 else
233 $newattrs['cyrus-pop3s'] = "TRUE";
234 if ($newattrs['cyrus-sieve'] == 0)
235 $newattrs['cyrus-sieve'] = "FALSE";
236 else
237 $newattrs['cyrus-sieve'] = "TRUE";
238 if ($newattrs['proftpd-ftp'] == 0)
239 $newattrs['proftpd-ftp'] = "FALSE";
240 else
241 $newattrs['proftpd-ftp'] = "TRUE";
242 if ($newattrs['apache-http'] == 0)
243 $newattrs['apache-http'] = "FALSE";
244 else
245 $newattrs['apache-http'] = "TRUE";
246 if ($newattrs['apache-allow-unauthenticated-fb'] == 0)
247 $newattrs['apache-allow-unauthenticated-fb'] = "FALSE";
248 else
249 $newattrs['apache-allow-unauthenticated-fb'] = "TRUE";
252 /* Reorder Host array, to get constant increasing index */
253 $newattrs['kolabHost'] = array();
255 /* If we want to add someone or do only changes on the settings ...*/
256 if(!$this->remove)
257 {
258 /* Get all Host known, that are member of the Kolab extension */
259 $this->kolabHost = $this->attrs['kolabHost'];
261 /* So, the Host is already member of the extension, so get all and do nothing */
262 if(in_array($this->hostname,$this->kolabHost))
263 {
264 $newattrs['kolabHost']=$this->kolabHost;
265 }
266 /* So this is the first entry */
267 elseif(empty($this->kolabHost))
268 {
269 /* Create an array an add the Host */
270 $newattrs['kolabHost']=array();
271 $newattrs['kolabHost'][]=$this->hostname;
272 }
273 /* Theres already an entry, but only in a string, */
274 elseif(is_string($this->kolabHost))
275 {
276 $tmp = $this->kolabHost;
277 $newattrs['kolabHost']=array();
278 $newattrs['kolabHost'][]=$tmp;
279 $newattrs['kolabHost'][]=$this->hostname;
280 }
281 /* Here we have already some entries */
282 elseif(is_array($newattrs['kolabHost']))
283 {
284 /* Insert the new one*/
285 foreach($this->kolabHost as $key=>$val) {
286 if (is_int($key)) {
287 $newattrs['kolabHost'][] = $val;
288 }
289 }
290 $newattrs['kolabHost'][]= $this->hostname;
291 }
292 }
293 else
294 {
295 /* Here we want to delete an entry*/
296 $newattrs['kolabHost']= $this->attrs['kolabHost'];
297 }
298 /* Save as following object ! */
299 $this->kolabdn = "k=kolab,".$this->config->current['BASE'];
301 /* If we already have an object like this one,
302 we only need to modify the entry
303 */
305 /* is this an empty extension, no host defined for it, than delet it */
306 if(count($newattrs['kolabHost'])==0)
307 {
308 /* Delete the entry*/
309 $ldap->cd ("k=kolab,".$this->config->current['BASE']);
310 $ldap->rmdir("k=kolab,".$this->config->current['BASE']);
312 }elseif ($ldap->dn_exists($this->kolabdn)) {
313 /* Ok there is already an extension, so we only need to add the changes and the new Host, (if it was a new host)*/
314 gosa_log("Modifying");
316 /* unset all attributes we won't change*/
317 unset($newattrs['cyrus-admins']);
318 unset($newattrs['postfix-mydomain']);
319 unset($newattrs['postfix-mydestination']);
321 /* Update changes */
322 $ldap->cd($this->kolabdn);
323 $ldap->modify($newattrs);
324 } else {
326 /* We must create a new Entry */
327 $newattrs['k'] = "kolab";
328 $newattrs['uid'] = "freebusy";
329 $newattrs['postfix-mydomain'] = "gonicus.de";
330 $newattrs['postfix-mydestination'] = "\$mydomain";
331 $newattrs['userPassword'] = "tester";
332 $newattrs['objectClass'] = $this->objectclasses;
334 /* For better reading / Objectclass was added at last */
335 $newattrs = array_reverse ($newattrs);
337 /* And add the entry*/
338 $ldap->cd($this->kolabdn);
339 $ldap->add($newattrs);
340 }
341 /* show any errors */
342 show_ldap_error($ldap->get_error());
344 /* Optionally execute a command after we're done */
345 if ($this->initially_was_account == $this->is_account) {
346 if ($this->is_modified) {
347 $this->handle_post_events("mofify");
348 }
349 } else {
350 $this->handle_post_events("add");
351 }
353 }
355 }
357 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
358 ?>