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
61bbce57
Commit
61bbce57
authored
Sep 20, 2018
by
Chavee Issariyapat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update topic protocol
parent
8b9e2a85
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
10 deletions
+34
-10
authhook/auth_on_publish.js
+10
-3
authhook/auth_on_subscribe.js
+0
-2
authhook/utils/getTopic.js
+9
-5
authhook/utils/modify.js
+15
-0
No files found.
authhook/auth_on_publish.js
View file @
61bbce57
...
...
@@ -27,15 +27,17 @@ module.exports = function (options = {}) {
var
authstatus
=
cache
.
get
(
cachekey
);
// checkRole
var
checkRealDB
=
require
(
'./checkClientRole'
).
checkRealDB
var
checkRealDB
=
require
(
'./checkClientRole'
).
checkRealDB
;
checkRealDB
(
req
.
body
.
username
,
(
err
,
decoded
)
=>
{
if
(
err
)
{
// Set Response
var
isShadow
=
require
(
'./utils/getTopic'
).
isShadow
if
(
isShadow
(
topic
))
{
var
output
=
{};
var
getGroupID
=
require
(
'./utils/getGroupID'
).
getGroupID
getGroupID
(
req
.
body
.
username
,
req
.
body
.
client_id
,
(
_id
)
=>
{
// get groupID
var
_ftopic
=
require
(
'./utils/getTopic'
).
rewriteTopic
(
topic
,
'pub'
,
_id
,
req
.
body
.
client_id
)
// get topic where concat with groupID
var
_ftopic
=
require
(
'./utils/getTopic'
).
rewriteTopic
(
topic
,
'pub'
,
_id
,
req
.
body
.
client_id
,
output
);
// get topic where concat with groupID
var
response
=
{
'result'
:
'ok'
,
'modifiers'
:
{
...
...
@@ -44,7 +46,12 @@ module.exports = function (options = {}) {
'retain'
:
false
}
}
console
.
log
(
response
)
if
(
output
.
verb
==
'get'
||
output
.
verb
==
'read'
)
{
response
.
modifiers
.
payload
=
Buffer
.
from
(
req
.
body
.
client_id
).
toString
(
'base64'
);
}
console
.
log
(
response
);
if
(
typeof
(
authstatus
)
==
'undefined'
)
{
// cache missed
...
...
authhook/auth_on_subscribe.js
View file @
61bbce57
...
...
@@ -97,9 +97,7 @@ module.exports = function (options = {}) {
}
}
else
{
console
.
log
(
'>>>>>>>>>>>>>>>>>>>'
)
console
.
log
(
decoded
)
console
.
log
(
'>>>>>>>>>>>>>>>>>>>'
)
if
(
decoded
.
role
===
'realtimedb'
)
{
var
response
=
{
'result'
:
'ok'
...
...
authhook/utils/getTopic.js
View file @
61bbce57
...
...
@@ -21,18 +21,22 @@
var
modify
=
require
(
'./modify'
);
function
rewriteTopic
(
topic
,
op
,
groupid
,
clientid
)
{
var
chunk
=
topic
.
split
(
'/'
,
2
);
function
rewriteTopic
(
topic
,
op
,
groupid
,
clientid
,
output
)
{
var
chunk
=
topic
.
split
(
'/'
);
switch
(
chunk
[
0
])
{
case
'@msg'
:
return
modify
.
insertWordIntoTopic
(
topic
,
'!'
+
clientid
,
1
);
case
'@shadow'
:
if
(
chunk
[
1
]
==
'write'
)
if
(
chunk
[
1
]
==
'write'
||
chunk
[
1
]
==
'read'
)
{
output
.
verb
=
chunk
[
1
];
return
modify
.
insertWordIntoTopic
(
topic
,
''
+
clientid
,
2
);
else
if
(
chunk
[
1
]
==
'set'
)
return
modify
.
insertWordIntoTopic
(
topic
,
''
+
groupid
,
2
);
}
else
if
(
chunk
[
1
]
==
'set'
||
chunk
[
1
]
==
'get'
)
{
output
.
verb
=
chunk
[
1
];
return
modify
.
insertWordIntoTopic
(
topic
,
groupid
,
2
);
}
else
if
(
chunk
[
1
]
==
'changed'
)
{
if
(
op
==
'pub'
)
{
...
...
authhook/utils/modify.js
View file @
61bbce57
module
.
exports
.
insertWordIntoTopic
=
insertWordIntoTopic
module
.
exports
.
removeTempWordInTopic
=
removeTempWordInTopic
module
.
exports
.
replaceWords
=
replaceWords
module
.
exports
.
cleanUpTopic
=
cleanUpTopic
/*
Ex: insertWordIntoTopic('@shadow/home/temp', '!GROUP', 1)
...
...
@@ -31,7 +33,20 @@ function removeTempWordInTopic(topic) {
return
a
.
join
(
'/'
);
}
function
replaceWords
(
topic
,
word
,
from
,
to
)
{
var
a
=
topic
.
split
(
'/'
);
a
.
splice
(
from
,
to
-
from
+
1
);
if
(
word
!=
null
)
a
.
splice
(
from
,
0
,
word
);
return
a
.
join
(
'/'
);
}
// Sample
// var str = insertWordIntoTopic('@shadow/home/temp', '!GROUP', 0);
// console.log(str);
// console.log(removeTempWordInTopic(str));
//console.log(replaceWords('@shadow/set/home/bob/bedroom/temp', 'CLIENTID-XXXXX', 2, 3));
function
cleanUpTopic
(
topic
)
{
topic
=
topic
.
trim
();
if
(
topic
.
substr
(
-
1
)
==
'/'
)
return
topic
.
slice
(
-
1
);
}
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