From 825820f6bfe7eecfd8a02860ba19916c610fe16a Mon Sep 17 00:00:00 2001 From: Ludovic Dubost Date: Sun, 29 Nov 2020 20:55:20 +0100 Subject: [PATCH] Improved daily check with configuration parameters --- config/config.example.js | 57 +++++++++++++++++++++++++++++++++++++++- lib/commands/quota.js | 31 +++++++++++++++------- lib/env.js | 12 ++++++--- lib/stats.js | 9 ++++--- package.json | 1 + 5 files changed, 92 insertions(+), 18 deletions(-) diff --git a/config/config.example.js b/config/config.example.js index 32bcb20cf..6b7613d48 100644 --- a/config/config.example.js +++ b/config/config.example.js @@ -141,6 +141,8 @@ module.exports = { /* CryptPad will display a point of contact for your instance on its contact page * (/contact.html) if you provide it below. + * This email will also be sent to the CryptPad Team as part of the daily check unless you + * set the blockAdminEmail parameter. */ adminEmail: 'i.did.not.read.my.config@cryptpad.fr', @@ -148,11 +150,64 @@ module.exports = { * By default, CryptPad contacts one of our servers once a day. * This check-in will also send some very basic information about your instance including its * version and the adminEmail so we can reach you if we are aware of a serious problem. - * We will never sell it or send you marketing mail. + * * * If you want to block this check-in and remain set 'blockDailyCheck' to true. + * If you want to send the daily check but without the administrator email set 'blockAdminEmail' to true + * If you want to send the daily check but without instance statistical information set 'blockStats' to true + * + * These information allows the CryptPad Team to count how many instances are running including by country + * It also allows to estimate the number of users of CryptPad instances around the world. + * We will use the aggregated information in order to promote CryptPad and encourage more use of it. + * + * We will never sell it or send you marketing mail. + * + * In case you would like your data to be deleted, you can contact the CryptPad Team at privacy@cryptpad.fr */ //blockDailyCheck: false, + //blockAdminEmail: false, + //blockStats: false, + + /* + * By default the information sent with the daily check will NOT be published + * and is kept only by the CryptPad development team + * If you would like to publish this information and be listed in the directory + * at https://cryptpad.fr/servers/ please set the following value to "true" + * and update the information below that are being sent + */ + //serverPublish: false, + + /* + * + * By default the statistical information sent with the daily check will NOT be published + * and is kept only by the CryptPad development team + * If you would like to publish this information in the directory + * at https://cryptpad.fr/servers/ please set the following value to "true" + * and update the information below that are being sent + */ + //serverStatsPublish: false, + + /* + * In case you would like you instance to be published in the directory of CryptPad instances + * You should provide a name of your instance. + * + * For this update the information below + */ + //serverName: "noname", + + /* + * In case you would like you instance to be published in the directory of CryptPad instances + * You should provide a description of your instance. + * + * For this update the information below + */ + //serverDesc: "no description provided", + + /* + * Wether the Server is open for registration or private + * It should be one of: open, private, unknown + */ + //serverType: "unknown", /* * By default users get 50MB of storage by registering on an instance. diff --git a/lib/commands/quota.js b/lib/commands/quota.js index ce99106f7..3ba4a5164 100644 --- a/lib/commands/quota.js +++ b/lib/commands/quota.js @@ -66,20 +66,31 @@ var queryAccountServer = function (Env, cb) { console.log("DEBUG: query account server"); var done = Util.once(Util.mkAsync(cb)); - var body = JSON.stringify({ - domain: Env.myDomain, - subdomain: Env.mySubdomain, - adminEmail: Env.adminEmail, + var data = { + protocol: "2.0", + uuid: Env.Stats.stats.uuid, + url: Env.serverUrl, + adminEmail: "", version: Package.version, + name: Env.serverName, desc: Env.serverDesc, type: Env.serverType, publish: Env.serverPublish, - registeredUsers: Env.Stats.stats.registeredUsers, - maxOpenUniqueWebSockets: Env.Stats.stats.maxOpenUniqueWebSockets, - maxOpenWebSockets: Env.Stats.stats.maxOpenWebSockets, - openPadsSinceLastPing: Env.Stats.stats.openPadsSinceLastPing, - newPadsSinceLastPing: Env.Stats.stats.newPadsSinceLastPing - }); + publishStats: Env.serverStatsPublish + } + if (!Env.blockAdminEmail) { + data.adminEmail = Env.adminEmail; + } + + // We should not send statistics if the config says not to + if (!Env.blockStats) { + data.registeredUsers = Env.Stats.stats.registeredUsers; + data.maxOpenUniqueWebSockets = Env.Stats.stats.maxOpenUniqueWebSockets; + data.maxOpenWebSockets = Env.Stats.stats.maxOpenWebSockets; + data.openPadsSinceLastPing = Env.Stats.stats.openPadsSinceLastPing; + data.newPadsSinceLastPing = Env.Stats.stats.newPadsSinceLastPing; + } + var body = JSON.stringify(data); var options = { host: 'devaccounts.cryptpad.fr', port: 5001, diff --git a/lib/env.js b/lib/env.js index 005202806..0c1c981f7 100644 --- a/lib/env.js +++ b/lib/env.js @@ -39,9 +39,13 @@ module.exports.create = function (config) { // TODO implement mutability adminEmail: config.adminEmail, supportMailbox: config.supportMailboxPublicKey, - serverDesc: config.serverDesc, - serverType: config.serverType, - serverPublish: config.serverPublish, + + serverUrl: config.httpUnsafeOrigin, + serverName: config.serverName || "noname", + serverDesc: config.serverDesc || "no description provided", + serverType: config.serverType || "unknown", + serverPublish: config.serverPublish || false, + serverStatsPublish: config.serverPublish || false, metadata_cache: {}, channel_cache: {}, @@ -84,6 +88,8 @@ module.exports.create = function (config) { allowSubscriptions: config.allowSubscriptions === true, blockDailyCheck: config.blockDailyCheck === true, + blockAdminEmail: config.blockAdminEmail === true, + blockStats: config.blockDailyCheck === true, myDomain: config.myDomain, mySubdomain: config.mySubdomain, // only exists for the accounts integration diff --git a/lib/stats.js b/lib/stats.js index 40add1ccf..743c2bd4f 100644 --- a/lib/stats.js +++ b/lib/stats.js @@ -2,12 +2,12 @@ const Fs = require('fs'); const nThen = require("nthen"); const Admin = require("./commands/admin-rpc"); +const uuid = require("uuid"); module.exports.create = function (Env) { Env.Stats = { - stats : { registeredUsers : 0, maxOpenWebSockets : 0, maxOpenUniqueWebSockets: 0, - openPadsSinceLastPing : 0, newPadsSinceLastPing : 0 }, + stats : {}, getStats: function() { return stats; @@ -89,7 +89,8 @@ module.exports.create = function (Env) { } catch (e) { this.stats = { registeredUsers : 0, maxOpenWebSockets : 0, maxOpenUniqueWebSockets: 0, openPadsSinceLastPing : 0, newPadsSinceLastPing : 0 } - this.saveStats(); + this.stats.uuid = uuid.v4(); + this.saveStats(Env); } this.getRegisteredUsers(Env, function(nbRegs) { @@ -100,7 +101,7 @@ module.exports.create = function (Env) { }, updateStats: function(Env) { - if (Env.Server) { + if (Env && Env.Server) { var sessionStats = Env.Server.getSessionStats(); console.log("DEBUG: Current connections: ", sessionStats.total); console.log("DEBUG: Current unique connections: ", sessionStats.unique); diff --git a/package.json b/package.json index 37fd6c686..f8d34b6b4 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "stream-to-pull-stream": "^1.7.2", "tweetnacl": "~0.12.2", "ulimit": "0.0.2", + "uuid": "^8.3.1", "ws": "^3.3.1" }, "devDependencies": {