Skip to content

Commit 0617255

Browse files
committed
Version 2.2.0
Update dependencies (security fix) Fix lint errors
1 parent e7f8967 commit 0617255

File tree

11 files changed

+10335
-5075
lines changed

11 files changed

+10335
-5075
lines changed

lib/config/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = function Configuration (logger, configPath = null) {
1515
configPath = './lib/config/config.json'
1616
}
1717
try {
18-
let data = require('fs').readFileSync(configPath)
18+
const data = require('fs').readFileSync(configPath)
1919
config = JSON.parse(data)
2020
} catch (error) {
2121
logger.fatal(`Invalid configuration file: ${error.message}, current directory is: ${process.cwd()}`)

lib/error/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111

1212
module.exports = (logger, xmpp) => {
13-
let nodeCleanup = require('node-cleanup')
13+
const nodeCleanup = require('node-cleanup')
1414
nodeCleanup(function (exitCode, signal) {
1515
logger.warn(`Received ${exitCode}/${signal} (application is closing), disconnect from XMPP server`)
1616
try {

lib/logger/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = () => {
2525
}
2626

2727
// add appenders
28-
let appenders = []
28+
const appenders = []
2929
if (config.file.active) {
3030
const fs = require('fs')
3131
if (!fs.existsSync(config.file.path)) {
@@ -73,7 +73,7 @@ module.exports = () => {
7373
}
7474
},
7575
categories: {
76-
default: { appenders: appenders, level: 'info' }
76+
default: { appenders, level: 'info' }
7777
}
7878
})
7979
logger = log4js.getLogger()

lib/outgoing/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
*/
1111

1212
module.exports = async (logger, config, xmpp, user, destination, message, type, code) => {
13-
let webhook = config.getOutgoingWebhook(code)
13+
const webhook = config.getOutgoingWebhook(code)
1414
if (!webhook) {
1515
logger.warn(`There is no webhook with code "${code}"`)
1616
throw new Error(`There is no webhook with code "${code}"`)
1717
}
1818
const { promisify } = require('util')
1919
const request = promisify(require('request'))
2020
// request.debug = true
21-
let options = {
21+
const options = {
2222
method: 'POST',
2323
url: webhook.url,
2424
strictSSL: webhook.strictSSL
@@ -50,7 +50,7 @@ module.exports = async (logger, config, xmpp, user, destination, message, type,
5050
logger.trace('Content-type: application/x-www-form-urlencoded')
5151
options.form = {
5252
from: user,
53-
message: message,
53+
message,
5454
channel: destination
5555
}
5656
logger.trace('Outgoing webhook request:', options.form)
@@ -59,7 +59,7 @@ module.exports = async (logger, config, xmpp, user, destination, message, type,
5959
logger.trace('Content-type: application/json')
6060
options.json = {
6161
from: user,
62-
message: message,
62+
message,
6363
channel: destination
6464
}
6565
logger.trace('Outgoing webhook request:', options.json)

lib/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict'
22

33
// create default logger
4-
let logger = require('./logger')()
4+
const logger = require('./logger')()
55

66
// get configuration
7-
let config = require('./config')(logger)
7+
const config = require('./config')(logger)
88

99
// update logger with configuration
1010
logger.updateConfig(config.logger)

lib/webhook/index.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = (logger, config, xmpp) => {
1818
const port = config.listener.port || 8000
1919
const portSsl = config.listener.ssl.port || 8001
2020

21-
var webhook = express()
21+
const webhook = express()
2222

2323
// handle connection from proxy (get IP in 'X-Forwarded-For' header)
2424
webhook.set('trust proxy', true)
@@ -57,29 +57,28 @@ module.exports = (logger, config, xmpp) => {
5757
// handle post request
5858
webhook.post(config.listener.path + '/*', (req, res) => {
5959
logger.info(`Incoming webhook from ${req.auth.user}`)
60-
let webhook = config.getWebhookAction(req.path)
60+
const webhook = config.getWebhookAction(req.path)
6161
if (!webhook) {
6262
logger.error(`Webhook received: ${req.path}, not found`)
6363
return res.status(404).send('Webhook not found')
6464
}
6565
logger.debug(`Webhook received: ${webhook.path}, start action: ${webhook.action}`)
6666
logger.trace(req.body)
6767
switch (webhook.action) {
68-
case 'send_xmpp_message':
69-
68+
case 'send_xmpp_message': {
7069
// get destination
7170
if ('destination' in req.body === false) {
7271
logger.error('Destination not found')
7372
return res.status(400).send('Destination not found')
7473
}
75-
let destination = req.body.destination
74+
const destination = req.body.destination
7675

7776
// get message
7877
if ('message' in req.body === false) {
7978
logger.error('Message not found')
8079
return res.status(400).send('Message not found')
8180
}
82-
let message = req.body.message
81+
const message = req.body.message
8382

8483
// check if destination is a group chat
8584
const type = config.xmpp.rooms.some((room) => room.id === destination) ? 'groupchat' : 'chat'
@@ -88,17 +87,17 @@ module.exports = (logger, config, xmpp) => {
8887
logger.trace(`Send to ${destination} (group:${type}) following message :\r\n${message}`)
8988
xmpp.send(destination, message, type)
9089
.then(() => {
91-
return res.status(200).send({ 'status': 'ok', destination })
90+
return res.status(200).send({ status: 'ok', destination })
9291
})
9392
.catch(() => {
9493
return res.status(500).send('Could not send message')
9594
})
9695
break
96+
}
9797

98-
case 'send_xmpp_template':
99-
98+
case 'send_xmpp_template': {
10099
// bind data in template
101-
let msg = webhook.template.replace(/\$\{(.+?)\}/g, (match, $1) => {
100+
const msg = webhook.template.replace(/\$\{(.+?)\}/g, (match, $1) => {
102101
return jmespath.search(req.body, $1) || ''
103102
})
104103
logger.trace(`Message:\r\n${msg}`)
@@ -114,6 +113,7 @@ module.exports = (logger, config, xmpp) => {
114113
return res.status(500).send('Could not send message')
115114
})
116115
break
116+
}
117117

118118
default:
119119
return res.status(204).send()
@@ -133,10 +133,10 @@ module.exports = (logger, config, xmpp) => {
133133
// get IP v4 addresses and prepare endpoints for output
134134
let addresses = []
135135
const networkInterfaces = require('os').networkInterfaces()
136-
for (let ifaceName in networkInterfaces) {
136+
for (const ifaceName in networkInterfaces) {
137137
addresses = addresses.concat(networkInterfaces[ifaceName].reduce((add, iface) => {
138-
if (iface['family'] === 'IPv4') {
139-
add.push(iface['address'])
138+
if (iface.family === 'IPv4') {
139+
add.push(iface.address)
140140
}
141141
return add
142142
}, []))
@@ -166,7 +166,7 @@ module.exports = (logger, config, xmpp) => {
166166
try {
167167
fs.accessSync(config.listener.ssl.certPath, fs.constants.R_OK)
168168
logger.debug('Can read certificate')
169-
let credentials = {
169+
const credentials = {
170170
key: fs.readFileSync(config.listener.ssl.keyPath),
171171
cert: fs.readFileSync(config.listener.ssl.certPath)
172172
}

lib/xmpp/index.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ module.exports = (logger, config) => {
5555
})
5656
// join rooms
5757
config.xmpp.rooms.forEach(function (room) {
58-
let occupantJid = room.id + '/' + address.local
58+
const occupantJid = room.id + '/' + address.local
5959
logger.debug(`Join room: ${room.id} ('${occupantJid}')`)
6060
const stanza = xml(
6161
'presence', {
@@ -78,16 +78,16 @@ module.exports = (logger, config) => {
7878
// not a message, do nothing
7979
return
8080
}
81-
let type = stanza.attrs.type
81+
const type = stanza.attrs.type
8282
switch (type) {
8383
case 'chat':
84-
case 'groupchat':
85-
let body = stanza.getChild('body')
84+
case 'groupchat': {
85+
const body = stanza.getChild('body')
8686
if (!body) {
8787
// empty body, do nothing
8888
return
8989
}
90-
let fromJid = jid(stanza.attrs.from)
90+
const fromJid = jid(stanza.attrs.from)
9191
// for chat, "to" and "replyTo" must be something like "[email protected]", "from" is local part "user"
9292
let to = this.jid.bare()
9393
let from = fromJid.local
@@ -102,15 +102,15 @@ module.exports = (logger, config) => {
102102
return
103103
}
104104
}
105-
let message = body.text()
105+
const message = body.text()
106106
// handle message delivery receipts for chat
107107
if (type === 'chat') {
108-
let request = stanza.getChild('request')
108+
const request = stanza.getChild('request')
109109
if (request &&
110110
request.attrs.xmlns &&
111111
request.attrs.xmlns === 'urn:xmpp:receipts' &&
112112
stanza.attrs.id) {
113-
logger.debug(`Message delivery receipt is requested and will be processed`)
113+
logger.debug('Message delivery receipt is requested and will be processed')
114114
const receiptStanza = xml(
115115
'message', {
116116
to: fromJid
@@ -127,7 +127,7 @@ module.exports = (logger, config) => {
127127
}
128128
logger.info(`Incoming ${type} message from ${from} (${fromJid.toString()}) to ${to}`)
129129
logger.debug(`Message: "${message.replace(/\n|\r/g, ' ')}"`)
130-
let xmppHook = config.getXmppHookAction(to.toString())
130+
const xmppHook = config.getXmppHookAction(to.toString())
131131
if (!xmppHook) {
132132
logger.error(`There is no action for incoming ${type} message to: "${to}"`)
133133
return
@@ -144,6 +144,7 @@ module.exports = (logger, config) => {
144144
break
145145
}
146146
break
147+
}
147148
}
148149
})
149150

0 commit comments

Comments
 (0)