diff --git a/lib/commands/admin-rpc.js b/lib/commands/admin-rpc.js index bbcbc0c30..bfd273f38 100644 --- a/lib/commands/admin-rpc.js +++ b/lib/commands/admin-rpc.js @@ -176,6 +176,7 @@ var restoreArchivedDocument = function (Env, Server, cb) { }; // CryptPad_AsyncStore.rpc.send('ADMIN', ['SET_DEFAULT_STORAGE_LIMIT', 1024 * 1024 * 1024 /* 1GB */], console.log) +// XXX remove var setDefaultStorageLimit = function (Env, Server, cb, data) { var value = Array.isArray(data) && data[1]; if (typeof(value) !== 'number' || value <= 0) { return void cb('EINVAL'); } diff --git a/lib/commands/quota.js b/lib/commands/quota.js index 90babbc85..e39bcbcc8 100644 --- a/lib/commands/quota.js +++ b/lib/commands/quota.js @@ -7,14 +7,23 @@ const Keys = require("../keys"); const Package = require('../../package.json'); const Https = require("https"); +Quota.isValidLimit = function (o) { + var valid = o && typeof(o) === 'object' && + typeof(o.limit) === 'number' && + typeof(o.plan) === 'string' && + typeof(o.note) === 'string' && + // optionally contains a 'users' array + (Array.isArray(o.users) || typeof(o.users) === 'undefined'); + + return valid; +}; + Quota.applyCustomLimits = function (Env) { - var isLimit = function (o) { - var valid = o && typeof(o) === 'object' && - typeof(o.limit) === 'number' && - typeof(o.plan) === 'string' && - typeof(o.note) === 'string'; - return valid; - }; + // DecreedLimits > customLimits > serverLimits; + + // XXX perform an integrity check on shared limits + // especially relevant because we use Env.limits + // when considering whether to archive inactive accounts // read custom limits from the Environment (taken from config) var customLimits = (function (custom) { @@ -38,12 +47,12 @@ Quota.applyCustomLimits = function (Env) { Env.limits = Env.limits || {}; Object.keys(customLimits).forEach(function (k) { - if (!isLimit(customLimits[k])) { return; } + if (!Quota.isValidLimit(customLimits[k])) { return; } Env.limits[k] = customLimits[k]; }); + // console.log(Env.limits); }; - /* Env = { myDomain, @@ -93,6 +102,9 @@ Quota.updateCachedLimits = function (Env, cb) { response.on('end', function () { try { var json = JSON.parse(str); + // don't overwrite the limits with junk data + if (json && json.message === 'EINVAL') { return void cb(); } + Env.limits = json; Quota.applyCustomLimits(Env); //console.log('Env.customLimits', Env.customLimits); diff --git a/lib/decrees.js b/lib/decrees.js index cecb9d837..5f1bdaa47 100644 --- a/lib/decrees.js +++ b/lib/decrees.js @@ -4,18 +4,30 @@ var Decrees = module.exports; IMPLEMENTED: -RESTRICT_REGISTRATION -UPDATE_DEFAULT_STORAGE +RESTRICT_REGISTRATION() +UPDATE_DEFAULT_STORAGE() NOT IMPLEMENTED: +// QUOTA MANAGEMENT ADD_QUOTA -RM_QUOTA +RM_QUOTA() UPDATE_QUOTA + +// RESTRICTED REGISTRATION ADD_INVITE REVOKE_INVITE REDEEM_INVITE +// 2.0 +UPDATE_INACTIVE_TIME +UPDATE_ACCOUNT_RETENTION_TIME +UPDATE_ARCHIVE_RETENTION_TIME + +// 3.0 +UPDATE_MAX_UPLOAD_SIZE +UPDATE_PREMIUM_UPLOAD_SIZE + */ var commands = {}; @@ -44,9 +56,13 @@ commands.RESTRICT_REGISTRATION = function (Env, args) { return true; }; +var isNonNegativeNumber = function (n) { + return !(typeof(n) !== 'number' || isNaN(n) || n < 0); +}; + // CryptPad_AsyncStore.rpc.send('ADMIN', [ 'ADMIN_DECREE', ['UPDATE_DEFAULT_STORAGE', [100 * 1024 * 1024]]], console.log) commands.UPDATE_DEFAULT_STORAGE = function (Env, args) { - if (!Array.isArray(args) || typeof(args[0]) !== 'number' || isNaN(args[0]) || args[0] < 0) { + if (!Array.isArray(args) || isNonNegativeNumber(args[0])) { throw new Error('INVALID_ARGS'); } var limit = args[0]; @@ -55,6 +71,23 @@ commands.UPDATE_DEFAULT_STORAGE = function (Env, args) { return true; }; +//var Quota = require("./commands/quota"); + +commands.ADD_QUOTA = function (Env, args) { + args = args; + throw new Error("NOT_IMPLEMENTED"); +}; + +commands.RM_QUOTA = function (Env, args) { + args = args; + throw new Error("NOT_IMPLEMENTED"); +}; + +commands.UPDATE_QUOTA = function (Env, args) { + args = args; + throw new Error("NOT_IMPLEMENTED"); +}; + // [, , ,