summaryrefslogtreecommitdiffstats
path: root/util/rtrfilter.in
diff options
context:
space:
mode:
authorTar Committer <tar@ocjtech.us>2004-01-12 03:17:26 +0000
committerTar Committer <tar@ocjtech.us>2004-01-12 03:17:26 +0000
commit989312339ea2e16579803a48700628c5469e327a (patch)
tree967ee77195819d70f2dc675444e92340bb98e0d6 /util/rtrfilter.in
parentff168ecfe045c690c24d5bbc5a3062bf9d64120c (diff)
downloadrancid-989312339ea2e16579803a48700628c5469e327a.tar.gz
rancid-989312339ea2e16579803a48700628c5469e327a.tar.xz
rancid-989312339ea2e16579803a48700628c5469e327a.zip
Imported from rancid-2.3.rc1.tar.gz.rancid-2.3.rc1
Diffstat (limited to 'util/rtrfilter.in')
-rwxr-xr-xutil/rtrfilter.in158
1 files changed, 0 insertions, 158 deletions
diff --git a/util/rtrfilter.in b/util/rtrfilter.in
deleted file mode 100755
index 28bd21a..0000000
--- a/util/rtrfilter.in
+++ /dev/null
@@ -1,158 +0,0 @@
-#!@PERLV_PATH@
-##
-## Copyright (C) 1997-2001 by Henry Kilmer.
-## All rights reserved.
-##
-## This software may be freely copied, modified and redistributed without
-## fee for non-commerical purposes provided that this copyright notice is
-## preserved intact on all copies and modified copies.
-##
-## There is no warranty or other guarantee of fitness of this software.
-## It is provided solely "as is". The author(s) disclaim(s) all
-## responsibility and liability with respect to this software's usage
-## or its effect upon hardware, computer systems, other software, or
-## anything else.
-#
-# rtrtfilter - "| rtrfilter -x <perl regex> -i <perl regex> -f <regex file> \
-# -u <From address> -s <subject> <rcpts>"
-# expects to read an email message on stdin containing a diff from
-# rancid and emails a filtered copy to <rcpts> with the subject of the
-# original msg or the contents of -s <subject>. the perl regex(es) specified
-# via -x or -i (exclusive and inclusive, respectively) are applied to the
-# router names (ie: files) from the "Index:" of the diff o/p. alternatively,
-# the regex's may be specified in -f <regex file> in the form:
-# # comment
-# x <regex>
-# # comment
-# i <regex>
-# do not include /'s in the regex's.
-# eg:
-# #i inc1
-# i a0[12]\.
-# i a0[34]\.
-# # comment
-# x router\.db
-# x ^r0[0-9]
-# #i foo
-#
-# exclusion takes precedence and defaults to nothing. inclusion defaults to
-# everything.
-#
-# this program requires the Mail::Mailer module which can be found on CPAN.
-##
-BEGIN {
-$me = $0;
-$me =~ s/.*\/(\S+)$/$1/;
-}
-
-require 'newgetopt.pl';
-use Mail::Mailer;
-
-# process command line options
-$newgetopt'ignorecase=0;
-$newgetopt'autoabbrev=1;
-$result = &NGetOpt('h','x=s@','i=s@','f=s','s=s');
-&usage($result) if (defined($opt_h) || $result == 0);
-
-if ($#ARGV < 0) {
- usage;
-}
-my($rcpts) = join(',', @ARGV);
-
-# if specified, read the regex file and append to @opt_i / @opt_x
-if (defined($opt_f)) {
- open(FILE, "< $opt_f") || die "Cant open the regex file $opt_f: $!";
-
- while (<FILE>) {
- next if (! /^(i|x)\s+(.*$)/);
- #/(i|x)\s+(.*)$/;
- if ($1 eq "i" ) {
- push(@opt_i, $2);
- } else {
- push(@opt_x, $2);
- }
- }
- close(FILE);
-}
-
-# read the header, grok the subject line
-my($subject, $from);
-while (<STDIN>) {
- last if (/^$/);
- if (s/^from: //i) {
- chomp;
- $from = $_;
- }
- if (s/^subject: //i) {
- chomp;
- $subject = $_;
- }
-}
-if (defined($opt_s)) { $subject = $opt_s;}
-if (defined($opt_u)) { $from = $opt_u;}
-
-# filter the remainder of the mail. save mail in memory to avoid empty msgs
-my(@mail);
-my($skip) = 1;
-while (<STDIN>) {
- # look for /^Index: ", the filtering key
- if (/^Index: (.*)$/) {
- # strip the directory before passing to filter()
- my($line) = ($1 =~ /.*\/([^\/\s]*)$/);
- $skip = filter($line);
- }
-
- next if ($skip);
-
- push(@mail, $_);
-}
-
-# send mail, if any
-if ($#mail < 0) { exit; }
-$mailer = new Mail::Mailer 'sendmail', ('-t');
-$headers{From} = $from;
-$headers{"Reply-To"} = $from;
-$headers{"Errors-To"} = $from;
-$headers{Subject} = $subject;
-$headers{To} = $rcpts;
-$headers{Precedence} = "bulk";
-
-$mailer->open(\%headers);
-print $mailer @mail;
-$mailer->close;
-
-exit;
-
-# filter $line inclusive/exclusive (0 / 1)
-sub filter {
- my($line) = shift;
-
- # exclusion
- if (defined(@opt_x)) {
- foreach $regex (@opt_x) {
- if ($line =~ /$regex/) { return(1); }
- }
- }
-
- # inclusion / default inclusion
- if (! @opt_i) { return(0); }
- foreach $regex (@opt_i) {
- if ($line =~ /$regex/) { return(0); }
- }
-
- # inclusion regex specified, but fall through
- return(1);
-}
-
-sub usage {
- print STDERR <<USAGE;
-usage: $me [-h] [-i <perl regex>] [-x <perl regex>] [-f <regex file>] [-u <From: address>] [-s <subject>] <mail rcpt> [<rcpt> ...]
- -h prints this message
- -f file containing perl regex matching router names (mind the cwd())
- -i perl regex matching router names (inclusive)
- -u From: address
- -s mail subject
- -x perl regex matching router names (exclusive)
-USAGE
- exit $_;
-}