From ea6a33f237368e31aba6ec547d83d890f4460443 Mon Sep 17 00:00:00 2001 From: Steve Allison Date: Wed, 20 Feb 2013 21:49:54 +0000 Subject: [PATCH] First attempt at login_failed hook --- defense.php | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/defense.php b/defense.php index 3e40f4e..7463822 100644 --- a/defense.php +++ b/defense.php @@ -71,13 +71,15 @@ class defense extends rcube_plugin { $this->load_config(); // set config variables, set defaults + $this->db_table = $this->rc->config->get('defense_db_table', 'defense'); + $this->fail_max = $this->rc->config->get('defense_fail_max', 5); $this->fail_reset = $this->rc->config->get('defense_fail_reset', 600); $this->ban_period = $this->rc->config->get('defense_ban_period', 120); $this->ban_httpstatus = $this->rc->config->get('defense_ban_httpstatus', false); $this->repeat_multiplier = $this->rc->config->get('defense_repeat_multiplier', 4); $this->repeat_reset = $this->rc->config->get('defense_repeat_reset', 86400); - $this->db_table = $this->rc->config->get('defense_db_table', 'defense'); + $this->db_expire = $this->rc->config->get('defense_db_expire', 40); $this->log_pwd = $this->rc->config->get('defense_log_pwd', false); @@ -86,11 +88,12 @@ class defense extends rcube_plugin { // Roundcube event hooks $this->add_hook('template_object_loginform', array($this, 'hookLoginForm')); - $this->add_hook('authenticate', array($this, 'authenticate')); - $this->add_hook('login_failed', array($this, 'login_failed')); + $this->add_hook('authenticate', array($this, 'hookAuthenticate')); + $this->add_hook('login_failed', array($this, 'hookLoginFailed')); } /** + * Hooked function: login_form($content) * Process whitelist and blacklist * * @param string Login form HTML @@ -113,6 +116,31 @@ class defense extends rcube_plugin { die(); } } + + /** + * Hooked function: authenticate($host, $user, $cookiecheck, $valid) + * Login attempt intercepted if IP is banned. + * + * @param var (untouched) + * @return var (untouched) + */ + public function hookAuthenticate($args) { + return $args + } + + /** + * Hooked function: login_failed($host, $user, $code) + * Log event to database + * + * @param string host + * @param string user + * @param int code + * + */ + public function hookLoginFailed($host, $user, $code) { + $query = "INSERT INTO " . $this->db_table . " (timestamp, type, src, data) VALUES (" . time() . ", 'fail', " . ip2long($this->ipaddr) . ", 'data')"; + print $query; + } }