9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/iptables_web/model/access_rule.rb', line 9
def to_s
protocols = protocol.to_s.downcase == 'all' ? SUPPORTED_PROTOCOLS : [protocol]
protocols.map do |protocol|
self.resolved_ips.map do |ip|
command = %w(-A INPUT)
self.attributes.each do |name, value|
case name.to_sym
when :port
next if value.to_s.empty? || !value
if value.include?(',')
command << '-m'
command << 'multiport'
command << '--dports'
command << value
else
command << '--dport'
command << value
end
when :protocol
next unless protocol
command << '-p'
command << protocol
when :description
if value
command << '-m'
command << 'comment'
command << '--comment'
command << "\"#{::Shellwords.escape(value)}\""
end
else
end
end
command << '-s'
command << ip
command << '-j'
command << 'ACCEPT'
command.join(' ')
end
end.join("\n")
end
|