# = ildus/server/backend - generic server backend library # # 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. require 'singleton' module Ildus class Server # = Backend access module # # Module that is able to load and retrieve account or # backend classes & code. module Backend # Load the plugin for account backend _name_ and return the class # that can be instantiated. def self.get_account(name) get("account", AccountBackend, name) end # Load the plugin for domain backend _name_ and return the class # that can be instantiated. def self.get_domain(name) get("domain", DomainBackend, name) end # Method that does the actual loading and class retrieving. def self.get(type, mod, name) name = name.to_s path = File.dirname(__FILE__) file = File.join(path, "#{type}_backends", name + ".rb") require file return mod.const_get(name.capitalize) rescue NameError, LoadError nil end end # module Backend # = Account administration backend module # # This module contains all account backends that are used for managing # Ildus accounts in some database. All classes inherit from Basic, # which defines the basic interface. # # For the interface of each class in the AccountBackend, see the Basic # class. module AccountBackend # = Basic account backend # # Class defining the basic interface of an account backend class. # All account backend classes should inherit from this class. # # All methods marked with (*Interface*) raise Handler::NotImplementedError # and should be overriden by a class implementing the interface. class Basic # Configuration for the backend (Hash). attr_reader :config # The currently selected user. attr_reader :user # The currently selected password. attr_reader :pass # Boolean determining the authentication status. attr_writer :auth # Creates a new account backend object, the current *user* # and *password* are undefined by default. def initialize(backend_config) @config = backend_config @user = nil @pass = nil @auth = false end # Sets the _username_. def user=(username) @user = username end # Sets the _password_ and tries to set/review the authentication # status via the interface (using #authenticate()). def pass=(password) @pass = password authenticate end # Determines whether the backend considers the currently selected # user with the currently selected password as authenticated. def authenticated? @auth end ################# # Backend methods # (*Interface*) Considers the currently selected _user_ and # _password_ and uses #auth= to set whether the user is # authenticated or not. def authenticate raise Handler::NotImplementedError end # (*Interface*) Registers a new account _user_ with password # _pass_ in the database. def register_account(user, pass) raise Handler::NotImplementedError end # (*Interface*) Removes the account of _user_ from the database. def unregister_account(user) raise Handler::NotImplementedError end end # class Basic end # module AccountBackend # = Domain administration backend module # # This module contains all domain backends that are used for managing # Ildus domain records in some database. All classes inherit from # Basic, which defines the basic interface. # # For the interface of each class in the DomainBackend, see the Basic # class. module DomainBackend # = Basic domain backend # # Class defining the basic interface of a domain backend class. # All domain backend classes should inherit from this class. # # All methods marked with (*Interface*) raise Handler::NotImplementedError # and should be overriden by a class implementing the interface. class Basic # Configuration for the backend (Hash). attr_accessor :config # The currently selected user. attr_accessor :user # Creates a new backend object with the configuration # _backend_config_. The current *user* is left undefined. def initialize(backend_config) @config = backend_config @user = nil end # Method called when all actions are done and the data should be # committed to the database (if not done real-time already before). # # This method can be override, but should also call +super+, since # this methods runs the optional hook. def commit system "#{@config['hook']}" if @config['hook'] end ################# # Backend methods # (*Interface*) Returns a datastructure containing # the list of hosts owned by the selected user. def hosts # FIXME: format constraints. raise Handler::NotImplementedError end # (*Interface*) Adds the given _host_ to the list # of owned hosts by the selected user. def add_host(host) raise Handler::NotImplementedError end # (*Interface*) Removes the given _host_ from the # list of owned hosts by the selected user. def remove_host(host) raise Handler::NotImplementedError end # (*Interface*) Updates the address of the given # _host_ to the give address _addr_. # If _addr_ is *nil*, the entry should be removed. def update_host(host, addr) raise Handler::NotImplementedError end # (*Interface*) Adds the alias _new_alias_ to the # given _host_. def add_alias(new_alias, host) raise Handler::NotImplementedError end # (*Interface*) Removes the alias _old_alias_ from # the given _host_. def remove_alias(old_alias, host) raise Handler::NotImplementedError end end # class Basic end # module DomainBackend end # class Server end # module Ildus