5050
5151class 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
0 commit comments