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 $avStatus = "";
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 govirusserver($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 $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 return($display.$smarty->fetch(get_template_path("goVirusServer.tpl",TRUE,dirname(__FILE__))));
119 }
122 /* remove this extension */
123 function remove_from_parent()
124 {
125 if(!$this->is_account && $this->initially_was_account){
126 plugin::remove_from_parent();
128 /* Check if this is a new entry ... add/modify */
129 $ldap = $this->config->get_ldap_link();
130 $ldap->cat($this->dn,array("objectClass"));
131 if($ldap->count()){
132 $ldap->cd($this->dn);
133 $ldap->modify($this->attrs);
134 }else{
135 $ldap->cd($this->dn);
136 $ldap->add($this->attrs);
137 }
138 show_ldap_error($ldap->get_error(), sprintf(_("Removing of server services/anti virus with dn '%s' failed."),$this->dn));
139 $this->handle_post_events("remove");
140 }
141 }
144 function save()
145 {
146 if(!$this->is_account) return;
148 /* Create Flags */
149 $this->avFlags = "";
150 foreach($this->Flags as $flag){
151 $var = "avFlags".$flag;
152 if($this->$var){
153 $this->avFlags .=$flag;
154 }
155 }
157 plugin::save();
159 /* Check if this is a new entry ... add/modify */
160 $ldap = $this->config->get_ldap_link();
161 $ldap->cat($this->dn,array("objectClass"));
162 if($ldap->count()){
163 $ldap->cd($this->dn);
164 $ldap->modify($this->attrs);
165 }else{
166 $ldap->cd($this->dn);
167 $ldap->add($this->attrs);
168 }
169 if($this->initially_was_account){
170 $this->handle_post_events("modify");
171 }else{
172 $this->handle_post_events("add");
173 }
175 show_ldap_error($ldap->get_error(), sprintf(_("Saving of server services/anti virus with dn '%s' failed."),$this->dn));
176 }
178 function check()
179 {
180 $message = plugin::check();
182 $mustBeNumeric = array(
183 "avMaxThreads" =>_("Maximum threads"),
184 "avArchiveMaxFileSize" =>_("Maximum file size"),
185 "avArchiveMaxRecursion" =>_("Maximum recursions"),
186 "avArchiveMaxCompressionRatio" =>_("Maximum compression ratio"),
187 "avChecksPerDay" =>_("Checks per day"));
189 foreach($mustBeNumeric as $key => $trans){
190 if(!is_numeric($this->$key)){
191 $message[] = sprintf(_("The specified value for '%s' must be a numeric value."),$trans);
192 }
193 }
195 return($message);
196 }
199 function save_object()
200 {
201 if(isset($_POST['goVirusServer'])){
202 plugin::save_object();
203 foreach($this->Flags as $flag){
204 $var = "avFlags".$flag;
205 if(isset($_POST[$var])){
206 $this->$var = TRUE;
207 }else{
208 $this->$var = FALSE;
209 }
210 }
211 }
212 }
216 /* For newer service management dialogs */
217 function getListEntry()
218 {
219 $this->updateStatusState();
220 $flag = $this->StatusFlag;
221 $fields['Status'] = $this->$flag;
222 $fields['Message'] = _("Anti virus");
223 $fields['AllowStart'] = true;
224 $fields['AllowStop'] = true;
225 $fields['AllowRestart'] = true;
226 $fields['AllowRemove'] = true;
227 $fields['AllowEdit'] = true;
228 return($fields);
229 }
231 function updateStatusState()
232 {
233 if(empty($this->StatusFlag)) return;
235 $attrs = array();
236 $flag = $this->StatusFlag;
237 $ldap = $this->config->get_ldap_link();
238 $ldap->cd($this->cn);
239 $ldap->cat($this->dn,array($flag));
240 if($ldap->count()){
241 $attrs = $ldap->fetch();
242 }
243 if(isset($attrs[$flag][0])){
244 $this->$flag = $attrs[$flag][0];
245 }
246 }
248 function action_hook($add_attrs= array())
249 {
250 /* Find postcreate entries for this class */
251 $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
252 if ($command == "" && isset($this->config->data['TABS'])){
253 $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
254 }
255 if ($command != ""){
256 /* Walk through attribute list */
257 foreach ($this->attributes as $attr){
258 if (!is_array($this->$attr)){
259 $command= preg_replace("/%$attr/", $this->$attr, $command);
260 }
261 }
262 $command= preg_replace("/%dn/", $this->dn, $command);
263 /* Additional attributes */
264 foreach ($add_attrs as $name => $value){
265 $command= preg_replace("/%$name/", $value, $command);
266 }
268 /* If there are still some %.. in our command, try to fill these with some other class vars */
269 if(preg_match("/%/",$command)){
270 $attrs = get_object_vars($this);
271 foreach($attrs as $name => $value){
272 if(!is_string($value)) continue;
273 $command= preg_replace("/%$name/", $value, $command);
274 }
275 }
277 if (check_command($command)){
278 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
279 $command, "Execute");
281 exec($command);
282 } else {
283 $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
284 print_red ($message);
285 }
286 }
287 }
289 /* Directly save new status flag */
290 function setStatus($value)
291 {
292 if($value == "none") return;
293 if(!$this->initially_was_account) return;
294 $ldap = $this->config->get_ldap_link();
295 $ldap->cd($this->dn);
296 $ldap->cat($this->dn,array("objectClass"));
297 if($ldap->count()){
299 $tmp = $ldap->fetch();
300 for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
301 $attrs['objectClass'][] = $tmp['objectClass'][$i];
302 }
303 $flag = $this->StatusFlag;
304 $attrs[$flag] = $value;
305 $this->$flag = $value;
306 $ldap->modify($attrs);
307 show_ldap_error($ldap->get_error(), sprintf(_("Set status flag for server services/anti virus with dn '%s' failed."),$this->dn));
308 $this->action_hook();
309 }
310 }
312 /* Return plugin informations for acl handling
313 function plInfo()
314 {
315 return (array(
316 "plShortName" => _("Anti virus"),
317 "plDescription" => _("Anti virus service"),
318 "plSelfModify" => FALSE,
319 "plDepends" => array(),
320 "plPriority" => 0,
321 "plSection" => array("administration"),
322 "plCategory" => array("server"),
323 "plProvidedAcls"=> array(
326 "avFlagsD" =>_("Enable debugging"),
327 "avFlagsS" =>_("Enable mail scanning"),
328 "avFlagsA" =>_("Enable scanning of archives"),
329 "avFlagsE" =>_("Block encrypted archives"),
331 "avMaxThreads" =>_("Maximum threads"),
332 // "avMaxDirectoryRecursions" =>_(""),
333 // "avUser" =>_(""),
334 "avArchiveMaxFileSize" =>_("Maximum file size"),
335 "avArchiveMaxRecursion" =>_("Maximum recursions"),
336 "avArchiveMaxCompressionRatio" =>_("Maximum compression ratio"),
337 "avDatabaseMirror" =>_("Database mirror"),
338 "avChecksPerDay" =>_("Checks per day"),
339 "avHttpProxyURL" =>_("Http proxy URL"))
340 ));
341 }
342 */
343 }
344 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
345 ?>