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
|
@config = nil
|
||||||
parse_config(config_file)
|
parse_config(config_file)
|
||||||
|
|
||||||
|
Backend.load
|
||||||
|
|
||||||
super(config['port'], DEFAULT_HOST, 20, $stderr, true, false)
|
super(config['port'], DEFAULT_HOST, 20, $stderr, true, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -63,8 +65,12 @@ module Ildus
|
||||||
raise ArgumentError unless FileTest.exists? filename
|
raise ArgumentError unless FileTest.exists? filename
|
||||||
|
|
||||||
File.open(filename, "r") do |io|
|
File.open(filename, "r") do |io|
|
||||||
|
# FIXME: merge the YAML with a default config
|
||||||
@config = YAML.load(io)
|
@config = YAML.load(io)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# FIXME: test config for existance of certain fields:
|
||||||
|
# port, passwd, backend, backend/type
|
||||||
end
|
end
|
||||||
|
|
||||||
end # class Server
|
end # class Server
|
||||||
|
|
|
@ -38,7 +38,7 @@ module Ildus
|
||||||
raise Handler::AlreadyAuthError if @auth
|
raise Handler::AlreadyAuthError if @auth
|
||||||
@pass = password
|
@pass = password
|
||||||
## STUB
|
## STUB
|
||||||
@auth = rand(2).zero?
|
@auth = (password == "foo")
|
||||||
##
|
##
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -12,35 +12,66 @@ require 'singleton'
|
||||||
module Ildus
|
module Ildus
|
||||||
|
|
||||||
class Server
|
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
|
class Basic
|
||||||
include Singleton
|
|
||||||
|
|
||||||
def hostnames_of(user)
|
def self.inherited(subclass)
|
||||||
raise Handler::NotImplementedError
|
type = subclass.to_s.split('::').last.downcase.to_sym
|
||||||
end
|
Backend.register(type, subclass)
|
||||||
|
end
|
||||||
|
|
||||||
def add_hostname(user)
|
def hostnames_of(user)
|
||||||
raise Handler::NotImplementedError
|
raise Handler::NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_hostname(user)
|
def add_hostname(user)
|
||||||
raise Handler::NotImplementedError
|
raise Handler::NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_hostname(user, host, addr)
|
def remove_hostname(user)
|
||||||
raise Handler::NotImplementedError
|
raise Handler::NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_alias(user, new_alias, host)
|
def update_hostname(user, host, addr)
|
||||||
raise Handler::NotImplementedError
|
raise Handler::NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_alias(user, old_alias, host)
|
def add_alias(user, new_alias, host)
|
||||||
raise Handler::NotImplementedError
|
raise Handler::NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
||||||
end # class Backend
|
def remove_alias(user, old_alias, host)
|
||||||
|
raise Handler::NotImplementedError
|
||||||
|
end
|
||||||
|
|
||||||
|
end # class Basic
|
||||||
|
|
||||||
|
end # module Backend
|
||||||
|
|
||||||
end # class Server
|
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
|
@server = server
|
||||||
@io = io
|
@io = io
|
||||||
@account = Account.new
|
@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
|
end
|
||||||
|
|
||||||
def handle_client
|
def handle_client
|
||||||
|
|
Reference in New Issue