Class: Radiustar::Request
- Inherits:
-
Object
- Object
- Radiustar::Request
- Defined in:
- lib/radiustar/request.rb
Instance Method Summary collapse
- #authenticate(name, password, secret) ⇒ Object
- #get_attributes(name, password, secret) ⇒ Object
-
#initialize(server, my_ip = nil, dict_file = nil) ⇒ Request
constructor
A new instance of Request.
- #inspect ⇒ Object
Constructor Details
#initialize(server, my_ip = nil, dict_file = nil) ⇒ Request
Returns a new instance of Request.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/radiustar/request.rb', line 7 def initialize(server, my_ip = nil, dict_file = nil) @dict = dict_file.nil? ? Dictionary.default : Dictionary.new(dict_file) @host, @port = server.split(":") @my_ip = my_ip || get_my_ip(@host) @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
#authenticate(name, password, secret) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/radiustar/request.rb', line 21 def authenticate(name, password, secret) @packet = Packet.new(@dict, Process.pid & 0xff) @packet.code = 'Access-Request' @packet.gen_authenticator @packet.set_attribute('User-Name', name) @packet.set_attribute('NAS-IP-Address', @my_ip) @packet.set_encoded_attribute('User-Password', password, secret) send_packet @recieved_packet = recv_packet return @recieved_packet.code == 'Access-Accept' end |
#get_attributes(name, password, secret) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/radiustar/request.rb', line 33 def get_attributes(name, password, secret) @packet = Packet.new(@dict, Process.pid & 0xff) @packet.code = 'Access-Request' @packet.gen_authenticator @packet.set_attribute('User-Name', name) @packet.set_attribute('NAS-IP-Address', @my_ip) @packet.set_encoded_attribute('User-Password', password, secret) send_packet @recieved_packet = recv_packet recieved_thing = [@recieved_packet.code] recieved_thing << @recieved_packet.attributes end |
#inspect ⇒ Object
46 47 48 |
# File 'lib/radiustar/request.rb', line 46 def inspect to_s end |