Changeset 308 for branches/1.1dev/lib


Ignore:
Timestamp:
Jan 30, 2008 9:33:49 AM (16 years ago)
Author:
quinn
Message:

General bug fixes. Backported email checking regex from codebase 2.1.2. Some css mods.

Location:
branches/1.1dev/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/1.1dev/lib/App.inc.php

    r225 r308  
    693693        }
    694694    }
    695     return $dolookup ? gethostbyaddr($ip) : $ip;
     695    return $dolookup && '' != $ip ? gethostbyaddr($ip) : $ip;
    696696}
    697697
  • branches/1.1dev/lib/FormValidator.inc.php

    r140 r308  
    347347     *
    348348     * @param  string  $form_name       The name of the incoming form variable
    349      * @param  boolean $allow_fullname  Allow the use of rfc822 expanded email address with comment: Quinn Commie <quinn@strangecode.com>
    350349     *
    351350     * @return bool    true if no errors found, false otherwise
    352351     */
    353     function validateEmail($form_name, $allow_fullname=false)
    354     {
     352    function validateEmail($form_name)
     353    {       
    355354        $email = getFormData($form_name);
    356355        if ('' == trim($email)) {
     
    358357        }
    359358       
     359        $regex = '/^(?:[^,@]*\s+|[^,@]*(<)|)'                           // Display name
     360        . '((?:[^.<>\s@\",\[\]]+[^<>\s@\",\[\]])*[^.<>\s@\",\[\]]+)'    // Local-part
     361        . '@'                                                           // @
     362        . '((?:(\[)|[A-Z0-9]?)'                                         // Domain, first char
     363        . '(?(4)'                                                       // Domain conditional for if first domain char is [
     364        . '(?:[0-9]{1,3}\.){3}[0-9]{1,3}\]'                             // TRUE, matches IP address
     365        . '|'
     366        . '[.-]?(?:[A-Z0-9]+[-.])*(?:[A-Z0-9]+\.)+[A-Z]{2,6}))'         // FALSE, matches domain name
     367        . '(?(1)'                                                       // Comment conditional for if initial < exists
     368        . '(?:>\s*|>\s+\([^,@]+\)\s*)'                                  // TRUE, ensure ending >
     369        . '|'
     370        . '(?:|\s*|\s+\([^,@]+\)\s*))$/i';
     371       
    360372        // Test email address format.
    361         if ($allow_fullname) {
    362             if (!$this->checkRegex($form_name, '/^[\w\s]*<?php[A-Za-z0-9._-]{1,}\@[A-Za-z0-9.-]{1,}\.[A-Za-z]{2,5}>?$/i', true, sprintf(_("<strong>%s</strong> is not a valid email address."), $email))) {
    363                 logMsg(sprintf('The email address %s is not valid.', getFormData($form_name)), LOG_DEBUG, __FILE__, __LINE__);
    364                 return false;
    365             }
    366         } else {
    367             if (!$this->checkRegex($form_name, '/^[A-Za-z0-9._-]{1,}\@[A-Za-z0-9.-]{1,}\.[A-Za-z]{2,5}$/i', true, sprintf(_("<strong>%s</strong> is not a valid email address."), $email))) {
    368                 logMsg(sprintf('The email address %s is not valid.', getFormData($form_name)), LOG_DEBUG, __FILE__, __LINE__);
    369                 return false;
    370             }
    371         }
     373        if (!preg_match($regex, getFormData($form_name), $e_parts)) {
     374            $this->addError($form_name, sprintf(_("The email address <strong>%s</strong> is formatted incorrectly."), oTxt(getFormData($form_name))), MSG_ERR, __FILE__, __LINE__);
     375            logMsg(sprintf('The email address %s is not valid.', getFormData($form_name)), LOG_DEBUG, __FILE__, __LINE__);
     376            return false;
     377        }
     378       
     379        // We have a match! Here are the captured subpatterns, on which further tests are run.
     380        // The part before the @.
     381        $local = $e_parts[2];
     382
     383        // The part after the @.
     384        // If domain is an IP [XXX.XXX.XXX.XXX] strip off the brackets.
     385        $domain = $e_parts[3]{0} == '[' ? mb_substr($e_parts[3], 1, -1) : $e_parts[3];
    372386       
    373387        // Test length.
    374         if (!$this->stringLength($form_name, 0, 128, sprintf(_("<strong>Email address</strong> must contain less than 128 characters."), $email))) {
    375             logMsg(sprintf('The email address %s must contain less than 128 characters.', getFormData($form_name)), LOG_DEBUG, __FILE__, __LINE__);
    376             return false;
    377         }
    378        
    379         // Check domain exists and has valid MX record.
    380         preg_match('/^[\w\s]*<?php[A-Za-z0-9._-]{1,}\@([A-Za-z0-9.-]{1,}\.[A-Za-z]{2,5})>?$/i', $email, $matches);
    381         if (!empty($matches[1])) {
    382             if (!checkdnsrr($matches[1] . '.', 'MX') && gethostbyname($matches[1]) == $matches[1]) {
    383                 $this->addError($form_name, sprintf(_("<strong>%s</strong> is not a valid email domain name"), $matches[1]));
    384                 logMsg(sprintf('The email address %s contains an invalid email domain name (%s).', getFormData($form_name), $matches[1]), LOG_DEBUG, __FILE__, __LINE__);
    385                 return false;
    386             }
     388        if (mb_strlen($local) > 64 || mb_strlen($domain) > 191) {
     389            $this->addError($form_name, sprintf(_("The email address <strong>%s</strong> is too long."), oTxt(getFormData($form_name))), MSG_ERR, __FILE__, __LINE__);
     390            logMsg(sprintf('The email address %s is too long.', getFormData($form_name)), LOG_DEBUG, __FILE__, __LINE__);
     391            return false;
     392        }
     393       
     394        // Check domain exists: It's a domain if ip2long fails; Checkdnsrr ensures a MX record exists; Gethostbyname() ensures the domain exists.
     395        // Compare ip2long twice for php4 backwards compat.
     396        if ((ip2long($domain) == '-1' || ip2long($domain) === false) && function_exists('checkdnsrr') && !checkdnsrr($domain . '.', 'MX') && gethostbyname($domain) == $domain) {
     397            $this->addError($form_name, sprintf(_("The email address <em>%s</em> does not have a valid domain name."), oTxt(getFormData($form_name))), MSG_ERR, __FILE__, __LINE__);
     398            logMsg(sprintf('The email address %s does not have a valid domain name.', getFormData($form_name)), LOG_DEBUG, __FILE__, __LINE__);
     399            return false;
    387400        }
    388401       
  • branches/1.1dev/lib/TemplateGlue.inc.php

    r289 r308  
    169169            if ('allone' == $flag) {
    170170                // Print a cell with multidimentioal array checkboxes.
    171                 ?><td><label><input type="checkbox" name="dbcol[<?php echo $db_col; ?>][<?php echo $item; ?>]"<?php echo $checked; ?> />&nbsp;<?php echo oTxt($item); ?></label>&nbsp;</td>
     171                ?><td><label class="normal"><input type="checkbox" name="dbcol[<?php echo $db_col; ?>][<?php echo $item; ?>]"<?php echo $checked; ?> />&nbsp;<?php echo oTxt($item); ?></label>&nbsp;</td>
    172172                <?php
    173173             } else {
    174174                // Print a cell with basic named checkboxes.
    175                 ?><td><label><input type="checkbox" name="<?php echo $db_col; ?>[<?php echo $item; ?>]"<?php echo $checked; ?> />&nbsp;<?php echo oTxt($item); ?></label>&nbsp;</td>
     175                ?><td><label class="normal"><input type="checkbox" name="<?php echo $db_col; ?>[<?php echo $item; ?>]"<?php echo $checked; ?> />&nbsp;<?php echo oTxt($item); ?></label>&nbsp;</td>
    176176                <?php
    177177            }
     
    248248            }
    249249            // Print a cell with basic named checkboxes.
    250             ?><td><label><input type="radio" name="<?php echo $db_col; ?>" value="<?php echo $item ?>"<?php echo $checked; ?> />&nbsp;<?php echo oTxt($item); ?></label>&nbsp;</td>
     250            ?><td><label class="normal"><input type="radio" name="<?php echo $db_col; ?>" value="<?php echo $item ?>"<?php echo $checked; ?> />&nbsp;<?php echo oTxt($item); ?></label>&nbsp;</td>
    251251            <?php
    252252        }
Note: See TracChangeset for help on using the changeset viewer.