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();
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'];
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 }
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 if(isset($this->attrs['postfix-mynetworks'])){
69 if(is_array($this->attrs['postfix-mynetworks'])){
70 unset($this->attrs['postfix-mynetworks']['count']);
71 $tmp="";
72 foreach($this->attrs['postfix-mynetworks'] as $tm){
73 $tmp.=$tm.";";
74 }
75 $this->postfix_mynetworks = $tmp;
76 }
77 }else{
78 $this->postfix_mynetworks="";
79 }
80 }
83 function execute()
84 {
85 /* Fill templating stuff */
86 $smarty = get_smarty();
87 $display = "";
89 /* The Ldap link is needed to ask ldap some questions */
90 $ldap = $this->config->get_ldap_link();
92 /* Do we need to flip is_account state? */
93 if (isset($_POST['modify_state'])) {
94 $this->is_account = !$this->is_account;
95 }
97 /* Show tab dialog headers */
98 if ($this->is_account) {
99 /* call Add Acoount to add account */
100 $display = $this->show_header(_("Remove Kolab extension"), _("This server has kolab features enabled. You can disable them by clicking below."));
101 } else {
102 /* call remove Account */
103 $display = $this->show_header(_("Add Kolab service"), _("This server has kolab features disabled. You can enable them by clicking below."));
104 return ($display);
105 }
107 /* Set relayhost and if we have MX lookup enabled*/
108 if($this->postfix_mxrelayenabled) {
109 $smarty->assign("RelayMxSupportCheck"," checked ");
110 } else {
111 $smarty->assign("RelayMxSupportCheck","");
112 }
114 /* Initialize all attributes, that were submitted */
115 foreach($this->attributes as $val)
116 {
117 $smarty->assign($val."ACL",chkacl($this->acl,str_replace("_","-",$val)));
119 /* Tell smarty which variables we are useing */
120 $smarty->assign($val, $this->$val);
121 if (($this->$val != "FALSE") && !empty($this->$val)){
122 $smarty->assign($val."Check", "checked");
123 } else {
124 $smarty->assign($val."Check", "");
125 }
126 }
128 /* Assemble free/busy string */
129 $edit= sprintf('<input name="kolabFreeBusyFuture" value="%s" %s type="text" maxlength="3" size="4">',
130 $this->kolabFreeBusyFuture, chkacl($this->acl, 'kolabFreeBusyFuture'));
131 $fbfuture= sprintf(_("Include data from %s days in the past when creating free/busy lists"), $edit);
132 $smarty->assign("fbfuture", $fbfuture);
134 /* Assemble quota string */
135 $edit= sprintf('<input name="cyrus_quotawarn" value="%s" type="text" maxlength="3" size="4" %s>',
136 $this->cyrus_quotawarn, chkacl($this->acl, 'cyrus_quotawarn'));
137 $quotastr= sprintf(_("Warn users when using more than %s%% of their mail quota"), $edit);
138 $smarty->assign("quotastr", $quotastr);
140 /* Load Template */
141 $display.=$smarty->fetch(get_template_path('servkolab.tpl', TRUE));
142 return ($display);
143 }
145 function remove_from_parent()
146 {
147 $ldap= $this->config->get_ldap_link();
148 $this->dn = "k=kolab,".$this->config->current['BASE'];
150 if (count($this->kolabHost) == 0){
151 return;
152 }
154 /* Are we alone? Remove complete entry... */
155 if (count($this->kolabHost) == 1){
157 /* Remove complete entry */
158 $ldap->rmdir ($this->dn);
159 show_ldap_error($ldap->get_error());
161 } else {
163 /* Only modify kolabHost */
164 $hosts= array();
165 foreach ($this->kolabHost as $host){
166 if ($host != $this->cn){
167 $hosts[]= $host;
168 }
169 }
170 $attrs= array('kolabHost' => $hosts);
171 $ldap->cd($this->dn);
172 $ldap->modify($attrs);
173 show_ldap_error($ldap->get_error());
174 }
176 /* Optionally execute a command after we're done */
177 $this->handle_post_events("remove");
178 }
181 function save_object()
182 {
183 if (isset($_POST['kolabtab'])){
184 plugin::save_object();
186 /* Save checkboxes */
187 foreach (array( "postfix_enable_virus_scan", "postfix_allow_unauthenticated",
188 "cyrus_admins", "cyrus_imap", "cyrus_pop3", "cyrus_imaps",
189 "cyrus_pop3s", "cyrus_sieve", "apache_allow_unauthenticated_fb",
190 "proftpd_ftp", "apache_http") as $cb){
191 if (isset($_POST[$cb])){
192 $this->$cb= "TRUE";
193 } else {
194 $this->$cb= "FALSE";
195 }
196 }
198 /* Toggle relay check */
199 $this->postfix_mxrelayenabled= isset($_POST['RelayMxSupport']);
200 }
202 }
205 function check()
206 {
207 $message = array();
208 if(($this->kolabFreeBusyFuture=="")) {
209 $message[] = _("Future days in Free/Busy settings must be set.");
210 }elseif(!is_uid($this->kolabFreeBusyFuture) || $this->kolabFreeBusyFuture < 0){
211 $message[] = _("Future days in Free/Busy settings must be a positive value.");
212 }
214 if(!is_int((int)($this->cyrus_quotawarn))) {
215 $message[] = _("The given Quota settings value must be a number.");
216 }elseif(!(($this->cyrus_quotawarn<=100)&&($this->cyrus_quotawarn>=0))){
217 $message[] = _("Please choose a value between 1 and 100 for Quota settings.");
218 }elseif(strcasecmp($this->cyrus_quotawarn,(int)$this->cyrus_quotawarn)){
219 $message[] = _("Future days must be a value.");
220 }
222 if(empty($this->postfix_mynetworks)) {
223 $message[] = _("No SMTP privileged networks set.");
224 }
226 if(empty($this->postfix_relayhost)) {
227 $message[] = _("No SMTP smarthost/relayhost set.");
228 }
230 return ($message);
231 }
234 /* Save to LDAP */
235 function save()
236 {
237 /* Set ldap connection */
238 $ldap = $this->config->get_ldap_link();
240 /* Open current dn*/
241 $this->dn = "k=kolab,".$this->config->current['BASE'];
243 /* Adapt relayhost */
244 $this->postfix_relayhost= preg_replace('/[\[\]]/', '', $this->postfix_relayhost);
245 if (!$this->postfix_mxrelayenabled && $this->postfix_relayhost != ""){
246 $this->postfix_relayhost= "[".$this->postfix_relayhost."]";
247 }
249 /* Add ourselves to the list of kolabHost's if needed */
250 if (!in_array($this->cn, $this->kolabHost)){
251 $this->kolabHost[]= $this->cn;
252 }
255 $tmp = split(";",$this->postfix_mynetworks);
256 $this->postfix_mynetworks = array();
257 foreach($tmp as $tm){
258 trim($tm);
259 if(!empty($tm)){
260 $this->postfix_mynetworks[]=$tm;
261 }
262 }
264 $this->attrs['postfix_mynetworks']=$this->postfix_mynetworks;
266 /* Call parents save to prepare $this->attrs */
267 plugin::save();
269 /* Save or modify? */
270 $ldap->cat($this->dn);
271 if (!$ldap->fetch()){
272 $mode= "add";
273 } else {
274 $mode= "modify";
275 }
277 /* Do attribute conversion */
278 foreach ($this->attrs as $key => $value){
279 if (preg_match('/_/', $key)){
280 $old_key= $key;
281 $key= preg_replace('/_/', '-', $key);
282 $this->attrs[$key]= $value;
283 unset($this->attrs[$old_key]);
284 }
285 }
287 /* Add kolab hosts */
288 $this->attrs['kolabHost']= $this->kolabHost;
290 /* Perform LDAP action */
291 $ldap->cd($this->dn);
292 $ldap->$mode($this->attrs);
293 show_ldap_error($ldap->get_error());
295 /* Optionally execute a command after we're done */
296 if ($this->initially_was_account == $this->is_account) {
297 if ($this->is_modified) {
298 $this->handle_post_events("mofify");
299 }
300 } else {
301 $this->handle_post_events("add");
302 }
304 }
306 }
308 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
309 ?>