Skip to content
Permalink
Browse files

refs #8 reportもsummary使うようにしとく

  • Loading branch information
kfly8 committed Sep 27, 2014
1 parent badbafa commit f4bd9e12c1d17ef1dab601b745c82daed134e504
Showing with 18 additions and 45 deletions.
  1. +18 −45 perl/lib/Isu4Qualifier/Web.pm
@@ -130,57 +130,30 @@ sub last_login {

sub banned_ips {
my ($self) = @_;
my @ips; # banned_ips
my $threshold = $self->config->{ip_ban_threshold};

# 1) threashold分試したのに、一回も成功したことがないip
my $not_succeeded = $self->db->select_all('SELECT ip FROM
(SELECT ip, MAX(succeeded) as max_succeeded, COUNT(1) as cnt FROM login_log GROUP BY ip) AS t0
WHERE
t0.max_succeeded = 0
AND
t0.cnt >= ?', $threshold
);

for my $row (@$not_succeeded) {
push @ips, $row->{ip};
}

# 2) 最後にログイン成功してから、ログインを試みた回数が、threashold以上ならダメ
my $last_succeeds = $self->db->select_all('
SELECT ip, MAX(id) AS last_login_id FROM login_log WHERE succeeded = 1 GROUP by ip');

for my $row (@$last_succeeds) {
my $count = $self->db->select_one('SELECT COUNT(1) AS cnt FROM login_log WHERE ip = ? AND ? < id', $row->{ip}, $row->{last_login_id});
if ($threshold <= $count) {
push @ips, $row->{ip};
}
}

\@ips;
$self->db->selectcol_arrayref('
SELECT ip FROM
ip_login_last_failure_count
WHERE
last_failure_count >= ?
',
undef,
$self->config->{ip_ban_threshold}
);
}

sub locked_users {
my ($self) = @_;
my @user_ids;
my $threshold = $self->config->{user_lock_threshold};

my $not_succeeded = $self->db->select_all('SELECT user_id, login FROM (SELECT user_id, login, MAX(succeeded) as max_succeeded, COUNT(1) as cnt FROM login_log GROUP BY user_id) AS t0 WHERE t0.user_id IS NOT NULL AND t0.max_succeeded = 0 AND t0.cnt >= ?', $threshold);

for my $row (@$not_succeeded) {
push @user_ids, $row->{login};
}

my $last_succeeds = $self->db->select_all('SELECT user_id, login, MAX(id) AS last_login_id FROM login_log WHERE user_id IS NOT NULL AND succeeded = 1 GROUP BY user_id');

for my $row (@$last_succeeds) {
my $count = $self->db->select_one('SELECT COUNT(1) AS cnt FROM login_log WHERE user_id = ? AND ? < id', $row->{user_id}, $row->{last_login_id});
if ($threshold <= $count) {
push @user_ids, $row->{login};
}
}

\@user_ids;
$self->db->selectcol_arrayref('
SELECT user_id FROM
user_login_last_failure_count
WHERE
last_failure_count >= ?
',
undef,
$self->config->{user_lock_threshold}
);
}

sub login_log {

0 comments on commit f4bd9e1

Please sign in to comment.
You can’t perform that action at this time.