Commit 410ac110 by Chavee Issariyapat

Merge branch 'alpha-test' of https://dev.nexpie.com/stack/vernemq into alpha-test

parents 7cbbb0fb 36200e3c
......@@ -13,6 +13,7 @@ var auth_on_subscribe = require('./auth_on_subscribe')({ debug: auth_on_subscrib
var on_publish = require('./on_publish')({ debug: on_publish_debug });
var on_deliver = require('./on_deliver').on_deliver
var signRole = require('./checkClientRole').signRole
var on_unsubscribe = require('./on_unsubscribe').on_unsubscribe
const server = restify.createServer({
name: 'authhook',
......@@ -39,6 +40,7 @@ server.post('/onsub', (req,res,next) => {
console.log(req.body)
res.send('')
})
server.post('/onunsub', on_unsubscribe)
server.post('/ondeliver', on_deliver)
server.post('/onpub', on_publish)
server.post('/signRole', signRole)
......
......@@ -19,6 +19,7 @@ function hasGroup(topics) {
}
else return false
}
module.exports.hasGroup = hasGroup
function beDesireTopic(topics) {
if (hasGroup(topics)) {
......@@ -26,8 +27,10 @@ function beDesireTopic(topics) {
}
else return topics
}
module.exports.beDesireTopic = beDesireTopic
function joinTopic(topics) {
var topic = topics.split('/!')[1]
return topics.split('/!')[0] + topic.substring(topic.indexOf('/'), topic.length)
}
\ No newline at end of file
}
module.exports.joinTopic = joinTopic
\ No newline at end of file
function on_unsubscribe(req, res, next) {
console.log('------on unsubscribe-------')
console.log(req.body)
var topic = req.body.topics[0];
// checkRole
var checkRealDB = require('./checkClientRole').checkRealDB
checkRealDB(req.body.username, (err, decoded) => {
if (err) {
// Set Response
var getGroupID = require('./utils/getGroupID').getGroupID
getGroupID(req.body.username, req.body.client_id, (_id) => { // get groupID
// console.log(_id)
var _ftopic = require('./utils/getTopic').getTopic(topic, _id) // get topic where concat with groupID
var response = {
"result": "ok",
"topics": [_ftopic]
}
console.log(response)
res.send(response);
})
}
else {
console.log(decoded)
if (decoded.role === 'realtimedb') {
var response = {
'result': 'ok'
}
console.log(response)
res.send(response);
}
}
})
}
module.exports.on_unsubscribe = on_unsubscribe
\ No newline at end of file
......@@ -817,6 +817,9 @@ vmq_webhooks.webhook3.endpoint = http://localhost:40000/authpub
vmq_webhooks.webhook5.hook = on_deliver
vmq_webhooks.webhook5.endpoint = http://localhost:40000/ondeliver
vmq_webhooks.webhook6.hook = on_unsubscribe
vmq_webhooks.webhook6.endpoint = http://localhost:40000/onunsub
## Specify the address and port of the bridge to connect to. Several
## bridges can configured by using different bridge names (e.g. br0). If the
## connection supports SSL encryption bridge.ssl.<name> can be used.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment