line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DJabberd::Authen::UserLimit; |
2
|
1
|
|
|
1
|
|
754
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
3
|
1
|
|
|
1
|
|
6
|
use base 'DJabberd::Authen'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
633
|
|
4
|
1
|
|
|
1
|
|
397
|
use DJabberd::Log; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $logger = DJabberd::Log->get_logger; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use vars qw($VERSION); |
8
|
|
|
|
|
|
|
$VERSION = '0.30'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use DJabberd::Util qw(as_num); |
12
|
|
|
|
|
|
|
sub log { |
13
|
|
|
|
|
|
|
$logger; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub set_config_userlimit { |
17
|
|
|
|
|
|
|
my ($self, $val) = @_; |
18
|
|
|
|
|
|
|
$self->{limit} = as_num($val); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub finalize { |
22
|
|
|
|
|
|
|
my ($self) = @_; |
23
|
|
|
|
|
|
|
die "Missing UserLimit directive" if not $self->{limit}; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub check_cleartext { |
28
|
|
|
|
|
|
|
my ($self, $cb, %args) = @_; |
29
|
|
|
|
|
|
|
# args contain: username and conn |
30
|
|
|
|
|
|
|
my $conn = $args{conn}; |
31
|
|
|
|
|
|
|
my $nb_user = keys %{$conn->vhost->{jid2sock}}; |
32
|
|
|
|
|
|
|
my $limit = $self->{limit}; |
33
|
|
|
|
|
|
|
$logger->info("Number of user : $nb_user , limit : $limit "); |
34
|
|
|
|
|
|
|
if ($nb_user ge $limit) { |
35
|
|
|
|
|
|
|
$cb->reject; |
36
|
|
|
|
|
|
|
return; |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
$cb->decline; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__END__ |