junos-config 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,42 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # bundler
12
+ .bundle
13
+
14
+ # jeweler generated
15
+ pkg
16
+
17
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
18
+ #
19
+ # * Create a file at ~/.gitignore
20
+ # * Include files you want ignored
21
+ # * Run: git config --global core.excludesfile ~/.gitignore
22
+ #
23
+ # After doing this, these files will be ignored in all your git projects,
24
+ # saving you from having to 'pollute' every project you touch with them
25
+ #
26
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
27
+ #
28
+ # For MacOS:
29
+ #
30
+ #.DS_Store
31
+ #
32
+ # For TextMate
33
+ #*.tmproj
34
+ #tmtags
35
+ #
36
+ # For emacs:
37
+ #*~
38
+ #\#*
39
+ #.\#*
40
+ #
41
+ # For vim:
42
+ #*.swp
@@ -1,14 +1,14 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- diff-lcs (1.1.2)
4
+ diff-lcs (1.1.3)
5
5
  git (1.2.5)
6
6
  jeweler (1.5.2)
7
7
  bundler (~> 1.0.0)
8
8
  git (>= 1.2.5)
9
9
  rake
10
- rake (0.8.7)
11
- rcov (0.9.8)
10
+ rake (0.9.2.2)
11
+ rcov (1.0.0)
12
12
  rspec (2.3.0)
13
13
  rspec-core (~> 2.3.0)
14
14
  rspec-expectations (~> 2.3.0)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -5,40 +5,22 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{junos-config}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["John Wulff"]
12
- s.date = %q{2011-03-29}
11
+ s.authors = ["John Wulff", "Aki Immonen"]
12
+ s.date = %q{2012-02-14}
13
13
  s.description = %q{Parser for Junos (Juniper network gear OS) config files.}
14
- s.email = %q{johnw@orcasnet.com}
14
+ s.email = %q{johnw@orcasnet.com aki@axasoft.fi}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
17
  "README.rdoc"
18
18
  ]
