d6a30a0e95bdbb42f8de8435567c443a2910a30d
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 = "";
10 var $postfix_mydestination = "";
11 var $postfix_mynetworks = "127.0.0.1/8";
12 var $postfix_enable_virus_scan = "TRUE";
13 var $postfix_relayhost = "";
14 var $postfix_mxrelayenabled = true;
15 var $postfix_allow_unauthenticated = "FALSE";
16 var $cyrus_quotawarn = "80";
17 var $kolabFreeBusyFuture = "1";
18 var $k = "kolab";
19 var $cyrus_admins = "TRUE";
20 var $cyrus_imap = "TRUE";
21 var $cyrus_pop3 = "TRUE";
22 var $cyrus_imaps = "TRUE";
23 var $cyrus_pop3s = "TRUE";
24 var $cyrus_sieve = "TRUE";
25 var $apache_allow_unauthenticated_fb = "TRUE";
26 var $proftpd_ftp = "TRUE";
27 var $apache_http = "TRUE";
28 var $kolabHost = array();
29 var $orig_cn = "";
31 var $attributes = array("postfix_mydomain", "postfix_mydestination", "proftpd_ftp", "k",
32 "postfix_mynetworks", "postfix_enable_virus_scan", "postfix_relayhost", "apache_http",
33 "postfix_allow_unauthenticated", "cyrus_admins", "cyrus_imap","kolabFreeBusyFuture",
34 "cyrus_pop3", "cyrus_imaps", "cyrus_pop3s", "cyrus_sieve", "apache_allow_unauthenticated_fb",
35 "cyrus_quotawarn");
36 var $objectclasses = array("top", "kolab");
38 function servkolab($config, $dn = NULL)
39 {
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 /* Toggle relayhost */
56 $this->postfix_mxrelayenabled = preg_match('/^\[/', $this->postfix_relayhost);
57 $this->postfix_relayhost = preg_replace("/[\[\]]/","",$this->postfix_relayhost);
59 /* Is this Server a member of the Kolab extension or not ?*/
60 if(isset($this->attrs['kolabHost'])) {
61 $this->kolabHost= $this->attrs['kolabHost'];
62 unset($this->kolabHost['count']);
63 }
64 $this->is_account = false;
65 $this->initially_was_account = false;
66 foreach($this->kolabHost as $host){
67 if($this->hostname == $host){
68 $this->is_account = true;
69 $this->initially_was_account = true;
70 }
71 }
73 /* Parse mynetworks */
74 if(isset($this->attrs['postfix-mynetworks'])){
75 if(is_array($this->attrs['postfix-mynetworks'])){
76 unset($this->attrs['postfix-mynetworks']['count']);
77 $tmp="";
78 foreach($this->attrs['postfix-mynetworks'] as $tm){
79 $tmp.=$tm.";";
80 }
81 $this->postfix_mynetworks = $tmp;
82 }
83 }else{
84 $this->postfix_mynetworks="";
85 }
86 }
89 function execute()
90 {
91 /* Call parent execute */
92 plugin::execute();
94 /***************
95 Variable initialisation
96 ***************/
98 $smarty = get_smarty();
99 $display = "";
100 $ldap = $this->config->get_ldap_link();
103 /* Assemble free/busy string */
104 $edit = sprintf('<input name="kolabFreeBusyFuture" value="%s" %s type="text" maxlength="3" size="4">',
105 $this->kolabFreeBusyFuture,
106 chkacl($this->acl, 'kolabFreeBusyFuture'));
107 $fbfuture = sprintf(_("Include data from %s days in the past when creating free/busy lists"), $edit);
109 /* Assemble quota string */
110 $edit = sprintf('<input name="cyrus_quotawarn" value="%s" type="text" maxlength="3" size="4" %s>',
111 $this->cyrus_quotawarn,
112 chkacl($this->acl, 'cyrus_quotawarn'));
113 $quotastr = sprintf(_("Warn users when using more than %s%% of their mail quota"), $edit);
116 /***************
117 Handle Account is_account state
118 ***************/
120 /* Do we need to flip is_account state? */
121 if (isset($_POST['modify_state'])) {
122 $this->is_account = !$this->is_account;
123 }
125 /* Show tab dialog headers */
126 if ($this->is_account) {
127 /* call Add Acoount to add account */
128 $display = $this->show_header(_("Remove Kolab extension"), _("This server has kolab features enabled. You can disable them by clicking below."));
129 } else {
130 /* call remove Account */
131 $display = $this->show_header(_("Add Kolab service"), _("This server has kolab features disabled. You can enable them by clicking below."));
132 return ($display);
133 }
136 /***************
137 Assign informations to smarty
138 ***************/
140 /* Set relayhost and if we have MX lookup enabled*/
141 if($this->postfix_mxrelayenabled) {
142 $smarty->assign("RelayMxSupportCheck"," checked ");
143 } else {
144 $smarty->assign("RelayMxSupportCheck","");
145 }
147 /* Initialize all attributes, that were submitted */
148 foreach($this->attributes as $val)
149 {
150 $smarty->assign($val."ACL",chkacl($this->acl,str_replace("_","-",$val)));
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 }
159 }
161 $smarty->assign("fbfuture", $fbfuture);
162 $smarty->assign("quotastr", $quotastr);
164 /* Load Template */
165 $display.=$smarty->fetch(get_template_path('servkolab.tpl', TRUE));
166 return ($display);
167 }
169 function remove_from_parent()
170 {
171 /* Only walk through following code, if this host
172 was a member of the kolab hosts, else skip this */
173 if(!$this->initially_was_account){
174 return;
175 }
177 /* !!! Don't use "cn" in this function
178 hostname -> the initial name of the host
179 cn -> is the new name of the host, in case that it was renamed.
180 */
182 $ldap = $this->config->get_ldap_link();
183 $this->dn = "k=kolab,".$this->config->current['BASE'];
185 /* We can't simply remove the whole entry, it is possible that there are
186 some other hosts assigned to this object.
187 So, first of all check if we are the last host entry within the host
188 : Remove k=kolab entry
189 if we aren't alone, only remove host name from hosts entry and save */
190 /* Are we alone? Remove complete entry... */
192 /* Check if we are definitly in kolabHosts */
193 if(!in_array_ics($this->hostname,$this->kolabHost)) {
194 return;
195 }
197 /* Integration check, not translatet because they can't pop up at all, only for debug */
198 if(count($this->kolabHost) == 0){
199 print_red("Server - Kolab tab : This is not possible, we can't remove an account which doesn't exists.");
200 return;
201 }
202 if(!isset($this->hostname) || (empty($this->hostname))){
203 print_red("The required attribute hostname seams to empty.");
204 }
206 /* Our hostname is in kolabHosts and there is a only one entry
207 = we are the last host entry, delete k=kolab entry */
208 if (count($this->kolabHost) == 1){
210 /* Remove complete entry */
211 $ldap->rmdir ($this->dn);
212 show_ldap_error($ldap->get_error(), _("Removing kolab host entry failed"));
213 gosa_log("k=kolab entry removed, ".$this->hostname." was the last kolabHost entry.");
215 } else {
217 /* Only modify kolabHost */
218 $hosts= array();
219 foreach ($this->kolabHost as $host){
220 if($host != $this->hostname){
221 $hosts[]= $host;
222 }
223 }
224 $attrs= array('kolabHost' => $hosts);
225 $ldap->cd($this->dn);
226 $this->cleanup();
227 $ldap->modify ($attrs);
228 show_ldap_error($ldap->get_error(), _("Removing server from kolab object failed"));
229 gosa_log("Removing ".$this->hostname." from list of kolabHosts");
230 }
232 /* Optionally execute a command after we're done */
233 $this->handle_post_events("remove");
234 }
237 function save_object()
238 {
239 if (isset($_POST['kolabtab'])){
240 plugin::save_object();
242 /* Save checkboxes */
243 foreach (array( "postfix_enable_virus_scan", "postfix_allow_unauthenticated",
244 "cyrus_admins", "cyrus_imap", "cyrus_pop3", "cyrus_imaps",
245 "cyrus_pop3s", "cyrus_sieve", "apache_allow_unauthenticated_fb",
246 "proftpd_ftp", "apache_http") as $cb){
247 if (isset($_POST[$cb])){
248 $this->$cb= "TRUE";
249 } else {
250 $this->$cb= "FALSE";
251 }
252 }
254 /* Toggle relay check */
255 $this->postfix_mxrelayenabled= isset($_POST['RelayMxSupport']);
256 }
258 }
261 function check()
262 {
263 /* Call common method to give check the hook */
264 $message= plugin::check();
266 if(($this->kolabFreeBusyFuture=="")) {
267 $message[] = _("Future days in Free/Busy settings must be set.");
268 }elseif(!is_uid($this->kolabFreeBusyFuture) || $this->kolabFreeBusyFuture < 0){
269 $message[] = _("Future days in Free/Busy settings must be a positive value.");
270 }
272 if(!is_int((int)($this->cyrus_quotawarn))) {
273 $message[] = _("The given Quota settings value must be a number.");
274 }elseif(!(($this->cyrus_quotawarn<=100)&&($this->cyrus_quotawarn>=0))){
275 $message[] = _("Please choose a value between 1 and 100 for Quota settings.");
276 }elseif(strcasecmp($this->cyrus_quotawarn,(int)$this->cyrus_quotawarn)){
277 $message[] = _("Future days must be a value.");
278 }
280 if(empty($this->postfix_mynetworks)) {
281 $message[] = _("No SMTP privileged networks set.");
282 }
284 /*if(empty($this->postfix_relayhost)) {
285 $message[] = _("No SMTP smarthost/relayhost set.");
286 }
287 */
289 return ($message);
290 }
293 /* Save to LDAP */
294 function save()
295 {
296 /* Set ldap connection */
297 $ldap = $this->config->get_ldap_link();
299 /* Open current dn*/
300 $this->dn = "k=kolab,".$this->config->current['BASE'];
302 /* Adapt relayhost */
303 $this->postfix_relayhost= preg_replace('/[\[\]]/', '', $this->postfix_relayhost);
304 if (!$this->postfix_mxrelayenabled && $this->postfix_relayhost != ""){
305 $this->postfix_relayhost= "[".$this->postfix_relayhost."]";
306 }
308 /* Check if this server was renamed, in this case we have to remove old cn first*/
309 if($this->hostname != $this->cn){
310 $tmp = array();
311 if(in_array_ics($this->hostname,$this->kolabHost)){
312 foreach($this->kolabHost as $host){
313 if($host != $this->hostname){
314 $tmp[] = $host;
315 }
316 }
317 $this->kolabHost = $tmp;
318 }
319 }
321 /* Add ourselves to the list of kolabHost's if needed */
322 if (!in_array_ics($this->cn,$this->kolabHost)){
323 $this->kolabHost[]= $this->cn;
324 }
326 /* Create mynetworks array by splitting the string with ; */
327 $tmp = split(";",$this->postfix_mynetworks);
328 $this->postfix_mynetworks = array();
329 foreach($tmp as $tm){
330 trim($tm);
331 if(!empty($tm)){
332 $this->postfix_mynetworks[]=$tm;
333 }
334 }
335 $this->attrs['postfix_mynetworks']=$this->postfix_mynetworks;
337 /* Call parents save to prepare $this->attrs */
338 plugin::save();
340 /* Save or modify? */
341 $ldap->cat($this->dn, array('dn'));
342 if (!$ldap->fetch()){
343 $mode= "add";
344 } else {
345 $mode= "modify";
346 }
348 /* Do attribute conversion */
349 foreach ($this->attrs as $key => $value){
350 if (preg_match('/_/', $key)){
351 $old_key= $key;
352 $key= preg_replace('/_/', '-', $key);
353 $this->attrs[$key]= $value;
354 unset($this->attrs[$old_key]);
355 }
356 }
357 /* Add kolab hosts */
358 $this->attrs['kolabHost']= $this->kolabHost;
360 /* Perform LDAP action */
361 $ldap->cd($this->dn);
362 $this->cleanup();;
363 $ldap->$mode($this->attrs);
364 show_ldap_error($ldap->get_error(), _("Saving server to kolab object failed"));
366 /* Optionally execute a command after we're done */
367 if ($this->initially_was_account == $this->is_account) {
368 if ($this->is_modified) {
369 $this->handle_post_events("mofify");
370 }
371 } else {
372 $this->handle_post_events("add");
373 }
374 }
375 }
377 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
378 ?>