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
203665ed
Commit
203665ed
authored
Oct 31, 2018
by
Mine ArithmeticOp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check group not null before pubsub
parent
f9fd9373
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
36 deletions
+45
-36
authhook/auth_on_publish.js
+22
-18
authhook/auth_on_register.js
+2
-2
authhook/auth_on_subscribe.js
+21
-16
No files found.
authhook/auth_on_publish.js
View file @
203665ed
...
...
@@ -27,7 +27,7 @@ module.exports = function (options = {}) {
var
response
var
decoded
=
require
(
'jwt-verify'
).
verify
(
req
.
body
.
username
).
res
if
(
decoded
)
{
if
(
decoded
.
role
===
'realtimedb'
)
response
=
{
'result'
:
'ok'
}
else
response
=
{
'result'
:
'no'
}
...
...
@@ -39,27 +39,31 @@ module.exports = function (options = {}) {
var
output
=
{};
GGID
.
getGroupID
(
req
.
body
.
username
,
req
.
body
.
client_id
,
function
(
group
)
{
console
.
log
(
'group: '
+
group
)
var
_ftopic
=
require
(
'./utils/router'
).
rewriteTopic
(
topic
,
'pub'
,
group
,
req
.
body
.
client_id
,
output
);
// get topic where concat with groupID
response
=
{
'result'
:
'ok'
,
'modifiers'
:
{
'topic'
:
_ftopic
,
'qos'
:
0
,
'retain'
:
false
if
(
group
)
{
var
_ftopic
=
require
(
'./utils/router'
).
rewriteTopic
(
topic
,
'pub'
,
group
,
req
.
body
.
client_id
,
output
);
// get topic where concat with groupID
response
=
{
'result'
:
'ok'
,
'modifiers'
:
{
'topic'
:
_ftopic
,
'qos'
:
0
,
'retain'
:
false
}
}
}
if
(
options
.
debug
)
{
console
.
log
(
response
);
}
if
(
options
.
debug
)
{
console
.
log
(
response
);
}
if
(
output
.
verb
==
'get'
||
output
.
verb
==
'read'
)
{
response
.
modifiers
.
payload
=
Buffer
.
from
(
req
.
body
.
client_id
).
toString
(
'base64'
);
if
(
output
.
verb
==
'get'
||
output
.
verb
==
'read'
)
{
response
.
modifiers
.
payload
=
Buffer
.
from
(
req
.
body
.
client_id
).
toString
(
'base64'
);
}
res
.
send
(
response
);
next
();
}
else
{
res
.
send
({
"result"
:
"no"
});
next
();
}
res
.
send
(
response
);
next
();
});
}
}
...
...
authhook/auth_on_register.js
View file @
203665ed
...
...
@@ -32,13 +32,13 @@ function authCheck(client_id, token, password, callback) {
// console.log('result : ' + util.inspect(res.result, false, null, true))
if
(
res
.
result
)
{
var
token_profile
=
(
res
&&
res
.
result
&&
res
.
result
[
0
])
?
res
.
result
[
0
]
:
{};
console
.
log
(
'token_profile: '
+
token_profile
)
console
.
log
(
'token_profile: '
+
util
.
inspect
(
token_profile
,
false
,
null
,
true
)
)
var
mqttauth
=
{
clientid
:
client_id
,
token
:
token
,
password
:
password
};
console
.
log
(
'mqttauth: '
+
mqttauth
)
console
.
log
(
'mqttauth: '
+
util
.
inspect
(
mqttauth
,
false
,
null
,
true
)
)
callback
(
validator
.
auth_connect
(
mqttauth
,
token_profile
));
}
else
{
...
...
authhook/auth_on_subscribe.js
View file @
203665ed
...
...
@@ -26,7 +26,7 @@ module.exports = function (options = {}) {
}
var
response
var
decoded
=
require
(
'jwt-verify'
).
verify
(
req
.
body
.
username
).
res
if
(
decoded
)
{
if
(
decoded
.
role
===
'realtimedb'
)
response
=
{
'result'
:
'ok'
}
else
response
=
{
'result'
:
'no'
}
...
...
@@ -37,23 +37,28 @@ module.exports = function (options = {}) {
var
GGID
=
require
(
'./utils/getGroupID'
);
GGID
.
getGroupID
(
req
.
body
.
username
,
req
.
body
.
client_id
,
function
(
group
)
{
console
.
log
(
'group: '
+
group
)
var
_ftopic
=
require
(
'./utils/router'
).
rewriteTopic
(
topic
,
'sub'
,
group
,
req
.
body
.
client_id
)
// get topic where concat with groupID
var
_topic
=
[{
// setTopic for response
'topic'
:
_ftopic
,
'qos'
:
0
}]
response
=
{
'result'
:
'ok'
,
'topics'
:
_topic
}
if
(
group
)
{
var
_ftopic
=
require
(
'./utils/router'
).
rewriteTopic
(
topic
,
'sub'
,
group
,
req
.
body
.
client_id
)
// get topic where concat with groupID
var
_topic
=
[{
// setTopic for response
'topic'
:
_ftopic
,
'qos'
:
0
}]
response
=
{
'result'
:
'ok'
,
'topics'
:
_topic
}
if
(
options
.
debug
)
{
console
.
log
(
response
);
}
if
(
options
.
debug
)
{
console
.
log
(
response
);
}
res
.
send
(
response
);
next
();
res
.
send
(
response
);
next
();
}
else
{
res
.
send
({
"result"
:
"no"
});
next
();
}
});
}
}
...
...
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