Skip to content

Commit 7eb3be8

Browse files
author
Marius Burkard
committed
- re-wrote policy editing to separate rspamd and amavis settings
1 parent befdfb2 commit 7eb3be8

File tree

10 files changed

+372
-350
lines changed

10 files changed

+372
-350
lines changed

install/patches/upd_0088.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
if(!defined('INSTALLER_RUN')) die('Patch update file access violation.');
4+
5+
/*
6+
Example installer patch update class. the classname must match
7+
the php and the sql patch update filename. The php patches are
8+
only executed when a corresponding sql patch exists.
9+
*/
10+
11+
class upd_0088 extends installer_patch_update {
12+
13+
public function onAfterSQL() {
14+
global $inst;
15+
16+
// delete all the files that were deleted on previous updates
17+
$delete = array(
18+
'interface/web/mail/templates/spamfilter_taglevel_edit.htm',
19+
'interface/web/mail/templates/spamfilter_quarantine_edit.htm',
20+
'interface/web/mail/templates/spamfilter_other_edit.htm',
21+
);
22+
23+
$curpath = dirname(dirname(realpath(dirname(__FILE__))));
24+
25+
$c = 0;
26+
$del_all = false;
27+
foreach($delete as $file) {
28+
if(strpos($file, '..') !== false) continue; // security!
29+
30+
if($del_all == false) {
31+
$answer = $inst->simple_query('Delete obsolete file ' . $file . '?', array('y', 'n', 'a', 'all', 'none'), 'y');
32+
if($answer == 'n') continue;
33+
elseif($answer == 'a' || $answer == 'all') $del_all = true;
34+
elseif($answer == 'none') break;
35+
}
36+
if(@is_file('/usr/local/ispconfig/' . $file) && !@is_file($curpath . '/' . $file)) {
37+
// be sure this is not a file contained in installation!
38+
@unlink('/usr/local/ispconfig/' . $file);
39+
ilog('Deleted obsolete file /usr/local/ispconfig/' . $file);
40+
$c++;
41+
}
42+
}
43+
ilog($c . 'obsolete files deleted.');
44+
}
45+
}
46+
47+
?>

interface/web/mail/form/spamfilter_policy.tform.php

Lines changed: 64 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,21 @@
8787
'default' => 'N',
8888
'value' => array('N' => 'No', 'Y' => 'Yes')
8989
),
90+
//#################################
91+
// ENDE Datatable fields
92+
//#################################
93+
)
94+
);
95+
96+
97+
$form["tabs"]['amavis'] = array (
98+
'title' => "Amavis",
99+
'width' => 100,
100+
'template' => "templates/spamfilter_amavis_edit.htm",
101+
'fields' => array (
102+
//#################################
103+
// Begin Datatable fields
104+
//#################################
90105
'banned_files_lover' => array (
91106
'datatype' => 'VARCHAR',
92107
'formtype' => 'SELECT',
@@ -117,21 +132,6 @@
117132
'default' => 'N',
118133
'value' => array('N' => 'No', 'Y' => 'Yes')
119134
),
120-
//#################################
121-
// ENDE Datatable fields
122-
//#################################
123-
)
124-
);
125-
126-
127-
$form["tabs"]['quarantine'] = array (
128-
'title' => "Quarantine",
129-
'width' => 100,
130-
'template' => "templates/spamfilter_quarantine_edit.htm",
131-
'fields' => array (
132-
//#################################
133-
// Begin Datatable fields
134-
//#################################
135135
'virus_quarantine_to' => array (
136136
'datatype' => 'VARCHAR',
137137
'formtype' => 'TEXT',
@@ -216,20 +216,6 @@
216216
'width' => '30',
217217
'maxlength' => '255'
218218
),
219-
//#################################
220-
// ENDE Datatable fields
221-
//#################################
222-
)
223-
);
224-
225-
$form["tabs"]['taglevel'] = array (
226-
'title' => "Tag-Level",
227-
'width' => 100,
228-
'template' => "templates/spamfilter_taglevel_edit.htm",
229-
'fields' => array (
230-
//#################################
231-
// Begin Datatable fields
232-
//#################################
233219
'spam_tag_level' => array (
234220
'datatype' => 'DOUBLE',
235221
'formtype' => 'TEXT',
@@ -304,57 +290,6 @@
304290
'width' => '30',
305291
'maxlength' => '255'
306292
),
307-
'rspamd_greylisting' => array (
308-
'datatype' => 'VARCHAR',
309-
'formtype' => 'CHECKBOX',
310-
'default' => 'y',
311-
'value' => array(0 => 'n', 1 => 'y')
312-
),
313-
'rspamd_spam_greylisting_level' => array (
314-
'datatype' => 'DOUBLE',
315-
'formtype' => 'TEXT',
316-
'default' => '0',
317-
'value' => '',
318-
'width' => '10',
319-
'maxlength' => '255'
320-
),
321-
'rspamd_spam_tag_level' => array (
322-
'datatype' => 'DOUBLE',
323-
'formtype' => 'TEXT',
324-
'default' => '0',
325-
'value' => '',
326-
'width' => '10',
327-
'maxlength' => '255'
328-
),
329-
'rspamd_spam_tag_method' => array (
330-
'datatype' => 'VARCHAR',
331-
'formtype' => 'SELECT',
332-
'default' => 'rewrite_subject',
333-
'value' => array('add_header' => $app->lng('add_header_txt'), 'rewrite_subject' => $app->lng('rewrite_subject_txt'))
334-
),
335-
'rspamd_spam_kill_level' => array (
336-
'datatype' => 'DOUBLE',
337-
'formtype' => 'TEXT',
338-
'default' => '0',
339-
'value' => '',
340-
'width' => '10',
341-
'maxlength' => '255'
342-
),
343-
//#################################
344-
// ENDE Datatable fields
345-
//#################################
346-
)
347-
);
348-
349-
350-
$form["tabs"]['other'] = array (
351-
'title' => "Other",
352-
'width' => 100,
353-
'template' => "templates/spamfilter_other_edit.htm",
354-
'fields' => array (
355-
//#################################
356-
// Begin Datatable fields
357-
//#################################
358293
'addr_extension_virus' => array (
359294
'datatype' => 'VARCHAR',
360295
'formtype' => 'TEXT',
@@ -522,11 +457,58 @@
522457
'width' => '30',
523458
'maxlength' => '255'
524459
),
525-
526460
//#################################
527461
// ENDE Datatable fields
528462
//#################################
529463
)
530464
);
531465

