@ -232,31 +232,25 @@ class zerobin
$ipKey = $header;
$ipKey = $header;
}
}
}
}
if (!trafficlimiter::canPass($_SERVER[$ipKey]))
if (!trafficlimiter::canPass($_SERVER[$ipKey])) return $this->_return_message(
{
1,
$this->_return_message(
i18n::_(
1,
'Please wait %d seconds between each post.',
i18n::_(
$this->_conf['traffic']['limit']
'Please wait %d seconds between each post.',
)
$this->_conf['traffic']['limit']
);
)
);
return;
}
// 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) + strlen($attachmentname) > $sizelimit)
if (
{
strlen($data) + strlen($attachment) + strlen($attachmentname) > $sizelimit
$this->_return_message(
) return $this->_return_message(
1,
1,
i18n::_(
i18n::_(
'Paste is limited to %s of encrypted data.',
'Paste is limited to %s of encrypted data.',
filter::size_humanreadable($sizelimit)
filter::size_humanreadable($sizelimit)
)
)
);
);
return;
}
// Make sure format is correct.
// Make sure format is correct.
if (!sjcl::isValid($data)) return $this->_return_message(1, 'Invalid data.');
if (!sjcl::isValid($data)) return $this->_return_message(1, 'Invalid data.');
@ -268,7 +262,7 @@ class zerobin
!$this->_getMainConfig('fileupload', false) ||
!$this->_getMainConfig('fileupload', false) ||
!sjcl::isValid($attachment) ||
!sjcl::isValid($attachment) ||
!($has_attachmentname & & sjcl::isValid($attachmentname))
!($has_attachmentname & & sjcl::isValid($attachmentname))
) $this->_return_message(1, 'Invalid attachment.');
) return $this->_return_message(1, 'Invalid attachment.');
}
}
// Read additional meta-information.
// Read additional meta-information.
@ -321,7 +315,7 @@ class zerobin
$formatter = $_POST['formatter'];
$formatter = $_POST['formatter'];
if (!array_key_exists($formatter, $this->_conf['formatter_options']))
if (!array_key_exists($formatter, $this->_conf['formatter_options']))
{
{
$formatter = $this->_getMainConfig('defaultformatter', 'syntaxhighlighting ');
$formatter = $this->_getMainConfig('defaultformatter', 'plaintext ');
}
}
$meta['formatter'] = $formatter;
$meta['formatter'] = $formatter;
}
}
@ -354,11 +348,7 @@ class zerobin
}
}
}
}
if ($error)
if ($error) return $this->_return_message(1, 'Invalid data.');
{
$this->_return_message(1, 'Invalid data.');
return;
}
// Add post date to meta.
// Add post date to meta.
$meta['postdate'] = time();
$meta['postdate'] = time();
@ -383,11 +373,7 @@ class zerobin
if (
if (
!filter::is_valid_paste_id($pasteid) ||
!filter::is_valid_paste_id($pasteid) ||
!filter::is_valid_paste_id($parentid)
!filter::is_valid_paste_id($parentid)
)
) return $this->_return_message(1, 'Invalid data.');
{
$this->_return_message(1, 'Invalid data.');
return;
}
// Comments do not expire (it's the paste that expires)
// Comments do not expire (it's the paste that expires)
unset($storage['expire_date']);
unset($storage['expire_date']);
@ -396,43 +382,26 @@ class zerobin
// Make sure paste exists.
// Make sure paste exists.
if (
if (
!$this->_model()->exists($pasteid)
!$this->_model()->exists($pasteid)
)
) return $this->_return_message(1, 'Invalid data.');
{
$this->_return_message(1, 'Invalid data.');
return;
}
// Make sure the discussion is opened in this paste.
// Make sure the discussion is opened in this paste.
$paste = $this->_model()->read($pasteid);
$paste = $this->_model()->read($pasteid);
if (
if (
!$paste->meta->opendiscussion
!$paste->meta->opendiscussion
)
) return $this->_return_message(1, 'Invalid data.');
{
$this->_return_message(1, 'Invalid data.');
return;
}
// Check for improbable collision.
// Check for improbable collision.
if (
if (
$this->_model()->existsComment($pasteid, $parentid, $dataid)
$this->_model()->existsComment($pasteid, $parentid, $dataid)
)
) return $this->_return_message(1, 'You are unlucky. Try again.');
{
$this->_return_message(1, 'You are unlucky. Try again.');
return;
}
// New comment
// New comment
if (
if (
$this->_model()->createComment($pasteid, $parentid, $dataid, $storage) === false
$this->_model()->createComment($pasteid, $parentid, $dataid, $storage) === false
)
) return $this->_return_message(1, 'Error saving comment. Sorry.');
{
$this->_return_message(1, 'Error saving comment. Sorry.');
return;
}
// 0 = no error
// 0 = no error
$this->_return_message(0, $dataid);
return $this->_return_message(0, $dataid);
return;
}
}
// The user posts a standard paste.
// The user posts a standard paste.
else
else
@ -440,11 +409,7 @@ class zerobin
// Check for improbable collision.
// Check for improbable collision.
if (
if (
$this->_model()->exists($dataid)
$this->_model()->exists($dataid)
)
) return $this->_return_message(1, 'You are unlucky. Try again.');
{
$this->_return_message(1, 'You are unlucky. Try again.');
return;
}
// Add attachment and its name, 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;
@ -453,10 +418,7 @@ class zerobin
// New paste
// New paste
if (
if (
$this->_model()->create($dataid, $storage) === false
$this->_model()->create($dataid, $storage) === false
) {
) return $this->_return_message(1, 'Error saving paste. Sorry.');
$this->_return_message(1, 'Error saving paste. Sorry.');
return;
}
// Generate the "delete" token.
// Generate the "delete" token.
// The token is the hmac of the pasteid signed with the server salt.
// The token is the hmac of the pasteid signed with the server salt.
@ -464,8 +426,7 @@ class zerobin
$deletetoken = hash_hmac('sha1', $dataid, serversalt::get());
$deletetoken = hash_hmac('sha1', $dataid, serversalt::get());
// 0 = no error
// 0 = no error
$this->_return_message(0, $dataid, array('deletetoken' => $deletetoken));
return $this->_return_message(0, $dataid, array('deletetoken' => $deletetoken));
return;
}
}
}
}
@ -609,7 +570,7 @@ class zerobin
}
}
else
else
{
{
$paste->meta->formatter = $this->_getMainConfig('defaultformatter', 'syntaxhighlighting ');
$paste->meta->formatter = $this->_getMainConfig('defaultformatter', 'plaintext ');
}
}
}
}
@ -680,7 +641,7 @@ class zerobin
$page->assign('SYNTAXHIGHLIGHTING', array_key_exists('syntaxhighlighting', $formatters));
$page->assign('SYNTAXHIGHLIGHTING', array_key_exists('syntaxhighlighting', $formatters));
$page->assign('SYNTAXHIGHLIGHTINGTHEME', $this->_getMainConfig('syntaxhighlightingtheme', ''));
$page->assign('SYNTAXHIGHLIGHTINGTHEME', $this->_getMainConfig('syntaxhighlightingtheme', ''));
$page->assign('FORMATTER', $formatters);
$page->assign('FORMATTER', $formatters);
$page->assign('FORMATTERDEFAULT', $this->_getMainConfig('defaultformatter', 'syntaxhighlighting '));
$page->assign('FORMATTERDEFAULT', $this->_getMainConfig('defaultformatter', 'plaintext '));
$page->assign('NOTICE', i18n::_($this->_getMainConfig('notice', '')));
$page->assign('NOTICE', i18n::_($this->_getMainConfig('notice', '')));
$page->assign('BURNAFTERREADINGSELECTED', $this->_getMainConfig('burnafterreadingselected', false));
$page->assign('BURNAFTERREADINGSELECTED', $this->_getMainConfig('burnafterreadingselected', false));
$page->assign('PASSWORD', $this->_getMainConfig('password', true));
$page->assign('PASSWORD', $this->_getMainConfig('password', true));