Code

Added goVirusServer service
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 1 Aug 2006 04:04:49 +0000 (04:04 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 1 Aug 2006 04:04:49 +0000 (04:04 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@4351 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/systems/class_goSpamServer.inc
plugins/admin/systems/class_goVirusServer.inc [new file with mode: 0644]
plugins/admin/systems/goVirusServer.tpl [new file with mode: 0644]

index e52198d13c9625aa7713418879d56109d6e61300..055496bf8bafb945fdb438285b39b5081671ff9a 100644 (file)
@@ -45,7 +45,8 @@ class goSpamServer extends plugin{
     $this->ui = get_userinfo();
 
     /* Set up the users ACL's for this 'dn' */
-    $this->acl= get_permissions ($this->dn, $this->ui->subtreeACL);
+    $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
+    $this->acl= get_module_permission($acl, "goSpamServer", $this->ui->dn);
 
     /* Get Flags */
     foreach($this->Flags as $flag){
@@ -181,7 +182,7 @@ class goSpamServer extends plugin{
 
     /* Create divlist */
     $DivRules = new divSelectBox("SpamRules");
-    $DivRules->SetHeight(150);
+    $DivRules->SetHeight(130);
 
     if(preg_match("/disabled/",chkacl($this->acl,"saTrustedNetworks"))){
       $actions = "";
diff --git a/plugins/admin/systems/class_goVirusServer.inc b/plugins/admin/systems/class_goVirusServer.inc
new file mode 100644 (file)
index 0000000..ee4bb64
--- /dev/null
@@ -0,0 +1,338 @@
+<?php
+
+class goVirusServer extends plugin{
+       
+  /* This plugin only writes its objectClass */
+  var $objectclasses    = array("goVirusServer");
+  var $attributes       = array("avMaxThreads","avMaxDirectoryRecursions",/*"avUser",*/"avFlags","avArchiveMaxFileSize","avArchiveMaxRecursion",
+                                "avArchiveMaxCompressionRatio","avDatabaseMirror","avChecksPerDay","avHttpProxyURL");
+  var $StatusFlag       = "avStatus";
+  /* This class can't be assigned twice so it conflicts with itsself */
+  var $conflicts        = array("goVirusServer");
+
+  var $DisplayName      = "";
+  var $dn               = NULL;
+  var $cn               = "";
+  var $saStatus         = "";
+
+  var $dialog           = NULL;
+  var $ui               = NULL;
+  var $acl              = NULL;
+
+  var $Flags            = array("D","S","A","E");
+  
+  var $avFlags          = "";
+  var $avFlagsD         = FALSE;
+  var $avFlagsS         = FALSE;
+  var $avFlagsA         = FALSE;
+  var $avFlagsE         = FALSE;
+
+  var $avMaxThreads                 = 5;
+  var $avMaxDirectoryRecursions     = 4;    
+//  var $avUser                       = "";
+  var $avArchiveMaxFileSize         = 4000;
+  var $avArchiveMaxRecursion        = 5;
+  var $avArchiveMaxCompressionRatio = 95;
+  var $avDatabaseMirror             = "";
+  var $avChecksPerDay               = 12;
+  var $avHttpProxyURL               = "";
+
+  function goVirusServer($config,$dn)
+  {
+    /* Init class */
+    plugin::plugin($config,$dn);
+    $this->DisplayName = _("Anti virus");
+
+    /* Get userinfo & acls */
+    $this->ui = get_userinfo();
+
+    /* Set up the users ACL's for this 'dn' */
+    $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
+    $this->acl= get_module_permission($acl, "goVirusServer", $this->ui->dn);
+
+    /* Get Flags */
+    foreach($this->Flags as $flag){
+      $var = "avFlags".$flag;
+      if(preg_match("/".$flag."/",$this->avFlags)){
+        $this->$var = TRUE;
+      }
+    }
+  }
+
+
+  function execute()
+  {
+    /* Do we need to flip is_account state? */
+    if (isset($_POST['modify_state'])) {
+      $this->is_account = !$this->is_account;
+    }
+    /* Show tab dialog headers */
+    if ($this->is_account) {
+      /* call Add Acoount to add account */
+      $display = $this->show_header(_("Remove anti virus extension"), 
+        _("This server has anti virus features enabled. You can disable them by clicking below."));
+    } else {
+      /* call remove Account */
+      $display = $this->show_header(_("Add anti virus service"), 
+        _("This server has anti virus features disabled. You can enable them by clicking below."));
+      return ($display);
+    }
+
+    /* Assign smarty vars */
+    $smarty = get_smarty(); 
+    foreach($this->attributes as $attr){
+      $smarty->assign($attr,$this->$attr);
+      $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
+    }
+
+    /* Assign checkbox states */
+    foreach($this->Flags as $Flag){
+      $var = "avFlags".$Flag;
+      $smarty->assign("avFlags".$Flag."ACL",chkacl($this->acl,$Flag));
+      if($this->$var){
+        $smarty->assign("avFlags".$Flag."CHK"," checked " );
+      }else{
+        $smarty->assign("avFlags".$Flag."CHK","");
+      }
+    }
+
+    return($display.$smarty->fetch(get_template_path("goVirusServer.tpl",TRUE,dirname(__FILE__))));
+  }
+
+
+  /* Add $post to list of configured trusted */
+  function AddTrust($post)
+  {
+    if(!empty($post)){
+      $this->TrustedNetworks[$post] = $post;
+    }
+  }
+
+
+  /* Delete trusted network */
+  function DelTrust($posts)
+  {
+    foreach($posts as $post){
+      if(isset($this->TrustedNetworks[$post])){
+        unset($this->TrustedNetworks[$post]);     
+      }
+    }
+  }
+
+
+  /* remove this extension */
+  function remove_from_parent()
+  {
+    if(!$this->is_account && $this->initially_was_account){
+      plugin::remove_from_parent();
+
+      /* Check if this is a new entry ... add/modify */
+      $ldap = $this->config->get_ldap_link();
+      $ldap->cat($this->dn,array("objectClass"));
+      if($ldap->count()){
+        $ldap->cd($this->dn);
+        $ldap->modify($this->attrs);
+      }else{
+        $ldap->cd($this->dn);
+        $ldap->add($this->attrs);
+      }
+      show_ldap_error($ldap->get_error(), sprintf(_("Removing of server services/anti virus with dn '%s' failed."),$this->dn));
+      $this->handle_post_events("remove");
+    }
+  }
+
+
+  function save()
+  {
+    if(!$this->is_account) return;
+
+    /* Create Flags */     
+    $this->avFlags = "";
+    foreach($this->Flags as $flag){
+      $var = "avFlags".$flag;
+      if($this->$var){
+        $this->avFlags .=$flag;
+      }
+    }
+
+    plugin::save();
+
+    print_a($this->attrs);
+
+    /* Check if this is a new entry ... add/modify */
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cat($this->dn,array("objectClass"));
+    if($ldap->count()){
+      $ldap->cd($this->dn);
+      $ldap->modify($this->attrs);
+    }else{
+      $ldap->cd($this->dn);
+      $ldap->add($this->attrs);
+    }
+    if($this->initially_was_account){
+      $this->handle_post_events("modify");
+    }else{
+      $this->handle_post_events("add");
+    }
+
+    show_ldap_error($ldap->get_error(), sprintf(_("Saving of server services/anti virus with dn '%s' failed."),$this->dn));
+  }
+
+  function check()
+  { 
+    $message = plugin::check();
+    return($message);
+  }
+  
+
+  function save_object()
+  {
+    if(isset($_POST['goVirusServer'])){
+      plugin::save_object();
+      foreach($this->Flags as $flag){
+        $var = "avFlags".$flag;
+        if(isset($_POST[$var])){
+          $this->$var = TRUE;
+        }else{
+          $this->$var = FALSE;
+        }
+      }
+    }    
+  }  
+
+  
+  /* Return plugin informations for acl handling 
+  function plInfo()
+  {
+    return (array(
+          "plShortName"   => _("Anti virus"),
+          "plDescription" => _("Anti virus service"),
+          "plSelfModify"  => FALSE,
+          "plDepends"     => array(),
+          "plPriority"    => 0,
+          "plSection"     => array("administration"),
+          "plCategory"    => array("server"),
+          "plProvidedAcls"=> array(
+
+
+          "avFlagsD"         =>_("Enable debugging"),
+          "avFlagsS"         =>_("Enable mail scanning"),
+          "avFlagsA"         =>_("Enable scanning of archives"),
+          "avFlagsE"         =>_("Block encrypted archives"),
+
+          "avMaxThreads"                 =>_("Maximum threads"),
+//          "avMaxDirectoryRecursions"     =>_(""),
+//          "avUser"                       =>_(""),
+          "avArchiveMaxFileSize"         =>_("Maximum file size"),
+          "avArchiveMaxRecursion"        =>_("Maximum recursions"),
+          "avArchiveMaxCompressionRatio" =>_("Maximum compression ratio"),
+          "avDatabaseMirror"             =>_("Database mirror"),
+          "avChecksPerDay"               =>_("Checks per day"),
+          "avHttpProxyURL"               =>_("Http proxy URL"))
+          ));
+  }
+  */
+
+  /* For newer service management dialogs */
+  /*function getListEntry()
+  {
+    $this->updateStatusState();
+    $flag                   = $this->StatusFlag;
+    $fields['Status']       = $this->$flag;
+    $fields['Message']      = _("Anti virus");
+    $fields['AllowStart']   = true;
+    $fields['AllowStop']    = true;
+    $fields['AllowRestart'] = true;
+    $fields['AllowRemove']  = true;
+    $fields['AllowEdit']    = true;
+    return($fields);
+  }
+
+  function updateStatusState()
+  {
+    if(empty($this->StatusFlag)) return;
+
+    $attrs = array();
+    $flag = $this->StatusFlag;
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($this->cn);
+    $ldap->cat($this->dn,array($flag));
+    if($ldap->count()){
+      $attrs = $ldap->fetch();
+    }
+    if(isset($attrs[$flag][0])){
+      $this->$flag = $attrs[$flag][0];
+    }
+  }
+  function action_hook($add_attrs= array())
+  {
+    /* Find postcreate entries for this class * /
+    $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
+    if ($command == "" && isset($this->config->data['TABS'])){
+      $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
+    }
+    if ($command != ""){
+      /* Walk through attribute list * /
+      foreach ($this->attributes as $attr){
+        if (!is_array($this->$attr)){
+          $command= preg_replace("/%$attr/", $this->$attr, $command);
+        }
+      }
+      $command= preg_replace("/%dn/", $this->dn, $command);
+      /* Additional attributes * /
+      foreach ($add_attrs as $name => $value){
+        $command= preg_replace("/%$name/", $value, $command);
+      }
+
+      /* If there are still some %.. in our command, try to fill these with some other class vars * /
+      if(preg_match("/%/",$command)){
+        $attrs = get_object_vars($this);
+        foreach($attrs as $name => $value){
+          if(!is_string($value)) continue;
+          $command= preg_replace("/%$name/", $value, $command);
+        }
+      }
+
+      if (check_command($command)){
+        @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
+            $command, "Execute");
+
+        exec($command);
+      } else {
+        $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
+        print_red ($message);
+      }
+    }
+  }
+
+  /* Directly save new status flag * /
+  function setStatus($value)
+  {
+    if($value == "none") return;
+    if(!$this->initially_was_account) return;
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($this->dn);
+    $ldap->cat($this->dn,array("objectClass"));
+    if($ldap->count()){
+
+      $tmp = $ldap->fetch();
+      for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
+        $attrs['objectClass'][] = $tmp['objectClass'][$i];
+      }
+      $flag = $this->StatusFlag;
+      $attrs[$flag] = $value;
+      $this->$flag = $value;
+      $ldap->modify($attrs);
+      show_ldap_error($ldap->get_error(), sprintf(_("Set status flag for server services/anti virus with dn '%s' failed."),$this->dn));
+      $this->action_hook();
+    }
+  }
+
+
+  */
+
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/plugins/admin/systems/goVirusServer.tpl b/plugins/admin/systems/goVirusServer.tpl
new file mode 100644 (file)
index 0000000..f5a6fd9
--- /dev/null
@@ -0,0 +1,112 @@
+
+<table style='width:100%;'>
+ <tr>
+  <td>
+       <h2>{t}Generic virus filtering{/t}</h2> 
+       <table style='width:100%;'>
+        <tr>
+         <td>
+               {t}Maximum threads{/t}
+         </td>
+         <td>
+               <input type='text' name='avMaxThreads' value='{$avMaxThreads}' {$avMaxThreadsACL}>
+         </td>
+        </tr>
+        <tr>
+         <td>
+               {t}Database mirror{/t}
+         </td>
+         <td>
+               <input type='text' name='avDatabaseMirror' value='{$avDatabaseMirror}' {$avDatabaseMirrorACL}>
+         </td>
+        </tr>
+        <tr>
+         <td>
+               {t}Checks per day{/t}
+         </td>
+         <td>
+               <input type='text' name='avChecksPerDay' value='{$avChecksPerDay}' {$avChecksPerDayACL}>
+         </td>
+        </tr>
+        <tr>
+         <td>
+               {t}Http proxy URL{/t}
+         </td>
+         <td>
+               <input type='text' name='avHttpProxyURL' value='{$avHttpProxyURL}' {$avHttpProxyURLACL}>
+         </td>
+        </tr>
+       </table>
+  </td>
+  <td style='border-left:1px solid #A0A0A0;'>
+  
+       <table style='width:100%;'>
+        <tr>
+         <td>
+               <input type='checkbox' name='avFlagsD' {$avFlagsDACL} {$avFlagsDCHK} value='1'>
+               {t}Enable debugging{/t}
+         </td>
+        </tr>
+        <tr>
+         <td>
+               <input type='checkbox' name='avFlagsS' {$avFlagsSACL} {$avFlagsSCHK} value='1'>
+               {t}Enable mail scanning{/t}
+         </td>
+        </tr>
+        <tr>
+         <td>
+               <input type='checkbox' name='avFlagsA' {$avFlagsAACL} {$avFlagsACHK} value='1'>
+               {t}Enable scanning of archives{/t}
+         </td>
+        </tr>
+       </table>
+  </td>
+ </tr>
+ <tr>
+  <td colspan=2>
+   <p class='seperator'>&nbsp;</p>
+  </td>
+ </tr>
+ <tr>
+  <td>
+       <h2>{t}Archive scanning{/t}</h2> 
+       <table style='width:100%;'>
+        <tr>
+         <td>{t}Maximum file size{/t}
+         </td>
+         <td>
+          <input name='avArchiveMaxFileSize' value='{$avArchiveMaxFileSize}' {$avArchiveMaxFileSizeACL} >
+         </td>
+        </tr>
+        <tr>
+         <td>{t}Maximum recursion{/t}
+         </td>
+         <td>
+          <input name='avArchiveMaxRecursion' value='{$avArchiveMaxRecursion}' {$avArchiveMaxRecursionACL} >
+         </td>
+        </tr>
+       </table>
+  
+  </td>
+  <td style='border-left:1px solid #A0A0A0;'>
+       <table style='width:100%;'>
+        <tr>
+         <td>{t}Maximum compression ratio{/t}
+         </td>
+         <td>
+          <input name='avArchiveMaxCompressionRatio' value='{$avArchiveMaxCompressionRatio}' {$avArchiveMaxCompressionRatioACL} >
+         </td>
+        </tr>
+        <tr>
+         <td>
+               <input type='checkbox' name='avFlagsE' {$avFlagsEACL} {$avFlagsECHK} value='1'>
+               {t}Block encrypted archives{/t}
+         </td>
+        </tr>
+       </table>
+  
+  </td>
+ </tr>
+</table>
+<input type='hidden' name='goVirusServer' value='1'>