Password-protected shared folders

pull/1/head
yflory 6 years ago
parent e6379dacd8
commit bf55657993

@ -156,7 +156,7 @@ define([
} }
var parsed = Hash.parsePadUrl(data.href || data.roHref); var parsed = Hash.parsePadUrl(data.href || data.roHref);
if (owned && parsed.hashData.type === 'pad') { if (!data.noEditPassword && owned && parsed.hashData.type === 'pad') {
var sframeChan = common.getSframeChannel(); var sframeChan = common.getSframeChannel();
var changePwTitle = Messages.properties_changePassword; var changePwTitle = Messages.properties_changePassword;
var changePwConfirm = Messages.properties_confirmChange; var changePwConfirm = Messages.properties_confirmChange;

@ -128,6 +128,7 @@ define([
href: '/drive/#' + Hash.getEditHashFromKeys(secret), href: '/drive/#' + Hash.getEditHashFromKeys(secret),
roHref: '/drive/#' + Hash.getViewHashFromKeys(secret), roHref: '/drive/#' + Hash.getViewHashFromKeys(secret),
channel: secret.channel, channel: secret.channel,
password: secret.password,
ctime: +new Date() ctime: +new Date()
} }
}, cb); }, cb);

@ -386,14 +386,14 @@ define([
if (data.folderData) { return; } if (data.folderData) { return; }
// Folder creation // Folder creation
var hash = Hash.createRandomHash('drive'); var hash = Hash.createRandomHash('drive', data.password);
var href = '/drive/#' + hash; var secret = Hash.getSecrets('drive', hash, data.password);
var secret = Hash.getSecrets('drive', hash); var hashes = Hash.getHashes(secret);
folderData = { folderData = {
href: href, href: '/drive/#' + hashes.editHash,
roHref: '/drive/#' + Hash.getViewHashFromKeys(secret), roHref: '/drive/#' + hashes.viewHash,
channel: secret.channel, channel: secret.channel,
ctime: +new Date() ctime: +new Date(),
}; };
if (data.password) { folderData.password = data.password; } if (data.password) { folderData.password = data.password; }
if (data.owned) { folderData.owners = [Env.edPublic]; } if (data.owned) { folderData.owners = [Env.edPublic]; }
@ -541,6 +541,11 @@ define([
// Set the value everywhere the given pad is stored (main and shared folders) // Set the value everywhere the given pad is stored (main and shared folders)
var setPadAttribute = function (Env, data, cb) { var setPadAttribute = function (Env, data, cb) {
cb = cb || function () {}; cb = cb || function () {};
if (!data.attr || !data.attr.trim()) { return void cb("E_INVAL_ATTR"); }
var sfId = Env.user.userObject.getSFIdFromHref(data.href);
if (sfId) {
Env.user.proxy[UserObject.SHARED_FOLDERS][sfId][data.attr] = data.value;
}
var datas = findHref(Env, data.href); var datas = findHref(Env, data.href);
var nt = nThen; var nt = nThen;
datas.forEach(function (d) { datas.forEach(function (d) {
@ -557,6 +562,10 @@ define([
// correct one. // correct one.
var getPadAttribute = function (Env, data, cb) { var getPadAttribute = function (Env, data, cb) {
cb = cb || function () {}; cb = cb || function () {};
var sfId = Env.user.userObject.getSFIdFromHref(data.href);
if (sfId) {
return void cb(null, Env.user.proxy[UserObject.SHARED_FOLDERS][sfId][data.attr]);
}
var datas = findHref(Env, data.href); var datas = findHref(Env, data.href);
var nt = nThen; var nt = nThen;
var res = {}; var res = {};

@ -204,6 +204,10 @@ define([
// If no password, continue... // If no password, continue...
todo(); todo();
} }
}).nThen(function (waitFor) {
if (cfg.afterSecrets) {
cfg.afterSecrets(Cryptpad, Utils, secret, waitFor());
}
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
// Check if the pad exists on server // Check if the pad exists on server
if (!window.location.hash) { isNewFile = true; return; } if (!window.location.hash) { isNewFile = true; return; }

@ -320,6 +320,18 @@ define([
return result; return result;
}; };
exp.getSFIdFromHref = function (href) {
var result;
getFiles([SHARED_FOLDERS]).some(function (id) {
if (files[SHARED_FOLDERS][id].href === href ||
files[SHARED_FOLDERS][id].roHref === href) {
result = id;
return true;
}
});
return result;
};
// SEARCH // SEARCH
var _findFileInRoot = function (path, file) { var _findFileInRoot = function (path, file) {
if (!isPathIn(path, [ROOT, TRASH])) { return []; } if (!isPathIn(path, [ROOT, TRASH])) { return []; }

@ -1763,8 +1763,8 @@ define([
h('h4', Messages.sharedFolders_create), h('h4', Messages.sharedFolders_create),
h('label', {for: 'cp-app-drive-sf-name'}, Messages.sharedFolders_create_name), h('label', {for: 'cp-app-drive-sf-name'}, Messages.sharedFolders_create_name),
h('input#cp-app-drive-sf-name', {type: 'text', placeholder: Messages.fm_newFolder}), h('input#cp-app-drive-sf-name', {type: 'text', placeholder: Messages.fm_newFolder}),
//h('label', {for: 'cp-app-drive-sf-password'}, Messages.sharedFolders_create_password), h('label', {for: 'cp-app-drive-sf-password'}, Messages.sharedFolders_create_password),
//UI.passwordInput({id: 'cp-app-drive-sf-password'}), UI.passwordInput({id: 'cp-app-drive-sf-password'}),
h('span', { h('span', {
style: 'display:flex;align-items:center;justify-content:space-between' style: 'display:flex;align-items:center;justify-content:space-between'
}, [ }, [
@ -1784,8 +1784,7 @@ define([
// Get the values // Get the values
var newName = $(content).find('#cp-app-drive-sf-name').val(); var newName = $(content).find('#cp-app-drive-sf-name').val();
//var password = $(content).find('#cp-app-drive-sf-password').val() || undefined; var password = $(content).find('#cp-app-drive-sf-password').val() || undefined;
var password;
var owned = $(content).find('#cp-app-drive-sf-owned').is(':checked'); var owned = $(content).find('#cp-app-drive-sf-owned').is(':checked');
cb({ cb({
@ -3067,7 +3066,8 @@ define([
if (manager.isSharedFolder(el)) { if (manager.isSharedFolder(el)) {
delete data.roHref; delete data.roHref;
data.noPassword = true; //data.noPassword = true;
data.noEditPassword = true;
data.noExpiration = true; data.noExpiration = true;
} }

@ -36,21 +36,13 @@ define([
}; };
window.addEventListener('message', onMsg); window.addEventListener('message', onMsg);
}).nThen(function (/*waitFor*/) { }).nThen(function (/*waitFor*/) {
var getSecrets = function (Cryptpad, Utils, cb) { var afterSecrets = function (Cryptpad, Utils, secret, cb) {
var hash = window.location.hash.slice(1); var hash = window.location.hash.slice(1);
var secret = Utils.Hash.getSecrets('drive', hash);
if (hash && Utils.LocalStore.isLoggedIn()) { if (hash && Utils.LocalStore.isLoggedIn()) {
// Add a shared folder! // Add a shared folder!
// TODO password?
Cryptpad.addSharedFolder(secret, function (id) { Cryptpad.addSharedFolder(secret, function (id) {
window.CryptPad_newSharedFolder = id; window.CryptPad_newSharedFolder = id;
// Update the hash in the address bar cb();
var ohc = window.onhashchange;
window.onhashchange = function () {};
window.location.hash = "";
window.onhashchange = ohc;
ohc({reset:true});
cb(null, secret);
}); });
return; return;
} else if (hash) { } else if (hash) {
@ -58,14 +50,11 @@ define([
window.CryptPad_newSharedFolder = id; window.CryptPad_newSharedFolder = id;
var data = { var data = {
href: Utils.Hash.getRelativeHref(window.location.href), href: Utils.Hash.getRelativeHref(window.location.href),
password: secret.password
}; };
Cryptpad.loadSharedFolder(id, data, function () { return void Cryptpad.loadSharedFolder(id, data, cb);
cb(null, secret);
});
return;
} }
// No password for drive cb();
cb(null, secret);
}; };
var addRpc = function (sframeChan, Cryptpad, Utils) { var addRpc = function (sframeChan, Cryptpad, Utils) {
sframeChan.on('EV_BURN_ANON_DRIVE', function () { sframeChan.on('EV_BURN_ANON_DRIVE', function () {
@ -123,7 +112,7 @@ define([
}); });
}; };
SFCommonO.start({ SFCommonO.start({
getSecrets: getSecrets, afterSecrets: afterSecrets,
noHash: true, noHash: true,
noRealtime: true, noRealtime: true,
driveEvents: true, driveEvents: true,

Loading…
Cancel
Save