#!/usr/bin/perl -w

$version = shift @ARGV;

open(INDEX, '>index.html') || die "unable to write to index.html $!";

$line = "<center><img src=coreLine.gif alt=
\"----------------------------------------------------------------------\">
</center>\n";

print INDEX "<html><head><title>CORE software : netl homepage</title></head>
<body bgcolor=#f1f1f1 text=#000000 link=#0000ff vlink=#9090ff>
<h2>CORE software : netl homepage</h2>

<p><i>netl</i> is a customizable low level network monitor.</p>

<p><i>netl</i> can be configured to look for particular TCP, UDP or ICMP
packets, or can be setup to look for generic IP packets or even raw
ethernet frames.</p>

<p>For example, <i>netl's</i> TCP filters allow individual SYNs and ACKs
(or any combination of flags) to be logged into syslogd or stdout, or
dumped into a file for later perusal.  the companion program <a
href=neta.1.html>neta (1)</a> is used to disassemble those packets in a
human readable form.</p>

$line

<center>[
<a href=#source>source</a> |
<a href=#bin>binaries</a> |
<a href=#tk>perl/Tk</a> |
<a href=#old>old</a> |
<a href=#doc>documentation</a>
]</center>

$line

<h3>Quickstart</h3>

<p>Netl is a network monitoring utility.  It still has a few rough edges,
but provides functionality which cannot be found in similar programs.  
If you are running a recent Red Hat Linux, there is a good chance we have
<a href=#bin>binary RPMs</a> which should work on your system.  If you
are running another dist of Linux, then compiling the <a
href=#source>source code</a> should be no problem.  Provided with the
netl dist is a file called <a href=netl_install.1.html>INSTALL</a> which
provides step by step instructions.  Unfortunately, if you are running a
different operating system, netl does not <i>yet</i> support it.  If you
are a decent programmer, then a netl port won't be too difficult.  <a
href=#contact>Contact the netl development team</a> if you are
interested.</p>

<p>Netl can now run in one of two different modes.  Interactive mode
requires a special netl user interface.  The only UI written for netl at
this time is the <a href=#tk>perl/Tk netl user interface</a>, but others
are sure to follow.  If you want to play around with the interactive
mode, then you will have to install perl/Tk and <a href=#tk>tknetl</a>.

<p>Daemon mode is the default, and original mode.  Using a <a
href=netl.conf.5.html>config file (usually /etc/netl.conf)</a>, you can
write rules which send packets to syslogd, or get dumped as a file.  You don't need to install anything special to use daemon mode.</a>

<a name=source></a>
<h3>netl source code</h3>

<p>The latest version of netl is $version.  For more information on
recent advances in the netl source base, consult the <a
href=HISTORY>HISTORY</a> file.

<ul><li><a href=http://www.netl.org/netl-$version.tar.gz>netl-$version.tar.gz</a></ul>

<a name=bin></a>
<h3>binaries</h3>

<p>We have binary versions available for redhat linux in RPM format.</p>

<table>

<tr><th>RPM <th>netl version <th>CPU <th>OS <th>os version

<tr><td><a href=http://www.netl.org/rh61/netl-1.08-1.i386.rpm>netl-1.08-1.i386.rpm</a>
    <td align=center>1.08 <td>i386 <td>Red Hat Linux <td align=center>6.1

<tr><td><a href=http://www.netl.org/rh60/netl-1.08-1.i386.rpm>netl-1.08-1.i386.rpm</a>
    <td align=center>1.08 <td>i386 <td>Red Hat Linux <td align=center>6.0

<tr><td><a href=http://www.nerl.org/rh60/netl-1.08-1.alpha.rpm>netl-1.08-1.alpha.rpm</a>
    <td align=center>1.08 <td>alpha <td>Red Hat Linux <td align=center>6.0

</table>

<a name=tk></a>
<h3>Perl/Tk interface</h3>

<p>As a prototype to a more perminent Gtk+ interface for netl, I have
been working on a perl/Tk interface.  If you download the source, the Tk
interface can be built from face/perlTk in the netl dist.  You will need
Perl/Tk 8 or better.  If compiling perl/Tk and the netl perl/Tk interface
sounds like a hassle, considering grabbing one of the binaries:</p>

<table>
<tr><th>RPM <th>netl version <th>CPU <th>OS <th>os version

