From 187941aac6e668418cffd8f2d50ad0b0a751ef4b Mon Sep 17 00:00:00 2001
From: Garvin Hicking <mail@garv.in>
Date: Tue, 31 May 2011 14:02:02 +0000
Subject: [PATCH]     * Added new event hook 'backend_loginfail' to track
 failed logins       (serendipity_event_externalauth can make use of it for
 fail2ban)

---
 docs/NEWS                        | 3 +++
 include/functions_config.inc.php | 7 +++++++
 2 files changed, 10 insertions(+)

diff --git a/docs/NEWS b/docs/NEWS
index d9c9934b..e84cbb90 100644
--- a/docs/NEWS
+++ b/docs/NEWS
@@ -3,6 +3,9 @@
 Version 1.6 ()
 ------------------------------------------------------------------------
 
+    * Added new event hook 'backend_loginfail' to track failed logins
+      (serendipity_event_externalauth can make use of it for fail2ban)
+      
     * Fixed a bug in synchronizing new files with the same basename
       but different extensions, where files with the same mimetype
       would not get added (garvinhicking)
diff --git a/include/functions_config.inc.php b/include/functions_config.inc.php
index dc5c0625..7148c79b 100644
--- a/include/functions_config.inc.php
+++ b/include/functions_config.inc.php
@@ -384,6 +384,7 @@ function serendipity_login($use_external = true) {
         if (empty($serendipity['POST']['auto'])) {
             serendipity_deleteCookie('author_information');
             serendipity_deleteCookie('author_information_iv');
+            
             return false;
         } else {
             serendipity_issueAutologin(
@@ -397,6 +398,9 @@ function serendipity_login($use_external = true) {
     } elseif (isset($serendipity['COOKIE']['author_information'])) {
         $cookie = serendipity_checkAutologin($serendipity['COOKIE']['author_information'], $serendipity['COOKIE']['author_information_iv']);
 
+        $data = array('ext' => $use_external, 'mode' => 1, 'user' => $cookie['username'], 'pass' => $cookie['password']);
+        serendipity_plugin_api::hook_event('backend_loginfail', $data);
+
         if (is_array($cookie) && serendipity_authenticate_author($cookie['username'], $cookie['password'], false, $use_external)) {
             return true;
         } else {
@@ -405,6 +409,9 @@ function serendipity_login($use_external = true) {
             return false;
         }
     }
+    
+    $data = array('ext' => $use_external, 'mode' => 2, 'user' => $serendipity['POST']['user'], 'pass' => $serendipity['POST']['pass']);
+    serendipity_plugin_api::hook_event('backend_loginfail', $data);
 }
 
 /**