19
- s.files = [
20
- ".document",
21
- ".rspec",
22
- "Gemfile",
23
- "Gemfile.lock",
24
- "LICENSE.txt",
25
- "README.rdoc",
26
- "Rakefile",
27
- "VERSION",
28
- "junos-config.gemspec",
29
- "lib/junos-config.rb",
30
- "lib/junos-config/config.rb",
31
- "lib/junos-config/interface.rb",
32
- "lib/junos-config/security/policy.rb",
33
- "lib/junos-config/security/zone.rb",
34
- "spec/junos-config_spec.rb",
35
- "spec/sample_configs/sample_1",
36
- "spec/spec_helper.rb"
37
- ]
38
- s.homepage = %q{http://github.com/jwulff/junos-config}
19
+ s.files = `git ls-files`.split
20
+ s.homepage = %q{http://github.com/axasoft/junos-config}
39
21
  s.licenses = ["MIT"]
40
22
  s.require_paths = ["lib"]
41
- s.rubygems_version = %q{1.6.2}
23
+ s.rubygems_version = %q{1.8.16}
42
24
  s.summary = %q{Parser for Junos config files.}
43
25
  s.test_files = [
44
26
  "spec/junos-config_spec.rb",
@@ -1,4 +1,8 @@
1
1
  require 'junos-config/security/policy'
2
2
  require 'junos-config/security/zone'
3
+ require 'junos-config/security/addressbook'
4
+ require 'junos-config/security/addressset'
5
+ require 'junos-config/security/address'
6
+ require 'junos-config/application'
3
7
  require 'junos-config/interface'
4
8
  require 'junos-config/config'
@@ -0,0 +1,63 @@
1
+ module JunosConfig
2
+ class Application
3
+ attr_accessor :raw,
4
+ :config,
5
+ :name
6
+
7
+ def initialize(config, raw)
8
+ @config = config
9
+ @raw = raw
10
+ @name = raw.match(/^\ {4}application (\S+)\ \{$/)[1]
11
+ end
12
+
13
+ def to_s
14
+ @name
15
+ end
16
+
17
+ def list_of_objects
18
+ [self]
19
+ end
20
+
21
+ def details
22
+ "#{name}: #{raw}"
23
+ end
24
+
25
+ end
26
+
27
+ class ApplicationSet
28
+ attr_accessor :raw,
29
+ :config,
30
+ :name,
31
+ :applications
32
+
33
+ def initialize(config, raw)
34
+ @config = config
35
+ @raw = raw
36
+ @name = raw.match(/^\ {4}application\-set (\S+)\ \{$/)[1]
37
+ @applications = raw.scan(/^(\ {8}application (\S+);)$/).collect do |x|
38
+ config.application(x[1])
39
+ end
40
+ end
41
+
42
+ def to_s
43
+ @name
44
+ end
45
+
46
+ def list_of_objects
47
+ applications
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+
54
+ class String
55
+
56
+ def list_of_objects
57
+ [self]
58
+ end
59
+
60
+ def details
61
+ to_s
62
+ end
63
+ end
@@ -1,18 +1,33 @@
1
1
  module JunosConfig
2
2
  class Config
3
3
  attr_reader :raw,
4
+ :last_changed,
5
+ :version,
6
+ :hostname,
4
7
  :interfaces,
5
8
  :security_zones,
6
- :security_policies
9
+ :security_policies,
10
+ :applications,
11
+ :application_sets
7
12
 
8
13
  def initialize(raw)
9
14
  @raw = raw
15
+
16
+ m = raw.match(/Last\ changed:\ (.*?)\nversion\ (\S+);/m)
17
+ @last_changed = m[1] if m
18
+ @version = m[2] if m
19
+
10
20
  raw.scan(/^(\w+)\ \{$(.*?)^\}$/m).each do |section|
11
21
  method = "parse_#{section[0]}"
12
22
  send method, section[1] if respond_to?(method)
13
23
  end
14
24
  end
15
25
 
26
+ def parse_groups(raw_section)
27
+ m = raw_section.match(/host\-name\ (\S+)-\S;/m)
28
+ @hostname = m[1]
29
+ end
30
+
16
31
  def parse_interfaces(raw_section)
17
32
  @interfaces = raw_section.scan(/^(\ {4}\S+\ \{$.*?^\ {4}\})$/m).collect do |x|
18
33
  Interface.new self, x[0]
@@ -32,5 +47,29 @@ module JunosConfig
32
47
  end
33
48
  @security_policies.flatten!
34
49
  end
50
+
51
+ def parse_applications(raw_section)
52
+ @applications = raw_section.scan(/^(\ {4}application\ \S+ \{$.*?^\ {4}\})$/m).collect do |x|
53
+ Application.new self, x[0]
54
+ end
55
+ @application_lookup = {}
56
+ @applications.each{|a| @application_lookup[a.name] = a }
57
+ @application_sets = raw_section.scan(/^(\ {4}application\-set\ \S+ \{$.*?^\ {4}\})$/m).collect do |x|
58
+ ApplicationSet.new self, x[0]
59
+ end
60
+ @application_sets.each{|a| @application_lookup[a.name] = a }
61
+
62
+ @security_policies.each do |policy|
63
+ policy.application.collect! {|name| application(name) }
64
+ end
65
+ end
66
+
67
+ def application(name)
68
+ if name =~ /any|ESP|esp|junos\-/
69
+ # junos internal applications
70
+ return name
71
+ end
72
+ @application_lookup[name]
73
+ end
35
74
  end
36
75
  end
@@ -0,0 +1,18 @@
1
+ module JunosConfig
2
+ module Security
3
+ class Address
4
+ attr_accessor :raw,
5
+ :config,
6
+ :name,
7
+ :ip
8
+
9
+ def initialize(config, raw)
10
+ @config = config
11
+ @raw = raw
12
+ m = raw.match(/^\ {16}address (\S+)\ (\S+);/)
13
+ @name = m[1]
14
+ @ip = m[2]
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,40 @@
1
+ module JunosConfig
2
+ module Security
3
+ class AddressBook
4
+ attr_accessor :raw,
5
+ :config,
6
+ :name,
7
+ :addresses,
8
+ :address_sets
9
+
10
+ def initialize(config, raw)
11
+ @config = config
12
+ @raw = raw
13
+ @addresses = raw.scan(/^(\ {16}address \S+ \S+;)$/).collect do |x|
14
+ Security::Address.new self, x[0]
15
+ end
16
+ @address_sets = raw.scan(/^(\ {16}address-set \S+ \{$.*?^\ {16}\})$/m).collect do |x|
17
+ Security::AddressSet.new self, x[0]
18
+ end
19
+ @resolv = {}
20
+ @addresses.each { |a| @resolv[a.name] = a }
21
+ @address_sets.each do |as|
22
+ @resolv[as.name] = as
23
+ aset = as.lookup_addresses(self)
24
+ aset.each{ |a| @resolv[a.name] = a }
25
+ end
26
+ end
27
+
28
+ def resolve(name)
29
+ @resolv[name]
30
+ end
31
+
32
+ def lookup(name)
33
+ addrs = resolve(name)
34
+ return unless addrs
35
+ return addrs.addresses if addrs.class == JunosConfig::Security::AddressSet
36
+ [addrs]
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,25 @@
1
+ module JunosConfig
2
+ module Security
3
+ class AddressSet
4
+ attr_accessor :raw,
5
+ :config,
6
+ :name,
7
+ :addresses
8
+
9
+ def initialize(config, raw)
10
+ @config = config
11
+ @raw = raw
12
+ @name = raw.match(/^\ {16}address-set (\S+)\ \{$/)[1]
13
+ @addresses = raw.scan(/^(\ {20}address (\S+);)$/).collect do |x|
14
+ String.new x[1]
15
+ end
16
+ end
17
+
18
+ def lookup_addresses( addressbook )
19
+ @addresses.collect! do |addr|
20
+ addressbook.resolve(addr)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -5,7 +5,10 @@ module JunosConfig
5
5
  :config,
6
6
  :name,
7
7
  :from_zone,
8
- :to_zone
8
+ :to_zone,
9
+ :source_address,
10
+ :destination_address,
11
+ :application
9
12
 
10
13
  def initialize(config, raw, from_zone, to_zone)
11
14
  @config = config
@@ -13,6 +16,22 @@ module JunosConfig
13
16
  @from_zone = from_zone
14
17
  @to_zone = to_zone
15
18
  @name = raw.match(/^\ {12}policy (\S+)\ \{$/)[1]
19
+
20
+ raw.scan(/^\ {20}source\-address\ ([^;]+);/).each do |src|
21
+ s = src[0].split(" ")
22
+ s = s.slice(1,s.length-2) if s.length > 1
23
+ @source_address = s
24
+ end
25
+ raw.scan(/^\ {20}destination\-address\ ([^;]+);/).each do |dst|
26
+ s = dst[0].split(" ")
27
+ s = s.slice(1,s.length-2) if s.length > 1
28
+ @destination_address = s
29
+ end
30
+ raw.scan(/^\ {20}application\ ([^;]+);/).each do |app|
31
+ s = app[0].split(" ")
32
+ s = s.slice(1,s.length-2) if s.length > 1
33
+ @application = s
34
+ end
16
35
  end
17
36
  end
18
37
  end
@@ -3,12 +3,16 @@ module JunosConfig
3
3
  class Zone
4
4
  attr_accessor :raw,
5
5
  :config,
6
- :name
6
+ :name,
7
+ :address_book
7
8
 
8
9
  def initialize(config, raw)
9
10
  @config = config
10
11
  @raw = raw
11
- @name = raw.match(/^\ {8}security\-zone\ (\S+) \{$/)[1]
12
+ @name = raw.match(/^\ {8}security\-zone\ (\S+) \{$/)[1]
13
+ @address_book = raw.scan(/^(\ {12}address\-book\ \{$.*?^\ {12}\})$/m).collect do |x|
14
+ Security::AddressBook.new self, x[0]
15
+ end
12
16
  end
13
17
  end
14
18
  end
metadata CHANGED
@@ -1,24 +1,26 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: junos-config
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Wulff
14
+ - Aki Immonen
14
15
  autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2011-03-29 00:00:00 -07:00
19
- default_executable:
19
+ date: 2012-02-14 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
22
24
  requirement: &id001 !ruby/object:Gem::Requirement
23
25
  none: false
24
26
  requirements:
@@ -30,11 +32,11 @@ dependencies:
30
32
  - 3
31
33
  - 0
32
34
  version: 2.3.0
33
- name: rspec
34
- version_requirements: *id001
35
- prerelease: false
36
35
  type: :development
36
+ version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
38
+ name: bundler
39
+ prerelease: false
38
40
  requirement: &id002 !ruby/object:Gem::Requirement
39
41
  none: false
40
42
  requirements:
@@ -46,11 +48,11 @@ dependencies:
46
48
  - 0
47
49
  - 0
48
50
  version: 1.0.0
49
- name: bundler
50
- version_requirements: *id002
51
- prerelease: false
52
51
  type: :development
52
+ version_requirements: *id002
53
53
  - !ruby/object:Gem::Dependency
54
+ name: jeweler
55
+ prerelease: false
54
56
  requirement: &id003 !ruby/object:Gem::Requirement
55
57
  none: false
56
58
  requirements:
@@ -62,11 +64,11 @@ dependencies:
62
64
  - 5
63
65
  - 2
64
66
  version: 1.5.2
65
- name: jeweler
66
- version_requirements: *id003
67
- prerelease: false
68
67
  type: :development
68
+ version_requirements: *id003
69
69
  - !ruby/object:Gem::Dependency
70
+ name: rcov
71
+ prerelease: false
70
72
  requirement: &id004 !ruby/object:Gem::Requirement
71
73
  none: false
72
74
  requirements:
@@ -76,12 +78,10 @@ dependencies:
76
78
  segments:
77
79
  - 0
78
80
  version: "0"
79
- name: rcov
80
- version_requirements: *id004
81
- prerelease: false
82
81
  type: :development
82
+ version_requirements: *id004
83
83
  description: Parser for Junos (Juniper network gear OS) config files.
84
- email: johnw@orcasnet.com
84
+ email: johnw@orcasnet.com aki@axasoft.fi
85
85
  executables: []
86
86
 
87
87
  extensions: []
@@ -91,6 +91,7 @@ extra_rdoc_files:
91
91
  - README.rdoc
92
92
  files:
93
93
  - .document
94
+ - .gitignore
94
95
  - .rspec
95
96
  - Gemfile
96
97
  - Gemfile.lock
@@ -100,15 +101,18 @@ files:
100
101
  - VERSION
101
102
  - junos-config.gemspec
102
103
  - lib/junos-config.rb
104
+ - lib/junos-config/application.rb
103
105
  - lib/junos-config/config.rb
104
106
  - lib/junos-config/interface.rb
107
+ - lib/junos-config/security/address.rb
108
+ - lib/junos-config/security/addressbook.rb
109
+ - lib/junos-config/security/addressset.rb
105
110
  - lib/junos-config/security/policy.rb
106
111
  - lib/junos-config/security/zone.rb
107
112
  - spec/junos-config_spec.rb
108
113
  - spec/sample_configs/sample_1
109
114
  - spec/spec_helper.rb
110
- has_rdoc: true
111
- homepage: http://github.com/jwulff/junos-config
115
+ homepage: http://github.com/axasoft/junos-config
112
116
  licenses:
113
117
  - MIT
114
118
  post_install_message:
@@ -137,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
141
  requirements: []
138
142
 
139
143
  rubyforge_project:
140
- rubygems_version: 1.6.2
144
+ rubygems_version: 1.8.10
141
145
  signing_key:
142
146
  specification_version: 3
143
147
  summary: Parser for Junos config files.