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


git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1451 a1433add-5e2c-0410-b055-b7f2511e0802
pull/2/head
Christian Boltz 12 years ago
parent c64768727d
commit 871bcbbe2f

@ -219,19 +219,20 @@ function check_string ($var) {
//
// 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 @@ function check_domain ($domain) {
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 @@ function check_domain ($domain) {
* 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 @@ function check_email ($email) {
// 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];

@ -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;
}
}

@ -158,7 +158,13 @@ class AliasHandler extends PFAHandler {
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 @@ class AliasHandler extends PFAHandler {
# 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";
}
} else {
$email_check = check_email($singlegoto);
if ($email_check != '') {
$errors[] = "$singlegoto: $email_check";
}
} elseif (!check_email($singlegoto)) {
$errors[] = "invalid: $singlegoto"; # TODO: better error message
}
}

@ -9,12 +9,12 @@ class DomainHandler extends PFAHandler {
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;
}
}

@ -125,7 +125,9 @@ class MailboxHandler extends PFAHandler {
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;
}

@ -50,12 +50,14 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
$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)

@ -92,9 +92,10 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
# - 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;

Loading…
Cancel
Save