diff options
author | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2012-12-17 12:01:45 +0100 |
---|---|---|
committer | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2012-12-17 12:01:45 +0100 |
commit | b80bd744ad873f6fc43018bc4bfb90677de167bd (patch) | |
tree | 072c4b0e33d442528555b82c415f5e7a1712b2b0 /misc/freeswitch/scripts/phones | |
parent | 3e706c2025ecc5523e81ad649639ef2ff75e7bac (diff) |
Start of GS5.
Diffstat (limited to 'misc/freeswitch/scripts/phones')
-rw-r--r-- | misc/freeswitch/scripts/phones/phone.lua | 114 | ||||
-rw-r--r-- | misc/freeswitch/scripts/phones/siemens.lua | 45 | ||||
-rw-r--r-- | misc/freeswitch/scripts/phones/snom.lua | 65 | ||||
-rw-r--r-- | misc/freeswitch/scripts/phones/uacsta.lua | 100 |
4 files changed, 324 insertions, 0 deletions
diff --git a/misc/freeswitch/scripts/phones/phone.lua b/misc/freeswitch/scripts/phones/phone.lua new file mode 100644 index 0000000..5cd210b --- /dev/null +++ b/misc/freeswitch/scripts/phones/phone.lua @@ -0,0 +1,114 @@ +-- Gemeinschaft 5 module: phone class +-- (c) AMOOMA GmbH 2012 +-- + +module(...,package.seeall) + +Phone = {} + +-- create phone object +function Phone.new(self, arg) + arg = arg or {} + object = arg.object or {} + setmetatable(object, self); + self.__index = self; + self.log = arg.log; + self.database = arg.database; + return object; +end + + + +-- Find a hot-deskable phone by sip-account +function Phone.find_all_hot_deskable_by_account(self, account_id) + require 'common.str' + + 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` \ + 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` \ + JOIN `manufacturers` `d` ON `c`.`manufacturer_id` = `d`.`id` \ + WHERE `b`.`hot_deskable` IS TRUE \ + AND `c`.`state` = "active" \ + AND `d`.`state` = "active" \ + AND `a`.`sip_account_id` = ' .. tonumber(account_id); + + 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 + + +function Phone.find_hot_deskable_by_account(self, account_id) + return self:find_all_hot_deskable_by_account(account_id)[1]; +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); + self.database:query(sql_query); +end + +function Phone.logout(self, account_id) + local tenant_id = self:tenant_id_get(); + + if not tenant_id then + self.log:info('PHONE_LOGOUT - tenant not found'); + return false; + end + + self:phoneable_set(tenant_id, 'Tenant'); + + sql_query = 'DELETE FROM `phone_sip_accounts` WHERE `sip_account_id` = ' .. tonumber(account_id); + return self.database:query(sql_query); +end + +function Phone.login(self, account_id, owner_id, owner_type) + self:phoneable_set(owner_id, owner_type); + sql_query = 'INSERT INTO `phone_sip_accounts` (`phone_id`, `sip_account_id`, `position`, `created_at`, `updated_at`) \ + VALUES ('.. tonumber(self.record.id) .. ', '.. tonumber(account_id) .. ', 1, NOW(), NOW())'; + + return self.database:query(sql_query); +end + +function Phone.resync(self, arg) + if not self.model then + self.log:notice('PHONE_RESYNC - unsupported phone model'); + return false; + end + + arg.ip_address = arg.ip_address or self.record.ip_address; + return self.model:resync(arg); +end
\ No newline at end of file diff --git a/misc/freeswitch/scripts/phones/siemens.lua b/misc/freeswitch/scripts/phones/siemens.lua new file mode 100644 index 0000000..71bb40a --- /dev/null +++ b/misc/freeswitch/scripts/phones/siemens.lua @@ -0,0 +1,45 @@ +-- Gemeinschaft 5 module: general siemens model class +-- (c) AMOOMA GmbH 2012 +-- + +module(...,package.seeall) + +Siemens = {} + +-- create siemens object +function Siemens.new(self, arg) + arg = arg or {} + object = arg.object or {} + setmetatable(object, self); + self.__index = self; + self.log = arg.log; + self.PHONE_HTTP_PORT = 8085; + return object; +end + +-- send reload message to phone +function Siemens.resync(self, arg) + if arg.ip_address then + return self:resync_http(arg.ip_address, arg.http_user, arg.http_password, arg.http_port); + end + + return false; +end + +-- send reload message to ip +function Siemens.resync_http(self, ip_address, http_user, http_password, http_port) + local port_str = ''; + if tonumber(http_port) then + port_str = ':' .. http_port; + end + + get_command = 'wget --no-proxy -q -O /dev/null -o /dev/null -b --tries=2 --timeout=10 --user="' .. (http_user or '') .. '" --password="' .. (http_password or '') .. '"' .. + ' wget http://' .. tostring(ip_address):gsub('[^0-9%.]', '') .. ':' .. (tonumber(http_port) or self.PHONE_HTTP_PORT) .. '/contact_dls.html/ContactDLS' .. + ' 1>>/dev/null 2>>/dev/null &'; + + result = os.execute(get_command); + + if result and tonumber(result) == 0 then + return true; + end +end diff --git a/misc/freeswitch/scripts/phones/snom.lua b/misc/freeswitch/scripts/phones/snom.lua new file mode 100644 index 0000000..80d1fce --- /dev/null +++ b/misc/freeswitch/scripts/phones/snom.lua @@ -0,0 +1,65 @@ +-- Gemeinschaft 5 module: general snom model class +-- (c) AMOOMA GmbH 2012 +-- + +module(...,package.seeall) + +Snom = {} + +-- Create Snom object +function Snom.new(self, arg) + arg = arg or {} + object = arg.object or {} + setmetatable(object, self); + self.__index = self; + self.log = arg.log; + self.reboot = arg.reboot or true; + return object; +end + +-- send reload message to phone +function Snom.resync(self, arg) + if arg.reboot == nil then + arg.reboot = self.reboot; + end + + local success = nil; + if arg.auth_name and arg.domain then + success = self:resync_sip(arg.auth_name, arg.domain, arg.reboot); + end + + if arg.ip_address and arg.reboot then + success = self:resync_http(arg.ip_address, arg.http_user, arg.http_password, arg.http_port); + end + + return success; +end + +-- send reload message to sip_account +function Snom.resync_sip(self, sip_account, domain, reboot) + local event = freeswitch.Event('NOTIFY'); + event:addHeader('profile', 'gemeinschaft'); + event:addHeader('event-string', 'check-sync;reboot=' .. tostring(reboot)); + event:addHeader('user', sip_account); + event:addHeader('host', domain); + event:addHeader('content-type', 'application/simple-message-summary'); + return event:fire(); +end + +-- send reload message to ip +function Snom.resync_http(self, ip_address, http_user, http_password, http_port) + local port_str = ''; + if tonumber(http_port) then + port_str = ':' .. http_port; + end + + get_command = 'wget --no-proxy -q -O /dev/null -o /dev/null -b --tries=2 --timeout=10 --user="' .. (http_user or '') .. '" --password="' .. (http_password or '') .. '"' .. + ' wget http://' .. tostring(ip_address):gsub('[^0-9%.]', '') .. port_str .. '/advanced.htm?reboot=Reboot' .. + ' 1>>/dev/null 2>>/dev/null &'; + + result = os.execute(get_command); + + if result and tonumber(result) == 0 then + return true; + end +end diff --git a/misc/freeswitch/scripts/phones/uacsta.lua b/misc/freeswitch/scripts/phones/uacsta.lua new file mode 100644 index 0000000..61cb788 --- /dev/null +++ b/misc/freeswitch/scripts/phones/uacsta.lua @@ -0,0 +1,100 @@ +-- CommonModule: Uacsta +-- +module(...,package.seeall) + +Uacsta = {} + +-- Create Uacsta object +function Uacsta.new(self, arg) + arg = arg or {} + object = arg.object or {} + setmetatable(object, self) + self.__index = self + self.log = arg.log; + + return object +end + +function Uacsta.send(self, sip_account, domain, body) + local event = freeswitch.Event("NOTIFY"); + event:addHeader("profile", "gemeinschaft"); + event:addHeader("event-string", "uaCSTA"); + event:addHeader("user", sip_account); + event:addHeader("host", domain); + event:addHeader("content-type", "application/csta+xml"); + event:addBody(body); + event:fire(); +end + +function Uacsta.make_call(self, sip_account, domain, number) + local body = +[[<?xml version="1.0" encoding="UTF-8"?> +<MakeCall xmlns="http://www.ecma-international.org/standards/ecma-323/csta/ed4"> + <callingDevice>]] .. sip_account .. [[</callingDevice> + <calledDirectoryNumber>]] .. number .. [[</calledDirectoryNumber> + <autoOriginate>doNotPrompt</autoOriginate> +</MakeCall>]] + + self:send(sip_account, domain, body); +end + +function Uacsta.answer_call(self, sip_account, domain) + local body = +[[<?xml version="1.0" encoding="UTF-8"?> +<AnswerCall xmlns="http://www.ecma-international.org/standards/ecma-323/csta/ed4"> + <callToBeAnswered> + <deviceID>]] .. sip_account .. [[</deviceID> + </callToBeAnswered> +</AnswerCall>]] + + self:send(sip_account, domain, body); +end + +function Uacsta.set_microphone_mute(self, sip_account, domain, value) + local body = +[[<?xml version="1.0" encoding="UTF-8"?> +<SetMicrophoneMute xmlns="http://www.ecma-international.org/standards/ecma-323/csta/ed3"> + <device>]] .. sip_account .. [[</device> + <auditoryApparatus>1</auditoryApparatus> + <microphoneMuteOn>]] .. tostring(value) .. [[</microphoneMuteOn> +</SetMicrophoneMute>]] + + self:send(sip_account, domain, body); +end + +function Uacsta.set_speaker_volume(self, sip_account, domain, value) + local body = +[[<?xml version="1.0" encoding="UTF-8"?> +<SetSpeakerVolume xmlns="http://www.ecma-international.org/standards/ecma-323/csta/ed3"> + <device>]] .. sip_account .. [[</device> + <auditoryApparatus>1</auditoryApparatus> + <speakerVolume>]] .. tonumber(value) .. [[</speakerVolume> +</SetSpeakerVolume>]] + + self:send(sip_account, domain, body); +end + +function Uacsta.set_do_not_disturb(self, sip_account, domain, value) + local body = +[[<?xml version="1.0" encoding="UTF-8"?> +<SetDoNotDisturb xmlns="http://www.ecma-international.org/standards/ecma-323/csta/ed3"> + <device>]] .. sip_account .. [[</device> + <doNotDisturbOn>]] .. tostring(value) .. [[</doNotDisturbOn> +</SetDoNotDisturb>]] + + self:send(sip_account, domain, body); +end + +function Uacsta.set_forwarding(self, sip_account, domain, forwarding_type, number, activate) + local forwarding_types = { "forwardImmediate", "forwardBusy", "forwardNoAns" } + local body = +[[<?xml version="1.0" encoding="UTF-8"?> +<SetForwarding xmlns="http://www.ecma-international.org/standards/ecma-323/csta/ed3"> + <device>]] .. sip_account .. [[</device> + <forwardingType>]] .. tostring(forwarding_types[tonumber(forwarding_type)]) .. [[</forwardingType> + <forwardDN>]] .. number .. [[</forwardDN> + <activateForward>]] .. tostring(activate) .. [[</activateForward> +</SetForwarding>]] + + self:send(sip_account, domain, body); +end |