-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Paul Kelly
committed
Oct 6, 2010
1 parent
c4b4755
commit 7443766
Showing
7 changed files
with
86 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module NetdbManager | ||
module ActionControllerExtensions | ||
def self.included(base) #:nodoc: | ||
base.send :include, InstanceMethods | ||
base.class_eval do | ||
alias_method_chain :process, :netdb_support | ||
end | ||
end | ||
|
||
module InstanceMethods | ||
def process_with_netdb_support *args | ||
require_dependency 'netdb_manager/host_ext' | ||
require_dependency 'netdb_manager/user_ext' | ||
require_dependency 'netdb_manager/application_controller_ext' | ||
process_without_netdb_support *args | ||
end | ||
end | ||
end | ||
end | ||
ActionController::Base.send :include, NetdbManager::ActionControllerExtensions |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module NetdbManager | ||
module ApplicationControllerExtensions | ||
NET_TTL = 7200 | ||
|
||
def self.included(base) #:nodoc: | ||
base.send :include, InstanceMethods | ||
base.class_eval do | ||
before_filter :initialise_caches | ||
end | ||
end | ||
|
||
module InstanceMethods | ||
def initialise_caches | ||
return true unless @user | ||
return true if SETTINGS[:unattended] and SETTINGS[:unattended] == false | ||
|
||
@dhcp = Rails.cache.fetch(:dhcp, :expires_in => NET_TTL){ | ||
DHCP::Dhcp.new(session) | ||
}.dup # For some reason the object is frozen in this implementation of the cache! | ||
raise RuntimeException, "Unable to create DHCP memcache storage" unless @dhcp | ||
|
||
@user_cache = Rails.cache.fetch("user_cache", :expires_in => NET_TTL){ | ||
{} | ||
}.dup # For some reason the object is frozen in this implementation of the cache! | ||
raise RuntimeException, "Unable to create password cache storage" unless @pass | ||
|
||
# The DHCP instance needs access to the session as some of its DHCPServer implementations need to know about the user | ||
per_user_data = @user_cache[login] | ||
@dhcp.personalise(per_user_data) | ||
true | ||
end | ||
def save_network_data | ||
return true if RAILS_ENV == "test" | ||
if @dhcp | ||
dhcpServer = @dhcp.serverFor subnet.number | ||
if new_record? | ||
setDHCP dhcpServer | ||
end | ||
else | ||
true # No netdb management unless we use memcache | ||
end | ||
end | ||
end | ||
end | ||
end | ||
ApplicaitonController::Base.send :include, NetdbManager::ApplicationControllerExtensions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,36 @@ | ||
module NetdbManager | ||
module UserExtensions | ||
NET_TTL = 7200 | ||
def self.included(base) #:nodoc: | ||
base.class_eval { alias_method_chain :try_to_login, :networking_support } | ||
base.extend ClassMethods | ||
base.send :include, InstanceMethods | ||
base.class_eval do | ||
class << self | ||
alias_method_chain :try_to_login, :netdb_support | ||
end | ||
end | ||
end | ||
|
||
module InstanceMethods | ||
end | ||
|
||
module ClassMethods | ||
|
||
def try_to_login_with_networking_support(login, password) | ||
if user = try_to_login_without_network_support | ||
User.initialise_network_support | ||
def try_to_login_with_netdb_support(login, password) | ||
if user = self.try_to_login_without_netdb_support(login, password) | ||
User.capture_user_data user | ||
end | ||
user | ||
end | ||
|
||
def initialise_network_cache | ||
return true unless @user | ||
return true if SETTINGS[:unattended] and SETTINGS[:unattended] == false | ||
|
||
@dhcp = Rails.cache.fetch(:dhcp, :expires_in => NET_TTL){ | ||
DHCP::Dhcp.new(session) | ||
}.dup # For some reason the object is frozen in this implementation of the cache! | ||
raise RuntimeException, "Unable to create DHCP memcache storage" unless @dhcp | ||
|
||
# The DHCP instance needs access to the session as some of its DHCPServer implementations need to know about the user | ||
per_user_dhcp_data = session[:dhcp_data] ||= {:user => @user.login} | ||
@dhcp.personalise(per_user_dhcp_data) | ||
def capture_user_data user | ||
if @user_cache | ||
@user_cache[user.login] = {:password => user.password, :rejected => {}} | ||
Rails.cache.write "user_cache", @user_cache, :expires_in => NET_TTL | ||
end | ||
true | ||
end | ||
end | ||
end | ||
end | ||
# And yes we need to put this in ActiveRecord and NOT User | ||
User.send :include, NetdbManager::UserExtensions |