Warn the owners when deleting a BAR pad

pull/1/head
yflory 5 years ago
parent bdd338902b
commit 09da8ac6a2

@ -1653,6 +1653,45 @@ define([
}; };
// Delete a pad received with a burn after reading URL // Delete a pad received with a burn after reading URL
var notifyOwnerPadRemoved = function (data, obj) {
var channel = data.channel;
var href = data.href;
var parsed = Hash.parsePadUrl(href);
var secret = Hash.getSecrets(parsed.type, parsed.hash, data.password);
if (obj && obj.error) { return; }
if (!obj.mailbox) { return; }
// Decrypt the mailbox
var crypto = Crypto.createEncryptor(secret.keys);
var m = [];
try {
if (typeof (obj.mailbox) === "string") {
m.push(crypto.decrypt(obj.mailbox, true, true));
} else {
Object.keys(obj.mailbox).forEach(function (k) {
m.push(crypto.decrypt(obj.mailbox[k], true, true));
});
}
} catch (e) {
console.error(e);
}
// Tell all the owners that the pad was deleted from the server
var curvePublic = store.proxy.curvePublic;
var myData = Messaging.createData(store.proxy, false);
m.forEach(function (obj) {
var mb = JSON.parse(obj);
if (mb.curvePublic === curvePublic) { return; }
store.mailbox.sendTo('OWNED_PAD_REMOVED', {
channel: channel,
user: myData
}, {
channel: mb.notifications,
curvePublic: mb.curvePublic
}, function () {});
});
};
Store.burnPad = function (clientId, data) { Store.burnPad = function (clientId, data) {
var channel = data.channel; var channel = data.channel;
var ownerKey = Crypto.b64AddSlashes(data.ownerKey || ''); var ownerKey = Crypto.b64AddSlashes(data.ownerKey || '');
@ -1665,8 +1704,14 @@ define([
edPrivate: Hash.encodeBase64(pair.secretKey) edPrivate: Hash.encodeBase64(pair.secretKey)
}, function (e, rpc) { }, function (e, rpc) {
if (e) { return void console.error(e); } if (e) { return void console.error(e); }
rpc.removeOwnedChannel(channel, function (err) { Store.getPadMetadata(null, {
if (err) { console.error(err); } channel: channel
}, function (md) {
rpc.removeOwnedChannel(channel, function (err) {
if (err) { return void console.error(err); }
// Notify owners that the pad was removed
notifyOwnerPadRemoved(data, md);
});
}); });
}); });
} catch (e) { } catch (e) {

@ -1240,6 +1240,8 @@ define([
if (burnAfterReading) { if (burnAfterReading) {
Cryptpad.padRpc.onReadyEvent.reg(function () { Cryptpad.padRpc.onReadyEvent.reg(function () {
Cryptpad.burnPad({ Cryptpad.burnPad({
password: password,
href: window.location.href,
channel: secret.channel, channel: secret.channel,
ownerKey: burnAfterReading ownerKey: burnAfterReading
}); });

Loading…
Cancel
Save