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 * Checks if a domain is valid
// Action: Checks if domain is valid and returns TRUE if this is the case. * @param string $domain
// Call: check_domain (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: make check_domain able to handle as example .local domains
* TODO: skip DNS check if the domain exists in PostfixAdmin?
*/
function check_domain ($domain) { function check_domain ($domain) {
global $CONF; global $CONF;
global $PALANG; global $PALANG;
if (!preg_match ('/^([-0-9A-Z]+\.)+' . '([0-9A-Z]){2,6}$/i', ($domain))) { if (!preg_match ('/^([-0-9A-Z]+\.)+' . '([0-9A-Z]){2,6}$/i', ($domain))) {
flash_error(sprintf($PALANG['pInvalidDomainRegex'], htmlentities($domain))); return sprintf($PALANG['pInvalidDomainRegex'], htmlentities($domain));
return false;
} }
if (isset($CONF['emailcheck_resolve_domain']) && 'YES' == $CONF['emailcheck_resolve_domain'] && 'WINDOWS'!=(strtoupper(substr(php_uname('s'), 0, 7)))) { 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')) { if(function_exists('checkdnsrr')) {
// AAAA (IPv6) is only available in PHP v. >= 5 // AAAA (IPv6) is only available in PHP v. >= 5
if (version_compare(phpversion(), "5.0.0", ">=")) { 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,'A')) return '';
if (checkdnsrr($domain,'MX')) return true; if (checkdnsrr($domain,'MX')) return '';
flash_error(sprintf($PALANG['pInvalidDomainDNS'], htmlentities($domain))); return sprintf($PALANG['pInvalidDomainDNS'], htmlentities($domain));
return false;
} else { } 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 * check_email
* Checks if an email is valid - if it is, return true, else false. * Checks if an email is valid - if it is, return true, else false.
* @param String $email - a string that may be an email address. * @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: make check_email able to handle already added domains
* TODO: don't use flash_error, use return value instead
*/ */
function check_email ($email) { function check_email ($email) {
global $CONF; global $CONF;
@ -280,15 +279,13 @@ function check_email ($email) {
// Perform non-domain-part sanity checks // Perform non-domain-part sanity checks
if (!preg_match ('/^[-!#$%&\'*+\\.\/0-9=?A-Z^_{|}~]+' . '@' . '[^@]+$/i', $ce_email)) { if (!preg_match ('/^[-!#$%&\'*+\\.\/0-9=?A-Z^_{|}~]+' . '@' . '[^@]+$/i', $ce_email)) {
flash_error($PALANG['pInvalidMailRegex']); return $PALANG['pInvalidMailRegex'];
return false;
} }
// Determine domain name // Determine domain name
$matches=array(); $matches=array();
if (!preg_match('|@(.+)$|',$ce_email,$matches)) { if (!preg_match('|@(.+)$|',$ce_email,$matches)) {
flash_error($PALANG['pInvalidMailRegex']); return $PALANG['pInvalidMailRegex'];
return false;
} }
$domain=$matches[1]; $domain=$matches[1];

@ -4,12 +4,13 @@
class AdminHandler extends PFAHandler { class AdminHandler extends PFAHandler {
protected function validate_new_id() { protected function validate_new_id() {
$valid = check_email($this->id); $email_check = check_email($this->id);
if ($valid) { if ($email_check == '') {
return true; return true;
} else { } 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; return false;
} }
} }

@ -158,7 +158,13 @@ class AliasHandler extends PFAHandler {
if ($local_part == '') { # catchall if ($local_part == '') { # catchall
$valid = true; $valid = true;
} else { } 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; return $valid;
@ -297,11 +303,15 @@ class AliasHandler extends PFAHandler {
# and because alias domains can't forward to external domains # and because alias domains can't forward to external domains
# TODO: allow this only if $this->id is a catchall? # TODO: allow this only if $this->id is a catchall?
list (/*NULL*/, $domain) = explode('@', $singlegoto); list (/*NULL*/, $domain) = explode('@', $singlegoto);
if (!check_domain($domain)) { $domain_check = check_domain($domain);
$errors[] = "invalid: $singlegoto"; # TODO: better error message 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 $domain_field = 'domain';
protected function validate_new_id() { protected function validate_new_id() {
$valid = check_domain($this->id); $domain_check = check_domain($this->id);
if ($valid) { if ($domain_check == '') {
return true; return true;
} else { } 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; return false;
} }
} }

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

@ -50,12 +50,14 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
$tBody = stripslashes($tBody); # TODO: check for get_magic_quotes_gpc inside safepost/safeget $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; $error = 1;
$tTo = escape_string ($_POST['fTo']); $tTo = escape_string ($_POST['fTo']);
$tSubject = escape_string ($_POST['fSubject']); $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) 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 # - 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 # check for that in the 2.3 branch, but we should use a better solution
# (avoid empty elements in $goto) in trunk ;-) # (avoid empty elements in $goto) in trunk ;-)
if(!check_email($address)) { $email_check = check_email($address);
if($email_check != '') {
$error += 1; $error += 1;
flash_error($PALANG['pEdit_alias_goto_text_error2'] . " $address"); flash_error("$address: $email_check");
} }
else { else {
$good_goto[] = $address; $good_goto[] = $address;

Loading…
Cancel
Save