Added a YAML account backend, removed the not in forseeable future working htaccess backend.
git-svn-id: svn+ssh://svn.luon.net/svn/ildus/trunk@13 65a33f86-aa00-0410-91be-cd1bf5efb309
This commit is contained in:
parent
50ccb02e2f
commit
37536b1fac
|
@ -1,17 +0,0 @@
|
||||||
# = ildus/server/account_backends/htaccess - account backend library for .htacces files
|
|
||||||
#
|
|
||||||
# Copyright (C) 2005 Paul van Tilburg <paul@luon.net>
|
|
||||||
#
|
|
||||||
# Ildus is free software; you can redistribute it and/or modify it under
|
|
||||||
# the terms of the GNU General Public License as published by the Free
|
|
||||||
# Software Foundation; either version 2 of the License, or (at your option)
|
|
||||||
# any later version.
|
|
||||||
|
|
||||||
module Ildus::Server::AccountBackend
|
|
||||||
|
|
||||||
# = Account backend class for Apache's htaccess files.
|
|
||||||
class Htaccess < Basic
|
|
||||||
|
|
||||||
end # class Htaccess
|
|
||||||
|
|
||||||
end # module Ildus::Server::AccountBackend
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
# = ildus/server/account_backends/yaml - account backend library for YAML files
|
||||||
|
#
|
||||||
|
# Copyright (C) 2005 Paul van Tilburg <paul@luon.net>
|
||||||
|
#
|
||||||
|
# Ildus is free software; you can redistribute it and/or modify it under
|
||||||
|
# the terms of the GNU General Public License as published by the Free
|
||||||
|
# Software Foundation; either version 2 of the License, or (at your option)
|
||||||
|
# any later version.
|
||||||
|
|
||||||
|
module Ildus::Server::AccountBackend
|
||||||
|
|
||||||
|
# = Account backend class for Apache's htaccess files.
|
||||||
|
class Yaml < Basic
|
||||||
|
|
||||||
|
def initialize(*args)
|
||||||
|
super
|
||||||
|
@db = nil
|
||||||
|
load_db
|
||||||
|
end
|
||||||
|
|
||||||
|
def authenticate
|
||||||
|
case config['crypt'].to_sym
|
||||||
|
when :unix
|
||||||
|
regged_pass = @db[user]
|
||||||
|
self.auth = (pass.crypt(regged_pass) == regged_pass)
|
||||||
|
else
|
||||||
|
raise "unsupported crypt type: #{config['crypt']}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def register_account(user, pass)
|
||||||
|
raise "user already exists" if @db.has_key? user
|
||||||
|
raise "password to short" if pass.length < 5
|
||||||
|
salt = pass[-2..-1].succ.succ
|
||||||
|
@db[user] = pass.crypt(salt)
|
||||||
|
save_db
|
||||||
|
end
|
||||||
|
|
||||||
|
def unregister_account(user)
|
||||||
|
raise "user does not exist" unless @db.has_k
|
||||||
|
@db.delete user
|
||||||
|
save_db
|
||||||
|
end
|
||||||
|
|
||||||
|
########
|
||||||
|
private
|
||||||
|
########
|
||||||
|
|
||||||
|
def load_db
|
||||||
|
db = nil
|
||||||
|
File.open(config['file'], 'r') { |f| db = YAML.load(f) || Hash.new }
|
||||||
|
raise "wrong account database format" unless db.is_a? Hash
|
||||||
|
@db = db
|
||||||
|
end
|
||||||
|
|
||||||
|
def save_db
|
||||||
|
unless FileTest.exists? config['file']
|
||||||
|
raise "account database file does not exist: " + config['file']
|
||||||
|
end
|
||||||
|
File.open(config['file'], 'w') { |f| f.puts @db.to_yaml }
|
||||||
|
end
|
||||||
|
|
||||||
|
end # class Yaml
|
||||||
|
|
||||||
|
end # module Ildus::Server::AccountBackend
|
Reference in New Issue