radiustar 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,2 +1,5 @@
1
+ == 0.0.3 / 2010-06-30
2
+ * no longer require to specify your own IP (via bwlang)
3
+
1
4
  == 0.0.1 / 2010-04-14
2
5
  * winning at radius
@@ -44,7 +44,7 @@ Ruby Radius Library
44
44
 
45
45
  require 'radiustar'
46
46
 
47
- req = Radiustar::Request.new('server', 'my_ip_address')
47
+ req = Radiustar::Request.new('server')
48
48
  resp = req.authenticate('my_user', 'my_password', 'shared_secret')
49
49
  resp #=> true
50
50
 
@@ -2,45 +2,66 @@ module Radiustar
2
2
 
3
3
  class Dictionary
4
4
 
5
+ include Radiustar
6
+
5
7
  DEFAULT_DICTIONARY_PATH = ::File.join(::File.dirname(__FILE__), '..', '..', 'templates', 'default.txt')
6
8
 
7
9
  def initialize(initial_path = nil)
8
10
  @attributes = AttributesCollection.new
11
+ @vendors = VendorCollection.new
9
12
 
10
13
  read initial_path if initial_path
11
14
  end
12
15
 
13
16
  def read(path)
14
17
  file = File.open(path) do |f|
18
+ current_vendor = nil
15
19
  f.each_line do |line|
16
20
  next if line =~ /^\#/ # discard comments
17
21
  split_line = line.split(/\s+/)
18
22
  next if split_line == []
19
23
  case split_line.first.upcase
20
24
  when "ATTRIBUTE"
21
- set_attr(split_line)
25
+ current_vendor.nil? ? set_attr(split_line) : set_vendor_attr(current_vendor, split_line)
22
26
  when "VALUE"
23
- set_value(split_line)
27
+ current_vendor.nil? ? set_value(split_line) : set_vendor_value(current_vendor, split_line)
28
+ when "VENDOR"
29
+ add_vendor(split_line)
30
+ when "BEGIN-VENDOR"
31
+ current_vendor = set_vendor(split_line)
32
+ when "END-VENDOR"
33
+ current_vendor = nil
24
34
  end
25
35
  end
26
36
  end
37
+ end
27
38
 
28
- def find_attribute_by_name(name)
29
- @attributes.find_by_name(name)
30
- end
39
+ def find_attribute_by_name(name)
40
+ @attributes.find_by_name(name)
41
+ end
31
42
 
32
- def find_attribute_by_id(id)
33
- @attributes.find_by_id(id)
34
- end
43
+ def find_attribute_by_id(id)
44
+ @attributes.find_by_id(id)
45
+ end
35
46
 
36
- def attribute_name_defined?(name)
37
- !@attributes.find_by_name(name).nil?
38
- end
47
+ def attribute_name_defined?(name)
48
+ !@attributes.find_by_name(name).nil?
49
+ end
39
50
 
40
- def attribute_id_defined?(id)
41
- !@attributes.find_by_id(id).nil?
42
- end
51
+ def attribute_id_defined?(id)
52
+ !@attributes.find_by_id(id).nil?
53
+ end
54
+
55
+ def vendors
56
+ @vendors
57
+ end
58
+
59
+ def attributes
60
+ @attributes
61
+ end
43
62
 
63
+ def name
64
+ "Dictionary"
44
65
  end
45
66
 
46
67
  class << self
@@ -61,6 +82,22 @@ module Radiustar
61
82
  @attributes.find_by_name(line[1]).add_value(line[2], line[3])
62
83
  end
63
84
 
85
+ def add_vendor(line)
86
+ @vendors.add(line[2], line[1])
87
+ end
88
+
89
+ def set_vendor(line)
90
+ @vendors.find_by_name(line[1])
91
+ end
92
+
93
+ def set_vendor_attr(vendor, line)
94
+ vendor.add_attribute(line[1], line[2], line[3])
95
+ end
96
+
97
+ def set_vendor_value(vendor, line)
98
+ vendor.find_attribute_by_name(line[1]).add_value(line[2], line[3])
99
+ end
100
+
64
101
  end
65
102
 
66
103
  end
@@ -1,6 +1,6 @@
1
1
  module Radiustar
2
2
 
3
- class AttributesCollection
3
+ class AttributesCollection < Array
4
4
 
5
5
  def initialize
6
6
  @collection = {}
@@ -10,6 +10,7 @@ module Radiustar
10
10
  def add(name, id, type)
11
11
  @collection[name] ||= Attribute.new(name, id.to_i, type)
12
12
  @revcollection[id.to_i] ||= @collection[name]
13
+ self << @collection[name]
13
14
  end
14
15
 
15
16
  def find_by_name(name)
@@ -24,6 +25,8 @@ module Radiustar
24
25
 
25
26
  class Attribute
26
27
 
28
+ include Radiustar
29
+
27
30
  attr_reader :name, :id, :type
28
31
 
29
32
  def initialize(name, id, type)
@@ -49,6 +52,10 @@ module Radiustar
49
52
  !@values.empty?
50
53
  end
51
54
 
55
+ def values
56
+ @values
57
+ end
58
+
52
59
  end
53
60
 
54
61
  end
@@ -1,6 +1,6 @@
1
1
  module Radiustar
2
2
 
3
- class ValuesCollection
3
+ class ValuesCollection < Array
4
4
 
5
5
  def initialize
6
6
  @collection = {}
@@ -10,6 +10,7 @@ module Radiustar
10
10
  def add(name, id)
11
11
  @collection[name] ||= Value.new(name, id)
12
12
  @revcollection[id.to_i] ||= @collection[name]
13
+ self << @collection[name]
13
14
  end
14
15
 
15
16
  def find_by_name(name)
@@ -27,6 +28,9 @@ module Radiustar
27
28
  end
28
29
 
29
30
  class Value
31
+
32
+ include Radiustar
33
+
30
34
  attr_accessor :name
31
35
 
32
36
  def initialize(name, id)
@@ -112,7 +112,7 @@ module Radiustar
112
112
  attribute_type = attribute_type.to_i
113
113
 
114
114
  attribute = @dict.find_attribute_by_id(attribute_type)
115
- attribute_value = case attribute.type
115
+ attribute_value = case attribute.class
116
116
  when 'string'
117
117
  attribute_value
118
118
  when 'integer'
@@ -1,3 +1,7 @@
1
1
  module Radiustar
2
2
 
3
+ def inspect
4
+ "#<#{self.class}:#{self.name}>"
5
+ end
6
+
3
7
  end
@@ -4,10 +4,13 @@ module Radiustar
4
4
 
5
5
  class Request
6
6
 
7
- def initialize(server, my_ip, dict_file = nil)
7
+ def initialize(server, my_ip = nil, dict_file = nil)
8
8
  @dict = dict_file.nil? ? Dictionary.default : Dictionary.new(dict_file)
9
- @my_ip = my_ip
9
+
10
10
  @host, @port = server.split(":")
11
+
12
+ @my_ip = my_ip || get_my_ip(@host)
13
+
11
14
  @port = Socket.getservbyname("radius", "udp") unless @port
12
15
  @port = 1812 unless @port
13
16
  @port = @port.to_i # just in case
@@ -60,6 +63,18 @@ module Radiustar
60
63
  Packet.new(@dict, Process.pid & 0xff, data[0])
61
64
  end
62
65
 
66
+ #looks up the source IP address with a route to the specified destination
67
+ def get_my_ip(dest_address)
68
+ orig_reverse_lookup_setting = Socket.do_not_reverse_lookup
69
+ Socket.do_not_reverse_lookup = true
70
+
71
+ UDPSocket.open do |sock|
72
+ sock.connect dest_address, 1
73
+ sock.addr.last
74
+ end
75
+ ensure
76
+ Socket.do_not_reverse_lookup = orig_reverse_lookup_setting
77
+ end
63
78
 
64
79
  end
65
80
 
