|
|
|
@ -78,7 +78,7 @@ define([
|
|
|
|
|
};
|
|
|
|
|
var AppConfig;
|
|
|
|
|
var Test;
|
|
|
|
|
var password, newPadPassword;
|
|
|
|
|
var password, newPadPassword, newPadPasswordForce;
|
|
|
|
|
var initialPathInDrive;
|
|
|
|
|
var burnAfterReading;
|
|
|
|
|
|
|
|
|
@ -312,6 +312,7 @@ define([
|
|
|
|
|
newPadPassword = Crypto.decrypt(newPad.pw, uKey);
|
|
|
|
|
} catch (e) { console.error(e); }
|
|
|
|
|
}
|
|
|
|
|
if (newPad.f) { newPadPasswordForce = 1; }
|
|
|
|
|
if (newPad.d) {
|
|
|
|
|
Cryptpad.fromFileData = newPad.d;
|
|
|
|
|
var _parsed1 = Utils.Hash.parsePadUrl(Cryptpad.fromFileData.href);
|
|
|
|
@ -319,6 +320,7 @@ define([
|
|
|
|
|
delete Cryptpad.fromFileData;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e, parsed.hashData.newPadOpts);
|
|
|
|
|
}
|
|
|
|
@ -349,7 +351,7 @@ define([
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We now need to check if there is a password and if we know the correct password.
|
|
|
|
|
// We'll use getFileSize and isNewChannel to detect incorrect passwords.
|
|
|
|
|
// We'll use getFileSize and hasChannelHistory to detect incorrect passwords.
|
|
|
|
|
|
|
|
|
|
// First we'll get the password value from our drive (getPadAttribute), and we'll check
|
|
|
|
|
// if the channel is valid. If the pad is not stored in our drive, we'll test with an
|
|
|
|
@ -397,15 +399,15 @@ define([
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
if (parsed.type === "file") {
|
|
|
|
|
// `isNewChannel` doesn't work for files (not a channel)
|
|
|
|
|
// `hasChannelHistory` doesn't work for files (not a channel)
|
|
|
|
|
// `getFileSize` is not adapted to channels because of metadata
|
|
|
|
|
Cryptpad.getFileSize(currentPad.href, password, function (e, size) {
|
|
|
|
|
next(e, size === 0);
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Not a file, so we can use `isNewChannel`
|
|
|
|
|
Cryptpad.isNewChannel(currentPad.href, password, next);
|
|
|
|
|
// Not a file, so we can use `hasChannelHistory`
|
|
|
|
|
Cryptpad.hasChannelHistory(currentPad.href, password, next);
|
|
|
|
|
});
|
|
|
|
|
sframeChan.event("EV_PAD_PASSWORD", cfg);
|
|
|
|
|
};
|
|
|
|
@ -474,17 +476,25 @@ define([
|
|
|
|
|
password = val;
|
|
|
|
|
}), parsed.getUrl());
|
|
|
|
|
}).nThen(function (w) {
|
|
|
|
|
// If we've already tested this password and this is a redirect, force
|
|
|
|
|
if (typeof(newPadPassword) !== "undefined" && newPadPasswordForce) {
|
|
|
|
|
password = newPadPassword;
|
|
|
|
|
return void todo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the pad is not stored and we have a newPadPassword, it probably
|
|
|
|
|
// comes from a notification: password prompt pre-filled
|
|
|
|
|
if (!password && !stored && newPadPassword) {
|
|
|
|
|
passwordCfg.value = newPadPassword;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Pad not stored && password required: always ask for the password
|
|
|
|
|
if (!stored && parsed.hashData.password) {
|
|
|
|
|
if (!stored && parsed.hashData.password && !newPadPasswordForce) {
|
|
|
|
|
return void askPassword(true, passwordCfg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (parsed.type === "file") {
|
|
|
|
|
// `isNewChannel` doesn't work for files (not a channel)
|
|
|
|
|
// `hasChannelHistory` doesn't work for files (not a channel)
|
|
|
|
|
// `getFileSize` is not adapted to channels because of metadata
|
|
|
|
|
Cryptpad.getFileSize(currentPad.href, password, w(function (e, size) {
|
|
|
|
|
if (size !== 0) { return void todo(); }
|
|
|
|
@ -493,8 +503,8 @@ define([
|
|
|
|
|
}));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Not a file, so we can use `isNewChannel`
|
|
|
|
|
Cryptpad.isNewChannel(currentPad.href, password, w(function(e, isNew) {
|
|
|
|
|
// Not a file, so we can use `hasChannelHistory`
|
|
|
|
|
Cryptpad.hasChannelHistory(currentPad.href, password, w(function(e, isNew) {
|
|
|
|
|
if (isNew && expire && expire < (+new Date())) {
|
|
|
|
|
sframeChan.event("EV_EXPIRED_ERROR");
|
|
|
|
|
waitFor.abort();
|
|
|
|
@ -541,8 +551,7 @@ define([
|
|
|
|
|
|
|
|
|
|
if (realtime) {
|
|
|
|
|
// TODO we probably don't need to check again for password-protected pads
|
|
|
|
|
// (we use isNewChannel to test the password...)
|
|
|
|
|
Cryptpad.isNewChannel(currentPad.href, password, waitFor(function (e, isNew) {
|
|
|
|
|
Cryptpad.hasChannelHistory(currentPad.href, password, waitFor(function (e, isNew) {
|
|
|
|
|
if (e) { return console.error(e); }
|
|
|
|
|
isNewFile = Boolean(isNew);
|
|
|
|
|
}));
|
|
|
|
@ -608,6 +617,7 @@ define([
|
|
|
|
|
feedbackAllowed: Utils.Feedback.state,
|
|
|
|
|
isPresent: parsed.hashData && parsed.hashData.present,
|
|
|
|
|
isEmbed: parsed.hashData && parsed.hashData.embed,
|
|
|
|
|
oldVersionHash: parsed.hashData && parsed.hashData.version < 2, // password
|
|
|
|
|
isHistoryVersion: parsed.hashData && parsed.hashData.versionHash,
|
|
|
|
|
notifications: notifs,
|
|
|
|
|
accounts: {
|
|
|
|
@ -1674,6 +1684,45 @@ define([
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
sframeChan.on('Q_PASSWORD_CHECK', function (pw, cb) {
|
|
|
|
|
Cryptpad.isNewChannel(currentPad.href, pw, function (e, isNew) {
|
|
|
|
|
if (isNew === false) {
|
|
|
|
|
var channel = Hash.hrefToHexChannelId(currentPad.href, pw);
|
|
|
|
|
|
|
|
|
|
nThen(function (w) {
|
|
|
|
|
// If the pad is stored, update its data
|
|
|
|
|
var _secret = Utils.Hash.getSecrets(parsed.type, parsed.hash, pw);
|
|
|
|
|
var chan = _secret.channel;
|
|
|
|
|
var editH = Utils.Hash.getEditHashFromKeys(_secret);
|
|
|
|
|
var viewH = Utils.Hash.getViewHashFromKeys(_secret);
|
|
|
|
|
var href = Utils.Hash.hashToHref(editH, parsed.type);
|
|
|
|
|
var roHref = Utils.Hash.hashToHref(viewH, parsed.type);
|
|
|
|
|
Cryptpad.setPadAttribute('password', password, w(), parsed.getUrl());
|
|
|
|
|
Cryptpad.setPadAttribute('channel', chan, w(), parsed.getUrl());
|
|
|
|
|
Cryptpad.setPadAttribute('href', href, w(), parsed.getUrl());
|
|
|
|
|
Cryptpad.setPadAttribute('roHref', roHref, w(), parsed.getUrl());
|
|
|
|
|
}).nThen(function () {
|
|
|
|
|
// Get redirect URL
|
|
|
|
|
var uHash = Utils.LocalStore.getUserHash();
|
|
|
|
|
var uSecret = Utils.Hash.getSecrets('drive', uHash);
|
|
|
|
|
var uKey = uSecret.keys.cryptKey;
|
|
|
|
|
var url = Utils.Hash.getNewPadURL(currentPad.href, {
|
|
|
|
|
pw: Crypto.encrypt(pw, uKey),
|
|
|
|
|
f: 1
|
|
|
|
|
});
|
|
|
|
|
// redirect
|
|
|
|
|
window.location.href = url;
|
|
|
|
|
document.location.reload();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
cb({
|
|
|
|
|
error: e
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (cfg.messaging) {
|
|
|
|
|
sframeChan.on('Q_CHAT_OPENPADCHAT', function (data, cb) {
|
|
|
|
|
Cryptpad.universal.execCommand({
|
|
|
|
|