diff --git a/.flowconfig b/.flowconfig new file mode 100644 index 000000000..4a58bdcde --- /dev/null +++ b/.flowconfig @@ -0,0 +1,7 @@ +[ignore] + +[include] + +[libs] + +[options] diff --git a/.jshintignore b/.jshintignore index ae60d4ba0..51636ed77 100644 --- a/.jshintignore +++ b/.jshintignore @@ -9,4 +9,4 @@ server.js NetFluxWebsocketSrv.js NetFluxWebsocketServer.js WebRTCSrv.js - +www/common/media-tag.js diff --git a/.travis.yml b/.travis.yml index 24288c6f2..4160b8719 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ node_js: - "6.6.0" before_script: - npm run-script lint - - cp config.js.dist config.js + - cp config.example.js config.js - npm install bower - ./node_modules/bower/bin/bower install - node ./server.js & diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index b1d2515f1..0d1d94873 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -76,7 +76,7 @@ Chainpad can handle out of order messages, but it performs best when its message By architecting your system such that all clients send to a server which then relays to other clients, you guarantee that a particular chain of patches is consistent between the participants of your session. Cryptpad is capable of using a variety of data stores. -Which data store your instance employs can be [easily configured](https://github.com/xwiki-labs/cryptpad/blob/master/config.js.dist). +Which data store your instance employs can be [easily configured](https://github.com/xwiki-labs/cryptpad/blob/master/config.example.js). You simply need to write an adaptor which conforms to a simple API. The documentation for writing such an adaptor, and the complete list of implemented adaptors, is available [here](https://github.com/xwiki-labs/cryptpad/tree/master/storage). @@ -243,5 +243,3 @@ A session could still have difficulty with very large chains, however, in practi ## Conclusion - - diff --git a/config.js.dist b/config.example.js similarity index 99% rename from config.js.dist rename to config.example.js index 6ef7267c1..692a91c59 100644 --- a/config.js.dist +++ b/config.example.js @@ -1,3 +1,4 @@ +/*@flow*/ /* globals module */ diff --git a/container-start.sh b/container-start.sh index 89f3be1f1..2aa4ae10f 100755 --- a/container-start.sh +++ b/container-start.sh @@ -4,12 +4,12 @@ mkdir -p customize [ -z "$(ls -A customize)" ] && echo "Creating customize folder" \ && cp -R customize.dist/* customize/ \ - && cp config.js.dist customize/config.js + && cp config.example.js customize/config.js -# Linking config.js +# Linking config.js [ ! -h config.js ] && echo "Linking config.js" && ln -s customize/config.js config.js -# Configure +# Configure [ -n "$USE_SSL" ] && echo "Using secure websockets: $USE_SSL" \ && sed -i "s/useSecureWebsockets: .*/useSecureWebsockets: ${USE_SSL},/g" customize/config.js diff --git a/readme.md b/readme.md index b3c8a1a61..60da12331 100644 --- a/readme.md +++ b/readme.md @@ -32,8 +32,8 @@ npm install npm install -g bower ## if necessary bower install -## copy config.js.dist to config.js -cp config.js.dist config.js +## copy config.example.js to config.js +cp config.example.js config.js node ./server.js ``` @@ -162,4 +162,3 @@ sales@xwiki.com [fragment identifier]: https://en.wikipedia.org/wiki/Fragment_identifier [active attack]: https://en.wikipedia.org/wiki/Attack_(computing)#Types_of_attacks [Creative Commons Attribution 2.5 License]: http://creativecommons.org/licenses/by/2.5/ - diff --git a/rpc.js b/rpc.js index d68fa78b4..808815d84 100644 --- a/rpc.js +++ b/rpc.js @@ -1,3 +1,4 @@ +/*@flow*/ /* Use Nacl for checking signatures of messages */ var Nacl = require("tweetnacl"); @@ -375,7 +376,8 @@ var resetUserPins = function (store, Sessions, publicKey, channelList, cb) { }); }; -RPC.create = function (config, cb) { +/*::const ConfigType = require('./config.example.js');*/ +RPC.create = function (config /*:typeof(ConfigType)*/, cb /*:(?Error, ?Function)=>void*/) { // load pin-store... console.log('loading rpc module...'); @@ -384,7 +386,11 @@ RPC.create = function (config, cb) { var store; - var rpc = function (ctx, data, respond) { + var rpc = function ( + ctx /*:{ store: Object }*/, + data /*:Array>*/, + respond /*:(?string, ?Array)=>void*/) + { if (!Array.isArray(data)) { return void respond('INVALID_ARG_FORMAT'); } @@ -494,4 +500,3 @@ RPC.create = function (config, cb) { }, 60000); }); }; - diff --git a/storage/README.md b/storage/README.md index 03117d95c..8fabdf53b 100644 --- a/storage/README.md +++ b/storage/README.md @@ -46,14 +46,14 @@ While we migrate to our new Netflux API, only the leveldb adaptor will be suppor ## removeChannel(channelName, callback) -This method is called (optionally, see config.js.dist for more info) some amount of time after the last client in a channel disconnects. +This method is called (optionally, see config.example.js for more info) some amount of time after the last client in a channel disconnects. It should remove any history of that channel, and execute a callback which takes an error message as an argument. ## Documenting your adaptor Naturally, you should comment your code well before making a PR. -Failing that, you should definitely add notes to `cryptpad/config.js.dist` such that people who wish to install your adaptor know how to do so. +Failing that, you should definitely add notes to `cryptpad/config.example.js` such that people who wish to install your adaptor know how to do so. Notes on how to install the back end, as well as how to install the client for connecting to the back end (as is the case with many datastores), as well as how to configure cryptpad to use your adaptor. The current configuration file should serve as an example of what to add, and how to comment. diff --git a/www/assert/main.js b/www/assert/main.js index eb9bb9157..3306c3bab 100644 --- a/www/assert/main.js +++ b/www/assert/main.js @@ -139,6 +139,49 @@ define([ strungJSON(orig); }); + // check that old hashes parse correctly + assert(function () { + var secret = Cryptpad.parseHash('67b8385b07352be53e40746d2be6ccd7XAYSuJYYqa9NfmInyHci7LNy'); + return secret.channel === "67b8385b07352be53e40746d2be6ccd7" && + secret.key === "XAYSuJYYqa9NfmInyHci7LNy" && + secret.version === 0; + }, "Old hash failed to parse"); + + // make sure version 1 hashes parse correctly + assert(function () { + var secret = Cryptpad.parseHash('/1/edit/3Ujt4F2Sjnjbis6CoYWpoQ/usn4+9CqVja8Q7RZOGTfRgqI'); + return secret.version === 1 && + secret.mode === "edit" && + secret.channel === "3Ujt4F2Sjnjbis6CoYWpoQ" && + secret.key === "usn4+9CqVja8Q7RZOGTfRgqI" && + !secret.present; + }, "version 1 hash failed to parse"); + + // test support for present mode in hashes + assert(function () { + var secret = Cryptpad.parseHash('/1/edit/CmN5+YJkrHFS3NSBg-P7Sg/DNZ2wcG683GscU4fyOyqA87G/present'); + return secret.version === 1 + && secret.mode === "edit" + && secret.channel === "CmN5+YJkrHFS3NSBg-P7Sg" + && secret.key === "DNZ2wcG683GscU4fyOyqA87G" + && secret.present; + }, "version 1 hash failed to parse"); + + // test support for trailing slash + assert(function () { + var secret = Cryptpad.parseHash('/1/edit/3Ujt4F2Sjnjbis6CoYWpoQ/usn4+9CqVja8Q7RZOGTfRgqI/'); + return secret.version === 1 && + secret.mode === "edit" && + secret.channel === "3Ujt4F2Sjnjbis6CoYWpoQ" && + secret.key === "usn4+9CqVja8Q7RZOGTfRgqI" && + !secret.present; + }, "test support for trailing slashes in version 1 hash failed to parse"); + + assert(function () { + // TODO + return true; + }, "version 2 hash failed to parse correctly"); + var swap = function (str, dict) { return str.replace(/\{\{(.*?)\}\}/g, function (all, key) { return typeof dict[key] !== 'undefined'? dict[key] : all; diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 757b04e15..1c90f9c95 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -1189,6 +1189,11 @@ define([ if (typeof(window.Proxy) === 'undefined') { feedback("NO_PROXIES"); } + + if (typeof(Array.isArray) === 'function') { + feedback("NO_ISARRAY"); + } + $(function() { // Race condition : if document.body is undefined when alertify.js is loaded, Alertify // won't work. We have to reset it now to make sure it uses a correct "body" diff --git a/www/examples/file/main.js b/www/examples/file/main.js index 4db3eb8ba..298d88904 100644 --- a/www/examples/file/main.js +++ b/www/examples/file/main.js @@ -45,7 +45,6 @@ define([ }; Toolbar.create($bar, null, null, null, null, configTb); }); - }; Cryptpad.ready(function (err, anv) {