177 lines
5.2 KiB
JavaScript
177 lines
5.2 KiB
JavaScript
class PlatformModel extends EICBusModel {
|
|
|
|
getUsers() {
|
|
return(
|
|
this.busWssGwRequest('GETACTIVEUSERS')
|
|
.then(
|
|
list => {
|
|
if(!list) list = []
|
|
list.sort((a,b) => {
|
|
if(a.family_name<b.family_name) return(-1)
|
|
else if(a.family_name>b.family_name) return(1)
|
|
else if(a.given_name<b.given_name) return(-1)
|
|
else return(1)
|
|
})
|
|
return(list)
|
|
},
|
|
() => [] // Empty list on connection timeout
|
|
)
|
|
)
|
|
}
|
|
|
|
getPlatformStatus() {
|
|
return(
|
|
this.busWssGwRequest('GETPLATFORMMODE', {}).then(data=>{
|
|
if(!data) return(null)
|
|
if(data.platformRestrictions) data.platformRestrictions.allowedUUIDs = data.platformRestrictions.allowedUUIDs || []
|
|
data.blockedUUIDs = data.blockedUUIDs || []
|
|
return(data)
|
|
})
|
|
)
|
|
}
|
|
|
|
setPlatformStatus(status){
|
|
app.MessageBus.requestWssGwAction('SETPLATFORMMODE', status)
|
|
}
|
|
|
|
async getDaemonsStatus(){
|
|
let daemons = {
|
|
wssGateway:false,
|
|
httpGateway:false,
|
|
midas:false
|
|
}
|
|
for(let daemon of Object.keys(daemons)){
|
|
let result = null
|
|
if(daemon == 'wssGateway'){ //for him, ask direct in wss
|
|
result = await app.MessageBus.requestWssGwAction('TIME',{}, 200)
|
|
} else { //all the others we talk via bus
|
|
try{
|
|
result = await this.busActionRequest(`infraNotifs:${daemon}`, 'TIME', {}, 200)
|
|
} catch(err) {
|
|
console.warn(`Daemon ${daemon} timed out on TIME request ! `)
|
|
}
|
|
|
|
}
|
|
daemons[daemon] = (result !== null) ? result[`${daemon}Time`] : false
|
|
}
|
|
return(daemons)
|
|
}
|
|
|
|
async ban(uid) {
|
|
let status = await this.getPlatformStatus()
|
|
if(!status.blockedUUIDs.includes(uid)) status.blockedUUIDs.push(uid)
|
|
this.setPlatformStatus(status)
|
|
this.kick(uid)
|
|
}
|
|
|
|
async unban(uid) {
|
|
let status = await this.getPlatformStatus()
|
|
let idx = status.blockedUUIDs.indexOf(uid)
|
|
if(idx>-1) status.blockedUUIDs.splice(idx,1)
|
|
this.setPlatformStatus(status)
|
|
}
|
|
|
|
async stopPlatform(data){
|
|
let status = await this.getPlatformStatus()
|
|
if(status.XX_platformRestrictions) delete(status.XX_platformRestrictions)
|
|
status.platformRestrictions = {
|
|
"allowedRoles": data.allowedRoles,
|
|
"allowedUUIDs": data.allowedUUIDs,
|
|
}
|
|
this.setPlatformStatus(status)
|
|
}
|
|
|
|
async startPlatform(data){
|
|
let status = await this.getPlatformStatus()
|
|
this.setPlatformStatus({
|
|
"blockedUUIDs":status.blockedUUIDs
|
|
})
|
|
}
|
|
|
|
|
|
growlOne(uid, growlData) {
|
|
let userNotifChan = app.config.messageBus.userNotifChan.replace(/\{uid\}/g, uid)
|
|
growlData.growlMessage = growlData.growlMessage.replace(/\n/g,'<br>')
|
|
this.busEvent(userNotifChan, 'growl', growlData)
|
|
}
|
|
|
|
growlGlobal(growlData) {
|
|
growlData.growlMessage = growlData.growlMessage.replace(/\n/g,'<br>')
|
|
this.busEvent('system:notifs', 'growl', growlData)
|
|
}
|
|
|
|
kick(uid) {
|
|
let userNotifChan = app.config.messageBus.userNotifChan.replace(/\{uid\}/g, uid)
|
|
this.busEvent(userNotifChan, 'kick')
|
|
return(
|
|
this.busWssGwRequest('KILLSESSION', {
|
|
uids: [ uid ],
|
|
notRoles : ['EIC_admin', 'EIC_Dev' ],
|
|
ttl: 0
|
|
})
|
|
)
|
|
}
|
|
|
|
kickAll() {
|
|
this.busEvent('system:notifs', 'kick')
|
|
return(
|
|
this.busWssGwRequest('KILLSESSION', {
|
|
uids: null,
|
|
notRoles : ['EIC_admin', 'EIC_Dev' ],
|
|
ttl: 0
|
|
})
|
|
)
|
|
}
|
|
|
|
refreshWssGwRights(){
|
|
return(
|
|
this.busWssGwRequest('RELOADACCESSRIGHTS', {})
|
|
)
|
|
}
|
|
|
|
viewWssGwRights(){
|
|
return(
|
|
this.busWssGwRequest('GETACCESSRIGHTS', {})
|
|
)
|
|
}
|
|
|
|
refreshHttpGwRights(){
|
|
return(
|
|
this.busActionRequest('infraNotifs:httpGateway', 'RELOADACCESSRIGHTS', {})
|
|
)
|
|
}
|
|
|
|
viewHttpGwRights(){
|
|
return(
|
|
this.busActionRequest('infraNotifs:httpGateway', 'GETACCESSRIGHTS', {})
|
|
)
|
|
}
|
|
|
|
refreshMidasConfig(){
|
|
return(
|
|
this.busActionRequest('infraNotifs:midas', 'RELOADCONFIG', {})
|
|
)
|
|
}
|
|
|
|
viewMidasConfig(){
|
|
return(
|
|
this.busActionRequest('infraNotifs:midas', 'GETCONFIG', {})
|
|
)
|
|
}
|
|
|
|
refreshMidasPlugins(){
|
|
return(
|
|
this.busActionRequest('infraNotifs:midas', 'RELOADPLUGINS', {})
|
|
)
|
|
}
|
|
|
|
viewMidasPlugins(){
|
|
return(
|
|
this.busActionRequest('infraNotifs:midas', 'LISTPLUGINS', {})
|
|
)
|
|
}
|
|
|
|
}
|
|
|
|
app.registerClass('PlatformModel', PlatformModel);
|