1 <?php
3 class servkolab extends plugin {
5 var $postfix_mydomain = "";
6 var $postfix_mydestination = "";
7 var $cyrus_admins = "";
8 var $postfix_mynetworks = "127.0.0.1/8";
9 var $postfix_enable_virus_scan = "TRUE";
10 var $postfix_relayhost = "";
11 var $postfix_mxrelayenabled = true;
12 var $postfix_allow_unauthenticated = "FALSE";
13 var $cyrus_quotawarn = "80";
14 var $kolabFreeBusyFuture = "1";
15 var $k = "kolab";
16 var $cyrus_imap = "TRUE";
17 var $cyrus_pop3 = "TRUE";
18 var $cyrus_imaps = "TRUE";
19 var $cyrus_pop3s = "TRUE";
20 var $cyrus_sieve = "TRUE";
21 var $apache_allow_unauthenticated_fb = "TRUE";
22 var $proftpd_ftp = "TRUE";
23 var $apache_http = "TRUE";
24 var $kolabHost = array();
25 var $orig_cn = "";
27 var $attributes = array("postfix_mydomain", "postfix_mydestination", "proftpd_ftp", "k",
28 "postfix_mynetworks", "postfix_enable_virus_scan", "postfix_relayhost", "apache_http",
29 "postfix_allow_unauthenticated", "cyrus_admins", "cyrus_imap","kolabFreeBusyFuture",
30 "cyrus_pop3", "cyrus_imaps", "cyrus_pop3s", "cyrus_sieve", "apache_allow_unauthenticated_fb",
31 "cyrus_quotawarn");
32 var $objectclasses = array("top", "kolab");
34 function servkolab($config, $dn = NULL, $parent= NULL)
35 {
36 /* Setting the hostname and tell this Plugin that we are the kolab extension*/
37 $this->hostname = preg_replace('/^cn=([^,]+),.*$/', '\1', $dn);
38 $this->dn = "k=kolab,".$config->current['BASE'];
40 /* Load variables, if given*/
41 plugin::plugin($config, $this->dn);
43 /* Copy needed attributes */
44 foreach($this->attributes as $val) {
45 $name = preg_replace('/_/', '-', $val);
46 if (isset($this->attrs["$name"][0])) {
47 $this->$val = $this->attrs["$name"][0];
48 }
49 }
51 /* Toggle relayhost */
52 $this->postfix_mxrelayenabled = preg_match('/^\[/', $this->postfix_relayhost);
53 $this->postfix_relayhost = preg_replace("/[\[\]]/","",$this->postfix_relayhost);
55 /* Is this Server a member of the Kolab extension or not ?*/
56 if(isset($this->attrs['kolabHost'])) {
57 $this->kolabHost= $this->attrs['kolabHost'];
58 unset($this->kolabHost['count']);
59 }
60 $this->is_account = false;
61 $this->initially_was_account = false;
62 foreach($this->kolabHost as $host){
63 if($this->hostname == $host){
64 $this->is_account = true;
65 $this->initially_was_account = true;
66 }
67 }
69 }
72 function execute()
73 {
74 /* Call parent execute */
75 plugin::execute();
77 /***************
78 Variable initialisation
79 ***************/
81 $smarty = get_smarty();
82 $display = "";
83 $ldap = $this->config->get_ldap_link();
86 /* Assemble free/busy string */
87 $edit = sprintf('<input name="kolabFreeBusyFuture" value="%s" %s type="text" maxlength="3" size="4">',
88 $this->kolabFreeBusyFuture,
89 chkacl($this->acl, 'kolabFreeBusyFuture'));
90 $fbfuture = sprintf(_("Include data from %s days in the past when creating free/busy lists"), $edit);
92 /* Assemble quota string */
93 $edit = sprintf('<input name="cyrus_quotawarn" value="%s" type="text" maxlength="3" size="4" %s>',
94 $this->cyrus_quotawarn,
95 chkacl($this->acl, 'cyrus_quotawarn'));
96 $quotastr = sprintf(_("Warn users when using more than %s%% of their mail quota"), $edit);
99 /***************
100 Handle Account is_account state
101 ***************/
103 /* Do we need to flip is_account state? */
104 if (isset($_POST['modify_state'])) {
105 $this->is_account = !$this->is_account;
106 }
108 /* Show tab dialog headers */
109 if ($this->is_account) {
110 /* call Add Acoount to add account */
111 $display = $this->show_header(_("Remove Kolab extension"), _("This server has kolab features enabled. You can disable them by clicking below."));
112 } else {
113 /* call remove Account */
114 $display = $this->show_header(_("Add Kolab service"), _("This server has kolab features disabled. You can enable them by clicking below."));
115 return ($display);
116 }
119 /***************
120 Assign informations to smarty
121 ***************/
123 /* Set relayhost and if we have MX lookup enabled*/
124 if($this->postfix_mxrelayenabled) {
125 $smarty->assign("RelayMxSupportCheck"," checked ");
126 } else {
127 $smarty->assign("RelayMxSupportCheck","");
128 }
130 /* Initialize all attributes, that were submitted */
131 foreach($this->attributes as $val)
132 {
133 $smarty->assign($val."ACL",chkacl($this->acl,str_replace("_","-",$val)));
135 /* Tell smarty which variables we are useing */
136 $smarty->assign($val, $this->$val);
137 if (($this->$val != "FALSE") && !empty($this->$val)){
138 $smarty->assign($val."Check", "checked");
139 } else {
140 $smarty->assign($val."Check", "");
141 }
142 }
144 $smarty->assign("fbfuture", $fbfuture);
145 $smarty->assign("quotastr", $quotastr);
147 /* Load Template */
148 $display.=$smarty->fetch(get_template_path('servkolab.tpl', TRUE));
149 return ($display);
150 }
152 function remove_from_parent()
153 {
154 /* Only walk through following code, if this host
155 was a member of the kolab hosts, else skip this */
156 if(!$this->initially_was_account){
157 return;
158 }
160 /* !!! Don't use "cn" in this function
161 hostname -> the initial name of the host
162 cn -> is the new name of the host, in case that it was renamed.
163 */
165 $ldap = $this->config->get_ldap_link();
166 $this->dn = "k=kolab,".$this->config->current['BASE'];
168 /* We can't simply remove the whole entry, it is possible that there are
169 some other hosts assigned to this object.
170 So, first of all check if we are the last host entry within the host
171 : Remove k=kolab entry
172 if we aren't alone, only remove host name from hosts entry and save */
173 /* Are we alone? Remove complete entry... */
175 /* Check if we are definitly in kolabHosts */
176 if(!in_array_ics($this->hostname,$this->kolabHost)) {
177 return;
178 }
180 /* Integration check, not translatet because they can't pop up at all, only for debug */
181 if(count($this->kolabHost) == 0){
182 print_red("Server - Kolab tab : This is not possible, we can't remove an account which doesn't exists.");
183 return;
184 }
185 if(!isset($this->hostname) || (empty($this->hostname))){
186 print_red("The required attribute hostname seams to empty.");
187 }
189 /* Our hostname is in kolabHosts and there is a only one entry
190 = we are the last host entry, delete k=kolab entry */
191 if (count($this->kolabHost) == 1){
193 /* Remove complete entry */
194 $ldap->rmdir ($this->dn);
195 show_ldap_error($ldap->get_error(), _("Removing kolab host entry failed"));
196 gosa_log("k=kolab entry removed, ".$this->hostname." was the last kolabHost entry.");
198 } else {
200 /* Only modify kolabHost */
201 $hosts= array();
202 foreach ($this->kolabHost as $host){
203 if($host != $this->hostname){
204 $hosts[]= $host;
205 }
206 }
207 $attrs= array('kolabHost' => $hosts);
208 $ldap->cd($this->dn);
209 $this->cleanup();
210 $ldap->modify ($attrs);
211 show_ldap_error($ldap->get_error(), _("Removing server from kolab object failed"));
212 gosa_log("Removing ".$this->hostname." from list of kolabHosts");
213 }
215 /* Optionally execute a command after we're done */
216 $this->handle_post_events("remove");
217 }
220 function save_object()
221 {
222 if (isset($_POST['kolabtab'])){
223 plugin::save_object();
225 /* Save checkboxes */
226 foreach (array( "postfix_enable_virus_scan", "postfix_allow_unauthenticated",
227 "cyrus_imap", "cyrus_pop3", "cyrus_imaps",
228 "cyrus_pop3s", "cyrus_sieve", "apache_allow_unauthenticated_fb",
229 "proftpd_ftp", "apache_http") as $cb){
230 if (isset($_POST[$cb])){
231 $this->$cb= "TRUE";
232 } else {
233 $this->$cb= "FALSE";
234 }
235 }
237 /* Toggle relay check */
238 $this->postfix_mxrelayenabled= isset($_POST['RelayMxSupport']);
239 }
241 }
244 function check()
245 {
246 /* Call common method to give check the hook */
247 $message= plugin::check();
249 if(($this->kolabFreeBusyFuture=="")) {
250 $message[] = _("Future days in Free/Busy settings must be set.");
251 }elseif(!is_uid($this->kolabFreeBusyFuture) || $this->kolabFreeBusyFuture < 0){
252 $message[] = _("Future days in Free/Busy settings must be a positive value.");
253 }
255 if(!is_int((int)($this->cyrus_quotawarn))) {
256 $message[] = _("The given Quota settings value must be a number.");
257 }elseif(!(($this->cyrus_quotawarn<=100)&&($this->cyrus_quotawarn>=0))){
258 $message[] = _("Please choose a value between 1 and 100 for Quota settings.");
259 }elseif(strcasecmp($this->cyrus_quotawarn,(int)$this->cyrus_quotawarn)){
260 $message[] = _("Future days must be a value.");
261 }
263 if(empty($this->postfix_mynetworks)) {
264 $message[] = _("No SMTP privileged networks set.");
265 }
267 /*if(empty($this->postfix_relayhost)) {
268 $message[] = _("No SMTP smarthost/relayhost set.");
269 }
270 */
272 return ($message);
273 }
276 /* Save to LDAP */
277 function save()
278 {
279 /* Set ldap connection */
280 $ldap = $this->config->get_ldap_link();
282 /* Open current dn*/
283 $this->dn = "k=kolab,".$this->config->current['BASE'];
285 /* Adapt relayhost */
286 $this->postfix_relayhost= preg_replace('/[\[\]]/', '', $this->postfix_relayhost);
287 if (!$this->postfix_mxrelayenabled && $this->postfix_relayhost != ""){
288 $this->postfix_relayhost= "[".$this->postfix_relayhost."]";
289 }
291 /* Check if this server was renamed, in this case we have to remove old cn first*/
292 if($this->hostname != $this->cn){
293 $tmp = array();
294 if(in_array_ics($this->hostname,$this->kolabHost)){
295 foreach($this->kolabHost as $host){
296 if($host != $this->hostname){
297 $tmp[] = $host;
298 }
299 }
300 $this->kolabHost = $tmp;
301 }
302 }
304 /* Add ourselves to the list of kolabHost's if needed */
305 if (!in_array_ics($this->cn,$this->kolabHost)){
306 $this->kolabHost[]= $this->cn;
307 }
309 /* Call parents save to prepare $this->attrs */
310 plugin::save();
312 /* Save or modify? */
313 $ldap->cat($this->dn, array('dn'));
314 if (!$ldap->fetch()){
315 $mode= "add";
316 } else {
317 $mode= "modify";
318 }
320 /* Do attribute conversion */
321 foreach ($this->attrs as $key => $value){
322 if (preg_match('/_/', $key)){
323 $old_key= $key;
324 $key= preg_replace('/_/', '-', $key);
325 $this->attrs[$key]= $value;
326 unset($this->attrs[$old_key]);
327 }
328 }
329 /* Add kolab hosts */
330 $this->attrs['kolabHost']= $this->kolabHost;
332 /* Perform LDAP action */
333 $ldap->cd($this->dn);
334 $this->cleanup();;
335 $ldap->$mode($this->attrs);
336 show_ldap_error($ldap->get_error(), _("Saving server to kolab object failed"));
338 /* Optionally execute a command after we're done */
339 if ($this->initially_was_account == $this->is_account) {
340 if ($this->is_modified) {
341 $this->handle_post_events("modify");
342 }
343 } else {
344 $this->handle_post_events("add");
345 }
346 }
347 }
349 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
350 ?>