adding file name support for #20, solving issue with unencryptable file
This commit is contained in:
parent
e144739dec
commit
ed9c4f45f4
|
@ -577,24 +577,33 @@ $(function() {
|
||||||
if (!this.prettyPrint.hasClass('prettyprinted')) {
|
if (!this.prettyPrint.hasClass('prettyprinted')) {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var cleartext = filter.decipher(key, password, comments[0].data);
|
|
||||||
if (cleartext.length == 0)
|
|
||||||
{
|
|
||||||
if (password.length == 0) password = this.requestPassword();
|
|
||||||
cleartext = filter.decipher(key, password, comments[0].data);
|
|
||||||
}
|
|
||||||
if (cleartext.length == 0) throw 'failed to decipher message';
|
|
||||||
this.passwordInput.val(password);
|
|
||||||
if (comments[0].attachment)
|
if (comments[0].attachment)
|
||||||
{
|
{
|
||||||
var attachment = filter.decipher(key, password, comments[0].attachment);
|
var attachment = filter.decipher(key, password, comments[0].attachment);
|
||||||
if (attachment)
|
if (attachment.length == 0)
|
||||||
{
|
{
|
||||||
|
if (password.length == 0) password = this.requestPassword();
|
||||||
|
attachment = filter.decipher(key, password, comments[0].attachment);
|
||||||
|
}
|
||||||
|
if (attachment.length == 0) throw 'failed to decipher attachment';
|
||||||
|
|
||||||
|
if (comments[0].attachmentname)
|
||||||
|
{
|
||||||
|
var attachmentname = filter.decipher(key, password, comments[0].attachmentname);
|
||||||
|
if (attachmentname.length > 0) this.attachmentLink.attr('download', attachmentname);
|
||||||
|
}
|
||||||
this.attachmentLink.attr('href', attachment);
|
this.attachmentLink.attr('href', attachment);
|
||||||
this.attachment.removeClass('hidden');
|
this.attachment.removeClass('hidden');
|
||||||
}
|
}
|
||||||
|
var cleartext = filter.decipher(key, password, comments[0].data);
|
||||||
|
if (cleartext.length == 0 && password.length == 0)
|
||||||
|
{
|
||||||
|
password = this.requestPassword();
|
||||||
|
cleartext = filter.decipher(key, password, comments[0].data);
|
||||||
}
|
}
|
||||||
|
if (cleartext.length == 0 && !comments[0].attachment) throw 'failed to decipher message';
|
||||||
|
|
||||||
|
this.passwordInput.val(password);
|
||||||
helper.setElementText(this.clearText, cleartext);
|
helper.setElementText(this.clearText, cleartext);
|
||||||
helper.setElementText(this.prettyPrint, cleartext);
|
helper.setElementText(this.prettyPrint, cleartext);
|
||||||
this.formatPaste(comments[0].meta.formatter);
|
this.formatPaste(comments[0].meta.formatter);
|
||||||
|
@ -844,7 +853,8 @@ $(function() {
|
||||||
return function(e) {
|
return function(e) {
|
||||||
zerobin.sendDataContinue(
|
zerobin.sendDataContinue(
|
||||||
randomkey,
|
randomkey,
|
||||||
filter.cipher(randomkey, password, e.target.result)
|
filter.cipher(randomkey, password, e.target.result),
|
||||||
|
filter.cipher(randomkey, password, theFile.name)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
})(files[0]);
|
})(files[0]);
|
||||||
|
@ -854,12 +864,13 @@ $(function() {
|
||||||
{
|
{
|
||||||
this.sendDataContinue(
|
this.sendDataContinue(
|
||||||
randomkey,
|
randomkey,
|
||||||
filter.cipher(randomkey, password, this.attachmentLink.attr('href'))
|
filter.cipher(randomkey, password, this.attachmentLink.attr('href')),
|
||||||
|
this.attachmentLink.attr('download')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.sendDataContinue(randomkey, '');
|
this.sendDataContinue(randomkey, '', '');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -868,7 +879,7 @@ $(function() {
|
||||||
*
|
*
|
||||||
* @param Event event
|
* @param Event event
|
||||||
*/
|
*/
|
||||||
sendDataContinue: function(randomkey, cipherdata_attachment)
|
sendDataContinue: function(randomkey, cipherdata_attachment, cipherdata_attachment_name)
|
||||||
{
|
{
|
||||||
var cipherdata = filter.cipher(randomkey, this.passwordInput.val(), this.message.val());
|
var cipherdata = filter.cipher(randomkey, this.passwordInput.val(), this.message.val());
|
||||||
var data_to_send = {
|
var data_to_send = {
|
||||||
|
@ -881,6 +892,10 @@ $(function() {
|
||||||
if (cipherdata_attachment.length > 0)
|
if (cipherdata_attachment.length > 0)
|
||||||
{
|
{
|
||||||
data_to_send.attachment = cipherdata_attachment;
|
data_to_send.attachment = cipherdata_attachment;
|
||||||
|
if (cipherdata_attachment_name.length > 0)
|
||||||
|
{
|
||||||
|
data_to_send.attachmentname = cipherdata_attachment_name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$.post(this.scriptLocation(), data_to_send, function(data)
|
$.post(this.scriptLocation(), data_to_send, function(data)
|
||||||
{
|
{
|
||||||
|
@ -1055,7 +1070,7 @@ $(function() {
|
||||||
{
|
{
|
||||||
this.clonedFile.addClass('hidden');
|
this.clonedFile.addClass('hidden');
|
||||||
// removes the saved decrypted file data
|
// removes the saved decrypted file data
|
||||||
$('#attachment a').attr('href', '');
|
this.attachmentLink.attr('href', '');
|
||||||
// the only way to deselect the file is to recreate the input
|
// the only way to deselect the file is to recreate the input
|
||||||
this.fileWrap.html(this.fileWrap.html());
|
this.fileWrap.html(this.fileWrap.html());
|
||||||
this.fileWrap.removeClass('hidden');
|
this.fileWrap.removeClass('hidden');
|
||||||
|
|
|
@ -215,8 +215,10 @@ class zerobin
|
||||||
$error = false;
|
$error = false;
|
||||||
|
|
||||||
$has_attachment = array_key_exists('attachment', $_POST);
|
$has_attachment = array_key_exists('attachment', $_POST);
|
||||||
|
$has_attachmentname = $has_attachment && array_key_exists('attachmentname', $_POST) && !empty($_POST['attachmentname']);
|
||||||
$data = array_key_exists('data', $_POST) ? $_POST['data'] : '';
|
$data = array_key_exists('data', $_POST) ? $_POST['data'] : '';
|
||||||
$attachment = $has_attachment ? $_POST['attachment'] : '';
|
$attachment = $has_attachment ? $_POST['attachment'] : '';
|
||||||
|
$attachmentname = $has_attachmentname ? $_POST['attachmentname'] : '';
|
||||||
|
|
||||||
// Make sure last paste from the IP address was more than X seconds ago.
|
// Make sure last paste from the IP address was more than X seconds ago.
|
||||||
trafficlimiter::setLimit($this->_conf['traffic']['limit']);
|
trafficlimiter::setLimit($this->_conf['traffic']['limit']);
|
||||||
|
@ -235,7 +237,7 @@ class zerobin
|
||||||
|
|
||||||
// Make sure content is not too big.
|
// Make sure content is not too big.
|
||||||
$sizelimit = (int) $this->_getMainConfig('sizelimit', 2097152);
|
$sizelimit = (int) $this->_getMainConfig('sizelimit', 2097152);
|
||||||
if (strlen($data) + strlen($attachment) > $sizelimit)
|
if (strlen($data) + strlen($attachment) + strlen($attachmentname) > $sizelimit)
|
||||||
{
|
{
|
||||||
$this->_return_message(
|
$this->_return_message(
|
||||||
1,
|
1,
|
||||||
|
@ -255,7 +257,8 @@ class zerobin
|
||||||
{
|
{
|
||||||
if (
|
if (
|
||||||
!$this->_getMainConfig('fileupload', false) ||
|
!$this->_getMainConfig('fileupload', false) ||
|
||||||
!sjcl::isValid($attachment)
|
!sjcl::isValid($attachment) ||
|
||||||
|
!($has_attachmentname && sjcl::isValid($attachmentname))
|
||||||
) $this->_return_message(1, 'Invalid attachment.');
|
) $this->_return_message(1, 'Invalid attachment.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -434,8 +437,9 @@ class zerobin
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add attachment if one was sent
|
// Add attachment and its name, if one was sent
|
||||||
if ($has_attachment) $storage['attachment'] = $attachment;
|
if ($has_attachment) $storage['attachment'] = $attachment;
|
||||||
|
if ($has_attachmentname) $storage['attachmentname'] = $attachmentname;
|
||||||
|
|
||||||
// New paste
|
// New paste
|
||||||
if (
|
if (
|
||||||
|
|
Loading…
Reference in New Issue