Code

Updated workstation - Startup
[gosa.git] / plugins / admin / systems / class_goVirusServer.inc
index 6335956b77b66de5c1cf303d6658c38a8f3b28e2..0d7cd71592009a3ba93853ef95f56b7c562132cd 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-class govirusserver extends plugin{
+class govirusserver extends goService{
        
   /* This plugin only writes its objectClass */
   var $objectclasses    = array("goVirusServer");
@@ -16,9 +16,7 @@ class govirusserver extends plugin{
   var $cn               = "";
   var $avStatus         = "";
 
-  var $dialog           = NULL;
   var $ui               = NULL;
-  var $acl              = NULL;
 
   var $Flags            = array("D","S","A","E");
   
@@ -38,20 +36,17 @@ class govirusserver extends plugin{
   var $avUser                       = "";
   var $avHttpProxyURL               = "";
   var $avDatabaseMirror             = "";
+  var $view_logged  =FALSE;
 
-  function govirusserver($config,$dn, $parent= NULL)
+  function govirusserver(&$config,$dn, $parent= NULL)
   {
     /* Init class */
-    plugin::plugin($config,$dn, $parent);
+    goService::goService($config,$dn, $parent);
     $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;
@@ -65,42 +60,31 @@ class govirusserver extends plugin{
   function execute()
   {
     $smarty = get_smarty(); 
-    if(get_class($this->parent) == "servtabs"){
 
-      $smarty->assign("servtabs",TRUE);
+    if($this->is_account && !$this->view_logged){
+      $this->view_logged = TRUE;
+      new log("view","server/".get_class($this),$this->dn);
+    }
 
-      /* 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);
-      }
-    }else{
-      $display = "";
-      $smarty->assign("servtabs",FALSE);
-      $this->is_account = true;
+    /* Set acls */
+    $tmp = $this->plInfo();
+    foreach($tmp['plProvidedAcls'] as $name => $translation) { 
+      $smarty->assign($name."ACL",$this->getacl($name));
     }
 
+    $display = "";
+    $smarty->assign("servtabs",FALSE);
+    $this->is_account = true;
+
     /* Assign smarty vars */
     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{
@@ -125,35 +109,6 @@ class govirusserver extends plugin{
   }
 
 
-  /* remove this extension */
-  function remove_from_parent()
-  {
-    if(!$this->is_account && $this->initially_was_account){
-
-      plugin::remove_from_parent();
-
-      /* Remove status flag, it is not a memeber of
-         this->attributes, so ensure that it is deleted too */
-      if(!empty($this->StatusFlag)){
-        $this->attrs[$this->StatusFlag] = array();
-      }
-
-      /* 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;
@@ -189,8 +144,10 @@ class govirusserver extends plugin{
     }
     if($this->initially_was_account){
       $this->handle_post_events("modify");
+      new log("modify","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
     }else{
       $this->handle_post_events("add");
+      new log("create","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
     }
 
     show_ldap_error($ldap->get_error(), sprintf(_("Saving of server services/anti virus with dn '%s' failed."),$this->dn));
@@ -214,6 +171,12 @@ class govirusserver extends plugin{
       }
     }
 
+    foreach(array("avUser"=>_("Database user"),"avHttpProxyURL"=>_("Http proxy URL"),"avDatabaseMirror"=>_("Database mirror")) as $attr => $name){
+      if(!preg_match("/^[a-z0-9:_\-\.\/]*$/",$this->$attr)){
+        $message[] = sprintf(_("Please specify a valid value for '%s'."),$name);
+      }
+    }
+  
     return($message);
   }
   
@@ -223,127 +186,46 @@ class govirusserver extends plugin{
     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;
+        if($this->acl_is_writeable($var)){
+          if(isset($_POST[$var])){
+            $this->$var = TRUE;
+          }else{
+            $this->$var = FALSE;
+          }
         }
       }
     }    
   }  
-
   
 
   /* 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       = goService::getListEntry();
     $fields['AllowEdit']    = true;
+    $fields['Message']      = _("Anti virus");
     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();
-    }
-  }
 
-  /* Return plugin informations for acl handling 
+  /* Return plugin informations for acl handling */ 
   function plInfo()
   {
     return (array(
           "plShortName"   => _("Anti virus"),
-          "plDescription" => _("Anti virus service"),
+          "plDescription" => _("Anti virus")." ("._("Services").")",
           "plSelfModify"  => FALSE,
           "plDepends"     => array(),
-          "plPriority"    => 0,
+          "plPriority"    => 96,
           "plSection"     => array("administration"),
           "plCategory"    => array("server"),
           "plProvidedAcls"=> array(
 
+          "start"         => _("Start"),
+          "stop"          => _("Stop"),
+          "restart"       => _("Restart"),
 
           "avFlagsD"         =>_("Enable debugging"),
           "avFlagsS"         =>_("Enable mail scanning"),
@@ -361,7 +243,6 @@ class govirusserver extends plugin{
           "avHttpProxyURL"               =>_("Http proxy URL"))
           ));
   }
-  */
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>