Skip to content
Snippets Groups Projects
Commit 90bee497 authored by Jesse Norell's avatar Jesse Norell
Browse files

allow client to use mail blacklist

parent ce648830
No related branches found
No related tags found
No related merge requests found
......@@ -112,5 +112,8 @@ $form["tabs"]['blacklist'] = array (
)
);
if (! $app->auth->is_admin()) {
$form['tabs']['blacklist']['fields']['type']['value'] = array('recipient' => 'Recipient', 'sender' => 'Sender');
}
?>
......@@ -119,7 +119,7 @@ $form["tabs"]['whitelist'] = array (
);
if (! $app->auth->is_admin()) {
$form["tabs"]['whitelist']['fields']['type']['value'] = array('recipient' => 'Recipient', 'sender' => 'Sender');
$form['tabs']['whitelist']['fields']['type']['value'] = array('recipient' => 'Recipient', 'sender' => 'Sender');
}
......
......@@ -78,10 +78,20 @@ $liste["item"][] = array( 'field' => "source",
'op' => "like",
'prefix' => "%",
'suffix' => "%",
'datasource' => array ( 'type' => 'SQL',
'querystring' => 'SELECT access_id,source FROM mail_access WHERE {AUTHSQL} ORDER BY source',
'keyfield'=> 'access_id',
'valuefield'=> 'source'
),
'width' => "",
'value' => "");
if ($app->auth->is_admin()) {
$type_values[] = array('recipient' => 'Recipient', 'sender' => 'Sender', 'client' => 'Client');
} else {
$type_values[] = array('recipient' => 'Recipient', 'sender' => 'Sender');
}
$liste["item"][] = array( 'field' => "type",
'datatype' => "VARCHAR",
'formtype' => "SELECT",
......@@ -89,7 +99,6 @@ $liste["item"][] = array( 'field' => "type",
'prefix' => "",
'suffix' => "",
'width' => "",
'value' => array('recipient' => 'Recipient', 'sender' => 'Sender', 'client' => 'Client'));
'value' => $type_values);
?>
......@@ -86,24 +86,19 @@ $liste["item"][] = array( 'field' => "source",
'width' => "",
'value' => "");
if ($app->auth->is_admin()) {
$liste["item"][] = array( 'field' => "type",
'datatype' => "VARCHAR",
'formtype' => "SELECT",
'op' => "=",
'prefix' => "",
'suffix' => "",
'width' => "",
'value' => array('recipient' => 'recipient_txt', 'sender' => 'sender_txt', 'client' => 'client_txt'));
$type_values[] = array('recipient' => 'Recipient', 'sender' => 'Sender', 'client' => 'Client');
} else {
$liste["item"][] = array( 'field' => "type",
'datatype' => "VARCHAR",
'formtype' => "SELECT",
'op' => "=",
'prefix' => "",
'suffix' => "",
'width' => "",
'value' => array('recipient' => 'recipient_txt', 'sender' => 'sender_txt'));
$type_values[] = array('recipient' => 'Recipient', 'sender' => 'Sender');
}
$liste["item"][] = array( 'field' => "type",
'datatype' => "VARCHAR",
'formtype' => "SELECT",
'op' => "=",
'prefix' => "",
'suffix' => "",
'width' => "",
'value' => $type_values);
?>
......@@ -42,9 +42,6 @@ $tform_def_file = "form/mail_blacklist.tform.php";
require_once '../../lib/config.inc.php';
require_once '../../lib/app.inc.php';
if($_SESSION["s"]["user"]["typ"] != 'admin') $app->error('This function needs admin privileges');
//* Check permissions for module
$app->auth->check_module_permissions('mail');
......
......@@ -50,36 +50,44 @@ $app->load('tform_actions');
class page_action extends tform_actions {
function onShowNew() {
global $app, $conf;
if($_SESSION["s"]["user"]["typ"] != 'admin') die('This function needs admin privileges');
parent::onShowNew();
}
protected $client_allowed_types = array( 'recipient', 'sender' );
function onBeforeUpdate() {
global $app, $conf;
if($_SESSION["s"]["user"]["typ"] != 'admin') die('This function needs admin privileges');
//* Check if the server has been changed
// We do this only for the admin or reseller users, as normal clients can not change the server ID anyway
if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
$rec = $app->db->queryOneRecord("SELECT server_id from mail_access WHERE access_id = ?", $this->id);
if($rec['server_id'] != $this->dataRecord["server_id"]) {
//* Add a error message and switch back to old server
$app->tform->errorMessage .= $app->lng('The Server can not be changed.');
$this->dataRecord["server_id"] = $rec['server_id'];
}
unset($rec);
$rec = $app->db->queryOneRecord("SELECT server_id from mail_access WHERE access_id = ?", $this->id);
if($rec['server_id'] != $this->dataRecord["server_id"]) {
//* Add a error message and switch back to old server
$app->tform->errorMessage .= $app->lng('The Server can not be changed.');
$this->dataRecord["server_id"] = $rec['server_id'];
}
unset($rec);
}
function onSubmit() {
global $app, $conf;
if($_SESSION["s"]["user"]["typ"] != 'admin') die('This function needs admin privileges');
// Non-admin checks
if($_SESSION["s"]["user"]["typ"] != 'admin') {
// Non-admin can only use type 'sender' or 'recipient' and address must belong to the client's domains
if(! in_array($this->dataRecord["type"], $this->client_allowed_types)) {
$app->tform->errorMessage .= $app->lng('Blacklist type requires admin permissions');
}
// address must be valid email
if(! filter_var( $this->dataRecord["source"], FILTER_VALIDATE_EMAIL )) {
$app->tform->errorMessage .= $app->lng('Invalid address: must be a valid email address');
}
$tmp = explode('@', $this->dataRecord["source"]);
$domain = trim( array_pop($tmp) );
$AUTHSQL = $app->tform->getAuthSQL('r');
$rec = $app->db->queryOneRecord("SELECT domain_id from mail_domain WHERE ${AUTHSQL} AND domain = ?", $domain);
// address must belong to the client's domains
if(! (is_array($rec) && isset($rec['domain_id']) && is_numeric($rec['domain_id']))) {
$app->tform->errorMessage .= $app->lng('Invalid address: you have no permission for this domain.');
}
unset($rec);
}
if(substr($this->dataRecord['source'], 0, 1) === '@') $this->dataRecord['source'] = substr($this->dataRecord['source'], 1);
......
......@@ -12,8 +12,6 @@ $list_def_file = "list/mail_blacklist.list.php";
* End Form configuration
******************************************/
if($_SESSION["s"]["user"]["typ"] != 'admin') $app->error('This function needs admin privileges');
//* Check permissions for module
$app->auth->check_module_permissions('mail');
......
......@@ -56,7 +56,6 @@ class page_action extends tform_actions {
global $app, $conf;
//* Check if the server has been changed
// We do this only for the admin or reseller users, as normal clients can not change the server ID anyway
$rec = $app->db->queryOneRecord("SELECT server_id from mail_access WHERE access_id = ?", $this->id);
if($rec['server_id'] != $this->dataRecord["server_id"]) {
//* Add a error message and switch back to old server
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment