From d8c18d0937a27caf15bb2db1cdc3e80a5b5abd97 Mon Sep 17 00:00:00 2001 From: felixboehm Date: Thu, 29 Dec 2016 22:02:03 +0100 Subject: [PATCH 01/10] adding docker and docker-compose --- .dockerignore | 5 ++++ .env | 4 +++ .gitignore | 1 + Dockerfile | 43 +++++++++++++++++++++++++++++ container-start.sh | 23 ++++++++++++++++ cryptpad-docker.md | 69 ++++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 23 ++++++++++++++++ readme.md | 4 +++ 8 files changed, 172 insertions(+) create mode 100644 .dockerignore create mode 100644 .env create mode 100644 Dockerfile create mode 100644 container-start.sh create mode 100644 cryptpad-docker.md create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..880c21fe3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +data +Dockerfile +docker-compose.yml +.git +.gitignore \ No newline at end of file diff --git a/.env b/.env new file mode 100644 index 000000000..95961b566 --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +VERSION=latest +USE_SSL=true +STORAGE='./storage/file' +LOG_TO_STDOUT=true \ No newline at end of file diff --git a/.gitignore b/.gitignore index 354096b87..a251b70b3 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ customization /customize/ messages.log .DS_Store +data \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..99b915055 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,43 @@ +FROM ubuntu:16.04 + +RUN apt-get update && apt-get install -y \ + vim \ + wget \ + git \ + curl \ + npm \ + nodejs-legacy + +ARG VERSION=0.3.0 + +# Download stable version +# RUN wget https://github.com/xwiki-labs/cryptpad/archive /${VERSION}.tar.gz -O /cryptpad.tar.gz \ +# && mkdir -p /cryptpad \ +# && tar -xzf /cryptpad.tar.gz -C /cryptpad --strip-components=1 \ +# && rm /cryptpad.tar.gz + +# Download from github +# RUN git clone https://github.com/xwiki-labs/cryptpad.git + +# Add code directly +ADD . /cryptpad + +WORKDIR /cryptpad + +RUN npm install \ + && npm install -g bower \ + && bower install --allow-root + +ADD container-start.sh /container-start.sh +RUN chmod u+x /container-start.sh + +EXPOSE 3000 + +VOLUME /cryptpad/datastore +VOLUME /cryptpad/customize + +ENV USE_SSL=false +ENV STORAGE='./storage/file' +ENV LOG_TO_STDOUT=true + +CMD /container-start.sh \ No newline at end of file diff --git a/container-start.sh b/container-start.sh new file mode 100644 index 000000000..db0bb924a --- /dev/null +++ b/container-start.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Creating customize folder +mkdir -p customize +[[ ! "$(ls -A customize)" ]] && echo "Creating customize folder" \ + && cp -R customize.dist/* customize/ \ + && cp config.js.dist customize/config.js + +# Linking config.js +[[ ! -h config.js ]] && echo "Linking config.js" && ln -s customize/config.js config.js + +# Configure +[[ -n "$USE_SSL" ]] && echo "Using secure websockets: $USE_SSL" \ + && sed -i "s/useSecureWebsockets: .*/useSecureWebsockets: ${USE_SSL},/g" customize/config.js + +[[ -n "$USE_SSL" ]] && echo "Using storage adapter: $STORAGE" \ + && sed -i "s/storage: .*/storage: ${STORAGE},/g" customize/config.js + +[[ -n "$LOG_TO_STDOUT" ]] && echo "Logging to stdout: $LOG_TO_STDOUT" \ + && sed -i "s/logToStdout: .*/logToStdout: ${LOG_TO_STDOUT},/g" customize/config.js + + +exec node ./server.js \ No newline at end of file diff --git a/cryptpad-docker.md b/cryptpad-docker.md new file mode 100644 index 000000000..1beb2412d --- /dev/null +++ b/cryptpad-docker.md @@ -0,0 +1,69 @@ +# Cryptpad Docker Image + +- Configuration via .env file +- Ready for use with traffic +- Using github master for now, release 0.3.0 too old +- Creating customize folder +- Adding config.js to customize folder +- Persistance for datastore and customize folder + +## TODO + +``` +cryptpad_1 | Linking config.js +cryptpad_1 | Using secure websockets: true +cryptpad_1 | Using storage adapter: './storage/file' +cryptpad_1 | sed: -e expression #1, char 27: unknown option to `s' +``` + +## Configuration + +Set configurations Dockerfile or in .env (using docker-compose) file. + +- VERSION=latest +- USE_SSL=false +- STORAGE='./storage/file' +- LOG_TO_STDOUT=true + +The .env variables are read by docker-compose and forwarded to docker container. +On runtime, in `bin/container-start.sh` the settings are written to the `config.js` file. + +## Run + +With docker + +``` +docker build -t xwiki/cryptpad . +docker -d --name cryptpad -p 3000:3000 -v ${PWD}/data:/cryptpad/datastore xwiki/cryptpad +``` + +With docker-compose + +``` +docker-compose up -d +``` + + +## Persistance + +The docker-compose file is preconfigured to persist folders + +- cryptpad/datastore --> ./data/customize +- cryptpad/customize --> ./data/customize + +In customize included find your configuration in `config.js`. + +The data folder is ignored by git, so if you want to add your customizations to git versioning change the volume: + +``` +./customize:/cryptpad/customize:rw +``` + +## SSL Proxy + +The [traefik](https://traefik.io/) proxy has builtin Let'sEncrypt for easy SSL setup. +In the docker-compose file you can find preset lables for usage with traefik. + +[Traefik Docker Image](https://hub.docker.com/_/traefik/) + +Alternativly just use plain old nginx. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..22cc3d59e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,23 @@ +version: '2' +services: + + cryptpad: + build: + context: . + args: + - VERSION=${VERSION} + image: "xwiki/cryptpad:${VERSION}" + hostname: cryptpad + + labels: + - traefik.port=3000 + - traefik.frontend.passHostHeader=true + environment: + - USE_SSL=${USE_SSL} + - STORAGE=${STORAGE} + - LOG_TO_STDOUT=${LOG_TO_STDOUT} + + restart: always + volumes: + - ./data/files:/cryptpad/datastore:rw + - ./data/customize:/cryptpad/customize:rw diff --git a/readme.md b/readme.md index e2dab9d9c..083d44431 100644 --- a/readme.md +++ b/readme.md @@ -82,6 +82,10 @@ To test CryptPad, go to http://your.server:3000/assert/ You can use WebDriver to run this test automatically by running TestSelenium.js but you will need chromedriver installed. If you use Mac, you can `brew install chromedriver`. +# Setup using Docker + +See [Cryptpad-Docker](cryptpad-docker.md) + ## Security CryptPad is *private*, not *anonymous*. Privacy protects your data, anonymity protects you. From 7c0df5aed9ad8b92bd5d093e9194681cfa7f6b21 Mon Sep 17 00:00:00 2001 From: felixboehm Date: Mon, 2 Jan 2017 11:54:50 +0100 Subject: [PATCH 02/10] use wss if useSecureWebsockets is true There are no certs / httpOtps set if proxy doing ssl offloading. Better use useSecureWebsockets from config file. --- server.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index f24117bd1..31d536de8 100644 --- a/server.js +++ b/server.js @@ -11,6 +11,7 @@ var WebRTCSrv = require('./WebRTCSrv'); var config = require('./config'); var websocketPort = config.websocketPort || config.httpPort; +var useSecureWebsockets = config.useSecureWebsockets || false; // support multiple storage back ends var Storage = require(config.storage||'./storage/file'); @@ -80,7 +81,7 @@ app.get('/api/config', function(req, res){ res.setHeader('Content-Type', 'text/javascript'); res.send('define(' + JSON.stringify({ websocketPath: config.websocketPath, - websocketURL:'ws' + ((httpsOpts) ? 's' : '') + '://' + host + ':' + + websocketURL:'ws' + ((useSecureWebsockets) ? 's' : '') + '://' + host + ':' + websocketPort + '/cryptpad_websocket', }) + ');'); }); From 4902aebe773877afcde4434b3befdf6416238f94 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 9 Jan 2017 11:01:29 +0100 Subject: [PATCH 03/10] open home page table links in new tabs --- customize.dist/main.js | 1 + 1 file changed, 1 insertion(+) diff --git a/customize.dist/main.js b/customize.dist/main.js index ca2e781a0..a03136b13 100644 --- a/customize.dist/main.js +++ b/customize.dist/main.js @@ -120,6 +120,7 @@ define([ .append($('').append(readOnlyText).append($('', { href: pad.href, title: pad.title, + target: '_blank', }).text(shortTitle))) .append($('').text(created)) .append($('').text(date)) From 0373556475045df5a82e2fb8c37da2c4d9e57c50 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 9 Jan 2017 11:46:21 +0100 Subject: [PATCH 04/10] support old hashes in /poll --- www/poll/main.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/www/poll/main.js b/www/poll/main.js index e689d33a4..99b887e56 100644 --- a/www/poll/main.js +++ b/www/poll/main.js @@ -22,6 +22,9 @@ define([ var secret = Cryptpad.getSecrets(); var readOnly = secret.keys && !secret.keys.editKeyStr; + if (!secret.keys) { + secret.keys = secret.key; + } Cryptpad.addLoadingScreen(); var onConnectError = function (info) { From a3cd100c9408c257f3547fc362fd91ce89daa372 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 9 Jan 2017 11:46:51 +0100 Subject: [PATCH 05/10] apply yflory's safari patch --- www/pad/main.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/www/pad/main.js b/www/pad/main.js index 09c2be0f4..e957c5634 100644 --- a/www/pad/main.js +++ b/www/pad/main.js @@ -630,6 +630,11 @@ define([ if (!APP.isMaximized) { editor.execCommand('maximize'); APP.isMaximized = true; + // We have to call it 3 times in Safari in order to have the editor fully maximized -_- + if ((''+window.navigator.vendor).indexOf('Apple') !== -1) { + editor.execCommand('maximize'); + editor.execCommand('maximize'); + } } module.patchText = TextPatcher.create({ From 0abec4ddb3b58f3545ce5b9e0e1381c30b3fd254 Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 6 Jan 2017 13:52:30 +0100 Subject: [PATCH 06/10] Fix error with placeholder translations in Safari --- customize.dist/messages.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/customize.dist/messages.js b/customize.dist/messages.js index 1807d5c82..59be80317 100644 --- a/customize.dist/messages.js +++ b/customize.dist/messages.js @@ -95,7 +95,7 @@ define(['/customize/languageSelector.js', $('[data-localization]').each(translateText); $('#pad-iframe').contents().find('[data-localization]').each(translateText); $('[data-localization-title]').each(translateTitle); - $('[data-localization-placeholder').each(translatePlaceholder); + $('[data-localization-placeholder]').each(translatePlaceholder); $('#pad-iframe').contents().find('[data-localization-title]').each(translateTitle); }; From 1c3f1a15cdb8c82982c3e77b8b1dec6355657661 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 9 Jan 2017 17:02:01 +0100 Subject: [PATCH 07/10] make sure that /pad is resized after loading --- www/common/cryptpad-common.js | 4 ++-- www/pad/main.js | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 0bf419a24..6fdbeb0bc 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -678,8 +678,8 @@ define([ $loading.append($container); $('body').append($loading); }; - common.removeLoadingScreen = function () { - $('#' + LOADING).fadeOut(750); + common.removeLoadingScreen = function (cb) { + $('#' + LOADING).fadeOut(750, cb); }; common.errorLoadingScreen = function (error) { $('.spinnerContainer').hide(); diff --git a/www/pad/main.js b/www/pad/main.js index e957c5634..3c65bfcb0 100644 --- a/www/pad/main.js +++ b/www/pad/main.js @@ -62,6 +62,14 @@ define([ Cryptpad: Cryptpad, }; + var emitResize = APP.emitResize = function () { + var cw = $('#pad-iframe')[0].contentWindow; + + var evt = cw.document.createEvent('UIEvents'); + evt.initUIEvent('resize', true, false, cw, 0); + cw.dispatchEvent(evt); + }; + var toolbar; var isNotMagicLine = function (el) { @@ -630,11 +638,6 @@ define([ if (!APP.isMaximized) { editor.execCommand('maximize'); APP.isMaximized = true; - // We have to call it 3 times in Safari in order to have the editor fully maximized -_- - if ((''+window.navigator.vendor).indexOf('Apple') !== -1) { - editor.execCommand('maximize'); - editor.execCommand('maximize'); - } } module.patchText = TextPatcher.create({ @@ -661,7 +664,8 @@ define([ console.log("Unlocking editor"); setEditable(true); initializing = false; - Cryptpad.removeLoadingScreen(); + Cryptpad.removeLoadingScreen(emitResize); + // Update the toolbar list: // Add the current user in the metadata if he has edit rights if (readOnly) { return; } From 74a12f50acd540d29273e1c18fb6ddce0bc6e639 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 9 Jan 2017 17:35:58 +0100 Subject: [PATCH 08/10] only migrate keys which don't already exist --- www/poll/main.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/www/poll/main.js b/www/poll/main.js index 99b887e56..133f76a11 100644 --- a/www/poll/main.js +++ b/www/poll/main.js @@ -364,12 +364,19 @@ define([ if (proxy && proxy.version === 1) { return; } console.log("Configuring proxy schema..."); - proxy.info = schema.info; - proxy.table = schema.table; + proxy.info = proxy.info || schema.info; + Object.keys(schema.info).forEach(function (k) { + if (!proxy.info[k]) { proxy.info[k] = schema.info[k]; } + }); + + proxy.table = proxy.table || schema.table; + Object.keys(schema.table).forEach(function (k) { + if (!proxy.table[k]) { proxy.table[k] = schema.table[k]; } + }); + proxy.version = 1; }; - /* */ @@ -645,7 +652,7 @@ define([ suggestName: suggestName }, ifrw: window, - common: Cryptpad + common: Cryptpad, }; var toolbar = info.realtime.toolbar = Toolbar.create(APP.$bar, info.myID, info.realtime, info.getLag, userList, config); From b39067d2a1bac2ac76398f73b4f7f2eb0ef9a0a8 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 9 Jan 2017 18:07:45 +0100 Subject: [PATCH 09/10] jshint compliance --- customize.dist/translations/messages.js | 2 +- www/examples/upload/main.js | 5 +++-- www/pad/main.js | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js index 36c48315b..34ccd85c6 100644 --- a/customize.dist/translations/messages.js +++ b/customize.dist/translations/messages.js @@ -237,7 +237,7 @@ define(function () { out.login_cancel_prompt = "...or if you may have entered the wrong username or password, cancel to try again."; - out.login_registerSuccess = "registered successfully. Make sure you don't forget your password!" + out.login_registerSuccess = "registered successfully. Make sure you don't forget your password!"; out.login_passwordMismatch = "The two passwords you entered do not match. Try again"; out.login_warning = [ diff --git a/www/examples/upload/main.js b/www/examples/upload/main.js index 0cfde2693..1aa4ffb75 100644 --- a/www/examples/upload/main.js +++ b/www/examples/upload/main.js @@ -12,16 +12,17 @@ define([ //console.log("plaintext"); //console.log(body); +/* 0 && Crypt.put(body, function (e, out) { if (e) { return void console.error(e); } if (out) { console.log(out); } - }); + }); */ var data = {}; -(_ => { +(function () { var cyphertext = data.payload = Crypto.encrypt(body, key); console.log("encrypted"); console.log(cyphertext); diff --git a/www/pad/main.js b/www/pad/main.js index 3c65bfcb0..2f611e566 100644 --- a/www/pad/main.js +++ b/www/pad/main.js @@ -62,7 +62,7 @@ define([ Cryptpad: Cryptpad, }; - var emitResize = APP.emitResize = function () { + var emitResize = module.emitResize = function () { var cw = $('#pad-iframe')[0].contentWindow; var evt = cw.document.createEvent('UIEvents'); @@ -635,9 +635,9 @@ define([ // this should only ever get called once, when the chain syncs var onReady = realtimeOptions.onReady = function (info) { - if (!APP.isMaximized) { + if (!module.isMaximized) { editor.execCommand('maximize'); - APP.isMaximized = true; + module.isMaximized = true; } module.patchText = TextPatcher.create({ From 63b9d4e9fd06057dc549b3bc606ce156484384f7 Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 10 Jan 2017 10:53:09 +0100 Subject: [PATCH 10/10] remove path for backwards compatibility --- www/README.txt | 58 ------------------------------------------------ www/p/index.html | 28 ----------------------- 2 files changed, 86 deletions(-) delete mode 100644 www/README.txt delete mode 100644 www/p/index.html diff --git a/www/README.txt b/www/README.txt deleted file mode 100644 index 85583e4fe..000000000 --- a/www/README.txt +++ /dev/null @@ -1,58 +0,0 @@ -# This is Cryptpad - -There are quite a few realtime editors packed into this installation. -Most are prototypes that could use a lot of work. - -All editors make use of Cryptpad's end to end encryption. -Some of them have much better UI. - -## /pad/ - -Pad is the main feature of Cryptpad. It features a CKEditor for realtime WYSIWYG editing. - -## /code/ - -Code has syntax highlighting features. - -## /sheet/ - -Sheet is under development. It will feature realtime collaborative spreadsheets. - -## /text/ - -Text is a very simple encrypted plain text editor with no highlighting. - -## /render/ - -Render takes advantage of the fact that multiple editors can both use the same 'channel' at once. -Channel, in this sense, refers to part of the unique hash of a page which groups messages together. -If you visit a /text/ and a /render/ page simultaneously, the changes you make in /text/ will be -rendered as markdown in /render/. You can't edit in /render/ directly, but it adds value to other -editors by allowing a realtime preview of your work. - -## /vdom/ - -Vdom is under heavy development, and features an alternative approach to the realtime WYSIWYG -editor. It syncs a representation of a virtual-dom instead of syncing the HTML itself. In practice, -this means that there are fewer inconsistencies between different browsers' representations of the dom. -This makes the codebase much simpler, and eliminates many classes of bugs. It's still far from perfect, -but it is quite promising. - -## /hack/ - -Hack leaves it to the user to decide whether XSS (Cross site scripting) is a bug or a feature. -It exposes a realtime text pad to multiple users, and provides a button which will cause the -contents of the pad to be passed to an `eval` call. Anyone with the hash of the page can edit -the contents, so make sure you read the code you're about to run. If you can't read it, you -probably shouldn't run it. In any case, it might be useful for pair programming or when you want -to sketch out and prototype simple demos. - -## Coming soon - -* style - - live editing of CSS as applied to some Lorum Ipsum -* polyweb - - a multi-featured editor which connects to multiple channels at once, for: - 1. live rendered markdown - 2. live style editing - 3. live javascript diff --git a/www/p/index.html b/www/p/index.html deleted file mode 100644 index caf716785..000000000 --- a/www/p/index.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - -

There's nothing here.

-

You probably want to visit old.cryptpad.fr

- - - -