Class: Radiustar::Request
- Inherits:
-
Object
- Object
- Radiustar::Request
- Defined in:
- lib/radiustar/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.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/radiustar/request.rb', line 7 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
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/radiustar/request.rb', line 48 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
77 78 79 |
# File 'lib/radiustar/request.rb', line 77 def accounting_start(name, secret, sessionid, = {}) accounting_request('Start', name, secret, sessionid, ) end |
#accounting_stop(name, secret, sessionid, options = {}) ⇒ Object
85 86 87 |
# File 'lib/radiustar/request.rb', line 85 def accounting_stop(name, secret, sessionid, = {}) accounting_request('Stop', name, secret, sessionid, ) end |
#accounting_update(name, secret, sessionid, options = {}) ⇒ Object
81 82 83 |
# File 'lib/radiustar/request.rb', line 81 def accounting_update(name, secret, sessionid, = {}) accounting_request('Interim-Update', name, secret, sessionid, ) end |
#authenticate(name, password, secret, user_attributes = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/radiustar/request.rb', line 23 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
89 90 91 |
# File 'lib/radiustar/request.rb', line 89 def inspect to_s end |