parent
664ffa6134
commit
d199343535
@ -0,0 +1,35 @@
|
|||||||
|
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
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
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
|
||||||
@ -0,0 +1,80 @@
|
|||||||
|
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
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"private": true,
|
||||||
|
"name": "custom",
|
||||||
|
"type": "module"
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"private": true,
|
||||||
|
"name": "custom",
|
||||||
|
"type": "module",
|
||||||
|
"dependencies": {
|
||||||
|
"@xmpp/client": "^0.14.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@xmpp/debug": "^0.14.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
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
|
||||||
@ -0,0 +1,80 @@
|
|||||||
|
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,8 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "signpost",
|
"name": "signpost",
|
||||||
"version": "0.1.0",
|
"version": "0.2.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"packages/*"
|
"packages/*",
|
||||||
]
|
"custom"
|
||||||
|
],
|
||||||
|
"scripts": {
|
||||||
|
"custom": "cp custom/package-custom.json custom/package.json"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,27 @@
|
|||||||
|
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))
|
||||||
|
}
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
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