3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-10-03 01:48:38 +02:00

Add SSL support, and other misc updates

This commit is contained in:
Pragmatic Software 2013-02-25 02:27:24 +00:00
parent abd9fafb87
commit dc52430044
11 changed files with 75 additions and 25 deletions

View File

@ -540,8 +540,8 @@ sub check_nickserv_accounts {
} }
foreach my $baninfo (@bans) { foreach my $baninfo (@bans) {
$self->{pbot}->logger->log("anti-flood: [check-bans] $account_mask evaded $baninfo->{banmask} banned in $baninfo->{channel} by $baninfo->{owner}\n"); $self->{pbot}->logger->log("anti-flood: [check-bans] $account_mask may have evaded $baninfo->{banmask} banned in $baninfo->{channel} by $baninfo->{owner}\n");
$self->{pbot}->conn->privmsg($nick, "You have been banned in $baninfo->{channel} for attempting to evade a ban on $baninfo->{banmask} set by $baninfo->{owner}"); #$self->{pbot}->conn->privmsg($nick, "You have been banned in $baninfo->{channel} for attempting to evade a ban on $baninfo->{banmask} set by $baninfo->{owner}");
$account_mask =~ m/[^!]+\!(.*)/; $account_mask =~ m/[^!]+\!(.*)/;
my $banmask = "*!$1"; my $banmask = "*!$1";

View File

@ -693,7 +693,7 @@ sub factfind {
chop $text; chop $text;
return "found one factoid submitted for " . ($last_chan eq '.*' ? 'global channel' : $last_chan) . " " . $argtype . ": '$last_trigger' is '" . $factoids->{$last_chan}->{$last_trigger}->{action} . "'"; return "found one factoid submitted for " . ($last_chan eq '.*' ? 'global channel' : $last_chan) . " " . $argtype . ": '$last_trigger' is '" . $factoids->{$last_chan}->{$last_trigger}->{action} . "'";
} else { } else {
return "$i factoids " . $argtype . ": $text" unless $i == 0; return "found $i factoids " . $argtype . ": $text" unless $i == 0;
my $chans = (defined $channel ? ($channel eq '.*' ? 'global channel' : $channel) : 'any channels'); my $chans = (defined $channel ? ($channel eq '.*' ? 'global channel' : $channel) : 'any channels');
return "No factoids " . $argtype . " submitted for $chans"; return "No factoids " . $argtype . " submitted for $chans";

View File

@ -129,7 +129,7 @@ sub execute_module {
Carp::croak("Could not chdir to '$module_dir': $!"); Carp::croak("Could not chdir to '$module_dir': $!");
} }
print "module arguments: [$arguments]\n"; # print "module arguments: [$arguments]\n";
if(defined $tonick) { if(defined $tonick) {
$self->{pbot}->logger->log("($from): $nick!$user\@$host) sent to $tonick\n"); $self->{pbot}->logger->log("($from): $nick!$user\@$host) sent to $tonick\n");

View File

@ -207,7 +207,7 @@ sub interpreter {
my ($result, $channel); my ($result, $channel);
my $pbot = $self->{pbot}; my $pbot = $self->{pbot};
return undef if not length $keyword; return undef if not length $keyword or $count > 5;
$from = lc $from; $from = lc $from;
@ -253,13 +253,13 @@ sub interpreter {
# if multiple channels have this keyword, then ask user to disambiguate # if multiple channels have this keyword, then ask user to disambiguate
if($found > 1) { if($found > 1) {
return $ref_from . "Ambiguous keyword '$original_keyword' exists in multiple locations (use 'fact <location> <keyword>' to choose one): $chans"; return $ref_from . "Ambiguous keyword '$original_keyword' exists in multiple channels (use 'fact <channel> <keyword>' to choose one): $chans";
} }
# if there's just one other channel that has this keyword, trigger that instance # if there's just one other channel that has this keyword, trigger that instance
elsif($found == 1) { elsif($found == 1) {
$pbot->logger->log("Found '$original_keyword' as '$fwd_trig' in [$fwd_chan]\n"); $pbot->logger->log("Found '$original_keyword' as '$fwd_trig' in [$fwd_chan]\n");
return $pbot->factoids->interpreter($from, $nick, $user, $host, $count, $fwd_trig, $arguments, $tonick, $fwd_chan); return $pbot->factoids->interpreter($from, $nick, $user, $host, ++$count, $fwd_trig, $arguments, $tonick, $fwd_chan);
} }
# otherwise keyword hasn't been found, display similiar matches for all channels # otherwise keyword hasn't been found, display similiar matches for all channels
else { else {
@ -270,7 +270,7 @@ sub interpreter {
# found factfind matches # found factfind matches
if($matches !~ m/^No factoids/) { if($matches !~ m/^No factoids/) {
return "No such factoid '$original_keyword'; found $matches"; return "No such factoid '$original_keyword'; $matches";
} }
# otherwise find levenshtein closest matches from all channels # otherwise find levenshtein closest matches from all channels

View File

@ -50,6 +50,8 @@ my %autoloaded = ( 'ircname' => undef,
'hostname' => undef, 'hostname' => undef,
'pacing' => undef, 'pacing' => undef,
'ssl' => undef, 'ssl' => undef,
'ssl_ca_path' => undef,
'ssl_ca_file' => undef,
); );
# This hash will contain any global default handlers that the user specifies. # This hash will contain any global default handlers that the user specifies.
@ -77,6 +79,8 @@ sub new {
_lastsl => 0, _lastsl => 0,
_pacing => 0, # no pacing by default _pacing => 0, # no pacing by default
_ssl => 0, # no ssl by default _ssl => 0, # no ssl by default
_ssl_ca_path => undef,
_ssl_ca_file => undef,
_format => { 'default' => "[%f:%t] %m <%d>", }, _format => { 'default' => "[%f:%t] %m <%d>", },
}; };
@ -228,6 +232,8 @@ sub connect {
$self->username($arg{'Username'}) if exists $arg{'Username'}; $self->username($arg{'Username'}) if exists $arg{'Username'};
$self->pacing($arg{'Pacing'}) if exists $arg{'Pacing'}; $self->pacing($arg{'Pacing'}) if exists $arg{'Pacing'};
$self->ssl($arg{'SSL'}) if exists $arg{'SSL'}; $self->ssl($arg{'SSL'}) if exists $arg{'SSL'};
$self->ssl_ca_path($arg{'SSL_ca_path'}) if exists $arg{'SSL_ca_path'};
$self->ssl_ca_file($arg{'SSL_ca_file'}) if exists $arg{'SSL_ca_file'};
} }
# Lots of error-checking claptrap first... # Lots of error-checking claptrap first...
@ -260,12 +266,31 @@ sub connect {
if($self->ssl) { if($self->ssl) {
require IO::Socket::SSL; require IO::Socket::SSL;
$self->socket(IO::Socket::SSL->new(PeerAddr => $self->server, if($self->ssl_ca_file) {
PeerPort => $self->port, $self->socket(IO::Socket::SSL->new(PeerAddr => $self->server,
Proto => "tcp", PeerPort => $self->port,
LocalAddr => $self->hostname, Proto => "tcp",
)); LocalAddr => $self->hostname,
SSL_verify_mode => IO::Socket::SSL->SSL_VERIFY_PEER,
SSL_ca_file => $self->ssl_ca_file,
));
} elsif($self->ssl_ca_path) {
$self->socket(IO::Socket::SSL->new(PeerAddr => $self->server,
PeerPort => $self->port,
Proto => "tcp",
LocalAddr => $self->hostname,
SSL_verify_mode => IO::Socket::SSL->SSL_VERIFY_PEER,
SSL_ca_path => $self->ssl_ca_path,
));
} else {
$self->socket(IO::Socket::SSL->new(PeerAddr => $self->server,
PeerPort => $self->port,
Proto => "tcp",
LocalAddr => $self->hostname,
));
}
} else { } else {
$self->socket(IO::Socket::INET->new(PeerAddr => $self->server, $self->socket(IO::Socket::INET->new(PeerAddr => $self->server,

View File

@ -74,6 +74,10 @@ sub initialize {
$self->{module_dir} = delete $conf{module_dir} // "$ENV{HOME}/pbot/modules"; $self->{module_dir} = delete $conf{module_dir} // "$ENV{HOME}/pbot/modules";
$self->{ircserver} = delete $conf{ircserver} // "irc.freenode.net"; $self->{ircserver} = delete $conf{ircserver} // "irc.freenode.net";
$self->{port} = delete $conf{port} // 6667;
$self->{SSL} = delete $conf{SSL} // 0;
$self->{SSL_ca_file} = delete $conf{SSL_ca_file} // undef;
$self->{SSL_ca_path} = delete $conf{SSL_ca_path} // undef;
$self->{botnick} = delete $conf{botnick} // "pbot3"; $self->{botnick} = delete $conf{botnick} // "pbot3";
$self->{username} = delete $conf{username} // "pbot3"; $self->{username} = delete $conf{username} // "pbot3";
$self->{ircname} = delete $conf{ircname} // "http://code.google.com/p/pbot2-pl/"; $self->{ircname} = delete $conf{ircname} // "http://code.google.com/p/pbot2-pl/";
@ -171,12 +175,15 @@ sub connect {
$self->logger->log("Connecting to $server ...\n"); $self->logger->log("Connecting to $server ...\n");
$self->conn($self->irc->newconn( $self->conn($self->irc->newconn(
Nick => $self->{botnick}, Nick => $self->{botnick},
Username => $self->{username}, Username => $self->{username},
Ircname => $self->{ircname}, Ircname => $self->{ircname},
Server => $server, Server => $server,
Port => $self->{port})) SSL => $self->{SSL},
or Carp::croak "$0: Can't connect to IRC server.\n"; SSL_ca_file => $self->{SSL_ca_file},
SSL_ca_path => $self->{SSL_ca_path},
Port => $self->{port}))
or Carp::croak "$0: Can't connect to IRC server.\n";
$self->{connected} = 1; $self->{connected} = 1;

View File

@ -13,8 +13,8 @@ use warnings;
# These are set automatically by the build/commit script # These are set automatically by the build/commit script
use constant { use constant {
BUILD_NAME => "PBot", BUILD_NAME => "PBot",
BUILD_REVISION => 403, BUILD_REVISION => 404,
BUILD_DATE => "2013-02-12", BUILD_DATE => "2013-02-24",
}; };
1; 1;

View File

@ -12,7 +12,7 @@ my $RESULTS_SPECIFIED = 2;
my $search = join ' ', @ARGV; my $search = join ' ', @ARGV;
if(not length $search) { if(not length $search) {
print "Usage: c11std [-list] [-n#] [-section <section>] [search text] -- 'section' must be in the form of X.YpZ where X and Y are section/chapter and, optionally, Z is paragraph. If both 'section' and 'search text' are specified, then the search space will be within the specified section. You may use -n # to skip to the #th match. To list only the section numbers containing 'search text', add -list.\n"; print "Usage: c11std [-list] [-n#] [-section <section>] [search text] -- 'section' must be in the form of X.YpZ where X and Y are section/chapter and, optionally, pZ is paragraph. If both 'section' and 'search text' are specified, then the search space will be within the specified section. You may use -n # to skip to the #th match. To list only the section numbers containing 'search text', add -list.\n";
exit 0; exit 0;
} }

View File

@ -12,7 +12,7 @@ my $RESULTS_SPECIFIED = 2;
my $search = join ' ', @ARGV; my $search = join ' ', @ARGV;
if(not length $search) { if(not length $search) {
print "Usage: c99std [-list] [-n#] [-section <section>] [search text] -- 'section' must be in the form of X.YpZ where X and Y are section/chapter and, optionally, Z is paragraph. If both 'section' and 'search text' are specified, then the search space will be within the specified section. You may use -n # to skip to the #th match. To list only the section numbers containing 'search text', add -list.\n"; print "Usage: c99std [-list] [-n#] [-section <section>] [search text] -- 'section' must be in the form of X.YpZ where X and Y are section/chapter and, optionally, pZ is paragraph. If both 'section' and 'search text' are specified, then the search space will be within the specified section. You may use -n # to skip to the #th match. To list only the section numbers containing 'search text', add -list.\n";
exit 0; exit 0;
} }

View File

@ -12,7 +12,7 @@ my $RESULTS_SPECIFIED = 2;
my $search = join ' ', @ARGV; my $search = join ' ', @ARGV;
if(not length $search) { if(not length $search) {
print "Usage: cstd [-list] [-n#] [-section <section>] [search text] -- 'section' must be in the form of X.YpZ where X and Y are section/chapter and, optionally, Z is paragraph. If both 'section' and 'search text' are specified, then the search space will be within the specified section. You may use -n # to skip to the #th match. To list only the section numbers containing 'search text', add -list.\n"; print "Usage: cstd [-list] [-n#] [-section <section>] [search text] -- 'section' must be in the form of X.YpZ where X and Y are section/chapter and, optionally, pZ is paragraph. If both 'section' and 'search text' are specified, then the search space will be within the specified section. You may use -n # to skip to the #th match. To list only the section numbers containing 'search text', add -list.\n";
exit 0; exit 0;
} }

18
pbot.pl
View File

@ -26,6 +26,21 @@ my %config = (
# IRC server address to connect to # IRC server address to connect to
ircserver => 'irc.freenode.net', ircserver => 'irc.freenode.net',
# IRC port
port => '6667',
# Use SSL? 0 = disabled, 1 = enabled
# Note that you may need to use a specific port for SSL; e.g., freenode uses 6697 or 7000 for SSL
# Uncomment SSL_ca_path or SSL_ca_file below to enable SSL verification (will still work without
# verification, but will be susceptible to man-in-the-middle attacks)
SSL => 0,
# SSL CA certificates path; e.g., linux: /etc/ssl/certs
# SSL_ca_path => '/etc/ssl/certs',
# SSL CA file, if SSL_ca_path will not do; e.g., OpenBSD: /etc/ssl/cert.pem
# SSL_ca_file => '/etc/ssl/cert.pem',
# IRC nick (what people see when you talk in channels) # IRC nick (what people see when you talk in channels)
# (must be a nick registered with a NickServ account for channel auto-join to work) # (must be a nick registered with a NickServ account for channel auto-join to work)
botnick => 'pbot3', botnick => 'pbot3',
@ -62,6 +77,9 @@ my %config = (
# You shouldn't need to change anything below this line. # You shouldn't need to change anything below this line.
# ----------------------------------------------------- # -----------------------------------------------------
# Maximum messages to remember per nick/hostmask
MAX_NICK_MESSAGES => 256,
# Path to data directory # Path to data directory
data_dir => "$bothome/data", data_dir => "$bothome/data",