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
1c99fce2
Commit
1c99fce2
authored
Sep 26, 2018
by
Chavee Issariyapat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug
parent
47162778
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
21 deletions
+35
-21
authhook/auth_on_publish.js
+5
-0
authhook/auth_on_subscribe.js
+6
-9
authhook/index.js
+4
-2
authhook/on_deliver.js
+7
-6
authhook/on_unsubscribe.js
+10
-3
authhook/utils/getTopic.js
+3
-1
No files found.
authhook/auth_on_publish.js
View file @
1c99fce2
...
...
@@ -53,6 +53,11 @@ module.exports = function (options = {}) {
'retain'
:
false
}
}
if
(
options
.
debug
)
{
console
.
log
(
response
);
}
if
(
output
.
verb
==
'get'
||
output
.
verb
==
'read'
)
{
response
.
modifiers
.
payload
=
Buffer
.
from
(
req
.
body
.
client_id
).
toString
(
'base64'
);
}
...
...
authhook/auth_on_subscribe.js
View file @
1c99fce2
...
...
@@ -6,17 +6,8 @@ var LRU = require("lru-cache"),
max
:
500
,
maxAge
:
1000
*
60
*
5
});
var
debug
=
false
;
// for testing
// function authCheck(client_id, token, topic, callback) {
// callback(true);
// }
module
.
exports
=
function
(
options
=
{})
{
debug
=
options
.
debug
||
false
;
return
function
(
req
,
res
,
next
)
{
if
(
options
.
debug
)
{
...
...
@@ -46,6 +37,7 @@ module.exports = function (options = {}) {
var
GGID
=
require
(
'./utils/getGroupID'
);
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
_topic
=
[{
// setTopic for response
'topic'
:
_ftopic
,
...
...
@@ -55,6 +47,11 @@ module.exports = function (options = {}) {
'result'
:
'ok'
,
'topics'
:
_topic
}
if
(
options
.
debug
)
{
console
.
log
(
response
);
}
res
.
send
(
response
);
next
();
});
...
...
authhook/index.js
View file @
1c99fce2
...
...
@@ -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_subscribe_debug
=
process
.
env
[
"AUTH_ON_SUBSCRIBE_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
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_subscribe
=
require
(
'./auth_on_subscribe'
)({
debug
:
auth_on_subscribe_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
on_unsubscribe
=
require
(
'./on_unsubscribe'
).
on_unsubscribe
const
server
=
restify
.
createServer
({
name
:
'authhook'
,
...
...
authhook/on_deliver.js
View file @
1c99fce2
var
modify
=
require
(
'./utils/modify'
);
function
on_deliver
(
req
,
res
,
next
)
{
module
.
exports
=
function
(
options
=
{})
{
return
function
(
req
,
res
,
next
)
{
console
.
log
(
'----on_deliver-----'
)
var
topics
=
modify
.
removeTempWordInTopic
(
req
.
body
.
topic
)
console
.
log
(
req
.
body
)
...
...
@@ -13,11 +14,11 @@ function on_deliver(req, res, next) {
}
console
.
log
(
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
]
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
authhook/on_unsubscribe.js
View file @
1c99fce2
function
on_unsubscribe
(
req
,
res
,
next
)
{
module
.
exports
=
function
(
options
=
{})
{
return
function
(
req
,
res
,
next
)
{
console
.
log
(
'------on unsubscribe-------'
)
console
.
log
(
req
.
body
)
var
topic
=
req
.
body
.
topics
[
0
];
...
...
@@ -27,9 +28,15 @@ function on_unsubscribe(req, res, next) {
}
}
else
response
=
{
'result'
:
'no'
}
if
(
options
.
debug
)
{
console
.
log
(
'on_unsubscribe-------------'
);
console
.
log
(
response
);
}
res
.
send
(
response
);
next
()
});
}
}
}
\ No newline at end of file
module
.
exports
.
on_unsubscribe
=
on_unsubscribe
\ No newline at end of file
authhook/utils/getTopic.js
View file @
1c99fce2
...
...
@@ -3,9 +3,11 @@ var modify = require('./modify');
function
rewriteTopic
(
topic
,
op
,
groupid
,
clientid
,
output
)
{
var
chunk
=
topic
.
split
(
'/'
);
console
.
log
(
groupid
);
switch
(
chunk
[
0
])
{
case
'@msg'
:
return
modify
.
insertWordIntoTopic
(
topic
,
'!'
+
client
id
,
1
);
return
modify
.
insertWordIntoTopic
(
topic
,
'!'
+
group
id
,
1
);
case
'@shadow'
:
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