Bot-Pastebot
view release on metacpan or search on metacpan
lib/Bot/Pastebot/Server/Http.pm view on Meta::CPAN
# TODO - Better type support.
if ($filename =~ /\.(gif|jpe?g|png)$/i) {
$type = lc($1);
$type = "jpeg" if $type eq "jpg";
$type = "image/$1";
}
}
else {
$code = 500;
$type = "text/html";
$content = (
"<html><head><title>File Error</title></head>" .
"<body>Error opening $filename: $!</body></html>"
);
}
}
else {
$code = 404;
$type = "text/html";
$content = (
"<html><head><title>404 File Not Found</title></head>" .
"<body>File $filename does not exist.</body></html>"
);
}
my $response = HTTP::Response->new($code);
$response->push_header('Content-type', $type);
$response->content($content);
$heap->{wheel}->put( $response );
return;
}
### Store paste.
if ($url =~ m,/paste$,) {
my $content = parse_content($request->content());
if (defined $content->{paste} and length $content->{paste}) {
my $channel = $content->{channel};
defined $channel or $channel = "";
$channel =~ tr[\x00-\x1F\x7F][]d;
my $remote_addr = $heap->{remote_addr};
if ($heap->{my_proxy} && $remote_addr eq $heap->{my_proxy}) {
# apache sets the X-Forwarded-For header to a list of the
# IP addresses that were forwarded from/to
my $forwarded = $request->headers->header('X-Forwarded-For');
if ($forwarded) {
($remote_addr) = $forwarded =~ /([^,\s]+)$/;
}
# else must be local?
}
my $error = "";
if (length $channel) {
# See if it matches.
if (is_ignored($heap->{my_isrv}, $channel, $remote_addr)) {
$error = (
"<p><b><font size='+1' color='#800000'>" .
"Your IP address has been blocked from pasting to $channel." .
"</font></b></p>"
);
$channel = "";
}
}
# Goes as a separate block.
if (length $channel) {
unless (grep $_ eq $channel, channels($heap->{my_isrv})) {
$error = (
"<p><b><font size='+1' color='#800000'>" .
"I'm not on $channel." .
"</font></b></p>"
);
$channel = "";
}
}
my $nick = $content->{nick};
$nick = "" unless defined $nick;
$nick =~ tr[\x00-\x1F\x7F][ ]s;
$nick =~ s/\s+/ /g;
$nick =~ s/^\s+//;
$nick =~ s/\s+$//;
$nick = substr($nick, 0, 30);
$nick = html_encode($nick);
if (length $nick) {
$nick = qq("$nick");
}
else {
$nick = "Someone";
}
$nick .= " at $remote_addr";
# <CanyonMan> how about adding a form field with a "Subject"
# line ?
my $summary = $content->{summary};
$summary = "" unless defined $summary;
$summary =~ tr[\x00-\x1F\x7F][ ]s;
$summary =~ s/\s+/ /g;
$summary =~ s/^\s+//;
$summary =~ s/\s+$//;
# <TorgoX> [...] in the absence of anything in the subject, it
# falls back to [the first 30 characters of what's pasted]
my $paste = $content->{paste};
unless (length($summary)) {
$summary = $paste;
$summary =~ s/\s+/ /g;
$summary =~ s/^\s+//;
$summary = substr($summary, 0, 30);
$summary =~ s/\s+$//;
}
$summary = "something" unless length $summary;
my $html_summary = html_encode($summary);
( run in 0.461 second using v1.01-cache-2.11-cpan-39bf76dae61 )