Code

Fixed logging
[gosa.git] / plugins / admin / systems / class_goVirusServer.inc
1 <?php
3 require_once("class_goService.inc");
5 class govirusserver extends goService{
6         
7   /* This plugin only writes its objectClass */
8   var $objectclasses    = array("goVirusServer");
9   var $attributes       = array("avMaxThreads","avMaxDirectoryRecursions","avUser","avFlags","avArchiveMaxFileSize","avArchiveMaxRecursion",
10                                 "avArchiveMaxCompressionRatio","avDatabaseMirror","avChecksPerDay","avHttpProxyURL");
11   var $StatusFlag       = "avStatus";
12  
13   /* This class can't be assigned twice so it conflicts with itsself */
14   var $conflicts        = array("goVirusServer");
16   var $DisplayName      = "";
17   var $dn               = NULL;
18   var $cn               = "";
19   var $avStatus         = "";
21   var $dialog           = NULL;
22   var $ui               = NULL;
24   var $Flags            = array("D","S","A","E");
25   
26   var $avFlags          = "DS";
27   var $avFlagsD         = TRUE;
28   var $avFlagsS         = TRUE;
29   var $avFlagsA         = FALSE;
30   var $avFlagsE         = FALSE;
32   var $avMaxThreads                 = 5;
33   var $avMaxDirectoryRecursions     = 4;    
34   var $avArchiveMaxFileSize         = 4000;
35   var $avArchiveMaxRecursion        = 5;
36   var $avArchiveMaxCompressionRatio = 95;
37   var $avChecksPerDay               = 12;
39   var $avUser                       = "";
40   var $avHttpProxyURL               = "";
41   var $avDatabaseMirror             = "";
42   var $view_logged  =FALSE;
44   function govirusserver($config,$dn, $parent= NULL)
45   {
46     /* Init class */
47     goService::goService($config,$dn, $parent);
48     $this->DisplayName = _("Anti virus");
50     /* Get userinfo & acls */
51     $this->ui = get_userinfo();
53     /* Get Flags */
54     foreach($this->Flags as $flag){
55       $var = "avFlags".$flag;
56       if(preg_match("/".$flag."/",$this->avFlags)){
57         $this->$var = TRUE;
58       }
59     }
60   }
63   function execute()
64   {
65     $smarty = get_smarty(); 
67     if($this->is_account && !$this->view_logged){
68       $this->view_logged = TRUE;
69       @log::log("view","server/".get_class($this),$this->dn);
70     }
73     /* Set acls */
74     $tmp = $this->plInfo();
75     foreach($tmp['plProvidedAcls'] as $name => $translation) { 
76       $smarty->assign($name."ACL",$this->getacl($name));
77     }
79     $display = "";
80     $smarty->assign("servtabs",FALSE);
81     $this->is_account = true;
83     /* Assign smarty vars */
84     foreach($this->attributes as $attr){
85       $smarty->assign($attr,$this->$attr);
86     }
88     /* Assign checkbox states */
89     foreach($this->Flags as $Flag){
90       $var = "avFlags".$Flag;
91       if($this->$var){
92         $smarty->assign("avFlags".$Flag."CHK"," checked " );
93       }else{
94         $smarty->assign("avFlags".$Flag."CHK","");
95       }
96     }
98     /* Assign value for max thread select box */
99     $tmp = array();
100     for($i = 1 ; $i <= 20 ; $i ++){
101       $tmp[$i] = $i;
102     }
103     $smarty->assign("ThreadValues",$tmp);
105     if($this->avFlagsA){
106       $smarty->assign("avFlagsAState" , "" );
107     }else{
108       $smarty->assign("avFlagsAState" , " disabled " );
109     }
111     return($display.$smarty->fetch(get_template_path("goVirusServer.tpl",TRUE,dirname(__FILE__))));
112   }
115   function save()
116   {
117     if(!$this->is_account) return;
119     /* Create Flags */     
120     $this->avFlags = "";
121     foreach($this->Flags as $flag){
122       $var = "avFlags".$flag;
123       if($this->$var){
124         $this->avFlags .=$flag;
125       }
126     }
128     plugin::save();
130     if(!$this->avFlagsA){
131       $arr = array("avArchiveMaxFileSize","avArchiveMaxRecursion","avArchiveMaxCompressionRatio");
132       foreach($arr as $attr){
133         $this->attrs[$attr] =  array();
134       }
135       $this->attrs['avFlags'] = preg_replace("/E/","",$this->attrs['avFlags']);
136     }
138     /* Check if this is a new entry ... add/modify */
139     $ldap = $this->config->get_ldap_link();
140     $ldap->cat($this->dn,array("objectClass"));
141     if($ldap->count()){
142       $ldap->cd($this->dn);
143       $ldap->modify($this->attrs);
144     }else{
145       $ldap->cd($this->dn);
146       $ldap->add($this->attrs);
147     }
148     if($this->initially_was_account){
149       $this->handle_post_events("modify");
150       @log::log("modify","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
151     }else{
152       $this->handle_post_events("add");
153       @log::log("create","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
154     }
156     show_ldap_error($ldap->get_error(), sprintf(_("Saving of server services/anti virus with dn '%s' failed."),$this->dn));
157   }
159   function check()
160   { 
161     $message = plugin::check();
163     $mustBeNumeric = array(
164           "avMaxDirectoryRecursions"     =>_("Maximum directory recursions"),
165           "avMaxThreads"                 =>_("Maximum threads"),
166           "avArchiveMaxFileSize"         =>_("Maximum file size"),
167           "avArchiveMaxRecursion"        =>_("Maximum recursions"),
168           "avArchiveMaxCompressionRatio" =>_("Maximum compression ratio"),
169           "avChecksPerDay"               =>_("Checks per day"));
171     foreach($mustBeNumeric as $key => $trans){
172       if(!is_numeric($this->$key)){
173         $message[] = sprintf(_("The specified value for '%s' must be a numeric value."),$trans);
174       }
175     }
177     foreach(array("avUser"=>_("Database user"),"avHttpProxyURL"=>_("Http proxy URL"),"avDatabaseMirror"=>_("Database mirror")) as $attr => $name){
178       if(!preg_match("/^[a-z0-9:_\-\.\/]*$/",$this->$attr)){
179         $message[] = sprintf(_("Please specify a valid value for '%s'."),$name);
180       }
181     }
182   
183     return($message);
184   }
185   
187   function save_object()
188   {
189     if(isset($_POST['goVirusServer'])){
190       plugin::save_object();
191       foreach($this->Flags as $flag){
193         $var = "avFlags".$flag;
194         if($this->acl_is_writeable($var)){
195           if(isset($_POST[$var])){
196             $this->$var = TRUE;
197           }else{
198             $this->$var = FALSE;
199           }
200         }
201       }
202     }    
203   }  
204   
206   /* For newer service management dialogs */
207   function getListEntry()
208   {
209     $fields       = goService::getListEntry();
210     $fields['AllowEdit']    = true;
211     $fields['Message']      = _("Anti virus");
212     return($fields);
213   }
216   /* Return plugin informations for acl handling */ 
217   function plInfo()
218   {
219     return (array(
220           "plShortName"   => _("Anti virus"),
221           "plDescription" => _("Anti virus")." ("._("Services").")",
222           "plSelfModify"  => FALSE,
223           "plDepends"     => array(),
224           "plPriority"    => 96,
225           "plSection"     => array("administration"),
226           "plCategory"    => array("server"),
227           "plProvidedAcls"=> array(
229           "start"         => _("Start"),
230           "stop"          => _("Stop"),
231           "restart"       => _("Restart"),
233           "avFlagsD"         =>_("Enable debugging"),
234           "avFlagsS"         =>_("Enable mail scanning"),
235           "avFlagsA"         =>_("Enable scanning of archives"),
236           "avFlagsE"         =>_("Block encrypted archives"),
238           "avMaxThreads"                 =>_("Maximum threads"),
239           "avMaxDirectoryRecursions"     =>_("Maximum directory recursions"),
240           "avUser"                       =>_("Anti virus user"),
241           "avArchiveMaxFileSize"         =>_("Maximum file size"),
242           "avArchiveMaxRecursion"        =>_("Maximum recursions"),
243           "avArchiveMaxCompressionRatio" =>_("Maximum compression ratio"),
244           "avDatabaseMirror"             =>_("Database mirror"),
245           "avChecksPerDay"               =>_("Checks per day"),
246           "avHttpProxyURL"               =>_("Http proxy URL"))
247           ));
248   }
250 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
251 ?>