summaryrefslogtreecommitdiff
path: root/misc/freeswitch
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-28 20:27:04 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-28 20:27:04 +0100
commitf3c3e77eaa2b82567f02601b6f66177208674181 (patch)
tree1946390f7f697e80fcdab4164ad620d507b6a1fe /misc/freeswitch
parent3e76142566ad8f55a64a88fe5c19e7d0ec7c11c0 (diff)
parent8d20201910b1915cffa495e6474d50f9c8e8331d (diff)
Merge branch 'develop'5.0.1
Diffstat (limited to 'misc/freeswitch')
-rw-r--r--misc/freeswitch/scripts/common/call_history.lua9
-rw-r--r--misc/freeswitch/scripts/dialplan/dialplan.lua8
-rw-r--r--misc/freeswitch/scripts/dialplan/functions.lua2
-rw-r--r--misc/freeswitch/scripts/phones/phone.lua72
4 files changed, 53 insertions, 38 deletions
diff --git a/misc/freeswitch/scripts/common/call_history.lua b/misc/freeswitch/scripts/common/call_history.lua
index c5bc0bf..7a9ac07 100644
--- a/misc/freeswitch/scripts/common/call_history.lua
+++ b/misc/freeswitch/scripts/common/call_history.lua
@@ -70,8 +70,6 @@ function CallHistory.insert_event(self, uuid, account_type, account_id, entry_ty
call_history.callee_id_name = common.str.to_sql(event:getHeader('variable_effective_callee_id_name'));
call_history.result = common.str.to_sql(event:getHeader('variable_hangup_cause'));
call_history.start_stamp = 'FROM_UNIXTIME(' .. math.floor(common.str.to_i(event:getHeader('Caller-Channel-Created-Time')) / 1000000) .. ')';
- call_history.caller_account_type = common.str.to_sql(camelize_type(event:getHeader('variable_gs_caller_account_type') or event:getHeader('variable_gs_account_type')));
- call_history.caller_account_id = common.str.to_sql(event:getHeader('variable_gs_caller_account_id') or event:getHeader('variable_gs_account_id'));
call_history.auth_account_type = common.str.to_sql(camelize_type(event:getHeader('variable_gs_auth_account_type')));
call_history.auth_account_id = common.str.to_sql(event:getHeader('variable_gs_auth_account_id'));
call_history.callee_account_type = common.str.to_sql(camelize_type(event:getHeader('variable_gs_destination_type')));
@@ -79,6 +77,11 @@ function CallHistory.insert_event(self, uuid, account_type, account_id, entry_ty
call_history.destination_number = common.str.to_sql(event:getHeader('variable_gs_destination_number'));
call_history.forwarding_service = common.str.to_sql(event:getHeader('variable_gs_forwarding_service'));
+ if not common.str.to_b(event:getHeader('variable_gs_clir')) then
+ call_history.caller_account_type = common.str.to_sql(camelize_type(event:getHeader('variable_gs_caller_account_type') or event:getHeader('variable_gs_account_type')));
+ call_history.caller_account_id = common.str.to_sql(event:getHeader('variable_gs_caller_account_id') or event:getHeader('variable_gs_account_id'));
+ end
+
if common.str.to_s(event:getHeader('variable_gs_call_service')) == 'pickup' then
call_history.forwarding_service = common.str.to_sql('pickup');
end
@@ -111,7 +114,7 @@ function CallHistory.insert_forwarded(self, uuid, account_type, account_id, call
call_history.result = common.str.to_sql(result.cause or 'UNSPECIFIED');
call_history.start_stamp = 'FROM_UNIXTIME(' .. math.floor(caller:to_i('created_time') / 1000000) .. ')';
- if caller.account then
+ if caller.account and not caller.clir then
call_history.caller_account_type = common.str.to_sql(camelize_type(caller.account.class));
call_history.caller_account_id = common.str.to_sql(caller.account.id);
end
diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua
index f4dca9e..391f5bf 100644
--- a/misc/freeswitch/scripts/dialplan/dialplan.lua
+++ b/misc/freeswitch/scripts/dialplan/dialplan.lua
@@ -872,6 +872,8 @@ function Dialplan.run(self, destination)
self.caller:set_variable('gs_save_cdr', true);
self.caller:set_variable('gs_call_service', 'dial');
self.caller.session:setAutoHangup(false);
+ self.caller.date = os.date('%y%m%d%w');
+ self.caller.time = os.date('%H%M%S');
self.routes = common.configuration_file.get('/opt/freeswitch/scripts/ini/routes.ini');
self.caller.domain_local = self.domain;
@@ -905,9 +907,8 @@ function Dialplan.run(self, destination)
end
end
- self.log:info('DIALPLAN start - caller_id: ',self.caller.caller_id_number, ' "', self.caller.caller_id_name,'"',
- ', number: ', destination.number);
-
+ self.log:info('DIALPLAN start - caller_id: ',self.caller.caller_id_number, ' "', self.caller.caller_id_name, '" , number: ', destination.number);
+
local result = { continue = false };
local loop = self.caller.loop_count;
while self.caller:ready() and loop < self.max_loops do
@@ -918,6 +919,7 @@ function Dialplan.run(self, destination)
' - destination: ', destination.type, '=', destination.id, '/', destination.uuid,'@', destination.node_id,
', number: ', destination.number);
+ self.caller:set_variable('gs_clir', self.caller.clir);
self.caller:set_variable('gs_destination_type', destination.type);
self.caller:set_variable('gs_destination_id', destination.id);
self.caller:set_variable('gs_destination_uuid', destination.uuid);
diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua
index c104f89..9a89857 100644
--- a/misc/freeswitch/scripts/dialplan/functions.lua
+++ b/misc/freeswitch/scripts/dialplan/functions.lua
@@ -31,7 +31,7 @@ function Functions.dialplan_function(self, caller, dialed_number)
local fid = tostring(parameters[2]);
local result = { continue = false, code = 404, phrase = 'Function not found', no_cdr = true };
- self.log:debug('DIALPLAN_DUNCTION - execute: ', dialed_number);
+ self.log:debug('DIALPLAN_FUNCTION - execute: ', dialed_number);
if fid == "ta" then
result = self:transfer_all(caller, parameters[3]);
diff --git a/misc/freeswitch/scripts/phones/phone.lua b/misc/freeswitch/scripts/phones/phone.lua
index 5cd210b..bc2aa3d 100644
--- a/misc/freeswitch/scripts/phones/phone.lua
+++ b/misc/freeswitch/scripts/phones/phone.lua
@@ -18,6 +18,26 @@ function Phone.new(self, arg)
end
+function Phone.list_by_sql(self, sql_query)
+ local account_phones = {};
+
+ self.database:query(sql_query, function(account_entry)
+ local phone = Phone:new(self, {object = parent_class});
+ phone.record = account_entry;
+ phone.record.ieee_name = common.str.downcase(account_entry.ieee_name);
+
+ if phone.record.ieee_name == 'snom technology ag' then
+ require 'phones.snom'
+ phone.model = phones.snom.Snom:new();
+ elseif account_entry.ieee_name == 'siemens enterprise communicationsgmbh & co. kg' then
+ require 'phones.siemens'
+ phone.model = phones.siemens.Siemens:new();
+ end
+ table.insert(account_phones, phone);
+ end)
+
+ return account_phones;
+end
-- Find a hot-deskable phone by sip-account
function Phone.find_all_hot_deskable_by_account(self, account_id)
@@ -25,7 +45,7 @@ function Phone.find_all_hot_deskable_by_account(self, account_id)
local sql_query = 'SELECT \
`b`.`id`, `b`.`mac_address`, `b`.`ip_address`, `b`.`http_user`, `b`.`http_password`, `b`.`phoneable_type`, `b`.`phoneable_id`, \
- `d`.`ieee_name` \
+ `b`.`tenant_id`, `b`.`fallback_sip_account_id`, `d`.`ieee_name` \
FROM `phone_sip_accounts` `a` \
JOIN `phones` `b` ON `a`.`phone_id` = `b`.`id` \
JOIN `phone_models` `c` ON `b`.`phone_model_id` = `c`.`id` \
@@ -35,22 +55,21 @@ function Phone.find_all_hot_deskable_by_account(self, account_id)
AND `d`.`state` = "active" \
AND `a`.`sip_account_id` = ' .. tonumber(account_id);
- local account_phones = {};
+ local account_phones = self:list_by_sql(sql_query);
- self.database:query(sql_query, function(account_entry)
- local phone = Phone:new(self, {object = parent_class});
- phone.record = account_entry;
- phone.record.ieee_name = common.str.downcase(account_entry.ieee_name);
+ if #account_phones == 0 then
+ sql_query = 'SELECT `b`.`id`, `b`.`mac_address`, `b`.`ip_address`, `b`.`http_user`, `b`.`http_password`, `b`.`phoneable_type`, `b`.`phoneable_id`, \
+ `b`.`tenant_id`, `b`.`fallback_sip_account_id`, `d`.`ieee_name` \
+ FROM `phones` `b` \
+ JOIN `phone_models` `c` ON `b`.`phone_model_id` = `c`.`id` \
+ JOIN `manufacturers` `d` ON `c`.`manufacturer_id` = `d`.`id` \
+ WHERE `b`.`hot_deskable` IS TRUE \
+ AND `c`.`state` = "active" \
+ AND `d`.`state` = "active" \
+ AND `b`.`fallback_sip_account_id` = ' .. tonumber(account_id);
- if phone.record.ieee_name == 'snom technology ag' then
- require 'phones.snom'
- phone.model = phones.snom.Snom:new();
- elseif account_entry.ieee_name == 'siemens enterprise communicationsgmbh & co. kg' then
- require 'phones.siemens'
- phone.model = phones.siemens.Siemens:new();
- end
- table.insert(account_phones, phone);
- end)
+ account_phones = self:list_by_sql(sql_query);
+ end
return account_phones;
end
@@ -61,20 +80,6 @@ function Phone.find_hot_deskable_by_account(self, account_id)
end
-function Phone.tenant_id_get(self)
- local sql_query = 'SELECT `c`.`sip_accountable_id` \
- FROM `phones` `a` LEFT JOIN `phone_sip_accounts` `b` ON `a`.`id` = `b`.`phone_id` \
- JOIN `sip_accounts` `c` ON `b`.`sip_account_id` = `c`.`id` AND `sip_accountable_type` = "Tenant" \
- WHERE `a`.`id` = ' .. tonumber(self.record.id) .. ' LIMIT 1';
-
- local tenant_id = nil;
- self.database:query(sql_query, function(tenant_entry)
- tenant_id = tenant_entry.sip_accountable_id;
- end)
-
- return tenant_id;
-end
-
function Phone.phoneable_set(self, phoneable_id, phoneable_type)
sql_query = 'UPDATE `phones` SET `phoneable_type` = "' .. phoneable_type ..'", `phoneable_id` = ' .. phoneable_id .. ' \
WHERE `id` = ' .. tonumber(self.record.id);
@@ -82,7 +87,7 @@ function Phone.phoneable_set(self, phoneable_id, phoneable_type)
end
function Phone.logout(self, account_id)
- local tenant_id = self:tenant_id_get();
+ local tenant_id = tonumber(self.record.tenant_id);
if not tenant_id then
self.log:info('PHONE_LOGOUT - tenant not found');
@@ -91,7 +96,12 @@ function Phone.logout(self, account_id)
self:phoneable_set(tenant_id, 'Tenant');
- sql_query = 'DELETE FROM `phone_sip_accounts` WHERE `sip_account_id` = ' .. tonumber(account_id);
+ if account_id then
+ sql_query = 'DELETE FROM `phone_sip_accounts` WHERE `sip_account_id` = ' .. tonumber(account_id);
+ self.database:query(sql_query);
+ end
+
+ sql_query = 'DELETE FROM `phone_sip_accounts` WHERE `phone_id` = ' .. self.record.id;
return self.database:query(sql_query);
end