diff --git a/app/controllers/integration/sipgate_controller.rb b/app/controllers/integration/sipgate_controller.rb index 5fa0eb2b8..53768edc0 100644 --- a/app/controllers/integration/sipgate_controller.rb +++ b/app/controllers/integration/sipgate_controller.rb @@ -118,7 +118,10 @@ class Integration::SipgateController < ApplicationController def base_url http_type = Setting.get('http_type') - fqdn = Setting.get('fqdn') + fqdn = Setting.get('sipgate_alternative_fqdn') + if fqdn.blank? + fqdn = Setting.get('fqdn') + end "#{http_type}://#{fqdn}/api/v1/sipgate" end diff --git a/db/migrate/20181010000000_setting_add_sipgate_alternative_fqdn.rb b/db/migrate/20181010000000_setting_add_sipgate_alternative_fqdn.rb new file mode 100644 index 000000000..512008d44 --- /dev/null +++ b/db/migrate/20181010000000_setting_add_sipgate_alternative_fqdn.rb @@ -0,0 +1,30 @@ +class SettingAddSipgateAlternativeFqdn < ActiveRecord::Migration[5.1] + def up + + # return if it's a new setup + return if !Setting.find_by(name: 'system_init_done') + + Setting.create_if_not_exists( + title: 'sipgate.io alternative fqdn', + name: 'sipgate_alternative_fqdn', + area: 'Integration::Sipgate::Expert', + description: 'Alternative FQDN for callbacks if you operate Zammad in internal network.', + options: { + form: [ + { + display: '', + null: false, + name: 'sipgate_alternative_fqdn', + tag: 'input', + }, + ], + }, + state: '', + preferences: { + permission: ['admin.integration'], + }, + frontend: false + ) + end + +end diff --git a/db/seeds/settings.rb b/db/seeds/settings.rb index 094967f5f..c7cd1075e 100644 --- a/db/seeds/settings.rb +++ b/db/seeds/settings.rb @@ -3913,6 +3913,27 @@ Setting.create_if_not_exists( }, frontend: false, ) +Setting.create_if_not_exists( + title: 'sipgate.io alternative fqdn', + name: 'sipgate_alternative_fqdn', + area: 'Integration::Sipgate::Expert', + description: 'Alternative FQDN for callbacks if you operate Zammad in internal network.', + options: { + form: [ + { + display: '', + null: false, + name: 'sipgate_alternative_fqdn', + tag: 'input', + }, + ], + }, + state: '', + preferences: { + permission: ['admin.integration'], + }, + frontend: false +) Setting.create_if_not_exists( title: 'cti integration', name: 'cti_integration', diff --git a/spec/requests/integration/sipgate_spec.rb b/spec/requests/integration/sipgate_spec.rb index f88301419..bee8673ee 100644 --- a/spec/requests/integration/sipgate_spec.rb +++ b/spec/requests/integration/sipgate_spec.rb @@ -441,5 +441,24 @@ RSpec.describe 'Integration Sipgate', type: :request do expect(json_response['list'][4]['state']).to eq('hangup') expect(json_response['list'][5]['call_id']).to eq('1234567890-1') end + + it 'alternative fqdn' do + Setting.set('sipgate_alternative_fqdn', 'external.host.example.com') + + # inbound - I + params = 'event=newCall&direction=in&from=4912347114711&to=4930600000000&callId=4991155921769858278-1&user%5B%5D=user+1&user%5B%5D=user+2' + post '/api/v1/sipgate/in', params: params + expect(@response).to have_http_status(200) + on_hangup = nil + on_answer = nil + content = @response.body + response = REXML::Document.new(content) + response.elements.each('Response') do |element| + on_hangup = element.attributes['onHangup'] + on_answer = element.attributes['onAnswer'] + end + expect(on_hangup).to eq('http://external.host.example.com/api/v1/sipgate/in') + expect(on_answer).to eq('http://external.host.example.com/api/v1/sipgate/in') + end end end