summaryrefslogtreecommitdiff
path: root/misc/freeswitch/scripts/common/intruder.lua
blob: 083ec37040fb90bf4a58834bd3448332e48c6520 (plain)
1
2
3
4
5
6
7
8
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
-- Gemeinschaft 5 module: intruder class
-- (c) AMOOMA GmbH 2013
--

module(...,package.seeall)


Intruder = {}


function Intruder.new(self, arg)
  arg = arg or {}
  object = arg.object or {}
  setmetatable(object, self);
  self.__index = self;
  self.log = arg.log;
  self.class = 'intruder'
  self.database = arg.database;

  return object;
end


function Intruder.update_blacklist(self, event)
  local intruder_record = {
    list_type = 'blacklist',
    key = event.key,
    points = event.points,
    bans = event.record.banned,
    contact_ip = event.received_ip,
    contact_port = event.received_port,
    contact_count = event.record.contact_count + 1,
    contact_last = { 'FROM_UNIXTIME(' .. tostring(math.floor(event.timestamp/1000000)) .. ')', raw = true },
    contacts_per_second = event.contacts_per_second,
    contacts_per_second_max = event.contacts_per_second_max,
    user_agent = event.user_agent,
    to_user = event.to_user,
    comment = 'Permimeter',
    created_at = {'NOW()', raw = true },
    updated_at = {'NOW()', raw = true },
  };

  if tonumber(event.ban_time) then
    intruder_record.ban_last = { 'FROM_UNIXTIME(' .. event.ban_time .. ')', raw = true };
  end
  if tonumber(event.ban_end) then
    intruder_record.ban_end = { 'FROM_UNIXTIME(' .. event.ban_end .. ')', raw = true };
  end

  self.database:insert_or_update('intruders', intruder_record, { created_at = false, comment = false });
end