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 $cyrus_admins = "";
12 var $postfix_mynetworks = "127.0.0.1/8";
13 var $postfix_enable_virus_scan = "TRUE";
14 var $postfix_relayhost = "";
15 var $postfix_mxrelayenabled = true;
16 var $postfix_allow_unauthenticated = "FALSE";
17 var $cyrus_quotawarn = "80";
18 var $kolabFreeBusyFuture = "1";
19 var $k = "kolab";
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, $parent= 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 }
76 function execute()
77 {
78 /* Call parent execute */
79 plugin::execute();
81 /***************
82 Variable initialisation
83 ***************/
85 $smarty = get_smarty();
86 $display = "";
87 $ldap = $this->config->get_ldap_link();
90 /* Assemble free/busy string */
91 $edit = sprintf('<input name="kolabFreeBusyFuture" value="%s" %s type="text" maxlength="3" size="4">',
92 $this->kolabFreeBusyFuture,
93 chkacl($this->acl, 'kolabFreeBusyFuture'));
94 $fbfuture = sprintf(_("Include data from %s days in the past when creating free/busy lists"), $edit);
96 /* Assemble quota string */
97 $edit = sprintf('<input name="cyrus_quotawarn" value="%s" type="text" maxlength="3" size="4" %s>',
98 $this->cyrus_quotawarn,
99 chkacl($this->acl, 'cyrus_quotawarn'));
100 $quotastr = sprintf(_("Warn users when using more than %s%% of their mail quota"), $edit);
103 /***************
104 Handle Account is_account state
105 ***************/
107 /* Do we need to flip is_account state? */
108 if (isset($_POST['modify_state'])) {
109 $this->is_account = !$this->is_account;
110 }
112 /* Show tab dialog headers */
113 if ($this->is_account) {
114 /* call Add Acoount to add account */
115 $display = $this->show_header(_("Remove Kolab extension"), _("This server has kolab features enabled. You can disable them by clicking below."));
116 } else {
117 /* call remove Account */
118 $display = $this->show_header(_("Add Kolab service"), _("This server has kolab features disabled. You can enable them by clicking below."));
119 return ($display);
120 }
123 /***************
124 Assign informations to smarty
125 ***************/
127 /* Set relayhost and if we have MX lookup enabled*/
128 if($this->postfix_mxrelayenabled) {
129 $smarty->assign("RelayMxSupportCheck"," checked ");
130 } else {
131 $smarty->assign("RelayMxSupportCheck","");
132 }
134 /* Initialize all attributes, that were submitted */
135 foreach($this->attributes as $val)
136 {
137 $smarty->assign($val."ACL",chkacl($this->acl,str_replace("_","-",$val)));
139 /* Tell smarty which variables we are useing */
140 $smarty->assign($val, $this->$val);
141 if (($this->$val != "FALSE") && !empty($this->$val)){
142 $smarty->assign($val."Check", "checked");
143 } else {
144 $smarty->assign($val."Check", "");
145 }
146 }
148 $smarty->assign("fbfuture", $fbfuture);
149 $smarty->assign("quotastr", $quotastr);
151 /* Load Template */
152 $display.=$smarty->fetch(get_template_path('servkolab.tpl', TRUE));
153 return ($display);
154 }
156 function remove_from_parent()
157 {
158 /* Only walk through following code, if this host
159 was a member of the kolab hosts, else skip this */
160 if(!$this->initially_was_account){
161 return;
162 }
164 /* !!! Don't use "cn" in this function
165 hostname -> the initial name of the host
166 cn -> is the new name of the host, in case that it was renamed.
167 */
169 $ldap = $this->config->get_ldap_link();
170 $this->dn = "k=kolab,".$this->config->current['BASE'];
172 /* We can't simply remove the whole entry, it is possible that there are
173 some other hosts assigned to this object.
174 So, first of all check if we are the last host entry within the host
175 : Remove k=kolab entry
176 if we aren't alone, only remove host name from hosts entry and save */
177 /* Are we alone? Remove complete entry... */
179 /* Check if we are definitly in kolabHosts */
180 if(!in_array_ics($this->hostname,$this->kolabHost)) {
181 return;
182 }
184 /* Integration check, not translatet because they can't pop up at all, only for debug */
185 if(count($this->kolabHost) == 0){
186 print_red("Server - Kolab tab : This is not possible, we can't remove an account which doesn't exists.");
187 return;
188 }
189 if(!isset($this->hostname) || (empty($this->hostname))){
190 print_red("The required attribute hostname seams to empty.");
191 }
193 /* Our hostname is in kolabHosts and there is a only one entry
194 = we are the last host entry, delete k=kolab entry */
195 if (count($this->kolabHost) == 1){
197 /* Remove complete entry */
198 $ldap->rmdir ($this->dn);
199 show_ldap_error($ldap->get_error(), _("Removing kolab host entry failed"));
200 gosa_log("k=kolab entry removed, ".$this->hostname." was the last kolabHost entry.");
202 } else {
204 /* Only modify kolabHost */
205 $hosts= array();
206 foreach ($this->kolabHost as $host){
207 if($host != $this->hostname){
208 $hosts[]= $host;
209 }
210 }
211 $attrs= array('kolabHost' => $hosts);
212 $ldap->cd($this->dn);
213 $this->cleanup();
214 $ldap->modify ($attrs);
215 show_ldap_error($ldap->get_error(), _("Removing server from kolab object failed"));
216 gosa_log("Removing ".$this->hostname." from list of kolabHosts");
217 }
219 /* Optionally execute a command after we're done */
220 $this->handle_post_events("remove");
221 }
224 function save_object()
225 {
226 if (isset($_POST['kolabtab'])){
227 plugin::save_object();
229 /* Save checkboxes */
230 foreach (array( "postfix_enable_virus_scan", "postfix_allow_unauthenticated",
231 "cyrus_imap", "cyrus_pop3", "cyrus_imaps",
232 "cyrus_pop3s", "cyrus_sieve", "apache_allow_unauthenticated_fb",
233 "proftpd_ftp", "apache_http") as $cb){
234 if (isset($_POST[$cb])){
235 $this->$cb= "TRUE";
236 } else {
237 $this->$cb= "FALSE";
238 }
239 }
241 /* Toggle relay check */
242 $this->postfix_mxrelayenabled= isset($_POST['RelayMxSupport']);
243 }
245 }
248 function check()
249 {
250 /* Call common method to give check the hook */
251 $message= plugin::check();
253 if(($this->kolabFreeBusyFuture=="")) {
254 $message[] = _("Future days in Free/Busy settings must be set.");
255 }elseif(!is_uid($this->kolabFreeBusyFuture) || $this->kolabFreeBusyFuture < 0){
256 $message[] = _("Future days in Free/Busy settings must be a positive value.");
257 }
259 if(!is_int((int)($this->cyrus_quotawarn))) {
260 $message[] = _("The given Quota settings value must be a number.");
261 }elseif(!(($this->cyrus_quotawarn<=100)&&($this->cyrus_quotawarn>=0))){
262 $message[] = _("Please choose a value between 1 and 100 for Quota settings.");
263 }elseif(strcasecmp($this->cyrus_quotawarn,(int)$this->cyrus_quotawarn)){
264 $message[] = _("Future days must be a value.");
265 }
267 if(empty($this->postfix_mynetworks)) {
268 $message[] = _("No SMTP privileged networks set.");
269 }
271 /*if(empty($this->postfix_relayhost)) {
272 $message[] = _("No SMTP smarthost/relayhost set.");
273 }
274 */
276 return ($message);
277 }
280 /* Save to LDAP */
281 function save()
282 {
283 /* Set ldap connection */
284 $ldap = $this->config->get_ldap_link();
286 /* Open current dn*/
287 $this->dn = "k=kolab,".$this->config->current['BASE'];
289 /* Adapt relayhost */
290 $this->postfix_relayhost= preg_replace('/[\[\]]/', '', $this->postfix_relayhost);
291 if (!$this->postfix_mxrelayenabled && $this->postfix_relayhost != ""){
292 $this->postfix_relayhost= "[".$this->postfix_relayhost."]";
293 }
295 /* Check if this server was renamed, in this case we have to remove old cn first*/
296 if($this->hostname != $this->cn){
297 $tmp = array();
298 if(in_array_ics($this->hostname,$this->kolabHost)){
299 foreach($this->kolabHost as $host){
300 if($host != $this->hostname){
301 $tmp[] = $host;
302 }
303 }
304 $this->kolabHost = $tmp;
305 }
306 }
308 /* Add ourselves to the list of kolabHost's if needed */
309 if (!in_array_ics($this->cn,$this->kolabHost)){
310 $this->kolabHost[]= $this->cn;
311 }
313 /* Call parents save to prepare $this->attrs */
314 plugin::save();
316 /* Save or modify? */
317 $ldap->cat($this->dn, array('dn'));
318 if (!$ldap->fetch()){
319 $mode= "add";
320 } else {
321 $mode= "modify";
322 }
324 /* Do attribute conversion */
325 foreach ($this->attrs as $key => $value){
326 if (preg_match('/_/', $key)){
327 $old_key= $key;
328 $key= preg_replace('/_/', '-', $key);
329 $this->attrs[$key]= $value;
330 unset($this->attrs[$old_key]);
331 }
332 }
333 /* Add kolab hosts */
334 $this->attrs['kolabHost']= $this->kolabHost;
336 /* Perform LDAP action */
337 $ldap->cd($this->dn);
338 $this->cleanup();;
339 $ldap->$mode($this->attrs);
340 show_ldap_error($ldap->get_error(), _("Saving server to kolab object failed"));
342 /* Optionally execute a command after we're done */
343 if ($this->initially_was_account == $this->is_account) {
344 if ($this->is_modified) {
345 $this->handle_post_events("modify");
346 }
347 } else {
348 $this->handle_post_events("add");
349 }
350 }
351 }
353 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
354 ?>