1 <?php
3 class govirusserver extends plugin{
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";
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");
25 var $avFlags = "DSAE";
26 var $avFlagsD = TRUE;
27 var $avFlagsS = TRUE;
28 var $avFlagsA = TRUE;
29 var $avFlagsE = TRUE;
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 gvirusserver($config,$dn)
43 {
44 /* Init class */
45 plugin::plugin($config,$dn);
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 /* Do we need to flip is_account state? */
68 if (isset($_POST['modify_state'])) {
69 $this->is_account = !$this->is_account;
70 }
72 /* Show tab dialog headers */
73 if ($this->is_account) {
74 /* call Add Acoount to add account */
75 $display = $this->show_header(_("Remove anti virus extension"),
76 _("This server has anti virus features enabled. You can disable them by clicking below."));
77 } else {
78 /* call remove Account */
79 $display = $this->show_header(_("Add anti virus service"),
80 _("This server has anti virus features disabled. You can enable them by clicking below."));
81 return ($display);
82 }
84 /* Assign smarty vars */
85 $smarty = get_smarty();
86 foreach($this->attributes as $attr){
87 $smarty->assign($attr,$this->$attr);
88 $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
89 }
91 /* Assign checkbox states */
92 foreach($this->Flags as $Flag){
93 $var = "avFlags".$Flag;
94 $smarty->assign("avFlags".$Flag."ACL",chkacl($this->acl,$Flag));
95 if($this->$var){
96 $smarty->assign("avFlags".$Flag."CHK"," checked " );
97 }else{
98 $smarty->assign("avFlags".$Flag."CHK","");
99 }
100 }
102 /* Assign value for max thread select box */
103 $tmp = array();
104 for($i = 1 ; $i <= 20 ; $i ++){
105 $tmp[$i] = $i;
106 }
107 $smarty->assign("ThreadValues",$tmp);
109 return($display.$smarty->fetch(get_template_path("goVirusServer.tpl",TRUE,dirname(__FILE__))));
110 }
113 /* remove this extension */
114 function remove_from_parent()
115 {
116 if(!$this->is_account && $this->initially_was_account){
117 plugin::remove_from_parent();
119 /* Check if this is a new entry ... add/modify */
120 $ldap = $this->config->get_ldap_link();
121 $ldap->cat($this->dn,array("objectClass"));
122 if($ldap->count()){
123 $ldap->cd($this->dn);
124 $ldap->modify($this->attrs);
125 }else{
126 $ldap->cd($this->dn);
127 $ldap->add($this->attrs);
128 }
129 show_ldap_error($ldap->get_error(), sprintf(_("Removing of server services/anti virus with dn '%s' failed."),$this->dn));
130 $this->handle_post_events("remove");
131 }
132 }
135 function save()
136 {
137 if(!$this->is_account) return;
139 /* Create Flags */
140 $this->avFlags = "";
141 foreach($this->Flags as $flag){
142 $var = "avFlags".$flag;
143 if($this->$var){
144 $this->avFlags .=$flag;
145 }
146 }
148 plugin::save();
150 /* Check if this is a new entry ... add/modify */
151 $ldap = $this->config->get_ldap_link();
152 $ldap->cat($this->dn,array("objectClass"));
153 if($ldap->count()){
154 $ldap->cd($this->dn);
155 $ldap->modify($this->attrs);
156 }else{
157 $ldap->cd($this->dn);
158 $ldap->add($this->attrs);
159 }
160 if($this->initially_was_account){
161 $this->handle_post_events("modify");
162 }else{
163 $this->handle_post_events("add");
164 }
166 show_ldap_error($ldap->get_error(), sprintf(_("Saving of server services/anti virus with dn '%s' failed."),$this->dn));
167 }
169 function check()
170 {
171 $message = plugin::check();
173 $mustBeNumeric = array(
174 "avMaxThreads" =>_("Maximum threads"),
175 "avArchiveMaxFileSize" =>_("Maximum file size"),
176 "avArchiveMaxRecursion" =>_("Maximum recursions"),
177 "avArchiveMaxCompressionRatio" =>_("Maximum compression ratio"),
178 "avChecksPerDay" =>_("Checks per day"));
180 foreach($mustBeNumeric as $key => $trans){
181 if(!is_numeric($this->$key)){
182 $message[] = sprintf(_("The specified value for '%s' must be a numeric value."),$trans);
183 }
184 }
192 return($message);
193 }
196 function save_object()
197 {
198 if(isset($_POST['goVirusServer'])){
199 plugin::save_object();
200 foreach($this->Flags as $flag){
201 $var = "avFlags".$flag;
202 if(isset($_POST[$var])){
203 $this->$var = TRUE;
204 }else{
205 $this->$var = FALSE;
206 }
207 }
208 }
209 }
212 /* Return plugin informations for acl handling
213 function plInfo()
214 {
215 return (array(
216 "plShortName" => _("Anti virus"),
217 "plDescription" => _("Anti virus service"),
218 "plSelfModify" => FALSE,
219 "plDepends" => array(),
220 "plPriority" => 0,
221 "plSection" => array("administration"),
222 "plCategory" => array("server"),
223 "plProvidedAcls"=> array(
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" =>_(""),
233 // "avUser" =>_(""),
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 */
244 /* For newer service management dialogs */
245 /*function getListEntry()
246 {
247 $this->updateStatusState();
248 $flag = $this->StatusFlag;
249 $fields['Status'] = $this->$flag;
250 $fields['Message'] = _("Anti virus");
251 $fields['AllowStart'] = true;
252 $fields['AllowStop'] = true;
253 $fields['AllowRestart'] = true;
254 $fields['AllowRemove'] = true;
255 $fields['AllowEdit'] = true;
256 return($fields);
257 }
259 function updateStatusState()
260 {
261 if(empty($this->StatusFlag)) return;
263 $attrs = array();
264 $flag = $this->StatusFlag;
265 $ldap = $this->config->get_ldap_link();
266 $ldap->cd($this->cn);
267 $ldap->cat($this->dn,array($flag));
268 if($ldap->count()){
269 $attrs = $ldap->fetch();
270 }
271 if(isset($attrs[$flag][0])){
272 $this->$flag = $attrs[$flag][0];
273 }
274 }
275 function action_hook($add_attrs= array())
276 {
277 /* Find postcreate entries for this class * /
278 $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
279 if ($command == "" && isset($this->config->data['TABS'])){
280 $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
281 }
282 if ($command != ""){
283 /* Walk through attribute list * /
284 foreach ($this->attributes as $attr){
285 if (!is_array($this->$attr)){
286 $command= preg_replace("/%$attr/", $this->$attr, $command);
287 }
288 }
289 $command= preg_replace("/%dn/", $this->dn, $command);
290 /* Additional attributes * /
291 foreach ($add_attrs as $name => $value){
292 $command= preg_replace("/%$name/", $value, $command);
293 }
295 /* If there are still some %.. in our command, try to fill these with some other class vars * /
296 if(preg_match("/%/",$command)){
297 $attrs = get_object_vars($this);
298 foreach($attrs as $name => $value){
299 if(!is_string($value)) continue;
300 $command= preg_replace("/%$name/", $value, $command);
301 }
302 }
304 if (check_command($command)){
305 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
306 $command, "Execute");
308 exec($command);
309 } else {
310 $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
311 print_red ($message);
312 }
313 }
314 }
316 /* Directly save new status flag * /
317 function setStatus($value)
318 {
319 if($value == "none") return;
320 if(!$this->initially_was_account) return;
321 $ldap = $this->config->get_ldap_link();
322 $ldap->cd($this->dn);
323 $ldap->cat($this->dn,array("objectClass"));
324 if($ldap->count()){
326 $tmp = $ldap->fetch();
327 for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
328 $attrs['objectClass'][] = $tmp['objectClass'][$i];
329 }
330 $flag = $this->StatusFlag;
331 $attrs[$flag] = $value;
332 $this->$flag = $value;
333 $ldap->modify($attrs);
334 show_ldap_error($ldap->get_error(), sprintf(_("Set status flag for server services/anti virus with dn '%s' failed."),$this->dn));
335 $this->action_hook();
336 }
337 }
340 */
342 }
343 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
344 ?>