add mqtt cli option to only allow processing specific portnums

This commit is contained in:
liamcottle
2024-09-09 13:52:21 +12:00
parent ce4895bb8c
commit 0e0ed2b9ee

View File

@ -43,6 +43,13 @@ const optionsList = [
typeLabel: '<topic> ...',
description: "MQTT Topic to subscribe to (e.g: msh/#)",
},
{
name: "allowed-portnums",
type: Number,
multiple: true,
typeLabel: '<portnum> ...',
description: "If provided, only packets with these portnums will be processed.",
},
{
name: "log-unknown-portnums",
type: Boolean,
@ -177,6 +184,7 @@ const mqttUsername = options["mqtt-username"] ?? "meshdev";
const mqttPassword = options["mqtt-password"] ?? "large4cats";
const mqttClientId = options["mqtt-client-id"] ?? null;
const mqttTopics = options["mqtt-topic"] ?? ["msh/#"];
const allowedPortnums = options["allowed-portnums"] ?? null;
const logUnknownPortnums = options["log-unknown-portnums"] ?? false;
const collectServiceEnvelopes = options["collect-service-envelopes"] ?? false;
const collectPositions = options["collect-positions"] ?? true;
@ -663,6 +671,11 @@ client.on("message", async (topic, message) => {
const logKnownPacketTypes = false;
const portnum = envelope.packet?.decoded?.portnum;
// if allowed portnums are configured, ignore portnums that are not in the list
if(allowedPortnums != null && !allowedPortnums.includes(portnum)){
return;
}
if(portnum === 1) {
if(!collectTextMessages){