adding file name support for #20, solving issue with unencryptable file

This commit is contained in:
El RIDO 2015-09-18 12:33:10 +02:00
parent e144739dec
commit ed9c4f45f4
2 changed files with 40 additions and 21 deletions

View file

@ -577,24 +577,33 @@ $(function() {
if (!this.prettyPrint.hasClass('prettyprinted')) {
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)
{
var attachment = filter.decipher(key, password, comments[0].attachment);
if (attachment)
if (attachment.length == 0)
{
this.attachmentLink.attr('href', attachment);
this.attachment.removeClass('hidden');
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.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.prettyPrint, cleartext);
this.formatPaste(comments[0].meta.formatter);
@ -844,7 +853,8 @@ $(function() {
return function(e) {
zerobin.sendDataContinue(
randomkey,
filter.cipher(randomkey, password, e.target.result)
filter.cipher(randomkey, password, e.target.result),
filter.cipher(randomkey, password, theFile.name)
);
}
})(files[0]);
@ -854,12 +864,13 @@ $(function() {
{
this.sendDataContinue(
randomkey,
filter.cipher(randomkey, password, this.attachmentLink.attr('href'))
filter.cipher(randomkey, password, this.attachmentLink.attr('href')),
this.attachmentLink.attr('download')
);
}
else
{
this.sendDataContinue(randomkey, '');
this.sendDataContinue(randomkey, '', '');
}
},
@ -868,7 +879,7 @@ $(function() {
*
* @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 data_to_send = {
@ -881,6 +892,10 @@ $(function() {
if (cipherdata_attachment.length > 0)
{
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)
{
@ -1055,7 +1070,7 @@ $(function() {
{
this.clonedFile.addClass('hidden');
// 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
this.fileWrap.html(this.fileWrap.html());
this.fileWrap.removeClass('hidden');

View file

@ -215,8 +215,10 @@ class zerobin
$error = false;
$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'] : '';
$attachment = $has_attachment ? $_POST['attachment'] : '';
$attachmentname = $has_attachmentname ? $_POST['attachmentname'] : '';
// Make sure last paste from the IP address was more than X seconds ago.
trafficlimiter::setLimit($this->_conf['traffic']['limit']);
@ -235,7 +237,7 @@ class zerobin
// Make sure content is not too big.
$sizelimit = (int) $this->_getMainConfig('sizelimit', 2097152);
if (strlen($data) + strlen($attachment) > $sizelimit)
if (strlen($data) + strlen($attachment) + strlen($attachmentname) > $sizelimit)
{
$this->_return_message(
1,
@ -255,7 +257,8 @@ class zerobin
{
if (
!$this->_getMainConfig('fileupload', false) ||
!sjcl::isValid($attachment)
!sjcl::isValid($attachment) ||
!($has_attachmentname && sjcl::isValid($attachmentname))
) $this->_return_message(1, 'Invalid attachment.');
}
@ -434,8 +437,9 @@ class zerobin
return;
}
// Add attachment if one was sent
if($has_attachment) $storage['attachment'] = $attachment;
// Add attachment and its name, if one was sent
if ($has_attachment) $storage['attachment'] = $attachment;
if ($has_attachmentname) $storage['attachmentname'] = $attachmentname;
// New paste
if (