Commit f581cf9b authored by Phyks's avatar Phyks

Adding a setting option to configure minimum number of strikes before being banned

parent dc72c4b1
......@@ -20,7 +20,8 @@ sub startup {
length => 8,
secret => ['hfudsifdsih'],
page_offset => 10,
theme => 'default'
theme => 'default',
ban_min_strike => 3
}
});
......
......@@ -12,10 +12,10 @@ sub login {
my $ip = $c->ip;
my @banned = LstuModel::Ban->select('WHERE ip = ? AND until > ? AND strike >= 3', $ip, time);
my @banned = LstuModel::Ban->select('WHERE ip = ? AND until > ? AND strike >= ?', $ip, time, $c->config('ban_min_strike'));
if (scalar @banned) {
my $penalty = 3600;
if ($banned[0]->strike >= 6) {
if ($banned[0]->strike >= 2 * $c->config('ban_min_strike')) {
$penalty = 3600 * 24 * 30; # 30 days of banishing
}
$banned[0]->update(
......
......@@ -13,10 +13,10 @@ sub add {
my $ip = $c->ip;
my @banned = LstuModel::Ban->select('WHERE ip = ? AND until > ? AND strike >= 3', $ip, time);
my @banned = LstuModel::Ban->select('WHERE ip = ? AND until > ? AND strike >= ?', $ip, time, $c->config('ban_min_strike'));
if (scalar @banned) {
my $penalty = 3600;
if ($banned[0]->strike >= 6) {
if ($banned[0]->strike >= 2 * $c->config('ban_min_strike')) {
$penalty = 3600 * 24 * 30; # 30 days of banishing
}
$banned[0]->update(
......
......@@ -64,4 +64,12 @@
# remember that it has to be in a directory writable by Lstu user
# optional, default is lstu.db
#db_path => 'lstu.db',
# Rate-limiting for the API
# After ban_min_strike requests in a second, the IP address will be
# banned for one hour.
# If it continues to query the API during this ban time at least
# ban_min_strike times, it will be banned for a month.
# optional, default is 3
#ban_min_strike => 3,
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment