diff options
Diffstat (limited to 'misc/freeswitch/scripts')
-rw-r--r-- | misc/freeswitch/scripts/dialplan/functions.lua | 2 | ||||
-rw-r--r-- | misc/freeswitch/scripts/phones/phone.lua | 58 |
2 files changed, 42 insertions, 18 deletions
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 |