Code

ee4bb64e31c8c52af72c5713f8ae1c5ca26300e4
[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 $saStatus         = "";
19   var $dialog           = NULL;
20   var $ui               = NULL;
21   var $acl              = NULL;
23   var $Flags            = array("D","S","A","E");
24   
25   var $avFlags          = "";
26   var $avFlagsD         = FALSE;
27   var $avFlagsS         = FALSE;
28   var $avFlagsA         = FALSE;
29   var $avFlagsE         = FALSE;
31   var $avMaxThreads                 = 5;
32   var $avMaxDirectoryRecursions     = 4;    
33 //  var $avUser                       = "";
34   var $avArchiveMaxFileSize         = 4000;
35   var $avArchiveMaxRecursion        = 5;
36   var $avArchiveMaxCompressionRatio = 95;
37   var $avDatabaseMirror             = "";
38   var $avChecksPerDay               = 12;
39   var $avHttpProxyURL               = "";
41   function goVirusServer($config,$dn)
42   {
43     /* Init class */
44     plugin::plugin($config,$dn);
45     $this->DisplayName = _("Anti virus");
47     /* Get userinfo & acls */
48     $this->ui = get_userinfo();
50     /* Set up the users ACL's for this 'dn' */
51     $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
52     $this->acl= get_module_permission($acl, "goVirusServer", $this->ui->dn);
54     /* Get Flags */
55     foreach($this->Flags as $flag){
56       $var = "avFlags".$flag;
57       if(preg_match("/".$flag."/",$this->avFlags)){
58         $this->$var = TRUE;
59       }
60     }
61   }
64   function execute()
65   {
66     /* Do we need to flip is_account state? */
67     if (isset($_POST['modify_state'])) {
68       $this->is_account = !$this->is_account;
69     }
70  
71     /* Show tab dialog headers */
72     if ($this->is_account) {
73       /* call Add Acoount to add account */
74       $display = $this->show_header(_("Remove anti virus extension"), 
75         _("This server has anti virus features enabled. You can disable them by clicking below."));
76     } else {
77       /* call remove Account */
78       $display = $this->show_header(_("Add anti virus service"), 
79         _("This server has anti virus features disabled. You can enable them by clicking below."));
80       return ($display);
81     }
83     /* Assign smarty vars */
84     $smarty = get_smarty(); 
85     foreach($this->attributes as $attr){
86       $smarty->assign($attr,$this->$attr);
87       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
88     }
90     /* Assign checkbox states */
91     foreach($this->Flags as $Flag){
92       $var = "avFlags".$Flag;
93       $smarty->assign("avFlags".$Flag."ACL",chkacl($this->acl,$Flag));
94       if($this->$var){
95         $smarty->assign("avFlags".$Flag."CHK"," checked " );
96       }else{
97         $smarty->assign("avFlags".$Flag."CHK","");
98       }
99     }
101     return($display.$smarty->fetch(get_template_path("goVirusServer.tpl",TRUE,dirname(__FILE__))));
102   }
105   /* Add $post to list of configured trusted */
106   function AddTrust($post)
107   {
108     if(!empty($post)){
109       $this->TrustedNetworks[$post] = $post;
110     }
111   }
114   /* Delete trusted network */
115   function DelTrust($posts)
116   {
117     foreach($posts as $post){
118       if(isset($this->TrustedNetworks[$post])){
119         unset($this->TrustedNetworks[$post]);     
120       }
121     }
122   }
125   /* remove this extension */
126   function remove_from_parent()
127   {
128     if(!$this->is_account && $this->initially_was_account){
129       plugin::remove_from_parent();
131       /* Check if this is a new entry ... add/modify */
132       $ldap = $this->config->get_ldap_link();
133       $ldap->cat($this->dn,array("objectClass"));
134       if($ldap->count()){
135         $ldap->cd($this->dn);
136         $ldap->modify($this->attrs);
137       }else{
138         $ldap->cd($this->dn);
139         $ldap->add($this->attrs);
140       }
141       show_ldap_error($ldap->get_error(), sprintf(_("Removing of server services/anti virus with dn '%s' failed."),$this->dn));
142       $this->handle_post_events("remove");
143     }
144   }
147   function save()
148   {
149     if(!$this->is_account) return;
151     /* Create Flags */     
152     $this->avFlags = "";
153     foreach($this->Flags as $flag){
154       $var = "avFlags".$flag;
155       if($this->$var){
156         $this->avFlags .=$flag;
157       }
158     }
160     plugin::save();
162     print_a($this->attrs);
164     /* Check if this is a new entry ... add/modify */
165     $ldap = $this->config->get_ldap_link();
166     $ldap->cat($this->dn,array("objectClass"));
167     if($ldap->count()){
168       $ldap->cd($this->dn);
169       $ldap->modify($this->attrs);
170     }else{
171       $ldap->cd($this->dn);
172       $ldap->add($this->attrs);
173     }
174     if($this->initially_was_account){
175       $this->handle_post_events("modify");
176     }else{
177       $this->handle_post_events("add");
178     }
180     show_ldap_error($ldap->get_error(), sprintf(_("Saving of server services/anti virus with dn '%s' failed."),$this->dn));
181   }
183   function check()
184   { 
185     $message = plugin::check();
186     return($message);
187   }
188   
190   function save_object()
191   {
192     if(isset($_POST['goVirusServer'])){
193       plugin::save_object();
194       foreach($this->Flags as $flag){
195         $var = "avFlags".$flag;
196         if(isset($_POST[$var])){
197           $this->$var = TRUE;
198         }else{
199           $this->$var = FALSE;
200         }
201       }
202     }    
203   }  
205   
206   /* Return plugin informations for acl handling 
207   function plInfo()
208   {
209     return (array(
210           "plShortName"   => _("Anti virus"),
211           "plDescription" => _("Anti virus service"),
212           "plSelfModify"  => FALSE,
213           "plDepends"     => array(),
214           "plPriority"    => 0,
215           "plSection"     => array("administration"),
216           "plCategory"    => array("server"),
217           "plProvidedAcls"=> array(
220           "avFlagsD"         =>_("Enable debugging"),
221           "avFlagsS"         =>_("Enable mail scanning"),
222           "avFlagsA"         =>_("Enable scanning of archives"),
223           "avFlagsE"         =>_("Block encrypted archives"),
225           "avMaxThreads"                 =>_("Maximum threads"),
226 //          "avMaxDirectoryRecursions"     =>_(""),
227 //          "avUser"                       =>_(""),
228           "avArchiveMaxFileSize"         =>_("Maximum file size"),
229           "avArchiveMaxRecursion"        =>_("Maximum recursions"),
230           "avArchiveMaxCompressionRatio" =>_("Maximum compression ratio"),
231           "avDatabaseMirror"             =>_("Database mirror"),
232           "avChecksPerDay"               =>_("Checks per day"),
233           "avHttpProxyURL"               =>_("Http proxy URL"))
234           ));
235   }
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   }
269   function action_hook($add_attrs= array())
270   {
271     /* Find postcreate entries for this class * /
272     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
273     if ($command == "" && isset($this->config->data['TABS'])){
274       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
275     }
276     if ($command != ""){
277       /* Walk through attribute list * /
278       foreach ($this->attributes as $attr){
279         if (!is_array($this->$attr)){
280           $command= preg_replace("/%$attr/", $this->$attr, $command);
281         }
282       }
283       $command= preg_replace("/%dn/", $this->dn, $command);
284       /* Additional attributes * /
285       foreach ($add_attrs as $name => $value){
286         $command= preg_replace("/%$name/", $value, $command);
287       }
289       /* If there are still some %.. in our command, try to fill these with some other class vars * /
290       if(preg_match("/%/",$command)){
291         $attrs = get_object_vars($this);
292         foreach($attrs as $name => $value){
293           if(!is_string($value)) continue;
294           $command= preg_replace("/%$name/", $value, $command);
295         }
296       }
298       if (check_command($command)){
299         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
300             $command, "Execute");
302         exec($command);
303       } else {
304         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
305         print_red ($message);
306       }
307     }
308   }
310   /* Directly save new status flag * /
311   function setStatus($value)
312   {
313     if($value == "none") return;
314     if(!$this->initially_was_account) return;
315     $ldap = $this->config->get_ldap_link();
316     $ldap->cd($this->dn);
317     $ldap->cat($this->dn,array("objectClass"));
318     if($ldap->count()){
320       $tmp = $ldap->fetch();
321       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
322         $attrs['objectClass'][] = $tmp['objectClass'][$i];
323       }
324       $flag = $this->StatusFlag;
325       $attrs[$flag] = $value;
326       $this->$flag = $value;
327       $ldap->modify($attrs);
328       show_ldap_error($ldap->get_error(), sprintf(_("Set status flag for server services/anti virus with dn '%s' failed."),$this->dn));
329       $this->action_hook();
330     }
331   }
334   */
337 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
338 ?>