summaryrefslogtreecommitdiff
path: root/misc/freeswitch
diff options
context:
space:
mode:
Diffstat (limited to 'misc/freeswitch')
-rw-r--r--misc/freeswitch/conf/freeswitch.xml5
-rw-r--r--misc/freeswitch/scripts/common/intruder.lua43
-rw-r--r--misc/freeswitch/scripts/common/perimeter.lua32
-rw-r--r--misc/freeswitch/scripts/common/sip_account.lua6
-rw-r--r--misc/freeswitch/scripts/dialplan/dialplan.lua16
-rw-r--r--misc/freeswitch/scripts/dialplan/voicemail.lua9
-rw-r--r--misc/freeswitch/scripts/event/perimeter_defense.lua24
7 files changed, 110 insertions, 25 deletions
diff --git a/misc/freeswitch/conf/freeswitch.xml b/misc/freeswitch/conf/freeswitch.xml
index f72651f..a2c2bf5 100644
--- a/misc/freeswitch/conf/freeswitch.xml
+++ b/misc/freeswitch/conf/freeswitch.xml
@@ -914,7 +914,6 @@
<match>
<action function="play-file" data="ivr/ivr-you_are_number.wav"/>
<action function="say" data="$1" method="pronounced" type="number"/>
- <action function="play-file" data="ivr/ivr-in_line.wav"/>
</match>
</input>
</macro>
@@ -923,7 +922,6 @@
<match>
<action function="play-file" data="ivr/ivr-you_are_number.wav"/>
<action function="say" data="1" method="pronounced" type="number"/>
- <action function="play-file" data="ivr/ivr-in_line.wav"/>
<action function="break"/>
</match>
</input>
@@ -931,7 +929,6 @@
<match>
<action function="play-file" data="ivr/ivr-you_are_number.wav"/>
<action function="say" data="$1" method="pronounced" type="number"/>
- <action function="play-file" data="ivr/ivr-in_line.wav"/>
<action function="play-file" data="ivr/ivr-thank_you_for_holding.wav"/>
</match>
</input>
@@ -941,7 +938,6 @@
<match>
<action function="play-file" data="ivr/ivr-you_are_number.wav"/>
<action function="say" data="1" method="pronounced" type="number"/>
- <action function="play-file" data="ivr/ivr-in_line.wav"/>
<action function="break"/>
</match>
</input>
@@ -949,7 +945,6 @@
<match>
<action function="play-file" data="ivr/ivr-you_are_number.wav"/>
<action function="say" data="$1" method="pronounced" type="number"/>
- <action function="play-file" data="ivr/ivr-in_line.wav"/>
<action function="play-file" data="ivr/ivr-thank_you_for_holding.wav"/>
</match>
</input>
diff --git a/misc/freeswitch/scripts/common/intruder.lua b/misc/freeswitch/scripts/common/intruder.lua
index 083ec37..7d12155 100644
--- a/misc/freeswitch/scripts/common/intruder.lua
+++ b/misc/freeswitch/scripts/common/intruder.lua
@@ -49,3 +49,46 @@ function Intruder.update_blacklist(self, event)
self.database:insert_or_update('intruders', intruder_record, { created_at = false, comment = false });
end
+
+
+function Intruder.sources_list(self, key)
+ local sql_query = nil;
+
+ if key then
+ sql_query = 'SELECT * FROM `intruders` WHERE `key` = ' .. self.database:escape(key, '"') .. ' LIMIT 1';
+ else
+ sql_query = 'SELECT * FROM `intruders`';
+ end
+
+ local sources = {};
+ local sources_count = 0;
+ local blacklist_count = 0;
+ local whitelist_count = 0;
+
+ self.database:query(sql_query, function(record)
+ sources[record.key] = {
+ ignore = (record.list_type == 'whitelist'),
+ contact_first = 0,
+ contact_last = 0,
+ contact_count = tonumber(record.contact_count) or 0,
+ span_contact_count = 0,
+ span_start = 0,
+ points = tonumber(record.points) or 0,
+ banned = tonumber(record.bans) or 0,
+ };
+ sources_count = sources_count + 1;
+ if record.list_type == 'whitelist' then
+ whitelist_count = whitelist_count + 1;
+ elseif record.list_type == 'blacklist' then
+ blacklist_count = blacklist_count + 1;
+ end
+ end);
+
+ self.log:info('[intruder] INTRUDER_LIST - entries loaded: ', sources_count, ', blacklist: ', blacklist_count, ', whitelist: ', whitelist_count);
+
+ if key then
+ return sources[key];
+ end
+
+ return sources;
+end
diff --git a/misc/freeswitch/scripts/common/perimeter.lua b/misc/freeswitch/scripts/common/perimeter.lua
index 0815d33..8ad38d3 100644
--- a/misc/freeswitch/scripts/common/perimeter.lua
+++ b/misc/freeswitch/scripts/common/perimeter.lua
@@ -94,12 +94,24 @@ end
function Perimeter.check(self, event)
- if not event or not event.key then
- self.log:warning('[perimeter] PERIMETER_CHECK - no event/key');
+ if not type(event) == 'list' then
+ self.log:warning('[perimeter] PERIMETER_CHECK - no event data');
+ return;
+ end
+ if not event.key then
+ self.log:warning('[perimeter] PERIMETER_CHECK - no key');
+ for key, value in pairs() do
+ self.log:debug('[perimeter] PERIMETER_CHECK event_data - "', key, '" = "', value, '"');
+ end
return;
end
- event.record = self:record_load(event);
+ event.record = self:record_load(event);
+
+ if event.record.ignore then
+ return
+ end
+
if event.record.banned <= self.ban_tries then
for check_name, check_points in pairs(self.checks[event.action]) do
if self.checks_available[check_name] then
@@ -239,3 +251,17 @@ function Perimeter.expand_variables(self, line, variables)
return variables[captured] or '';
end))
end
+
+
+function Perimeter.action_db_rescan(self, record)
+ require 'common.str';
+ require 'common.intruder';
+
+ if common.str.blank(record.key) then
+ self.log:info('[perimeter] PERIMETER rescan entire sources database');
+ self.sources = common.intruder.Intruder:new{ log = self.log, database = self.database }:sources_list();
+ else
+ self.log:info('[perimeter] PERIMETER rescan sources database - key: ', record.key);
+ self.sources[record.key] = common.intruder.Intruder:new{ log = self.log, database = self.database }:sources_list(record.key);
+ end
+end
diff --git a/misc/freeswitch/scripts/common/sip_account.lua b/misc/freeswitch/scripts/common/sip_account.lua
index 6cc7d25..e7ee0d7 100644
--- a/misc/freeswitch/scripts/common/sip_account.lua
+++ b/misc/freeswitch/scripts/common/sip_account.lua
@@ -130,9 +130,9 @@ end
function SipAccount.call_state(self)
- local sql_query = 'SELECT `callstate` FROM `detailed_calls` \
- WHERE `presence_id` LIKE "' .. self.record.auth_name .. '@%" \
- OR `b_presence_id` LIKE "' .. self.record.auth_name .. '@%" \
+ local sql_query = 'SELECT `callstate` FROM `calls_active` \
+ WHERE `sip_account_id` = ' .. self.id .. ' \
+ OR `b_sip_account_id` = ' .. self.id .. ' \
LIMIT 1';
return self.database:query_return_value(sql_query);
diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua
index ffad4da..4cc2245 100644
--- a/misc/freeswitch/scripts/dialplan/dialplan.lua
+++ b/misc/freeswitch/scripts/dialplan/dialplan.lua
@@ -579,13 +579,17 @@ end
function Dialplan.voicemail(self, destination)
- if not self.caller.auth_account or self.caller.auth_account.class ~= 'sipaccount' then
- self.log:error('VOICEMAIL - incompatible destination');
- return { continue = false, code = 404, phrase = 'Mailbox not found' }
- end
-
+ require 'common.str';
require 'dialplan.voicemail'
- local voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database }:find_by_sip_account_id(self.caller.auth_account.id);
+
+ local voicemail_account = nil;
+
+ local sip_account_id
+ if not common.str.blank(destination.number) and false then
+ voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database }:find_by_number(destination.number);
+ elseif self.caller.auth_account and self.caller.auth_account.class == 'sipaccount' then
+ voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database }:find_by_sip_account_id(self.caller.auth_account.id);
+ end
if not voicemail_account then
self.log:error('VOICEMAIL - no mailbox');
diff --git a/misc/freeswitch/scripts/dialplan/voicemail.lua b/misc/freeswitch/scripts/dialplan/voicemail.lua
index ae7d0a1..caeeb48 100644
--- a/misc/freeswitch/scripts/dialplan/voicemail.lua
+++ b/misc/freeswitch/scripts/dialplan/voicemail.lua
@@ -66,15 +66,14 @@ function Voicemail.find_by_name(self, account_name)
return voicemail_account
end
--- Find Voicemail account by name
+-- Find Voicemail account by number
function Voicemail.find_by_number(self, phone_number)
local sip_account = nil;
require "common.phone_number"
- local phone_number_class = common.phone_number.PhoneNumber:new{ log = self.log, database = self.database };
- local destination_number_object = phone_number_class:find_by_number(phone_number);
- if destination_number_object and destination_number_object.record.phone_numberable_type == "SipAccount" then
- return Voicemail:find_by_sip_account_id(destination_number_object.record.phone_numberable_id);
+ local destination_number_object = common.phone_number.PhoneNumber:new{ log = self.log, database = self.database }:find_by_number(phone_number);
+ if destination_number_object and destination_number_object.record.phone_numberable_type:lower() == "sipaccount" then
+ return self:find_by_sip_account_id(destination_number_object.record.phone_numberable_id);
end
return false;
diff --git a/misc/freeswitch/scripts/event/perimeter_defense.lua b/misc/freeswitch/scripts/event/perimeter_defense.lua
index acdfa8d..5bd124b 100644
--- a/misc/freeswitch/scripts/event/perimeter_defense.lua
+++ b/misc/freeswitch/scripts/event/perimeter_defense.lua
@@ -31,9 +31,10 @@ end
function PerimeterDefense.event_handlers(self)
return {
CUSTOM = {
- ['sofia::pre_register'] = self.sofia_pre_register,
- ['sofia::register_attempt'] = self.sofia_register_attempt,
- ['sofia::register_failure'] = self.sofia_register_failure,
+ ['sofia::pre_register'] = self.sofia_pre_register,
+ ['sofia::register_attempt'] = self.sofia_register_attempt,
+ ['sofia::register_failure'] = self.sofia_register_failure,
+ ['perimeter::control'] = self.perimeter_control,
},
CHANNEL_HANGUP = { [true] = self.channel_hangup },
};
@@ -112,3 +113,20 @@ function PerimeterDefense.channel_hangup(self, event)
local record = self:to_call_record(event, 'channel_hangup');
self.perimeter:check(record);
end
+
+
+function PerimeterDefense.control_to_action(self, event)
+ return {
+ key = event:getHeader('key'),
+ };
+end
+
+
+function PerimeterDefense.perimeter_control(self, event)
+ local action = event:getHeader('action');
+ if self.perimeter['action_' .. action] then
+ self.perimeter['action_' .. action](self.perimeter, self:control_to_action(event))
+ else
+ self.log:error('[perimeter_defense] PERIMETER_DEFENSE - could not execute action: ', action);
+ end
+end