Skip to content

Commit aaf6aae

Browse files
authored
Merge pull request #102 from node-red-contrib/codex/handle-routeros-empty-reply
Handle RouterOS 7.18 empty API replies
2 parents 4d76162 + e6a6524 commit aaf6aae

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

src/mikrotik.html.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ RED.nodes.registerType('mikrotik', {
2020
oneditprepare: function () {
2121
let node = this;
2222
$("#node-input-action").on('change', function () {
23-
let cmd = node.command;
24-
let newType = 'str';
23+
let cmd: string = node.command;
24+
let newType: string = 'str';
2525

2626
const lookUp = ['/log/print', '/system/resource/print', '/interface/wireless/registration-table/print', '/system/reboot'];
2727
let value = parseInt($("#node-input-action").val() as string, 10);
@@ -47,4 +47,4 @@ RED.nodes.registerType('mikrotik', {
4747
oneditsave: function () {
4848
this.action = null;
4949
}
50-
});
50+
});

src/mikrotik.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@ import { NodeAPI, Node, NodeMessageInFlow } from "node-red";
22
import { MikrotikDeviceNode } from "./interfaces"
33

44
import { RouterOSAPI } from "node-routeros";
5+
import { Channel } from "node-routeros/dist/Channel";
6+
7+
function patchRouterOSEmptyReply() {
8+
const channelPrototype = Channel.prototype as any;
9+
if (channelPrototype.handlesRouterOSEmptyReply)
10+
return;
11+
12+
const processPacket = channelPrototype.processPacket;
13+
channelPrototype.processPacket = function (packet: string[]) {
14+
// RouterOS 7.18 sends !empty before !done when a query has no records.
15+
if (packet[0] === '!empty') {
16+
packet.shift();
17+
return;
18+
}
19+
20+
return processPacket.call(this, packet);
21+
};
22+
23+
channelPrototype.handlesRouterOSEmptyReply = true;
24+
}
25+
26+
patchRouterOSEmptyReply();
527

628
export = function (RED: NodeAPI) {
729
function NodeMikrotik(this: Node, config: any) {

tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
"allowJs": false,
1010
"declaration": false,
1111
"sourceMap": false,
12+
"skipLibCheck": true,
1213
"strict": false,
14+
"rootDir": "./src",
1315
"outDir": "./nodes/",
1416
},
1517

0 commit comments

Comments
 (0)