Code

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@576 594d385d-05f5-0310...
[gosa.git] / plugins / admin / systems / class_servKolab.inc
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   
30   var $attributes =  array("postfix_mydomain", "postfix_mydestination", "proftpd_ftp", "k",
31         "postfix_mynetworks", "postfix_enable_virus_scan", "postfix_relayhost", "apache_http",
32         "postfix_allow_unauthenticated", "cyrus_admins", "cyrus_imap","kolabFreeBusyFuture",
33         "cyrus_pop3", "cyrus_imaps", "cyrus_pop3s", "cyrus_sieve", "apache_allow_unauthenticated_fb",
34         "cyrus_quotawarn");
35   var $objectclasses = array("top", "kolab");
37   function servkolab($config, $dn = NULL) 
38   {
39     /* Setting the hostname and tell this Plugin that we are the kolab extension*/
40     $this->hostname= preg_replace('/^cn=([^,]+),.*$/', '\1', $dn);
41     $this->dn = "k=kolab,".$config->current['BASE'];
42     
43     /* Load variables, if given*/
44     plugin::plugin($config, $this->dn);
46     /* Copy needed attributes */
47     foreach($this->attributes as $val) {
48       $name = preg_replace('/_/', '-', $val);
49       if (isset($this->attrs["$name"][0])) {
50         $this->$val = $this->attrs["$name"][0];
51       }
52     }
53   
54     /* Toggle relayhost */
55     $this->postfix_mxrelayenabled= preg_match('/^\[/', $this->postfix_relayhost);
56     $this->postfix_relayhost = preg_replace("/[\[\]]/","",$this->postfix_relayhost);
58     /* Is this Server a member of the Kolab extension or not ?*/ 
59     if(isset($this->attrs['kolabHost'])) {
60       $this->kolabHost= $this->attrs['kolabHost'];
61       unset($this->kolabHost['count']);
62     }
63     if(in_array($this->hostname, $this->kolabHost)) {
64       $this->is_account=true;
65     } else {   
66       $this->is_account=false;    
67     } 
68   }
71   function execute() 
72   {
73     /* Fill templating stuff */
74     $smarty = get_smarty();
75     $display = "";
77     /* The Ldap link is needed to ask ldap some questions */
78     $ldap = $this->config->get_ldap_link();
80     /* Do we need to flip is_account state? */
81     if (isset($_POST['modify_state'])) {
82       $this->is_account = !$this->is_account;
83     }
85     /* Show tab dialog headers */
86     if ($this->is_account) {
87       /* call Add Acoount to add account */
88       $display = $this->show_header(_("Remove Kolab extension"), _("This server has kolab features enabled. You can disable them by clicking below."));
89     } else {
90       /* call remove Account */
91       $display = $this->show_header(_("Add Kolab service"), _("This server has kolab features disabled. You can enable them by clicking below."));
92       return ($display);
93     }
95     /* Set relayhost and if we have MX lookup enabled*/
96     if($this->postfix_mxrelayenabled) {
97       $smarty->assign("RelayMxSupportCheck"," checked ");
98     } else {
99       $smarty->assign("RelayMxSupportCheck","");
100     }
101     
102     /* Initialize all attributes, that were submitted */
103     foreach($this->attributes as $val) 
104     {
105       $smarty->assign($val."ACL",chkacl($this->acl,str_replace("_","-",$val)));
107       /* Tell smarty which variables we are useing */
108       $smarty->assign($val, $this->$val);
109       if (($this->$val != "FALSE") && !empty($this->$val)){
110         $smarty->assign($val."Check", "checked");
111       } else {
112         $smarty->assign($val."Check", "");
113       }
114     }
116     /* Assemble free/busy string */
117     $edit= sprintf('<input name="kolabFreeBusyFuture" value="%s" %s type="text" maxlength="3" size="4">',
118             $this->kolabFreeBusyFuture, chkacl($this->acl, 'kolabFreeBusyFuture'));
119     $fbfuture= sprintf(_("Include data from %s days in the past when creating free/busy lists"), $edit);
120     $smarty->assign("fbfuture", $fbfuture);
122     /* Assemble quota string */
123     $edit= sprintf('<input name="cyrus_quotawarn" value="%s" type="text" maxlength="3" size="4" %s>',
124           $this->cyrus_quotawarn, chkacl($this->acl, 'cyrus_quotawarn'));
125     $quotastr= sprintf(_("Warn users when using more than %s%% of their mail quota"), $edit);
126     $smarty->assign("quotastr", $quotastr);
128     /* Load Template */
129     $display.=$smarty->fetch(get_template_path('servkolab.tpl', TRUE));
130     return ($display);
131   }
133   function remove_from_parent() 
134   {
135     $ldap= $this->config->get_ldap_link();
136     $this->dn = "k=kolab,".$this->config->current['BASE'];
138     if (count($this->kolabHost) == 0){
139       return;
140     }
142     /* Are we alone? Remove complete entry... */
143     if (count($this->kolabHost) == 1){
145       /* Remove complete entry */
146       $ldap->rmdir ($this->dn);
147       show_ldap_error($ldap->get_error());
148       
149     } else {
151       /* Only modify kolabHost */
152       $hosts= array();
153       foreach ($this->kolabHost as $host){
154         if ($host != $this->cn){
155           $hosts[]= $host;
156         }
157       }
158       $attrs= array('kolabHost' => $hosts);
159       $ldap->cd($this->dn);
160       $ldap->modify($attrs);
161       show_ldap_error($ldap->get_error());
162     }
164     /* Optionally execute a command after we're done */
165     $this->handle_post_events("remove");
166   }
169   function save_object()    
170   {
171     if (isset($_POST['kolabtab'])){
172       plugin::save_object();
174       /* Save checkboxes */
175       foreach (array( "postfix_enable_virus_scan", "postfix_allow_unauthenticated",
176                       "cyrus_admins", "cyrus_imap", "cyrus_pop3", "cyrus_imaps",
177                       "cyrus_pop3s", "cyrus_sieve", "apache_allow_unauthenticated_fb",
178                       "proftpd_ftp", "apache_http") as $cb){
179         if (isset($_POST[$cb])){
180           $this->$cb= "TRUE";
181         } else {
182           $this->$cb= "FALSE";
183         }
184       }
186       /* Toggle relay check */
187       $this->postfix_mxrelayenabled= isset($_POST['RelayMxSupport']);
188     }
190   }
193   function check() 
194   {
195     $message = array();
196     if(($this->kolabFreeBusyFuture==""))    {
197       $message[] = _("Future days in Free/Busy settings must be set.");
198     }elseif(!is_uid($this->kolabFreeBusyFuture) || $this->kolabFreeBusyFuture < 0){
199       $message[] = _("Future days in Free/Busy settings must be a positive value.");
200     }
202     if(!is_int((int)($this->cyrus_quotawarn))) {
203       $message[] = _("The given Quota settings value must be a number.");
204     }elseif(!(($this->cyrus_quotawarn<=100)&&($this->cyrus_quotawarn>=0))){
205       $message[] = _("Please choose a value between 1 and 100 for Quota settings.");
206     }elseif(strcasecmp($this->cyrus_quotawarn,(int)$this->cyrus_quotawarn)){
207       $message[] = _("Future days must be a value.");
208     }
210     if(empty($this->postfix_mynetworks)) { 
211       $message[] = _("No SMTP privileged networks set.");
212     }
214     if(empty($this->postfix_relayhost)) {
215       $message[] = _("No SMTP smarthost/relayhost set.");
216     }
218     return ($message);
219   }
222   /* Save to LDAP */
223   function save() 
224   {
225     /* Set ldap connection */
226     $ldap = $this->config->get_ldap_link();
227     
228     /* Open current dn*/
229     $this->dn = "k=kolab,".$this->config->current['BASE'];
230   
231     /* Adapt relayhost */
232     $this->postfix_relayhost= preg_replace('/[\[\]]/', '', $this->postfix_relayhost);
233     if (!$this->postfix_mxrelayenabled && $this->postfix_relayhost != ""){
234       $this->postfix_relayhost= "[".$this->postfix_relayhost."]";
235     }
237     /* Add ourselves to the list of kolabHost's if needed */
238     if (!in_array($this->cn, $this->kolabHost)){
239       $this->kolabHost[]= $this->cn;
240     }
242     /* Call parents save to prepare $this->attrs */
243     plugin::save();
245     /* Save or modify? */
246     $ldap->cat($this->dn);
247     if (!$ldap->fetch()){
248       $mode= "add"; 
249     } else {
250       $mode= "modify";
251     }
253     /* Do attribute conversion */
254     foreach ($this->attrs as $key => $value){
255       if (preg_match('/_/', $key)){
256         $old_key= $key;
257         $key= preg_replace('/_/', '-', $key);
258         $this->attrs[$key]= $value;
259         unset($this->attrs[$old_key]);
260       }
261     }
263     /* Add kolab hosts */
264     $this->attrs['kolabHost']= $this->kolabHost;
266     /* Perform LDAP action */
267     $ldap->cd($this->dn);
268     $ldap->$mode($this->attrs);
269     show_ldap_error($ldap->get_error());
270     
271     /* Optionally execute a command after we're done */
272     if ($this->initially_was_account == $this->is_account) {
273       if ($this->is_modified) {
274         $this->handle_post_events("mofify");
275       }
276     } else {
277       $this->handle_post_events("add");
278     }
280   }
284 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
285 ?>