Skip to content

Commit

Permalink
Allow http in endpoints
Browse files Browse the repository at this point in the history
Add debug logging to openwebnet-handler and mqtt
  • Loading branch information
slyoldfox committed Jul 16, 2024
1 parent 053acf8 commit 73039f3
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 30 deletions.
13 changes: 0 additions & 13 deletions lib/apis/register-endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,4 @@ module.exports = class Api {
if (q.raw)
response.end()
}

matchStringInFile(filename, lineMatcher, errorHandler) {
const lines = fs.readFileSync(filename).toString().split('\n')
console.log("file: " + filename + " contains " + lines.length + " lines.")
for (let i = 0; i < lines.length; i++) {
let line = lines[i]
if (lineMatcher(line)) {
console.log(" [OK]")
return true
}
}
errorHandler()
}
}
15 changes: 1 addition & 14 deletions lib/apis/validate-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = class Api {
}

// Verify trusted-hosts
this.matchStringInFile("/home/bticino/cfg/flexisip.conf",
utils.matchStringInFile("/home/bticino/cfg/flexisip.conf",
(line) => { return line.startsWith('trusted-hosts=') && line.indexOf(ip) > 0 },
() => { errors.push(`Please add the IP ${ip} to /home/bticino/cfg/flexisip.conf or scrypted won't be able to talk to the SIP server.`) }
)
Expand All @@ -34,17 +34,4 @@ module.exports = class Api {
if (q.raw)
response.end()
}

matchStringInFile(filename, lineMatcher, errorHandler) {
var lines = fs.readFileSync(filename).toString().split('\n')
console.log("file: " + filename + " contains " + lines.length + " lines.")
for (let i = 0; i < lines.length; i++) {
let line = lines[i]
if (lineMatcher(line)) {
console.log(" [OK]")
return true
}
}
errorHandler()
}
}
7 changes: 6 additions & 1 deletion lib/endpoint-registry.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";

const https = require("https")
const http = require("http")
const utils = require("./utils")
const debug = utils.getDebugger("endpoint-registry")
const CHECK_INTERVAL = 30 * 1000
Expand Down Expand Up @@ -46,7 +47,11 @@ class EndpointRegistry {
this.#endpoints.forEach((v, k) => {
let url = v[type]
if (url) {
https.get(url, requestOptions, (res) => { console.log(" [" + res.statusCode + "] for endpoint: " + url) })
if( url.toString().indexOf("https://") >= 0 ) {
https.get(url, requestOptions, (res) => { console.log(" [" + res.statusCode + "] for endpoint: " + url) })
} else {
http.get(url, requestOptions, (res) => { console.log(" [" + res.statusCode + "] for endpoint: " + url) })
}
} else {
console.warn(`Ignoring dispatch event '${type}' for endpoint: ${k}`)
}
Expand Down
4 changes: 3 additions & 1 deletion lib/handlers/openwebnet-handler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const btAvMedia = require("./bt-av-media")
const utils = require("../utils")
const debug = utils.getDebugger("openwebnet-handler")

class OpenwebnetHandler {

Expand All @@ -18,7 +20,7 @@ class OpenwebnetHandler {

handle(listener, system, msg) {
// Uncomment the line below if you wish to debug and view the messages in the console
//console.log(msg)
debug(msg)
this.#mqtt.dispatch(msg)
switch (msg) {
case msg.startsWith('*8*19*') ? msg : undefined:
Expand Down
3 changes: 2 additions & 1 deletion lib/mqtt.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const config = require('../config')
const utils = require("./utils")
const debug = utils.getDebugger("mqtt")
const openwebnet = require('./openwebnet')
const child_process = require('child_process')

Expand Down Expand Up @@ -52,7 +53,7 @@ class MQTT {
#dispatchInternal( topic, msg ) {
if( config.mqtt_config.enabled && config.mqtt_config.host.length > 0 ) {
let cmd = this.#cmd + ( config.mqtt_config.retain ? ' -r' : '' ) + ' -t ' + topic + " -m '" + msg + "'"
//console.log("exec: " + cmd)
debug("exec: " + cmd)
try {
child_process.exec(cmd, {timeout: 2500}, (err, stdout, stderr) => {
//console.log(msg)
Expand Down

0 comments on commit 73039f3

Please sign in to comment.