From c90ba890ca2599d6667396293d58569e35a47902 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 22 Jan 2018 16:56:37 +0100 Subject: [PATCH] Add more configurable options and add a new way to use custom config --- customize.dist/application_config.js | 82 +++-------------------- www/common/application_config_internal.js | 79 ++++++++++++++++++++++ www/common/common-ui-elements.js | 37 +++++++--- www/common/cryptpad-common.js | 9 +++ 4 files changed, 123 insertions(+), 84 deletions(-) create mode 100644 www/common/application_config_internal.js diff --git a/customize.dist/application_config.js b/customize.dist/application_config.js index 2320bf9af..0cebf4b51 100644 --- a/customize.dist/application_config.js +++ b/customize.dist/application_config.js @@ -1,74 +1,10 @@ -define(function() { - var config = {}; - - /* Select the buttons displayed on the main page to create new collaborative sessions - * Existing types : pad, code, poll, slide - */ - config.availablePadTypes = ['drive', 'pad', 'code', 'slide', 'poll', 'whiteboard', 'file', 'todo', 'contacts']; - config.registeredOnlyTypes = ['file', 'contacts']; - - /* Cryptpad apps use a common API to display notifications to users - * by default, notifications are hidden after 5 seconds - * You can change their duration here (measured in milliseconds) - */ - config.notificationTimeout = 5000; - config.disableUserlistNotifications = false; - config.hideLoadingScreenTips = false; - - config.enablePinning = true; - - config.whiteboardPalette = [ - '#000000', // black - '#FFFFFF', // white - '#848484', // grey - '#8B4513', // saddlebrown - '#FF0000', // red - '#FF8080', // peach? - '#FF8000', // orange - '#FFFF00', // yellow - '#80FF80', // light green - '#00FF00', // green - '#00FFFF', // cyan - '#008B8B', // dark cyan - '#0000FF', // blue - '#FF00FF', // fuschia - '#FF00C0', // hot pink - '#800080', // purple - ]; - - config.enableTemplates = true; - - config.enableHistory = 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 - such that anyone who wants to bruteforce common credentials must do so - again on each CryptPad instance that they wish to attack. - - WARNING: this should only be set when your CryptPad instance is first - created. Changing it at a later time will break logins for all existing - users. - */ - config.loginSalt = ''; - config.minimumPasswordLength = 8; - - config.badStateTimeout = 30000; - - config.applicationsIcon = { - file: 'fa-file-text-o', - pad: 'fa-file-word-o', - code: 'fa-file-code-o', - slide: 'fa-file-powerpoint-o', - poll: 'fa-calendar', - whiteboard: 'fa-paint-brush', - todo: 'fa-tasks', - contacts: 'fa-users', - }; - - config.displayCreationScreen = false; - - config.disableAnonymousStore = false; - - return config; +/* + * You can override the configurable values from this file. + * The recommended method is to make a copy of this file (/customize.dist/application_config.js) + in a 'customize' directory (/customize/application_config.js). + * If you want to check all the configurable values, you can open the internal configuration file + but you should not change it directly (/common/application_config_internal.js) +*/ +define(['/common/application_config_internal.js'], function (AppConfig) { + return AppConfig; }); diff --git a/www/common/application_config_internal.js b/www/common/application_config_internal.js new file mode 100644 index 000000000..dc473e4a9 --- /dev/null +++ b/www/common/application_config_internal.js @@ -0,0 +1,79 @@ +/* + * This is an internal configuration file. + * If you want to change some configurable values, use the '/customize/application_config.js' + * file (make a copy from /customize.dist/application_config.js) + */ +define(function() { + var config = {}; + + /* Select the buttons displayed on the main page to create new collaborative sessions + * Existing types : pad, code, poll, slide + */ + config.availablePadTypes = ['drive', 'pad', 'code', 'slide', 'poll', 'whiteboard', 'file', 'todo', 'contacts']; + config.registeredOnlyTypes = ['file', 'contacts']; + + /* Cryptpad apps use a common API to display notifications to users + * by default, notifications are hidden after 5 seconds + * You can change their duration here (measured in milliseconds) + */ + config.notificationTimeout = 5000; + config.disableUserlistNotifications = false; + config.hideLoadingScreenTips = false; + + config.enablePinning = true; + + config.whiteboardPalette = [ + '#000000', // black + '#FFFFFF', // white + '#848484', // grey + '#8B4513', // saddlebrown + '#FF0000', // red + '#FF8080', // peach? + '#FF8000', // orange + '#FFFF00', // yellow + '#80FF80', // light green + '#00FF00', // green + '#00FFFF', // cyan + '#008B8B', // dark cyan + '#0000FF', // blue + '#FF00FF', // fuschia + '#FF00C0', // hot pink + '#800080', // purple + ]; + + config.enableTemplates = true; + + config.enableHistory = 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 + such that anyone who wants to bruteforce common credentials must do so + again on each CryptPad instance that they wish to attack. + + WARNING: this should only be set when your CryptPad instance is first + created. Changing it at a later time will break logins for all existing + users. + */ + config.loginSalt = ''; + config.minimumPasswordLength = 8; + + config.badStateTimeout = 30000; + + config.applicationsIcon = { + file: 'fa-file-text-o', + pad: 'fa-file-word-o', + code: 'fa-file-code-o', + slide: 'fa-file-powerpoint-o', + poll: 'fa-calendar', + whiteboard: 'fa-paint-brush', + todo: 'fa-tasks', + contacts: 'fa-users', + }; + + config.displayCreationScreen = false; + + config.disableAnonymousStore = false; + + return config; +}); diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index 286fb84d6..dbbf86b71 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -953,7 +953,32 @@ define([ }; if (!window.Symbol) { return void displayDefault(); } // IE doesn't have Symbol if (!href) { return void displayDefault(); } + + var centerImage = function ($img, $image, img) { + var w = img.width; + var h = img.height; + if (w>h) { + $image.css('max-height', '100%'); + $img.css('flex-direction', 'column'); + if (cb) { cb($img); } + return; + } + $image.css('max-width', '100%'); + $img.css('flex-direction', 'row'); + if (cb) { cb($img); } + }; + var parsed = Hash.parsePadUrl(href); + if (parsed.type !== "file" || parsed.hashData.type !== "file") { + var $img = $('').appendTo($container); + var img = new Image(); + $(img).attr('src', href); + img.onload = function () { + centerImage($img, $(img), img); + $(img).appendTo($img); + }; + return; + } var secret = Hash.getSecrets('file', parsed.hash); if (secret.keys && secret.channel) { var cryptKey = secret.keys && secret.keys.fileKeyStr; @@ -971,17 +996,7 @@ define([ $img.attr('data-crypto-key', 'cryptpad:' + cryptKey); UIElements.displayMediatagImage(Common, $img, function (err, $image, img) { if (err) { return void console.error(err); } - var w = img.width; - var h = img.height; - if (w>h) { - $image.css('max-height', '100%'); - $img.css('flex-direction', 'column'); - if (cb) { cb($img); } - return; - } - $image.css('max-width', '100%'); - $img.css('flex-direction', 'row'); - if (cb) { cb($img); } + centerImage($img, $image, img); }); }); } diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 775c725ad..5ec198a44 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -727,6 +727,10 @@ define([ }; Nthen(function (waitFor) { + if (AppConfig.beforeLogin) { + AppConfig.beforeLogin(LocalStore.isLoggedIn(), waitFor()); + } + }).nThen(function (waitFor) { var cfg = { query: onMessage, // TODO temporary, will be replaced by a webworker channel userHash: LocalStore.getUserHash(), @@ -763,6 +767,7 @@ define([ } initFeedback(data.feedback); + initialized = true; })); }).nThen(function (waitFor) { // Load the new pad when the hash has changed @@ -829,6 +834,10 @@ define([ delete sessionStorage.migrateAnonDrive; })); } + }).nThen(function (waitFor) { + if (AppConfig.afterLogin) { + AppConfig.afterLogin(common, waitFor()); + } }).nThen(function () { updateLocalVersion(); f(void 0, env);