Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 460 lines (325 sloc) 13.776 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
#!/usr/bin/perl

use warnings;
use strict;

use lib qw(. ./lib);

our $VERSION = '0.541';

use File::Basename;
use Perl::Tidy;

use POE;
use Bot::Pastebot;
use Bot::Pastebot::Conf;
use Bot::Pastebot::Data;
use Bot::Pastebot::Client::Irc;
use Bot::Pastebot::Server::Http;
use Bot::Pastebot::Administrivia qw/uses_pidfile get_pid write_pidfile/;

my %conf = (
  Bot::Pastebot::Data->get_conf(),
  Bot::Pastebot::Client::Irc->get_conf(),
  Bot::Pastebot::Server::Http->get_conf(),
  Bot::Pastebot::Administrivia->get_conf(),
);

# Command line options.

my $conf_file = Bot::Pastebot::Conf->get_conf_file();
Bot::Pastebot::Conf->load($conf_file, \%conf);

if (uses_pidfile() && (my $pid = get_pid()) ) {
  die(
    "pastebot seems to be running as PID $pid.\n",
    "Please check if this is the case.\n",
  );
} elsif( uses_pidfile() ) {
  write_pidfile();
}

Bot::Pastebot::Data->initialize();
Bot::Pastebot::Client::Irc->initialize();
Bot::Pastebot::Server::Http->initialize();

POE::Kernel->run();
exit 0;

sub HELP_MESSAGE {
  my $output = shift;
  print $output "usage:\n";
  print $output " $0 -f file.conf (configure and run a pastebot)\n";
  print $output "\n";
  print $output " You can read pastebot's documentation with the\n";
  print $output " perldoc command. Run: perldoc pastebot\n";
  exit;
}

sub VERSION_MESSAGE {
  my $output = shift;
  print $output "$0 version $VERSION\n";
}

__END__

=head1 NAME

pastebot - the original clipboard to chat gateway

=head1 SYNOPSIS

pastebot -f configfile

=head1 DESCRIPTION

Pastebot is an IRC bot and a web server in one program. Users submit
short pieces of text to the web server, and the IRC bot announces them
in IRC.

A single pastebot instance can provide one or more web servers, each
accepting connections on a different virtual host and/or port.

Likewise, a single pastebot may connect to zero or more IRC networks
and announce pastes on zero or more channels on each. The pastebot
merely acts as a web service in zero-bot mode.

=head1 CONFIGURATION SYNTAX

Nearly all of pastebot's options are set in a configuration file. The
general syntax for this file follows these rules:

Sections are defined by text that begins in the first column. Section
parameters are indented and consist of a parameter name and its value
separated by whitespace. This example defines a web_server section
named "poenet" that listens on port 8888.

web_server
name poenet
port 8888

Each section defines a component type within the pastebot. Each
section requires a unique name since there may be more than one
instance of a component. The names permit the program to reference
specific components without confusion.

Some parameters may contain multiple values, though. Each value is
defined on a separate configuration line using the same parameter
name. For example, it's useful to configure multiple IRC servers for
a bot to choose from. If one server is unavailable, it can try
another. Here's how that's done:

irc
name efnet
server irc.carrier1.net.uk 6667
server irc.daxnet.no 6667

Configuration files may contain comments, which are text after a hash
mark ("#"). Comments and blank lines are ignored.

# Configure the paste database.
pastes
expire 86400

That's all.

=head1 CONFIGURING PASTEBOT

Pastebot configuration is broken down into three section types:
"web_server", "irc", and "pastes". They define the web server, irc
network, and paste database that the bot will use.

=head2 Optional Administrivia

These settings make it easier to administrate pastebot. Right now it
only covers a PID file, but may be expanded upon in the future. This
entire section is optional, but is global for the bot.

A sample:

administrivia
name administrivia
pidfile /var/run/pastebot.pid

=over 2

=item name

The name for this section. 'administrivia' is simple and clear, but
it's not limited to this.

=item pidfile

A path, absolute or relative, that will hold a PID for the bot. Upon
startup, this file will be read and its contents interpreted as a
PID. If this PID is running, pastebot will exit with a message
notifying the administrator of this fact. If this PID is not
running, pastebot will write its own PID to the pidfile before
continuing.

=back

=head2 Configuring a Web Server

The web_server section defines a pastebot's web server. A pastebot
may have more than one web server. Each web server is defined in a
separate web_server section, and each must have a different name.

A sample:

web_server
iface 10.0.0.80
ifname poe.perl.org
iname http://poe.perl.org:8888/
irc freenode_irc
name freenode_web
port 8888
proxy 127.0.0.1
static /path/to/static
template Bot::Pastebot::TextTemplate

=over 2

=item iface HOST_OR_ADDRESS

Defines the interface host or numeric address that this web server
will bind to while listening for new connections. It's common for the
interface address to be different than the one the outside world sees.
Required.

=item ifname HOST_OR_ADDRESS

Defines the web server's public address, which is displayed to users
in various messages and may be different than the internal address the
web service has bound to. Optional. If omitted, the value of "iface"
will be used instead.

=item iname BASE_URL

The "home page" for the pastebot's web server. It's advertised in
multiple places, such as the bot's WHOIS information. The BASE_URL
should agree with "ifname" and "port". Optional.

=item irc IRC_NAME

Identifies the IRC bot that will announce paste URLs. The IRC_NAME is
the name of the bot as specified by the "name" parameter of the "irc"
section. Required.

=item name NAME

Defines the web server's name. Each web server must have its own name
so they can be referenced individually. The web server's name is also
used in web page titles and IRC announcements. Required.

=item port PORT_NUMBER

This is the port the web server listens on. Required.

=item proxy ADDRESS

Optional. Used when the pastebot's web server is behind a proxy.
Identifies the proxy so it may be ignored when headers are examined.

=item static STATIC_PATH

Optional. Defines the directory that contains static files that will
be provided by the pastebot's built-in web server. Templates,
graphics, and style sheets for the various served pages go here. It
is essentially the Pastebot server's document root. Each web server
is permitted to have its own static directory.

The Pastebot comes with a set of default static files that will be
used if "static" is not specified. The files are installed in
Bot::Pastebot's architecture-dependent auto directory, which may be
found by running the following Perl command:

perl -MFile::ShareDir=dist_dir -wle 'print dist_dir("Bot-Pastebot")'

If "static" is omitted, the default files will be loaded from that
directory.

=item template CLASS

Optional. Defines the class that implements the templating for generated
pages. The class must define specific methods, see
L<Bot::Pastebot::TextTemplate> for which methods and return values are
expected.

=back

=head2 Configuring an IRC Bot

The irc section defines a pastebot's IRC bot. A pastebot may have
zero, one, or more IRC bots. Each bot is defined in a separate irc
section, and each must have a different name. A pastebot with no IRC
bots is a web-only service.

A sample:

irc
away saving humanity from evil paste
ccinfo ACTION VERSION CLIENTINFO USERINFO
channel pastebot
channel perl
channel poe
channel \#\#perl
cuinfo owned and operated by rcaputo <rcaputo@cpan.org>
cver pastebot 1.0 <http://thirdlobe.com/projects/pastebot/>
flags +i
iname http://poe.perl.org:8888/
join_cfg_only 1
localaddr poe.perl.org
name freenode_irc
nick eatpaste
nick pastebot
quit how will you live without me?
server irc.freenode.net 6667
server irc.freenode.net 7000
uname pastebot
nickserv_pass password

=over 2

=item away AWAY_MESSAGE

Pastebots set themselves "away" immediately when they connect to IRC.
They run unattended, so there is nobody to answer any messages. This
parameter sets the message that will be displayed to anyone examining
the bot's WHOIS information.

=item ccinfo CTCP_CLIENT_INFO

Sets the bot's CTCP CLIENTINFO response. Optional, but some networks
require that clients respond to client information requests.

=item channel CHANNEL

Required. Defines the channel or channels that the pastebot will
automatically join when it connects to this IRC network. A pastebot
may join multiple channels, each defined as a separate "channel"
entry. The channel prefix '#' may be escaped with a '\' allowing
the bot to join channels such as ##perl (\#\#perl).

=item cuinfo CTCP_USER_INFO

Sets the bot's CTCP USERINFO response. Optional, but some networks
require that clients respond to user information requests.

=item cver CTCP_VERSION_INFO

Sets the bot's CTCP VERSION response. Optional, but some networks
require that clients respond to version requests.

=item flags USER_FLAGS

Optional. When specified, sets the user flags that the pastebot will
set once it has connected to the IRC network. Commonly set to "+i" so
the bot will be "invisible" outside the channels it's currently on.
This helps reduce the amount of harassment the bot receives.

=item iname IRC_NAME

The pastebot's "IRC name", which is what appears in WHOIS information.
By convention, pastebots include their home page URLs here. Be sure
the URL's host and port match "ifname" and "port" in the appropriate
web_server section. Required.

=item join_cfg_only BOOLEAN

Optional. Defaults to 0 (false). Normally a pastebot will join any
channel it's invited into. When join_cfg_only is true, however, the
pastebot will only join channels that have been specified in its
configuration file.

=item localaddr ADDRESS

Optional. The localaddr specifies an ADDRESS that the bot will bind
to before making connections. This allows the bot to appear online as
coming from a particular virtual host ADDRESS, if its host machine has
more than one.

=item name NAME

Required. This is the IRC bot's internal name. To be useful, it
should match the "irc" parameter in one of the web_server sections.

=item nick NICKNAME

Required. Specifies the bot's nickname on the IRC network. A bot may
have multiple nicknames, each specified as a separate configuration
line. It will attempt to use them in order, skipping to the next in
the list as it determines each is already taken. If every nickname is
taken, it will append numeric digets to the names and try again.

The pastebot will periodically try to reclaim one of the original
nicknames in its configuration.

=item quit QUIT_MESSAGE

This sets the pastebot's quit message should it need to log off for
any reason.

=item server SERVER PORT

Sets the IRC server and port to connect to. Required. The pastebot
can connect to one of several servers, each specified on a different
"server" line. If one is unavailable, it will rotate to the next.

=item uname USER_NAME

IRC requires clients to send a short "user name" when establishing a
connection. This parameter specifies that name.

=item nickserv_pass PASSWORD

Specifies the password to use to identify to the NickServ nickname
service. Upon connecting to the irc server, the command
"/msg NickServ IDENTIFY PASSWORD" will be issued to identify the bot
to the NickServ service.

=back

=head2 Configuring Pastebot's Database

Pastebot must store uploaded text somewhere.

pastes
check 3600
count 0
expire 864000
name pasty
store /home/troc/.pastebot

=over 2

=item check SECONDS

How often to check for expired pastes. The value is the number of
SECONDS between each check. 3600 is an hour, 86400 is a day.

Performing expiration checks too frequently will slow down the bot.
Currently these checks are done within the main process, which is
cooperatively multitasked. The entire bot pauses while the check
occurs.

TODO - Revise the expiration check to work cooperatively, or fork it
into a separate process altogether.

=item count MAX_PASTES

Set a limit on the number of pastes a pastebot's database may hold,
regardless whether they're too young to expire. This limit will be
disabled if MAX_PASTES is zero.

If set, only the MAX_PASTES newest pastes will remain after a periodic
expiration check.

=item expire MAX_AGE_SECONDS

Sets the maximum limit for the age of pastes to retain. This limit
may be disabled if MAX_AGE_SECONDS is zero. If set, however, pastes
that are older than MAX_AGE_SECONDS will be purged during a periodic
expiration check.

=item name NAME

Defines the database's name. Each database must have a unique name so
they may be addressed individually. Database names are not currently
used, but the configuration parser requires every component to be
named.

=item store DIRECTORY

Sets the absolute path of the base directory in which pastes will be
stored. This directory will be created if it doesn't exist. Parent
directories will not be created, however.

=back

=head1 BUG TRACKER

https://rt.cpan.org/Dist/Display.html?Queue=Bot-Pastebot

=head1 REPOSITORY

http://github.com/~rcaputo/bot-pastebot
http://gitorious.org/bot-pastebot

=head1 OTHER RESOURCES

http://search.cpan.org/dist/Bot-Pastebot/
irc://irc.perl.org/poe

=head1 AUTHORS & COPYRIGHT

Pastebot is Copyright (C) 2002-2010 by Rocco Caputo. All rights are
reserved. Pastebot is free software; you may redistribute and/or
modify it under the same terms as Perl itself.

=cut
Something went wrong with that request. Please try again.