532-
?>
466+
$form["tabs"]['rspamd'] = array (
467+
'title' => "Rspamd",
468+
'width' => 100,
469+
'template' => "templates/spamfilter_rspamd_edit.htm",
470+
'fields' => array (
471+
//#################################
472+
// Begin Datatable fields
473+
//#################################
474+
'rspamd_greylisting' => array (
475+
'datatype' => 'VARCHAR',
476+
'formtype' => 'CHECKBOX',
477+
'default' => 'y',
478+
'value' => array(0 => 'n', 1 => 'y')
479+
),
480+
'rspamd_spam_greylisting_level' => array (
481+
'datatype' => 'DOUBLE',
482+
'formtype' => 'TEXT',
483+
'default' => '0',
484+
'value' => '',
485+
'width' => '10',
486+
'maxlength' => '255'
487+
),
488+
'rspamd_spam_tag_level' => array (
489+
'datatype' => 'DOUBLE',
490+
'formtype' => 'TEXT',
491+
'default' => '0',
492+
'value' => '',
493+
'width' => '10',
494+
'maxlength' => '255'
495+
),
496+
'rspamd_spam_tag_method' => array (
497+
'datatype' => 'VARCHAR',
498+
'formtype' => 'SELECT',
499+
'default' => 'rewrite_subject',
500+
'value' => array('add_header' => $app->lng('add_header_txt'), 'rewrite_subject' => $app->lng('rewrite_subject_txt'))
501+
),
502+
'rspamd_spam_kill_level' => array (
503+
'datatype' => 'DOUBLE',
504+
'formtype' => 'TEXT',
505+
'default' => '0',
506+
'value' => '',
507+
'width' => '10',
508+
'maxlength' => '255'
509+
),
510+
//#################################
511+
// ENDE Datatable fields
512+
//#################################
513+
)
514+
);

interface/web/mail/lib/lang/en_spamfilter_policy.lng

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,10 @@ $wb['rspamd_spam_tag_method_txt'] = 'SPAM tag method';
4242
$wb['rspamd_spam_kill_level_txt'] = 'SPAM reject level';
4343
$wb['btn_save_txt'] = 'Save';
4444
$wb['btn_cancel_txt'] = 'Cancel';
45-
?>
45+
46+
$wb['amavis_settings_txt'] = 'Settings';
47+
$wb['amavis_taglevel_txt'] = 'Tag-Level';
48+
$wb['amavis_quarantine_txt'] = 'Quarantine';
49+
$wb['amavis_other_txt'] = 'Other';
50+
$wb['add_header_txt'] = 'Add header';
51+
$wb['rewrite_subject_txt'] = 'Rewrite subject';

interface/web/mail/spamfilter_policy_edit.php

Lines changed: 18 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -49,48 +49,9 @@
4949
$app->load('tform_actions');
5050