<tr><td><a href=http://www.nerl.org/rh61/tknetl-1.08-1.i386.rpm>tknetl-1.08-1.i386.rpm</a>
    <td align=center>1.08 <td>i386 <td>Red Hat Linux <td align=center>6.1

<tr><td><a href=http://www.nerl.org/rh60/tknetl-1.08-1.i386.rpm>tknetl-1.08-1.i386.rpm</a>
    <td align=center>1.08 <td>i386 <td>Red Hat Linux <td align=center>6.0

<tr><td><a href=http://www.nerl.org/rh60/tknetl-1.08-1.alpha.rpm>tknetl-1.08-1.alpha.rpm</a>
    <td align=center>1.08 <td>alpha <td>Red Hat Linux <td align=center>6.0

</table>

<p>You will also need perl/Tk, and since Red Hat 6.0 doesn't come with
that, I have also provided that in binary form:</p>

<table>
<tr><th>RPM <th>netl version <th>CPU <th>OS <th>os version

<tr><td><a href=http://www.nerl.org/rh61/perl-Tk-800.014.i386.rpm>perl-Tk-800.014.i386.rpm</a>
    <td align=center>1.08 <td>i386 <td>Red Hat Linux <td align=center>6.1

<tr><td><a href=http://www.nerl.org/rh60/perl-Tk-800.014.i386.rpm>perl-Tk-800.014.i386.rpm</a>
    <td align=center>1.08 <td>i386 <td>Red Hat Linux <td align=center>6.0

<tr><td><a href=http://www.nerl.org/rh60/perl-Tk-800.014.alpha.rpm>perl-Tk-800.014.alpha.rpm</a>
    <td align=center>1.08 <td>alpha <td>Red Hat Linux <td align=center>6.0

</table>

<p>You can also, optionally install perl/Tk yourself (you may have to
provide rpm the `--nodep' option when installing tknetl, if it gives you
problems).  perl/Tk is available at your local CPAN mirror.  See 
<a href=http://www.perl.com>www.perl.com</a> for more details.</p>

<a name=old></a>
<h3>old versions</h3>

<p>We keep a limited number of older versions of netl available.</p>

<ul>
	<li><a href=http://www.nerl.org/netl-1.07.tar.gz>netl-1.07.tar.gz</a>
	<li><a href=http://www.nerl.org/netl-1.05.tar.gz>netl-1.05.tar.gz</a>
	<li><a href=http://www.nerl.org/netl-1.05-1.i386.rpm>netl-1.05-1.i386.rpm</a>
	<li><a href=http://www.nerl.org/netl-1.04.tar.gz>netl-1.04.tar.gz</a>
	<li><a href=http://www.nerl.org/netl-1.04-1.i386.rpm>netl-1.04-1.i386.rpm</a>
	<li><a href=http://www.nerl.org/netl-1.04-1.alpha.rpm>netl-1.04-1.alpha.rpm</a>
	<li><a href=http://www.nerl.org/netl-1.03.tar.gz>netl-1.03.tar.gz</a>
	<li><a href=http://www.nerl.org/netl-1.02.tar.gz>netl-1.02.tar.gz</a>
	<li><a href=http://www.nerl.org/netl-1.01.tar.gz>netl-1.01.tar.gz</a>
</ul>

$line

<a name=doc></a>
<h3>netl documentation</h3>

<p>It's best to start out with the main daemon <a
href=netl.8.html>netl(8)</a>, unless you haven't managed to install netl
yet, in which case it's best to start with the <a
href=netl_install.1.html>install guide</a>.  The newest, and most
exciting new features for netl are the new <a
href=netl_module.1.html>netl modules</a> and <a href=netlcc.1.html>netl
compiler</a>.  Modules are considered stable, in fact netl 1.02 and later
are module based.  The compiler is experimental, but useable.</p>

<ul>
";

$tail_text = "
$line

<a name=contact></a>
<h3>Contact Information</h3>

<p>You can contact the netl team at <a
href=mailto:netl\@netl.org>netl\@netl.org</a>.

$line
<center>
[
<a href=http://www.whitedactyl.com/ollisg/>Tarquin Hill</a> |
<a href=http://www.whitedactyl.com/core/>CORE</a> |
<a href=http://www.netl.org/>netl</a>
]
</center>
$line
<address><center>
<a href=http://www.whitedactyl.com/ollisg/>ollisg</a>
(<a href=mailto:netl\@netl.org>netl\@netl.org</a>)
</center></address>
<center><h6>
<img src=copyright.gif alt=\"(c)\"> 1999 CORE software international
</h6></center>
</body></html>\n\n";

for(@ARGV) {
	$filename = $_;
	($root = $filename) =~ s/\.rms//i;

	my $title = ''; my $section = 1;  my $header = ''; my $tail = '';  my $line = 0;

	open(FP, $filename) || die "unable to read $filename $!";
	open(TXT, ">$root.txt") || die "unable to write to $root.txt $!";
	open(MAN, ">$root") || die "unable to write to $root";
	open(HTML, ">$root.html") || die "unable to write $root.html";
	$html = '';
	$html_toc = '';
	$section_number = 0;

	while(<FP>) {
		chomp;
		$line++;

		if(/^#TITLE (.*)$/) { $title = $1; next }
		if(/^#SECTION (.*)$/) { $section = $1; next }
		if(/^#HEAD (.*)$/) { $header = $1; next }
		if(/^#TAIL (.*)$/) { $tail = $1; next }
		if(/^#EXEC (.*)$/) { $filename = "$1.rms"; $line = 0; open(FP, "$1.rms") || die "unable to open $1.rms $!"; next; }

		if(/^#INCLUDE (.*)$/) {
			open(FRED, $1) || die "unable to read $1 $!";
			print MAN ".nf\n";
			$html .= "\n\n<pre>";
			while(<FRED>) {
				print MAN; print TXT;  
				($tmp47 = $_) =~ s!\&!&amp;!g;
				$tmp47 =~ s!\<!&lt;!g;
				$html .= $tmp47;
			}
			$html .= "</pre>\n\n";
			print MAN ".fi\n";
			next;
		}

		if(/^#START/) {
			print MAN ".ad b
.TH $title $section \"$tail\" \"$header\" \"$header\"
.AT 3
.de sh
.br
.ne 5
.PP
\\fB\\\\\$1\\fR
.PP
..\n";
			print HTML "<html><head><title>$header : $title($section)</title></head>
<body bgcolor=#f1f1f1 text=#000000 link=#0000ff vlink=#9090ff>
<h2>$header : $title($section)</h2>\n";
			print TXT "$title\($section\)
$header
$tail";

			next;

		}

		if(/^#H (.*)$/) {
			print MAN ".SH $1\n";
			print TXT "\n$1\n";
			$section_number++;
			$html .= "<a name=sec$section_number><h3>$1</h3>\n\n";
			$html_toc .= "  <li><a href=#sec$section_number>$1</a>\n";
			if($1 eq 'NAME') {
				print INDEX "  <li><a href=$root.html>$title($section)</a>\n";
				$go_name = 1;
			}
			next;
		}

		warn "$filename:$line:unknown directive" if /^#/;

		if($_ eq '') {
			print MAN ".PP\n";
			print TXT "\n";
			$html .= "<p>\n";
			next;
		}

		($man = $_) =~ s/i\<(.*?)\>\s*/\n.I $1\n/mg;
		$man =~ s/b\<(.*?)\>\s*/\n.B $1\n/mg;
		$man =~ s/sa\<(.*?)\>\((.*?)\)(\S*)\s*/\n.BR $1 ($2)$3\n/mg;
		($tmp = $_) =~ s!i\<(.*?)\>\s*! <i>$1</i> !mg;
		$tmp =~ s!b\<(.*?)\>\s*! <b>$1</b> !mg;
		$tmp =~ s!sa\<(.*?)\>\((.*?)\)\s*! <a href=$1.$2.html>$1 ($2)</a> !mg;
		$tmp =~ s!\b(http://.*?)\s!<a href=$1>$1</a>!mg;
		($txt = $_) =~ s/[ib]\<(.*?)\>/$1/mg;
		$txt =~ s/sa\<(.*?)\>/$1/mg;


		chomp($man);
		$man =~ s/^\n//gm;
		$html .= "$tmp\n";

		warn "$filename:$line:newline" if $_ =~ /\n/m;
		warn "$filename:$line:blank" if $_ eq '';

		print MAN "$man\n";
		print TXT "$txt\n";
		if($go_name) {
			($tmp2 = $tmp) =~ s/^.*?-//;
			print INDEX "$tmp2\n";
			$go_name = 0;
		}
	}

	print HTML "<h3>table of content</h3>\n<ul>\n$html_toc\n</ul>\n$html\n$tail_text";
}

print INDEX "</ul>$tail_text";
