iptables-web 0.1.0 → 0.2.0.beta1

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: 8a139530b147346fe830287212857940a70cfad5
4
- data.tar.gz: c0fc21ed2e8c05aada06d3d06d869df259cabd22
3
+ metadata.gz: d1617382a4273d74b32143e069ed9ceec430a890
4
+ data.tar.gz: 183bebac53e65517e71674382e4300d1d3e29d60
5
5
  SHA512:
6
- metadata.gz: 672789d5c2099099ad2589abe1eb3bcc3fbb0cf30f4bb7b829284c4a6211385c99bade46ffa8ac792f6e98d60d4813079caed35789b18d164cf48cc698b66fd0
7
- data.tar.gz: 88add871cab6f009691bc3f1036c0c9e954845b912cb068baa4b69d992532884a989003faf0130d9dfc47989df116c608bd3d5338b9ef2ac5b16ee0b6b8f9171
6
+ metadata.gz: 4130032a62a91def785039cad41784b5de812183f4b9937315e267592bb48cde769351f3f52b1bbb97504f6e3a0bb0a5892b079fec0b3b44e5985928bd70111c
7
+ data.tar.gz: 6b316ef4967f98cc6b5b87b1a874375a677b3aa041fee4bd2f0f1a0ad7a3b9d5d61092b079bacbb9052830a63cc6d7c2066c7835caf47c662ea5e5092ad312ac
data/bin/iptables-web CHANGED
@@ -71,11 +71,17 @@ command :update do |c|
71
71
  c.syntax = 'iptables-web update'
72
72
  c.description = 'Display bar with optional prefix and suffix'
73
73
  c.option '--config STRING', String, 'Path to config file'
74
- c.action do |args, options|
74
+ c.option '--print', 'Show rules without restoring'
75
+ c.action do |_, options|
75
76
  IptablesWeb::Configuration.load(options.config) if options.config
76
77
  IptablesWeb::Model::Node.handshake do
77
- iptables = IptablesWeb::Iptables.new
78
- iptables.restore(IptablesWeb::Model::AccessRule.all)
78
+ rules = IptablesWeb::Model::AccessRule.all
79
+ if options.print
80
+ say rules.map(&:to_s).join("\n")
81
+ else
82
+ iptables = IptablesWeb::Iptables.new
83
+ iptables.restore(rules)
84
+ end
79
85
  end
80
86
  end
81
87
  end
@@ -5,7 +5,6 @@ module IptablesWeb
5
5
 
6
6
  def restore(access_rules)
7
7
  temp_file = Tempfile.new('rules')
8
- puts render(access_rules)
9
8
  temp_file.write render(access_rules)
10
9
  temp_file.rewind
11
10
  execute("iptables-restore -c < #{temp_file.path}")
@@ -1,53 +1,50 @@
1
+ require 'shellwords'
1
2
  module IptablesWeb
2
3
  module Model
3
4
  class AccessRule < Base
4
5
  self.element_name = 'access_rule'
5
6
 
6
- MAPPING = {
7
- chain: 'INPUT',
8
- target_chain: 'ACCEPT',
9
- protocol: '-p {value}',
10
- port: '--dport {value}',
11
- ip: '-s {value}',
12
- description: '-m comment --comment "{value}"'
13
- }
7
+ SUPPORTED_PROTOCOLS = %w(tcp udp)
14
8
 
15
9
  def to_s
16
- command = %w(-A INPUT)
17
- self.attributes.each do |name, value|
18
-
19
- case name.to_sym
20
- when :port
21
- next unless value
22
- if value.include?(',')
23
- command << '-m'
24
- command << 'multiport'
25
- command << '--dports'
10
+ protocols = protocol.to_s.downcase == 'all' ? SUPPORTED_PROTOCOLS : [protocol]
11
+ protocols.map do |protocol|
12
+ command = %w(-A INPUT)
13
+ self.attributes.each do |name, value|
14
+ case name.to_sym
15
+ when :port
16
+ next if value.to_s.empty? || !value
17
+ if value.include?(',')
18
+ command << '-m'
19
+ command << 'multiport'
20
+ command << '--dports'
21
+ command << value
22
+ else
23
+ command << '--dport'
24
+ command << value
25
+ end
26
+ when :ip
27
+ command << '-s'
26
28
  command << value
29
+ when :protocol
30
+ next unless protocol
31
+ command << '-p'
32
+ command << protocol
33
+ when :description
34
+ if value
35
+ command << '-m'
36
+ command << 'comment'
37
+ command << '--comment'
38
+ command << ::Shellwords.escape(value)
39
+ end
27
40
  else
28
- command << '--dport'
29
- command << value
30
- end
31
- when :ip
32
- command << '-s'
33
- command << value
34
- when :protocol
35
- command << '-p'
36
- command << value
37
- when :description
38
- if value
39
- command << '-m'
40
- command << 'comment'
41
- command << '--comment'
42
- command << Shellwords.escape(value)
43
- end
44
- else
45
- #skip
41
+ #skip
42
+ end
46
43
  end
47
- end
48
- command << '-j'
49
- command << 'ACCEPT'
50
- command.join(' ')
44
+ command << '-j'
45
+ command << 'ACCEPT'
46
+ command.join(' ')
47
+ end.join("\n")
51
48
  # -A INPUT -s 88.150.233.48/29 -p tcp -m tcp --dport 9200 -j ACCEPT
52
49
  end
53
50
 
@@ -7,7 +7,7 @@ module IptablesWeb
7
7
  def self.handshake
8
8
  node = find('current')
9
9
  node.ips = []
10
- System.get_ifaddrs.each do |interface, config|
10
+ ::System.get_ifaddrs.each do |interface, config|
11
11
  next if interface.to_s.include?('lo')
12
12
  node.ips.push({
13
13
  interface: interface,
@@ -1,3 +1,3 @@
1
1
  module IptablesWeb
2
- VERSION = "0.1.0"
2
+ VERSION = '0.2.0.beta1'
3
3
  end
data/lib/iptables_web.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'iptables_web/version'
2
2
  require 'iptables_web/configuration'
3
+ require 'system/getifaddrs'
3
4
  require 'iptables_web/mixin/sudo'
4
5
  require 'iptables_web/model/base'
5
6
  require 'iptables_web/model/access_rule'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iptables-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - NikolayMurga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-06 00:00:00.000000000 Z
11
+ date: 2014-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: system-getifaddrs
@@ -115,12 +115,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
115
  version: '0'
116
116
  required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  requirements:
118
- - - '>='
118
+ - - '>'
119
119
  - !ruby/object:Gem::Version
120
- version: '0'
120
+ version: 1.3.1
121
121
  requirements: []
122
122
  rubyforge_project:
123
- rubygems_version: 2.2.2
123
+ rubygems_version: 2.4.5
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: Write a short summary. Required.