Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Commit

Permalink
adding file name support for #20, solving issue with unencryptable file
Browse files Browse the repository at this point in the history
  • Loading branch information
elrido committed Sep 18, 2015
1 parent e144739 commit ed9c4f4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
47 changes: 31 additions & 16 deletions js/zerobin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
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)
{
this.attachmentLink.attr('href', attachment);
this.attachment.removeClass('hidden');
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);
Expand Down Expand Up @@ -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]);
Expand All @@ -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, '', '');
}
},

Expand All @@ -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 = {
Expand All @@ -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)
{
Expand Down Expand Up @@ -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');
Expand Down
12 changes: 8 additions & 4 deletions lib/zerobin.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,10 @@ private function _create()
$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']);
Expand All @@ -235,7 +237,7 @@ private function _create()

// 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,
Expand All @@ -255,7 +257,8 @@ private function _create()
{
if (
!$this->_getMainConfig('fileupload', false) ||
!sjcl::isValid($attachment)
!sjcl::isValid($attachment) ||
!($has_attachmentname && sjcl::isValid($attachmentname))
) $this->_return_message(1, 'Invalid attachment.');
}

Expand Down Expand Up @@ -434,8 +437,9 @@ private function _create()
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 (
Expand Down

0 comments on commit ed9c4f4

Please sign in to comment.