Code

Kolab functions would runn now
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 18 May 2005 13:04:45 +0000 (13:04 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 18 May 2005 13:04:45 +0000 (13:04 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@245 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/systems/class_servKolab.inc
plugins/admin/systems/servkolab.tpl

index 0e00cc9e962ef3dab8217fc9b14e5672de141ded..bf160a091d3b52a248cfef9e45a569eaaf1f59cf 100644 (file)
-<?php
-
-class servkolab extends plugin
-{
+<?php class servkolab extends plugin {
   /* CLI vars */
-  var $cli_summary=           "Manage server basic objects";
-  var $cli_description=       "Some longer text\nfor help";
-  var $cli_parameters=        array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
+  var $cli_summary = "Manage server basic objects";
+  var $cli_description = "Some longer text\nfor help";
+  var $cli_parameters = array("eins"=>"Eins ist toll", "zwei"=>"Zwei ist noch besser");
+
+
+  var $postfix_mydomain                 = "";
+  var $postfix_mydestination            = "";
+  var $postfix_mynetworks               = "";
+  var $postfix_enable_virus_scan        = "";
+  var $cyrus_autocreatequota            = "";
+  var $cyrus_quotawarn                  = "";
+  var $cyrus_admins                     = "";
+  var $cyrus_imap                       = "";
+  var $cyrus_pop3                       = "";
+  var $cyrus_imaps                      = "";
+  var $cyrus_pop3s                      = "";
+  var $cyrus_sieve                      = "";
+  var $apache_allow_unauthenticated_fb  = "";
+  var $proftpd_ftp                      = "";
+  var $apache_http                      = "";
+  var $kolabHost                        = array("");
+
+  var $attributes =  array("postfix_mydomain", "postfix_mydestination",
+        "postfix_mynetworks", "postfix_enable_virus_scan",
+        "cyrus_autocreatequota", "cyrus_admins", "cyrus_imap",
+        "cyrus_pop3", "cyrus_imaps", "cyrus_pop3s", "cyrus_sieve",
+        "apache_allow_unauthenticated_fb", "proftpd_ftp",
+        "apache_http", "cyrus_quotawarn", "kolabHost");
+
+  var $objectclasses = array("top", "kolab");
+
+  function servkolab($config, $dn = NULL) 
+  {
+    echo "DN korrigieren<br>";
+    $this->dn = "k=kolab,".$config->current['BASE'];
+    
+    plugin::plugin($config, $this->dn);
+    $this->dn = $dn;
+
+    /* Copy needed attributes */
+    foreach($this->attributes as $val) {
+      $name = preg_replace('/_/', '-', $val);
+      if (isset($this->attrs["$name"][0])) {
+        $this->$val = $this->attrs["$name"][0];
+      }
+    }
+  }
+
+
 
-  /* attribute list for save action */
-  var $attributesi            = array();
-  var $objectclasses          = array("whatever");
 
-  function servkolab ($config, $dn= NULL)
+  /* If the Button remove Kolab extension is clicked, this will be called */
+  function RemoveAccount() 
   {
-    plugin::plugin ($config, $dn);
+  
+  gosa_log("Remove function");
+    
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($this->dn);
+
+    if ($ldap->dn_exists($this->dn)) {
+      $ldap->rmdir($this->dn);
+      show_ldap_error($ldap->get_error());
+    }
   }
 
-  function execute()
+
+
+
+
+  /* this fucntion generates all needed attributes to start a new kolab extension */
+  function AddAccount() 
+  {
+
+    /* get the Ldap link, to test if there is an obeject with the same dn */
+    $ldap = $this->config->get_ldap_link();
+    
+    gosa_log("Add function");
+
+    /* test */
+    if (!$ldap->dn_exists($this->dn)) {
+      /* Object Classes */
+      $str['objectClass'][] = "top";
+      $str['objectClass'][] = "kolab";
+
+      /* specific kolab attribute */
+      $str['k'][] = "kolab";
+
+      /* Postfix default values */
+      $str['postfix-mydomain'][] = "gonicus.de";
+      $str['postfix-mydestination'][] = "\$mydomain";
+      $str['postfix-mynetworks'][] = "127.0.0.0/8";
+      $str['postfix-enable-virus-scan'][] = "TRUE";
+
+      /* Cyrus Attributes */
+      $str['cyrus-autocreatequota'][] = "100000";
+      $str['cyrus-quotawarn'][] = "80";
+      $str['cyrus-admins'][] = "manager";
+      $str['cyrus-imap'][] = "TRUE";
+      $str['cyrus-pop3'][] = "FALSE";
+      $str['cyrus-imaps'][] = "FALSE";
+      $str['cyrus-pop3s'][] = "FALSE";
+      $str['cyrus-sieve'][] = "FALSE";
+
+      /* */
+      $str['apache-allow-unauthenticated-fb'][] = "FALSE";
+      $str['proftpd-ftp'][] = "FALSE";
+      $str['uid'][] = "freebusy";
+      $str['userPassword'][] = "ZnJlZWJ1c3k";
+      $str['apache-http'][] = "TRUE";
+
+
+      /* Set Attributes */
+      $ldap->cd($this->dn);
+      $this->attrs = $str;
+
+      /* Copy needed attributes */
+      foreach($this->attributes as $val) {
+        $name = preg_replace('/_/', '-', $val);
+        if (isset($this->attrs["$name"][0])) {
+          $this->$val = $this->attrs["$name"][0];
+        }
+      }
+
+    }
+
+
+  }
+
+
+  function execute() 
   {
     /* Fill templating stuff */
-    $smarty       = get_smarty();
-    $display      = "";
+    $smarty = get_smarty();
+    $display = "";
 
+    /* Tell the script the dn, we are using */
+    $this->dn = "k=kolab,".$this->config->current['BASE'];
+
+    $ldap = $this->config->get_ldap_link();
+    
     /* Do we need to flip is_account state? */
-    if (isset($_POST['modify_state'])){
-      $this->is_account= !$this->is_account;
+    if (isset($_POST['modify_state'])) {
+      $this->is_account = !$this->is_account;
+      if($this->is_account) 
+        $this->AddAccount();
+      else  
+        $this->RemoveAccount();   
+    
+    
     }
 
     /* Show tab dialog headers */
-    if ($this->is_account){
-      $display= $this->show_header(_("Remove Kolab extension"),
-          _("This server has kolab features enabled. You can disable them by clicking below."));
+    if ($this->is_account) {
+      /* call Add Acoount to add account */
+      $display = $this->show_header(_("Remove Kolab extension"), _("This server has kolab features enabled. You can disable them by clicking below."));
     } else {
-      $display= $this->show_header(_("Add Kolab service"),
-          _("This server has kolab features disabled. You can enable them by clicking below."));
+      /* call remove Account */
+      $display = $this->show_header(_("Add Kolab service"), _("This server has kolab features disabled. You can enable them by clicking below."));
       return ($display);
     }
 
-    $display.= $smarty->fetch(get_template_path('servkolab.tpl', TRUE));
-    return($display);
+    /* There a new Host submitted */
+    if (isset($_POST['NewHost'])) {
+      $this->attrs['kolabHost'][] = $_POST['NewkolabHost'];
+      gosa_log("Adding Host");
+    }
+
+    /* We need to delete a Host */
+    if (isset($_POST['DelHost'])) {
+      foreach($this->attrs['kolabHost'] as $key => $host) {
+        if ($host == $_POST['kolabHost'])
+          unset($this->attrs['kolabHost'][$key]);
+      }
+      gosa_log("Removing Host".$this->attrs['kolabHost'][$key]);
+    }
+
+
+
+    /* Initialize all attributes, that were submitted */
+    foreach($this->attributes as $val) {
+      /* If theres a button pressed, we need to check all attributes */
+      if ((isset($_POST['NewHost'])) || (isset($_POST['DelHost']))) {
+        /* Set var to value or to zero */
+        if (isset($_POST[$val])) {
+
+          $this->$val = $_POST[$val];
+        } else {
+          $this->$val = 0;
+        }
+      }
+      /* Tell smarty which variables we are useing */
+      $smarty->assign($val, $this->$val);
+      if (($this->$val != "FALSE") && (!empty($this->$val)))
+        $smarty->assign($val."Check", "checked");
+
+    }
+
+    /*  If there are some Host submitted, tell it smarty */
+    $this->kolabHost = array();
+    if (isset($this->attrs['kolabHost'])) {
+      $this->kolabHost = $this->attrs['kolabHost'];
+      unset($this->kolabHost['count']);
+    }
+
+    $smarty->assign("kolabHost", $this->kolabHost);
+
+    /* Load Template */
+    $display.=$smarty->fetch(get_template_path('servkolab.tpl', TRUE));
+  
+    print_a($this);
+  
+    return ($display);
   }
 
-  function remove_from_parent()
+  function remove_from_parent() 
   {
   }
 
 
-  function save_object()
+  function save_object()    
   {
     plugin::save_object();
   }
 
 
-  function check()
+  function check() 
   {
-    $message= array();
+    $message = array();
+
+
+    if(!is_int((int)($this->cyrus_quotawarn))) {
+      $message[] = "The given Quota settings value must be a number";
+    }elseif(!(($this->cyrus_quotawarn<=100)&&($this->cyrus_quotawarn>=1))){
+      $message[] = "Please choose a value between 1 and 100 for Quota settings";
+    }
+    
+
+    /* You will need a least one entry to save this settings */
+    if (count($this->kolabHost) == 0) {
+      $message[] =
+        "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  ";
+    }
     return ($message);
   }
 
 
   /* Save to LDAP */
-  function save()
+  function save() 
   {
-    plugin::save();
+    /* Set ldap connection */
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($this->dn);
+
+    /* Setup Attributes to save */
+    $newattrs = array();
+
+    /* Set vars with correct - _ - */
+    foreach($this->attributes as $key) {
+      $key2 = str_replace("_", "-", $key);
+      $newattrs[$key2] = $this->$key;
+    }
+
+    /* Set bool vars */
+    if ($newattrs['postfix-enable-virus-scan'] == 0)
+      $newattrs['postfix-enable-virus-scan'] = "FALSE";
+    else
+      $newattrs['postfix-enable-virus-scan'] = "TRUE";
+    if ($newattrs['cyrus-imap'] == 0)
+      $newattrs['cyrus-imap'] = "FALSE";
+    else
+      $newattrs['cyrus-imap'] = "TRUE";
+    if ($newattrs['cyrus-imaps'] == 0)
+      $newattrs['cyrus-imaps'] = "FALSE";
+    else
+      $newattrs['cyrus-imaps'] = "TRUE";
+    if ($newattrs['cyrus-pop3'] == 0)
+      $newattrs['cyrus-pop3'] = "FALSE";
+    else
+      $newattrs['cyrus-pop3'] = "TRUE";
+    if ($newattrs['cyrus-pop3s'] == 0)
+      $newattrs['cyrus-pop3s'] = "FALSE";
+    else
+      $newattrs['cyrus-pop3s'] = "TRUE";
+    if ($newattrs['cyrus-sieve'] == 0)
+      $newattrs['cyrus-sieve'] = "FALSE";
+    else
+      $newattrs['cyrus-sieve'] = "TRUE";
+    if ($newattrs['proftpd-ftp'] == 0)
+      $newattrs['proftpd-ftp'] = "FALSE";
+    else
+      $newattrs['proftpd-ftp'] = "TRUE";
+    if ($newattrs['apache-http'] == 0)
+      $newattrs['apache-http'] = "FALSE";
+    else
+      $newattrs['apache-http'] = "TRUE";
+    if ($newattrs['apache-allow-unauthenticated-fb'] == 0)
+      $newattrs['apache-allow-unauthenticated-fb'] = "FALSE";
+    else
+      $newattrs['apache-allow-unauthenticated-fb'] = "TRUE";
+
+
+    /* Reorder Host array, to get constant increasing index */
+    $newattrs['kolabHost'] = array();
+    foreach($this->attrs['kolabHost'] as $key=>$val) {
+      if (is_int($key)) {
+        $newattrs['kolabHost'][] = $val;
+      }
+    }
+
+    /* Save as following object ! */
+    $this->dn = "k=kolab,".$this->config->current['BASE'];
+
+    /* If we already have an object like this one,
+       we only need to modify the entry
+     */
+    if ($ldap->dn_exists($this->dn)) {
+      gosa_log("Modifying");
+      $ldap->cd($this->dn);
+      $ldap->modify($newattrs);
+    } else {
+      /* We must create a new Entry */
+      gosa_log("Adding");
+      $newattrs['k'] = "kolab";
+      $newattrs['uid'] = "freebusy";
+      $newattrs['postfix-mydomain'] = "gonicus.de";
+      $newattrs['postfix-mydestination'] = "\$mydomain";
+      $newattrs['userPassword'] = "tester";
+      $newattrs['objectClass'] = $this->objectclasses;
+      $ldap->cd($this->dn);
+      $ldap->add($newattrs);
+    }
+
+    /* show any errors */
+    show_ldap_error($ldap->get_error());
+
+    /* Optionally execute a command after we're done */
+    if ($this->initially_was_account == $this->is_account) {
+      if ($this->is_modified) {
+        $this->handle_post_events("mofify");
+      }
+    } else {
+      $this->handle_post_events("add");
+    }
+
   }
 
 }
index b75c898b9d3ebdb1584ef053b01502ef2dcc9917..a68749a101a10d3fd9520ea3850c7471549b9d80 100644 (file)
@@ -8,7 +8,7 @@
        </tr>
        <tr>
                <td>
-                       <input name="cyrus-pop3" value="1" type="checkbox" >
+                       <input name="cyrus_pop3" value="1" type="checkbox" {$cyrus_pop3Check}>
                </td>
                <td>
                        POP3 Service    
@@ -16,7 +16,7 @@
        </tr>
        <tr>
         <td>
-            <input name="cyrus-pop3s" value="1" type="checkbox" >
+            <input name="cyrus_pop3s" value="1" type="checkbox" {$cyrus_pop3sCheck}>
         </td>
                <td>
                        POP3/SSL service (TCP port 995)         
@@ -24,7 +24,7 @@
     </tr>
     <tr>
         <td>
-            <input name="cyrus-imap" value="1" type="checkbox" >
+            <input name="cyrus_imap" value="1" type="checkbox" {$cyrus_imapCheck}>
         </td>
         <td>
                        IMAP Service    
@@ -32,7 +32,7 @@
     </tr>
     <tr>
         <td>
-            <input name="cyrus-imaps" value="1" type="checkbox" >
+            <input name="cyrus_imaps" value="1" type="checkbox" {$cyrus_imapsCheck}>
         </td>
         <td>
                        IMAP/SSL Service (TCP port 993)         
@@ -40,7 +40,7 @@
     </tr>
     <tr>
         <td>
-            <input name="cyrus-sieve" value="1" type="checkbox" >
+            <input name="cyrus_sieve" value="1" type="checkbox" {$cyrus_sieveCheck}>
         </td>
         <td>
                        Sieve service (TCP port 2000)   
     </tr>
     <tr>
         <td>
-            <input name="proftpd-ftp" value="1" type="checkbox" >
-        </td>
+            <input name="proftpd_ftp" value="1" type="checkbox" {$proftpd_ftpCheck}>
+        </td>  
         <td>
                        FTP FreeBusy Service (Legacy, not interoperable with Kolab2 FreeBusy)   
         </td>
     </tr>
     <tr>
         <td>
-            <input name="" value="1" type="checkbox" >
+            <input name="apache_http" value="1" type="checkbox" {$apache_httpCheck}>
         </td>
         <td>
                        HTTP FreeBusy Service (Legacy)  
@@ -64,7 +64,7 @@
     </tr>
     <tr>
         <td>
-            <input name="" value="1" type="checkbox" >
+            <input name="postfix_enable_virus_scan" value="1" type="checkbox" {$postfix_enable_virus_scanCheck}>
         </td>
         <td>
                        Amavis Email Scanning (Virus/Spam)
        </tr>
     <tr>
      <td>
-        <select style="width:350px;" id="goExportEntry" name="goExportEntry" {$goNfsServerState} size=6 multiple {$trustmodeACL} {$trusthide}>
-            {html_options values=$goExportEntry output=$goExportEntry}
+        <select style="width:350px;" size="6"  name="kolabHost">
+            {html_options values=$kolabHost output=$kolabHost}
         </select>
     <br>
-        <input type="text"      name="NewNfsExport" {$goNfsServerState} id="NewNfsExportId">
-        <input type="submit"    value="{t}Add{/t}"      name="NewNfsAdd"    {$goNfsServerState} id="NewNfsAddId">
-        <input type="submit"    value="{t}Delete{/t}"   name="DelNfsEnt"    {$goNfsServerState} id="DelNfsEntId">
+        <input type="text"      name="NewkolabHost">
+        <input type="submit"    value="{t}Add{/t}"      name="NewHost">
+        <input type="submit"    value="{t}Delete{/t}"   name="DelHost">
     </td>
        </tr>
        </table>        
        </tr>
        <tr>
                <td>
-                       <input name="" value="" type="text" maxlength="2" size="3">%
+                       <input name="cyrus_quotawarn" value="{$cyrus_quotawarn}" type="text" maxlength="2" size="3">%
                </td>
                <td>
                        Percentage to warn users
     </tr>
     <tr>
         <td>
-            <input name="" value="1" type="checkbox">
+            <input name="apache_allow_unauthenticated_fb" value="1" type="checkbox" {$apache_allow_unauthenticated_fbCheck}>
         </td>
         <td>
             Allow unauthenticated downloading of Free/Busy information 
     </tr>
     <tr>
         <td>
-            <input name="" value="" type="text">
+            <input name="postfix_mynetworks" value="{$postfix_mynetworks}" type="text">
         </td>
         <td>
                        Networks allowed to relay and send mail through unauthenticated SMTP connections to the Kolab server (comma separated networks in x.x.x.x/y format)
                <b>{t}SMTP "smarthost/relayhost"{/t}</b>
                </td>
     </tr>
+       <tr>    
+               <td>
+                       <input name="postfix_relayhost" value="{$postfix_relayhost}" type="text">
+               </td>
+               <td>
+                       Smarthost to use to send outgoing mail (host.domain.tld). Leave empty for no relayhost.
+               </td>
+       </tr>
     <tr>
         <td>
             <input name="" value="1" type="checkbox" >
         </td>
         <td>
-               Smarthost to use to send outgoing mail (host.domain.tld). Leave empty for no relayhost.
                        Enable MX lookup for relayhost (if in doubt, leave it off)
                </td>
      </tr>
    <table>
     <tr>
         <td colspan="2">
-               <b>{t}Accept Internet Mai{/t}</b>
+               <b>{t}Accept Internet Mail{/t}</b>
                </td>
     </tr>
     <tr>