added eMessage Puppeteering Connector

master
cheetah 2 years ago
parent 43115476f8
commit ba841740fb

@ -20,6 +20,10 @@
"enabled": false, "enabled": false,
"duplexTimeout": 180 "duplexTimeout": 180
}, },
"emPuppettering": {
"enabled": true,
"duplexTimeout": 180
},
"emessage": { "emessage": {
"enabled": false, "enabled": false,
"username": "", "username": "",

@ -78,6 +78,16 @@
<label for="ecityruf_duplex_timeout">Duplex Timeout(in seconds): [recommended 180s]</label> <label for="ecityruf_duplex_timeout">Duplex Timeout(in seconds): [recommended 180s]</label>
<input type="number" min="10" max="1200" id="ecityruf_duplex_timeout"/> <input type="number" min="10" max="1200" id="ecityruf_duplex_timeout"/>
</fieldset> </fieldset>
<fieldset>
<legend>eMessage Puppeteering Connector</legend>
<label for="emp_enabled">Enabled:</label>
<input type="checkbox" id="emp_enabled"/>
</br>
<label for="emp_duplex_timeout">Duplex Timeout(in seconds): [recommended 180s]</label>
<input type="number" min="10" max="1200" id="emp_duplex_timeout"/>
</fieldset>
emPuppettering
<fieldset> <fieldset>
<legend>eMessage Connector</legend> <legend>eMessage Connector</legend>
<label for="emessage_enabled">Enabled:</label> <label for="emessage_enabled">Enabled:</label>
@ -138,6 +148,9 @@
$('#ecityruf_enabled').attr('checked', config.connectors.ecityruf.enabled) $('#ecityruf_enabled').attr('checked', config.connectors.ecityruf.enabled)
$('#ecityruf_duplex_timeout').val(config.connectors.ecityruf.duplexTimeout) $('#ecityruf_duplex_timeout').val(config.connectors.ecityruf.duplexTimeout)
$('#emp_enabled').attr('checked', config.connectors.emPuppettering.enabled)
$('#emp_duplex_timeout').val(config.connectors.emPuppettering.duplexTimeout)
$('#emessage_enabled').attr('checked', config.connectors.emessage.enabled) $('#emessage_enabled').attr('checked', config.connectors.emessage.enabled)
$('#emessage_username').val(config.connectors.emessage.username) $('#emessage_username').val(config.connectors.emessage.username)
$('#emessage_password').val(config.connectors.emessage.password) $('#emessage_password').val(config.connectors.emessage.password)
@ -166,6 +179,9 @@
// connectors.ecityruf // connectors.ecityruf
newConfig.connectors.ecityruf.enabled = $('#ecityruf_enabled').prop('checked') newConfig.connectors.ecityruf.enabled = $('#ecityruf_enabled').prop('checked')
newConfig.connectors.ecityruf.duplexTimeout = parseInt($('#ecityruf_duplex_timeout').val()) newConfig.connectors.ecityruf.duplexTimeout = parseInt($('#ecityruf_duplex_timeout').val())
// connectors.emPuppettering
newConfig.connectors.emPuppettering.enabled = $('#emp_enabled').prop('checked')
newConfig.connectors.emPuppettering.duplexTimeout = parseInt($('#emp_duplex_timeout').val())
// connectors.emessage // connectors.emessage
newConfig.connectors.emessage.enabled = $('#emessage_enabled').prop('checked') newConfig.connectors.emessage.enabled = $('#emessage_enabled').prop('checked')

@ -24,6 +24,11 @@ if (!!config.connectors.ecityruf && config.connectors.ecityruf.enabled === true)
if (!!config.connectors.emessage && config.connectors.emessage.enabled === true) { if (!!config.connectors.emessage && config.connectors.emessage.enabled === true) {
types.ConnectorRegistry.register(new types.Connectors.eMessageConnector(connection)) types.ConnectorRegistry.register(new types.Connectors.eMessageConnector(connection))
} }
if (!!config.connectors.emPuppettering && config.connectors.emPuppettering.enabled === true) {
types.ConnectorRegistry.register(new types.Connectors.eMessagePuppeteerConnector(connection))
}
types.ConnectorRegistry.register(new types.Connectors.DummyConnector()) types.ConnectorRegistry.register(new types.Connectors.DummyConnector())
types.DeviceRegistry.register(new types.devices.GenericPager()) types.DeviceRegistry.register(new types.devices.GenericPager())

@ -26,6 +26,7 @@
"md5": "^2.3.0", "md5": "^2.3.0",
"mqtt": "^4.2.6", "mqtt": "^4.2.6",
"node-crc": "^1.3.0", "node-crc": "^1.3.0",
"puppeteer": "^19.2.2",
"querystring": "^0.2.1", "querystring": "^0.2.1",
"socket.io": "^4.0.2" "socket.io": "^4.0.2"
} }

@ -0,0 +1,96 @@
const Connector = require("./Connector")
const config = require('../../config.json')
const boskrypt = require('../../boskrypt')
const md5 = require('md5')
const axios = require('axios')
const puppeteer = require('puppeteer')
function sleep(ms) { return new Promise(r=>setTimeout(r, ms))}
// [ "ecityruf", "123456789" ]
class eMessagePuppeteerConnector extends Connector {
constructor (amqpConnMngr) {
super(amqpConnMngr)
this.name = "em-puppet"
this.duplexCapable = true
this.supportBOSkrypt = true
}
async transmitMessage(msg, params) {
const UUID = this.name+':'+md5(JSON.stringify([this.name,...params]))
const target = params[0]
if (target.split('#').length !== 2) throw 'No valid eMessage Parameter <serviceName#identifier>'
const serviceName = target.split('#')[ 0 ], identifier = target.split('#')[ 1 ]
const $device = msg.routingParams.device
let payloadBuffer = Buffer.from(msg.payload)
const boskryptSupport = require("../DeviceRegistry").Devices[ $device ].supportBOSkrypt || false
console.log('device supports boskrypt', boskryptSupport)
if (boskryptSupport && !!config.pagers[ $device ] && config.pagers[ $device ].boskrypt.enabled) {
//payloadBuffer
const keyTable = config.pagers[ $device ].boskrypt.keys
const FunkrufNummer = "em-"+identifier
console.log('LUT ', FunkrufNummer, 'key=', keyTable[ FunkrufNummer ])
if (!!keyTable[ FunkrufNummer ]) {
payloadBuffer = Buffer.from(boskrypt.encrypt(payloadBuffer, keyTable[ FunkrufNummer ], 0))
}
}
let sendPromise = new Promise(async (res, rej) => {
const browser = await puppeteer.launch({ headless: true })
this.connectorRegistry.reportState(msg, UUID, 'puppettering')
const page = await browser.newPage()
await page.goto('https://ruf.emessage.de/')
const serviceSelect = 'select[name="pageSendForm:serviceSelect"]'
await page.waitForSelector(serviceSelect)
await page.select(serviceSelect, serviceName)
await page.click(serviceSelect)
await page.click(serviceSelect)
await sleep(1e3)
const selectServiceButton = 'input[name="pageSendForm:selectServiceButton"]'
await page.waitForSelector(selectServiceButton)
await page.click(selectServiceButton)
const pagerNumberInput = 'input[name="pageSendForm:pagerNumberInput"]'
await page.waitForSelector(pagerNumberInput)
await page.type(pagerNumberInput, identifier)
const validatePagerNumberButton = 'input[id="pageSendForm:validatePagerNumberButton"]'
await page.waitForSelector(validatePagerNumberButton)
await page.click(validatePagerNumberButton)
const pageContentInput = 'textarea[id="pageSendForm:pageContentInput"]'
await page.waitForSelector(pageContentInput)
await page.type(pageContentInput, payloadBuffer.toString('ascii'))
const sendPageButton = 'input[id="pageSendForm:sendPageButton"]'
await page.waitForSelector(sendPageButton)
await page.click(sendPageButton)
const messageSentResult = 'span[id="pageSendForm:messageSentResult"]'
await page.waitForSelector(messageSentResult)
let $messageSentResult = await page.$(messageSentResult)
let value = await page.evaluate(el => el.textContent, $messageSentResult)
// pageSendForm:messageSentResult
if (value.indexOf("Meldung : OK") > -1) {
this.connectorRegistry.reportState(msg, UUID, 'transit')
await browser.close()
return res(true)
} else {
this.connectorRegistry.reportState(msg, UUID, 'fail')
await browser.close()
return rej(value)
}
})
sendPromise
.catch((err) => {
console.error(err)
this.connectorRegistry.reportFail(msg, UUID)
return false
})
}
}
module.exports = eMessagePuppeteerConnector

@ -2,6 +2,7 @@ module.exports = {
DAPNETConnector: require("./DAPNETConnector"), DAPNETConnector: require("./DAPNETConnector"),
eCityrufConnector: require('./eCityrufConnector'), eCityrufConnector: require('./eCityrufConnector'),
eMessageConnector: require('./eMessageConnector'), eMessageConnector: require('./eMessageConnector'),
eMessagePuppeteerConnector: require('./eMessagePuppeteerConnector'),
LoRaWANConnector: require("./LoRaWANConnector"), LoRaWANConnector: require("./LoRaWANConnector"),
POCSAGConnector: require("./POCSAGConnector"), POCSAGConnector: require("./POCSAGConnector"),
DummyConnector: require("./DummyConnector"), DummyConnector: require("./DummyConnector"),

Loading…
Cancel
Save