Added multiple backend/plugin support:
* Transformed Server::Handler::Backend to Server::Handler::Backend::Basic. * Inheritance from this class will result in registering of the class for that type. * Written Server::Handler::Backend module for loading and getting backends. * Provided empty LDAP backend class. * Changed auth stub to not use rand() but to check whether the password is "foo". git-svn-id: svn+ssh://svn.luon.net/svn/ildus/trunk@5 65a33f86-aa00-0410-91be-cd1bf5efb309
This commit is contained in:
parent
55bf169b2c
commit
1254787d03
|
@ -29,6 +29,8 @@ module Ildus
|
|||
@config = nil
|
||||
parse_config(config_file)
|
||||
|
||||
Backend.load
|
||||
|
||||
super(config['port'], DEFAULT_HOST, 20, $stderr, true, false)
|
||||
end
|
||||
|
||||
|
@ -63,8 +65,12 @@ module Ildus
|
|||
raise ArgumentError unless FileTest.exists? filename
|
||||
|
||||
File.open(filename, "r") do |io|
|
||||
# FIXME: merge the YAML with a default config
|
||||
@config = YAML.load(io)
|
||||
end
|
||||
|
||||
# FIXME: test config for existance of certain fields:
|
||||
# port, passwd, backend, backend/type
|
||||
end
|
||||
|
||||
end # class Server
|
||||
|
|
|
@ -38,7 +38,7 @@ module Ildus
|
|||
raise Handler::AlreadyAuthError if @auth
|
||||
@pass = password
|
||||
## STUB
|
||||
@auth = rand(2).zero?
|
||||
@auth = (password == "foo")
|
||||
##
|
||||
end
|
||||
|
||||
|
|
|
@ -12,35 +12,66 @@ require 'singleton'
|
|||
module Ildus
|
||||
|
||||
class Server
|
||||
|
||||
module Backend
|
||||
|
||||
BackendClasses = Hash.new
|
||||
|
||||
class << self
|
||||
|
||||
def load
|
||||
path = File.dirname(__FILE__)
|
||||
Dir["#{path}/backends/**/*.rb"].each { |file| require file }
|
||||
end
|
||||
|
||||
def get(type)
|
||||
BackendClasses[type.to_sym]
|
||||
end
|
||||
alias_method :[], :get
|
||||
|
||||
def register(type, backend_class)
|
||||
if BackendClasses.include? type
|
||||
raise "type #{type} already registered"
|
||||
end
|
||||
BackendClasses[type] = backend_class
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Backend
|
||||
include Singleton
|
||||
class Basic
|
||||
|
||||
def hostnames_of(user)
|
||||
raise Handler::NotImplementedError
|
||||
end
|
||||
def self.inherited(subclass)
|
||||
type = subclass.to_s.split('::').last.downcase.to_sym
|
||||
Backend.register(type, subclass)
|
||||
end
|
||||
|
||||
def add_hostname(user)
|
||||
raise Handler::NotImplementedError
|
||||
end
|
||||
def hostnames_of(user)
|
||||
raise Handler::NotImplementedError
|
||||
end
|
||||
|
||||
def remove_hostname(user)
|
||||
raise Handler::NotImplementedError
|
||||
end
|
||||
def add_hostname(user)
|
||||
raise Handler::NotImplementedError
|
||||
end
|
||||
|
||||
def update_hostname(user, host, addr)
|
||||
raise Handler::NotImplementedError
|
||||
end
|
||||
def remove_hostname(user)
|
||||
raise Handler::NotImplementedError
|
||||
end
|
||||
|
||||
def add_alias(user, new_alias, host)
|
||||
raise Handler::NotImplementedError
|
||||
end
|
||||
def update_hostname(user, host, addr)
|
||||
raise Handler::NotImplementedError
|
||||
end
|
||||
|
||||
def remove_alias(user, old_alias, host)
|
||||
raise Handler::NotImplementedError
|
||||
end
|
||||
def add_alias(user, new_alias, host)
|
||||
raise Handler::NotImplementedError
|
||||
end
|
||||
|
||||
end # class Backend
|
||||
def remove_alias(user, old_alias, host)
|
||||
raise Handler::NotImplementedError
|
||||
end
|
||||
|
||||
end # class Basic
|
||||
|
||||
end # module Backend
|
||||
|
||||
end # class Server
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
# = ildus/server/backend - generic server backend library
|
||||
#
|
||||
# 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::Backend
|
||||
|
||||
class LDAP < Basic
|
||||
end
|
||||
|
||||
end
|
|
@ -61,7 +61,10 @@ module Ildus
|
|||
@server = server
|
||||
@io = io
|
||||
@account = Account.new
|
||||
@backend = Backend.instance
|
||||
type = server.config["backend"]["type"]
|
||||
klass = Backend[server.config["backend"]["type"]]
|
||||
raise "backend type `#{type}' not found" if klass.nil?
|
||||
@backend = klass.new
|
||||
end
|
||||
|
||||
def handle_client
|
||||
|
|
Reference in New Issue