Skip to content

Commit

Permalink
11.57: added incoming TS6 handlers for KLINE, ENCAP KLINE, ENCAP DLINE.
Browse files Browse the repository at this point in the history
#32.             added convenience function add_update_enforce_activate_ban to Ban.             added support for TS6 capabilities KLN and UNKLN.
  • Loading branch information
cooper committed Jul 24, 2016
1 parent 3b2c441 commit a9c6372
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 38 deletions.
4 changes: 4 additions & 0 deletions INDEV
Original file line number Diff line number Diff line change
Expand Up @@ -3428,3 +3428,7 @@ CHANGES:
fixed some oper notices which were broken since the changes to ->notice_info().
silented annoying warnings produced by load_or_reload().
added ridiculous experimental fake user for #32.

57. added incoming TS6 handlers for KLINE, ENCAP KLINE, ENCAP DLINE. #32.
added convenience function add_update_enforce_activate_ban to Ban.
added support for TS6 capabilities KLN and UNKLN.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11.56
11.57
2 changes: 1 addition & 1 deletion modules/Ban/Ban.module/Ban.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"description" : "provides an interface for user and server banning",
"name" : "Ban",
"package" : "M::Ban",
"version" : "9.3"
"version" : "9.4"
}
14 changes: 10 additions & 4 deletions modules/Ban/Ban.module/Ban.pm
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ our ($table, %ban_types, %timers);
#
# reason user-set reason for ban
#

# _just_set_by UID of user who set a ban. used for propagation.
#
sub init {
$table = $conf->table('bans') or return;

Expand Down Expand Up @@ -184,6 +185,13 @@ sub delete_ban_by_id {
$table->row(id => $id)->delete;
}

sub add_update_enforce_activate_ban {
my %ban = @_ or return;
add_or_update_ban(%ban);
enforce_ban(%ban);
activate_ban(%ban);
}

###############
### BAN API ###
###############
Expand Down Expand Up @@ -270,9 +278,7 @@ sub register_ban {
%opts
);

add_or_update_ban(%ban);
enforce_ban(%ban);
activate_ban(%ban);
add_update_enforce_activate_ban(%ban);

# forward it
$pool->fire_command_all(baninfo => \%ban);
Expand Down
2 changes: 1 addition & 1 deletion modules/Ban/Ban.module/JELP.module/JELP.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"description" : "JELP ban propagation",
"name" : "Ban::JELP",
"package" : "M::Ban::JELP",
"version" : "0.9"
"version" : "1"
}
8 changes: 3 additions & 5 deletions modules/Ban/Ban.module/JELP.module/JELP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ use strict;
use 5.010;

M::Ban->import(qw(
enforce_ban activate_ban enforce_ban
get_all_bans ban_by_id
add_or_update_ban delete_ban_by_id
delete_ban_by_id add_update_enforce_activate_ban
));

our ($api, $mod, $pool, $conf, $me);
Expand Down Expand Up @@ -186,9 +185,8 @@ sub scmd_baninfo {
return unless defined $ban{id};

# update, enforce, and activate
add_or_update_ban(%ban);
enforce_ban(%ban);
activate_ban(%ban);
add_update_enforce_activate_ban(%ban);


}

Expand Down
2 changes: 1 addition & 1 deletion modules/Ban/Ban.module/TS6.module/TS6.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"description" : "TS6 ban propagation",
"name" : "Ban::TS6",
"package" : "M::Ban::TS6",
"version" : "2.7"
"version" : "3"
}
120 changes: 95 additions & 25 deletions modules/Ban/Ban.module/TS6.module/TS6.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ use utils qw(fnv v);
use M::TS6::Utils qw(ts6_id);

M::Ban->import(qw(
enforce_ban activate_ban enforce_ban
get_all_bans ban_by_id
add_or_update_ban delete_ban_by_id
delete_ban_by_id add_update_enforce_activate_ban
));

our ($api, $mod, $pool, $conf, $me);
Expand All @@ -43,16 +42,22 @@ our %ts6_outgoing_commands = (
);

our %ts6_incoming_commands = (
ENCAP_KLINE => {
# :uid ENCAP target KLINE duration ident_mask host_mask :reason
params => '-source(user) * * * * * *',
code => \&encap_kline
},
ENCAP_DLINE => {
# :uid ENCAP target DLINE duration ip_mask :reason
params => '-source(user) * * * * *',
code => \encap_&dline
}
code => \&encap_dline
},
ENCAP_KLINE => {
# :<source> ENCAP <target> KLINE <time> <user> <host> :<reason>
params => '-source(user) * * * * * *',
code => \&encap_kline
},
KLINE => {
# :<source> KLINE <target> <time> <user> <host> :<reason>
params => '-source(user) * * * * *',
code => \&kline
},

);

