Class: FIDIUS::EvasionDB::Knowledge::IdsRule

Inherits:
Connection
  • Object
show all
Defined in:
lib/evasion-db/knowledge/ids_rule.rb

Class Method Summary collapse

Class Method Details

.create_if_not_exists(text, sort = 0) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/evasion-db/knowledge/ids_rule.rb', line 18

def self.create_if_not_exists(text,sort=0)
  q = self.sub_query_for_insert(text,sort)
  begin
    self.connection.execute("INSERT IGNORE INTO ids_rules (rule_text,rule_hash,sort) VALUES #{q};")
  rescue
    puts $!.message
    puts "trying without IGNORE command"
    begin
      self.connection.execute("INSERT INTO ids_rules (rule_text,rule_hash,sort) VALUES #{q};")
    rescue
      puts $!.message
    end
  end
end

.exists?(text) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/evasion-db/knowledge/ids_rule.rb', line 7

def self.exists?(text)
  self.find_by_rule_hash(Digest::MD5.hexdigest(text)) != nil
end

.sub_query_for_insert(text, sort) ⇒ Object



11
12
13
14
15
16
# File 'lib/evasion-db/knowledge/ids_rule.rb', line 11

def self.sub_query_for_insert(text,sort)
  h = Digest::MD5.hexdigest(text)
  # escape single quotes
  text = self.sanitize(text)
  return "(#{text},'#{h}',#{sort})"
end

.table_nameObject



3
4
5
# File 'lib/evasion-db/knowledge/ids_rule.rb', line 3

def self.table_name
  "ids_rules"
end