Compare commits
No commits in common. '1f3cfa148b6578fb2a19ec5696cc66afc782b251' and 'e689be1b42a79e95fa3ca3daa8ac9e5f862e3361' have entirely different histories.
1f3cfa148b
...
e689be1b42
@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"private": true,
|
|
||||||
"name": "custom",
|
|
||||||
"type": "module"
|
|
||||||
}
|
|
||||||
@ -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,12 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "signpost",
|
"name": "signpost",
|
||||||
"version": "0.2.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"packages/*",
|
"packages/*"
|
||||||
"custom"
|
]
|
||||||
],
|
|
||||||
"scripts": {
|
|
||||||
"custom": "cp custom/package-custom.json custom/package.json"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,27 +0,0 @@
|
|||||||
import { input, password } from '@inquirer/prompts'
|
|
||||||
import { v4 as uuidv4 } from 'uuid'
|
|
||||||
import path from 'path'
|
|
||||||
import chalk from 'chalk'
|
|
||||||
import crypto from 'node:crypto'
|
|
||||||
|
|
||||||
import runMigrationSqlite from './../db/migration.js'
|
|
||||||
import getOrCreateSqlite from './../db/sqlite.js'
|
|
||||||
|
|
||||||
import TokenHelper from './../helper/token.js'
|
|
||||||
|
|
||||||
// getting flow
|
|
||||||
import FlowStore from './../store/flow.js'
|
|
||||||
|
|
||||||
// get config
|
|
||||||
import config from './../_config.js'
|
|
||||||
config()
|
|
||||||
|
|
||||||
// getting db and flowStore
|
|
||||||
const mainDB = getOrCreateSqlite({ 'uri': process.env.APP_SQLITE_URI_MAIN, 'create': true, 'readwrite': true })
|
|
||||||
const flowStore = new FlowStore(mainDB)
|
|
||||||
|
|
||||||
const results = flowStore.find()
|
|
||||||
|
|
||||||
for (const result of results) {
|
|
||||||
console.log(chalk.green(result.uuid + ' / Action: ' + result.action + ' / Schema: ' + result.schema))
|
|
||||||
}
|
|
||||||
@ -1,44 +0,0 @@
|
|||||||
import DOMPurify from 'isomorphic-dompurify'
|
|
||||||
import TokenHelper from './../helper/token.js'
|
|
||||||
import logger from './../helper/logger.js'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* handle token
|
|
||||||
*
|
|
||||||
* @author Björn Hase <me@herr-hase.wtf>
|
|
||||||
* @license hhttps://www.gnu.org/licenses/gpl-3.0.en.html GPL-3
|
|
||||||
* @link https://git.node001.net/HerrHase/signpost.git
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
async function bearerHandler(request, response) {
|
|
||||||
|
|
||||||
if (!request.headers.authorization) {
|
|
||||||
return response
|
|
||||||
.code(403)
|
|
||||||
.send()
|
|
||||||
}
|
|
||||||
|
|
||||||
let token = DOMPurify.sanitize(request.headers.authorization)
|
|
||||||
token = token.match(/^Bearer ([A-Za-z0-9._~+/-]+=*)$/)
|
|
||||||
|
|
||||||
// check if token exists
|
|
||||||
if (!token || !token[1]) {
|
|
||||||
logger(response.locals.flow.uuid).error('token not found in header')
|
|
||||||
|
|
||||||
return response
|
|
||||||
.code(403)
|
|
||||||
.send()
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if token is same as for the flow
|
|
||||||
if (!TokenHelper.equal(token[1], response.locals.flow.hash)) {
|
|
||||||
logger(response.locals.flow.uuid).error('token not equal with hash from flow')
|
|
||||||
|
|
||||||
return response
|
|
||||||
.code(403)
|
|
||||||
.send()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default bearerHandler
|
|
||||||
Loading…
Reference in new issue