in lib/Mail/SpamAssassin/Plugin/Redirectors.pm [142:469]
sub set_config {
my($self, $conf) = @_;
my @cmds = ();
push (@cmds, {
setting => 'url_redirector',
default => {},
type => $Mail::SpamAssassin::Conf::CONF_TYPE_HASH_KEY_VALUE,
code => sub {
my ($self, $key, $value, $line) = @_;
if ($value eq '') {
return $Mail::SpamAssassin::Conf::MISSING_REQUIRED_VALUE;
}
foreach my $domain (split(/\s+/, $value)) {
$self->{url_redirector}->{lc $domain} = 1; # 1 == head
}
}
});
=over 4
=item clear_url_redirector [domain] [domain...]
Clear configured url_redirector domains, for example to
override default settings from an update channel. If domains are specified,
then only those are removed from list.
=back
=cut
push (@cmds, {
setting => 'clear_url_redirector',
code => sub {
my ($self, $key, $value, $line) = @_;
if ($value eq '') {
$self->{url_redirector} = {};
} else {
foreach my $domain (split(/\s+/, $value)) {
delete $self->{url_redirector}->{lc $domain};
}
}
}
});
=over 4
=item url_redirector_get domain [domain...] (default: none)
Domains that should be considered as an URL redirector. If the domain begins
with a '.', 3rd level tld of the main domain will be checked.
The http GET method will be used to check those domains.
=back
=cut
push (@cmds, {
setting => 'url_redirector_get',
code => sub {
my ($self, $key, $value, $line) = @_;
if ($value eq '') {
return $Mail::SpamAssassin::Conf::MISSING_REQUIRED_VALUE;
}
foreach my $domain (split(/\s+/, $value)) {
$self->{url_redirector}->{lc $domain} = 2; # 2 == get
}
}
});
=over 4
=item url_redirector_params regexp (default: (?:adurl|af_web_dp|cm_destination|continue|destination|destURL|h|l|login|location|p1|pval|r|redir|redirect|redirectTo|return|returnUrl|referer|service|target|tid|u|url)=(.*))
Regexp used to parse uri parameters in order to detect redirectors and to get redirected domains.
The regexp must match only the redirected domain.
=back
=cut
push(@cmds, {
setting => 'url_redirector_params',
default => qr/(?:adurl|af_web_dp|cm_destination|continue|destination|destURL|h|l|login|location|p1|pval|r|redir|redirect|redirectTo|ret_url|return|returnUrl|referer|service|target|tid|u|url)=(.*)/,
type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING,
code => sub {
my ($self, $key, $value, $line) = @_;
unless (defined $value && $value !~ /^$/) {
return $Mail::SpamAssassin::Conf::MISSING_REQUIRED_VALUE;
}
my ($rec, $err) = compile_regexp($value, 0);
if (!$rec) {
dbg("config: invalid url_redirector_params '$value': $err");
return $Mail::SpamAssassin::Conf::INVALID_VALUE;
}
$self->{url_redirector_params} = $rec;
},
});
=head1 PRIVILEGED SETTINGS
=over 4
=item url_redirector_cache_type (default: none)
The cache type that is being utilized. Currently only supported value is
C<dbi> that implies C<url_redirector_cache_dsn> is a DBI connect string.
DBI module is required.
Example:
url_redirector_cache_type dbi
=back
=cut
push (@cmds, {
setting => 'url_redirector_cache_type',
default => '',
is_priv => 1,
type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING
});
=over 4
=item url_redirector_cache_dsn (default: none)
The DBI dsn of the database to use.
For SQLite, the database will be created automatically if it does not
already exist, the supplied path and file must be read/writable by the
user running spamassassin or spamd.
For MySQL/MariaDB or PostgreSQL, see sql-directory for database table
creation clauses.
You will need to have the proper DBI module for your database. For example
DBD::SQLite, DBD::mysql, DBD::MariaDB or DBD::Pg.
Minimum required SQLite version is 3.24.0 (available from DBD::SQLite 1.59_01).
Examples:
url_redirector_cache_dsn dbi:SQLite:dbname=/var/lib/spamassassin/Redirectors.db
=back
=cut
push (@cmds, {
setting => 'url_redirector_cache_dsn',
default => '',
is_priv => 1,
type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING
});
=over 4
=item url_redirector_cache_username (default: none)
The username that should be used to connect to the database. Not used for
SQLite.
=back
=cut
push (@cmds, {
setting => 'url_redirector_cache_username',
default => '',
is_priv => 1,
type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING
});
=over 4
=item url_redirector_cache_password (default: none)
The password that should be used to connect to the database. Not used for
SQLite.
=back
=cut
push (@cmds, {
setting => 'url_redirector_cache_password',
default => '',
is_priv => 1,
type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING
});
=over 4
=item url_redirector_cache_ttl (default: 86400)
The length of time a cache entry will be valid for in seconds.
Default is 86400 (1 day).
See C<url_redirector_cache_autoclean> for database cleaning.
=back
=cut
push (@cmds, {
setting => 'url_redirector_cache_ttl',
is_admin => 1,
default => 86400,
type => $Mail::SpamAssassin::Conf::CONF_TYPE_NUMERIC
});
=head1 ADMINISTRATOR SETTINGS
=over 4
=item url_redirector_cache_autoclean (default: 1000)
Automatically purge old entries from database. Value describes a random run
chance of 1/x. The default value of 1000 means that cleaning is run
approximately once for every 1000 messages processed. Value of 1 would mean
database is cleaned every time a message is processed.
Set 0 to disable automatic cleaning and to do it manually.
=back
=cut
push (@cmds, {
setting => 'url_redirector_cache_autoclean',
is_admin => 1,
default => 1000,
type => $Mail::SpamAssassin::Conf::CONF_TYPE_NUMERIC
});
=over 4
=item url_redirector_loginfo (default: 0 (off))
If this option is enabled (set to 1), then redirected URLs and the decoded URLs will be logged with info priority.
=back
=cut
push (@cmds, {
setting => 'url_redirector_loginfo',
is_admin => 1,
default => 0,
type => $Mail::SpamAssassin::Conf::CONF_TYPE_BOOL
});
=over 4
=item url_redirector_timeout (default: 5)
Maximum time a redirection URL HTTP request can take, in seconds.
=back
=cut
push (@cmds, {
setting => 'url_redirector_timeout',
is_admin => 1,
default => 5,
type => $Mail::SpamAssassin::Conf::CONF_TYPE_NUMERIC
});
=over 4
=item max_redir_urls (default: 10)
Maximum amount of redirector URLs that will be looked up per message. Chained
redirections are not counted, only initial redirection URLs found.
Setting it to 0 disables HTTP requests, allowing only redir_url() test to
work and report any found redirector URLs.
=back
=cut
push (@cmds, {
setting => 'max_redir_urls',
is_admin => 1,
default => 10,
type => $Mail::SpamAssassin::Conf::CONF_TYPE_NUMERIC
});
=over 4
=item max_redir_url_redirections (default: 10)
Maximum depth of chained redirections that a redirector can generate.
=back
=cut
push (@cmds, {
setting => 'max_redir_url_redirections',
is_admin => 1,
default => 10,
type => $Mail::SpamAssassin::Conf::CONF_TYPE_NUMERIC
});
=over 4
=item url_redirector_user_agent (default: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36)
Set User-Agent header for HTTP requests. Some services require it to look
like a common browser.
=back
=cut
push (@cmds, {
setting => 'url_redirector_user_agent',
is_admin => 1,
default => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36',
type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING
});
$conf->{parser}->register_commands(\@cmds);
}