[Xfce4-commits] <moka:nick/maintainer-improvements> Log failed logins.

Nick Schermer noreply at xfce.org
Sat Oct 15 13:12:01 CEST 2011


Updating branch refs/heads/nick/maintainer-improvements
         to f6600ffafb815f6a9bef1334ddfda95e9d38c385 (commit)
       from 5ec3702e83166004c11020552e0ff0d295be584c (commit)

commit f6600ffafb815f6a9bef1334ddfda95e9d38c385
Author: Nick Schermer <nick at xfce.org>
Date:   Sat Oct 15 13:09:48 2011 +0200

    Log failed logins.

 examples/xfce/config.ru           |    3 +--
 lib/controllers/authentication.rb |   11 ++++++++---
 lib/moka.rb                       |    4 ----
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/examples/xfce/config.ru b/examples/xfce/config.ru
index 0115ffa..ae22e5f 100755
--- a/examples/xfce/config.ru
+++ b/examples/xfce/config.ru
@@ -4,14 +4,13 @@ require 'rubygems'
 require 'dm-core'
 require 'dm-migrations'
 require 'digest/sha1'
-
 require '../../lib/moka'
 
 # Connect to the database
 directory = File.expand_path(File.dirname(__FILE__))
 db = File.join(directory, 'example.db')
 
-DataMapper::Logger.new($stdout, :debug)
+#DataMapper::Logger.new($stdout, :debug)
 DataMapper.setup(:default, 'sqlite://' + db)
 
 # From http://blog.macromates.com/2006/wrapping-text-with-regular-expressions/
diff --git a/lib/controllers/authentication.rb b/lib/controllers/authentication.rb
index 5da50da..756f6d1 100755
--- a/lib/controllers/authentication.rb
+++ b/lib/controllers/authentication.rb
@@ -1,9 +1,8 @@
 require 'rubygems'
-require 'pp'
-
-#gem 'warden', '0.2.3'
+require 'logger'
 require 'warden'
 require 'pony'
+require 'time'
 
 module Moka
   module Controllers
@@ -124,6 +123,12 @@ module Moka
         end
 
         app.post '/unauthenticated' do
+          # report the failed login, so we can use fail2ban on the server
+          logger = Logger.new('auth.log')
+          logger.datetime_format = "%Y-%m-%d %H:%M:%S"
+          logger.warn "Authentication failure for #{request.env['REMOTE_ADDR']}"
+          logger.close
+
           view :login_unauthenticated
         end
 
diff --git a/lib/moka.rb b/lib/moka.rb
index 0291ce8..a569e8c 100755
--- a/lib/moka.rb
+++ b/lib/moka.rb
@@ -1,9 +1,5 @@
 require 'rubygems'
-
-# gem 'sinatra', '0.9.2'
 require 'sinatra'
-
-# gem 'haml', '2.2.1'
 require 'sass'
 
 directory = File.expand_path(File.dirname(__FILE__))


More information about the Xfce4-commits mailing list