Class: Autumn::Authentication::Hostname

Inherits:
Base
  • Object
show all
Defined in:
lib/autumn/authentication.rb

Overview

Authenticates by the host portion of an IRC message. A hostmask is used to match the relevant portion of the address with a whitelist of accepted host addresses.

This method can be a secure way of preventing unauthorized access if you choose an appropriately narrow hostmask. However, you must configure in advance the computers you may want to administrate your leaves from.

Instance Method Summary collapse

Methods inherited from Base

#unauthorized

Constructor Details

#initialize(options = {}) ⇒ Hostname

Creates a new authenticator. You provide a hostmask via the hostmask option – either a Regexp with one capture (that captures the portion of the hostmask you are interested in), or a Proc, which takes a host as an argument and returns true if the host is authorized, false if not. If the hostmask option is not provided, a standard hostmask regexp will be used. This regexp strips everything left of the first period; for the example hostmask “wsd1.ca.widgetcom.net”, it would return “ca.widgetcom.net” to be used for comparison.

You also provide an authorized host with the host option, or a list of such hosts with the hosts option. If neither is given, an exception is raised.



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/autumn/authentication.rb', line 139

def initialize(options={})
  @hostmask = options[:hostmask]
  @hostmask ||= /^.+?\.(.+)$/
  @hostmask = @hostmask.to_rx(false) if @hostmask.kind_of? String
  if @hostmask.kind_of? Regexp then
    mask = @hostmask
    @hostmask = lambda do |host|
      if matches = host.match(mask) then matches[1] else nil end
    end
  end
          
  @hosts = options[:host]
  @hosts ||= options[:hosts]
  raise "You must give the host address of an administrator to use nick-based authentication." unless @hosts
  @hosts = [ @hosts ] unless @hosts.kind_of? Array
end

Instance Method Details

#authenticate(stem, channel, sender, leaf) ⇒ Object

:nodoc:



156
157
158
# File 'lib/autumn/authentication.rb', line 156

def authenticate(stem, channel, sender, leaf) # :nodoc:
  @hosts.include? @hostmask.call(sender[:host])
end