mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2025-05-02 06:26:16 -04:00
unify IP-related logic into traffic limiter
This commit is contained in:
parent
dbe8debe30
commit
1034d4038e
3 changed files with 101 additions and 60 deletions
|
@ -195,35 +195,14 @@ class Controller
|
|||
*/
|
||||
private function _create()
|
||||
{
|
||||
// Check if whitelist feature is enabled
|
||||
if (($option = $this->_conf->getKey('creators', 'traffic')) !== '') {
|
||||
// Parse whitelist into array
|
||||
$whitelist = explode(',', $option);
|
||||
// Check for source IP in HTTP header
|
||||
if (($option = $this->_conf->getKey('header', 'traffic')) !== null) {
|
||||
$httpHeader = 'HTTP_' . $option;
|
||||
// Grab source IP from HTTP header (if it exists)
|
||||
if (array_key_exists($httpHeader, $_SERVER) && !empty($_SERVER[$httpHeader])) {
|
||||
// Check if source IP reported from HTTP header is in whitelist array
|
||||
if (!in_array($_SERVER[$httpHeader], $whitelist)) {
|
||||
$this->_return_message(1, I18n::_('Your IP is not authorized to create pastes.'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure last paste from visitors IP address was more than configured amount of seconds ago.
|
||||
ServerSalt::setStore($this->_model->getStore());
|
||||
TrafficLimiter::setConfiguration($this->_conf);
|
||||
TrafficLimiter::setStore($this->_model->getStore());
|
||||
if (!TrafficLimiter::canPass()) {
|
||||
$this->_return_message(
|
||||
1, I18n::_(
|
||||
'Please wait %d seconds between each post.',
|
||||
$this->_conf->getKey('limit', 'traffic')
|
||||
)
|
||||
);
|
||||
try {
|
||||
TrafficLimiter::canPass();
|
||||
} catch (Exception $e) {
|
||||
$this->_return_message(1, $e->getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue