parent
d199343535
commit
1f3cfa148b
@ -1,35 +0,0 @@
|
|||||||
import Action from './../../packages/server/actions/action.js'
|
|
||||||
import XmppHelper from './../helpers/Xmpp.js'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Getting Http State
|
|
||||||
*
|
|
||||||
* @author Björn Hase <me@herr-hase.wtf>
|
|
||||||
* @license http://opensource.org/licenses/MIT The MIT License
|
|
||||||
* @link https://git.node001.net/HerrHase/super-hog.git
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
class Pingdom extends Action {
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
async run() {
|
|
||||||
|
|
||||||
const xmppHelper = new XmppHelper(
|
|
||||||
process.env.XMPP_SERVICE,
|
|
||||||
process.env.XMPP_DOMAIN,
|
|
||||||
process.env.XMPP_USERNAME,
|
|
||||||
process.env.XMPP_PASSWORD
|
|
||||||
)
|
|
||||||
|
|
||||||
const message = this.data.check_params.full_url + ' / ' + this.data.current_state
|
|
||||||
await xmppHelper.sendToRoom(this.flow, process.env.XMPP_ROOM, message)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Pingdom
|
|
||||||
@ -1,32 +0,0 @@
|
|||||||
import Action from './../../packages/server/actions/action.js'
|
|
||||||
import XmppHelper from './../helpers/Xmpp.js'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Xmpp Message
|
|
||||||
*
|
|
||||||
* @author Björn Hase <me@herr-hase.wtf>
|
|
||||||
* @license http://opensource.org/licenses/MIT The MIT License
|
|
||||||
* @link https://git.node001.net/HerrHase/super-hog.git
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
class Xmpp extends Action {
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
async run() {
|
|
||||||
const xmppHelper = new XmppHelper(
|
|
||||||
process.env.XMPP_SERVICE,
|
|
||||||
process.env.XMPP_DOMAIN,
|
|
||||||
process.env.XMPP_USERNAME,
|
|
||||||
process.env.XMPP_PASSWORD
|
|
||||||
)
|
|
||||||
|
|
||||||
await xmppHelper.sendToRoom(this.flow, process.env.XMPP_ROOM, this.data.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Xmpp
|
|
||||||
@ -1,80 +0,0 @@
|
|||||||
import { client, xml } from '@xmpp/client'
|
|
||||||
import debug from '@xmpp/debug'
|
|
||||||
import DOMPurify from 'isomorphic-dompurify'
|
|
||||||
|
|
||||||
import Action from './../../packages/server/actions/action.js'
|
|
||||||
import logger from './../../packages/server/helper/logger.js'
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author Björn Hase <me@herr-hase.wtf>
|
|
||||||
* @license http://opensource.org/licenses/MIT The MIT License
|
|
||||||
* @link https://git.node001.net/HerrHase/super-hog.git
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
class XmppHelper {
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
constructor(service, domain, username, password) {
|
|
||||||
this.service = service
|
|
||||||
this.domain = domain
|
|
||||||
this.username = username
|
|
||||||
this.password = password
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
async sendToRoom(flow, room, message) {
|
|
||||||
|
|
||||||
// cleaning data
|
|
||||||
message = DOMPurify.sanitize(message)
|
|
||||||
|
|
||||||
const xmpp = client({
|
|
||||||
service: this.service,
|
|
||||||
domain: this.domain,
|
|
||||||
username: this.username,
|
|
||||||
password: this.password
|
|
||||||
})
|
|
||||||
|
|
||||||
if (process.env.APP_DEBUG) {
|
|
||||||
debug(xmpp, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle if client has errors
|
|
||||||
xmpp.on('error', (error) => {
|
|
||||||
logger(flow.uuid).error('xmpp / error ' + error)
|
|
||||||
})
|
|
||||||
|
|
||||||
// handle if client goes online
|
|
||||||
xmpp.once('online', async (address) => {
|
|
||||||
|
|
||||||
// join group
|
|
||||||
await xmpp.send(xml("presence", { to: room + '/' + this.username }, xml("x", { xmlns: 'http://jabber.org/protocol/muc' })))
|
|
||||||
|
|
||||||
// sends a message to the room
|
|
||||||
const message = xml(
|
|
||||||
'message', {
|
|
||||||
type: 'groupchat',
|
|
||||||
to: room
|
|
||||||
},
|
|
||||||
xml('body', {}, message)
|
|
||||||
)
|
|
||||||
|
|
||||||
await xmpp.send(message)
|
|
||||||
logger(flow.uuid).info('xmpp / message send')
|
|
||||||
|
|
||||||
await xmpp.disconnect()
|
|
||||||
})
|
|
||||||
|
|
||||||
await xmpp.start()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default XmppHelper
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"private": true,
|
|
||||||
"name": "custom",
|
|
||||||
"type": "module",
|
|
||||||
"dependencies": {
|
|
||||||
"@xmpp/client": "^0.14.0"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@xmpp/debug": "^0.14.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in new issue