From cd18075ac726da35a0da59f74fb55a1cb511b074 Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 2 Aug 2016 15:17:20 +0200 Subject: [PATCH] add some redirection logic to support old hash types --- www/common/cryptpad-common.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 6a53b2955..9fa8a9131 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -34,12 +34,35 @@ define([ var isArray = function (o) { return Object.prototype.toString.call(o) === '[object Array]'; }; + common.redirect = function (hash) { + var hostname = window.location.hostname; + + // don't do anything funny unless you're on a cryptpad subdomain + if (!/cryptpad.fr/i.test(hostname)) { return; } + + if (hash.length >= 56) { + // you're on the right domain + return; + } + + // old.cryptpad only supports these apps, so only redirect on a match + if (['/pad/', '/p/', '/code/'].indexOf(window.location.pathname) === -1) { + return; + } + + // if you make it this far then there's something wrong with your hash + // you should probably be on old.cryptpad.fr... + + window.location.hostname = 'old.cryptpad.fr'; + }; + var getSecrets = common.getSecrets = function () { var secret = {}; if (!/#/.test(window.location.href)) { secret.key = Crypto.genKey(); } else { var hash = window.location.hash.slice(1); + common.redirect(hash); secret.channel = hash.slice(0, 32); secret.key = hash.slice(32); }