Commit 7ac5ed06 by Chavee Issariyapat

Merge branch 'master' of https://dev.nexpie.com/stack/vernemq

parents 1c918283 1c99fce2
...@@ -53,6 +53,11 @@ module.exports = function (options = {}) { ...@@ -53,6 +53,11 @@ module.exports = function (options = {}) {
'retain': false 'retain': false
} }
} }
if (options.debug) {
console.log(response);
}
if (output.verb == 'get' || output.verb == 'read') { if (output.verb == 'get' || output.verb == 'read') {
response.modifiers.payload = Buffer.from(req.body.client_id).toString('base64'); response.modifiers.payload = Buffer.from(req.body.client_id).toString('base64');
} }
......
...@@ -6,17 +6,8 @@ var LRU = require("lru-cache"), ...@@ -6,17 +6,8 @@ var LRU = require("lru-cache"),
max: 500, max: 500,
maxAge: 1000 * 60 * 5 maxAge: 1000 * 60 * 5
}); });
var debug = false;
// for testing
// function authCheck(client_id, token, topic, callback) {
// callback(true);
// }
module.exports = function (options = {}) { module.exports = function (options = {}) {
debug = options.debug || false;
return function (req, res, next) { return function (req, res, next) {
if (options.debug) { if (options.debug) {
...@@ -46,6 +37,7 @@ module.exports = function (options = {}) { ...@@ -46,6 +37,7 @@ module.exports = function (options = {}) {
var GGID = require('./utils/getGroupID'); var GGID = require('./utils/getGroupID');
GGID.getGroupID(req.body.username, req.body.client_id, function(group) { GGID.getGroupID(req.body.username, req.body.client_id, function(group) {
console.log(group);
var _ftopic = require('./utils/getTopic').rewriteTopic(topic, 'sub', group, req.body.client_id) // get topic where concat with groupID var _ftopic = require('./utils/getTopic').rewriteTopic(topic, 'sub', group, req.body.client_id) // get topic where concat with groupID
var _topic = [{ // setTopic for response var _topic = [{ // setTopic for response
'topic': _ftopic, 'topic': _ftopic,
...@@ -55,6 +47,11 @@ module.exports = function (options = {}) { ...@@ -55,6 +47,11 @@ module.exports = function (options = {}) {
'result': 'ok', 'result': 'ok',
'topics': _topic 'topics': _topic
} }
if (options.debug) {
console.log(response);
}
res.send(response); res.send(response);
next(); next();
}); });
......
...@@ -5,15 +5,17 @@ var auth_on_register_debug = process.env["AUTH_ON_REGISTER_DEBUG"] || false; ...@@ -5,15 +5,17 @@ var auth_on_register_debug = process.env["AUTH_ON_REGISTER_DEBUG"] || false;
var auth_on_publish_debug = process.env["AUTH_ON_PUBLISH_DEBUG"] || true; var auth_on_publish_debug = process.env["AUTH_ON_PUBLISH_DEBUG"] || true;
var auth_on_subscribe_debug = process.env["AUTH_ON_SUBSCRIBE_DEBUG"] || true; var auth_on_subscribe_debug = process.env["AUTH_ON_SUBSCRIBE_DEBUG"] || true;
var on_publish_debug = process.env["ON_PUBLISH_DEBUG"] || true; var on_publish_debug = process.env["ON_PUBLISH_DEBUG"] || true;
var on_deliver_debug = process.env["ON_DELIVER_DEBUG"] || true;
var on_unsubscribe_debug = process.env["ON_UNSUBSCRIBE_DEBUG"] || true;
var restify = require('restify'); var restify = require('restify');
var auth_on_register = require('./auth_on_register')({ debug: auth_on_register_debug }); var auth_on_register = require('./auth_on_register')({ debug: auth_on_register_debug });
var auth_on_publish = require('./auth_on_publish')({ debug: auth_on_publish_debug }); var auth_on_publish = require('./auth_on_publish')({ debug: auth_on_publish_debug });
var auth_on_subscribe = require('./auth_on_subscribe')({ debug: auth_on_subscribe_debug }); var auth_on_subscribe = require('./auth_on_subscribe')({ debug: auth_on_subscribe_debug });
var on_publish = require('./on_publish')({ debug: on_publish_debug }); var on_publish = require('./on_publish')({ debug: on_publish_debug });
var on_deliver = require('./on_deliver').on_deliver var on_deliver = require('./on_deliver')({ debug: on_deliver_debug });
var on_unsubscribe = require('./on_unsubscribe')({ debug: on_unsubscribe_debug });
var signRole = require('./checkClientRole').signRole var signRole = require('./checkClientRole').signRole
var on_unsubscribe = require('./on_unsubscribe').on_unsubscribe
const server = restify.createServer({ const server = restify.createServer({
name: 'authhook', name: 'authhook',
......
var modify = require('./utils/modify'); var modify = require('./utils/modify');
function on_deliver(req, res, next) { module.exports = function(options = {}) {
return function (req, res, next) {
console.log('----on_deliver-----') console.log('----on_deliver-----')
var topics = modify.removeTempWordInTopic(req.body.topic) var topics = modify.removeTempWordInTopic(req.body.topic)
console.log(req.body) console.log(req.body)
...@@ -13,11 +14,11 @@ function on_deliver(req, res, next) { ...@@ -13,11 +14,11 @@ function on_deliver(req, res, next) {
} }
console.log(response); console.log(response);
res.send(response) res.send(response)
} }
module.exports.on_deliver = on_deliver module.exports.on_deliver = on_deliver
function joinTopic(topics) { function joinTopic(topics) {
var topic = topics.split('/!')[1] var topic = topics.split('/!')[1]
return topics.split('/!')[0] + topic.substring(topic.indexOf('/'), topic.length) 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) { module.exports = function(options = {}) {
return function (req, res, next) {
console.log('------on unsubscribe-------') console.log('------on unsubscribe-------')
console.log(req.body) console.log(req.body)
var topic = req.body.topics[0]; var topic = req.body.topics[0];
...@@ -27,9 +28,15 @@ function on_unsubscribe(req, res, next) { ...@@ -27,9 +28,15 @@ function on_unsubscribe(req, res, next) {
} }
} }
else response = { 'result': 'no' } else response = { 'result': 'no' }
if (options.debug) {
console.log('on_unsubscribe-------------');
console.log(response);
}
res.send(response); res.send(response);
next() next()
}); });
} }
}
} }
\ No newline at end of file
module.exports.on_unsubscribe = on_unsubscribe
\ No newline at end of file
...@@ -3,9 +3,11 @@ var modify = require('./modify'); ...@@ -3,9 +3,11 @@ var modify = require('./modify');
function rewriteTopic(topic, op, groupid, clientid, output) { function rewriteTopic(topic, op, groupid, clientid, output) {
var chunk = topic.split('/'); var chunk = topic.split('/');
console.log(groupid);
switch (chunk[0]) { switch (chunk[0]) {
case '@msg' : case '@msg' :
return modify.insertWordIntoTopic(topic, '!'+clientid, 1); return modify.insertWordIntoTopic(topic, '!'+groupid, 1);
case '@shadow' : case '@shadow' :
if (chunk[1] == 'write' || chunk[1] == 'read') { if (chunk[1] == 'write' || chunk[1] == 'read') {
......
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