Changeset 881

Show
Ignore:
Timestamp:
12/29/05 19:37:36 (7 years ago)
Author:
fproulx
Message:

2005-12-29 Fran�ois Proulx <francois.proulx@…>

  • Integrating Philippe's code for User class
  • This build needs extensive testing please
  • E-mail blacklisting (Mail class)
Location:
trunk/wifidog-auth
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/ChangeLog

    r880 r881  
    22        * Integrating Philippe's code for User class 
    33        * This build needs extensive testing please 
     4        * E-mail blacklisting (Mail class) 
    45         
    562005-12-29 François Proulx <francois.proulx@gmail.com> 
  • trunk/wifidog-auth/wifidog/classes/Mail.php

    r877 r881  
    11<?php 
     2 
    23 
    34/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 
     
    4849class Mail 
    4950{ 
    50     // Business domain attributes 
    51     private $from_name; 
    52     private $from_email; 
    53     private $to_name; 
    54     private $to_email; 
    55     private $subject; 
    56     private $body; 
     51        // List of fake e-mails hosts 
     52        private static $_hosts_black_list = array ("simplicato.net", "mytrashmail.com", "spamhole.com", "mailexpire.com", "sneakemail.com", "spamex.com", "emailias.com", "mymailoasis.com", "spamcon.org", "spamgourmet.com", "spammotel.com", "dodgeit.com"); 
    5753 
    58     public function __construct() 
    59     { 
    60     } 
     54        // Business domain attributes 
     55        private $from_name; 
     56        private $from_email; 
     57        private $to_name; 
     58        private $to_email; 
     59        private $subject; 
     60        private $body; 
    6161 
    62     private function encodeMimeHeader($header) 
    63     { 
    64         // BASE 64 according to the RFC 
    65         // Taken from : www.php.net mb_send_mail comments 
    66         $header = preg_replace('/([^a-z ])/ie', 'sprintf("=%02x",ord(StripSlashes("\\1")))', $header); 
    67         $header = str_replace(' ', '_', $header); 
    68         return "=?utf-8?Q?$header?="; 
    69     } 
     62        public function __construct() 
     63        { 
     64        } 
    7065 
    71     public function getMessageBody() 
    72     { 
    73         return $this->body; 
    74     } 
     66        private function encodeMimeHeader($header) 
     67        { 
     68                // BASE 64 according to the RFC 
     69                // Taken from : www.php.net mb_send_mail comments 
     70                $header = preg_replace('/([^a-z ])/ie', 'sprintf("=%02x",ord(StripSlashes("\\1")))', $header); 
     71                $header = str_replace(' ', '_', $header); 
     72                return "=?utf-8?Q?$header?="; 
     73        } 
    7574 
    76     public function getMessageSubject() 
    77     { 
    78         return $this->subject; 
    79     } 
     75        public function getMessageBody() 
     76        { 
     77                return $this->body; 
     78        } 
    8079 
    81     public function getRecipientName() 
    82     { 
    83         return $this->to_name; 
    84     } 
     80        public function getMessageSubject() 
     81        { 
     82                return $this->subject; 
     83        } 
    8584 
    86     public function getRecipientEmail() 
    87     { 
    88         return $this->to_email; 
    89     } 
     85        public function getRecipientName() 
     86        { 
     87                return $this->to_name; 
     88        } 
    9089 
    91     public function getSenderName() 
    92     { 
    93         return $this->from_name; 
    94     } 
     90        public function getRecipientEmail() 
     91        { 
     92                return $this->to_email; 
     93        } 
    9594 
    96     public function getSenderEmail() 
    97     { 
    98         return $this->from_email; 
    99     } 
     95        public function getSenderName() 
     96        { 
     97                return $this->from_name; 
     98        } 
    10099 
    101     // Packs e-mail and send it according to RFC822 
    102     public function send() 
    103     { 
    104         $headers = "From: \"".$this->getSenderName()."\" <".$this->getSenderEmail().">\r\n"; 
    105         $headers .= "Reply-To: ".$this->getSenderEmail()."\r\n"; 
    106         $headers .= "Content-Type: text/plain; charset=utf-8"; 
    107         $args = "-f".$this->getSenderEmail(); 
    108         return mail($this->getRecipientEmail(), $this->getMessageSubject(), $this->getMessageBody(), $headers, $args); 
    109     } 
     100        public function getSenderEmail() 
     101        { 
     102                return $this->from_email; 
     103        } 
    110104 
    111     public function setMessageBody($body) 
    112     { 
    113         $this->body = $body; 
    114     } 
     105        // Packs e-mail and send it according to RFC822 
     106        public function send() 
     107        { 
     108                $headers = "From: \"".$this->getSenderName()."\" <".$this->getSenderEmail().">\r\n"; 
     109                $headers .= "Reply-To: ".$this->getSenderEmail()."\r\n"; 
     110                $headers .= "Content-Type: text/plain; charset=utf-8"; 
     111                $args = "-f".$this->getSenderEmail(); 
     112                return mail($this->getRecipientEmail(), $this->getMessageSubject(), $this->getMessageBody(), $headers, $args); 
     113        } 
    115114 
    116     public function setMessageSubject($subject) 
    117     { 
    118         $this->subject = $this->encodeMimeHeader($subject); 
    119     } 
     115        public function setMessageBody($body) 
     116        { 
     117                $this->body = $body; 
     118        } 
    120119 
    121     public function setRecipientEmail($mail) 
    122     { 
    123         $this->to_email = $mail; 
    124     } 
     120        public function setMessageSubject($subject) 
     121        { 
     122                $this->subject = $this->encodeMimeHeader($subject); 
     123        } 
    125124 
    126     public function setSenderName($name) 
    127     { 
    128         // Encode header 
    129         $this->from_name = $this->encodeMimeHeader($name); 
    130     } 
     125        public function setRecipientEmail($mail) 
     126        { 
     127                $this->to_email = $mail; 
     128        } 
    131129 
    132     public function setSenderEmail($mail) 
    133     { 
    134         $this->from_email = $mail; 
    135     } 
     130        public function setSenderName($name) 
     131        { 
     132                // Encode header 
     133                $this->from_name = $this->encodeMimeHeader($name); 
     134        } 
     135 
     136        public function setSenderEmail($mail) 
     137        { 
     138                $this->from_email = $mail; 
     139        } 
     140 
     141        /** 
     142         * Validates an e-mail address  
     143         * 
     144         * This function will make sure an e-mail is RFC822 compliant 
     145         * and is not black listed. 
     146         *  
     147         * Here's an example of how to use the function: 
     148         * <code> 
     149         * Mail::validateEmailAddress($mail); 
     150         * </code> 
     151         * 
     152         * @param string $mail The e-mail address to validate 
     153         * 
     154         * @return boolean Returns whether the e-mail is valid or not 
     155         * 
     156         * @access public 
     157         * @static 
     158         */ 
     159        public static function validateEmailAddress($email) 
     160        { 
     161                $matches = null; 
     162                // Test if the email matches the regexp 
     163                $regex = "/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i"; 
     164                if (preg_match_all($regex, $email, $matches)) 
     165                { 
     166                        // If the hostname is black listed, reject the e-mail. 
     167                        $full_hostname = $matches[2][0].".".$matches[3][0]; 
     168                        if(in_array($full_hostname, self::$_hosts_black_list)) 
     169                                return false; 
     170                        else 
     171                                return true; 
     172                } 
     173                else 
     174                        return false; 
     175        } 
     176 
    136177} 
    137178 
     
    143184 * End: 
    144185 */ 
    145  
    146186?> 
  • trunk/wifidog-auth/wifidog/signup.php

    r874 r881  
    5252require_once('classes/Security.php'); 
    5353require_once('classes/MainUI.php'); 
     54require_once('classes/Mail.php'); 
    5455 
    5556if (defined("CUSTOM_SIGNUP_URL")) 
     
    7374        throw new Exception(_("A valid email address is required.")); 
    7475 
    75     if (!ereg("^.*@.*\..*$", $email)) 
    76         throw new Exception(_("The email address must be of the form user@domain.com.")); 
     76        if(Mail::validateEmailAddress($email) === false) 
     77        throw new Exception(_("The email address must be of the form user@domain.com and is not black-listed.")); 
    7778} 
    7879