From: <dai...@us...> - 2010-05-15 10:53:11
|
Revision: 3461 http://web-erp.svn.sourceforge.net/web-erp/?rev=3461&view=rev Author: daintree Date: 2010-05-15 10:53:04 +0000 (Sat, 15 May 2010) Log Message: ----------- Combined the common address checking function from Save.php and MiscFunctions.php into a single function Modified Paths: -------------- trunk/doc/Change.log.html trunk/includes/MiscFunctions.php trunk/install/save.php Modified: trunk/doc/Change.log.html =================================================================== --- trunk/doc/Change.log.html 2010-05-15 10:39:42 UTC (rev 3460) +++ trunk/doc/Change.log.html 2010-05-15 10:53:04 UTC (rev 3461) @@ -1,5 +1,6 @@ <p><font SIZE=4 COLOR=BLUE><b>webERP Change Log</b></font></p> <p></p> +<p>15/5/10 Phil: Used Lindsay/Ngaraj's nice email address checking function to replace the existing function in MiscFunctions.php and includes MiscFunctions.php in install/save.php to avoid duplication of the function</p> <p>15/5/10 Phil: $debug variable in UserLogin.php was only set on first login - not subsequent page calls (its not a session variable) - moved it back into session.inc so that full info about bugs is available to sysadmins <p>15/5/10 Phil: GetPrices.inc Prices.php and Prices_Customer.php - modified to allow default prices - with no end dates - reducing requirement to administer - also updated Prices section of the manual <p>11/05/10 Tim: Exit MRP scripts gracefully if no MRP calculation has been done.</p> Modified: trunk/includes/MiscFunctions.php =================================================================== --- trunk/includes/MiscFunctions.php 2010-05-15 10:39:42 UTC (rev 3460) +++ trunk/includes/MiscFunctions.php 2010-05-15 10:53:04 UTC (rev 3461) @@ -50,26 +50,67 @@ return '<DIV class="'.$Class.'"><B>' . $Prefix . '</B> : ' .$Msg . '</DIV>'; }//getMsg -function IsEmailAddress($TestEmailAddress){ +function IsEmailAddress($email){ -/*thanks to Gavin Sharp for this regular expression to test validity of email addresses */ + $atIndex = strrpos ($email, "@"); + if ($atIndex === false) + { + return false; // No @ sign is not acceptable. + } - if (function_exists('preg_match')){ - if(preg_match("/^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/", $TestEmailAddress)){ - return true; - } else { - return false; - } - } else { - if (strlen($TestEmailAddress)>5 AND strstr($TestEmailAddress,'@')>2 AND (strstr($TestEmailAddress,'.co')>3 OR strstr($TestEmailAddress,'.org')>3 OR strstr($TestEmailAddress,'.net')>3 OR strstr($TestEmailAddress,'.edu')>3 OR strstr($TestEmailAddress,'.biz')>3)){ - return true; - } else { - return false; - } + if (preg_match('/\\.\\./', $email)) + return false; // > 1 consecutive dot is not allowed. + + // Check component length limits + $domain = substr ($email, $atIndex+1); + $local = substr ($email, 0, $atIndex); + $localLen = strlen ($local); + $domainLen = strlen ($domain); + if ($localLen < 1 || $localLen > 64) + { + // local part length exceeded + return false; } + if ($domainLen < 1 || $domainLen > 255) + { + // domain part length exceeded + return false; + } + + if ($local[0] == '.' || $local[$localLen-1] == '.') + { + // local part starts or ends with '.' + return false; + } + if (!preg_match ('/^[A-Za-z0-9\\-\\.]+$/', $domain )) + { + // character not valid in domain part + return false; + } + if (!preg_match ('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', + str_replace ("\\\\", "" ,$local ) )) + { + // character not valid in local part unless local part is quoted + if (!preg_match ('/^"(\\\\"|[^"])+"$/', + str_replace("\\\\", "", $local) )) + { + return false; + } + } + + // Check for a DNS 'MX' or 'A' record. + // Windows supported from PHP 5.3.0 on - so check. + $ret = true; + if (version_compare(PHP_VERSION, '5.3.0') >= 0 + || strtoupper(substr(PHP_OS, 0, 3) !== 'WIN')) { + $ret = checkdnsrr( $domain, "MX" ) || checkdnsrr( $domain, "A" ); + } + + return $ret; } + Function ContainsIllegalCharacters ($CheckVariable) { if (strstr($CheckVariable,"'") Modified: trunk/install/save.php =================================================================== --- trunk/install/save.php 2010-05-15 10:39:42 UTC (rev 3460) +++ trunk/install/save.php 2010-05-15 10:53:04 UTC (rev 3461) @@ -4,6 +4,7 @@ ini_set('display_errors', "On"); ini_set('max_execution_time', "180"); +require_once('../includes/MiscFunctions.php'); // Start a session if(!defined('SESSION_STARTED')){ session_name('ba_session_id'); @@ -108,64 +109,8 @@ return $default_dir_mode; } -function is_valid_email($email) { - $atIndex = strrpos ($email, "@"); - if ($atIndex === false) - { - return false; // No @ sign is not acceptable. - } - if (preg_match('/\\.\\./', $email)) - return false; // > 1 consecutive dot is not allowed. - // Check component length limits - $domain = substr ($email, $atIndex+1); - $local = substr ($email, 0, $atIndex); - $localLen = strlen ($local); - $domainLen = strlen ($domain); - if ($localLen < 1 || $localLen > 64) - { - // local part length exceeded - return false; - } - if ($domainLen < 1 || $domainLen > 255) - { - // domain part length exceeded - return false; - } - - if ($local[0] == '.' || $local[$localLen-1] == '.') - { - // local part starts or ends with '.' - return false; - } - if (!preg_match ('/^[A-Za-z0-9\\-\\.]+$/', $domain )) - { - // character not valid in domain part - return false; - } - if (!preg_match ('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', - str_replace ("\\\\", "" ,$local ) )) - { - // character not valid in local part unless local part is quoted - if (!preg_match ('/^"(\\\\"|[^"])+"$/', - str_replace("\\\\", "", $local) )) - { - return false; - } - } - - // Check for a DNS 'MX' or 'A' record. - // Windows supported from PHP 5.3.0 on - so check. - $ret = true; - if (version_compare(PHP_VERSION, '5.3.0') >= 0 - || strtoupper(substr(PHP_OS, 0, 3) !== 'WIN')) { - $ret = checkdnsrr( $domain, "MX" ) || checkdnsrr( $domain, "A" ); - } - - return $ret; -} - if (isset($_POST['path_to_root'])) { $path_to_root = $_POST['path_to_root']; } else { @@ -258,7 +203,7 @@ if (!isset($_POST['admin_email']) || $_POST['admin_email'] == ''){ set_error('Please enter an email for the Administrator account'); } else { - if (is_valid_email($_POST['admin_email'])==false) { + if (IsEmailAddress($_POST['admin_email'])==false) { set_error('Please enter a valid email address for the Administrator account'); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |