class Tablomat::IPSet
The IPSet
interface
Attributes
ipset_bin[RW]
Public Class Methods
new()
click to toggle source
# File lib/tablomat/ipset.rb, line 15 def initialize @ipset_bin = 'ipset' @ipset_bin = "sudo #{@ipset_bin}" if Etc.getlogin != 'root' @sets = {} end
Public Instance Methods
add(set_name:, entry_data:, add_options: '', exist: false)
click to toggle source
# 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: add_options, exist: exist) end
create(set_name:, type:, create_options: '', rangefrom: '', rangeto: '')
click to toggle source
# File lib/tablomat/ipset.rb, line 59 def create(set_name:, type:, create_options: '', rangefrom: '', rangeto: '') set(set_name).create(type: type, create_options: create_options, rangefrom: rangefrom, rangeto: rangeto) end
del(set_name:, entry_data:, exist: false)
click to toggle source
# 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:)
click to toggle source
# File lib/tablomat/ipset.rb, line 67 def destroy(set_name:) set(set_name).destroy end
destroy_all(really_all = false)
click to toggle source
# 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)
click to toggle source
# File lib/tablomat/ipset.rb, line 37 def exec(cmd) Exec.exec(cmd) rescue StandardError => e raise IPSetError.new, e.message end
matchset(flags:, option: '', negate: false, negate_option: false, set_name:)
click to toggle source
# 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
set(name, &block)
click to toggle source
# File lib/tablomat/ipset.rb, line 28 def set(name, &block) name = name.to_s.downcase (@sets[name] || Set.new(self, name)).tap do |set| @sets[name] = set block&.call(set) end @sets[name] end