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
74b7fd7f
Commit
74b7fd7f
authored
Sep 16, 2018
by
zCaesar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
can publish onGroup
parent
14c11a3b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
21 deletions
+33
-21
authhook/auth_on_publish.js
+33
-21
No files found.
authhook/auth_on_publish.js
View file @
74b7fd7f
var
config
=
require
(
'config'
);
var
config
=
require
(
'config'
);
// https://github.com/isaacs/node-lru-cache
// https://github.com/isaacs/node-lru-cache
var
LRU
=
require
(
"lru-cache"
)
,
var
LRU
=
require
(
"lru-cache"
),
cache
=
LRU
({
cache
=
LRU
({
max
:
500
,
max
:
500
,
maxAge
:
1000
*
60
*
5
maxAge
:
1000
*
60
*
5
});
});
// for testing
// for testing
function
authCheck
(
client_id
,
username
,
topic
,
callback
)
{
function
authCheck
(
client_id
,
username
,
topic
,
callback
)
{
callback
(
true
);
callback
(
true
);
}
}
module
.
exports
=
function
(
options
=
{})
{
module
.
exports
=
function
(
options
=
{})
{
return
function
(
req
,
res
,
next
)
{
return
function
(
req
,
res
,
next
)
{
if
(
req
.
header
(
'vernemq-hook'
)
==
'auth_on_publish'
&&
req
&&
req
.
body
)
{
if
(
req
.
header
(
'vernemq-hook'
)
==
'auth_on_publish'
&&
req
&&
req
.
body
)
{
if
(
options
.
debug
)
{
if
(
options
.
debug
)
{
...
@@ -23,24 +23,36 @@ module.exports = function(options={}) {
...
@@ -23,24 +23,36 @@ module.exports = function(options={}) {
var
authstatus
;
var
authstatus
;
var
topic
=
req
.
body
.
topic
;
var
topic
=
req
.
body
.
topic
;
var
cachekey
=
'pub:'
+
req
.
body
.
client_id
+
':'
+
req
.
body
.
username
+
':'
+
topic
;
var
cachekey
=
'pub:'
+
req
.
body
.
client_id
+
':'
+
req
.
body
.
username
+
':'
+
topic
;
var
authstatus
=
cache
.
get
(
cachekey
);
var
authstatus
=
cache
.
get
(
cachekey
);
if
(
typeof
(
authstatus
)
==
'undefined'
)
{
// Set Response
// cache missed
var
getGroupID
=
require
(
'./utils/getGroupID'
).
getGroupID
authCheck
(
req
.
body
.
client_id
,
req
.
body
.
username
,
topic
,
function
(
result
)
{
getGroupID
(
req
.
body
.
username
,
req
.
body
.
client_id
,
(
_id
)
=>
{
// get groupID
cache
.
set
(
cachekey
,
result
);
// console.log(_id)
res
.
send
({
var
_ftopic
=
require
(
'./utils/getTopic'
).
getTopic
(
topic
,
_id
)
// get topic where concat with groupID
"result"
:
result
?
"ok"
:
"no"
var
response
=
{
'result'
:
'ok'
,
'modifiers'
:
{
'topic'
:
_ftopic
,
'qos'
:
0
,
'retain'
:
false
}
}
console
.
log
(
response
)
if
(
typeof
(
authstatus
)
==
'undefined'
)
{
// cache missed
authCheck
(
req
.
body
.
client_id
,
req
.
body
.
username
,
topic
,
function
(
result
)
{
cache
.
set
(
cachekey
,
result
);
res
.
send
(
response
);
});
});
});
}
}
else
{
else
{
res
.
send
(
response
);
res
.
send
({
}
"result"
:
authstatus
?
"ok"
:
"no"
next
();
});
})
}
next
();
}
}
else
{
else
{
res
.
send
({
res
.
send
({
...
...
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