PCS with owners and password for spreadsheets

pull/1/head
yflory 6 years ago
parent a0049b360a
commit 412670c8a6

@ -1992,7 +1992,7 @@ define([
$expire.find('#cp-creation-expire-false').attr('checked', true); $expire.find('#cp-creation-expire-false').attr('checked', true);
} }
}; };
UIElements.getPadCreationScreen = function (common, cfg, cb) { UIElements.getPadCreationScreen = function (common, cfg, appCfg, cb) {
if (!common.isLoggedIn()) { return void cb(); } if (!common.isLoggedIn()) { return void cb(); }
var sframeChan = common.getSframeChannel(); var sframeChan = common.getSframeChannel();
var metadataMgr = common.getMetadataMgr(); var metadataMgr = common.getMetadataMgr();
@ -2119,12 +2119,14 @@ define([
} }
return b.used - a.used; return b.used - a.used;
}); });
allData.unshift({ if (!appCfg.noTemplates) {
name: Messages.creation_newTemplate, allData.unshift({
id: -1, name: Messages.creation_newTemplate,
//icon: h('span.fa.fa-bookmark') id: -1,
icon: h('span.cptools.cptools-new-template') //icon: h('span.fa.fa-bookmark')
}); icon: h('span.cptools.cptools-new-template')
});
}
allData.unshift({ allData.unshift({
name: Messages.creation_noTemplate, name: Messages.creation_noTemplate,
id: 0, id: 0,

@ -870,10 +870,12 @@ define([
var $rightside = toolbar.$rightside; var $rightside = toolbar.$rightside;
/*var $save = common.createButton('save', true, {}, function () { if (window.CP_DEV_MODE) {
saveToServer(); var $save = common.createButton('save', true, {}, function () {
}); saveToServer();
$save.appendTo($rightside);*/ });
$save.appendTo($rightside);
}
var $export = common.createButton('export', true, {}, exportFile); var $export = common.createButton('export', true, {}, exportFile);
$export.appendTo($rightside); $export.appendTo($rightside);
@ -940,6 +942,12 @@ define([
}); });
}; };
config.onError = function (err) {
common.onServerError(err, toolbar, function () {
setEditable(false);
});
};
config.onRemote = function () { config.onRemote = function () {
if (initializing) { return; } if (initializing) { return; }
var userDoc = APP.realtime.getUserDoc(); var userDoc = APP.realtime.getUserDoc();
@ -1013,6 +1021,10 @@ define([
UI.addLoadingScreen(); UI.addLoadingScreen();
})); }));
SFCommon.create(waitFor(function (c) { APP.common = common = c; })); SFCommon.create(waitFor(function (c) { APP.common = common = c; }));
}).nThen(function (waitFor) {
common.handleNewFile(waitFor, {
noTemplates: true
});
}).nThen(function (/*waitFor*/) { }).nThen(function (/*waitFor*/) {
andThen(common); andThen(common);
}); });

