| 1 |
#!/usr/bin/perl -I../Modules -I ../Bot-BasicBot/lib |
|---|
| 2 |
# Copyright (C) 2006, 2007 Software Freedom Law Center, Inc. |
|---|
| 3 |
# Author: Bradley M. Kuhn <bkuhn@softwarefreedom.org> |
|---|
| 4 |
# |
|---|
| 5 |
# This software gives you freedom; it is licensed to you under version |
|---|
| 6 |
# 3 of the GNU Affero General Public License. |
|---|
| 7 |
# |
|---|
| 8 |
# This software is distributed WITHOUT ANY WARRANTY, without even the |
|---|
| 9 |
# implied warranties of MERCHANTABILITY and FITNESS FOR A PARTICULAR |
|---|
| 10 |
# PURPOSE. See the GNU Affero General Public License for further |
|---|
| 11 |
# details. |
|---|
| 12 |
# |
|---|
| 13 |
# You should have received a copy of the GNU Affero General Public |
|---|
| 14 |
# License, version 3 along with this software. If not, see |
|---|
| 15 |
# <http://www.gnu.org/licenses/>. |
|---|
| 16 |
|
|---|
| 17 |
use strict; |
|---|
| 18 |
use warnings; |
|---|
| 19 |
|
|---|
| 20 |
use Bot::BasicBot::Log; |
|---|
| 21 |
|
|---|
| 22 |
use Unix::Syslog qw(:subs); |
|---|
| 23 |
use Unix::Syslog qw(:macros); |
|---|
| 24 |
use Date::Manip; |
|---|
| 25 |
|
|---|
| 26 |
my $PID_FILE = "/home/ircbot/pids/log-bot.pid"; |
|---|
| 27 |
|
|---|
| 28 |
my $PAGE_EMAIL = 'page@example.org'; |
|---|
| 29 |
|
|---|
| 30 |
my @CHANNELS = ( { channel => "#mainchannel", |
|---|
| 31 |
password => 'PASS' }); |
|---|
| 32 |
|
|---|
| 33 |
############################################################################### |
|---|
| 34 |
{ |
|---|
| 35 |
my %messageHistory; |
|---|
| 36 |
|
|---|
| 37 |
sub WarnLog ($$) { |
|---|
| 38 |
my($now, $message) = @_; |
|---|
| 39 |
|
|---|
| 40 |
syslog LOG_INFO, $message; |
|---|
| 41 |
|
|---|
| 42 |
my $lastTime = $messageHistory{$message}; |
|---|
| 43 |
|
|---|
| 44 |
my $sendIt = 0; |
|---|
| 45 |
if (not defined $lastTime) { |
|---|
| 46 |
$sendIt = 1; |
|---|
| 47 |
} else { |
|---|
| 48 |
my $err; |
|---|
| 49 |
my $sinceLast = DateCalc($lastTime,"+ 10 minutes",\$err); |
|---|
| 50 |
$sendIt = 1 if ($now gt $sinceLast); |
|---|
| 51 |
} |
|---|
| 52 |
if ($sendIt) { |
|---|
| 53 |
open(SENDMAIL, "|/usr/sbin/sendmail -f root\@example.org -t"); |
|---|
| 54 |
print SENDMAIL "To: $PAGE_EMAIL\nFrom: root\@example.org\n", |
|---|
| 55 |
"Subject: IRC, LOG\n\n$message\n.\n"; |
|---|
| 56 |
close(SENDMAIL); |
|---|
| 57 |
if ($? != 0) { |
|---|
| 58 |
syslog LOG_INFO, "Unable to perform sendmail: $!"; |
|---|
| 59 |
} else { |
|---|
| 60 |
$messageHistory{$message} = $now; |
|---|
| 61 |
} |
|---|
| 62 |
} |
|---|
| 63 |
} |
|---|
| 64 |
} |
|---|
| 65 |
############################################################################### |
|---|
| 66 |
|
|---|
| 67 |
my($server, $channel, $nick) = ($ARGV[0], $ARGV[1], $ARGV[2]); |
|---|
| 68 |
unless (defined $server and defined $channel) { |
|---|
| 69 |
$server = "localhost"; |
|---|
| 70 |
$channel = "#mainchannel"; |
|---|
| 71 |
} |
|---|
| 72 |
if ($channel eq "#mainchannel") { |
|---|
| 73 |
$channel = [ { channel => "#mainchannel", |
|---|
| 74 |
password => 'PASS', |
|---|
| 75 |
invite_nick => 'ChanServ'}]; |
|---|
| 76 |
} else { |
|---|
| 77 |
$channel = [ { channel => "$channel" } ]; |
|---|
| 78 |
} |
|---|
| 79 |
open(PASSWORD, "</home/ircbot/passwords/log") |
|---|
| 80 |
or die "unable to open password file: $!"; |
|---|
| 81 |
my(%passwords); |
|---|
| 82 |
foreach my $line (<PASSWORD>) { |
|---|
| 83 |
chomp $line; |
|---|
| 84 |
next unless $line =~/^\s*(\S+)\s*:\s*(\S+)\s*$/; |
|---|
| 85 |
$passwords{$1} = $2; |
|---|
| 86 |
} |
|---|
| 87 |
close PASSWORD; |
|---|
| 88 |
|
|---|
| 89 |
die "Unable to find password in password file" |
|---|
| 90 |
unless defined $passwords{nick_password} |
|---|
| 91 |
and defined $passwords{server_password}; |
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
open(PID, ">$PID_FILE") or WarnLog(ParseDate("today"), |
|---|
| 95 |
"unable to write to $PID_FILE: $!"); |
|---|
| 96 |
print PID "$$\n"; |
|---|
| 97 |
close PID; |
|---|
| 98 |
|
|---|
| 99 |
$nick = 'log' if not defined $nick; |
|---|
| 100 |
|
|---|
| 101 |
my $bot = Bot::BasicBot::Log->new(channels => $channel, |
|---|
| 102 |
nick_password => $passwords{nick_password}, |
|---|
| 103 |
server => $server, |
|---|
| 104 |
port => "6667", |
|---|
| 105 |
nick => $nick, |
|---|
| 106 |
password => $passwords{server_password}, |
|---|
| 107 |
ssl => 1, |
|---|
| 108 |
username => "Logger", |
|---|
| 109 |
name => "SFLC Logging Bot", |
|---|
| 110 |
logFileDirectory => "/home/ircbot/channelLogs", |
|---|
| 111 |
logInviteUserList => [ '#*EVERYONE' ], |
|---|
| 112 |
logNeverLeaveChannelList => [ '#mainchannel' ] |
|---|
| 113 |
); |
|---|
| 114 |
|
|---|
| 115 |
$bot->run() or WarnLog(ParseDate("today"), "Bot died."); |
|---|
| 116 |
|
|---|
| 117 |
############################################################################### |
|---|
| 118 |
# |
|---|
| 119 |
# Local variables: |
|---|
| 120 |
# compile-command: "perl -I./modules -c logging-bot.plx" |
|---|
| 121 |
# End: |
|---|
| 122 |
|
|---|