From 66520b60413a515454439da15715027478497885 Mon Sep 17 00:00:00 2001 From: Caleb James DeLisle Date: Fri, 26 May 2017 18:09:31 +0200 Subject: [PATCH] cleaned up the accounts, limits and revenue sharing and unified the config in one place --- config.example.js | 49 ++++++++++++++++++++----- customize.dist/application_config.js | 2 - customize.dist/translations/messages.js | 1 + rpc.js | 9 ++++- server.js | 1 + www/common/cryptpad-common.js | 11 ++++-- www/common/toolbar.js | 6 ++- www/common/toolbar2.js | 6 ++- www/drive/main.js | 12 +++--- 9 files changed, 70 insertions(+), 27 deletions(-) diff --git a/config.example.js b/config.example.js index fe3f2fb91..a0f3003e0 100644 --- a/config.example.js +++ b/config.example.js @@ -116,11 +116,46 @@ module.exports = { 'contact', ], - /* Domain - * If you want to have enable payments on your CryptPad instance, it has to be able to tell - * our account server what is your domain + /* Limits, Subscriptions and Contact + * + * CryptPad limits every registered user to 50MB of storage. + * By default it also allows that limit to be increased by subscribing at accounts.cryptpad.fr + * You can either: + * A: Hide the button for subscribing, so everyone is limited to 50MB + * B: Support cryptpad and share 50% of the revenue earned on your instance + * + * CryptPad is developed by people who need to live and who deserve an equivilent life to + * what they would get at a company which monitizes user data. However, we intend to have + * a mutually positive relationship with every one of our users, including you. If you are + * getting value from CryptPad, you should be giving equal value back. + * + * If you are using CryptPad in a business context, please consider taking a support contract + * by contacting sales@cryptpad.fr + * + * If you choose A, set this variable to true to hide the subscription button. + */ + noSubscriptionButton: false, + /* + * If you choose B, set the domain of your cryptpad instance here and then contact + * sales@cryptpad.fr and tell us your domain, we will tell you what is needed to get paid. + */ + myDomain: 'i.did.not.read.my.config.cryptpad.myserver.tld', + /* + * If you are using CryptPad internally and you want to increase the per-user storage limit, + * change the following value. + * Please note: Providing a public offer that is better than cryptpad.fr is an attack on + * the project. Please leave this alone if you are providing a public service. + */ + defaultStorageLimit: 50 * 1024 * 1024, + /* + * By default, CryptPad contacts our accounts server once a day to check for changes in the + * people who have accounts. This check-in will also send your email and the version of + * CryptPad you run so we can reach you if we are aware of a serious problem with your + * CryptPad instance. We will never sell it or use it for marketing. If you want to block this + * check-in and remain completely private, set this to false and noSubscriptionButton to true. */ - // domain: 'https://cryptpad.fr', + adminEmail: 'i.did.not.read.my.config@cryptpad.fr', + /* You have the option of specifying an alternative storage adaptor. @@ -211,12 +246,6 @@ module.exports = { */ //restrictUploads: false, - /* Default user storage limit (bytes) - * if you don't want to limit users, - * you can set this to the size of your hard disk - */ - defaultStorageLimit: 50 * 1024 * 1024, - /* Max Upload Size (bytes) * this sets the maximum size of any one file uploaded to the server. * anything larger than this size will be rejected diff --git a/customize.dist/application_config.js b/customize.dist/application_config.js index 24ed2c740..151a8b7da 100644 --- a/customize.dist/application_config.js +++ b/customize.dist/application_config.js @@ -37,8 +37,6 @@ define(function() { config.enableHistory = true; - config.enablePinLimit = true; - /* user passwords are hashed with scrypt, and salted with their username. this value will be appended to the username, causing the resulting hash to differ from other CryptPad instances if customized. This makes it diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js index 751cf3633..d39407194 100644 --- a/customize.dist/translations/messages.js +++ b/customize.dist/translations/messages.js @@ -78,6 +78,7 @@ define(function () { out.updated_0_pinLimitReachedAlert = "You've reached your storage limit. New pads won't be stored in your CryptDrive.
" + 'You can either remove pads from your CryptDrive or subscribe to a premium offer to increase your limit.'; out.pinLimitReachedAlert = out.updated_0_pinLimitReachedAlert; + out.pinLimitReachedAlertNoAccounts = out.pinLimitReached; out.pinAboveLimitAlert = 'As of this release, we are imposing a 50MB limit on free data storage and you are currently using {0}. You will need to either delete some pads or subscribe on accounts.cryptpad.fr. Your contribution will help us improve CryptPad and spread Zero Knowledge. Please contact support if you have any other questions.'; out.pinLimitNotPinned = "You've reached your storage limit.
"+ "This pad is not stored in your CryptDrive."; diff --git a/rpc.js b/rpc.js index 0257c498f..45be04cc7 100644 --- a/rpc.js +++ b/rpc.js @@ -1,4 +1,5 @@ /*@flow*/ +/*jshint esversion: 6 */ /* Use Nacl for checking signatures of messages */ var Nacl = require("tweetnacl"); @@ -8,6 +9,7 @@ var Nacl = require("tweetnacl"); var Fs = require("fs"); var Path = require("path"); var Https = require("https"); +const Package = require('./package.json'); var RPC = module.exports; @@ -371,6 +373,7 @@ var getHash = function (Env, publicKey, cb) { // To each key is associated an object containing the 'limit' value and a 'note' explaining that limit var limits = {}; var updateLimits = function (config, publicKey, cb) { + if (config.adminEmail === false && config.noSubscriptionButton === true) { return; } if (typeof cb !== "function") { cb = function () {}; } var defaultLimit = typeof(config.defaultStorageLimit) === 'number'? @@ -382,8 +385,10 @@ var updateLimits = function (config, publicKey, cb) { } var body = JSON.stringify({ - domain: config.domain, - subdomain: config.subdomain + domain: config.myDomain, + subdomain: config.mySubdomain, + adminEmail: config.adminEmail, + version: Package.version }); var options = { host: 'accounts.cryptpad.fr', diff --git a/server.js b/server.js index 037a8adeb..e2527fa7d 100644 --- a/server.js +++ b/server.js @@ -121,6 +121,7 @@ app.get('/api/config', function(req, res){ waitSeconds: 60, urlArgs: 'ver=' + Package.version + (DEV_MODE? '-' + (+new Date()): ''), }, + noSubscriptionButton: (config.noSubscriptionButton === true), websocketPath: config.useExternalWebsocket ? undefined : config.websocketPath, websocketURL:'ws' + ((useSecureWebsockets) ? 's' : '') + '://' + host + ':' + websocketPort + '/cryptpad_websocket', diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 5214fcc3b..ae73867de 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -599,7 +599,7 @@ define([ var data = makePad(href, name); getStore().pushData(data, function (e) { if (e) { - if (e === 'E_OVER_LIMIT' && AppConfig.enablePinLimit) { + if (e === 'E_OVER_LIMIT') { common.alert(Messages.pinLimitNotPinned, null, true); return; } @@ -761,7 +761,7 @@ define([ }; common.isOverPinLimit = function (cb) { - if (!common.isLoggedIn() || !AppConfig.enablePinLimit) { return void cb(null, false); } + if (!common.isLoggedIn()) { return void cb(null, false); } var usage; var andThen = function (e, limit, plan) { if (e) { return void cb(e); } @@ -817,7 +817,10 @@ define([ var width = Math.floor(Math.min(quota, 1)*200); // the bar is 200px width var $usage = $('', {'class': 'usage'}).css('width', width+'px'); - if ((quota >= 0.8 || alwaysDisplayUpgrade) && data.plan !== "power") { + if (Config.noSubscriptionButton !== true && + (quota >= 0.8 || alwaysDisplayUpgrade) && + data.plan !== "power") + { var origin = encodeURIComponent(window.location.hostname); var $upgradeLink = $('', { href: "https://accounts.cryptpad.fr/#!on=" + origin, @@ -845,7 +848,7 @@ define([ else if (quota < 1) { $usage.addClass('warning'); } else { $usage.addClass('above'); - if (!limitReachedDisplayed) { + if (!limitReachedDisplayed && Config.noSubscriptionButton === true) { limitReachedDisplayed = true; common.alert(Messages._getKey('pinAboveLimitAlert', [prettyUsage, encodeURIComponent(window.location.hostname)]), null, true); } diff --git a/www/common/toolbar.js b/www/common/toolbar.js index 6920c0b0d..bf08fcb07 100644 --- a/www/common/toolbar.js +++ b/www/common/toolbar.js @@ -500,8 +500,12 @@ define([ var todo = function (e, overLimit) { if (e) { return void console.error("Unable to get the pinned usage"); } if (overLimit) { + var message = Messages.pinLimitReachedAlert; + if (ApiConfig.noSubscriptionButton === true) { + message = Messages.pinLimitReachedAlertNoAccounts; + } $limit.show().click(function () { - Cryptpad.alert(Messages.pinLimitReachedAlert, null, true); + Cryptpad.alert(message, null, true); }); } }; diff --git a/www/common/toolbar2.js b/www/common/toolbar2.js index 57d113a48..a17e24199 100644 --- a/www/common/toolbar2.js +++ b/www/common/toolbar2.js @@ -616,8 +616,12 @@ define([ var todo = function (e, overLimit) { if (e) { return void console.error("Unable to get the pinned usage"); } if (overLimit) { + var key = 'pinLimitReachedAlert'; + if (ApiConfig.noSubscriptionButton === true) { + key = 'pinLimitReachedAlertNoAccounts'; + } $limit.show().click(function () { - Cryptpad.alert(Messages._getKey('pinLimitReachedAlert', [encodeURIComponent(window.location.hostname)]), null, true); + Cryptpad.alert(Messages._getKey(key, [encodeURIComponent(window.location.hostname)]), null, true); }); } }; diff --git a/www/drive/main.js b/www/drive/main.js index 5343bd829..03dcb7716 100644 --- a/www/drive/main.js +++ b/www/drive/main.js @@ -2712,13 +2712,11 @@ define([ } /* add the usage */ - if (AppConfig.enablePinLimit) { - Cryptpad.createUsageBar(function (err, $limitContainer) { - if (err) { return void logError(err); } - $leftside.html(''); - $leftside.append($limitContainer); - }); - } + Cryptpad.createUsageBar(function (err, $limitContainer) { + if (err) { return void logError(err); } + $leftside.html(''); + $leftside.append($limitContainer); + }); /* add a history button */ var histConfig = {