sub init {
Expand Down Expand Up @@ -83,9 +88,13 @@ sub ts6_ban {
if ($duration) {
$duration = int($duration / 60 + 0.5);
$duration = 1 if $duration < 1;
$ban{duration} = $duration;
$ban{duration_minutes} = $duration;
}

$ban{duration} ||= 0;
$ban{duration_minutes} ||= 0;
$ban{reason} //= 'no reason';

# add user and host if there's an @
if ($ban{match} =~ m/^(.*?)\@(.*)$/) {
$ban{match_user} = $1;
Expand All @@ -109,11 +118,10 @@ sub ts6_ban {
}

# create and register a ban
sub create_ts6_ban {
sub create_or_update_ts6_ban {
my %ban = ts6_ban(@_);
add_or_update_ban(%ban);
enforce_ban(%ban);
activate_ban(%ban);
add_update_enforce_activate_ban(%ban);
return %ban;
}

################
Expand Down Expand Up @@ -150,6 +158,7 @@ sub burst_bans {
);
$fake_user->set_mode('invisible');
$fake_user->set_mode('ircop');
$fake_user->set_mode('service');

# send out bans
$server->fire_command(ban => @bans);
Expand Down Expand Up @@ -196,12 +205,22 @@ sub out_baninfo {
# charybdis will send the encap target as it is received from the oper.
# we don't care about that though. juno bans are global.

# CAP_KLN: :<source> KLINE <target> <time> <user> <host> :<reason>
if ($ban{type} eq 'kline' && $to_server->has_cap('KLN')) {
return sprintf ':%s KLINE * %d %s %s :%s',
ts6_id($from);
$ban{duration},
$ban{match_user},
$ban{match_host},
$ban{reason};
}

# encap fallback
return sprintf ':%s ENCAP * %s %d %s :%s',
ts6_id($from),
uc $ban{type},
$ban{duration} || 0,
$ban{match_ts6},
$ban{reason} // 'no reason';
$ban{duration},
$ban{match_ts6};
}

# bandel is sent out when a ban is removed. in TS6, use ENCAP UNK/DLINE
Expand All @@ -213,6 +232,16 @@ sub out_bandel {
my $from = $pool->lookup_user($ban{_just_set_by})
|| get_fake_user($to_server) or return;

# CAP_UNKLN: :<source> UNKLINE <target> <user> <host>
if ($ban{type} eq 'kline' && $to_server->has_cap('UNKLN')) {
return sprintf ':%s UNKLINE * %s %s',
ts6_id($from);
$ban{duration},
$ban{match_user},
$ban{match_host};
}

# encap fallback
return sprintf ':%s ENCAP * UN%s %s',
ts6_id($from),
uc $ban{type},
Expand All @@ -223,18 +252,59 @@ sub out_bandel {
### INCOMING ###
################

sub encap_kline {
my ($server, $msg, $user, $serv_mask, undef,
sub encap_kline { kline(@_[0..3, 5..8]) }
sub encap_dline { dline(@_[0..3, 5..7]) }

sub kline {
my ($server, $msg, $user, $serv_mask,
$duration, $ident_mask, $host_mask, $reason) = @_;
# forward and/or
# call kline(stuff)

# create and activate the ban
my %ban = create_or_update_ts6_ban(
type => 'kline',
match => "$ident_mask\@$host_mask",
reason => $reason,
added => time,
modified => time,
duration => $duration * 60, # convert to seconds
expires => $duration ? time + $duration * 60 : 0,
aserver => $user->server->name,
auser => $user->full,
_just_set_by => $user->id
);

#=== Forward ===#
#
# we ignore the target mask. juno bans are global, so let's pretend
# this was intended to be global too.
#
$msg->forward(baninfo => \%ban);
}

sub encap_dline {
my ($server, $msg, $user, $serv_mask, undef,
sub dline {
my ($server, $msg, $user, $serv_mask,
$duration, $ip_mask, $reason) = @_;
# forward and/or
# call dline(stuff)

# create and activate the ban
my %ban = create_or_update_ts6_ban(
type => 'dline',
match => $ip_mask,
reason => $reason,
added => time,
modified => time,
duration => $duration * 60, # convert to seconds
expires => $duration ? time + $duration * 60 : 0,
aserver => $user->server->name,
auser => $user->full,
_just_set_by => $user->id
);

#=== Forward ===#
#
# we ignore the target mask. juno bans are global, so let's pretend
# this was intended to be global too.
#
$msg->forward(baninfo => \%ban);
}

$mod

0 comments on commit a9c6372

Please sign in to comment.