Files
P42_wssGateway/actions/utilities.js
T

156 lines
3.9 KiB
JavaScript

export const 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.allRediscnx.map(cnx => cnx.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.allRediscnx.map(cnx => cnx.getProcessInfo)
};
if(reqid) reply.reqid = reqid;
this.send(JSON.stringify(reply));
},
}