@@ -0,0 +1,60 @@
1
+ module Radiustar
2
+
3
+ class VendorCollection < Array
4
+
5
+ def initialize
6
+ @collection = {}
7
+ @revcollection = []
8
+ end
9
+
10
+ def add(id, name)
11
+ @collection[name] ||= Vendor.new(name, id)
12
+ @revcollection[id.to_i] ||= @collection[name]
13
+ self << @collection[name]
14
+ end
15
+
16
+ def find_by_name(name)
17
+ @collection[name]
18
+ end
19
+
20
+ def find_by_id(id)
21
+ @revcollection[id.to_i]
22
+ end
23
+
24
+ end
25
+
26
+ class Vendor
27
+
28
+ include Radiustar
29
+
30
+ attr_reader :name, :id
31
+
32
+ def initialize(name, id)
33
+ @name = name
34
+ @id = id
35
+ @attributes = AttributesCollection.new
36
+ end
37
+
38
+ def add_attribute(name, id, type)
39
+ @attributes.add(name, id, type)
40
+ end
41
+
42
+ def find_attribute_by_name(name)
43
+ @attributes.find_by_name(name)
44
+ end
45
+
46
+ def find_attribute_by_id(id)
47
+ @attributes.find_by_id(id.to_i)
48
+ end
49
+
50
+ def has_attributes?
51
+ !@attributes.empty?
52
+ end
53
+
54
+ def attributes
55
+ @attributes
56
+ end
57
+
58
+ end
59
+
60
+ end
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{radiustar}
5
+ s.version = "0.0.3"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["PJ Davis"]
9
+ s.date = %q{2010-06-30}
10
+ s.description = %q{Ruby Radius Library}
11
+ s.email = %q{pj.davis@gmail.com}
12
+ s.extra_rdoc_files = ["History.txt", "README.rdoc", "templates/default.txt", "version.txt"]
13
+ s.files = [".gitignore", "History.txt", "README.rdoc", "Rakefile", "lib/radiustar.rb", "lib/radiustar/dictionary.rb", "lib/radiustar/dictionary/attributes.rb", "lib/radiustar/dictionary/values.rb", "lib/radiustar/packet.rb", "lib/radiustar/radiustar.rb", "lib/radiustar/request.rb", "lib/radiustar/vendor.rb", "radiustar.gemspec", "spec/radiustar_spec.rb", "spec/spec_helper.rb", "templates/default.txt", "templates/dictionary.digium", "templates/gandalf.dictionary", "test/test_radiustar.rb", "version.txt"]
14
+ s.homepage = %q{http://github.com/pjdavis/radiustar}
15
+ s.rdoc_options = ["--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{radiustar}
18
+ s.rubygems_version = %q{1.3.6}
19
+ s.summary = %q{Ruby Radius Library}
20
+ s.test_files = ["test/test_radiustar.rb"]
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ s.add_development_dependency(%q<bones>, [">= 3.4.1"])
28
+ else
29
+ s.add_dependency(%q<bones>, [">= 3.4.1"])
30
+ end
31
+ else
32
+ s.add_dependency(%q<bones>, [">= 3.4.1"])
33
+ end
34
+ end
@@ -0,0 +1,36 @@
1
+ # -*- text -*-
2
+ ##############################################################################
3
+ #
4
+ # Digium's Asterisk specific radius attributes
5
+ # markster@digium.com
6
+ #
7
+ # http://bugs.digium.com/file_download.php\?file_id=9688\&type=bug
8
+ #
9
+ # $Id$
10
+ #
11
+ ##############################################################################
12
+
13
+ VENDOR Digium 22736
14
+
15
+ BEGIN-VENDOR Digium
16
+
17
+ ATTRIBUTE Asterisk-Acc-Code 101 string
18
+ ATTRIBUTE Asterisk-Src 102 string
19
+ ATTRIBUTE Asterisk-Dst 103 string
20
+ ATTRIBUTE Asterisk-Dst-Ctx 104 string
21
+ ATTRIBUTE Asterisk-Clid 105 string
22
+ ATTRIBUTE Asterisk-Chan 106 string
23
+ ATTRIBUTE Asterisk-Dst-Chan 107 string
24
+ ATTRIBUTE Asterisk-Last-App 108 string
25
+ ATTRIBUTE Asterisk-Last-Data 109 string
26
+ ATTRIBUTE Asterisk-Start-Time 110 string
27
+ ATTRIBUTE Asterisk-Answer-Time 111 string
28
+ ATTRIBUTE Asterisk-End-Time 112 string
29
+ ATTRIBUTE Asterisk-Duration 113 integer
30
+ ATTRIBUTE Asterisk-Bill-Sec 114 integer
31
+ ATTRIBUTE Asterisk-Disposition 115 string
32
+ ATTRIBUTE Asterisk-AMA-Flags 116 string
33
+ ATTRIBUTE Asterisk-Unique-ID 117 string
34
+ ATTRIBUTE Asterisk-User-Field 118 string
35
+
36
+ END-VENDOR Digium
@@ -0,0 +1,105 @@
1
+ # -*- text -*-
2
+ # Gandalf dictionary
3
+ #
4
+ # Version: 1.00 24-July-2003 Blaise St-Laurent <bstlaurent@okiok.com>
5
+ #
6
+ # Notes: Dictionary was made specifically for the Gandalf XpressWay
7
+ # RLAN with Link Authentication through RADIUS
8
+ #
9
+ # $Id$
10
+ #
11
+ VENDOR Gandalf 64
12
+
13
+ #
14
+ # Vendor-specific attributes
15
+ #
16
+ BEGIN-VENDOR Gandalf
17
+
18
+ ATTRIBUTE Gandalf-Remote-LAN-Name 0 string
19
+ ATTRIBUTE Gandalf-Operational-Modes 1 integer
20
+ ATTRIBUTE Gandalf-Compression-Status 2 integer
21
+ ATTRIBUTE Gandalf-Min-Outgoing-Bearer 3 integer
22
+ ATTRIBUTE Gandalf-Authentication-String 5 string
23
+ ATTRIBUTE Gandalf-PPP-Authentication 6 integer
24
+ ATTRIBUTE Gandalf-PPP-NCP-Type 7 integer
25
+ ATTRIBUTE Gandalf-Fwd-Multicast-In 8 integer
26
+ ATTRIBUTE Gandalf-Fwd-Broadcast-In 9 integer
27
+ ATTRIBUTE Gandalf-Fwd-Unicast-In 10 integer
28
+ ATTRIBUTE Gandalf-Fwd-Multicast-Out 11 integer
29
+ ATTRIBUTE Gandalf-Fwd-Broadcast-Out 12 integer
30
+ ATTRIBUTE Gandalf-Fwd-Unicast-Out 13 integer
31
+ ATTRIBUTE Gandalf-Around-The-Corner 14 integer
32
+ ATTRIBUTE Gandalf-Channel-Group-Name-1 15 string
33
+ ATTRIBUTE Gandalf-Dial-Prefix-Name-1 16 string
34
+ ATTRIBUTE Gandalf-Phone-Number-1 17 string
35
+ ATTRIBUTE Gandalf-Calling-Line-ID-1 18 string
36
+ ATTRIBUTE Gandalf-Channel-Group-Name-2 19 string
37
+ ATTRIBUTE Gandalf-Dial-Prefix-Name-2 20 string
38
+ ATTRIBUTE Gandalf-Phone-Number-2 21 string
39
+ ATTRIBUTE Gandalf-Calling-Line-ID-2 22 string
40
+ ATTRIBUTE Gandalf-IPX-Spoofing-State 23 integer
41
+ ATTRIBUTE Gandalf-IPX-Watchdog-Spoof 24 integer
42
+ ATTRIBUTE Gandalf-SAP-Group-Name-1 25 string
43
+ ATTRIBUTE Gandalf-SAP-Group-Name-2 26 string
44
+ ATTRIBUTE Gandalf-SAP-Group-Name-3 27 string
45
+ ATTRIBUTE Gandalf-SAP-Group-Name-4 28 string
46
+ ATTRIBUTE Gandalf-SAP-Group-Name-5 29 string
47
+ ATTRIBUTE Gandalf-Hunt-Group 30 string
48
+ ATTRIBUTE Gandalf-Modem-Mode 31 integer
49
+ ATTRIBUTE Gandalf-Modem-Required-1 32 integer
50
+ ATTRIBUTE Gandalf-Modem-Required-2 33 integer
51
+
52
+ VALUE Gandalf-Operational-Modes Disabled 1
53
+ VALUE Gandalf-Operational-Modes Called-Only 2
54
+ VALUE Gandalf-Operational-Modes Calling-Called 3
55
+ VALUE Gandalf-Operational-Modes Calling-Only 4
56
+
57
+ VALUE Gandalf-Compression-Status Disabled 1
58
+ VALUE Gandalf-Compression-Status Enabled 2
59
+
60
+ VALUE Gandalf-Min-Outgoing-Bearer Unrestricted-64K 1
61
+ VALUE Gandalf-Min-Outgoing-Bearer Digital-56K 2
62
+ VALUE Gandalf-Min-Outgoing-Bearer 3100Hz-Audio 3
63
+
64
+ VALUE Gandalf-PPP-Authentication CHAP 1
65
+ VALUE Gandalf-PPP-Authentication PAP 2
66
+ VALUE Gandalf-PPP-Authentication PAP-Sending-on-Incoming-Calls 3
67
+
68
+ VALUE Gandalf-PPP-NCP-Type BCP 2
69
+ VALUE Gandalf-PPP-NCP-Type IPCP 3
70
+
71
+ VALUE Gandalf-Fwd-Multicast-In Disabled 1
72
+ VALUE Gandalf-Fwd-Multicast-In Enabled 2
73
+
74
+ VALUE Gandalf-Fwd-Broadcast-In Disabled 1
75
+ VALUE Gandalf-Fwd-Broadcast-In Enabled 2
76
+
77
+ VALUE Gandalf-Fwd-Unicast-In Disabled 1
78
+ VALUE Gandalf-Fwd-Unicast-In Enabled 2
79
+
80
+ VALUE Gandalf-Fwd-Multicast-Out Disabled 1
81
+ VALUE Gandalf-Fwd-Multicast-Out Enabled 2
82
+
83
+ VALUE Gandalf-Fwd-Broadcast-Out Disabled 1
84
+ VALUE Gandalf-Fwd-Broadcast-Out Enabled 2
85
+
86
+ VALUE Gandalf-Fwd-Unicast-Out Disabled 1
87
+ VALUE Gandalf-Fwd-Unicast-Out Enabled 2
88
+
89
+ VALUE Gandalf-IPX-Spoofing-State Forward 1
90
+ VALUE Gandalf-IPX-Spoofing-State Spoof 2
91
+ VALUE Gandalf-IPX-Spoofing-State Filter-all-outgoing-RIP-SAP 3
92
+
93
+ VALUE Gandalf-IPX-Watchdog-Spoof Disabled 1
94
+ VALUE Gandalf-IPX-Watchdog-Spoof Enabled 2
95
+
96
+ VALUE Gandalf-Modem-Mode Disabled 1
97
+ VALUE Gandalf-Modem-Mode Enabled 2
98
+
99
+ VALUE Gandalf-Modem-Required-1 Disabled 1
100
+ VALUE Gandalf-Modem-Required-1 Enabled 2
101
+
102
+ VALUE Gandalf-Modem-Required-2 Disabled 1
103
+ VALUE Gandalf-Modem-Required-2 Enabled 2
104
+
105
+ END-VENDOR Gandalf
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - PJ Davis
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-20 00:00:00 -05:00
17
+ date: 2010-06-30 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -54,9 +54,13 @@ files:
54
54
  - lib/radiustar/packet.rb
55
55
  - lib/radiustar/radiustar.rb
56
56
  - lib/radiustar/request.rb
57
+ - lib/radiustar/vendor.rb
58
+ - radiustar.gemspec
57
59
  - spec/radiustar_spec.rb
58
60
  - spec/spec_helper.rb
59
61
  - templates/default.txt
62
+ - templates/dictionary.digium
63
+ - templates/gandalf.dictionary
60
64
  - test/test_radiustar.rb
61
65
  - version.txt
62
66
  has_rdoc: true