|
50 | 50 |
|
51 | 51 | class page_action extends tform_actions { |
52 | 52 |
|
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' ); |
60 | 54 |
|
61 | 55 | function onBeforeUpdate() { |
62 | 56 | global $app, $conf; |
63 | 57 |
|
64 | | - if($_SESSION["s"]["user"]["typ"] != 'admin') die('This function needs admin privileges'); |
65 | | - |
66 | 58 | //* 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']; |
76 | 64 | } |
| 65 | + unset($rec); |
77 | 66 | } |
78 | 67 |
|
79 | 68 | function onSubmit() { |
80 | 69 | global $app, $conf; |
81 | 70 |
|
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 | + } |
83 | 91 |
|
84 | 92 | if(substr($this->dataRecord['source'], 0, 1) === '@') $this->dataRecord['source'] = substr($this->dataRecord['source'], 1); |
85 | 93 |
|
|
0 commit comments