Class: Tablomat::IPSet
- Inherits:
-
Object
- Object
- Tablomat::IPSet
- Extended by:
- Exec
- Defined in:
- lib/tablomat/ipset.rb,
lib/tablomat/ipset/set.rb,
lib/tablomat/ipset/entry.rb
Overview
The IPSet interface
Defined Under Namespace
Instance Attribute Summary collapse
-
#ipset_bin ⇒ Object
Returns the value of attribute ipset_bin.
Instance Method Summary collapse
- #add(set_name:, entry_data:, add_options: '', exist: false) ⇒ Object
- #create(set_name:, type:, create_options: '', rangefrom: '', rangeto: '') ⇒ Object
- #del(set_name:, entry_data:, exist: false) ⇒ Object
- #destroy(set_name:) ⇒ Object
- #destroy_all(really_all = false) ⇒ Object
- #exec(cmd) ⇒ Object
-
#initialize ⇒ IPSet
constructor
A new instance of IPSet.
- #matchset(flags:, option: '', negate: false, negate_option: false, set_name:) ⇒ Object
- #set(name, &block) ⇒ Object
Methods included from Exec
Constructor Details
#initialize ⇒ IPSet
Returns a new instance of IPSet.
15 16 17 18 19 |
# File 'lib/tablomat/ipset.rb', line 15 def initialize @ipset_bin = 'ipset' @ipset_bin = "sudo #{@ipset_bin}" if Etc.getlogin != 'root' @sets = {} end |
Instance Attribute Details
#ipset_bin ⇒ Object
Returns the value of attribute ipset_bin.
13 14 15 |
# File 'lib/tablomat/ipset.rb', line 13 def ipset_bin @ipset_bin end |
Instance Method Details
#add(set_name:, entry_data:, add_options: '', exist: false) ⇒ Object
55 56 57 |
# File 'lib/tablomat/ipset.rb', line 55 def add(set_name:, entry_data:, add_options: '', exist: false) set(set_name).add(entry_data: entry_data, add_options: , exist: exist) end |
#create(set_name:, type:, create_options: '', rangefrom: '', rangeto: '') ⇒ Object
59 60 61 |
# File 'lib/tablomat/ipset.rb', line 59 def create(set_name:, type:, create_options: '', rangefrom: '', rangeto: '') set(set_name).create(type: type, create_options: , rangefrom: rangefrom, rangeto: rangeto) end |
#del(set_name:, entry_data:, exist: false) ⇒ Object
63 64 65 |
# File 'lib/tablomat/ipset.rb', line 63 def del(set_name:, entry_data:, exist: false) set(set_name).del(entry_data: entry_data, exist: exist) end |
#destroy(set_name:) ⇒ Object
67 68 69 |
# File 'lib/tablomat/ipset.rb', line 67 def destroy(set_name:) set(set_name).destroy end |
#destroy_all(really_all = false) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/tablomat/ipset.rb', line 43 def destroy_all(really_all = false) # destroys all sets created in this Instance unless really_all = true if really_all command = "#{@ipset_bin} destroy" exec(command) else @sets.each do |_name, set| set.destroy if set.active end end end |
#exec(cmd) ⇒ Object
37 38 39 40 41 |
# File 'lib/tablomat/ipset.rb', line 37 def exec(cmd) Exec.exec(cmd) rescue StandardError => e raise IPSetError.new, e. end |
#matchset(flags:, option: '', negate: false, negate_option: false, set_name:) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/tablomat/ipset.rb', line 21 def matchset(flags:, option: '', negate: false, negate_option: false, set_name:) set_set = "--match-set #{set_name} #{flags}" set_set = "! #{set_set}" if negate option = "! #{option}" if negate_option "set #{set_set} #{option}" end |