Skip to content

Commit ce64883

Browse files
committed
allow client to use mail whitelist
1 parent 46e09fd commit ce64883

File tree

6 files changed

+70
-28
lines changed

6 files changed

+70
-28
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,9 @@
118118
)
119119
);
120120

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

122126
?>

interface/web/mail/lib/module.conf.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@
6161
'html_id' => 'mail_domain_catchall_list');
6262
}
6363

64+
if(! $app->auth->is_admin())
65+
{
66+
$items[] = array( 'title' => 'Email Whitelist',
67+
'target' => 'content',
68+
'link' => 'mail/mail_whitelist_list.php',
69+
'html_id' => 'mail_whitelist_list');
70+
71+
72+
$items[] = array( 'title' => 'Email Blacklist',
73+
'target' => 'content',
74+
'link' => 'mail/mail_blacklist_list.php',
75+
'html_id' => 'mail_blacklist_list');
76+
}
77+
6478
if($app->auth->get_client_limit($userid, 'mailrouting') != 0)
6579
{
6680
$items[] = array( 'title' => 'Email Routing',
@@ -110,8 +124,8 @@
110124
'html_id' => 'spamfilter_blacklist_list');
111125
}
112126

113-
if($app->auth->is_admin()) {
114-
127+
if($app->auth->is_admin())
128+
{
115129
$items[] = array( 'title' => 'User / Domain',
116130
'target' => 'content',
117131
'link' => 'mail/spamfilter_users_list.php',
@@ -191,7 +205,9 @@
191205
'target' => 'content',
192206
'link' => 'mail/mail_user_stats.php',
193207
'html_id' => 'mail_user_stats');
194-
if($app->auth->get_client_limit($userid, 'backup') == 'y') {
208+
209+
if($app->auth->get_client_limit($userid, 'backup') == 'y')
210+
{
195211
$items[] = array (
196212
'title' => 'Backup Stats',
197213
'target' => 'content',
@@ -206,8 +222,8 @@
206222

207223
//**** Global filters menu
208224
$items = array();
209-
if($_SESSION['s']['user']['typ'] == 'admin') {
210-
225+
if($app->auth->is_admin())
226+
{
211227
$items[] = array( 'title' => 'Postfix Whitelist',
212228
'target' => 'content',
213229
'link' => 'mail/mail_whitelist_list.php',

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,32 @@
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

84-
$liste["item"][] = array( 'field' => "type",
85-
'datatype' => "VARCHAR",
86-
'formtype' => "SELECT",
87-
'op' => "=",
88-
'prefix' => "",
89-
'suffix' => "",
90-
'width' => "",
91-
'value' => array('recipient' => 'recipient_txt', 'sender' => 'sender_txt', 'client' => 'client_txt'));
92-
89+
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'));
98+
} 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'));
107+
}
93108

94109
?>

interface/web/mail/mail_whitelist_del.php

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

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

interface/web/mail/mail_whitelist_edit.php

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,11 @@
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-
58-
parent::onShowNew();
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
6759
// We do this only for the admin or reseller users, as normal clients can not change the server ID anyway
6860
$rec = $app->db->queryOneRecord("SELECT server_id from mail_access WHERE access_id = ?", $this->id);
@@ -77,7 +69,26 @@ function onBeforeUpdate() {
7769
function onSubmit() {
7870
global $app, $conf;
7971

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

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

interface/web/mail/mail_whitelist_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

0 commit comments

Comments
 (0)