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
3147fd4d
Commit
3147fd4d
authored
Nov 19, 2018
by
zCaesar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed
parent
a328920c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
24 deletions
+27
-24
authhook/auth_on_register.js
+10
-14
authhook/on_offline.js
+1
-1
authhook/redis/on_offline.js
+4
-3
authhook/redis/on_register.js
+12
-6
No files found.
authhook/auth_on_register.js
View file @
3147fd4d
...
@@ -104,38 +104,34 @@ module.exports = function (options = {}) {
...
@@ -104,38 +104,34 @@ module.exports = function (options = {}) {
// cache missed
// cache missed
authCheck
(
req
.
body
.
client_id
,
req
.
body
.
username
,
req
.
body
.
password
,
function
(
result
)
{
authCheck
(
req
.
body
.
client_id
,
req
.
body
.
username
,
req
.
body
.
password
,
function
(
result
)
{
cache
.
set
(
cachekey
,
result
);
cache
.
set
(
cachekey
,
result
);
console
.
log
(
client_id
)
if
(
!
result
)
{
console
.
log
(
client_id
.
indexOf
(
'-'
))
if
(
client_id
.
indexOf
(
'mqttjs'
)
!==
-
1
)
{
res
.
send
({
"result"
:
result
?
"ok"
:
"no"
});
}
else
{
require
(
'./redis/on_register'
).
on_register_redis
(
req
.
body
.
client_id
).
then
(
status
=>
{
require
(
'./redis/on_register'
).
on_register_redis
(
req
.
body
.
client_id
).
then
(
status
=>
{
console
.
log
(
'redis:status: '
+
status
)
console
.
log
(
'redis:status: '
+
status
)
res
.
send
({
res
.
send
({
"result"
:
status
?
"ok"
:
"no"
"result"
:
status
?
"ok"
:
"no"
});
});
})
})
}
else
{
res
.
send
({
"result"
:
"no"
});
}
}
// const util = require('util')
// const util = require('util')
// console.log(util.inspect(status, false, null, true))
// console.log(util.inspect(status, false, null, true))
});
});
}
}
else
{
else
{
if
(
client_id
.
indexOf
(
'mqttjs'
)
!==
-
1
)
{
if
(
authstatus
)
{
res
.
send
({
"result"
:
authstatus
?
"ok"
:
"no"
});
}
else
{
require
(
'./redis/on_register'
).
on_register_redis
(
req
.
body
.
client_id
).
then
(
status
=>
{
require
(
'./redis/on_register'
).
on_register_redis
(
req
.
body
.
client_id
).
then
(
status
=>
{
console
.
log
(
'redis:status: '
+
status
)
console
.
log
(
'redis:status: '
+
status
)
res
.
send
({
res
.
send
({
"result"
:
status
?
"ok"
:
"no"
"result"
:
status
?
"ok"
:
"no"
});
});
})
})
}
else
{
res
.
send
({
"result"
:
"no"
});
}
}
}
}
next
();
next
();
...
...
authhook/on_offline.js
View file @
3147fd4d
...
@@ -7,7 +7,7 @@ module.exports = function(options = {}) {
...
@@ -7,7 +7,7 @@ module.exports = function(options = {}) {
}
}
function
doRedis
(
client_id
)
{
function
doRedis
(
client_id
)
{
if
(
client_id
.
indexOf
(
'mqttjs
_
'
)
===
-
1
)
{
if
(
client_id
.
indexOf
(
'mqttjs'
)
===
-
1
)
{
require
(
'./redis/on_offline'
).
on_offline_redis
(
client_id
).
then
(
status
=>
{
require
(
'./redis/on_offline'
).
on_offline_redis
(
client_id
).
then
(
status
=>
{
console
.
log
(
'redis:status: '
+
status
)
console
.
log
(
'redis:status: '
+
status
)
})
})
...
...
authhook/redis/on_offline.js
View file @
3147fd4d
...
@@ -4,9 +4,10 @@ var redis = new Redis()
...
@@ -4,9 +4,10 @@ var redis = new Redis()
function
on_offline_redis
(
deviceid
)
{
// first time to access on authhook auth_on_register
function
on_offline_redis
(
deviceid
)
{
// first time to access on authhook auth_on_register
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
var
information
=
setValue
(
deviceid
)
var
information
=
setValue
(
deviceid
)
redis
.
hincrby
(
setBrokerValue
().
keys
,
'device_usage_count'
,
-
1
)
redis
.
hincrby
(
setBrokerValue
().
keys
,
'device_usage_count'
,
-
1
,
function
(
err
,
res
)
{
redis
.
hset
(
information
.
keys
,
'status'
,
information
.
status
,
'offline_on'
,
information
.
offline_on
,
function
(
err
,
res
)
{
redis
.
hset
(
information
.
keys
,
'status'
,
information
.
status
,
'offline_on'
,
information
.
offline_on
,
function
(
err
,
res
)
{
resolve
(
!
res
)
// 0 is ok, 1 is no => if ok is 0 then not 0 = 1
resolve
(
!
res
)
// 0 is ok, 1 is no => if ok is 0 then not 0 = 1
})
})
})
})
})
}
}
...
...
authhook/redis/on_register.js
View file @
3147fd4d
...
@@ -3,12 +3,18 @@ var redis = new Redis()
...
@@ -3,12 +3,18 @@ var redis = new Redis()
function
on_register_redis
(
deviceid
)
{
// first time to access on authhook auth_on_register
function
on_register_redis
(
deviceid
)
{
// first time to access on authhook auth_on_register
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
var
information
=
setValue
(
deviceid
)
if
(
deviceid
.
indexOf
(
'mqtt'
)
===
0
)
{
redis
.
hdel
(
information
.
keys
,
'offline_on'
)
resolve
(
true
)
redis
.
hincrby
(
setBrokerValue
().
keys
,
'device_usage_count'
,
1
)
}
redis
.
hset
(
information
.
keys
,
'status'
,
information
.
status
,
'register_on'
,
information
.
register_on
,
'last_check'
,
information
.
last_check
,
function
(
err
,
res
)
{
else
{
resolve
(
!
res
)
// 0 is ok, 1 is no => if ok is 0 then not 0 = 1
var
information
=
setValue
(
deviceid
)
})
redis
.
hdel
(
information
.
keys
,
'offline_on'
)
redis
.
hincrby
(
setBrokerValue
().
keys
,
'device_usage_count'
,
1
,
function
(
err
,
res
)
{
redis
.
hset
(
information
.
keys
,
'status'
,
information
.
status
,
'register_on'
,
information
.
register_on
,
'last_check'
,
information
.
last_check
,
function
(
err
,
res
)
{
resolve
(
!
res
)
// 0 is ok, 1 is no => if ok is 0 then not 0 = 1
})
})
}
})
})
}
}
module
.
exports
.
on_register_redis
=
on_register_redis
module
.
exports
.
on_register_redis
=
on_register_redis
...
...
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