Code

Updated inherit button filter, only display the button if gotoWorkstationTemplate...
[gosa.git] / plugins / admin / systems / class_goVirusServer.inc
1 <?php
3 class govirusserver extends plugin{
4         
5   /* This plugin only writes its objectClass */
6   var $objectclasses    = array("goVirusServer");
7   var $attributes       = array("avMaxThreads","avMaxDirectoryRecursions","avUser","avFlags","avArchiveMaxFileSize","avArchiveMaxRecursion",
8                                 "avArchiveMaxCompressionRatio","avDatabaseMirror","avChecksPerDay","avHttpProxyURL");
9   var $StatusFlag       = "avStatus";
10  
11   /* This class can't be assigned twice so it conflicts with itsself */
12   var $conflicts        = array("goVirusServer");
14   var $DisplayName      = "";
15   var $dn               = NULL;
16   var $cn               = "";
17   var $avStatus         = "";
19   var $dialog           = NULL;
20   var $ui               = NULL;
21   var $acl              = NULL;
23   var $Flags            = array("D","S","A","E");
24   
25   var $avFlags          = "DS";
26   var $avFlagsD         = TRUE;
27   var $avFlagsS         = TRUE;
28   var $avFlagsA         = FALSE;
29   var $avFlagsE         = FALSE;
31   var $avMaxThreads                 = 5;
32   var $avMaxDirectoryRecursions     = 4;    
33   var $avArchiveMaxFileSize         = 4000;
34   var $avArchiveMaxRecursion        = 5;
35   var $avArchiveMaxCompressionRatio = 95;
36   var $avChecksPerDay               = 12;
38   var $avUser                       = "";
39   var $avHttpProxyURL               = "";
40   var $avDatabaseMirror             = "";
42   function govirusserver($config,$dn, $parent= NULL)
43   {
44     /* Init class */
45     plugin::plugin($config,$dn, $parent);
46     $this->DisplayName = _("Anti virus");
48     /* Get userinfo & acls */
49     $this->ui = get_userinfo();
51     /* Set up the users ACL's for this 'dn' */
52     $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
53     $this->acl= get_module_permission($acl, "goVirusServer", $this->ui->dn);
55     /* Get Flags */
56     foreach($this->Flags as $flag){
57       $var = "avFlags".$flag;
58       if(preg_match("/".$flag."/",$this->avFlags)){
59         $this->$var = TRUE;
60       }
61     }
62   }
65   function execute()
66   {
67     $smarty = get_smarty(); 
68     if(get_class($this->parent) == "servtabs"){
70       $smarty->assign("servtabs",TRUE);
72       /* Do we need to flip is_account state? */
73       if (isset($_POST['modify_state'])) {
74         $this->is_account = !$this->is_account;
75       }
77       /* Show tab dialog headers */
78       if ($this->is_account) {
79         /* call Add Acoount to add account */
80         $display = $this->show_header(_("Remove anti virus extension"), 
81             _("This server has anti virus features enabled. You can disable them by clicking below."));
82       } else {
83         /* call remove Account */
84         $display = $this->show_header(_("Add anti virus service"), 
85             _("This server has anti virus features disabled. You can enable them by clicking below."));
86         return ($display);
87       }
88     }else{
89       $display = "";
90       $smarty->assign("servtabs",FALSE);
91       $this->is_account = true;
92     }
94     /* Assign smarty vars */
95     foreach($this->attributes as $attr){
96       $smarty->assign($attr,$this->$attr);
97       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
98     }
100     /* Assign checkbox states */
101     foreach($this->Flags as $Flag){
102       $var = "avFlags".$Flag;
103       $smarty->assign("avFlags".$Flag."ACL",chkacl($this->acl,$Flag));
104       if($this->$var){
105         $smarty->assign("avFlags".$Flag."CHK"," checked " );
106       }else{
107         $smarty->assign("avFlags".$Flag."CHK","");
108       }
109     }
111     /* Assign value for max thread select box */
112     $tmp = array();
113     for($i = 1 ; $i <= 20 ; $i ++){
114       $tmp[$i] = $i;
115     }
116     $smarty->assign("ThreadValues",$tmp);
118     if($this->avFlagsA){
119       $smarty->assign("avFlagsAState" , "" );
120     }else{
121       $smarty->assign("avFlagsAState" , " disabled " );
122     }
124     return($display.$smarty->fetch(get_template_path("goVirusServer.tpl",TRUE,dirname(__FILE__))));
125   }
128   /* remove this extension */
129   function remove_from_parent()
130   {
131     if(!$this->is_account && $this->initially_was_account){
133       plugin::remove_from_parent();
135       /* Remove status flag, it is not a memeber of
136          this->attributes, so ensure that it is deleted too */
137       if(!empty($this->StatusFlag)){
138         $this->attrs[$this->StatusFlag] = array();
139       }
141       /* Check if this is a new entry ... add/modify */
142       $ldap = $this->config->get_ldap_link();
143       $ldap->cat($this->dn,array("objectClass"));
144       if($ldap->count()){
145         $ldap->cd($this->dn);
146         $ldap->modify($this->attrs);
147       }else{
148         $ldap->cd($this->dn);
149         $ldap->add($this->attrs);
150       }
151       show_ldap_error($ldap->get_error(), sprintf(_("Removing of server services/anti virus with dn '%s' failed."),$this->dn));
152       $this->handle_post_events("remove");
153     }
154   }
157   function save()
158   {
159     if(!$this->is_account) return;
161     /* Create Flags */     
162     $this->avFlags = "";
163     foreach($this->Flags as $flag){
164       $var = "avFlags".$flag;
165       if($this->$var){
166         $this->avFlags .=$flag;
167       }
168     }
170     plugin::save();
172     if(!$this->avFlagsA){
173       $arr = array("avArchiveMaxFileSize","avArchiveMaxRecursion","avArchiveMaxCompressionRatio");
174       foreach($arr as $attr){
175         $this->attrs[$attr] =  array();
176       }
177       $this->attrs['avFlags'] = preg_replace("/E/","",$this->attrs['avFlags']);
178     }
180     /* Check if this is a new entry ... add/modify */
181     $ldap = $this->config->get_ldap_link();
182     $ldap->cat($this->dn,array("objectClass"));
183     if($ldap->count()){
184       $ldap->cd($this->dn);
185       $ldap->modify($this->attrs);
186     }else{
187       $ldap->cd($this->dn);
188       $ldap->add($this->attrs);
189     }
190     if($this->initially_was_account){
191       $this->handle_post_events("modify");
192     }else{
193       $this->handle_post_events("add");
194     }
196     show_ldap_error($ldap->get_error(), sprintf(_("Saving of server services/anti virus with dn '%s' failed."),$this->dn));
197   }
199   function check()
200   { 
201     $message = plugin::check();
203     $mustBeNumeric = array(
204           "avMaxDirectoryRecursions"     =>_("Maximum directory recursions"),
205           "avMaxThreads"                 =>_("Maximum threads"),
206           "avArchiveMaxFileSize"         =>_("Maximum file size"),
207           "avArchiveMaxRecursion"        =>_("Maximum recursions"),
208           "avArchiveMaxCompressionRatio" =>_("Maximum compression ratio"),
209           "avChecksPerDay"               =>_("Checks per day"));
211     foreach($mustBeNumeric as $key => $trans){
212       if(!is_numeric($this->$key)){
213         $message[] = sprintf(_("The specified value for '%s' must be a numeric value."),$trans);
214       }
215     }
217     return($message);
218   }
219   
221   function save_object()
222   {
223     if(isset($_POST['goVirusServer'])){
224       plugin::save_object();
225       foreach($this->Flags as $flag){
226         $var = "avFlags".$flag;
227         if(isset($_POST[$var])){
228           $this->$var = TRUE;
229         }else{
230           $this->$var = FALSE;
231         }
232       }
233     }    
234   }  
236   
238   /* For newer service management dialogs */
239   function getListEntry()
240   {
241     $this->updateStatusState();
242     $flag                   = $this->StatusFlag;
243     $fields['Status']       = $this->$flag;
244     $fields['Message']      = _("Anti virus");
245     $fields['AllowStart']   = true;
246     $fields['AllowStop']    = true;
247     $fields['AllowRestart'] = true;
248     $fields['AllowRemove']  = true;
249     $fields['AllowEdit']    = true;
250     return($fields);
251   }
253   function updateStatusState()
254   {
255     if(empty($this->StatusFlag)) return;
257     $attrs = array();
258     $flag = $this->StatusFlag;
259     $ldap = $this->config->get_ldap_link();
260     $ldap->cd($this->cn);
261     $ldap->cat($this->dn,array($flag));
262     if($ldap->count()){
263       $attrs = $ldap->fetch();
264     }
265     if(isset($attrs[$flag][0])){
266       $this->$flag = $attrs[$flag][0];
267     }
268   }
270   function action_hook($add_attrs= array())
271   {
272     /* Find postcreate entries for this class */
273     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
274     if ($command == "" && isset($this->config->data['TABS'])){
275       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
276     }
277     if ($command != ""){
278       /* Walk through attribute list */
279       foreach ($this->attributes as $attr){
280         if (!is_array($this->$attr)){
281           $command= preg_replace("/%$attr/", $this->$attr, $command);
282         }
283       }
284       $command= preg_replace("/%dn/", $this->dn, $command);
285       /* Additional attributes */
286       foreach ($add_attrs as $name => $value){
287         $command= preg_replace("/%$name/", $value, $command);
288       }
290       /* If there are still some %.. in our command, try to fill these with some other class vars */
291       if(preg_match("/%/",$command)){
292         $attrs = get_object_vars($this);
293         foreach($attrs as $name => $value){
294           if(!is_string($value)) continue;
295           $command= preg_replace("/%$name/", $value, $command);
296         }
297       }
299       if (check_command($command)){
300         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
301             $command, "Execute");
303         exec($command);
304       } else {
305         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
306         print_red ($message);
307       }
308     }
309   }
311   /* Directly save new status flag */
312   function setStatus($value)
313   {
314     if($value == "none") return;
315     if(!$this->initially_was_account) return;
316     $ldap = $this->config->get_ldap_link();
317     $ldap->cd($this->dn);
318     $ldap->cat($this->dn,array("objectClass"));
319     if($ldap->count()){
321       $tmp = $ldap->fetch();
322       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
323         $attrs['objectClass'][] = $tmp['objectClass'][$i];
324       }
325       $flag = $this->StatusFlag;
326       $attrs[$flag] = $value;
327       $this->$flag = $value;
328       $ldap->modify($attrs);
329       show_ldap_error($ldap->get_error(), sprintf(_("Set status flag for server services/anti virus with dn '%s' failed."),$this->dn));
330       $this->action_hook();
331     }
332   }
334   /* Return plugin informations for acl handling 
335   function plInfo()
336   {
337     return (array(
338           "plShortName"   => _("Anti virus"),
339           "plDescription" => _("Anti virus service"),
340           "plSelfModify"  => FALSE,
341           "plDepends"     => array(),
342           "plPriority"    => 0,
343           "plSection"     => array("administration"),
344           "plCategory"    => array("server"),
345           "plProvidedAcls"=> array(
348           "avFlagsD"         =>_("Enable debugging"),
349           "avFlagsS"         =>_("Enable mail scanning"),
350           "avFlagsA"         =>_("Enable scanning of archives"),
351           "avFlagsE"         =>_("Block encrypted archives"),
353           "avMaxThreads"                 =>_("Maximum threads"),
354           "avMaxDirectoryRecursions"     =>_("Maximum directory recursions"),
355           "avUser"                       =>_("Anti virus user"),
356           "avArchiveMaxFileSize"         =>_("Maximum file size"),
357           "avArchiveMaxRecursion"        =>_("Maximum recursions"),
358           "avArchiveMaxCompressionRatio" =>_("Maximum compression ratio"),
359           "avDatabaseMirror"             =>_("Database mirror"),
360           "avChecksPerDay"               =>_("Checks per day"),
361           "avHttpProxyURL"               =>_("Http proxy URL"))
362           ));
363   }
364   */
366 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
367 ?>