riptables 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6163673be40ac8debc91fbbb58b934d622a0551b
4
- data.tar.gz: 834420f08005d80abf266219d82445f9187b42cb
3
+ metadata.gz: 188cb2ed7bb522ea47cd1c2fde51ff290b258f68
4
+ data.tar.gz: 269aaf5101ca29be6afa53f288527384f4840ae3
5
5
  SHA512:
6
- metadata.gz: ffcca219d8afdab19f25844fa2e6352cd49f5149e7254fc70c691864db89c7698a4d7950639b9a93900165544cfe5bfb0b65901903352f1b3fa7d19eaaa71153
7
- data.tar.gz: 97b4c44f8ec3b26978c6cf7e3bca149a7dfa79277f4f77db1e627beacf47f84b25e123444b427653e94bd8e1d087e6264a6a60ce26f48942e739ad7007b4c5e0
6
+ metadata.gz: 95f7cd9e5d4a41434d2976e3ec5332aceb239196a2ceb75c9161d06726a05c0000f04b2e5abb92a3a0821b12fb0bbf1cd09b948e2b9afe970cf1efe5a08e7c3e
7
+ data.tar.gz: 71146751cebabb763760533c9adf4e810b67f364c54d281a564ff4b999d4f18f4e54c513b2db4d36895cf1f707ac08b3ef602b8a88357049b306d33fec1328f9
data/README.md CHANGED
@@ -116,6 +116,17 @@ both and cannot currently be different depending on IP version.
116
116
  The `riptables` command is used to generate your iptables-save files. These can
117
117
  then be used with `iptables-restore`.
118
118
 
119
+ ### Installing
120
+
121
+ * Ensure you have Ruby 2.0 or higher installed.
122
+ * Ensure you have RubyGems install.
123
+
124
+ ```text
125
+ gem install riptables
126
+ ```
127
+
128
+ ### Usage
129
+
119
130
  ```text
120
131
  $ riptables
121
132
  ```
data/bin/riptables CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  $:.unshift(File.expand_path('../../lib', __FILE__))
3
- require 'riptables'
3
+
4
4
  require 'optparse'
5
5
 
6
6
  options = {}
@@ -21,8 +21,9 @@ OptionParser.new do |opts|
21
21
  end.parse!
22
22
 
23
23
  begin
24
- Riptables.load_from_file(load_path)
25
- Riptables.tables.each do |table|
24
+ require 'riptables/base'
25
+ base = Riptables::Base.load_from_file(load_path)
26
+ base.tables.each do |table|
26
27
  puts table.export(options).to_savefile(ipv)
27
28
  end
28
29
  rescue Riptables::Error => e
@@ -0,0 +1,29 @@
1
+ require 'riptables/error'
2
+ require 'riptables/dsl/base'
3
+
4
+ module Riptables
5
+ class Base
6
+
7
+ attr_reader :tables
8
+
9
+ def initialize(&block)
10
+ @tables = []
11
+ dsl.instance_eval(&block) if block_given?
12
+ end
13
+
14
+ def dsl
15
+ @dsl ||= DSL::Base.new(self)
16
+ end
17
+
18
+ def self.load_from_file(file)
19
+ if File.file?(file)
20
+ base = Base.new
21
+ base.dsl.instance_eval(File.read(file), file)
22
+ base
23
+ else
24
+ raise Error, "File not found at `#{file}`"
25
+ end
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ require 'riptables/dsl/base'
2
+ require 'riptables/table'
3
+
4
+ module Riptables
5
+ module DSL
6
+ class Base < Global
7
+
8
+ def initialize(base, &block)
9
+ @base = base
10
+ end
11
+
12
+ def table(name, &block)
13
+ table = Riptables::Table.new(@base, name)
14
+ table.dsl.instance_eval(&block)
15
+ @base.tables << table
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -5,10 +5,12 @@ require 'riptables/table_export'
5
5
  module Riptables
6
6
  class Table
7
7
 
8
+ attr_reader :base
8
9
  attr_reader :name
9
10
  attr_reader :chains
10
11
 
11
- def initialize(name)
12
+ def initialize(base, name)
13
+ @base = base
12
14
  @name = name
13
15
  @chains = {}
14
16
  end
@@ -1,3 +1,3 @@
1
1
  module Riptables
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
data/lib/riptables.rb CHANGED
@@ -1,26 +1 @@
1
- require 'riptables/dsl/root'
2
- require 'riptables/error'
3
-
4
- module Riptables
5
-
6
-
7
- # Store all tables configured
8
- #
9
- def self.tables
10
- @tables ||= []
11
- end
12
-
13
- #
14
- # Parse a given file
15
- #
16
- def self.load_from_file(file)
17
- if File.file?(file)
18
- dsl = DSL::Root.new
19
- dsl.instance_eval(File.read(file), file)
20
- true
21
- else
22
- raise Error, "File not found at `#{file}`"
23
- end
24
- end
25
-
26
- end
1
+ require 'riptables/base'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riptables
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke
@@ -22,10 +22,11 @@ files:
22
22
  - README.md
23
23
  - bin/riptables
24
24
  - lib/riptables.rb
25
+ - lib/riptables/base.rb
25
26
  - lib/riptables/chain.rb
26
27
  - lib/riptables/condition.rb
28
+ - lib/riptables/dsl/base.rb
27
29
  - lib/riptables/dsl/global.rb
28
- - lib/riptables/dsl/root.rb
29
30
  - lib/riptables/dsl/rule.rb
30
31
  - lib/riptables/dsl/table.rb
31
32
  - lib/riptables/error.rb
@@ -1,19 +0,0 @@
1
- require 'riptables/dsl/global'
2
- require 'riptables/table'
3
-
4
- module Riptables
5
- module DSL
6
- class Root < Global
7
-
8
- #
9
- # Rules within a given table
10
- #
11
- def table(name, &block)
12
- table = Riptables::Table.new(name)
13
- table.dsl.instance_eval(&block)
14
- Riptables.tables << table
15
- end
16
-
17
- end
18
- end
19
- end