#!/usr/bin/perl -w # # Create a very compact HTML index into the RFCs. # The idea for this is from Jutta Degener # and is used here with her permission. # # 19961126 Thomas Lenggenhager, SWITCH # 19990322 Simon Leinen # 20040322 Thomas Lenggenhager, SWITCH use strict; use vars qw($opt_h); use English; ## Prototypes sub usage($ ); sub parse_original_index($ ); sub write_web_mini_index(); # check if run as user mirror (by using setuid mirror) my $me = (getpwuid($EFFECTIVE_USER_ID))[0]; die "Use this script as user \"mirror\" instead of \"$me\"!\n" if $me ne 'mirror'; my $write_web_mini_index = 1; my $write_messages_for_inexistent_rfcs = 0; require 'getopts.pl'; &Getopts('hmt:') || usage (1); usage (0) if $opt_h; my $ROOT = "/opt/ftp/doc/standard/rfc"; my ($min_rfc, $max_rfc, %entries, %file_exists, %not_available, %status, %status_names, %status_list); parse_original_index ("$ROOT/rfc-index.txt"); if ($write_web_mini_index) { write_web_mini_index (); } 1; sub parse_original_index ($) { my ($rfc_index) = @_; open(IN, $rfc_index); my $skip = 1; my $OK = 0; my ($entry, $number, $orig_name); my ($dir, $short_number, $num, $newdir); my %months = ( 'January' => 1, 'Jan' => 1, 'February' => 2, 'Feb' => 2, 'March' => 3, 'Mar' => 3, 'April' => 4, 'Apr' => 4, 'May' => 5, 'May' => 5, 'June' => 6, 'Jun' => 6, 'July' => 7, 'Jul' => 7, 'August' => 8, 'Aug' => 8, 'September' => 9, 'Sep' => 9, 'October' => 10, 'Oct' => 10, 'November' => 11, 'Nov' => 11, 'December' => 12, 'Dec' => 12, ); while () { chomp; # Skip everything before this $skip = 0 if $skip && /^0001 /; next if $skip; # skip the header lines next if /^\s*RFC Index/; next if /^\s*---------/; # remove the trailing white space of every line s/\s*$//; # skip all empty lines except the first one after an entry if (/^\s*$/) { if ($OK) { $OK = 0; # store the entry itself $entries{$number} = $entry; if (($entry =~ /Not Issued/is) || ($entry =~ /Not\s*online/is)) { $not_available{$number} = 1; } # store the status of the entry if ($entry =~ /\(Status:\s*(.*)\)/is) { $orig_name = $1; my $name = lc($orig_name); $name =~ s/[ \n]+/_/g; if (!$status_names{$name}) { $status_names{$name} = $orig_name; } $status{$number} = $name; $status_list{$name} .= "$number "; } next; } } # a new entry begins with its number at the beginning of the line if (/^(\d+)\s*/) { $number = $1; $OK = 1; $entry = $_; $min_rfc = $number unless defined $min_rfc && $min_rfc < $number; $max_rfc = $number unless defined $max_rfc && $max_rfc > $number; } else { # this is a continuation line of an entry, so just append it $entry .= "\n" . $_; } } $entries{$number} = $entry; close IN || die "close $rfc_index: $!"; } sub usage ($) { my ($exitval) = @_; print STDERR <"; open (INDEX, ">$ROOT/mini-index.html.new") || die "creating $ROOT/mini-index.html.new"; print INDEX < Internet Standards Archive

IETF Request for Comments

EOM # print INDEX " RFC related resources on SWITCHmirror
[ RFC Index | RFC Directory | RFC Search Tool ] EOM close INDEX || die "close $ROOT/mini-index.html.new: $!"; if (-s "$ROOT/mini-index.html.new") { unlink "$ROOT/mini-index.html"; rename "$ROOT/mini-index.html.new", "$ROOT/mini-index.html" || die "mv $ROOT/mini-index.html.new $ROOT/mini-index.html: $!"; } chmod 0664, "$ROOT/mini-index.html"; }