| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ |
|---|
| 5 | |
|---|
| 6 | // +-------------------------------------------------------------------+ |
|---|
| 7 | // | WiFiDog Authentication Server | |
|---|
| 8 | // | ============================= | |
|---|
| 9 | // | | |
|---|
| 10 | // | The WiFiDog Authentication Server is part of the WiFiDog captive | |
|---|
| 11 | // | portal suite. | |
|---|
| 12 | // +-------------------------------------------------------------------+ |
|---|
| 13 | // | PHP version 5 required. | |
|---|
| 14 | // +-------------------------------------------------------------------+ |
|---|
| 15 | // | Homepage: http://www.wifidog.org/ | |
|---|
| 16 | // | Source Forge: http://sourceforge.net/projects/wifidog/ | |
|---|
| 17 | // +-------------------------------------------------------------------+ |
|---|
| 18 | // | This program is free software; you can redistribute it and/or | |
|---|
| 19 | // | modify it under the terms of the GNU General Public License as | |
|---|
| 20 | // | published by the Free Software Foundation; either version 2 of | |
|---|
| 21 | // | the License, or (at your option) any later version. | |
|---|
| 22 | // | | |
|---|
| 23 | // | This program is distributed in the hope that it will be useful, | |
|---|
| 24 | // | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|---|
| 25 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|---|
| 26 | // | GNU General Public License for more details. | |
|---|
| 27 | // | | |
|---|
| 28 | // | You should have received a copy of the GNU General Public License | |
|---|
| 29 | // | along with this program; if not, contact: | |
|---|
| 30 | // | | |
|---|
| 31 | // | Free Software Foundation Voice: +1-617-542-5942 | |
|---|
| 32 | // | 59 Temple Place - Suite 330 Fax: +1-617-542-2652 | |
|---|
| 33 | // | Boston, MA 02111-1307, USA gnu@gnu.org | |
|---|
| 34 | // | | |
|---|
| 35 | // +-------------------------------------------------------------------+ |
|---|
| 36 | |
|---|
| 37 | /** |
|---|
| 38 | * @package WiFiDogAuthServer |
|---|
| 39 | * @author Francois Proulx <francois.proulx@gmail.com> |
|---|
| 40 | * @copyright 2005-2006 Francois Proulx, Technologies Coeus inc. |
|---|
| 41 | * @version Subversion $Id$ |
|---|
| 42 | * @link http://www.wifidog.org/ |
|---|
| 43 | */ |
|---|
| 44 | |
|---|
| 45 | /** |
|---|
| 46 | * Load required classes |
|---|
| 47 | */ |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | /** |
|---|
| 51 | * This a wrapper class conforming RFC822 capable of sending valid UTF-8 MIME |
|---|
| 52 | * headers |
|---|
| 53 | * |
|---|
| 54 | * @package WiFiDogAuthServer |
|---|
| 55 | * @author Francois Proulx <francois.proulx@gmail.com> |
|---|
| 56 | * @copyright 2005-2006 Francois Proulx, Technologies Coeus inc. |
|---|
| 57 | */ |
|---|
| 58 | class Mail { |
|---|
| 59 | /** |
|---|
| 60 | * List of fake e-mails hosts. IMPORTANT NOTE: This is not meant to block |
|---|
| 61 | * hotmail, gmail, etc. On the contrary, we encourage users to use |
|---|
| 62 | * annonymous email. We just want them to stay reachable in case of problem |
|---|
| 63 | * or abuse. |
|---|
| 64 | * |
|---|
| 65 | * All domains must be lowercase |
|---|
| 66 | * @note We may have to do something a little smarter to deal with the likes |
|---|
| 67 | * of 2prong.com and blah+blah@gmail.com |
|---|
| 68 | */ |
|---|
| 69 | private static $_hosts_black_list = array ( |
|---|
| 70 | "10minutemail.com", |
|---|
| 71 | "afrobacon.com", |
|---|
| 72 | "antispam24.de", |
|---|
| 73 | "bloglines.com", |
|---|
| 74 | "discardmail.com", |
|---|
| 75 | "disposeamail.com", |
|---|
| 76 | "dodgeit.com", |
|---|
| 77 | "dontreg.com", |
|---|
| 78 | "dumpmail.de", |
|---|
| 79 | "e4ward.com", |
|---|
| 80 | "emailias.com", |
|---|
| 81 | "guerrillamail.info", |
|---|
| 82 | "gishpuppy.com", |
|---|
| 83 | "golfilla.info", |
|---|
| 84 | "greensloth.com", |
|---|
| 85 | "hatespam.org", |
|---|
| 86 | "haltospam.com", |
|---|
| 87 | "h8s.org", |
|---|
| 88 | "ipoo.org", |
|---|
| 89 | "jetable.org", |
|---|
| 90 | "kasmail.com", |
|---|
| 91 | "mail-filter.com", |
|---|
| 92 | "maileater.com", |
|---|
| 93 | "mailexpire.com", |
|---|
| 94 | "mailinator.com", |
|---|
| 95 | "mailnull.com", |
|---|
| 96 | "mailshell.com", |
|---|
| 97 | "mymailoasis.com", |
|---|
| 98 | "mytrashmail.com", |
|---|
| 99 | "mytrashmail.net", |
|---|
| 100 | "nervmich.net", |
|---|
| 101 | "oopi.org", |
|---|
| 102 | "poofy.org", |
|---|
| 103 | "pookmail.com", |
|---|
| 104 | "put2.net", |
|---|
| 105 | "senseless-entertainment.com", |
|---|
| 106 | "shortmail.net", |
|---|
| 107 | "simplicato.net", |
|---|
| 108 | "slaskpost.se", |
|---|
| 109 | "sneakemail.com", |
|---|
| 110 | "sofort-mail.de", |
|---|
| 111 | "spam.la", |
|---|
| 112 | "spamcon.org", |
|---|
| 113 | "spamday.com", |
|---|
| 114 | "spamex.com", |
|---|
| 115 | "spamgourmet.com", |
|---|
| 116 | "spamhole.com", |
|---|
| 117 | "spammotel.com", |
|---|
| 118 | "tempemail.net", |
|---|
| 119 | "tempinbox.com", |
|---|
| 120 | "temporaryinbox.com", |
|---|
| 121 | "throwaway.de", |
|---|
| 122 | "trash-mail.de", |
|---|
| 123 | "woodyland.org", |
|---|
| 124 | "wuzup.net" |
|---|
| 125 | ); |
|---|
| 126 | /** |
|---|
| 127 | * Name email will been sent from |
|---|
| 128 | * |
|---|
| 129 | * @var string |
|---|
| 130 | */ |
|---|
| 131 | private $_fromName; |
|---|
| 132 | |
|---|
| 133 | /** |
|---|
| 134 | * Address email will be sent from |
|---|
| 135 | * |
|---|
| 136 | * @var string |
|---|
| 137 | */ |
|---|
| 138 | private $_fromEmail; |
|---|
| 139 | |
|---|
| 140 | /** |
|---|
| 141 | * Name email will be sent to |
|---|
| 142 | * |
|---|
| 143 | * @var string |
|---|
| 144 | */ |
|---|
| 145 | private $_toName; |
|---|
| 146 | |
|---|
| 147 | /** |
|---|
| 148 | * Address email will be sent to |
|---|
| 149 | * |
|---|
| 150 | * @var string |
|---|
| 151 | */ |
|---|
| 152 | private $_toEmail; |
|---|
| 153 | |
|---|
| 154 | /** |
|---|
| 155 | * Subject of email |
|---|
| 156 | * |
|---|
| 157 | * @var string |
|---|
| 158 | */ |
|---|
| 159 | private $_subject; |
|---|
| 160 | |
|---|
| 161 | /** |
|---|
| 162 | * Content of email |
|---|
| 163 | * |
|---|
| 164 | * @var string |
|---|
| 165 | */ |
|---|
| 166 | private $_body; |
|---|
| 167 | |
|---|
| 168 | /** |
|---|
| 169 | * Priority of email |
|---|
| 170 | * |
|---|
| 171 | * @var boolean |
|---|
| 172 | */ |
|---|
| 173 | private $_highPriority; |
|---|
| 174 | |
|---|
| 175 | /** |
|---|
| 176 | * Encodes the MIME header |
|---|
| 177 | * |
|---|
| 178 | * @param string $header Header of email |
|---|
| 179 | * |
|---|
| 180 | * @return string Encoded MIME header |
|---|
| 181 | |
|---|
| 182 | * |
|---|
| 183 | * @see http://www.php.net/manual/en/function.mb-send-mail.php |
|---|
| 184 | */ |
|---|
| 185 | private function _encodeMimeHeader($header) { |
|---|
| 186 | // BASE 64 according to the RFC |
|---|
| 187 | $header = preg_replace('/([^a-z ])/ie', 'sprintf("=%02x",ord(StripSlashes("\\1")))', $header); |
|---|
| 188 | $header = str_replace(' ', '_', $header); |
|---|
| 189 | return "=?utf-8?Q?$header?="; |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | /** |
|---|
| 193 | * Returns name of sender of email |
|---|
| 194 | * |
|---|
| 195 | * @return string Name of sender of email |
|---|
| 196 | * |
|---|
| 197 | * @access public |
|---|
| 198 | */ |
|---|
| 199 | public function getSenderName() { |
|---|
| 200 | return $this->_fromName; |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | /** |
|---|
| 204 | * Sets name of sender of email |
|---|
| 205 | * |
|---|
| 206 | * @param string $name Name of sender of email |
|---|
| 207 | * |
|---|
| 208 | * @return void |
|---|
| 209 | * |
|---|
| 210 | * @access public |
|---|
| 211 | */ |
|---|
| 212 | public function setSenderName($name) { |
|---|
| 213 | // Encode name |
|---|
| 214 | $this->_fromName = $this->_encodeMimeHeader($name); |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | /** |
|---|
| 218 | * Returns address of sender of email |
|---|
| 219 | * |
|---|
| 220 | * @return string Address of sender of email |
|---|
| 221 | * |
|---|
| 222 | * @access public |
|---|
| 223 | */ |
|---|
| 224 | public function getSenderEmail() { |
|---|
| 225 | return $this->_fromEmail; |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | /** |
|---|
| 229 | * Sets address of sender of email |
|---|
| 230 | * |
|---|
| 231 | * @param string $mail Address of sender of email |
|---|
| 232 | * |
|---|
| 233 | * @return void |
|---|
| 234 | * |
|---|
| 235 | * @access public |
|---|
| 236 | */ |
|---|
| 237 | public function setSenderEmail($mail) { |
|---|
| 238 | $this->_fromEmail = $mail; |
|---|
| 239 | } |
|---|
| 240 | |
|---|
| 241 | /** |
|---|
| 242 | * Returns name of recipient of email |
|---|
| 243 | * |
|---|
| 244 | * @return string Name of recipient of email |
|---|
| 245 | * |
|---|
| 246 | * @access public |
|---|
| 247 | */ |
|---|
| 248 | public function getRecipientName() { |
|---|
| 249 | return $this->_toName; |
|---|
| 250 | } |
|---|
| 251 | |
|---|
| 252 | /** |
|---|
| 253 | * Sets name of recipient of email |
|---|
| 254 | * |
|---|
| 255 | * @param string $name Name of recipient of email |
|---|
| 256 | * |
|---|
| 257 | * @return void |
|---|
| 258 | * |
|---|
| 259 | * @access public |
|---|
| 260 | */ |
|---|
| 261 | public function setRecipientName($name) { |
|---|
| 262 | // Encode name |
|---|
| 263 | $this->_toName = $this->_encodeMimeHeader($name); |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | /** |
|---|
| 267 | * Returns address of recipient of email |
|---|
| 268 | * |
|---|
| 269 | * @return string Address of recipient of email |
|---|
| 270 | * |
|---|
| 271 | * @access public |
|---|
| 272 | */ |
|---|
| 273 | public function getRecipientEmail() { |
|---|
| 274 | return $this->_toEmail; |
|---|
| 275 | } |
|---|
| 276 | |
|---|
| 277 | /** |
|---|
| 278 | * Sets address of recipient of email |
|---|
| 279 | * |
|---|
| 280 | * @param string $mail Address of recipient of email |
|---|
| 281 | * |
|---|
| 282 | * @return void |
|---|
| 283 | * |
|---|
| 284 | * @access public |
|---|
| 285 | */ |
|---|
| 286 | public function setRecipientEmail($mail) { |
|---|
| 287 | $this->_toEmail = $mail; |
|---|
| 288 | } |
|---|
| 289 | |
|---|
| 290 | /** |
|---|
| 291 | * Returns subject of email |
|---|
| 292 | * |
|---|
| 293 | * @return string Subject of email |
|---|
| 294 | * |
|---|
| 295 | * @access public |
|---|
| 296 | */ |
|---|
| 297 | public function getMessageSubject() { |
|---|
| 298 | return $this->_subject; |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | /** |
|---|
| 302 | * Sets subject of email |
|---|
| 303 | * |
|---|
| 304 | * @param string $subject Subject of email |
|---|
| 305 | * |
|---|
| 306 | * @return void |
|---|
| 307 | * |
|---|
| 308 | * @access public |
|---|
| 309 | */ |
|---|
| 310 | public function setMessageSubject($subject) { |
|---|
| 311 | $this->_subject = $this->_encodeMimeHeader($subject); |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | /** |
|---|
| 315 | * Returns message body of email |
|---|
| 316 | * |
|---|
| 317 | * @return string Message body of email |
|---|
| 318 | * |
|---|
| 319 | * @access public |
|---|
| 320 | */ |
|---|
| 321 | public function getMessageBody() { |
|---|
| 322 | return $this->_body; |
|---|
| 323 | } |
|---|
| 324 | |
|---|
| 325 | /** |
|---|
| 326 | * Sets message body of email |
|---|
| 327 | * |
|---|
| 328 | * @param string $body Message body of email |
|---|
| 329 | * |
|---|
| 330 | * @return void |
|---|
| 331 | * |
|---|
| 332 | * @access public |
|---|
| 333 | */ |
|---|
| 334 | public function setMessageBody($body) { |
|---|
| 335 | $this->_body = $body; |
|---|
| 336 | } |
|---|
| 337 | |
|---|
| 338 | /** |
|---|
| 339 | * Returns the priority of the email |
|---|
| 340 | * |
|---|
| 341 | * @return boolean Whether high priority or not |
|---|
| 342 | * |
|---|
| 343 | * @access public |
|---|
| 344 | */ |
|---|
| 345 | public function getHighPriority() { |
|---|
| 346 | return $this->_highPriority; |
|---|
| 347 | } |
|---|
| 348 | |
|---|
| 349 | /** |
|---|
| 350 | * Sets the priority of the email |
|---|
| 351 | * |
|---|
| 352 | * @param boolean $boolean Whether high priority or not |
|---|
| 353 | * |
|---|
| 354 | * @return void |
|---|
| 355 | * |
|---|
| 356 | * @access public |
|---|
| 357 | */ |
|---|
| 358 | public function setHighPriority($boolean) { |
|---|
| 359 | $this->_highPriority = $boolean ? true : false; |
|---|
| 360 | } |
|---|
| 361 | |
|---|
| 362 | /** |
|---|
| 363 | * Packs email and sends it according to RFC822 |
|---|
| 364 | * |
|---|
| 365 | * @return bool True if email could be sent |
|---|
| 366 | * |
|---|
| 367 | * @access public |
|---|
| 368 | */ |
|---|
| 369 | public function send() { |
|---|
| 370 | $dir = new DirectoryIterator('lib'); |
|---|
| 371 | foreach ($dir as $fileinfo) { |
|---|
| 372 | if ($fileinfo->isDir() && (substr($fileinfo->getFilename(), 0, 9) == 'PHPMailer')) { |
|---|
| 373 | $phpmailerPath = 'lib/' . $fileinfo->getFilename() . '/'; |
|---|
| 374 | } |
|---|
| 375 | } |
|---|
| 376 | require_once ($phpmailerPath.'class.phpmailer.php'); |
|---|
| 377 | require_once ($phpmailerPath.'class.smtp.php'); |
|---|
| 378 | require_once ('classes/Session.php'); |
|---|
| 379 | $mail = new PHPMailer(); |
|---|
| 380 | $session = Session::getObject(); |
|---|
| 381 | $lang = substr ($session->get(SESS_LANGUAGE_VAR),0,2); |
|---|
| 382 | $mail->SetLanguage($lang, $phpmailerPath.'language/'); |
|---|
| 383 | $mail->CharSet = "utf-8"; |
|---|
| 384 | # $mail->SMTPDebug=TRUE; |
|---|
| 385 | |
|---|
| 386 | $mail->Mailer = EMAIL_MAILER; |
|---|
| 387 | if (EMAIL_MAILER == 'smtp') { |
|---|
| 388 | $mail->IsSMTP(); |
|---|
| 389 | $mail->Host = EMAIL_HOST; |
|---|
| 390 | $mail->SMTPAuth = EMAIL_AUTH; |
|---|
| 391 | |
|---|
| 392 | if (EMAIL_AUTH) { |
|---|
| 393 | $mail->Username = EMAIL_USERNAME; |
|---|
| 394 | $mail->Password = EMAIL_PASSWORD; |
|---|
| 395 | } |
|---|
| 396 | } |
|---|
| 397 | |
|---|
| 398 | $mail->AddAddress($this->getRecipientEmail(), $this->getRecipientName()); |
|---|
| 399 | $mail->From = $this->getSenderEmail(); |
|---|
| 400 | $mail->FromName = $this->getSenderName(); |
|---|
| 401 | $mail->Sender = $this->getSenderEmail(); // add Sender Name |
|---|
| 402 | if ($this->getHighPriority()) { |
|---|
| 403 | $mail->Priority = 1; |
|---|
| 404 | } |
|---|
| 405 | $mail->Subject = $this->getMessageSubject(); |
|---|
| 406 | $mail->Body = $this->getMessageBody(); |
|---|
| 407 | |
|---|
| 408 | $result = $mail->Send(); |
|---|
| 409 | if (!$result) { |
|---|
| 410 | throw new exception(sprintf(_("PHPMailer couldn't sent mail. Error was: %s"),$mail->ErrorInfo)); |
|---|
| 411 | } |
|---|
| 412 | return $result; |
|---|
| 413 | } |
|---|
| 414 | |
|---|
| 415 | /** |
|---|
| 416 | * Validates an email address |
|---|
| 417 | * |
|---|
| 418 | * This function will make sure an e-mail is RFC2822 compliant |
|---|
| 419 | * and is not black listed. |
|---|
| 420 | * |
|---|
| 421 | * The regex was taken from http://www.regular-expressions.info/email.html |
|---|
| 422 | * Read also http://www.linuxjournal.com/article/9585 for more on email validation |
|---|
| 423 | * |
|---|
| 424 | * @param string $mail The email address to validate |
|---|
| 425 | * |
|---|
| 426 | * @return bool Returns whether the email address is valid or not |
|---|
| 427 | * |
|---|
| 428 | * @static |
|---|
| 429 | * @access public |
|---|
| 430 | */ |
|---|
| 431 | public static function validateEmailAddress($email) { |
|---|
| 432 | // Init values |
|---|
| 433 | $_matches = null; |
|---|
| 434 | $_retVal = false; |
|---|
| 435 | |
|---|
| 436 | // Test if the email address is valid |
|---|
| 437 | // $regex = "/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i"; |
|---|
| 438 | // The full regex is |
|---|
| 439 | // /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i |
|---|
| 440 | // We will check it in two parts: domain and local |
|---|
| 441 | |
|---|
| 442 | $atIndex = strrpos($email, "@"); |
|---|
| 443 | if ($atIndex !== false) |
|---|
| 444 | { |
|---|
| 445 | $domain = substr($email, $atIndex+1); |
|---|
| 446 | $local = substr($email, 0, $atIndex); |
|---|
| 447 | |
|---|
| 448 | // Verify local part |
|---|
| 449 | if (preg_match("/^[a-z0-9!#$%&'*+\\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\\/=?^_`{|}~-]+)*$/i",$local) && |
|---|
| 450 | preg_match("/^(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i",$domain) ) |
|---|
| 451 | { |
|---|
| 452 | |
|---|
| 453 | if (!in_array(strtolower($domain), self :: $_hosts_black_list)) { |
|---|
| 454 | if (checkdnsrr($domain,"MX") || checkdnsrr($domain,"A")) { |
|---|
| 455 | $_retVal = true; |
|---|
| 456 | } |
|---|
| 457 | } |
|---|
| 458 | } |
|---|
| 459 | } |
|---|
| 460 | |
|---|
| 461 | return $_retVal; |
|---|
| 462 | } |
|---|
| 463 | |
|---|
| 464 | } |
|---|
| 465 | |
|---|
| 466 | /* |
|---|
| 467 | * Local variables: |
|---|
| 468 | * tab-width: 4 |
|---|
| 469 | * c-basic-offset: 4 |
|---|
| 470 | * c-hanging-comment-ender-p: nil |
|---|
| 471 | * End: |
|---|
| 472 | */ |
|---|