From 928b7e3583ed6ab0027054b64f2dc5fb2317ae6b Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 7 Oct 2020 15:08:33 +0530 Subject: [PATCH] implement GET_LIMITS admin rpc ...and label stored usage limits according to their source --- lib/commands/admin-rpc.js | 6 ++++++ lib/commands/quota.js | 9 ++++++++- lib/decrees.js | 1 + lib/historyKeeper.js | 9 +++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/commands/admin-rpc.js b/lib/commands/admin-rpc.js index 415bf5ef5..bd9978b0b 100644 --- a/lib/commands/admin-rpc.js +++ b/lib/commands/admin-rpc.js @@ -225,6 +225,11 @@ var instanceStatus = function (Env, Server, cb) { }); }; +// CryptPad_AsyncStore.rpc.send('ADMIN', ['LIST_LIMITS'], console.log) +var getLimits = function (Env, Server, cb) { + cb(void 0, Env.limits); +}; + var commands = { ACTIVE_SESSIONS: getActiveSessions, ACTIVE_PADS: getActiveChannelCount, @@ -241,6 +246,7 @@ var commands = { ADMIN_DECREE: adminDecree, INSTANCE_STATUS: instanceStatus, + GET_LIMITS: getLimits, }; Admin.command = function (Env, safeKey, data, _cb, Server) { diff --git a/lib/commands/quota.js b/lib/commands/quota.js index c5aaef8b3..d35aa463d 100644 --- a/lib/commands/quota.js +++ b/lib/commands/quota.js @@ -8,7 +8,7 @@ const Package = require('../../package.json'); const Https = require("https"); const Util = require("../common-util"); -var validLimitFields = ['limit', 'plan', 'note', 'users']; +var validLimitFields = ['limit', 'plan', 'note', 'users', 'origin']; Quota.isValidLimit = function (o) { var valid = o && typeof(o) === 'object' && @@ -137,7 +137,14 @@ Quota.updateCachedLimits = function (Env, cb) { if (err) { return void cb(err); } if (!json) { return void cb(); } + for (var k in json) { + if (k.length === 44 && json[k]) { + json[k].origin = 'remote'; + } + } + Env.limits = json; + Quota.applyCustomLimits(Env); cb(); }); diff --git a/lib/decrees.js b/lib/decrees.js index a71a1521c..9de7d5573 100644 --- a/lib/decrees.js +++ b/lib/decrees.js @@ -106,6 +106,7 @@ commands.SET_QUOTA = function (Env, args) { throw new Error("INVALID_ARGS"); } + limit.origin = 'decree'; // map the new limit to the user's unsafeKey Env.customLimits[unsafeKey] = limit; Env.limits[unsafeKey] = limit; diff --git a/lib/historyKeeper.js b/lib/historyKeeper.js index c240f968d..3da325191 100644 --- a/lib/historyKeeper.js +++ b/lib/historyKeeper.js @@ -79,6 +79,15 @@ module.exports.create = function (config, cb) { domain: config.domain }; + (function () { + var custom = Env.customLimits; + for (var k in custom) { + if (k.length === 44 && custom[k]) { + custom.origin = 'config'; + } + } + }()); + (function () { var pes = config.premiumUploadSize; if (!isNaN(pes) && pes >= Env.maxUploadSize) {