Class: RadiusRB::Request
- Inherits:
-
Object
- Object
- RadiusRB::Request
- Defined in:
- lib/radiusrb/request.rb
Instance Method Summary collapse
- #accounting_request(status_type, name, secret, sessionid, user_attributes = {}) ⇒ Object
- #accounting_start(name, secret, sessionid, options = {}) ⇒ Object
- #accounting_stop(name, secret, sessionid, options = {}) ⇒ Object
- #accounting_update(name, secret, sessionid, options = {}) ⇒ Object
- #authenticate(name, password, secret, user_attributes = {}) ⇒ Object
-
#initialize(server, options = {}) ⇒ Request
constructor
A new instance of Request.
- #inspect ⇒ Object
Constructor Details
#initialize(server, options = {}) ⇒ Request
Returns a new instance of Request.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/radiusrb/request.rb', line 24 def initialize(server, = {}) @dict = [:dict].nil? ? Dictionary.default : [:dict] @nas_ip = [:nas_ip] || get_my_ip(@host) @nas_identifier = [:nas_identifier] || @nas_ip @reply_timeout = [:reply_timeout].nil? ? 60 : [:reply_timeout].to_i @retries_number = [:retries_number].nil? ? 1 : [:retries_number].to_i @host, @port = server.split(":") @port = Socket.getservbyname("radius", "udp") unless @port @port = 1812 unless @port @port = @port.to_i # just in case @socket = UDPSocket.open @socket.connect(@host, @port) end |
Instance Method Details
#accounting_request(status_type, name, secret, sessionid, user_attributes = {}) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/radiusrb/request.rb', line 65 def accounting_request(status_type, name, secret, sessionid, user_attributes = {}) @packet = Packet.new(@dict, Process.pid & 0xff) @packet.code = 'Accounting-Request' @packet.set_attribute('User-Name', name) @packet.set_attribute('NAS-Identifier', @nas_identifier) @packet.set_attribute('NAS-IP-Address', @nas_ip) @packet.set_attribute('Acct-Status-Type', status_type) @packet.set_attribute('Acct-Session-Id', sessionid) @packet.set_attribute('Acct-Authentic', 'RADIUS') user_attributes.each_pair do |name, value| @packet.set_attribute(name, value) end @packet.gen_acct_authenticator(secret) begin send_packet @recieved_packet = recv_packet(@reply_timeout) rescue Exception => e retry if (@retries_number -= 1) > 0 raise end return true end |
#accounting_start(name, secret, sessionid, options = {}) ⇒ Object
94 95 96 |
# File 'lib/radiusrb/request.rb', line 94 def accounting_start(name, secret, sessionid, = {}) accounting_request('Start', name, secret, sessionid, ) end |
#accounting_stop(name, secret, sessionid, options = {}) ⇒ Object
102 103 104 |
# File 'lib/radiusrb/request.rb', line 102 def accounting_stop(name, secret, sessionid, = {}) accounting_request('Stop', name, secret, sessionid, ) end |
#accounting_update(name, secret, sessionid, options = {}) ⇒ Object
98 99 100 |
# File 'lib/radiusrb/request.rb', line 98 def accounting_update(name, secret, sessionid, = {}) accounting_request('Interim-Update', name, secret, sessionid, ) end |
#authenticate(name, password, secret, user_attributes = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/radiusrb/request.rb', line 40 def authenticate(name, password, secret, user_attributes = {}) @packet = Packet.new(@dict, Process.pid & 0xff) @packet.gen_auth_authenticator @packet.code = 'Access-Request' @packet.set_attribute('User-Name', name) @packet.set_attribute('NAS-Identifier', @nas_identifier) @packet.set_attribute('NAS-IP-Address', @nas_ip) @packet.set_encoded_attribute('User-Password', password, secret) user_attributes.each_pair do |name, value| @packet.set_attribute(name, value) end begin send_packet @recieved_packet = recv_packet(@reply_timeout) rescue Exception => e retry if (@retries_number -= 1) > 0 raise end reply = { :code => @recieved_packet.code } reply.merge @recieved_packet.attributes end |
#inspect ⇒ Object
106 107 108 |
# File 'lib/radiusrb/request.rb', line 106 def inspect to_s end |