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