-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathnode_helper.js
More file actions
43 lines (40 loc) · 1.17 KB
/
node_helper.js
File metadata and controls
43 lines (40 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const Log = require("logger")
const NodeHelper = require("node_helper")
const express = require("express")
const { exec } = require("node:child_process")
module.exports = NodeHelper.create({
start: function () {
this.expressApp.use(express.json())
this.expressApp.use(express.urlencoded({ extended: true }))
this.expressApp.post("/webhook", (req, res) => {
Log.log("[NOTTRG] reqpost?", req.body)
this.sendSocketNotification("WEBHOOK", req.body)
res.status(200).send({ status: 200 })
})
this.expressApp.get("/webhook", (req, res) => {
Log.log("[NOTTRG] reqget?", req.query)
this.sendSocketNotification("WEBHOOK", req.query)
res.status(200).send({ status: 200 })
})
},
socketNotificationReceived: function (noti, payload) {
if (noti === "EXEC") {
exec(payload.exec, (error, stdout, stderr) => {
if (error) {
Log.error(`[NOTTRG] exec error: ${error}`)
}
else {
Log.log(`[NOTTRG] stdout: ${stdout}`)
Log.log(`[NOTTRG] stderr: ${stderr}`)
}
this.sendSocketNotification("EXEC_RESULT", {
trigger: payload.trigger,
fire: payload.fire,
error: error,
stdout: stdout,
stderr: stderr
})
})
}
}
})