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 goService::goService($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 $display = "";
73 $smarty->assign("servtabs",FALSE);
74 $this->is_account = true;
76 /* Assign smarty vars */
77 foreach($this->attributes as $attr){
78 $smarty->assign($attr,$this->$attr);
79 }
81 /* Assign checkbox states */
82 foreach($this->Flags as $Flag){
83 $var = "avFlags".$Flag;
84 if($this->$var){
85 $smarty->assign("avFlags".$Flag."CHK"," checked " );
86 }else{
87 $smarty->assign("avFlags".$Flag."CHK","");
88 }
89 }
91 /* Assign value for max thread select box */
92 $tmp = array();
93 for($i = 1 ; $i <= 20 ; $i ++){
94 $tmp[$i] = $i;
95 }
96 $smarty->assign("ThreadValues",$tmp);
98 if($this->avFlagsA){
99 $smarty->assign("avFlagsAState" , "" );
100 }else{
101 $smarty->assign("avFlagsAState" , " disabled " );
102 }
104 return($display.$smarty->fetch(get_template_path("goVirusServer.tpl",TRUE,dirname(__FILE__))));
105 }
108 function save()
109 {
110 if(!$this->is_account) return;
112 /* Create Flags */
113 $this->avFlags = "";
114 foreach($this->Flags as $flag){
115 $var = "avFlags".$flag;
116 if($this->$var){
117 $this->avFlags .=$flag;
118 }
119 }
121 plugin::save();
123 if(!$this->avFlagsA){
124 $arr = array("avArchiveMaxFileSize","avArchiveMaxRecursion","avArchiveMaxCompressionRatio");
125 foreach($arr as $attr){
126 $this->attrs[$attr] = array();
127 }
128 $this->attrs['avFlags'] = preg_replace("/E/","",$this->attrs['avFlags']);
129 }
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 if($this->initially_was_account){
142 $this->handle_post_events("modify");
143 @log::log("modify","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
144 }else{
145 $this->handle_post_events("add");
146 @log::log("create","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
147 }
149 show_ldap_error($ldap->get_error(), sprintf(_("Saving of server services/anti virus with dn '%s' failed."),$this->dn));
150 }
152 function check()
153 {
154 $message = plugin::check();
156 $mustBeNumeric = array(
157 "avMaxDirectoryRecursions" =>_("Maximum directory recursions"),
158 "avMaxThreads" =>_("Maximum threads"),
159 "avArchiveMaxFileSize" =>_("Maximum file size"),
160 "avArchiveMaxRecursion" =>_("Maximum recursions"),
161 "avArchiveMaxCompressionRatio" =>_("Maximum compression ratio"),
162 "avChecksPerDay" =>_("Checks per day"));
164 foreach($mustBeNumeric as $key => $trans){
165 if(!is_numeric($this->$key)){
166 $message[] = sprintf(_("The specified value for '%s' must be a numeric value."),$trans);
167 }
168 }
170 foreach(array("avUser"=>_("Database user"),"avHttpProxyURL"=>_("Http proxy URL"),"avDatabaseMirror"=>_("Database mirror")) as $attr => $name){
171 if(!preg_match("/^[a-z0-9:_\-\.\/]*$/",$this->$attr)){
172 $message[] = sprintf(_("Please specify a valid value for '%s'."),$name);
173 }
174 }
176 return($message);
177 }
180 function save_object()
181 {
182 if(isset($_POST['goVirusServer'])){
183 plugin::save_object();
184 foreach($this->Flags as $flag){
186 $var = "avFlags".$flag;
187 if($this->acl_is_writeable($var)){
188 if(isset($_POST[$var])){
189 $this->$var = TRUE;
190 }else{
191 $this->$var = FALSE;
192 }
193 }
194 }
195 }
196 }
199 /* For newer service management dialogs */
200 function getListEntry()
201 {
202 $fields = goService::getListEntry();
203 $fields['AllowEdit'] = true;
204 $fields['Message'] = _("Anti virus");
205 return($fields);
206 }
209 /* Return plugin informations for acl handling */
210 function plInfo()
211 {
212 return (array(
213 "plShortName" => _("Anti virus"),
214 "plDescription" => _("Anti virus")." ("._("Services").")",
215 "plSelfModify" => FALSE,
216 "plDepends" => array(),
217 "plPriority" => 96,
218 "plSection" => array("administration"),
219 "plCategory" => array("server"),
220 "plProvidedAcls"=> array(
222 "start" => _("Start"),
223 "stop" => _("Stop"),
224 "restart" => _("Restart"),
226 "avFlagsD" =>_("Enable debugging"),
227 "avFlagsS" =>_("Enable mail scanning"),
228 "avFlagsA" =>_("Enable scanning of archives"),
229 "avFlagsE" =>_("Block encrypted archives"),
231 "avMaxThreads" =>_("Maximum threads"),
232 "avMaxDirectoryRecursions" =>_("Maximum directory recursions"),
233 "avUser" =>_("Anti virus user"),
234 "avArchiveMaxFileSize" =>_("Maximum file size"),
235 "avArchiveMaxRecursion" =>_("Maximum recursions"),
236 "avArchiveMaxCompressionRatio" =>_("Maximum compression ratio"),
237 "avDatabaseMirror" =>_("Database mirror"),
238 "avChecksPerDay" =>_("Checks per day"),
239 "avHttpProxyURL" =>_("Http proxy URL"))
240 ));
241 }
242 }
243 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
244 ?>