|
|
@ -1,11 +1,25 @@
|
|
|
|
|
|
|
|
// Load #1, load as little as possible because we are in a race to get the loading screen up.
|
|
|
|
define([
|
|
|
|
define([
|
|
|
|
|
|
|
|
'/bower_components/nthen/index.js',
|
|
|
|
'/api/config',
|
|
|
|
'/api/config',
|
|
|
|
'jquery',
|
|
|
|
'jquery',
|
|
|
|
'/common/requireconfig.js',
|
|
|
|
'/common/requireconfig.js'
|
|
|
|
'/common/cryptget.js'
|
|
|
|
], function (nThen, ApiConfig, $, RequireConfig) {
|
|
|
|
], function (ApiConfig, $, RequireConfig, Cryptget) {
|
|
|
|
|
|
|
|
var requireConfig = RequireConfig();
|
|
|
|
var requireConfig = RequireConfig();
|
|
|
|
$(function () {
|
|
|
|
|
|
|
|
|
|
|
|
// Loaded in load #3
|
|
|
|
|
|
|
|
var CpNfOuter;
|
|
|
|
|
|
|
|
var Cryptpad;
|
|
|
|
|
|
|
|
var Crypto;
|
|
|
|
|
|
|
|
var Cryptget;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var sframeChan;
|
|
|
|
|
|
|
|
var secret;
|
|
|
|
|
|
|
|
var hashes;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nThen(function (waitFor) {
|
|
|
|
|
|
|
|
$(waitFor());
|
|
|
|
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
var req = {
|
|
|
|
var req = {
|
|
|
|
cfg: requireConfig,
|
|
|
|
cfg: requireConfig,
|
|
|
|
req: [ '/common/loading.js' ],
|
|
|
|
req: [ '/common/loading.js' ],
|
|
|
@ -16,183 +30,195 @@ define([
|
|
|
|
$('#sbox-iframe').attr('src',
|
|
|
|
$('#sbox-iframe').attr('src',
|
|
|
|
ApiConfig.httpSafeOrigin + '/pad2/inner.html?' + requireConfig.urlArgs +
|
|
|
|
ApiConfig.httpSafeOrigin + '/pad2/inner.html?' + requireConfig.urlArgs +
|
|
|
|
'#' + encodeURIComponent(JSON.stringify(req)));
|
|
|
|
'#' + encodeURIComponent(JSON.stringify(req)));
|
|
|
|
});
|
|
|
|
|
|
|
|
require([
|
|
|
|
// This is a cheap trick to avoid loading sframe-channel in parallel with the
|
|
|
|
'/common/sframe-channel.js',
|
|
|
|
// loading screen setup.
|
|
|
|
'/common/sframe-chainpad-netflux-outer.js',
|
|
|
|
var done = waitFor();
|
|
|
|
'/bower_components/nthen/index.js',
|
|
|
|
var onMsg = function (msg) {
|
|
|
|
'/common/cryptpad-common.js',
|
|
|
|
var data = JSON.parse(msg.data);
|
|
|
|
'/bower_components/chainpad-crypto/crypto.js'
|
|
|
|
if (data.q !== 'READY') { return; }
|
|
|
|
], function (SFrameChannel, CpNfOuter, nThen, Cryptpad, Crypto) {
|
|
|
|
window.removeEventListener('message', onMsg);
|
|
|
|
var sframeChan;
|
|
|
|
var _done = done;
|
|
|
|
var hashes;
|
|
|
|
done = function () { };
|
|
|
|
var secret;
|
|
|
|
_done();
|
|
|
|
nThen(function (waitFor) {
|
|
|
|
};
|
|
|
|
$(waitFor());
|
|
|
|
window.addEventListener('message', onMsg);
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
|
|
|
|
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
|
|
|
|
// Load #3, the loading screen is up so grab whatever you need...
|
|
|
|
|
|
|
|
require([
|
|
|
|
|
|
|
|
'/common/sframe-chainpad-netflux-outer.js',
|
|
|
|
|
|
|
|
'/common/cryptpad-common.js',
|
|
|
|
|
|
|
|
'/bower_components/chainpad-crypto/crypto.js',
|
|
|
|
|
|
|
|
'/common/cryptget.js',
|
|
|
|
|
|
|
|
'/common/sframe-channel.js',
|
|
|
|
|
|
|
|
], waitFor(function (_CpNfOuter, _Cryptpad, _Crypto, _Cryptget, SFrameChannel) {
|
|
|
|
|
|
|
|
CpNfOuter = _CpNfOuter;
|
|
|
|
|
|
|
|
Cryptpad = _Cryptpad;
|
|
|
|
|
|
|
|
Crypto = _Crypto;
|
|
|
|
|
|
|
|
Cryptget = _Cryptget;
|
|
|
|
SFrameChannel.create($('#sbox-iframe')[0].contentWindow, waitFor(function (sfc) {
|
|
|
|
SFrameChannel.create($('#sbox-iframe')[0].contentWindow, waitFor(function (sfc) {
|
|
|
|
sframeChan = sfc;
|
|
|
|
sframeChan = sfc;
|
|
|
|
console.log('sframe initialized');
|
|
|
|
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
Cryptpad.ready(waitFor());
|
|
|
|
Cryptpad.ready(waitFor());
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
}));
|
|
|
|
secret = Cryptpad.getSecrets();
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
if (!secret.channel) {
|
|
|
|
secret = Cryptpad.getSecrets();
|
|
|
|
// New pad: create a new random channel id
|
|
|
|
if (!secret.channel) {
|
|
|
|
secret.channel = Cryptpad.createChannelId();
|
|
|
|
// New pad: create a new random channel id
|
|
|
|
}
|
|
|
|
secret.channel = Cryptpad.createChannelId();
|
|
|
|
Cryptpad.getShareHashes(secret, waitFor(function (err, h) { hashes = h; }));
|
|
|
|
}
|
|
|
|
}).nThen(function (/*waitFor*/) {
|
|
|
|
Cryptpad.getShareHashes(secret, waitFor(function (err, h) { hashes = h; }));
|
|
|
|
var readOnly = secret.keys && !secret.keys.editKeyStr;
|
|
|
|
}).nThen(function (/*waitFor*/) {
|
|
|
|
if (!secret.keys) { secret.keys = secret.key; }
|
|
|
|
var readOnly = secret.keys && !secret.keys.editKeyStr;
|
|
|
|
var parsed = Cryptpad.parsePadUrl(window.location.href);
|
|
|
|
if (!secret.keys) { secret.keys = secret.key; }
|
|
|
|
parsed.type = parsed.type.replace('pad2', 'pad');
|
|
|
|
var parsed = Cryptpad.parsePadUrl(window.location.href);
|
|
|
|
if (!parsed.type) { throw new Error(); }
|
|
|
|
parsed.type = parsed.type.replace('pad2', 'pad');
|
|
|
|
var defaultTitle = Cryptpad.getDefaultName(parsed);
|
|
|
|
if (!parsed.type) { throw new Error(); }
|
|
|
|
var updateMeta = function () {
|
|
|
|
var defaultTitle = Cryptpad.getDefaultName(parsed);
|
|
|
|
//console.log('EV_METADATA_UPDATE');
|
|
|
|
var updateMeta = function () {
|
|
|
|
var name;
|
|
|
|
//console.log('EV_METADATA_UPDATE');
|
|
|
|
nThen(function (waitFor) {
|
|
|
|
var name;
|
|
|
|
Cryptpad.getLastName(waitFor(function (err, n) {
|
|
|
|
nThen(function (waitFor) {
|
|
|
|
if (err) { console.log(err); }
|
|
|
|
Cryptpad.getLastName(waitFor(function (err, n) {
|
|
|
|
name = n;
|
|
|
|
if (err) { console.log(err); }
|
|
|
|
}));
|
|
|
|
name = n;
|
|
|
|
}).nThen(function (/*waitFor*/) {
|
|
|
|
}));
|
|
|
|
sframeChan.event('EV_METADATA_UPDATE', {
|
|
|
|
}).nThen(function (/*waitFor*/) {
|
|
|
|
doc: {
|
|
|
|
sframeChan.event('EV_METADATA_UPDATE', {
|
|
|
|
defaultTitle: defaultTitle,
|
|
|
|
doc: {
|
|
|
|
type: parsed.type
|
|
|
|
defaultTitle: defaultTitle,
|
|
|
|
},
|
|
|
|
type: parsed.type
|
|
|
|
user: {
|
|
|
|
},
|
|
|
|
name: name,
|
|
|
|
user: {
|
|
|
|
uid: Cryptpad.getUid(),
|
|
|
|
name: name,
|
|
|
|
avatar: Cryptpad.getAvatarUrl(),
|
|
|
|
uid: Cryptpad.getUid(),
|
|
|
|
profile: Cryptpad.getProfileUrl(),
|
|
|
|
avatar: Cryptpad.getAvatarUrl(),
|
|
|
|
curvePublic: Cryptpad.getProxy().curvePublic,
|
|
|
|
profile: Cryptpad.getProfileUrl(),
|
|
|
|
netfluxId: Cryptpad.getNetwork().webChannels[0].myID,
|
|
|
|
curvePublic: Cryptpad.getProxy().curvePublic,
|
|
|
|
},
|
|
|
|
netfluxId: Cryptpad.getNetwork().webChannels[0].myID,
|
|
|
|
priv: {
|
|
|
|
},
|
|
|
|
accountName: Cryptpad.getAccountName(),
|
|
|
|
priv: {
|
|
|
|
origin: window.location.origin,
|
|
|
|
accountName: Cryptpad.getAccountName(),
|
|
|
|
pathname: window.location.pathname,
|
|
|
|
origin: window.location.origin,
|
|
|
|
readOnly: readOnly,
|
|
|
|
pathname: window.location.pathname,
|
|
|
|
availableHashes: hashes,
|
|
|
|
readOnly: readOnly,
|
|
|
|
isTemplate: Cryptpad.isTemplate(window.location.href),
|
|
|
|
availableHashes: hashes,
|
|
|
|
feedbackAllowed: Cryptpad.isFeedbackAllowed()
|
|
|
|
isTemplate: Cryptpad.isTemplate(window.location.href),
|
|
|
|
}
|
|
|
|
feedbackAllowed: Cryptpad.isFeedbackAllowed()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Cryptpad.onDisplayNameChanged(updateMeta);
|
|
|
|
|
|
|
|
sframeChan.onReg('EV_METADATA_UPDATE', updateMeta);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Cryptpad.onError(function (info) {
|
|
|
|
|
|
|
|
console.log('error');
|
|
|
|
|
|
|
|
console.log(info);
|
|
|
|
|
|
|
|
if (info && info.type === "store") {
|
|
|
|
|
|
|
|
//onConnectError();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sframeChan.on('Q_ANON_RPC_MESSAGE', function (data, cb) {
|
|
|
|
|
|
|
|
Cryptpad.anonRpcMsg(data.msg, data.content, function (err, response) {
|
|
|
|
|
|
|
|
cb({error: err, response: response});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Cryptpad.onDisplayNameChanged(updateMeta);
|
|
|
|
|
|
|
|
sframeChan.onReg('EV_METADATA_UPDATE', updateMeta);
|
|
|
|
|
|
|
|
|
|
|
|
sframeChan.on('Q_SET_PAD_TITLE_IN_DRIVE', function (newTitle, cb) {
|
|
|
|
Cryptpad.onError(function (info) {
|
|
|
|
Cryptpad.renamePad(newTitle, undefined, function (err) {
|
|
|
|
console.log('error');
|
|
|
|
if (err) { cb('ERROR'); } else { cb(); }
|
|
|
|
console.log(info);
|
|
|
|
});
|
|
|
|
if (info && info.type === "store") {
|
|
|
|
});
|
|
|
|
//onConnectError();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
sframeChan.on('Q_SETTINGS_SET_DISPLAY_NAME', function (newName, cb) {
|
|
|
|
sframeChan.on('Q_ANON_RPC_MESSAGE', function (data, cb) {
|
|
|
|
Cryptpad.setAttribute('username', newName, function (err) {
|
|
|
|
Cryptpad.anonRpcMsg(data.msg, data.content, function (err, response) {
|
|
|
|
if (err) {
|
|
|
|
cb({error: err, response: response});
|
|
|
|
console.log("Couldn't set username");
|
|
|
|
|
|
|
|
console.error(err);
|
|
|
|
|
|
|
|
cb('ERROR');
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Cryptpad.changeDisplayName(newName, true);
|
|
|
|
|
|
|
|
cb();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
sframeChan.on('Q_LOGOUT', function (data, cb) {
|
|
|
|
sframeChan.on('Q_SET_PAD_TITLE_IN_DRIVE', function (newTitle, cb) {
|
|
|
|
Cryptpad.logout(cb);
|
|
|
|
Cryptpad.renamePad(newTitle, undefined, function (err) {
|
|
|
|
|
|
|
|
if (err) { cb('ERROR'); } else { cb(); }
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
sframeChan.on('Q_SET_LOGIN_REDIRECT', function (data, cb) {
|
|
|
|
sframeChan.on('Q_SETTINGS_SET_DISPLAY_NAME', function (newName, cb) {
|
|
|
|
sessionStorage.redirectTo = window.location.href;
|
|
|
|
Cryptpad.setAttribute('username', newName, function (err) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
|
|
console.log("Couldn't set username");
|
|
|
|
|
|
|
|
console.error(err);
|
|
|
|
|
|
|
|
cb('ERROR');
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Cryptpad.changeDisplayName(newName, true);
|
|
|
|
cb();
|
|
|
|
cb();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
sframeChan.on('Q_GET_PIN_LIMIT_STATUS', function (data, cb) {
|
|
|
|
sframeChan.on('Q_LOGOUT', function (data, cb) {
|
|
|
|
Cryptpad.isOverPinLimit(function (e, overLimit, limits) {
|
|
|
|
Cryptpad.logout(cb);
|
|
|
|
cb({
|
|
|
|
});
|
|
|
|
error: e,
|
|
|
|
|
|
|
|
overLimit: overLimit,
|
|
|
|
|
|
|
|
limits: limits
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sframeChan.on('Q_MOVE_TO_TRASH', function (data, cb) {
|
|
|
|
sframeChan.on('Q_SET_LOGIN_REDIRECT', function (data, cb) {
|
|
|
|
Cryptpad.moveToTrash(cb);
|
|
|
|
sessionStorage.redirectTo = window.location.href;
|
|
|
|
});
|
|
|
|
cb();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
sframeChan.on('Q_SAVE_AS_TEMPLATE', function (data, cb) {
|
|
|
|
sframeChan.on('Q_GET_PIN_LIMIT_STATUS', function (data, cb) {
|
|
|
|
Cryptpad.saveAsTemplate(Cryptget.put, data, cb);
|
|
|
|
Cryptpad.isOverPinLimit(function (e, overLimit, limits) {
|
|
|
|
|
|
|
|
cb({
|
|
|
|
|
|
|
|
error: e,
|
|
|
|
|
|
|
|
overLimit: overLimit,
|
|
|
|
|
|
|
|
limits: limits
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
sframeChan.on('Q_GET_FULL_HISTORY', function (data, cb) {
|
|
|
|
sframeChan.on('Q_MOVE_TO_TRASH', function (data, cb) {
|
|
|
|
var network = Cryptpad.getNetwork();
|
|
|
|
Cryptpad.moveToTrash(cb);
|
|
|
|
var hkn = network.historyKeeper;
|
|
|
|
});
|
|
|
|
var crypto = Crypto.createEncryptor(secret.keys);
|
|
|
|
|
|
|
|
// Get the history messages and send them to the iframe
|
|
|
|
|
|
|
|
var parse = function (msg) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
return JSON.parse(msg);
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
var onMsg = function (msg) {
|
|
|
|
|
|
|
|
var parsed = parse(msg);
|
|
|
|
|
|
|
|
if (parsed[0] === 'FULL_HISTORY_END') {
|
|
|
|
|
|
|
|
console.log('END');
|
|
|
|
|
|
|
|
cb();
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parsed[0] !== 'FULL_HISTORY') { return; }
|
|
|
|
|
|
|
|
if (parsed[1] && parsed[1].validateKey) { // First message
|
|
|
|
|
|
|
|
secret.keys.validateKey = parsed[1].validateKey;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
msg = parsed[1][4];
|
|
|
|
|
|
|
|
if (msg) {
|
|
|
|
|
|
|
|
msg = msg.replace(/^cp\|/, '');
|
|
|
|
|
|
|
|
var decryptedMsg = crypto.decrypt(msg, secret.keys.validateKey);
|
|
|
|
|
|
|
|
sframeChan.event('EV_RT_HIST_MESSAGE', decryptedMsg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
network.on('message', onMsg);
|
|
|
|
|
|
|
|
network.sendto(hkn, JSON.stringify(['GET_FULL_HISTORY', secret.channel, secret.keys.validateKey]));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CpNfOuter.start({
|
|
|
|
sframeChan.on('Q_SAVE_AS_TEMPLATE', function (data, cb) {
|
|
|
|
sframeChan: sframeChan,
|
|
|
|
Cryptpad.saveAsTemplate(Cryptget.put, data, cb);
|
|
|
|
channel: secret.channel,
|
|
|
|
});
|
|
|
|
network: Cryptpad.getNetwork(),
|
|
|
|
|
|
|
|
validateKey: secret.keys.validateKey || undefined,
|
|
|
|
sframeChan.on('Q_GET_FULL_HISTORY', function (data, cb) {
|
|
|
|
readOnly: readOnly,
|
|
|
|
var network = Cryptpad.getNetwork();
|
|
|
|
crypto: Crypto.createEncryptor(secret.keys),
|
|
|
|
var hkn = network.historyKeeper;
|
|
|
|
onConnect: function (wc) {
|
|
|
|
var crypto = Crypto.createEncryptor(secret.keys);
|
|
|
|
if (readOnly) { return; }
|
|
|
|
// Get the history messages and send them to the iframe
|
|
|
|
Cryptpad.replaceHash(Cryptpad.getEditHashFromKeys(wc.id, secret.keys));
|
|
|
|
var parse = function (msg) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
return JSON.parse(msg);
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var onMsg = function (msg) {
|
|
|
|
|
|
|
|
var parsed = parse(msg);
|
|
|
|
|
|
|
|
if (parsed[0] === 'FULL_HISTORY_END') {
|
|
|
|
|
|
|
|
console.log('END');
|
|
|
|
|
|
|
|
cb();
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parsed[0] !== 'FULL_HISTORY') { return; }
|
|
|
|
|
|
|
|
if (parsed[1] && parsed[1].validateKey) { // First message
|
|
|
|
|
|
|
|
secret.keys.validateKey = parsed[1].validateKey;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
msg = parsed[1][4];
|
|
|
|
|
|
|
|
if (msg) {
|
|
|
|
|
|
|
|
msg = msg.replace(/^cp\|/, '');
|
|
|
|
|
|
|
|
var decryptedMsg = crypto.decrypt(msg, secret.keys.validateKey);
|
|
|
|
|
|
|
|
sframeChan.event('EV_RT_HIST_MESSAGE', decryptedMsg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
network.on('message', onMsg);
|
|
|
|
|
|
|
|
network.sendto(hkn, JSON.stringify(['GET_FULL_HISTORY', secret.channel, secret.keys.validateKey]));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CpNfOuter.start({
|
|
|
|
|
|
|
|
sframeChan: sframeChan,
|
|
|
|
|
|
|
|
channel: secret.channel,
|
|
|
|
|
|
|
|
network: Cryptpad.getNetwork(),
|
|
|
|
|
|
|
|
validateKey: secret.keys.validateKey || undefined,
|
|
|
|
|
|
|
|
readOnly: readOnly,
|
|
|
|
|
|
|
|
crypto: Crypto.createEncryptor(secret.keys),
|
|
|
|
|
|
|
|
onConnect: function (wc) {
|
|
|
|
|
|
|
|
if (readOnly) { return; }
|
|
|
|
|
|
|
|
Cryptpad.replaceHash(Cryptpad.getEditHashFromKeys(wc.id, secret.keys));
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|