Skip to content

Commit 90bee49

Browse files
committed
allow client to use mail blacklist
1 parent ce64883 commit 90bee49

File tree

8 files changed

+53
-44
lines changed

8 files changed

+53
-44
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,8 @@
112112
)
113113
);
114114

115+
if (! $app->auth->is_admin()) {
116+
$form['tabs']['blacklist']['fields']['type']['value'] = array('recipient' => 'Recipient', 'sender' => 'Sender');
117+
}
115118

116119
?>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
);
120120

121121
if (! $app->auth->is_admin()) {
122-
$form["tabs"]['whitelist']['fields']['type']['value'] = array('recipient' => 'Recipient', 'sender' => 'Sender');
122+
$form['tabs']['whitelist']['fields']['type']['value'] = array('recipient' => 'Recipient', 'sender' => 'Sender');
123123
}
124124

125125

interface/web/mail/list/mail_blacklist.list.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,27 @@
7878
'op' => "like",
7979
'prefix' => "%",
8080
'suffix' => "%",
81+
'datasource' => array ( 'type' => 'SQL',
82+
'querystring' => 'SELECT access_id,source FROM mail_access WHERE {AUTHSQL} ORDER BY source',
83+
'keyfield'=> 'access_id',
84+
'valuefield'=> 'source'
85+
),
8186
'width' => "",
8287
'value' => "");
8388

8489

90+
if ($app->auth->is_admin()) {
91+
$type_values[] = array('recipient' => 'Recipient', 'sender' => 'Sender', 'client' => 'Client');
92+
} else {
93+
$type_values[] = array('recipient' => 'Recipient', 'sender' => 'Sender');
94+
}
8595
$liste["item"][] = array( 'field' => "type",
8696
'datatype' => "VARCHAR",
8797
'formtype' => "SELECT",
8898
'op' => "=",
8999
'prefix' => "",
90100
'suffix' => "",
91101
'width' => "",
92-
'value' => array('recipient' => 'Recipient', 'sender' => 'Sender', 'client' => 'Client'));
93-
102+
'value' => $type_values);
94103

95104
?>

interface/web/mail/list/mail_whitelist.list.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -86,24 +86,19 @@
8686
'width' => "",
8787
'value' => "");
8888

89+
8990
if ($app->auth->is_admin()) {
90-
$liste["item"][] = array( 'field' => "type",
91-
'datatype' => "VARCHAR",
92-
'formtype' => "SELECT",
93-
'op' => "=",
94-
'prefix' => "",
95-
'suffix' => "",
96-
'width' => "",
97-
'value' => array('recipient' => 'recipient_txt', 'sender' => 'sender_txt', 'client' => 'client_txt'));
91+
$type_values[] = array('recipient' => 'Recipient', 'sender' => 'Sender', 'client' => 'Client');
9892
} else {
99-
$liste["item"][] = array( 'field' => "type",
100-
'datatype' => "VARCHAR",
101-
'formtype' => "SELECT",
102-
'op' => "=",
103-
'prefix' => "",
104-
'suffix' => "",
105-
'width' => "",
106-
'value' => array('recipient' => 'recipient_txt', 'sender' => 'sender_txt'));
93+
$type_values[] = array('recipient' => 'Recipient', 'sender' => 'Sender');
10794
}
95+
$liste["item"][] = array( 'field' => "type",
96+
'datatype' => "VARCHAR",
97+
'formtype' => "SELECT",
98+
'op' => "=",
99+
'prefix' => "",
100+
'suffix' => "",
101+
'width' => "",
102+
'value' => $type_values);
108103

109104
?>

interface/web/mail/mail_blacklist_del.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@
4242
require_once '../../lib/config.inc.php';
4343
require_once '../../lib/app.inc.php';
4444

45-
46-
if($_SESSION["s"]["user"]["typ"] != 'admin') $app->error('This function needs admin privileges');
47-
4845
//* Check permissions for module
4946
$app->auth->check_module_permissions('mail');
5047

interface/web/mail/mail_blacklist_edit.php

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,36 +50,44 @@
5050

5151
class page_action extends tform_actions {
5252

53-
function onShowNew() {
54-
global $app, $conf;
55-
56-
if($_SESSION["s"]["user"]["typ"] != 'admin') die('This function needs admin privileges');
57-
parent::onShowNew();
58-
}
59-
53+
protected $client_allowed_types = array( 'recipient', 'sender' );
6054

6155
function onBeforeUpdate() {
6256
global $app, $conf;
6357

64-
if($_SESSION["s"]["user"]["typ"] != 'admin') die('This function needs admin privileges');
65-
6658
//* Check if the server has been changed
67-
// We do this only for the admin or reseller users, as normal clients can not change the server ID anyway
68-
if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
69-
$rec = $app->db->queryOneRecord("SELECT server_id from mail_access WHERE access_id = ?", $this->id);
70-
if($rec['server_id'] != $this->dataRecord["server_id"]) {
71-
//* Add a error message and switch back to old server
72-
$app->tform->errorMessage .= $app->lng('The Server can not be changed.');
73-
$this->dataRecord["server_id"] = $rec['server_id'];
74-
}
75-
unset($rec);
59+
$rec = $app->db->queryOneRecord("SELECT server_id from mail_access WHERE access_id = ?", $this->id);
60+
if($rec['server_id'] != $this->dataRecord["server_id"]) {
61+
//* Add a error message and switch back to old server
62+
$app->tform->errorMessage .= $app->lng('The Server can not be changed.');
63+
$this->dataRecord["server_id"] = $rec['server_id'];
7664
}
65+
unset($rec);
7766
}
7867

7968
function onSubmit() {
8069
global $app, $conf;
8170

82-
if($_SESSION["s"]["user"]["typ"] != 'admin') die('This function needs admin privileges');
71+
// Non-admin checks
72+
if($_SESSION["s"]["user"]["typ"] != 'admin') {
73+
// Non-admin can only use type 'sender' or 'recipient' and address must belong to the client's domains
74+
if(! in_array($this->dataRecord["type"], $this->client_allowed_types)) {
75+
$app->tform->errorMessage .= $app->lng('Blacklist type requires admin permissions');
76+
}
77+
// address must be valid email
78+
if(! filter_var( $this->dataRecord["source"], FILTER_VALIDATE_EMAIL )) {
79+
$app->tform->errorMessage .= $app->lng('Invalid address: must be a valid email address');
80+
}
81+
$tmp = explode('@', $this->dataRecord["source"]);
82+
$domain = trim( array_pop($tmp) );
83+
$AUTHSQL = $app->tform->getAuthSQL('r');
84+
$rec = $app->db->queryOneRecord("SELECT domain_id from mail_domain WHERE ${AUTHSQL} AND domain = ?", $domain);
85+
// address must belong to the client's domains
86+
if(! (is_array($rec) && isset($rec['domain_id']) && is_numeric($rec['domain_id']))) {
87+
$app->tform->errorMessage .= $app->lng('Invalid address: you have no permission for this domain.');
88+
}
89+
unset($rec);
90+
}
8391

8492
if(substr($this->dataRecord['source'], 0, 1) === '@') $this->dataRecord['source'] = substr($this->dataRecord['source'], 1);
8593

interface/web/mail/mail_blacklist_list.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
* End Form configuration
1313
******************************************/
1414

15-
if($_SESSION["s"]["user"]["typ"] != 'admin') $app->error('This function needs admin privileges');
16-
1715
//* Check permissions for module
1816
$app->auth->check_module_permissions('mail');
1917

interface/web/mail/mail_whitelist_edit.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ function onBeforeUpdate() {
5656
global $app, $conf;
5757

5858
//* Check if the server has been changed
59-
// We do this only for the admin or reseller users, as normal clients can not change the server ID anyway
6059
$rec = $app->db->queryOneRecord("SELECT server_id from mail_access WHERE access_id = ?", $this->id);
6160
if($rec['server_id'] != $this->dataRecord["server_id"]) {
6261
//* Add a error message and switch back to old server

0 commit comments

Comments
 (0)