Fix read-only spreadsheets

pull/1/head
yflory 6 years ago
parent 905bbef823
commit 59d5723f3e

@ -102,9 +102,12 @@ define([
Cryptpad.onlyoffice.onEvent.reg(function (obj) { Cryptpad.onlyoffice.onEvent.reg(function (obj) {
if (obj.ev === 'MESSAGE' && !/^cp\|/.test(obj.data)) { if (obj.ev === 'MESSAGE' && !/^cp\|/.test(obj.data)) {
try { try {
var validateKey = obj.data.validateKey || true;
var skipCheck = validateKey === true;
var msg = obj.data.msg;
obj.data = { obj.data = {
msg: JSON.parse(Utils.crypto.decrypt(obj.data, Utils.secret.keys.validateKey)), msg: JSON.parse(Utils.crypto.decrypt(msg, validateKey, skipCheck)),
hash: obj.data.slice(0,64) hash: msg.slice(0,64)
}; };
} catch (e) { } catch (e) {
console.error(e); console.error(e);

@ -26,7 +26,10 @@ define([
if (!c.id) { c.id = chan.wc.myID + '-' + client; } if (!c.id) { c.id = chan.wc.myID + '-' + client; }
chan.history.forEach(function (msg) { chan.history.forEach(function (msg) {
ctx.emit('MESSAGE', msg, [client]); ctx.emit('MESSAGE', {
msg: msg,
validateKey: chan.validateKey
}, [client]);
}); });
// ==> And push the new tab to the list // ==> And push the new tab to the list
@ -37,7 +40,8 @@ define([
var onOpen = function (wc) { var onOpen = function (wc) {
ctx.channels[channel] = ctx.channels[channel] || { ctx.channels[channel] = ctx.channels[channel] || {
history: [] history: [],
validateKey: obj.validateKey
}; };
chan = ctx.channels[channel]; chan = ctx.channels[channel];
@ -61,7 +65,10 @@ define([
}); });
wc.on('message', function (msg) { wc.on('message', function (msg) {
chan.history.push(msg); chan.history.push(msg);
ctx.emit('MESSAGE', msg, chan.clients); ctx.emit('MESSAGE', {
msg: msg,
validateKey: chan.validateKey
}, chan.clients);
}); });
chan.wc = wc; chan.wc = wc;
@ -101,6 +108,7 @@ define([
}; };
network.on('message', function (msg, sender) { network.on('message', function (msg, sender) {
if (!ctx.channels[channel]) { return; }
var hk = network.historyKeeper; var hk = network.historyKeeper;
if (sender !== hk) { return; } if (sender !== hk) { return; }
@ -115,7 +123,12 @@ define([
// Keep only metadata messages for the current channel // Keep only metadata messages for the current channel
if (parsed.channel && parsed.channel !== channel) { return; } if (parsed.channel && parsed.channel !== channel) { return; }
// Ignore the metadata message // Ignore the metadata message
if (parsed.validateKey && parsed.channel) { return; } if (parsed.validateKey && parsed.channel) {
if (!chan.validateKey) {
chan.validateKey = parsed.validateKey;
}
return;
}
// End of history: emit READY // End of history: emit READY
if (parsed.state && parsed.state === 1 && parsed.channel) { if (parsed.state && parsed.state === 1 && parsed.channel) {
ctx.emit('READY', '', chan.clients); ctx.emit('READY', '', chan.clients);
@ -132,7 +145,9 @@ define([
if (hash === chan.lastKnownHash || hash === chan.lastCpHash) { return; } if (hash === chan.lastKnownHash || hash === chan.lastCpHash) { return; }
chan.lastKnownHash = hash; chan.lastKnownHash = hash;
ctx.emit('MESSAGE', msg, chan.clients); ctx.emit('MESSAGE', {
msg: msg,
}, chan.clients);
chan.history.push(msg); chan.history.push(msg);
}); });
@ -176,7 +191,9 @@ define([
return void chan.sendMsg(data.isCp, cb); return void chan.sendMsg(data.isCp, cb);
} }
chan.sendMsg(data.msg, cb); chan.sendMsg(data.msg, cb);
ctx.emit('MESSAGE', data.msg, chan.clients.filter(function (cl) { ctx.emit('MESSAGE', {
msg: data.msg
}, chan.clients.filter(function (cl) {
return cl !== clientId; return cl !== clientId;
})); }));
}; };

Loading…
Cancel
Save