Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
vernemq
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
stack
vernemq
Commits
7ac5ed06
Commit
7ac5ed06
authored
Sep 26, 2018
by
Chavee Issariyapat
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://dev.nexpie.com/stack/vernemq
parents
1c918283
1c99fce2
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
75 additions
and
61 deletions
+75
-61
authhook/auth_on_publish.js
+5
-0
authhook/auth_on_subscribe.js
+6
-9
authhook/index.js
+4
-2
authhook/on_deliver.js
+20
-19
authhook/on_unsubscribe.js
+37
-30
authhook/utils/getTopic.js
+3
-1
No files found.
authhook/auth_on_publish.js
View file @
7ac5ed06
...
@@ -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'
);
}
}
...
...
authhook/auth_on_subscribe.js
View file @
7ac5ed06
...
@@ -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
();
});
});
...
...
authhook/index.js
View file @
7ac5ed06
...
@@ -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'
,
...
...
authhook/on_deliver.js
View file @
7ac5ed06
var
modify
=
require
(
'./utils/modify'
);
var
modify
=
require
(
'./utils/modify'
);
function
on_deliver
(
req
,
res
,
next
)
{
module
.
exports
=
function
(
options
=
{})
{
console
.
log
(
'----on_deliver-----'
)
return
function
(
req
,
res
,
next
)
{
var
topics
=
modify
.
removeTempWordInTopic
(
req
.
body
.
topic
)
console
.
log
(
'----on_deliver-----'
)
console
.
log
(
req
.
body
)
var
topics
=
modify
.
removeTempWordInTopic
(
req
.
body
.
topic
)
// console.log(topics)
console
.
log
(
req
.
body
)
var
response
=
{
// console.log(topics)
'result'
:
'ok'
,
var
response
=
{
'modifiers'
:
{
'result'
:
'ok'
,
"topic"
:
topics
'modifiers'
:
{
"topic"
:
topics
}
}
}
console
.
log
(
response
);
res
.
send
(
response
)
}
}
console
.
log
(
response
);
module
.
exports
.
on_deliver
=
on_deliver
res
.
send
(
response
)
}
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
)
}
}
module
.
exports
.
joinTopic
=
joinTopic
}
\ No newline at end of file
\ No newline at end of file
authhook/on_unsubscribe.js
View file @
7ac5ed06
function
on_unsubscribe
(
req
,
res
,
next
)
{
module
.
exports
=
function
(
options
=
{})
{
console
.
log
(
'------on unsubscribe-------'
)
return
function
(
req
,
res
,
next
)
{
console
.
log
(
req
.
body
)
console
.
log
(
'------on unsubscribe-------'
)
var
topic
=
req
.
body
.
topics
[
0
];
console
.
log
(
req
.
body
)
var
token
=
req
.
body
.
username
var
topic
=
req
.
body
.
topics
[
0
];
var
client_id
=
req
.
body
.
client_id
var
token
=
req
.
body
.
username
var
response
var
client_id
=
req
.
body
.
client_id
var
response
var
decoded
=
require
(
'./checkClientRole'
).
checkRealDB
(
token
)
var
decoded
=
require
(
'./checkClientRole'
).
checkRealDB
(
token
)
if
(
decoded
)
{
if
(
decoded
)
{
if
(
decoded
.
role
===
'realtimedb'
)
{
if
(
decoded
.
role
===
'realtimedb'
)
{
response
=
{
'result'
:
'ok'
}
response
=
{
'result'
:
'ok'
}
}
else
response
=
{
'result'
:
'no'
}
res
.
send
(
response
);
next
()
}
else
{
var
GGID
=
require
(
'./utils/getGroupID'
);
GGID
.
getGroupID
(
token
,
client_id
,
function
(
group
)
{
if
(
group
)
{
var
_ftopic
=
require
(
'./utils/getTopic'
).
rewriteTopic
(
topic
,
'unsub'
,
group
,
client_id
)
response
=
{
"result"
:
"ok"
,
"topics"
:
[
_ftopic
]
}
}
}
else
response
=
{
'result'
:
'no'
}
else
response
=
{
'result'
:
'no'
}
res
.
send
(
response
);
res
.
send
(
response
);
next
()
next
()
});
}
else
{
var
GGID
=
require
(
'./utils/getGroupID'
);
GGID
.
getGroupID
(
token
,
client_id
,
function
(
group
)
{
if
(
group
)
{
var
_ftopic
=
require
(
'./utils/getTopic'
).
rewriteTopic
(
topic
,
'unsub'
,
group
,
client_id
)
response
=
{
"result"
:
"ok"
,
"topics"
:
[
_ftopic
]
}
}
else
response
=
{
'result'
:
'no'
}
if
(
options
.
debug
)
{
console
.
log
(
'on_unsubscribe-------------'
);
console
.
log
(
response
);
}
res
.
send
(
response
);
next
()
});
}
}
}
}
}
module
.
exports
.
on_unsubscribe
=
on_unsubscribe
\ No newline at end of file
\ No newline at end of file
authhook/utils/getTopic.js
View file @
7ac5ed06
...
@@ -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
,
'!'
+
client
id
,
1
);
return
modify
.
insertWordIntoTopic
(
topic
,
'!'
+
group
id
,
1
);
case
'@shadow'
:
case
'@shadow'
:
if
(
chunk
[
1
]
==
'write'
||
chunk
[
1
]
==
'read'
)
{
if
(
chunk
[
1
]
==
'write'
||
chunk
[
1
]
==
'read'
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment