Google

Thursday, March 16, 2006

This post is one of my post in dansguardian mail list.

Now i will tell how you will receive of the denied
site from linux to your predefined mail address.
I find a script for sending mail. Thanks these guys:)
We will use this script and assign a job to crontab
file and
you will receive denied site when you want. But i dont advice you receiving big mail from the server. But you wonder how it is done, so i am telling.
STEP1
Firstly copy the mime_mail script below and save it in
/bin .

#!/usr/bin/perl -w
#
# simple program to send a text message with an
attachment
#
# William Julien
###
#
# Create a new option to choose message type (text |
html)
# 08/27/04 Daniel Bauermann
###

use strict; # turn on the strict pragma
use Getopt::Std; # use standard getopt to parse
options

$/ = undef; # turn on slurp mode

#
# scope local variables
#
my ($date, # the current date
$sendmail, # the sendmail command
$document, # the document text
%options, # program options
$filename, # a file to send
$file, # the content of a file
@filelist, # list files to send
$tolist, # list of comma separated
email addresses
$today, # today's date
$usage, # program usage
$man, # program man page
$subject, # email subject
$extent, # file extension
%mime_type, # list of supported
application context mime types
$mime_type, # current mime application
content type
$typemessage, # define type message (new
option)
$headertypemessage, # content type message (new
option)
);

#
# variable initializations
#
$man = <NAME
mime_mail

DISCRIPTION
This program is a command line mailer that sends a
text file
description and one or more files in mime
attachments. On success,
mime_mail will work silently.

SYNOPSIS
mime_mail -h | -d document.txt -s "mail subject"
-u "user1 [,user2 ...]" -f "file1
[,file2 ...]" -t [text|html]

OPTIONS
-h
Displays a man page.

-d document.txt
Sends "document.txt" in the mail message body.
The file must
be a normal text file. If a "-" is provided as
an argument,
the input will be taken from stdin. If no "-d"
argument is
supplied, the attachment will be sent with the
message
"Please see the attached.".

-s "mail subject"
Sets the mail subject. The mail subject must
be quoted if the
subject contains any spaces.

-u user1,user2 ...
A comma separated list of email addresses or
aliases. Quotes
are required if the list contains any spaces.

-f file1,file2 ...
A comma separaed list of files to attach.
Quotes are required
if the list contains any spaces. The files can
be of any type.
The recognised application content types are
".doc", ".html",
,"htm",".xls", ".csv", ".pdf", ".rtf", and
".mdb".

-t [text|html]
Message type

William Julien
425-865-5511
MAN
$usage = <
Usage:
mime_mail -h | -d document.txt -s "mail subject"
-u "user1 [,user2 ...]" -f "file1 [,file2
...]" -t [text|html]
USAGE
$sendmail = "/usr/lib/sendmail";
if ( ! -f $sendmail ) {
die "Sorry -- cannot locate sendmail at
$sendmail.\nYou must edit $0\n";
}
$today = scalar(localtime());
%mime_type = ("doc" => "application/msword",
"txt" => "text/plain",
"htm" => "text/html",
"html" => "text/html",
"xls" => "application/vnd.ms-excel",
"csv" => "application/octet-stream",
"pdf" => "application/acrobat",
"rtf" => "application/rtf",
"mdb" => "application/vnd.ms-access",
);

#
# process program options
#
getopts('d:s:u:f:h:t', \%options) or die "$usage\n";
if ( defined $options{"h"} ) {
print "$man\n";
exit;
}
if ( defined $options{"f"} ) {
@filelist = split /\,/,$options{"f"};
foreach $file (@filelist) {
if (! -f $file) {
die "$0: cannot open $file\n";
}
}
} else {
die "$usage\n";
}
if ( defined $options{"d"} ) {
$document = $options{"d"};
if ( $document eq "-" ) {
$document = ;
} else {
if ( -f $document ) {
open F, "$document";
$document = ;
close F;
} else {
die "$0 error: cannot open $document\n";
}
}
} else {
$document = "Please see the attached.\n";
}
if ( defined $options{"s"} ) {
$subject = $options{"s"};
} else {
die "$usage\nError: No Subject\n";
}
if ( defined $options{"u"} ) {
$tolist = $options{"u"};
} else {
die "$usage\n$0 error: no subject specified\n";
}
#
# New option
#
if ( defined $options{"t"} ) {
$typemessage = $options{"t"};
} else {
$typemessage = "text";
}
if ( $typemessage eq "text" ) {
$headertypemessage = "Content-Type: text/plain;
charset=us-ascii\nContent-Transfer-Encoding: 7bit";
} else {
$headertypemessage = "Content-Type: text/html;\n
charset=\"iso-8859-1\"\nContent-Transfer-Encoding:
quoted-printable";
}
#
# End new option
#

