1 <?php
3 require_once("class_goService.inc");
5 class govirusserver extends goService{
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";
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");
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 = "";
43 function govirusserver($config,$dn, $parent= NULL)
44 {
45 /* Init class */
46 plugin::plugin($config,$dn, $parent);
47 $this->DisplayName = _("Anti virus");
49 /* Get userinfo & acls */
50 $this->ui = get_userinfo();
52 /* Get Flags */
53 foreach($this->Flags as $flag){
54 $var = "avFlags".$flag;
55 if(preg_match("/".$flag."/",$this->avFlags)){
56 $this->$var = TRUE;
57 }
58 }
59 }
62 function execute()
63 {
64 $smarty = get_smarty();
66 /* Set acls */
67 $tmp = $this->plInfo();
68 foreach($tmp['plProvidedAcls'] as $name => $translation) {
69 $smarty->assign($name."ACL",$this->getacl($name));
70 }
72 if(get_class($this->parent) == "servtabs"){
74 $smarty->assign("servtabs",TRUE);
76 /* Do we need to flip is_account state? */
77 if (isset($_POST['modify_state'])) {
78 $this->is_account = !$this->is_account;
79 }
81 /* Show tab dialog headers */
82 if ($this->is_account) {
83 /* call Add Acoount to add account */
84 $display = $this->show_header(_("Remove anti virus extension"),
85 _("This server has anti virus features enabled. You can disable them by clicking below."));
86 } else {
87 /* call remove Account */
88 $display = $this->show_header(_("Add anti virus service"),
89 _("This server has anti virus features disabled. You can enable them by clicking below."));
90 return ($display);
91 }
92 }else{
93 $display = "";
94 $smarty->assign("servtabs",FALSE);
95 $this->is_account = true;
96 }
98 /* Assign smarty vars */
99 foreach($this->attributes as $attr){
100 $smarty->assign($attr,$this->$attr);
101 }
103 /* Assign checkbox states */
104 foreach($this->Flags as $Flag){
105 $var = "avFlags".$Flag;
106 if($this->$var){
107 $smarty->assign("avFlags".$Flag."CHK"," checked " );
108 }else{
109 $smarty->assign("avFlags".$Flag."CHK","");
110 }
111 }
113 /* Assign value for max thread select box */
114 $tmp = array();
115 for($i = 1 ; $i <= 20 ; $i ++){
116 $tmp[$i] = $i;
117 }
118 $smarty->assign("ThreadValues",$tmp);
120 if($this->avFlagsA){
121 $smarty->assign("avFlagsAState" , "" );
122 }else{
123 $smarty->assign("avFlagsAState" , " disabled " );
124 }
126 return($display.$smarty->fetch(get_template_path("goVirusServer.tpl",TRUE,dirname(__FILE__))));
127 }
130 function save()
131 {
132 if(!$this->is_account) return;
134 /* Create Flags */
135 $this->avFlags = "";
136 foreach($this->Flags as $flag){
137 $var = "avFlags".$flag;
138 if($this->$var){
139 $this->avFlags .=$flag;
140 }
141 }
143 plugin::save();
145 if(!$this->avFlagsA){
146 $arr = array("avArchiveMaxFileSize","avArchiveMaxRecursion","avArchiveMaxCompressionRatio");
147 foreach($arr as $attr){
148 $this->attrs[$attr] = array();
149 }
150 $this->attrs['avFlags'] = preg_replace("/E/","",$this->attrs['avFlags']);
151 }
153 /* Check if this is a new entry ... add/modify */
154 $ldap = $this->config->get_ldap_link();
155 $ldap->cat($this->dn,array("objectClass"));
156 if($ldap->count()){
157 $ldap->cd($this->dn);
158 $ldap->modify($this->attrs);
159 }else{
160 $ldap->cd($this->dn);
161 $ldap->add($this->attrs);
162 }
163 if($this->initially_was_account){
164 $this->handle_post_events("modify");
165 }else{
166 $this->handle_post_events("add");
167 }
169 show_ldap_error($ldap->get_error(), sprintf(_("Saving of server services/anti virus with dn '%s' failed."),$this->dn));
170 }
172 function check()
173 {
174 $message = plugin::check();
176 $mustBeNumeric = array(
177 "avMaxDirectoryRecursions" =>_("Maximum directory recursions"),
178 "avMaxThreads" =>_("Maximum threads"),
179 "avArchiveMaxFileSize" =>_("Maximum file size"),
180 "avArchiveMaxRecursion" =>_("Maximum recursions"),
181 "avArchiveMaxCompressionRatio" =>_("Maximum compression ratio"),
182 "avChecksPerDay" =>_("Checks per day"));
184 foreach($mustBeNumeric as $key => $trans){
185 if(!is_numeric($this->$key)){
186 $message[] = sprintf(_("The specified value for '%s' must be a numeric value."),$trans);
187 }
188 }
190 return($message);
191 }
194 function save_object()
195 {
196 if(isset($_POST['goVirusServer'])){
197 plugin::save_object();
198 foreach($this->Flags as $flag){
200 $var = "avFlags".$flag;
201 if($this->acl_is_writeable($var)){
202 if(isset($_POST[$var])){
203 $this->$var = TRUE;
204 }else{
205 $this->$var = FALSE;
206 }
207 }
208 }
209 }
210 }
213 /* For newer service management dialogs */
214 function getListEntry()
215 {
216 $fields = goService::getListEntry();
217 $fields['AllowEdit'] = true;
218 return($fields);
219 }
222 /* Return plugin informations for acl handling */
223 function plInfo()
224 {
225 return (array(
226 "plShortName" => _("Anti virus"),
227 "plDescription" => _("Anti virus service"),
228 "plSelfModify" => FALSE,
229 "plDepends" => array(),
230 "plPriority" => 0,
231 "plSection" => array("administration"),
232 "plCategory" => array("server"),
233 "plProvidedAcls"=> array(
236 "avFlagsD" =>_("Enable debugging"),
237 "avFlagsS" =>_("Enable mail scanning"),
238 "avFlagsA" =>_("Enable scanning of archives"),
239 "avFlagsE" =>_("Block encrypted archives"),
241 "avMaxThreads" =>_("Maximum threads"),
242 "avMaxDirectoryRecursions" =>_("Maximum directory recursions"),
243 "avUser" =>_("Anti virus user"),
244 "avArchiveMaxFileSize" =>_("Maximum file size"),
245 "avArchiveMaxRecursion" =>_("Maximum recursions"),
246 "avArchiveMaxCompressionRatio" =>_("Maximum compression ratio"),
247 "avDatabaseMirror" =>_("Database mirror"),
248 "avChecksPerDay" =>_("Checks per day"),
249 "avHttpProxyURL" =>_("Http proxy URL"))
250 ));
251 }
252 }
253 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
254 ?>