Commit 16b4635d by zCaesar

add check id length

parent 3147fd4d
...@@ -97,7 +97,6 @@ module.exports = function (options = {}) { ...@@ -97,7 +97,6 @@ module.exports = function (options = {}) {
console.log('auth_on_register-------------'); console.log('auth_on_register-------------');
console.log(req.body); console.log(req.body);
} }
var client_id = req.body.client_id
var cachekey = 'auth:' + req.body.client_id + ':' + req.body.username + ':' + req.body.password; var cachekey = 'auth:' + req.body.client_id + ':' + req.body.username + ':' + req.body.password;
var authstatus = cache.get(cachekey); var authstatus = cache.get(cachekey);
if (typeof (authstatus) == 'undefined') { if (typeof (authstatus) == 'undefined') {
......
...@@ -3,12 +3,17 @@ var redis = new Redis() ...@@ -3,12 +3,17 @@ 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) => {
if (deviceid.indexOf('mqtt') === 0 && deviceid.length !== 36) {
resolve(true)
}
else {
var information = setValue(deviceid) var information = setValue(deviceid)
redis.hincrby(setBrokerValue().keys, 'device_usage_count', -1, function (err, res) { 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
}) })
}) })
}
}) })
} }
module.exports.on_offline_redis = on_offline_redis module.exports.on_offline_redis = on_offline_redis
......
...@@ -3,7 +3,7 @@ var redis = new Redis() ...@@ -3,7 +3,7 @@ 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) => {
if (deviceid.indexOf('mqtt') === 0) { if (deviceid.indexOf('mqtt') === 0 && deviceid.length !== 36) {
resolve(true) resolve(true)
} }
else { else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment