From 55a0d5ce38f99226174f358279c02178eacd75d7 Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 23 Dec 2012 16:04:05 +0100 Subject: login/logout methods --- misc/freeswitch/scripts/dialplan/functions.lua | 2 +- misc/freeswitch/scripts/phones/phone.lua | 58 ++++++++++++++++++-------- 2 files changed, 42 insertions(+), 18 deletions(-) (limited to 'misc/freeswitch') 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..4a32c37 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 @@ -82,7 +101,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 +110,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 -- cgit v1.2.3 From eea25f2f08c37593d7057a8af78412cb6b72c671 Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 23 Dec 2012 16:06:07 +0100 Subject: obsolete methods deleted --- misc/freeswitch/scripts/phones/phone.lua | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/phones/phone.lua b/misc/freeswitch/scripts/phones/phone.lua index 4a32c37..bc2aa3d 100644 --- a/misc/freeswitch/scripts/phones/phone.lua +++ b/misc/freeswitch/scripts/phones/phone.lua @@ -80,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); -- cgit v1.2.3 From e9dc7ef003b6adf68e6751b71a8347b843c54619 Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 23 Dec 2012 18:36:05 +0100 Subject: save clir value --- misc/freeswitch/scripts/dialplan/dialplan.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index f4dca9e..70edaa1 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -905,9 +905,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 +917,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); -- cgit v1.2.3 From 644af185f879b957d94b7e0207fdeff1d3132767 Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 23 Dec 2012 18:36:45 +0100 Subject: save clir value --- misc/freeswitch/scripts/common/call_history.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/common/call_history.lua b/misc/freeswitch/scripts/common/call_history.lua index c5bc0bf..364cfbf 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 common.str.to_b(event:getHeader('variable_gs_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 -- cgit v1.2.3 From 98fe29192d3fb3f79ad8913b73c89b6e7f234eb4 Mon Sep 17 00:00:00 2001 From: spag Date: Mon, 24 Dec 2012 15:10:03 +0100 Subject: typo --- misc/freeswitch/scripts/dialplan/dialplan.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index 70edaa1..bb4ad9f 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -905,7 +905,7 @@ 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; -- cgit v1.2.3 From 66e54fe90fa3a759a5e33cd018703992da475c63 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 27 Dec 2012 23:35:17 +0100 Subject: variable context fixed --- misc/freeswitch/scripts/common/call_history.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/common/call_history.lua b/misc/freeswitch/scripts/common/call_history.lua index 364cfbf..7a9ac07 100644 --- a/misc/freeswitch/scripts/common/call_history.lua +++ b/misc/freeswitch/scripts/common/call_history.lua @@ -114,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 and not common.str.to_b(event:getHeader('variable_gs_clir')) 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 -- cgit v1.2.3 From 43199a00bcb0cc93775a3e3b71abea476a33a1a7 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 27 Dec 2012 23:54:40 +0100 Subject: save date and time to caller record --- misc/freeswitch/scripts/dialplan/dialplan.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index bb4ad9f..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; -- cgit v1.2.3