File: log.pl

package info (click to toggle)
dircproxy 1.0.5-5etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 1,120 kB
  • ctags: 740
  • sloc: ansic: 9,466; sh: 2,946; makefile: 113; perl: 70
file content (120 lines) | stat: -rwxr-xr-x 2,765 bytes parent folder | download | duplicates (9)
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
#!/usr/bin/perl
# Perl script to take dircproxy log information and e-mail it to
# an address if it contains certain words or is from certain people.
#
# To use, set the following in dircproxyrc:
#   chan_log_program "/path/to/log.pl"
#  or
#   other_log_program "/path/to/log.pl"
#

use vars qw/$mailto @match @from $sendmail/;
use strict;

# Address to e-mail to
$mailto = 'nobody@localhost';

# Words to match on
@match = ('rabbit', 'llama');

# People to always send
@from = ('Joe', 'Bloggs');

# Path to sendmail
$sendmail = '/usr/lib/sendmail';


#------------------------------------------------------------------------------#

# The first argument to this script is the source of the text.  Its in the
# following formats
#
# -dircproxy-
#     Notice from dircproxy
#
# -servername-
#     Notice from a server
#
# <nick!username@host>
#     Private message from a person
#
# -nick!username@host-
#     Notice from a person
#
# [nick!username@host]
#     Unfiltered CTCP message (usually an ACTION) from a person
#

my $source = shift(@ARGV);
die "No source given by dircproxy" unless $source && length $source;

my $notice = ($source =~ /^-/ ? 1 : 0);
$source =~ s/^.//;
$source =~ s/.$//;

my ($nickname, $username, $hostname);
my $server = 0;
if ($source =~ /^([^!]*)!([^\@]*)\@(.*)$/) {
	($nickname, $username, $hostname) = ($1, $2, $3);
} else {
	$nickname = $source;
	$server = 1 if $notice;
}


#------------------------------------------------------------------------------#

# The second argument to this script is who it was to (your nickname or
# a channel name)

my $dest = shift(@ARGV);


#------------------------------------------------------------------------------#

# The text to log is on the standard input.

my $text = <STDIN>;
die "No text given by dircproxy" unless $text && length $text;


#------------------------------------------------------------------------------#

my $mailit = 0;

# Always mail server messages (including those from dircproxy)
$mailit = 1 if $server;

# Check the from
foreach my $from (@from) {
	$mailit = 1 if lc($nickname) eq lc($from);
}

# Check the text
foreach my $match (@match) {
	$mailit = 1 if $text =~ /$match/i;
}

#------------------------------------------------------------------------------#

if ($mailit) {
	my $subject = "";
	if ($server) {
		$subject .= "Server message";
	} elsif ($notice) {
		$subject .= "Notice";
	} else {
		$subject .= "Message";
	}
	$subject .= " from " . $nickname;
	$subject .= " ($username\@$hostname)" unless $server;
	
	open MAILER, '|' . $sendmail . ' -t';
	print MAILER "From: dircproxy\n";
	print MAILER "To: $mailto\n";
	print MAILER "Subject: $subject\n";
	print MAILER "\n";
	print MAILER "Sent to $dest\n" if $dest;
	print MAILER $text;
	close MAILER;
}