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/.travis.yml b/.travis.yml index bc9ee71df..1331ef3cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,8 @@ env: branches: only: - master - - diffdom - - beta - - netflux + - soon + - staging node_js: - "4.2.1" before_script: 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/TestSelenium.js b/TestSelenium.js index 2195e9ce6..9623577b5 100644 --- a/TestSelenium.js +++ b/TestSelenium.js @@ -1,6 +1,11 @@ /* global process */ var WebDriver = require("selenium-webdriver"); +if (process.env.TRAVIS_PULL_REQUEST && process.env.TRAVIS_PULL_REQUEST !== 'false') { + // We can't do saucelabs on pull requests so don't fail. + return; +} + var driver; if (process.env.SAUCE_USERNAME !== undefined) { var browserArray = process.env.BROWSER.split(':'); @@ -19,12 +24,15 @@ if (process.env.SAUCE_USERNAME !== undefined) { driver.get('http://localhost:3000/assert/'); var report = driver.wait(WebDriver.until.elementLocated(WebDriver.By.className("report")), 5000); report.getAttribute("class").then(function (cls) { - driver.quit(); - if (!cls) { - throw new Error("cls is null"); - } else if (cls.indexOf("failure") !== -1) { - throw new Error("cls contains the word failure"); - } else if (cls.indexOf("success") === -1) { - throw new Error("cls does not contain the word success"); - } + report.getText().then(function (text) { + console.log("\n-----\n" + text + "\n-----"); + driver.quit(); + if (!cls) { + throw new Error("cls is null"); + } else if (cls.indexOf("failure") !== -1) { + throw new Error("cls contains the word failure"); + } else if (cls.indexOf("success") === -1) { + throw new Error("cls does not contain the word success"); + } + }); }); diff --git a/WebRTCSrv.js b/WebRTCSrv.js deleted file mode 100644 index 2c1bc81e2..000000000 --- a/WebRTCSrv.js +++ /dev/null @@ -1,61 +0,0 @@ -'use strict' -let WebSocketServer = require('ws').Server -const UNSUPPORTED_DATA = 1007 -const POLICY_VIOLATION = 1008 -const CLOSE_UNSUPPORTED = 1003 - -var run = module.exports.run = function(server) { - server.on('connection', (socket) => { - if(socket.upgradeReq.url !== '/cryptpad_webrtc') { return; } - socket.on('message', (data) => { - try { - let msg = JSON.parse(data) - console.log(msg) - if (msg.hasOwnProperty('key')) { - for (let master of server.clients) { - if (master.key === msg.key) { - socket.close(POLICY_VIOLATION, 'The key already exists') - return - } - } - socket.key = msg.key - socket.joiningClients = [] - } else if (msg.hasOwnProperty('id')) { - for (let index in socket.joiningClients) { - if (index == msg.id) { - socket.joiningClients[index].send(JSON.stringify({data: msg.data})) - return - } - } - socket.close(POLICY_VIOLATION, 'Unknown id') - } else if (msg.hasOwnProperty('join')) { - for (let master of server.clients) { - if (master.key === msg.join) { - socket.master = master - master.joiningClients.push(socket) - let id = master.joiningClients.length - 1 - master.send(JSON.stringify({id, data: msg.data})) - return - } - } - socket.close(POLICY_VIOLATION, 'Unknown key') - } else if (msg.hasOwnProperty('data') && socket.hasOwnProperty('master')) { - let id = socket.master.joiningClients.indexOf(socket) - socket.master.send(JSON.stringify({id, data: msg.data})) - } else { - socket.close(UNSUPPORTED_DATA, 'Unsupported message format') - } - } catch (event) { - socket.close(CLOSE_UNSUPPORTED, 'Server accepts only JSON') - } - }) - - socket.on('close', (event) => { - if (socket.hasOwnProperty('joiningClients')) { - for (let client of socket.joiningClients) { - client.close(POLICY_VIOLATION, 'The peer is no longer available') - } - } - }); - }) -} \ No newline at end of file diff --git a/bower.json b/bower.json index c92757dea..93adb0c09 100644 --- a/bower.json +++ b/bower.json @@ -42,6 +42,6 @@ "alertifyjs": "^1.0.11", "spin.js": "^2.3.2", "scrypt-async": "^1.2.0", - "bootstrap": "^3.3.7" + "bootstrap": "#v4.0.0-alpha.6" } } diff --git a/config.js.dist b/config.js.dist index b015b55be..91bf38d95 100644 --- a/config.js.dist +++ b/config.js.dist @@ -17,7 +17,7 @@ module.exports = { /* httpHeaders: { "Content-Security-Policy": [ - "default-serc 'none'", + "default-src 'none'", "style-src 'unsafe-inline' 'self'", "script-src 'self' 'unsafe-eval' 'unsafe-inline'", "child-src 'self' cryptpad.fr *.cryptpad.fr", @@ -50,6 +50,12 @@ module.exports = { */ //websocketPort: 3000, + /* if you want to run a different version of cryptpad but using the same websocket + * server, you should use the other server port as websocketPort and disable + * the websockets on that server + */ + //useExternalWebsocket: false, + /* If Cryptpad is proxied without using https, the server needs to know. * Specify 'useSecureWebsockets: true' so that it can send * Content Security Policy Headers that prevent http and https from mixing @@ -75,6 +81,7 @@ module.exports = { 'privacy', 'terms', 'about', + 'contact', ], /* 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/DecorateToolbar.js b/customize.dist/DecorateToolbar.js deleted file mode 100644 index 023c929e1..000000000 --- a/customize.dist/DecorateToolbar.js +++ /dev/null @@ -1,39 +0,0 @@ -/* - globals define -*/ -define([ - '/customize/languageSelector.js', - '/customize/messages.js', - '/bower_components/jquery/dist/jquery.min.js' -], function (LS, Messages) { - var $ = window.jQuery; - var main = function () { - var url = window.location.pathname; - var isHtml = /\.html/.test(url) || url === '/' || url === ''; - if (!isHtml) { - Messages._applyTranslation(); - return; - } - $.ajax({ - url: isHtml ? '/customize/BottomBar.html' : '/customize/Header.html', - success: function (ret) { - var $bar = $(ret); - $('body').append($bar); - - var $sel = $bar.find('#language-selector'); - - Object.keys(Messages._languages).forEach(function (code) { - $sel.append($('