Roundcube Community Forum

News and Announcements => General Discussion => Topic started by: mattfox27 on October 11, 2010, 10:37:56 PM

Title: AntiBruteForce plugin just a little help with styling in php
Post by: mattfox27 on October 11, 2010, 10:37:56 PM
I have setup this antibriteforce plugin but the language is not in english i was able to go into the php code and customize the message shown when login fails but it has a countdown until you can login again i can't figure out how to center it.  Below is an example of what i want to do and then the code...Any help would be greatly appreciated.

(http://www.roundcubeforum.net/attachment.php?attachmentid=1444&stc=1&d=1286850990)

Here is the php code...i cant find where to center the countdown.

<?php
/**
* RoundCube antiBruteForce
*
* @version 1.0
* @author Anderson J. de Souza
* @url http://anderjs.blogspot.com
*/
class antiBruteForce extends rcube_plugin
{

   private
$registers=logs/userlogins&quot;; // arquivo de registro de tentativas
   
private $attempts=5; // o numero de tentativas antes de bloquear o acesso;
   
private $registeredAttemptsInTime=0; // variavel que mantem o numero de tentativas registradas dentro do tempo determinado
   
private $time=600; // tempo entre tentativas
   
private $blockedTime=null; // mantem o tempo restante de bloqueio em segundos
   
private $message=&quot;<center><b>Access Blocked-Too Many Failed Login Attempts</b></center><center>Time Remaning</center>&quot;; // mensagem de erro de bloqueio

 
function init()
 {
   
$this->add_hook('startup', array($this, 'clearAuth'));
   
$this->add_hook('template_object_loginform', array($this, 'blockMessage'));
   
$this->add_hook('login_failed', array($this, 'logFail'));
 }

 function
blocked() {
   
// vaz contabilizacao caso nao haja bloqueio definido
   
if ($this->blockedTime === null )
   
$this->checkFails();
   return
$this->blockedTime;
 }

 function
clearAuth($args) {
   if (
$this->blocked()) {
     
$args['task']='login';
     
$args['action']='';
    }
   return
$args;
 }

 function
getTrackIP(){
   
$trackIP = getenv('REMOTE_ADDR');
    if (
getenv('HTTP_X_FORWARDED_FOR'))
       
$trackIP.=','.getenv('HTTP_X_FORWARDED_FOR');
    return
$trackIP;
 }

 function
checkFails() {
     
$track=$this->getTrackIP(); // caminho utilizado do acesso ip e ips de proxys
     
$time=$this->time; // tempo entre tentativas
     
$attempts=0; // registra o numero de tentativas dentro do tempo definido
     
$now=time(); // tempo de agora para calculos
     
$wait=0; // tempo entre as tentativas, mantem o time da ultima tentativa invalida

     // le arquivo contabilizando as falhas de login dentro do tempo determinado
     
if (is_file($this->registers) && $fp=fopen($this->registers,'r')){
     while (
$line=fgets($fp) ) {
         if (
substr($line,0,strlen($track.&quot;:&quot;)) == $track.&quot;:&quot; ) {
             if ( (
$wait = $now - substr($line,strlen($track.&quot;:&quot;),10)) < $time )
               
$attempts++;
         }
     }
     
fclose($fp);
     }

   
// guarda valores para pesquisas futuras.
   
if ($attempts >= $this->attempts) $this->blockedTime = ($time - $wait);
   
$this->registeredAttemptsInTime = $attempts;
   return
$attempts;
 }

 function
blockMessage($args) {
     if (
$this->blocked())
         
$args['content']=$this->message.$this->blocked();
     return
$args;
 }


 function
logFail($args)
 {
   if (
$this->blocked()) return; // caso ja esteja bloqueado nao precisa registrar

   
$log_entry = 'FAILED login for ' .$args['user']. ' from ' .getenv('REMOTE_ADDR');
   
$log_config = rcmail::get_instance()->config->get('log_driver');
   
   
error_log($this->getTrackIP().':'.time().':'.$args['user'].&quot;:[&quot;.date('d-M-Y H:i:s O').]:$log_entry:&quot;.&quot;\n&quot;, 3, $this->registers);
 }

}

?>