#!/bin/perl -w # accerso - email to web page gateway # Created by Kevin P. Inscoe (kevin@inscoe.org) - December, 10, 2002 # Create a user and in the login directory put the following statement in # the .forward file: # # "|/usr/local/bin/accerso >> forward.log" # # The log file is optional. # # globals $vers="1.1"; $lynx="/usr/local/bin/lynx"; $mailprog='/usr/lib/sendmail'; $url=""; $fail=0; $tmp=""; $in=""; $collect=0; $date=scalar localtime(); $line=0; $gotit=0; while (<>) { $line++; print "[$line] $_"; # get reply address if ( /^From / ) { @fields = split (/ /, $_); $from = $fields[1]; } # get url - message body starts after two consectutive nulls s/^\s+//; s/\s+$//; if ( $collect == 1 && $gotit == 0 ) { $url = $_; $gotit=1; print "GOTIT!\n" } if ( $_ eq "" ) { $collect=1; print "blankline.\n" } else { $collect=0; } } # Cleanup the URL $url =~ s/^\s+//; $url =~ s/\s+$//; # download content @FullQuery = ($lynx,"-dump", $url); # do the queries, by using "lynx -dump URL" open(LYNX, "-|") || exec (@FullQuery); while ($in = ) { $tmp .= $in; } close(LYNX); if ( $tmp eq "" ) { $fail++; } if (index($tmp,"access start file") > -1) { $fail++; } if (index($tmp,"Start file") > -1) { $fail++; } if (index($tmp,"Alert!") > -1) { $fail++; } # return result if ( $fail > 0 ) { $tmp = "Could not obtain url. $url\n\n$tmp" } if ((open (MAIL, "|$mailprog -t $from")) == 1) { } else { print MAIL "From: Accerso Web \n"; print MAIL "Subject: Web Fetch Results\n\n"; print MAIL "URL: $url\n\n$tmp\n\n"; print MAIL "$date\n\n"; print MAIL "Generated by Accerso Web Appliance - http://inscoe.org/pub/scripts/accerso.pl.txt"; close (MAIL); # Print log print "FROM: $from URL: $url DATE: $date\n"; }