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