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
35b5edc5
Commit
35b5edc5
authored
Jun 30, 2018
by
Chavee Issariyapat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add on_publish
parent
cfeb4f4a
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
0 deletions
+43
-0
authhook/auth_on_publish.js
+1
-0
authhook/auth_on_register.js
+6
-0
authhook/auth_on_subscribe.js
+1
-0
authhook/index.js
+2
-0
authhook/on_publish.js
+33
-0
No files found.
authhook/auth_on_publish.js
View file @
35b5edc5
...
...
@@ -16,6 +16,7 @@ module.exports = function(options={}) {
if
(
req
.
header
(
'vernemq-hook'
)
==
'auth_on_publish'
&&
req
&&
req
.
body
)
{
if
(
options
.
debug
)
{
console
.
log
(
'auth_on_publish-------------'
);
console
.
log
(
req
.
body
);
}
...
...
authhook/auth_on_register.js
View file @
35b5edc5
...
...
@@ -26,6 +26,12 @@ module.exports = function(options={}) {
return
function
(
req
,
res
,
next
)
{
if
(
req
.
header
(
'vernemq-hook'
)
==
'auth_on_register'
&&
req
&&
req
.
body
)
{
if
(
options
.
debug
)
{
console
.
log
(
'auth_on_register-------------'
);
console
.
log
(
req
.
body
);
}
var
cachekey
=
'auth:'
+
req
.
body
.
client_id
+
':'
+
req
.
body
.
username
+
':'
+
req
.
body
.
password
;
var
authstatus
=
cache
.
get
(
cachekey
);
if
(
typeof
(
authstatus
)
==
'undefined'
)
{
...
...
authhook/auth_on_subscribe.js
View file @
35b5edc5
...
...
@@ -16,6 +16,7 @@ module.exports = function(options={}) {
if
(
req
.
header
(
'vernemq-hook'
)
==
'auth_on_subscribe'
&&
req
&&
req
.
body
)
{
if
(
options
.
debug
)
{
console
.
log
(
'auth_on_subscribe-------------'
);
console
.
log
(
req
.
body
);
}
...
...
authhook/index.js
View file @
35b5edc5
...
...
@@ -5,6 +5,7 @@ var restify = require('restify');
var
auth_on_register
=
require
(
'./auth_on_register'
)({
debug
:
true
});
var
auth_on_publish
=
require
(
'./auth_on_publish'
)({
debug
:
true
});
var
auth_on_subscribe
=
require
(
'./auth_on_subscribe'
)({
debug
:
true
});
var
on_publish
=
require
(
'./on_publish'
)({
debug
:
true
});
const
server
=
restify
.
createServer
({
name
:
'authplugin'
,
...
...
@@ -27,6 +28,7 @@ server.get('/about', function (req, res, next) {
server
.
post
(
'/authreg'
,
auth_on_register
);
server
.
post
(
'/authpub'
,
auth_on_publish
);
server
.
post
(
'/authsub'
,
auth_on_subscribe
);
server
.
post
(
'/onpub'
,
on_publish
);
server
.
listen
(
port
,
function
()
{
console
.
log
(
'%s listening at %s'
,
server
.
name
,
server
.
url
);
...
...
authhook/on_publish.js
0 → 100644
View file @
35b5edc5
var
config
=
require
(
'config'
);
// https://github.com/isaacs/node-lru-cache
var
LRU
=
require
(
"lru-cache"
)
,
cache
=
LRU
({
max
:
500
,
maxAge
:
1000
*
60
*
5
});
module
.
exports
=
function
(
options
=
{})
{
return
function
(
req
,
res
,
next
)
{
if
(
req
.
header
(
'vernemq-hook'
)
==
'on_publish'
&&
req
&&
req
.
body
)
{
if
(
options
.
debug
)
{
console
.
log
(
'on_publish-------------'
);
console
.
log
(
req
.
body
);
}
var
topic
=
req
.
body
.
topic
;
var
cachekey
=
'pub:'
+
req
.
body
.
client_id
+
':'
+
req
.
body
.
username
+
':'
+
topic
;
var
authstatus
=
cache
.
get
(
cachekey
);
res
.
status
(
200
);
res
.
send
(
''
);
next
();
}
else
{
res
.
status
(
200
);
res
.
send
(
''
);
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