Skip to content

Commit

Permalink
Improve validation slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
slyoldfox committed Jun 5, 2024
1 parent ddc6d96 commit ccaa235
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion controller-homekit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const model = utils.model().toLocaleUpperCase()
sdpserver.create(base.registry)

utils.fixMulticast()
utils.verifyFlexisip('webrtc@' + utils.domain()).forEach( (e) => console.error(e) )
utils.verifyFlexisip('webrtc@' + utils.domain()).forEach( (e) => console.error( `* ${e}`) )

const bridgeConfig = filestore.read('_bridge', () => {
return {
Expand Down
2 changes: 1 addition & 1 deletion controller-webrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ const base = require('./base')
const sdpserver = require('./lib/sdpserver')
const utils = require('./lib/utils')

utils.verifyFlexisip('webrtc@' + utils.domain()).forEach( (e) => console.error(e) )
utils.verifyFlexisip('webrtc@' + utils.domain()).forEach( (e) => console.error( `* ${e}`) )

sdpserver.create(base.registry)
30 changes: 26 additions & 4 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ function matchStringInFile(filename, lineMatcher, errorHandler) {
errorHandler()
}

function checkAllUserLine(line, identifier, domain) {
let alluser = line.startsWith("<sip:alluser@" + domain + ">")
if(alluser) {
let users = line.split(",")
let user = users.map( (u) => u.toString().trim() ).filter( (u) => u.indexOf('<sip:' + identifier + '>') >= 0 )
return user.length > 0
} else {
return false
}
}

module.exports = {
MESSAGES_FOLDER,
version() {
Expand Down Expand Up @@ -171,11 +182,11 @@ module.exports = {
return this["_domain"]
},
verifyFlexisip(identifier) {
//TODO: might need to improve this
//TODO: Also validate /etc/flexisip/flexisip.conf ?
console.log("[FLEXISIP] config check started...")
if( this.model() === 'unknown' ) {
console.log("Skipping configuration validation.")
return []
//return []
}
let errors = []
matchStringInFile("/etc/flexisip/users/users.db.txt",
Expand All @@ -186,11 +197,22 @@ module.exports = {
(line) => { return line.startsWith("<sip:" + identifier + ">") },
() => errors.push("The sip user '<sip:" + identifier + ">' is not added to /etc/flexisip/users/route.conf !")
)
matchStringInFile("/etc/flexisip/users/route.conf",
(line) => {
return checkAllUserLine(line, identifier, this.domain())
},
() => errors.push("The sip user '<sip:" + identifier + ">' is not added to the alluser line in /etc/flexisip/users/route.conf !")
)
matchStringInFile("/etc/flexisip/users/route_int.conf",
(line) => { return line.indexOf("<sip:" + identifier + ">") > 0 },
(line) => { return checkAllUserLine(line, identifier, this.domain()) },
() => errors.push("The sip user '<sip:" + identifier + ">' is not added to the alluser line in /etc/flexisip/users/route_int.conf !")
)
console.log(`[FLEXISIP] DONE: ${errors.length} errors`)
if(errors.length > 0) {
console.error(`[FLEXISIP]: ${errors.length} errors, incoming calls might not work.`)
} else {
console.log(`[FLEXISIP] DONE, no errors`)
}

return errors;
}
}

0 comments on commit ccaa235

Please sign in to comment.