open MAIL, "|$sendmail -t";
print MAIL <To: $tolist
Subject: $subject
Date: $today
Mime-Version: 1.0
Content-Type: multipart/mixed;
boundary="ThisRandomString"

This mail was formatted with mime_mail (wmj)

--ThisRandomString
$headertypemessage

$document
HEADER
foreach $filename (@filelist) {
$extent = $filename =~ /\.(\w+)$/ ? "\L$1" :
undef;
$mime_type = "application/octet-stream";
if ( defined $extent ) {
if ( defined $mime_type{"$extent"} ) {
$mime_type = $mime_type{"$extent"};
} else {
$mime_type = "application/octet-stream";
}
}
open F,"$filename";
$file = ;
close F;
$file = encode_base64($file);
print MAIL <--ThisRandomString
Content-Type: $mime_type; name="$filename"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="$filename"

$file
FILE
}
print MAIL "--ThisRandomString--\n";
#
# send the mail
#
close MAIL;

#
# fin
###

sub encode_base64
{
use integer;
my $res = "";
my $eol = $_[1];
$eol = "\n" unless defined $eol;
pos($_[0]) = 0; # ensure
start at the beginning
while ($_[0] =~ /(.{1,45})/gs) {
$res .= substr(pack('u', $1), 1);
chop($res);
}
$res =~ tr|` -_|AA-Za-z0-9+/|; # `#
help emacs
# fix padding at the end
my $padding = (3 - length($_[0]) % 3) % 3;
$res =~ s/.{$padding}$/'=' x $padding/e if
$padding;
# break encoded string into lines of no more than
76 characters each
if (length $eol) {
$res =~ s/(.{1,76})/$1$eol/g;
}
return $res;
}

and save it to /bin
dont forget to use chmod
"chmod 777 mime_mail"

Now it is time for writing the script for the schecule
job.

STEP2
vi mailme
filename=$(date '+%H_%d_%m_%g') # you get the name for
the accesslog after you grep the denied site you
should move your #accesslog to a new filename in order
not to grep the same denied sites .
echo $filename #your new log name format is
hour_day_mouth_year
grep -nr 'DENIED'
/where/is/your/dansguardian/access.log
>/var/log/denied #you grep the denied site and put
them in this #file /var/log/denied
cp /where/is/your/dansguardian/access.log
/where/is/your/dansguardian/$filename #grepped logs move to new file $filename
0>/where/is/your/dansguardian/access.log #you clean the content of your access.log #and by doing that you will not grep again and again the same denied sites
mime_mail -s "deniedsite" -u yourmail@yourdomain -f
/var/log/denied
##now save this script to /bin
chmod 777 mailme
STEP 3
you will edit the crontab file by using "crontab -e"
For example you want receive this mail from your
system at 21:00 clock everyday
"minute" "hour day of month" "month" "day of week"
0 21 * * * mailme
save and exit


now you will start receiving mail from your linux at
21:00 o clock everyday. I hope it will help you
:)Before doing this dont forget the backup your logs.

1 comment:

Anonymous said...

Bana 5.000.000,00 USD kredi veren kredi şirketi Diğer kredi yatırımcıları teklifimi ihmal ettiğinde ancak bay benjamin lee bana başarı kredisi verdiğinde. doğrudan kredi finansmanı ve yatırım açısından projeye giriyorlar. sermaye piyasası fonlarına erişim arayan şirketlere ve bireylere finansman çözümleri sağlarlar, projenizi finanse etmenize veya işinizi büyütmenize yardımcı olabilirler .. E-posta İletişim ::::
247officedept@gmail.com
+ 1- (989-394-3740) 'a whatsapp Numarasına yazın