Improved config input validation for issue #1698 - SipgateController - undefined method `each' for nil:NilClass (NoMethodError).
This commit is contained in:
parent
4108c78722
commit
82b5b6af2f
1 changed files with 13 additions and 8 deletions
|
@ -43,8 +43,13 @@ class Integration::SipgateController < ApplicationController
|
||||||
|
|
||||||
# set caller id of outbound call
|
# set caller id of outbound call
|
||||||
def out
|
def out
|
||||||
config_outbound = config_integration[:outbound][:routing_table]
|
config_outbound = config_integration[:outbound]
|
||||||
default_caller_id = config_integration[:outbound][:default_caller_id]
|
routing_table = nil
|
||||||
|
default_caller_id = nil
|
||||||
|
if config_outbound.present?
|
||||||
|
routing_table = config_outbound[:routing_table]
|
||||||
|
default_caller_id = config_outbound[:default_caller_id]
|
||||||
|
end
|
||||||
|
|
||||||
xml = Builder::XmlMarkup.new(indent: 2)
|
xml = Builder::XmlMarkup.new(indent: 2)
|
||||||
xml.instruct!
|
xml.instruct!
|
||||||
|
@ -53,8 +58,8 @@ class Integration::SipgateController < ApplicationController
|
||||||
content = nil
|
content = nil
|
||||||
to = params[:to]
|
to = params[:to]
|
||||||
from = nil
|
from = nil
|
||||||
if to
|
if to && routing_table.present?
|
||||||
config_outbound.each do |row|
|
routing_table.each do |row|
|
||||||
dest = row[:dest].gsub(/\*/, '.+?')
|
dest = row[:dest].gsub(/\*/, '.+?')
|
||||||
next if to !~ /^#{dest}$/
|
next if to !~ /^#{dest}$/
|
||||||
from = row[:caller_id]
|
from = row[:caller_id]
|
||||||
|
@ -63,7 +68,7 @@ class Integration::SipgateController < ApplicationController
|
||||||
end
|
end
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
if !content && default_caller_id
|
if !content && default_caller_id.present?
|
||||||
from = default_caller_id
|
from = default_caller_id
|
||||||
content = xml.Response(onHangup: url, onAnswer: url) do
|
content = xml.Response(onHangup: url, onAnswer: url) do
|
||||||
xml.Dial(callerId: default_caller_id) { xml.Number(params[:to]) }
|
xml.Dial(callerId: default_caller_id) { xml.Number(params[:to]) }
|
||||||
|
@ -73,8 +78,8 @@ class Integration::SipgateController < ApplicationController
|
||||||
content = xml.Response(onHangup: url, onAnswer: url)
|
content = xml.Response(onHangup: url, onAnswer: url)
|
||||||
end
|
end
|
||||||
|
|
||||||
send_data content, type: 'application/xml; charset=UTF-8;'
|
send_data(content, type: 'application/xml; charset=UTF-8;')
|
||||||
if from
|
if from.present?
|
||||||
params['from'] = from
|
params['from'] = from
|
||||||
end
|
end
|
||||||
Cti::Log.process(params)
|
Cti::Log.process(params)
|
||||||
|
@ -89,7 +94,7 @@ class Integration::SipgateController < ApplicationController
|
||||||
xml_error('Feature is disable, please contact your admin to enable it!')
|
xml_error('Feature is disable, please contact your admin to enable it!')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if !config_integration || !config_integration[:inbound] || !config_integration[:outbound]
|
if config_integration.blank? || config_integration[:inbound].blank? || config_integration[:outbound].blank?
|
||||||
xml_error('Feature not configured, please contact your admin!')
|
xml_error('Feature not configured, please contact your admin!')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue