#!/usr/bin/perl -w

use strict;
use CGI qw/:standard :html3 start_ul/;
use lib ($ENV{WEBINC} || '.');
use iscweb;
use iscpress;

use Cwd;

chdir("/udir/www/http/www.isc.org/htdocs/pubs/tn") || die;

print header();

my $tn = param('tn');


if (defined $tn && $tn =~ /^(isc\-tn\-\d+\-\d+)\.(txt|html)$/io && -f $&) {
	($tn, my $type) = ($1, $2);
	(my $uctn = $tn) =~ tr/a-z/A-Z/;
	print page_start($tn);
	open('file', "<$tn.$type") || die;
	if ($type eq 'txt') {
		print "<PRE>\n", <file>, "</PRE>\n";
	} elsif ($type eq 'html') {
		print <file>;
	} else {
		die;
	}
} else {
	print page_start("ISC Technical Note Series"),
		h3("ISC Technical Note Series"),
		p(qq{
			These technical notes describe methodologies in use
			at ISC that may be of use to other members of the
			Internet technical community.
		}),
		start_ul();
	my $self = url(-relative=>1);

	foreach (reverse(sort { $b <=> $a } <*.tn>)) {
		next unless /\.tn$/;
		my $tn = $`;
		my ($title, $abstract) = &get_tn($tn);
		(my $uctn = $tn) =~ tr/a-z/A-Z/;
		$_ = b($uctn).' &middot; '.em($title).' &middot; '."\n";
                #$_ .= a({href=>"/index.pl?/pubs/tn/index.pl?tn=$tn.txt"},
                $_ .= a({href=>"/pubs/tn/index.pl?tn=$tn.txt"},
                       '[text]')."\n" if -f "$tn.txt";
                #$_ .= a({href=>"/index.pl?/pubs/tn/index.pl?tn=$tn.html"},
                $_ .= a({href=>"/pubs/tn/index.pl?tn=$tn.html"},
                      '[html]')."\n" if -f "$tn.html";
		print li($_."\n".blockquote($abstract)), "\n";
	}
	print end_ul();

}

print page_finish();

exit 0;

sub get_tn {
	(my $tn) = @_;

	my $title = '';
	my $abstract = '';
	my $dest = \$title;
	open('abs', "<$tn.tn") || die;
	while (<abs>) {
		if ($_ eq "\n") {
			$dest = \$abstract;
		}
		$$dest .= $_;
	}
	close('abs');
	return ($title, $abstract);
}
