4145f5525dd6e45a2e3ff96cc222b105d795b362
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 $is_in_there = false;
30 var $exactName = false;
32 var $orig_cn = "";
34 var $attributes = array("postfix_mydomain", "postfix_mydestination", "proftpd_ftp", "k",
35 "postfix_mynetworks", "postfix_enable_virus_scan", "postfix_relayhost", "apache_http",
36 "postfix_allow_unauthenticated", "cyrus_admins", "cyrus_imap","kolabFreeBusyFuture",
37 "cyrus_pop3", "cyrus_imaps", "cyrus_pop3s", "cyrus_sieve", "apache_allow_unauthenticated_fb",
38 "cyrus_quotawarn");
39 var $objectclasses = array("top", "kolab");
41 function servkolab($config, $dn = NULL)
42 {
43 /* Setting the hostname and tell this Plugin that we are the kolab extension*/
44 $this->hostname = preg_replace('/^cn=([^,]+),.*$/', '\1', $dn);
45 $this->dn = "k=kolab,".$config->current['BASE'];
47 /* Load variables, if given*/
48 plugin::plugin($config, $this->dn);
50 /* Copy needed attributes */
51 foreach($this->attributes as $val) {
52 $name = preg_replace('/_/', '-', $val);
53 if (isset($this->attrs["$name"][0])) {
54 $this->$val = $this->attrs["$name"][0];
55 }
56 }
58 /* Toggle relayhost */
59 $this->postfix_mxrelayenabled = preg_match('/^\[/', $this->postfix_relayhost);
60 $this->postfix_relayhost = preg_replace("/[\[\]]/","",$this->postfix_relayhost);
62 /* Is this Server a member of the Kolab extension or not ?*/
63 if(isset($this->attrs['kolabHost'])) {
64 $this->kolabHost= $this->attrs['kolabHost'];
65 unset($this->kolabHost['count']);
66 }
67 $this->is_in_there = false;
68 $this->is_account = false;
69 $this->initially_was_account = false;
70 foreach($this->kolabHost as $host){
71 if(preg_match("/".$this->hostname.".*/i",$host)){
72 $this->is_account = true;
73 $this->is_in_there = true;
74 $this->initially_was_account = true;
75 }
76 }
79 /* Mhh */
80 if(in_array($this->hostname, $this->kolabHost)) {
81 $this->exactName=true;
82 } else {
83 $this->exactName=false;
84 }
86 /* Parse mynetworks */
87 if(isset($this->attrs['postfix-mynetworks'])){
88 if(is_array($this->attrs['postfix-mynetworks'])){
89 unset($this->attrs['postfix-mynetworks']['count']);
90 $tmp="";
91 foreach($this->attrs['postfix-mynetworks'] as $tm){
92 $tmp.=$tm.";";
93 }
94 $this->postfix_mynetworks = $tmp;
95 }
96 }else{
97 $this->postfix_mynetworks="";
98 }
99 }
102 function execute()
103 {
104 /* Call parent execute */
105 plugin::execute();
107 /***************
108 Variable initialisation
109 ***************/
111 $smarty = get_smarty();
112 $display = "";
113 $ldap = $this->config->get_ldap_link();
116 /* Assemble free/busy string */
117 $edit = sprintf('<input name="kolabFreeBusyFuture" value="%s" %s type="text" maxlength="3" size="4">',
118 $this->kolabFreeBusyFuture,
119 chkacl($this->acl, 'kolabFreeBusyFuture'));
120 $fbfuture = sprintf(_("Include data from %s days in the past when creating free/busy lists"), $edit);
122 /* Assemble quota string */
123 $edit = sprintf('<input name="cyrus_quotawarn" value="%s" type="text" maxlength="3" size="4" %s>',
124 $this->cyrus_quotawarn,
125 chkacl($this->acl, 'cyrus_quotawarn'));
126 $quotastr = sprintf(_("Warn users when using more than %s%% of their mail quota"), $edit);
129 /***************
130 Handle Account is_account state
131 ***************/
133 /* Do we need to flip is_account state? */
134 if (isset($_POST['modify_state'])) {
135 $this->is_account = !$this->is_account;
136 }
138 /* Show tab dialog headers */
139 if ($this->is_account) {
140 /* call Add Acoount to add account */
141 $display = $this->show_header(_("Remove Kolab extension"), _("This server has kolab features enabled. You can disable them by clicking below."));
142 } else {
143 /* call remove Account */
144 $display = $this->show_header(_("Add Kolab service"), _("This server has kolab features disabled. You can enable them by clicking below."));
145 return ($display);
146 }
149 /***************
150 Assign informations to smarty
151 ***************/
153 /* Set relayhost and if we have MX lookup enabled*/
154 if($this->postfix_mxrelayenabled) {
155 $smarty->assign("RelayMxSupportCheck"," checked ");
156 } else {
157 $smarty->assign("RelayMxSupportCheck","");
158 }
160 /* Initialize all attributes, that were submitted */
161 foreach($this->attributes as $val)
162 {
163 $smarty->assign($val."ACL",chkacl($this->acl,str_replace("_","-",$val)));
165 /* Tell smarty which variables we are useing */
166 $smarty->assign($val, $this->$val);
167 if (($this->$val != "FALSE") && !empty($this->$val)){
168 $smarty->assign($val."Check", "checked");
169 } else {
170 $smarty->assign($val."Check", "");
171 }
172 }
174 $smarty->assign("fbfuture", $fbfuture);
175 $smarty->assign("quotastr", $quotastr);
177 /* Load Template */
178 $display.=$smarty->fetch(get_template_path('servkolab.tpl', TRUE));
179 return ($display);
180 }
182 function remove_from_parent()
183 {
184 /* Only walk through following code, if this host
185 was a member of the kolab hosts, else skip this */
186 if(!$this->initially_was_account){
187 return;
188 }
190 /* !!! Don't use "cn" in this function
191 hostname -> the initial name of the host
192 cn -> is the new name of the host, in case that it was renamed.
193 */
195 $ldap = $this->config->get_ldap_link();
196 $this->dn = "k=kolab,".$this->config->current['BASE'];
198 /* We can't simply remove the whole entry, it is possible that there are
199 some other hosts assigned to this object.
200 So, first of all check if we are the last host entry within the host
201 : Remove k=kolab entry
202 if we aren't alone, only remove host name from hosts entry and save */
203 /* Are we alone? Remove complete entry... */
205 /* Check if we are definitly in kolabHosts */
206 if(!in_array_ics($this->hostname,$this->kolabHost)) {
207 return;
208 }
210 /* Integration check, not translatet because they can't pop up at all, only for debug */
211 if(count($this->kolabHost) == 0){
212 print_red("Server - Kolab tab : This is not possible, we can't remove an account which doesn't exists.");
213 return;
214 }
215 if(!isset($this->hostname) || (empty($this->hostname))){
216 print_red("The required attribute hostname seams to empty.");
217 }
219 /* Our hostname is in kolabHosts and there is a only one entry
220 = we are the last host entry, delete k=kolab entry */
221 if (count($this->kolabHost) == 1){
223 /* Remove complete entry */
224 $ldap->rmdir ($this->dn);
225 show_ldap_error($ldap->get_error(), _("Removing kolab host entry failed"));
226 gosa_log("k=kolab entry removed, ".$this->hostname." was the last kolabHost entry.");
228 } else {
230 /* Only modify kolabHost */
231 $hosts= array();
232 foreach ($this->kolabHost as $host){
233 if($host != $this->hostname){
234 $hosts[]= $host;
235 }
236 }
237 $attrs= array('kolabHost' => $hosts);
238 $ldap->cd($this->dn);
239 $this->cleanup();
240 $ldap->modify ($attrs);
241 show_ldap_error($ldap->get_error(), _("Removing server from kolab object failed"));
242 gosa_log("Removing ".$this->hostname." from list of kolabHosts");
243 }
245 /* Optionally execute a command after we're done */
246 $this->handle_post_events("remove");
247 }
250 function save_object()
251 {
252 if (isset($_POST['kolabtab'])){
253 plugin::save_object();
255 /* Save checkboxes */
256 foreach (array( "postfix_enable_virus_scan", "postfix_allow_unauthenticated",
257 "cyrus_admins", "cyrus_imap", "cyrus_pop3", "cyrus_imaps",
258 "cyrus_pop3s", "cyrus_sieve", "apache_allow_unauthenticated_fb",
259 "proftpd_ftp", "apache_http") as $cb){
260 if (isset($_POST[$cb])){
261 $this->$cb= "TRUE";
262 } else {
263 $this->$cb= "FALSE";
264 }
265 }
267 /* Toggle relay check */
268 $this->postfix_mxrelayenabled= isset($_POST['RelayMxSupport']);
269 }
271 }
274 function check()
275 {
276 /* Call common method to give check the hook */
277 $message= plugin::check();
279 if(($this->kolabFreeBusyFuture=="")) {
280 $message[] = _("Future days in Free/Busy settings must be set.");
281 }elseif(!is_uid($this->kolabFreeBusyFuture) || $this->kolabFreeBusyFuture < 0){
282 $message[] = _("Future days in Free/Busy settings must be a positive value.");
283 }
285 if(!is_int((int)($this->cyrus_quotawarn))) {
286 $message[] = _("The given Quota settings value must be a number.");
287 }elseif(!(($this->cyrus_quotawarn<=100)&&($this->cyrus_quotawarn>=0))){
288 $message[] = _("Please choose a value between 1 and 100 for Quota settings.");
289 }elseif(strcasecmp($this->cyrus_quotawarn,(int)$this->cyrus_quotawarn)){
290 $message[] = _("Future days must be a value.");
291 }
293 if(empty($this->postfix_mynetworks)) {
294 $message[] = _("No SMTP privileged networks set.");
295 }
297 /*if(empty($this->postfix_relayhost)) {
298 $message[] = _("No SMTP smarthost/relayhost set.");
299 }
300 */
302 return ($message);
303 }
306 /* Save to LDAP */
307 function save()
308 {
309 /* Set ldap connection */
310 $ldap = $this->config->get_ldap_link();
312 /* Open current dn*/
313 $this->dn = "k=kolab,".$this->config->current['BASE'];
315 /* Adapt relayhost */
316 $this->postfix_relayhost= preg_replace('/[\[\]]/', '', $this->postfix_relayhost);
317 if (!$this->postfix_mxrelayenabled && $this->postfix_relayhost != ""){
318 $this->postfix_relayhost= "[".$this->postfix_relayhost."]";
319 }
321 /* Check if this server was renamed, in this case we have to remove old cn first*/
322 if($this->hostname != $this->cn){
323 $tmp = array();
324 if(in_array_ics($this->hostname,$this->kolabHost)){
325 foreach($this->kolabHost as $host){
326 if($host != $this->hostname){
327 $tmp[] = $host;
328 }
329 }
330 }
331 $this->kolabHost = $tmp;
332 }
334 /* Add ourselves to the list of kolabHost's if needed */
335 if (!in_array($this->cn,$this->kolabHost)){
336 $this->kolabHost[]= $this->cn;
337 }
339 /* Create mynetworks array by splitting the string with ; */
340 $tmp = split(";",$this->postfix_mynetworks);
341 $this->postfix_mynetworks = array();
342 foreach($tmp as $tm){
343 trim($tm);
344 if(!empty($tm)){
345 $this->postfix_mynetworks[]=$tm;
346 }
347 }
348 $this->attrs['postfix_mynetworks']=$this->postfix_mynetworks;
350 /* Call parents save to prepare $this->attrs */
351 plugin::save();
353 /* Save or modify? */
354 $ldap->cat($this->dn, array('dn'));
355 if (!$ldap->fetch()){
356 $mode= "add";
357 } else {
358 $mode= "modify";
359 }
361 /* Do attribute conversion */
362 foreach ($this->attrs as $key => $value){
363 if (preg_match('/_/', $key)){
364 $old_key= $key;
365 $key= preg_replace('/_/', '-', $key);
366 $this->attrs[$key]= $value;
367 unset($this->attrs[$old_key]);
368 }
369 }
370 /* Add kolab hosts */
371 $this->attrs['kolabHost']= $this->kolabHost;
373 if(($this->is_in_there)&&(!$this->exactName)){
374 unset($this->attrs['kolabHost']);
375 }
377 /* Perform LDAP action */
378 $ldap->cd($this->dn);
379 $this->cleanup();;
380 $ldap->$mode($this->attrs);
381 show_ldap_error($ldap->get_error(), _("Saving server to kolab object failed"));
383 /* Optionally execute a command after we're done */
384 if ($this->initially_was_account == $this->is_account) {
385 if ($this->is_modified) {
386 $this->handle_post_events("mofify");
387 }
388 } else {
389 $this->handle_post_events("add");
390 }
391 }
392 }
394 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
395 ?>