diff options
Diffstat (limited to 'misc/freeswitch/scripts/dialplan/dialplan.lua')
-rw-r--r-- | misc/freeswitch/scripts/dialplan/dialplan.lua | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index 913d7a5..1133f58 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -124,16 +124,19 @@ function Dialplan.auth_node(self) end -function Dialplan.auth_sip_account(self) +function Dialplan.auth_account(self) if not common.str.blank(self.caller.auth_account_type) then - self.log:info('AUTH_SIP_ACCOUNT - ', self.caller.auth_account_type, '=', self.caller.account_id, '/', self.caller.account_uuid); + self.log:info('AUTH auth_account - ', self.caller.auth_account_type, '=', self.caller.account_id, '/', self.caller.account_uuid); + return true; + elseif not common.str.blank(self.caller.previous_destination_type) and not common.str.blank(self.caller.previous_destination_uuid) then + self.log:info('AUTH previous_destination - ', self.caller.previous_destination_type, '=', self.caller.previous_destination_id, '/', self.caller.previous_destination_uuid); return true; end end function Dialplan.auth_gateway(self) - require 'common.gateway' + require 'common.gateway'; local gateway_class = common.gateway.Gateway:new{ log = self.log, database = self.database}; local gateway = false; @@ -143,14 +146,14 @@ function Dialplan.auth_gateway(self) name = self.caller:to_s('gs_gateway_name'), id = self.caller:to_i('gs_gateway_id'), } - log:info('AUTH_GATEWAY - authenticaded by password and username: ', self.caller:to_s('username'), ', gateway=', gateway.id, '|', gateway.name, ', ip: ', self.caller.sip_contact_host); + log:info('AUTH gateway - authenticaded by password and username: ', self.caller:to_s('username'), ', gateway=', gateway.id, '|', gateway.name, ', ip: ', self.caller.sip_contact_host); return gateway_class:find_by_id(gateway.id); else gateway = gateway_class:authenticate(self.caller); end if gateway then - log:info('AUTH_GATEWAY - ', gateway.auth_source, ' ~ ', gateway.auth_pattern, ', gateway=', gateway.id, '|', gateway.name, ', ip: ', self.caller.sip_contact_host); + log:info('AUTH gateway - ', gateway.auth_source, ' ~ ', gateway.auth_pattern, ', gateway=', gateway.id, '|', gateway.name, ', ip: ', self.caller.sip_contact_host); return gateway_class:find_by_id(gateway.id); end end @@ -349,7 +352,7 @@ function Dialplan.dial(self, destination) self.log:debug('RINGTONE - phonebookentry=', self.caller.phone_book_entry.id, ', ringtone: ', self.caller.phone_book_entry.bellcore_id); self.caller:export_variable('alert_info', 'http://amooma.de;info=Ringer' .. self.caller.phone_book_entry.bellcore_id .. ';x-line-id=0'); end - if self.caller.phone_book_entry.image then + if not common.str.blank(self.caller.phone_book_entry.image) then self:set_caller_picture(self.caller.phone_book_entry.id, 'phonebookentry', self.caller.phone_book_entry.image); elseif self.caller.account and self.caller.account.owner then self:set_caller_picture(self.caller.account.owner.id, self.caller.account.owner.class); @@ -726,14 +729,6 @@ function Dialplan.switch(self, destination) destination.callee_id_number = destination.number; destination.callee_id_name = nil; - require 'dialplan.router' - local routes = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller, variables = self.caller }:route_run('outbound'); - - if not routes or #routes == 0 then - self.log:notice('SWITCH - no route - number: ', destination.number); - return { continue = false, code = 404, phrase = 'No route' } - end - if self.phonebook_number_lookup then local user_id = common.array.try(self.caller, 'account.owner.id'); local tenant_id = common.array.try(self.caller, 'account.owner.record.current_tenant_id'); @@ -763,7 +758,16 @@ function Dialplan.switch(self, destination) self.caller:set_callee_id(destination.callee_id_number, destination.callee_id_name); + require 'dialplan.router' + local routes = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller, variables = self.caller }:route_run('outbound'); + + if not routes or #routes == 0 then + self.log:notice('SWITCH - no route - number: ', destination.number); + return { continue = false, code = 404, phrase = 'No route' } + end + for index, route in ipairs(routes) do + self.caller:set_callee_id(route.callee_id_number or destination.callee_id_number, route.callee_id_name or destination.callee_id_name); if route.type == 'hangup' then self.log:notice('SWITCH_HANGUP - code: ', route.code, ', phrase: ', route.phrase, ', cause: ', route.cause); return { continue = false, code = route.code or '404', phrase = route.phrase, cause = route.cause } @@ -893,9 +897,10 @@ function Dialplan.run(self, destination) self.caller:set_variable('sound_prefix', common.array.try(self.config, 'sounds.' .. tostring(self.caller.language))); self.log:info('DIALPLAN start - caller_id: ',self.caller.caller_id_number, ' "', self.caller.caller_id_name, '" , number: ', destination.number, ', language: ', self.caller.language); - self.caller.static_caller_id_number = self.caller.caller_id_number; self.caller.static_caller_id_name = self.caller.caller_id_name; + self.caller:set_variable('gs_caller_id_number', self.caller.caller_id_number); + self.caller:set_variable('gs_caller_id_name', self.caller.caller_id_name); local result = { continue = false }; local loop = self.caller.loop_count; @@ -965,6 +970,14 @@ function Dialplan.run(self, destination) destination, result ); + local forwarding_path = self.caller:to_s('gs_forwarding_path'); + if forwarding_path ~= '' then + forwarding_path = forwarding_path .. ','; + end + + forwarding_path = forwarding_path .. auth_account.class:sub(1,1) .. ':' .. auth_account.id; + self.caller:set_variable('gs_forwarding_path', forwarding_path); + self.log:debug('FORWARDING_PATH: ', forwarding_path); end end |