2nd
This commit is contained in:
@@ -0,0 +1,203 @@
|
||||
module.exports.methods = {
|
||||
|
||||
/* Request:
|
||||
{
|
||||
"action": "PING"
|
||||
}
|
||||
Reply:
|
||||
{
|
||||
"action": "PONG",
|
||||
}
|
||||
*/
|
||||
action_PONG(action, payload){
|
||||
clearTimeout(this.keepAliveBomb);
|
||||
this.keepAliveNextTimeout = setTimeout(this.keepAlive.bind(this),this.config.server.keepAliveInterval*1000);
|
||||
},
|
||||
|
||||
|
||||
/* Request:
|
||||
{
|
||||
"action": "TIME"
|
||||
"reqid": "6az5e4r6a"
|
||||
}
|
||||
Reply:
|
||||
{
|
||||
"action": "TIME",
|
||||
"success": true,
|
||||
"payload" : {
|
||||
wssGatewayTime: "2022-09-01T14:42:22.603Z",
|
||||
redisTime: "2022-09-01T14:42:22.603Z"
|
||||
},
|
||||
"reqid": "6az5e4r6a"
|
||||
}
|
||||
*/
|
||||
action_TIME(action, payload, reqid){
|
||||
var tmstp =new Date().toISOString();
|
||||
var reply = {
|
||||
'action': action,
|
||||
'payload': {
|
||||
wssGatewayTime: tmstp,
|
||||
redisTime: this.rediscnx.redisClient.time()
|
||||
},
|
||||
'success': true,
|
||||
};
|
||||
if(reqid) reply.reqid = reqid;
|
||||
this.send(JSON.stringify(reply));
|
||||
},
|
||||
|
||||
|
||||
/* Request:
|
||||
{
|
||||
"action": "RELOADACCESSRIGHTS"
|
||||
}
|
||||
Reply:
|
||||
{
|
||||
"success": true,
|
||||
"reqid": "6az5e4r6a"
|
||||
}
|
||||
*/
|
||||
action_RELOADACCESSRIGHTS(action, payload, reqid){
|
||||
if(!this.accessRights.canDo(this.roles, 'reloadAccessRights')) {
|
||||
this.sendErr(action, 'Unauthorized action !', reqid);
|
||||
return
|
||||
}
|
||||
this.wssSrv.reloadAccessRights()
|
||||
var reply = {
|
||||
'action': action,
|
||||
'success': true,
|
||||
};
|
||||
if(reqid) reply.reqid = reqid;
|
||||
this.send(JSON.stringify(reply));
|
||||
},
|
||||
|
||||
/* Request:
|
||||
{
|
||||
"action": "GETACCESSRIGHTS"
|
||||
}
|
||||
Reply:
|
||||
{
|
||||
"success": true,
|
||||
"reqid": "6az5e4r6a",
|
||||
"payload": { the accessrights }
|
||||
}
|
||||
|
||||
Kept for backward compatibility : GETCONFIG gets everything !
|
||||
*/
|
||||
action_GETACCESSRIGHTS(action, payload, reqid){
|
||||
if(!this.accessRights.canDo(this.roles, 'reloadAccessRights')) {
|
||||
this.sendErr(action, 'Unauthorized action !', reqid);
|
||||
return
|
||||
}
|
||||
|
||||
var reply = {
|
||||
'action': action,
|
||||
'success': true,
|
||||
'payload': this.wssSrv.wssGatewayConfig.accessRights
|
||||
};
|
||||
if(reqid) reply.reqid = reqid;
|
||||
this.send(JSON.stringify(reply));
|
||||
},
|
||||
|
||||
/* Request:
|
||||
{
|
||||
"action": "GETCONFIG"
|
||||
}
|
||||
Reply:
|
||||
{
|
||||
"success": true,
|
||||
"reqid": "6az5e4r6a",
|
||||
"payload": { the config }
|
||||
}
|
||||
*/
|
||||
action_GETCONFIG(action, payload, reqid){
|
||||
if(!this.accessRights.canDo(this.roles, 'reloadAccessRights')) {
|
||||
this.sendErr(action, 'Unauthorized action !', reqid);
|
||||
return
|
||||
}
|
||||
|
||||
var reply = {
|
||||
'action': action,
|
||||
'success': true,
|
||||
'payload': this.wssSrv.wssGatewayConfig
|
||||
};
|
||||
if(reqid) reply.reqid = reqid;
|
||||
this.send(JSON.stringify(reply));
|
||||
},
|
||||
|
||||
|
||||
/* Request:
|
||||
{
|
||||
"action": "GETPROCESSINFO"
|
||||
}
|
||||
Reply:
|
||||
{
|
||||
"success": true,
|
||||
"reqid": "6az5e4r6a",
|
||||
"payload": { the result of redis INFO command }
|
||||
}
|
||||
*/
|
||||
action_GETPROCESSINFO(action, payload, reqid){
|
||||
if(!this.accessRights.canDo(this.roles, 'getProcessInfo')) {
|
||||
this.sendErr(action, 'Unauthorized action !', reqid);
|
||||
return
|
||||
}
|
||||
|
||||
var reply = {
|
||||
'action': action,
|
||||
'success': true,
|
||||
'payload': this.rediscnx.getProcessInfo
|
||||
};
|
||||
if(reqid) reply.reqid = reqid;
|
||||
this.send(JSON.stringify(reply));
|
||||
},
|
||||
|
||||
action_REDPILL(action, payload, reqid){
|
||||
if(!this.accessRights.canDo(this.roles, 'REDPILL', this.userId)) {
|
||||
this.sendErr(action, 'Unauthorized action', reqid);
|
||||
return;
|
||||
};
|
||||
|
||||
if(!this.rediscnx.redPillsUuids.includes(this.uuid)) {
|
||||
this.rediscnx.redPillsUuids.push(this.uuid)
|
||||
setTimeout(() => {
|
||||
if(this.rediscnx.redPillsUuids.includes(this.uuid)){ // could have been removed meanwhile & splice(-1) would remove the last !!!
|
||||
this.rediscnx.redPillsUuids.splice(this.rediscnx.redPillsUuids.indexOf(this.uuid),1)
|
||||
}
|
||||
let reply = {
|
||||
'action': 'BLUEPILL',
|
||||
'payload': {},
|
||||
'success': true,
|
||||
};
|
||||
this.send(JSON.stringify(reply));
|
||||
}, 600000) // Back to blupill after 10min
|
||||
}
|
||||
|
||||
let reply = {
|
||||
'action': action,
|
||||
'payload': {},
|
||||
'success': true,
|
||||
};
|
||||
if(reqid) reply.reqid = reqid;
|
||||
this.send(JSON.stringify(reply));
|
||||
},
|
||||
|
||||
action_BLUEPILL(action, payload, reqid){
|
||||
if(!this.accessRights.canDo(this.roles, 'BLUEPILL', this.userId)) {
|
||||
this.sendErr(action, 'Unauthorized action', reqid);
|
||||
return;
|
||||
};
|
||||
|
||||
if(this.rediscnx.redPillsUuids.includes(this.uuid)) {
|
||||
this.rediscnx.redPillsUuids.splice(this.rediscnx.redPillsUuids.indexOf(this.uuid),1)
|
||||
}
|
||||
|
||||
let reply = {
|
||||
'action': action,
|
||||
'payload': {},
|
||||
'success': true,
|
||||
};
|
||||
if(reqid) reply.reqid = reqid;
|
||||
this.send(JSON.stringify(reply));
|
||||
},
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user