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 12bcaf65b..abc6eb530 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ customization messages.log .DS_Store www/scratch +data 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/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($('
There's nothing here.
-You probably want to visit old.cryptpad.fr
- - - - diff --git a/www/pad/main.js b/www/pad/main.js index 6fbf46428..e8b148d78 100644 --- a/www/pad/main.js +++ b/www/pad/main.js @@ -62,6 +62,14 @@ define([ Cryptpad: Cryptpad, }; + var emitResize = module.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,14 +638,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'); - // 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'); - } - APP.isMaximized = true; + module.isMaximized = true; } module.patchText = TextPatcher.create({ @@ -664,7 +667,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; } diff --git a/www/poll/main.js b/www/poll/main.js index a0b9e5273..5f76a60b7 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) { @@ -361,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; }; - /* */ @@ -642,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);