e98ce04a15c060ec11c53795543abc88e26efe44
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");
10 var $postfix_mydomain = "";
11 var $postfix_mydestination = "";
12 var $postfix_mynetworks = "";
13 var $postfix_enable_virus_scan = "";
14 var $cyrus_autocreatequota = "";
15 var $cyrus_quotawarn = "";
16 var $cyrus_admins = "";
17 var $cyrus_imap = "";
18 var $cyrus_pop3 = "";
19 var $cyrus_imaps = "";
20 var $cyrus_pop3s = "";
21 var $cyrus_sieve = "";
22 var $apache_allow_unauthenticated_fb = "";
23 var $proftpd_ftp = "";
24 var $apache_http = "";
25 var $kolabHost = array("");
27 var $attributes = array("postfix_mydomain", "postfix_mydestination",
28 "postfix_mynetworks", "postfix_enable_virus_scan",
29 "cyrus_autocreatequota", "cyrus_admins", "cyrus_imap",
30 "cyrus_pop3", "cyrus_imaps", "cyrus_pop3s", "cyrus_sieve",
31 "apache_allow_unauthenticated_fb", "proftpd_ftp",
32 "apache_http", "cyrus_quotawarn", "kolabHost");
34 var $objectclasses = array("top", "kolab");
36 function servkolab($config, $dn = NULL)
37 {
38 echo "DN korrigieren<br>";
39 $this->dn = "k=kolab,".$config->current['BASE'];
41 plugin::plugin($config, $this->dn);
42 $this->dn = $dn;
44 /* Copy needed attributes */
45 foreach($this->attributes as $val) {
46 $name = preg_replace('/_/', '-', $val);
47 if (isset($this->attrs["$name"][0])) {
48 $this->$val = $this->attrs["$name"][0];
49 }
50 }
51 }
56 /* If the Button remove Kolab extension is clicked, this will be called */
57 function RemoveAccount()
58 {
60 gosa_log("Remove function");
62 $ldap = $this->config->get_ldap_link();
63 $ldap->cd($this->dn);
65 if ($ldap->dn_exists($this->dn)) {
66 $ldap->rmdir($this->dn);
67 show_ldap_error($ldap->get_error());
68 }
69 }
75 /* this fucntion generates all needed attributes to start a new kolab extension */
76 function AddAccount()
77 {
79 /* get the Ldap link, to test if there is an obeject with the same dn */
80 $ldap = $this->config->get_ldap_link();
82 gosa_log("Add function");
84 /* test */
85 if (!$ldap->dn_exists($this->dn)) {
86 /* Object Classes */
87 $str['objectClass'][] = "top";
88 $str['objectClass'][] = "kolab";
90 /* specific kolab attribute */
91 $str['k'][] = "kolab";
93 /* Postfix default values */
94 $str['postfix-mydomain'][] = "gonicus.de";
95 $str['postfix-mydestination'][] = "\$mydomain";
96 $str['postfix-mynetworks'][] = "127.0.0.0/8";
97 $str['postfix-enable-virus-scan'][] = "TRUE";
99 /* Cyrus Attributes */
100 $str['cyrus-autocreatequota'][] = "100000";
101 $str['cyrus-quotawarn'][] = "80";
102 $str['cyrus-admins'][] = "manager";
103 $str['cyrus-imap'][] = "TRUE";
104 $str['cyrus-pop3'][] = "FALSE";
105 $str['cyrus-imaps'][] = "FALSE";
106 $str['cyrus-pop3s'][] = "FALSE";
107 $str['cyrus-sieve'][] = "FALSE";
109 /* */
110 $str['apache-allow-unauthenticated-fb'][] = "FALSE";
111 $str['proftpd-ftp'][] = "FALSE";
112 $str['uid'][] = "freebusy";
113 $str['userPassword'][] = "ZnJlZWJ1c3k";
114 $str['apache-http'][] = "TRUE";
117 /* Set Attributes */
118 $ldap->cd($this->dn);
119 $this->attrs = $str;
121 /* Copy needed attributes */
122 foreach($this->attributes as $val) {
123 $name = preg_replace('/_/', '-', $val);
124 if (isset($this->attrs["$name"][0])) {
125 $this->$val = $this->attrs["$name"][0];
126 }
127 }
129 }
132 }
135 function execute()
136 {
137 /* Fill templating stuff */
138 $smarty = get_smarty();
139 $display = "";
141 /* Tell the script the dn, we are using */
142 $this->dn = "k=kolab,".$this->config->current['BASE'];
144 $ldap = $this->config->get_ldap_link();
146 /* Do we need to flip is_account state? */
147 if (isset($_POST['modify_state'])) {
148 $this->is_account = !$this->is_account;
149 if($this->is_account)
150 $this->AddAccount();
151 else
152 $this->RemoveAccount();
155 }
157 /* Show tab dialog headers */
158 if ($this->is_account) {
159 /* call Add Acoount to add account */
160 $display = $this->show_header(_("Remove Kolab extension"), _("This server has kolab features enabled. You can disable them by clicking below."));
161 } else {
162 /* call remove Account */
163 $display = $this->show_header(_("Add Kolab service"), _("This server has kolab features disabled. You can enable them by clicking below."));
164 return ($display);
165 }
167 /* There a new Host submitted */
168 if (isset($_POST['NewHost'])) {
169 $this->attrs['kolabHost'][] = $_POST['NewkolabHost'];
170 gosa_log("Adding Host");
171 }
173 /* We need to delete a Host */
174 if (isset($_POST['DelHost'])) {
175 foreach($this->attrs['kolabHost'] as $key => $host) {
176 if ($host == $_POST['kolabHost'])
177 unset($this->attrs['kolabHost'][$key]);
178 }
179 gosa_log("Removing Host".$this->attrs['kolabHost'][$key]);
180 }
184 /* Initialize all attributes, that were submitted */
185 foreach($this->attributes as $val) {
186 /* If theres a button pressed, we need to check all attributes */
187 if ((isset($_POST['NewHost'])) || (isset($_POST['DelHost']))) {
188 /* Set var to value or to zero */
189 if (isset($_POST[$val])) {
191 $this->$val = $_POST[$val];
192 } else {
193 $this->$val = 0;
194 }
195 }
196 /* Tell smarty which variables we are useing */
197 $smarty->assign($val, $this->$val);
198 if (($this->$val != "FALSE") && (!empty($this->$val)))
199 $smarty->assign($val."Check", "checked");
201 }
203 /* If there are some Host submitted, tell it smarty */
204 $this->kolabHost = array();
205 if (isset($this->attrs['kolabHost'])) {
206 $this->kolabHost = $this->attrs['kolabHost'];
207 unset($this->kolabHost['count']);
208 }
210 $smarty->assign("kolabHost", $this->kolabHost);
212 /* Load Template */
213 $display.=$smarty->fetch(get_template_path('servkolab.tpl', TRUE));
215 return ($display);
216 }
218 function remove_from_parent()
219 {
220 }
223 function save_object()
224 {
225 plugin::save_object();
226 }
229 function check()
230 {
231 $message = array();
234 if(!is_int((int)($this->cyrus_quotawarn))) {
235 $message[] = "The given Quota settings value must be a number";
236 }elseif(!(($this->cyrus_quotawarn<=100)&&($this->cyrus_quotawarn>=1))){
237 $message[] = "Please choose a value between 1 and 100 for Quota settings";
238 }
241 /* You will need a least one entry to save this settings */
242 if (count($this->kolabHost) == 0) {
243 $message[] =
244 "You will need at least one Entry in Hosts. If You want to 'Remove' Kolab extension please use the \"Remove Kolab extension\" Button to remove Kolab ";
245 }
246 return ($message);
247 }
250 /* Save to LDAP */
251 function save()
252 {
253 /* Set ldap connection */
254 $ldap = $this->config->get_ldap_link();
255 $ldap->cd($this->dn);
257 /* Setup Attributes to save */
258 $newattrs = array();
260 /* Set vars with correct - _ - */
261 foreach($this->attributes as $key) {
262 $key2 = str_replace("_", "-", $key);
263 $newattrs[$key2] = $this->$key;
264 }
266 /* Set bool vars */
267 if ($newattrs['postfix-enable-virus-scan'] == 0)
268 $newattrs['postfix-enable-virus-scan'] = "FALSE";
269 else
270 $newattrs['postfix-enable-virus-scan'] = "TRUE";
271 if ($newattrs['cyrus-imap'] == 0)
272 $newattrs['cyrus-imap'] = "FALSE";
273 else
274 $newattrs['cyrus-imap'] = "TRUE";
275 if ($newattrs['cyrus-imaps'] == 0)
276 $newattrs['cyrus-imaps'] = "FALSE";
277 else
278 $newattrs['cyrus-imaps'] = "TRUE";
279 if ($newattrs['cyrus-pop3'] == 0)
280 $newattrs['cyrus-pop3'] = "FALSE";
281 else
282 $newattrs['cyrus-pop3'] = "TRUE";
283 if ($newattrs['cyrus-pop3s'] == 0)
284 $newattrs['cyrus-pop3s'] = "FALSE";
285 else
286 $newattrs['cyrus-pop3s'] = "TRUE";
287 if ($newattrs['cyrus-sieve'] == 0)
288 $newattrs['cyrus-sieve'] = "FALSE";
289 else
290 $newattrs['cyrus-sieve'] = "TRUE";
291 if ($newattrs['proftpd-ftp'] == 0)
292 $newattrs['proftpd-ftp'] = "FALSE";
293 else
294 $newattrs['proftpd-ftp'] = "TRUE";
295 if ($newattrs['apache-http'] == 0)
296 $newattrs['apache-http'] = "FALSE";
297 else
298 $newattrs['apache-http'] = "TRUE";
299 if ($newattrs['apache-allow-unauthenticated-fb'] == 0)
300 $newattrs['apache-allow-unauthenticated-fb'] = "FALSE";
301 else
302 $newattrs['apache-allow-unauthenticated-fb'] = "TRUE";
305 /* Reorder Host array, to get constant increasing index */
306 $newattrs['kolabHost'] = array();
307 foreach($this->attrs['kolabHost'] as $key=>$val) {
308 if (is_int($key)) {
309 $newattrs['kolabHost'][] = $val;
310 }
311 }
313 /* Save as following object ! */
314 $this->dn = "k=kolab,".$this->config->current['BASE'];
316 /* If we already have an object like this one,
317 we only need to modify the entry
318 */
319 if ($ldap->dn_exists($this->dn)) {
320 gosa_log("Modifying");
321 $ldap->cd($this->dn);
322 $ldap->modify($newattrs);
323 } else {
324 /* We must create a new Entry */
325 gosa_log("Adding");
326 $newattrs['k'] = "kolab";
327 $newattrs['uid'] = "freebusy";
328 $newattrs['postfix-mydomain'] = "gonicus.de";
329 $newattrs['postfix-mydestination'] = "\$mydomain";
330 $newattrs['userPassword'] = "tester";
331 $newattrs['objectClass'] = $this->objectclasses;
332 $ldap->cd($this->dn);
333 $ldap->add($newattrs);
334 }
336 /* show any errors */
337 show_ldap_error($ldap->get_error());
339 /* Optionally execute a command after we're done */
340 if ($this->initially_was_account == $this->is_account) {
341 if ($this->is_modified) {
342 $this->handle_post_events("mofify");
343 }
344 } else {
345 $this->handle_post_events("add");
346 }
348 }
350 }
352 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
353 ?>