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
a74eabbd
Commit
a74eabbd
authored
Feb 20, 2019
by
Chavee Issariyapat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update api
parent
e8a395fd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
24 deletions
+63
-24
authhook/auth_on_subscribe.js
+6
-0
authhook/utils/getGroupID.js
+4
-1
authhook/utils/router.js
+53
-23
No files found.
authhook/auth_on_subscribe.js
View file @
a74eabbd
...
...
@@ -30,6 +30,12 @@ module.exports = function (options = {}) {
if
(
decoded
)
{
if
(
decoded
.
role
===
'realtimedb'
)
response
=
{
'result'
:
'ok'
}
else
response
=
{
result
:
{
error
:
'not allowed'
}
}
if
(
options
.
debug
)
{
console
.
log
(
'response:'
);
console
.
log
(
req
.
body
);
}
res
.
send
(
response
);
next
();
}
...
...
authhook/utils/getGroupID.js
View file @
a74eabbd
...
...
@@ -12,7 +12,10 @@ function getGroupID(token, client_id, callback) {
}
else
{
doDB
(
client_id
,
function
(
group
)
{
callback
(
group
);
if
(
group
)
callback
(
group
);
else
callback
(
client_id
);
// fake group to isolate device
});
}
}
...
...
authhook/utils/router.js
View file @
a74eabbd
...
...
@@ -7,37 +7,67 @@ function rewriteTopic(topic, op, groupid, clientid, output) {
return
modify
.
insertWordIntoTopic
(
topic
,
'!'
+
groupid
,
1
);
case
'@shadow'
:
if
(
chunk
[
1
]
==
'set'
||
chunk
[
1
]
==
'overset'
||
chunk
[
1
]
==
'get'
)
{
output
.
verb
=
chunk
[
1
];
return
modify
.
insertWordIntoTopic
(
topic
,
''
+
clientid
,
2
);
}
else
if
(
chunk
[
1
]
==
'write'
||
chunk
[
1
]
==
'overwrite'
||
chunk
[
1
]
==
'read'
)
{
output
.
verb
=
chunk
[
1
];
return
modify
.
insertWordIntoTopic
(
topic
,
groupid
,
2
);
if
(
chunk
[
1
]
==
'data'
)
{
if
(
chunk
[
2
]
==
'get'
||
chunk
[
2
]
==
'update'
||
chunk
[
2
].
startsWith
(
'get:'
)
||
chunk
[
2
].
startsWith
(
'update:'
))
{
return
modify
.
insertWordIntoTopic
(
topic
,
clientid
,
3
);
}
else
if
(
chunk
[
2
]
==
'updated'
)
{
return
modify
.
insertWordIntoTopic
(
topic
,
'!'
+
clientid
,
3
);
}
else
if
(
chunk
[
2
].
startsWith
(
'updated:'
))
{
return
modify
.
insertWordIntoTopic
(
topic
,
'!'
+
groupid
,
3
);
}
else
{
return
topic
;
}
}
else
if
(
chunk
[
1
]
==
'changed'
)
{
if
(
op
==
'pub'
)
{
if
(
chunk
.
length
>
2
)
return
modify
.
insertWordIntoTopic
(
topic
,
'!'
+
groupid
,
2
);
else
if
(
chunk
.
length
==
2
)
return
modify
.
insertWordIntoTopic
(
topic
,
'!'
+
clientid
,
2
);
else
return
""
;
else
if
(
chunk
[
1
]
==
'state'
)
{
if
(
chunk
[
2
]
==
'get'
||
chunk
[
2
]
==
'update'
||
chunk
[
2
].
startsWith
(
'get:'
)
||
chunk
[
2
].
startsWith
(
'update:'
))
{
return
modify
.
insertWordIntoTopic
(
topic
,
clientid
,
3
);
}
else
if
(
chunk
[
2
]
==
'updated'
||
chunk
[
2
]
==
'mismatched'
)
{
return
modify
.
insertWordIntoTopic
(
topic
,
'!'
+
clientid
,
3
);
}
else
if
(
chunk
[
2
].
startsWith
(
'updated:'
)
||
chunk
[
2
].
startsWith
(
'mismatched:'
))
{
return
modify
.
insertWordIntoTopic
(
topic
,
'!'
+
groupid
,
3
);
}
else
{
if
(
chunk
.
length
>
2
)
return
modify
.
insertWordIntoTopic
(
topic
,
'!'
+
groupid
,
2
);
else
if
(
chunk
.
length
==
2
)
return
modify
.
insertWordIntoTopic
(
topic
,
'!'
+
clientid
,
2
);
else
return
""
;
return
topic
;
}
}
else
return
""
;
break
;
// if (chunk[1] == 'set' || chunk[1] == 'overset' || chunk[1] == 'get') {
// output.verb = chunk[1];
// return modify.insertWordIntoTopic(topic, ''+clientid, 2);
// }
// else if (chunk[1] == 'write' || chunk[1] == 'overwrite' || chunk[1] == 'read') {
// output.verb = chunk[1];
// return modify.insertWordIntoTopic(topic, groupid, 2);
// }
// else if (chunk[1] == 'changed') {
// if (op == 'pub') {
// if ( chunk.length > 2 )
// return modify.insertWordIntoTopic(topic, '!'+groupid, 2);
// else if ( chunk.length == 2 )
// return modify.insertWordIntoTopic(topic, '!'+clientid, 2);
// else return "";
// }
// else {
// if ( chunk.length > 2 )
// return modify.insertWordIntoTopic(topic, '!'+groupid, 2);
// else if ( chunk.length == 2 )
// return modify.insertWordIntoTopic(topic, '!'+clientid, 2);
// else return "";
// }
// }
// else return "";
case
'@private'
:
console
.
log
(
modify
.
insertWordIntoTopic
(
topic
,
'!'
+
clientid
,
1
));
return
modify
.
insertWordIntoTopic
(
topic
,
'!'
+
clientid
,
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