@@ -281,11 +281,13 @@ function onSubmit() {
281281
282282 function onAfterInsert () {
283283 global $ app , $ conf ;
284+
285+ $ domain = $ app ->functions ->idn_encode ($ this ->dataRecord ["domain " ]);
284286
285287 // Spamfilter policy
286288 $ policy_id = $ app ->functions ->intval ($ this ->dataRecord ["policy " ]);
287289 if ($ policy_id > 0 ) {
288- $ tmp_user = $ app ->db ->queryOneRecord ("SELECT id FROM spamfilter_users WHERE email = ? " , '@ ' . $ this -> dataRecord [ " domain " ] );
290+ $ tmp_user = $ app ->db ->queryOneRecord ("SELECT id FROM spamfilter_users WHERE email = ? " , '@ ' . $ domain );
289291 if ($ tmp_user ["id " ] > 0 ) {
290292 // There is already a record that we will update
291293 $ app ->db ->datalogUpdate ('spamfilter_users ' , array ("policy_id " => $ policy_id ), 'id ' , $ tmp_user ["id " ]);
@@ -301,8 +303,8 @@ function onAfterInsert() {
301303 "server_id " => $ this ->dataRecord ["server_id " ],
302304 "priority " => 5 ,
303305 "policy_id " => $ policy_id ,
304- "email " => '@ ' . $ this -> dataRecord [ " domain " ] ,
305- "fullname " => '@ ' . $ this -> dataRecord [ " domain " ] ,
306+ "email " => '@ ' . $ domain ,
307+ "fullname " => '@ ' . $ domain ,
306308 "local " => 'Y '
307309 );
308310 $ app ->db ->datalogInsert ('spamfilter_users ' , $ insert_data , 'id ' );
@@ -324,6 +326,8 @@ function onAfterInsert() {
324326
325327 function onBeforeUpdate () {
326328 global $ app , $ conf ;
329+
330+ $ domain = $ app ->functions ->idn_encode ($ this ->dataRecord ["domain " ]);
327331
328332 //* Check if the server has been changed
329333 // We do this only for the admin or reseller users, as normal clients can not change the server ID anyway
@@ -339,7 +343,7 @@ function onBeforeUpdate() {
339343 } else {
340344 //* We do not allow users to change a domain which has been created by the admin
341345 $ rec = $ app ->db ->queryOneRecord ("SELECT domain from mail_domain WHERE domain_id = ? " , $ this ->id );
342- if ($ rec ['domain ' ] != $ this -> dataRecord [ " domain " ] && !$ app ->tform ->checkPerm ($ this ->id , 'u ' )) {
346+ if ($ rec ['domain ' ] != $ domain && !$ app ->tform ->checkPerm ($ this ->id , 'u ' )) {
343347 //* Add a error message and switch back to old server
344348 $ app ->tform ->errorMessage .= $ app ->lng ('The Domain can not be changed. Please ask your Administrator if you want to change the domain name. ' );
345349 $ this ->dataRecord ["domain " ] = $ rec ['domain ' ];
@@ -352,9 +356,11 @@ function onBeforeUpdate() {
352356 function onAfterUpdate () {
353357 global $ app , $ conf ;
354358
359+ $ domain = $ app ->functions ->idn_encode ($ this ->dataRecord ["domain " ]);
360+
355361 // Spamfilter policy
356362 $ policy_id = $ app ->functions ->intval ($ this ->dataRecord ["policy " ]);
357- $ tmp_user = $ app ->db ->queryOneRecord ("SELECT id FROM spamfilter_users WHERE email = ? " , '@ ' . $ this -> dataRecord [ " domain " ] );
363+ $ tmp_user = $ app ->db ->queryOneRecord ("SELECT id FROM spamfilter_users WHERE email = ? " , '@ ' . $ domain );
358364 if ($ policy_id > 0 ) {
359365 if ($ tmp_user ["id " ] > 0 ) {
360366 // There is already a record that we will update
@@ -371,8 +377,8 @@ function onAfterUpdate() {
371377 "server_id " => $ this ->dataRecord ["server_id " ],
372378 "priority " => 5 ,
373379 "policy_id " => $ policy_id ,
374- "email " => '@ ' . $ this -> dataRecord [ " domain " ] ,
375- "fullname " => '@ ' . $ this -> dataRecord [ " domain " ] ,
380+ "email " => '@ ' . $ domain ,
381+ "fullname " => '@ ' . $ domain ,
376382 "local " => 'Y '
377383 );
378384 $ app ->db ->datalogInsert ('spamfilter_users ' , $ insert_data , 'id ' );
@@ -385,7 +391,7 @@ function onAfterUpdate() {
385391 }
386392 } // endif spamfilter policy
387393 //** If the domain name or owner has been changed, change the domain and owner in all mailbox records
388- if ($ this ->oldDataRecord ['domain ' ] != $ this -> dataRecord [ ' domain ' ] || (isset ($ this ->dataRecord ['client_group_id ' ]) && $ this ->oldDataRecord ['sys_groupid ' ] != $ this ->dataRecord ['client_group_id ' ])) {
394+ if ($ this ->oldDataRecord ['domain ' ] != $ domain || (isset ($ this ->dataRecord ['client_group_id ' ]) && $ this ->oldDataRecord ['sys_groupid ' ] != $ this ->dataRecord ['client_group_id ' ])) {
389395 $ app ->uses ('getconf ' );
390396 $ mail_config = $ app ->getconf ->get_server_config ($ this ->dataRecord ["server_id " ], 'mail ' );
391397
@@ -398,7 +404,7 @@ function onAfterUpdate() {
398404 foreach ($ mailusers as $ rec ) {
399405 // setting Maildir, Homedir, UID and GID
400406 $ mail_parts = explode ("@ " , $ rec ['email ' ]);
401- $ maildir = str_replace ("[domain] " , $ this -> dataRecord [ ' domain ' ] , $ mail_config ["maildir_path " ]);
407+ $ maildir = str_replace ("[domain] " , $ domain , $ mail_config ["maildir_path " ]);
402408 $ maildir = str_replace ("[localpart] " , $ mail_parts [0 ], $ maildir );
403409 $ email = $ mail_parts [0 ].'@ ' .$ this ->dataRecord ['domain ' ];
404410 $ app ->db ->datalogUpdate ('mail_user ' , array ("maildir " => $ maildir , "email " => $ email , "sys_userid " => $ client_user_id , "sys_groupid " => $ sys_groupid ), 'mailuser_id ' , $ rec ['mailuser_id ' ]);
@@ -409,8 +415,8 @@ function onAfterUpdate() {
409415 $ forwardings = $ app ->db ->queryAllRecords ("SELECT * FROM mail_forwarding WHERE source like ? OR destination like ? " , '%@ ' . $ this ->oldDataRecord ['domain ' ], '%@ ' . $ this ->oldDataRecord ['domain ' ]);
410416 if (is_array ($ forwardings )) {
411417 foreach ($ forwardings as $ rec ) {
412- $ destination = str_replace ($ this ->oldDataRecord ['domain ' ], $ this -> dataRecord [ ' domain ' ] , $ rec ['destination ' ]);
413- $ source = str_replace ($ this ->oldDataRecord ['domain ' ], $ this -> dataRecord [ ' domain ' ] , $ rec ['source ' ]);
418+ $ destination = str_replace ($ this ->oldDataRecord ['domain ' ], $ domain , $ rec ['destination ' ]);
419+ $ source = str_replace ($ this ->oldDataRecord ['domain ' ], $ domain , $ rec ['source ' ]);
414420 $ app ->db ->datalogUpdate ('mail_forwarding ' , array ("source " => $ source , "destination " => $ destination , "sys_userid " => $ client_user_id , "sys_groupid " => $ sys_groupid ), 'forwarding_id ' , $ rec ['forwarding_id ' ]);
415421 }
416422 }
@@ -422,7 +428,7 @@ function onAfterUpdate() {
422428 $ fetchmail = $ app ->db ->queryAllRecords ("SELECT * FROM mail_get WHERE destination like ? " , '%@ ' . $ this ->oldDataRecord ['domain ' ]);
423429 if (is_array ($ fetchmail )) {
424430 foreach ($ fetchmail as $ rec ) {
425- $ destination = str_replace ($ this ->oldDataRecord ['domain ' ], $ this -> dataRecord [ ' domain ' ] , $ rec ['destination ' ]);
431+ $ destination = str_replace ($ this ->oldDataRecord ['domain ' ], $ domain , $ rec ['destination ' ]);
426432 $ app ->db ->datalogUpdate ('mail_get ' , array ("destination " => $ destination , "sys_userid " => $ client_user_id , "sys_groupid " => $ sys_groupid ), 'mailget_id ' , $ rec ['mailget_id ' ]);
427433 }
428434 }
@@ -436,15 +442,15 @@ function onAfterUpdate() {
436442
437443 //* update dns-record when the dkim record was changed
438444 // NOTE: only if the domain-name was not changed
439- if ( $ this ->dataRecord ['active ' ] == 'y ' && $ this -> dataRecord [ ' domain ' ] == $ this ->oldDataRecord ['domain ' ] ) {
445+ if ( $ this ->dataRecord ['active ' ] == 'y ' && $ domain == $ this ->oldDataRecord ['domain ' ] ) {
440446 $ dkim_active = @($ this ->dataRecord ['dkim ' ] == 'y ' ) ? true : false ;
441447 $ selector = @($ this ->dataRecord ['dkim_selector ' ] != $ this ->oldDataRecord ['dkim_selector ' ]) ? true : false ;
442448 $ dkim_private = @($ this ->dataRecord ['dkim_private ' ] != $ this ->oldDataRecord ['dkim_private ' ]) ? true : false ;
443449
444- $ soaDomain = $ this -> dataRecord [ ' domain ' ] .'. ' ;
450+ $ soaDomain = $ domain .'. ' ;
445451 while ((!isset ($ soa ) && (substr_count ($ soaDomain ,'. ' ) > 1 ))) {
446452 $ soa = $ app ->db ->queryOneRecord ("SELECT id AS zone, sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other, server_id, ttl, serial FROM dns_soa WHERE active = 'Y' AND origin = ? " , $ soaDomain );
447- $ soaDomain = preg_replace ("/^\w +\./ " ,"" ,$ soaDomain );
453+ $ soaDomain = preg_replace ("/^[\w\-] +\./ " ,"" ,$ soaDomain );
448454 }
449455
450456 if ( ($ selector || $ dkim_private || $ dkim_active ) && $ dkim_active )
@@ -455,7 +461,7 @@ function onAfterUpdate() {
455461 if (! $ dkim_active ) {
456462 // updated existing dmarc-record to policy 'none'
457463 $ sql = "SELECT * from dns_rr WHERE name = ? AND data LIKE 'v=DMARC1%' AND " . $ app ->tform ->getAuthSQL ('r ' );
458- $ rec = $ app ->db ->queryOneRecord ($ sql , '_dmarc. ' .$ this -> dataRecord [ ' domain ' ] .'. ' );
464+ $ rec = $ app ->db ->queryOneRecord ($ sql , '_dmarc. ' .$ domain .'. ' );
459465 if (is_array ($ rec ))
460466 if (strpos ($ rec ['data ' ], 'p=none= ' ) === false ) {
461467 $ rec ['data ' ] = str_replace (array ('quarantine ' , 'reject ' ), 'none ' , $ rec ['data ' ]);
0 commit comments