#!/usr/bin/perl
#
# viewtxt.pl v0.0.4 - View a plain text file in a HTML-document
# Copyright (C) 2006 Stian Skjæveland
#
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#

use CGI qw(:standard);
use strict;

print header;

print qq(
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!--
  Copyright (C) 2006 Stian Skjæveland.
   Verbatim copying and redistribution of this entire page are permitted provided this notice is preserved.
-->
<html>
<head>
<title>View plan text file</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta name="AUTHOR" content="stian at atlantiscrew period net">
<meta name="KEYWORDS" content="stian skjæveland, personal web site, document">
<link rel="icon" type="image/png" href="/pics/s-icon.png">
</head>
<body>
<h1>View plain text file</h1>
<p>
We are now viewing a plain text file inside of a HTML-document. Just for making things easy 
for you as a reader. 
);
print "<a href=\"$ENV{'HTTP_REFERER'}\">Back to previous page</a>.";

print qq(
<hr>
<pre>
);

my $param_txtfile=param('txtfile');
my $privdir="/home/stunix/domains/atlantiscrew.net/public_html/stian/doc/list.txt";
my $full=$privdir.=$param_txtfile;
my @txtlines;

open(PLAINTXTFILE, "<$full") || die(&filenotfound());
print @txtlines=<PLAINTXTFILE>;
close(PLAINTXTFILE);
print qq(
</pre>
);
print "<b>End of file <a href=\"$param_txtfile\">$param_txtfile</a>.</b> (Click to view/download the original file.) ";

&endtext();

sub filenotfound() {
print qq(
</pre>
);
  print "<b>Cannot find file '$param_txtfile': $!</b>";

print qq(
<p>
);
  &endtext();
}

sub endtext() {
  print "<a href=\"$ENV{'HTTP_REFERER'}\">Go back to previous page</a>.";
print qq(
<hr>
Copyright (C) 2006 Stian Skjæveland.
<br>Verbatim copying and redistribution of this entire page are permitted provided thisnotice is preserved.
<p>
<a href="http://www.perl.com"><img src="http://www.atlantiscrew.net/pics/perl.gif"border="0" alt="Powered by Perl"></a> <a href="http://validator.w3.org/check/referer"><img src="http://www.w3.org/Icons/valid-html401.png" border="0" alt="Valid HTML 4.01!"></a>
</body>
</html>
);
}
