df7115cf61c5d651d8b6c4d0d4144ec0fc0502bf
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;
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_in_there = false;
65 $this->is_account = false;
66 $this->initially_was_account = false;
67 foreach($this->kolabHost as $host){
68 if(preg_match("/".$this->hostname.".*/i",$host)){
69 $this->is_account = true;
70 $this->is_in_there = true;
71 $this->initially_was_account = true;
72 }
73 }
76 /* Mhh */
77 if(in_array($this->hostname, $this->kolabHost)) {
78 $this->exactName=true;
79 } else {
80 $this->exactName=false;
81 }
83 /* Parse mynetworks */
84 if(isset($this->attrs['postfix-mynetworks'])){
85 if(is_array($this->attrs['postfix-mynetworks'])){
86 unset($this->attrs['postfix-mynetworks']['count']);
87 $tmp="";
88 foreach($this->attrs['postfix-mynetworks'] as $tm){
89 $tmp.=$tm.";";
90 }
91 $this->postfix_mynetworks = $tmp;
92 }
93 }else{
94 $this->postfix_mynetworks="";
95 }
96 }
99 function execute()
100 {
101 /* Call parent execute */
102 plugin::execute();
104 /* Fill templating stuff */
105 $smarty = get_smarty();
106 $display = "";
108 /* The Ldap link is needed to ask ldap some questions */
109 $ldap = $this->config->get_ldap_link();
111 /* Do we need to flip is_account state? */
112 if (isset($_POST['modify_state'])) {
113 $this->is_account = !$this->is_account;
114 }
116 /* Show tab dialog headers */
117 if ($this->is_account) {
118 /* call Add Acoount to add account */
119 $display = $this->show_header(_("Remove Kolab extension"), _("This server has kolab features enabled. You can disable them by clicking below."));
120 } else {
121 /* call remove Account */
122 $display = $this->show_header(_("Add Kolab service"), _("This server has kolab features disabled. You can enable them by clicking below."));
123 return ($display);
124 }
126 /* Set relayhost and if we have MX lookup enabled*/
127 if($this->postfix_mxrelayenabled) {
128 $smarty->assign("RelayMxSupportCheck"," checked ");
129 } else {
130 $smarty->assign("RelayMxSupportCheck","");
131 }
133 /* Initialize all attributes, that were submitted */
134 foreach($this->attributes as $val)
135 {
136 $smarty->assign($val."ACL",chkacl($this->acl,str_replace("_","-",$val)));
138 /* Tell smarty which variables we are useing */
139 $smarty->assign($val, $this->$val);
140 if (($this->$val != "FALSE") && !empty($this->$val)){
141 $smarty->assign($val."Check", "checked");
142 } else {
143 $smarty->assign($val."Check", "");
144 }
145 }
147 /* Assemble free/busy string */
148 $edit= sprintf('<input name="kolabFreeBusyFuture" value="%s" %s type="text" maxlength="3" size="4">',
149 $this->kolabFreeBusyFuture, chkacl($this->acl, 'kolabFreeBusyFuture'));
150 $fbfuture= sprintf(_("Include data from %s days in the past when creating free/busy lists"), $edit);
151 $smarty->assign("fbfuture", $fbfuture);
153 /* Assemble quota string */
154 $edit= sprintf('<input name="cyrus_quotawarn" value="%s" type="text" maxlength="3" size="4" %s>',
155 $this->cyrus_quotawarn, chkacl($this->acl, 'cyrus_quotawarn'));
156 $quotastr= sprintf(_("Warn users when using more than %s%% of their mail quota"), $edit);
157 $smarty->assign("quotastr", $quotastr);
159 /* Load Template */
160 $display.=$smarty->fetch(get_template_path('servkolab.tpl', TRUE));
161 return ($display);
162 }
164 function remove_from_parent()
165 {
166 /* Only walk through following code, if this host
167 was a member of the kolab hosts, else skip this */
168 if(!$this->initially_was_account){
169 return;
170 }
172 $ldap = $this->config->get_ldap_link();
173 $this->dn = "k=kolab,".$this->config->current['BASE'];
176 /* We can't simply remove the whole entry, it is possible that there are
177 some other hosts assigned to this object.
178 So, first of all check if we are the last host entry within the host
179 : Remove k=kolab entry
180 if we aren't alone, only remove host name from hosts entry and save */
181 /* Are we alone? Remove complete entry... */
183 /* Check if we are definitly in kolabHosts */
184 if(!in_array_ics($this->cn,$this->kolabHost)) {
185 return;
186 }
188 /* Integration check, not translatet because they can't pop up at all, only for debug */
189 if(count($this->kolabHost) == 0){
190 print_red("Server - Kolab tab : This is not possible, we can't remove an account which doesn't exists.");
191 return;
192 }
193 if(!isset($this->cn) || (empty($this->cn))){
194 print_red("The required attribute cn seams to empty.");
195 }
197 /* Our hostname is in kolabHosts and there is a only one entry
198 = we are the last host entry, delete k=kolab entry */
199 if (count($this->kolabHost) == 1){
201 /* Remove complete entry */
202 $ldap->rmdir ($this->dn);
203 show_ldap_error($ldap->get_error(), _("Removing kolab host entry failed"));
204 gosa_log("k=kolab entry removed, ".$this->cn." was the last kolabHost entry.");
206 } else {
208 /* Only modify kolabHost */
209 $hosts= array();
210 foreach ($this->kolabHost as $host){
211 if($host != $this->cn){
212 $hosts[]= $host;
213 }
214 }
215 $attrs= array('kolabHost' => $hosts);
216 $ldap->cd($this->dn);
217 $this->cleanup();
218 $ldap->modify ($attrs);
219 show_ldap_error($ldap->get_error(), _("Removing server from kolab object failed"));
220 gosa_log("Removing ".$this->cn." from list of kolabHosts");
221 }
223 /* Optionally execute a command after we're done */
224 $this->handle_post_events("remove");
225 }
228 function save_object()
229 {
230 if (isset($_POST['kolabtab'])){
231 plugin::save_object();
233 /* Save checkboxes */
234 foreach (array( "postfix_enable_virus_scan", "postfix_allow_unauthenticated",
235 "cyrus_admins", "cyrus_imap", "cyrus_pop3", "cyrus_imaps",
236 "cyrus_pop3s", "cyrus_sieve", "apache_allow_unauthenticated_fb",
237 "proftpd_ftp", "apache_http") as $cb){
238 if (isset($_POST[$cb])){
239 $this->$cb= "TRUE";
240 } else {
241 $this->$cb= "FALSE";
242 }
243 }
245 /* Toggle relay check */
246 $this->postfix_mxrelayenabled= isset($_POST['RelayMxSupport']);
247 }
249 }
252 function check()
253 {
254 /* Call common method to give check the hook */
255 $message= plugin::check();
257 if(($this->kolabFreeBusyFuture=="")) {
258 $message[] = _("Future days in Free/Busy settings must be set.");
259 }elseif(!is_uid($this->kolabFreeBusyFuture) || $this->kolabFreeBusyFuture < 0){
260 $message[] = _("Future days in Free/Busy settings must be a positive value.");
261 }
263 if(!is_int((int)($this->cyrus_quotawarn))) {
264 $message[] = _("The given Quota settings value must be a number.");
265 }elseif(!(($this->cyrus_quotawarn<=100)&&($this->cyrus_quotawarn>=0))){
266 $message[] = _("Please choose a value between 1 and 100 for Quota settings.");
267 }elseif(strcasecmp($this->cyrus_quotawarn,(int)$this->cyrus_quotawarn)){
268 $message[] = _("Future days must be a value.");
269 }
271 if(empty($this->postfix_mynetworks)) {
272 $message[] = _("No SMTP privileged networks set.");
273 }
275 /*if(empty($this->postfix_relayhost)) {
276 $message[] = _("No SMTP smarthost/relayhost set.");
277 }
278 */
280 return ($message);
281 }
284 /* Save to LDAP */
285 function save()
286 {
287 /* Set ldap connection */
288 $ldap = $this->config->get_ldap_link();
290 /* Open current dn*/
291 $this->dn = "k=kolab,".$this->config->current['BASE'];
293 /* Adapt relayhost */
294 $this->postfix_relayhost= preg_replace('/[\[\]]/', '', $this->postfix_relayhost);
295 if (!$this->postfix_mxrelayenabled && $this->postfix_relayhost != ""){
296 $this->postfix_relayhost= "[".$this->postfix_relayhost."]";
297 }
299 /* Add ourselves to the list of kolabHost's if needed */
300 if ((!$this->is_in_there)){
301 $this->kolabHost[]= $this->cn;
302 }
306 $tmp = split(";",$this->postfix_mynetworks);
307 $this->postfix_mynetworks = array();
308 foreach($tmp as $tm){
309 trim($tm);
310 if(!empty($tm)){
311 $this->postfix_mynetworks[]=$tm;
312 }
313 }
315 $this->attrs['postfix_mynetworks']=$this->postfix_mynetworks;
317 /* Call parents save to prepare $this->attrs */
318 plugin::save();
320 /* Save or modify? */
321 $ldap->cat($this->dn, array('dn'));
322 if (!$ldap->fetch()){
323 $mode= "add";
324 } else {
325 $mode= "modify";
326 }
328 /* Do attribute conversion */
329 foreach ($this->attrs as $key => $value){
330 if (preg_match('/_/', $key)){
331 $old_key= $key;
332 $key= preg_replace('/_/', '-', $key);
333 $this->attrs[$key]= $value;
334 unset($this->attrs[$old_key]);
335 }
336 }
338 /* Add kolab hosts */
339 $this->attrs['kolabHost']= $this->kolabHost;
341 if(($this->is_in_there)&&(!$this->exactName)){
342 unset($this->attrs['kolabHost']);
343 }
345 /* Perform LDAP action */
346 $ldap->cd($this->dn);
347 $this->cleanup();;
348 $ldap->$mode($this->attrs);
349 show_ldap_error($ldap->get_error(), _("Saving server to kolab object failed"));
351 /* Optionally execute a command after we're done */
352 if ($this->initially_was_account == $this->is_account) {
353 if ($this->is_modified) {
354 $this->handle_post_events("mofify");
355 }
356 } else {
357 $this->handle_post_events("add");
358 }
360 }
362 }
364 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
365 ?>