@ -40,8 +40,6 @@ define([
obj.ooType = window.location.pathname.replace(/^\//, '').replace(/\/$/, ''); obj.ooType = window.location.pathname.replace(/^\//, '').replace(/\/$/, '');
}; };
var addRpc = function (sframeChan, Cryptpad, Utils) { var addRpc = function (sframeChan, Cryptpad, Utils) {
var crypto = Utils.Crypto.createEncryptor(Utils.secret.keys);
sframeChan.on('Q_OO_SAVE', function (data, cb) { sframeChan.on('Q_OO_SAVE', function (data, cb) {
var chanId = Utils.Hash.hrefToHexChannelId(data.url); var chanId = Utils.Hash.hrefToHexChannelId(data.url);
Cryptpad.getPadAttribute('lastVersion', function (err, data) { Cryptpad.getPadAttribute('lastVersion', function (err, data) {
@ -63,21 +61,36 @@ define([
Cryptpad.setPadAttribute('rtChannel', data.channel, function () {}); Cryptpad.setPadAttribute('rtChannel', data.channel, function () {});
}); });
}); });
Cryptpad.onlyoffice.execCommand({ var owners, expire;
cmd: 'OPEN_CHANNEL', nThen(function (waitFor) {
data: { if (Utils.rtConfig) {
// XXX add owners? owners = Utils.rtConfig.owners;
// owners: something... expire = Utils.rtConfig.expire;
channel: data.channel, return;
lastCpHash: data.lastCpHash,
padChan: Utils.secret.channel,
validateKey: Utils.secret.keys.validateKey
} }
}, cb); Cryptpad.getPadAttribute('owners', waitFor(function (err, res) {
owners = res;
}));
Cryptpad.getPadAttribute('expire', waitFor(function (err, res) {
expire = res;
}));
}).nThen(function () {
Cryptpad.onlyoffice.execCommand({
cmd: 'OPEN_CHANNEL',
data: {
owners: owners,
expire: expire,
channel: data.channel,
lastCpHash: data.lastCpHash,
padChan: Utils.secret.channel,
validateKey: Utils.secret.keys.validateKey
}
}, cb);
});
}); });
sframeChan.on('Q_OO_COMMAND', function (obj, cb) { sframeChan.on('Q_OO_COMMAND', function (obj, cb) {
if (obj.cmd === 'SEND_MESSAGE') { if (obj.cmd === 'SEND_MESSAGE') {
obj.data.msg = crypto.encrypt(JSON.stringify(obj.data.msg)); obj.data.msg = Utils.crypto.encrypt(JSON.stringify(obj.data.msg));
var hash = obj.data.msg.slice(0,64); var hash = obj.data.msg.slice(0,64);
var _cb = cb; var _cb = cb;
cb = function () { cb = function () {
@ -90,7 +103,7 @@ define([
if (obj.ev === 'MESSAGE' && !/^cp\|/.test(obj.data)) { if (obj.ev === 'MESSAGE' && !/^cp\|/.test(obj.data)) {
try { try {
obj.data = { obj.data = {
msg: JSON.parse(crypto.decrypt(obj.data, Utils.secret.keys.validateKey)), msg: JSON.parse(Utils.crypto.decrypt(obj.data, Utils.secret.keys.validateKey)),
hash: obj.data.slice(0,64) hash: obj.data.slice(0,64)
}; };
} catch (e) { } catch (e) {
@ -102,6 +115,7 @@ define([
}; };
SFCommonO.start({ SFCommonO.start({
type: 'oo', type: 'oo',
useCreationScreen: true,
addData: addData, addData: addData,
addRpc: addRpc, addRpc: addRpc,
messaging: true messaging: true

@ -87,6 +87,7 @@ define([
validateKey: obj.validateKey, validateKey: obj.validateKey,
lastKnownHash: chan.lastKnownHash || chan.lastCpHash, lastKnownHash: chan.lastKnownHash || chan.lastCpHash,
owners: obj.owners, owners: obj.owners,
expire: obj.expire
}; };
var msg = ['GET_HISTORY', wc.id, cfg]; var msg = ['GET_HISTORY', wc.id, cfg];
// Add the validateKey if we are the channel creator and we have a validateKey // Add the validateKey if we are the channel creator and we have a validateKey

@ -107,8 +107,14 @@ define([
Feedback.send('ERROR_DELETING_OWNED_PAD=' + channelId + '|' + obj.error, true); Feedback.send('ERROR_DELETING_OWNED_PAD=' + channelId + '|' + obj.error, true);
} }
}); });
// Also remove the realtime channel for onlyoffice
if (fd.rtChannel) {
removeOwnedChannel(fd.rtChannel, function () {});
}
// XXX fd.lastVersion to delete the encrypted cp?
} }
if (fd.lastVersion) { toClean.push(Hash.hrefToHexChannelId(fd.lastVersion)); } if (fd.lastVersion) { toClean.push(Hash.hrefToHexChannelId(fd.lastVersion)); }
if (fd.rtChannel) { toClean.push(fd.rtChannel); }
if (channelId) { toClean.push(channelId); } if (channelId) { toClean.push(channelId); }
if (exp.isSharedFolder(id)) { if (exp.isSharedFolder(id)) {
delete files[SHARED_FOLDERS][id]; delete files[SHARED_FOLDERS][id];

@ -490,13 +490,13 @@ define([
}); });
} }
uo.delete(resolved.main, waitFor(function (err, _toUnpin, _ownedRemoved) { uo.delete(resolved.main, waitFor(function (err, _toUnpin, _ownedRemoved) {
ownedRemoved = _ownedRemoved;
if (!Env.unpinPads || !_toUnpin) { return; } if (!Env.unpinPads || !_toUnpin) { return; }
Array.prototype.push.apply(toUnpin, _toUnpin); Array.prototype.push.apply(toUnpin, _toUnpin);
ownedRemoved = _ownedRemoved;
})); }));
} }
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
// Check if removed owned pads are duplicated is some shared folders // Check if removed owned pads are duplicated in some shared folders
// If that's the case, we have to remove them from the shared folders too // If that's the case, we have to remove them from the shared folders too
// We can do that by adding their paths to the list of pads to remove from shared folders // We can do that by adding their paths to the list of pads to remove from shared folders
if (ownedRemoved) { if (ownedRemoved) {
@ -526,8 +526,13 @@ define([
// Deleted channels // Deleted channels
toUnpin = Util.deduplicateString(toUnpin); toUnpin = Util.deduplicateString(toUnpin);
// Deleted channels that are still in another proxy // Deleted channels that are still in another proxy
var toKeep = _findChannels(Env, toUnpin).map(function (id) { var toKeep = [];
return _getFileData(Env, id).channel; _findChannels(Env, toUnpin).forEach(function (id) {
var data = _getFileData(Env, id);
var arr = [data.channel];
if (data.rtChannel) { arr.push(data.rtChannel); }
if (data.lastVersion) { arr.push(Hash.hrefToHexChannelId(data.lastVersion)); }
Array.prototype.push.apply(toKeep, arr);
}); });
// Compute the unpin list and unpin // Compute the unpin list and unpin
var unpinList = []; var unpinList = [];
@ -715,6 +720,9 @@ define([
result.push(otherChan); result.push(otherChan);
} }
} }
if (data.rtChannel && result.indexOf(data.rtChannel) === -1) {
result.push(data.rtChannel);
}
if (result.indexOf(data.channel) === -1) { if (result.indexOf(data.channel) === -1) {
result.push(data.channel); result.push(data.channel);
} }

@ -255,6 +255,7 @@ define([
secret.keys = secret.key; secret.keys = secret.key;
readOnly = false; readOnly = false;
} }
Utils.crypto = Utils.Crypto.createEncryptor(Utils.secret.keys);
var parsed = Utils.Hash.parsePadUrl(window.location.href); var parsed = Utils.Hash.parsePadUrl(window.location.href);
if (!parsed.type) { throw new Error(); } if (!parsed.type) { throw new Error(); }
var defaultTitle = Utils.Hash.getDefaultName(parsed); var defaultTitle = Utils.Hash.getDefaultName(parsed);
@ -953,6 +954,7 @@ define([
password = data.password; password = data.password;
var newHash = Utils.Hash.createRandomHash(parsed.type, password); var newHash = Utils.Hash.createRandomHash(parsed.type, password);
secret = Utils.secret = Utils.Hash.getSecrets(parsed.type, newHash, password); secret = Utils.secret = Utils.Hash.getSecrets(parsed.type, newHash, password);
Utils.crypto = Utils.Crypto.createEncryptor(Utils.secret.keys);
// Update the hash in the address bar // Update the hash in the address bar
var ohc = window.onhashchange; var ohc = window.onhashchange;
@ -975,6 +977,7 @@ define([
if (data.expire) { if (data.expire) {
rtConfig.expire = data.expire; rtConfig.expire = data.expire;
} }
Utils.rtConfig = rtConfig;
nThen(function(waitFor) { nThen(function(waitFor) {
if (data.templateId) { if (data.templateId) {
if (data.templateId === -1) { if (data.templateId === -1) {

@ -241,7 +241,7 @@ define([
}; };
// Store // Store
funcs.handleNewFile = function (waitFor) { funcs.handleNewFile = function (waitFor, config) {
if (window.__CRYPTPAD_TEST__) { return; } if (window.__CRYPTPAD_TEST__) { return; }
var priv = ctx.metadataMgr.getPrivateData(); var priv = ctx.metadataMgr.getPrivateData();
if (priv.isNewFile) { if (priv.isNewFile) {
@ -262,7 +262,7 @@ define([
return void funcs.createPad(c, waitFor()); return void funcs.createPad(c, waitFor());
} }
// If we display the pad creation screen, it will handle deleted pads directly // If we display the pad creation screen, it will handle deleted pads directly
funcs.getPadCreationScreen(c, waitFor()); funcs.getPadCreationScreen(c, config, waitFor());
} }
}; };
funcs.createPad = function (cfg, cb) { funcs.createPad = function (cfg, cb) {

Loading…
Cancel
Save