#!/usr/bin/perl ############################################################################# # v1.7 Needs perl5; edit path above to the location of your perl install # Run as root the first time to setup the index # or change $indexpath # This is a work in progress but i'm really happy with how easy it's # made my life. Written by freix/sifr #linuxhelp efnet # bug fixes/suggestions mail me at rfc@evilution.org ############################################################################# # TO DO # don't have grep at all so there are zero compat. issues # clean up and optimize some # have url numbers generated by array placement in -w ############################################################################# # Feel free to redistribute as long as you keep this header in tact. # http://www.dewn.com/rfc/ ############################################################################# use strict; my ($indexlength,$indexpath,$grepper,$rfcvar,$rfcbaseurl); my $homedir=glob("~/"); $indexpath="/etc/rfc-index"; #This makes it available for all users; change if you can't run it as root $grepper= "/usr/bin/egrep"; #Sun users want 'gegrep' my @URLS=qw(http://www.ietf.org/rfc/ http://www.faqs.org/rfc/ http://www.isi.edu/in-notes/ http://http://www.cis.ohio-state.edu/htbin/rfc); if (not -e "$homedir.rfcrc") {`echo $URLS[0] > $homedir.rfcrc`; print "\#\#Creating $homedir.rfcrc\n"; chomp($rfcbaseurl=`cat $homedir.rfcrc`) } else {chomp($rfcbaseurl=`cat $homedir.rfcrc`)} if ($ARGV[0] ne "-i" and not -e "$indexpath") {print "\nNo rfc-index!!! Run with the -i option to download it!\n" . " (as root if you didn't change \$indexpath)\n" . "usage: rfc -i updates the $indexpath via lynx\n\n";exit} my $grepstring = $ARGV[0]; unless ($grepstring) { die "rfc v1.7: perl util to search the rfc-index and disply the pages with lynx\n" . "usage: rfc \# search rfc-index for specified RFC and list topic\n" . "\trfc -d \# \/path\/ (optional) dumps plain text RFC. default is current dir\n" . "\trfc -e go wild with your own regexp on rfc-index\n" . "\trfc -h displays this stuff\n" . "\trfc -i updates the $indexpath via lynx\n" . "\trfc -k keyword; same as -s\n" . "\trfc -l \# spawns lynx to the specified RFC\n" . "\trfc -m \# user\@remote.net emails the RFC to specified address\n" . "\trfc -s \"string\" to search for in the index\n" . "\trfc -u \# sets the base URL to the number listed with -w\n" . "\trfc -w lists the available webservers to display\n" . "baseURL=$rfcbaseurl\n" . "comments\/bugfixes mailto: rfc\@dewn.com\n\n"; } my ($grepmod,$caretmod); if (int($ARGV[0]) != 0) { $grepmod = int($ARGV[0]); } else { $grepmod = int($ARGV[1]); } my $numdigits = length($grepmod); while ($numdigits < 4) { $grepmod = "0" . $grepmod; $numdigits++; } if ($ARGV[0] eq "-i") { `touch $indexpath`; chomp(my $indexlength=`wc -l $indexpath`); print "Modem users one moment, it's about 400k \(doesn't need to be updated often\)\n"; print "original lines \t= $indexlength\n"; system ("lynx -dump http://www.faqs.org/rfc/rfc-index.txt > $indexpath"); chomp(my $indexlength=`wc -l $indexpath`); print "new lines \t= $indexlength\n"; exit } $caretmod = "^$grepmod"; my ($index); $index = `$grepper -A3 $caretmod $indexpath`; #works for rfc numbers if ($ARGV[0] eq "-d") { if (defined $ARGV[1]) { print "Making... $ARGV[2]rfc$grepmod.txt\n"; system ("lynx -dump $rfcbaseurl"."rfc$grepmod.txt > $ARGV[2]rfc$grepmod.txt"); chomp(my $dumplength=`wc -l $ARGV[2]rfc$grepmod.txt`); print "lines = $dumplength .. "; print "Done.\n"; exit; } else { print "Must specify the RFC to dump!\n"; print "\trfc -d \# \/path\/-optional; dumps plain text RFC. default is current dir\n"; exit } } if ($ARGV[0] eq "-e") { if (defined $ARGV[1]) { print "here's egrep's argv $ARGV[1]\n"; $index = `$grepper $ARGV[1] $indexpath`; } else { print "Must give a regular expression in quotes!\n"; print "\trfc -e go wild with your own regexp on $indexpath\n"; exit } } if ($ARGV[0] eq "-k" or $ARGV[0] eq "-s") { $index = `grep -i '$ARGV[1]' $indexpath`; #works for key words } if ($ARGV[0] eq "-l") { if (defined $ARGV[1]) { exec "lynx $rfcbaseurl"."rfc$grepmod.txt"; } else {print "Need to specify the RFC to display!\n"; print "\trfc -l \# spawns lynx to the specified RFC\n"; exit }} ### email the rfc if ($ARGV[0] eq "-m") { if (defined $ARGV[1] and $ARGV[2]) { print "Retreiving rfc$grepmod.txt...\n"; system ("lynx -dump $rfcbaseurl"."rfc$grepmod.txt > $homedir.rfc$grepmod.txt"); print "Mailing $ARGV[2]\n"; open(RFC, "$homedir.rfc$grepmod.txt"); open(MAIL, "| sendmail -t "); print MAIL "To: $ARGV[2]\n"; print MAIL "Subject: RFCutil:- $rfcbaseurl"."rfc$grepmod.txt\n"; print MAIL ; close (MAIL); close (RFC); `rm $homedir.rfc$grepmod.txt`; exit; } else { print "Must specify the RFC and email addy!!\n"; print "\trfc -m \# user\@remote.net; emails plain text RFC to specified address\n"; exit } } if ($ARGV[0] eq "-u") { if (defined $ARGV[1]) { my $url=($ARGV[1] - 1); `echo $URLS[$url] > $homedir.rfcrc`; chomp(my $rfcbaseurl=`cat $homedir.rfcrc`); print "BaseURL is $rfcbaseurl\n"; exit; } else { print "Must specify a \# of the webserver listed in -w !!\n"; print "\trfc -u \# sets the base URL to the number listed with -w\n"; print "BaseURL is $rfcbaseurl\n"; exit}} if ($ARGV[0] eq "-w") { print "Use -u # to set the URL\n"; print "1) http://www.ietf.org/rfc/\n"; #make sure you have the trailing / print "2) http://www.faqs.org/rfc/\n"; #make sure you have the trailing / print "3) http://www.isi.edu/in-notes/\n"; #make sure you have the trailing / print "4) http://http://www.cis.ohio-state.edu/htbin/rfc/\n"; print "BaseURL is $rfcbaseurl\n"; exit } if ($ARGV[0] eq "-h") { print "rfc v1.7: perl util to search the rfc-index and disply the pages with lynx\n" . "usage: rfc \# search rfc-index for specified RFC and list topic\n" . "\trfc -d \# \/path\/ (optional) dumps plain text RFC. default is current dir\n" . "\trfc -e go wild with your own regexp on rfc-index\n" . "\trfc -h displays this stuff\n" . "\trfc -i updates the $indexpath via lynx\n" . "\trfc -k keyword; same as -s\n" . "\trfc -l \# spawns lynx to the specified RFC\n" . "\trfc -m \# user\@remote.net emails the RFC to specified address\n" . "\trfc -s \"string\" to search for in the index\n" . "\trfc -u \# sets the base URL to the number listed with -w\n" . "\trfc -w lists the available webservers to display\n" . "baseURL=$rfcbaseurl\n" . "comments\/bugfixes mailto: rfc\@dewn.com\n\n"; exit; } print "\nThe Result:\n$index\n";