5151
class page_action extends tform_actions {
52-
53-
function onShow() {
54-
global $app, $conf;
55-
56-
// get the config
57-
$app->uses('getconf');
58-
$mail_config = $app->getconf->get_server_config($conf['server_id'], 'mail');
59-
60-
$content_filter = 'amavisd';
61-
if($mail_config['content_filter'] == 'rspamd'){
62-
$content_filter = 'rspamd';
63-
unset($app->tform->formDef["tabs"]["policy"]['fields']['banned_files_lover']);
64-
unset($app->tform->formDef["tabs"]["policy"]['fields']['bad_header_lover']);
65-
unset($app->tform->formDef["tabs"]["policy"]['fields']['bypass_virus_checks']);
66-
unset($app->tform->formDef["tabs"]["policy"]['fields']['bypass_banned_checks']);
67-
unset($app->tform->formDef["tabs"]["policy"]['fields']['bypass_header_checks']);
68-
69-
unset($app->tform->formDef["tabs"]["taglevel"]['fields']['spam_tag_level']);
70-
unset($app->tform->formDef["tabs"]["taglevel"]['fields']['spam_tag2_level']);
71-
unset($app->tform->formDef["tabs"]["taglevel"]['fields']['spam_kill_level']);
72-
unset($app->tform->formDef["tabs"]["taglevel"]['fields']['spam_dsn_cutoff_level']);
73-
unset($app->tform->formDef["tabs"]["taglevel"]['fields']['spam_quarantine_cutoff_level']);
74-
unset($app->tform->formDef["tabs"]["taglevel"]['fields']['spam_modifies_subj']);
75-
unset($app->tform->formDef["tabs"]["taglevel"]['fields']['spam_subject_tag']);
76-
unset($app->tform->formDef["tabs"]["taglevel"]['fields']['spam_subject_tag2']);
77-
78-
unset($app->tform->formDef["tabs"]["quarantine"]);
79-
unset($app->tform->formDef["tabs"]["other"]);
80-
} else {
81-
unset($app->tform->formDef["tabs"]["taglevel"]['fields']['rspamd_greylisting']);
82-
unset($app->tform->formDef["tabs"]["taglevel"]['fields']['rspamd_spam_greylisting_level']);
83-
unset($app->tform->formDef["tabs"]["taglevel"]['fields']['rspamd_spam_tag_level']);
84-
unset($app->tform->formDef["tabs"]["taglevel"]['fields']['rspamd_spam_tag_method']);
85-
unset($app->tform->formDef["tabs"]["taglevel"]['fields']['rspamd_spam_kill_level']);
86-
}
87-
$app->tpl->setVar("content_filter", $content_filter);
88-
89-
parent::onShow();
90-
}
9152

9253
function onShowNew() {
93-
global $app, $conf;
54+
global $app;
9455

9556
// we will check only users, not admins
9657
if($_SESSION["s"]["user"]["typ"] == 'user') {
@@ -106,7 +67,7 @@ function onShowNew() {
10667
}
10768

10869
function onSubmit() {
109-
global $app, $conf;
70+
global $app;
11071

11172
// Check the client limits, if user is not the admin
11273
if($_SESSION["s"]["user"]["typ"] != 'admin') { // if user is not admin
@@ -128,35 +89,30 @@ function onSubmit() {
12889
}
12990

13091
function onAfterUpdate() {
131-
global $app, $conf;
132-
133-
$app->uses('getconf');
134-
$mail_config = $app->getconf->get_server_config($conf['server_id'], 'mail');
92+
global $app;
13593

136-
if($mail_config['content_filter'] == 'rspamd'){
137-
$record_has_changed = false;
138-
if(isset($this->dataRecord['rspamd_spam_greylisting_level']) && !isset($this->dataRecord['rspamd_greylisting'])) $this->dataRecord['rspamd_greylisting'] = 'n';
139-
foreach($this->dataRecord as $key => $val) {
140-
if(isset($this->oldDataRecord[$key]) && @$this->oldDataRecord[$key] != $val) {
141-
// Record has changed
142-
$record_has_changed = true;
143-
}
94+
$record_has_changed = false;
95+
if(isset($this->dataRecord['rspamd_spam_greylisting_level']) && !isset($this->dataRecord['rspamd_greylisting'])) {
96+
$this->dataRecord['rspamd_greylisting'] = 'n';
97+
}
98+
foreach($this->dataRecord as $key => $val) {
99+
if(isset($this->oldDataRecord[$key]) && @$this->oldDataRecord[$key] != $val) {
100+
// Record has changed
101+
$record_has_changed = true;
144102
}
145-
146-
if($record_has_changed){
147-
$spamfilter_users = $app->db->queryAllRecords("SELECT * FROM spamfilter_users WHERE policy_id = ?", intval($this->id));
103+
}
104+
105+
if($record_has_changed){
106+
$spamfilter_users = $app->db->queryAllRecords("SELECT * FROM spamfilter_users WHERE policy_id = ?", intval($this->id));
148107

149-
if(is_array($spamfilter_users) && !empty($spamfilter_users)){
150-
foreach($spamfilter_users as $spamfilter_user){
151-
$app->db->datalogUpdate('spamfilter_users', $spamfilter_user, 'id', $spamfilter_user["id"], true);
152-
}
108+
if(is_array($spamfilter_users) && !empty($spamfilter_users)){
109+
foreach($spamfilter_users as $spamfilter_user){
110+
$app->db->datalogUpdate('spamfilter_users', $spamfilter_user, 'id', $spamfilter_user["id"], true);
153111
}
154112
}
155113
}
156114
}
157-
158115
}
159116

160117
$app->tform_actions = new page_action;
161118
$app->tform_actions->onLoad();
162-
?>

0 commit comments

Comments
 (0)