SF.net SVN: postfixadmin:[1451] trunk
Brought to you by:
christian_boltz,
gingerdog
From: <chr...@us...> - 2013-04-01 21:22:33
|
Revision: 1451 http://sourceforge.net/p/postfixadmin/code/1451 Author: christian_boltz Date: 2013-04-01 21:22:30 +0000 (Mon, 01 Apr 2013) Log Message: ----------- functions.inc.php: - check_domain(), check_email(): instead of calling flash_error(), return string with error message - or empty string if everything is ok model/AdminHandler.php, model/AliasHandler.php, model/DomainHandler.php, model/MailboxHandler.php, sendmail.php, users/edit-alias.php: - adopt to changed check_domain() and check_email() return value Modified Paths: -------------- trunk/functions.inc.php trunk/model/AdminHandler.php trunk/model/AliasHandler.php trunk/model/DomainHandler.php trunk/model/MailboxHandler.php trunk/sendmail.php trunk/users/edit-alias.php Modified: trunk/functions.inc.php =================================================================== --- trunk/functions.inc.php 2013-04-01 20:25:33 UTC (rev 1450) +++ trunk/functions.inc.php 2013-04-01 21:22:30 UTC (rev 1451) @@ -219,19 +219,20 @@ -// -// check_domain -// Action: Checks if domain is valid and returns TRUE if this is the case. -// Call: check_domain (string domain) -// -// TODO: make check_domain able to handle as example .local domains +/** + * Checks if a domain is valid + * @param string $domain + * @return empty string if the domain is valid, otherwise string with the errormessage + * + * TODO: make check_domain able to handle as example .local domains + * TODO: skip DNS check if the domain exists in PostfixAdmin? + */ function check_domain ($domain) { global $CONF; global $PALANG; if (!preg_match ('/^([-0-9A-Z]+\.)+' . '([0-9A-Z]){2,6}$/i', ($domain))) { - flash_error(sprintf($PALANG['pInvalidDomainRegex'], htmlentities($domain))); - return false; + return sprintf($PALANG['pInvalidDomainRegex'], htmlentities($domain)); } if (isset($CONF['emailcheck_resolve_domain']) && 'YES' == $CONF['emailcheck_resolve_domain'] && 'WINDOWS'!=(strtoupper(substr(php_uname('s'), 0, 7)))) { @@ -241,18 +242,17 @@ if(function_exists('checkdnsrr')) { // AAAA (IPv6) is only available in PHP v. >= 5 if (version_compare(phpversion(), "5.0.0", ">=")) { - if (checkdnsrr($domain,'AAAA')) return true; + if (checkdnsrr($domain,'AAAA')) return ''; } - if (checkdnsrr($domain,'A')) return true; - if (checkdnsrr($domain,'MX')) return true; - flash_error(sprintf($PALANG['pInvalidDomainDNS'], htmlentities($domain))); - return false; + if (checkdnsrr($domain,'A')) return ''; + if (checkdnsrr($domain,'MX')) return ''; + return sprintf($PALANG['pInvalidDomainDNS'], htmlentities($domain)); } else { - flash_error("emailcheck_resolve_domain is enabled, but function (checkdnsrr) missing!"); + return 'emailcheck_resolve_domain is enabled, but function (checkdnsrr) missing!'; } } - return true; + return ''; } @@ -260,9 +260,8 @@ * check_email * Checks if an email is valid - if it is, return true, else false. * @param String $email - a string that may be an email address. - * @return boolean true if it's an email address, else false. + * @return empty string if it's a valid email address, otherwise string with the errormessage * TODO: make check_email able to handle already added domains - * TODO: don't use flash_error, use return value instead */ function check_email ($email) { global $CONF; @@ -280,15 +279,13 @@ // Perform non-domain-part sanity checks if (!preg_match ('/^[-!#$%&\'*+\\.\/0-9=?A-Z^_{|}~]+' . '@' . '[^@]+$/i', $ce_email)) { - flash_error($PALANG['pInvalidMailRegex']); - return false; + return $PALANG['pInvalidMailRegex']; } // Determine domain name $matches=array(); if (!preg_match('|@(.+)$|',$ce_email,$matches)) { - flash_error($PALANG['pInvalidMailRegex']); - return false; + return $PALANG['pInvalidMailRegex']; } $domain=$matches[1]; Modified: trunk/model/AdminHandler.php =================================================================== --- trunk/model/AdminHandler.php 2013-04-01 20:25:33 UTC (rev 1450) +++ trunk/model/AdminHandler.php 2013-04-01 21:22:30 UTC (rev 1451) @@ -4,12 +4,13 @@ class AdminHandler extends PFAHandler { protected function validate_new_id() { - $valid = check_email($this->id); + $email_check = check_email($this->id); - if ($valid) { + if ($email_check == '') { return true; } else { - $this->errormsg[$this->id_field] = Lang::read('pAdminCreate_admin_username_text_error1'); # TODO: half of the errormsg is currently delivered via flash_error() in check_email / check_domain + $this->errormsg[] = $email_check; + $this->errormsg[$this->id_field] = Lang::read('pAdminCreate_admin_username_text_error1'); return false; } } Modified: trunk/model/AliasHandler.php =================================================================== --- trunk/model/AliasHandler.php 2013-04-01 20:25:33 UTC (rev 1450) +++ trunk/model/AliasHandler.php 2013-04-01 21:22:30 UTC (rev 1451) @@ -158,7 +158,13 @@ if ($local_part == '') { # catchall $valid = true; } else { - $valid = check_email($this->id); # TODO: check_email should return error message instead of using flash_error itsself + $email_check = check_email($this->id); + if ($email_check == '') { + $valid = true; + } else { + $this->errormsg[$this->id_field] = $email_check; + $valid = false; + } } return $valid; @@ -297,11 +303,15 @@ # and because alias domains can't forward to external domains # TODO: allow this only if $this->id is a catchall? list (/*NULL*/, $domain) = explode('@', $singlegoto); - if (!check_domain($domain)) { - $errors[] = "invalid: $singlegoto"; # TODO: better error message + $domain_check = check_domain($domain); + if ($domain_check != '') { + $errors[] = "$singlegoto: $domain_check"; } - } elseif (!check_email($singlegoto)) { - $errors[] = "invalid: $singlegoto"; # TODO: better error message + } else { + $email_check = check_email($singlegoto); + if ($email_check != '') { + $errors[] = "$singlegoto: $email_check"; + } } } Modified: trunk/model/DomainHandler.php =================================================================== --- trunk/model/DomainHandler.php 2013-04-01 20:25:33 UTC (rev 1450) +++ trunk/model/DomainHandler.php 2013-04-01 21:22:30 UTC (rev 1451) @@ -9,12 +9,12 @@ protected $domain_field = 'domain'; protected function validate_new_id() { - $valid = check_domain($this->id); + $domain_check = check_domain($this->id); - if ($valid) { + if ($domain_check == '') { return true; } else { - $this->errormsg[$this->id_field] = Lang::read('pAdminCreate_domain_domain_text_error2'); # TODO: half of the errormsg is currently delivered via flash_error() in check_domain + $this->errormsg[$this->id_field] = $domain_check; return false; } } Modified: trunk/model/MailboxHandler.php =================================================================== --- trunk/model/MailboxHandler.php 2013-04-01 20:25:33 UTC (rev 1450) +++ trunk/model/MailboxHandler.php 2013-04-01 21:22:30 UTC (rev 1451) @@ -125,7 +125,9 @@ return false; } - if ( !check_email($this->id) ) { # TODO: check_email should return error message instead of using flash_error itsself + $email_check = check_email($this->id); + if ( $email_check != '' ) { + $this->errormsg[$this->id_field] = $email_check; return false; } Modified: trunk/sendmail.php =================================================================== --- trunk/sendmail.php 2013-04-01 20:25:33 UTC (rev 1450) +++ trunk/sendmail.php 2013-04-01 21:22:30 UTC (rev 1451) @@ -50,12 +50,14 @@ $tBody = stripslashes($tBody); # TODO: check for get_magic_quotes_gpc inside safepost/safeget } - if (empty ($fTo) or !check_email ($fTo)) + $email_check = check_email ($fTo); + if (empty ($fTo) or ($email_check != '')) { $error = 1; $tTo = escape_string ($_POST['fTo']); $tSubject = escape_string ($_POST['fSubject']); - flash_error($PALANG['pSendmail_to_text_error']); + flash_error($PALANG['pSendmail_to_text_error']); # TODO: superfluous? + flash_error($email_check); } if ($error != 1) Modified: trunk/users/edit-alias.php =================================================================== --- trunk/users/edit-alias.php 2013-04-01 20:25:33 UTC (rev 1450) +++ trunk/users/edit-alias.php 2013-04-01 21:22:30 UTC (rev 1451) @@ -92,9 +92,10 @@ # - for example, $goto[] can contain an element with empty string. I added a # check for that in the 2.3 branch, but we should use a better solution # (avoid empty elements in $goto) in trunk ;-) - if(!check_email($address)) { + $email_check = check_email($address); + if($email_check != '') { $error += 1; - flash_error($PALANG['pEdit_alias_goto_text_error2'] . " $address"); + flash_error("$address: $email_check"); } else { $good_goto[] = $address; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |