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