diff --git a/lib/ildus/server/account_backends/htaccess.rb b/lib/ildus/server/account_backends/htaccess.rb deleted file mode 100644 index 2c40310..0000000 --- a/lib/ildus/server/account_backends/htaccess.rb +++ /dev/null @@ -1,17 +0,0 @@ -# = ildus/server/account_backends/htaccess - account backend library for .htacces files -# -# Copyright (C) 2005 Paul van Tilburg -# -# 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 diff --git a/lib/ildus/server/account_backends/yaml.rb b/lib/ildus/server/account_backends/yaml.rb new file mode 100644 index 0000000..5bf3b91 --- /dev/null +++ b/lib/ildus/server/account_backends/yaml.rb @@ -0,0 +1,65 @@ +# = ildus/server/account_backends/yaml - account backend library for YAML files +# +# Copyright (C) 2005 Paul van Tilburg +# +# 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