2020-06-01 20:36:40 +02:00
|
|
|
/*
|
|
|
|
* A tool for deleting ALL GROUP sessions Etherpad user sessions from the CLI,
|
|
|
|
* because sometimes a brick is required to fix a face.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const request = require('../src/node_modules/request');
|
2020-11-23 19:21:51 +01:00
|
|
|
const settings = require(`${__dirname}/../tests/container/loadSettings`).loadSettings();
|
|
|
|
const supertest = require(`${__dirname}/../src/node_modules/supertest`);
|
|
|
|
const api = supertest(`http://${settings.ip}:${settings.port}`);
|
2020-06-01 20:36:40 +02:00
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
// get the API Key
|
2020-11-23 19:21:51 +01:00
|
|
|
const filePath = path.join(__dirname, '../APIKEY.txt');
|
|
|
|
const apikey = fs.readFileSync(filePath, {encoding: 'utf-8'});
|
2020-06-01 20:36:40 +02:00
|
|
|
|
|
|
|
// Set apiVersion to base value, we change this later.
|
2020-11-23 19:21:51 +01:00
|
|
|
let apiVersion = 1;
|
|
|
|
let guids;
|
2020-06-01 20:36:40 +02:00
|
|
|
|
|
|
|
// Update the apiVersion
|
|
|
|
api.get('/api/')
|
2020-11-23 19:21:51 +01:00
|
|
|
.expect((res) => {
|
|
|
|
apiVersion = res.body.currentVersion;
|
|
|
|
if (!res.body.currentVersion) throw new Error('No version set in API');
|
|
|
|
return;
|
2020-06-01 20:36:40 +02:00
|
|
|
})
|
2020-11-23 19:21:51 +01:00
|
|
|
.then(() => {
|
|
|
|
const guri = `/api/${apiVersion}/listAllGroups?apikey=${apikey}`;
|
|
|
|
api.get(guri)
|
|
|
|
.then((res) => {
|
|
|
|
guids = res.body.data.groupIDs;
|
|
|
|
guids.forEach((groupID) => {
|
|
|
|
const luri = `/api/${apiVersion}/listSessionsOfGroup?apikey=${apikey}&groupID=${groupID}`;
|
|
|
|
api.get(luri)
|
|
|
|
.then((res) => {
|
|
|
|
if (res.body.data) {
|
|
|
|
Object.keys(res.body.data).forEach((sessionID) => {
|
|
|
|
if (sessionID) {
|
|
|
|
console.log('Deleting', sessionID);
|
|
|
|
const duri = `/api/${apiVersion}/deleteSession?apikey=${apikey}&sessionID=${sessionID}`;
|
|
|
|
api.post(duri); // deletes
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// no session in this group.
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|