Changeset 37

Show
Ignore:
Timestamp:
04/28/08 12:36:26
Author:
nperriault
Message:

Added mail antiflood system

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/apps/main/config/i18n.yml

    r2 r37  
    66  default_culture:     en 
    77  source:              XLIFF 
    8   debug:               on 
     8  debug:               off 
    99  cache:               off 
    1010  untranslated_prefix: "[T]" 
  • trunk/apps/main/config/routing.yml

    r2 r37  
    9898 
    9999# Applications 
     100applications_test: 
     101  url: /applications/test 
     102  param: { module: applications, action: test } 
    100103applications_countries: 
    101104  url:   /applications/countries 
  • trunk/apps/main/lib/myActions.class.php

    r2 r37  
    235235  protected function sendSwiftSmtpPlainMail($module, $action, $to, $subject, $options = array()) 
    236236  { 
     237    try 
     238    { 
     239      $this->checkMailFlood(); 
     240    } 
     241    catch (sfException $e) 
     242    { 
     243      $this->setFlash('warning', $e->getMessage()); 
     244      $this->forward404(sprintf('User "%s" is flooding by mail', $this->getUser()->getGuardUser()->getUsername())); 
     245    } 
     246 
    237247    $conn = new Swift_Connection_SMTP(sfConfig::get('app_mail_hostname')); 
    238248    switch (strtolower(sfConfig::get('app_mail_protocol'))) 
     
    298308    } 
    299309    $mailer->disconnect(); 
     310     
     311    // Add mailSent timestamp 
     312    $this->getUser()->setAttribute('lastMailAt', time()); 
     313     
    300314    return ($sent > 0); 
    301315  } 
     
    338352    return $address; 
    339353  } 
     354   
     355  /** 
     356   * Checks for mail flooding (die, dirty spammers) 
     357   * 
     358   * @return boolean 
     359   * @throws sfException if mail flooding is detected 
     360   */ 
     361  protected function checkMailFlood() 
     362  { 
     363    $user = $this->getUser(); 
     364     
     365    if (!$user) 
     366    { 
     367      throw new sfException($this->__('Mail sending use the session, please allow cookies')); 
     368    } 
     369     
     370    $lastMailAt = $user->getAttribute('lastMailAt', null); 
     371     
     372    if (is_null($lastMailAt)) 
     373    { 
     374      return; 
     375    } 
     376     
     377    $ttl = sfConfig::get('app_mail_mail_flood_time', 300); 
     378     
     379    if (time() - $lastMailAt < $ttl)  
     380    { 
     381      throw new sfException(sprintf($this->__('You must wait at least %d seconds between two mail send, please try again later'), $ttl)); 
     382    } 
     383  } 
    340384 
    341385} 
  • trunk/data/fixtures/data.yml

    r2 r37  
    55    summary:            Father of the Symfony framework 
    66    password:           password 
    7     email:              fabien@symfony-project.com 
     7    email:              nperriault+test1@gmail.com 
    88    trac_username:      fabien 
    99    homepage:           "http://www.symfony-project.com/" 
     
    1919    display_name:       Nicolas Perriault 
    2020    password:           password 
    21     email:              nperriault@gmail.com 
     21    email:              nperriault+test2@gmail.com 
    2222    trac_username:      nicolas 
    2323    homepage:           "http://prendreuncafe.com/blog" 
     
    4242    display_name:       Tristan Rivoallan 
    4343    password:           password 
    44     email:              tristan@rivoallan.net 
     44    email:              nperriault+test3@gmail.com 
    4545    trac_username:      trivoallan 
    4646    country:            FR 
     
    5555    display_name:       François Zaninotto 
    5656    password:           password 
    57     email:              fzaninotto@ma-generation.com 
     57    email:              nperriault+test4@gmail.com 
    5858    trac_username:      francois 
    5959    homepage:           "http://www.mageneration.com/" 
     
    6767    username:           johndoe 
    6868    password:           password 
    69     email:              john@doe.com 
     69    email:              nperriault+test5@gmail.com 
    7070    summary:            "Super newbie" 
    7171    country:            US 
     
    7878    username:           I_shouldnt_appear 
    7979    password:           password 
    80     email:              foo@bar.com 
     80    email:              nperriault+test6@gmail.com 
    8181    country:            UK 
    8282    is_validated:       0