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