Skip to content

Commit

Permalink
Sensible default values for the sip config
Browse files Browse the repository at this point in the history
  • Loading branch information
slyoldfox committed May 31, 2024
1 parent 7cd6b27 commit 0a6d946
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
3 changes: 1 addition & 2 deletions lib/apis/validate-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ module.exports = class Api {
handle(request, response, parsedUrl, q) {
const ip = request.headers['x-forwarded-for'] || request.socket.remoteAddress
//ip += "."
const domain = fs.readFileSync("/etc/flexisip/domain-registration.conf").toString().split(' ')

var setup = {}
var errors = []
setup['domain'] = domain[0]
setup['domain'] = utils.domain()
setup['model'] = utils.model()

if( setup['model'] === "unknown" ) {
Expand Down
11 changes: 7 additions & 4 deletions lib/persistent-sip-manager.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
const sipConfig = require('../config').sip
const utils = require('./utils')
const sipbundle = require('./sip/sip-bundle')

let sipOptions = function sipOptions() {
const from = sipConfig.from
const to = sipConfig.to
const model = utils.model()
const from = sipConfig.from || '[email protected]'
const to = sipConfig.to || (model === 'unknown' ? undefined : model + '@127.0.0.1') // For development, specify the sip.to config value
const localIp = from?.split(':')[0].split('@')[1]
const localPort = parseInt(from?.split(':')[1]) || 5060
const domain = sipConfig.domain
const domain = sipConfig.domain || utils.domain() // For development, specify the sip.domain config value
const expire = sipConfig.expire || 600
const sipdebug = sipConfig.debug

if (!from || !to || !localIp || !localPort || !domain || !expire ) {
console.error('Error: SIP From/To/Domain URIs not specified!')
console.error('Error: SIP From/To/Domain URIs not specified! Current sip config: ')
console.info(JSON.stringify(config.sip))
throw new Error('SIP From/To/Domain URIs not specified!')
}

Expand Down
10 changes: 10 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,15 @@ module.exports = {
} catch( e ) {
console.error("Failure retrieving or modifying route.")
}
},
domain() {
if( !fs.existsSync("/etc/flexisip/domain-registration.conf") ) {
return undefined
}
if( !this["_domain"] ) {
const domain = fs.readFileSync("/etc/flexisip/domain-registration.conf").toString().split(' ')
this["_domain"] = domain[0]
}
return this["_domain"]
}
}

0 comments on commit 0a6d946

Please sign in to comment.