--- web/cgi-bin/docs.cgi 2004/03/21 23:59:32 1.7 +++ web/cgi-bin/docs.cgi 2004/03/24 23:29:21 1.10 @@ -6,17 +6,22 @@ use CGI; $| = 1; # Settings -my ($menu) = "../nwww/menu.inc" ; -my ($header) = "../nwww/header.inc"; -my ($footer) = "../nwww/footer.inc"; -my ($style) = "../nwww/style.inc"; +my ($incdir) = "../nwww"; +# Include files +my ($doctype) = "$incdir/doctype.inc"; +my ($style) = "$incdir/style.inc"; +my ($header) = "$incdir/header.inc"; +my ($footer) = "$incdir/footer.inc"; +my ($menu) = "$incdir/menu.inc" ; + my ($query) = new CGI; # Note filenames may only have one dot in them, in the ".txt". # This prevents malicious users using "../" to view files. my ($doc) = ($query->param('doc') =~ /^\s*([^\.]*?\.txt)\s*$/); +# This should be application/xhtml+xml print "Content-type: text/html\n\n"; unless (defined $doc) { @@ -34,57 +39,66 @@ $doc = "../htdocs/documentation/".$doc; my($docname) = $doc =~ /\/([^\/]+)$/; +&print_html($doctype); + print <<"END"; - - - - - i-scream plain text documentation viewer + + + i-scream plain text documentation viewer + END &print_html($style); print <<"END"; - - - -
- -
+ + +
+
END &print_html($header); print <<"END"; -
-

i-scream documentation viewer

-

$docname

+
+

+ i-scream documentation viewer +

+

+ $docname +

END &print_file($doc); -print "
"; +print <<"END"; + +
+END + &print_html($footer); -print "
"; +print <<"END"; +
+END + &print_html($menu); print <<"END"; -
- +
+ END exit 0; # Print a file, whilst escaping HTML: - -sub print_file ($) { +sub print_file { my ($urls) = '(' . join ('|', qw{ http telnet @@ -95,32 +109,41 @@ my ($urls) = '(' . join ('|', qw{ } ) . ')'; -my ($ltrs) = '\w'; -my ($gunk) = '/#~:.?+=&%@!\-'; -my ($punc) = '.:?\-'; -my ($any) = "${ltrs}${gunk}${punc}"; -my ($filename) = @_; -if(open(FILE, $filename)) { - print "
\n";
-    # Use $_ implicitly throughout.
-    while () {
-        # Must do the next line first!
-        s/&/&/g;
-        s//>/g;
-        s/"/"/g;
-        s/\b($urls:[$any]+?)(?=[$punc]*[^$any]|$)/$1<\/a>/igox;
-        print;
+    my ($ltrs) = '\w';
+    my ($gunk) = '/#~:.?+=&%@!\-';
+    my ($punc) = '.:?\-';
+    my ($any) = "${ltrs}${gunk}${punc}";
+    my ($filename) = @_;
+    if(open(FILE, $filename)) {
+        print "          
\n";
+        # Use $_ implicitly throughout.
+        while () {
+            # Must do the next line first!
+            s/&/&/g;
+            s//>/g;
+            s/"/"/g;
+            s/\b($urls:[$any]+?)(?=[$punc]*[^$any]|$)/$1<\/a>/igox;
+            print;
+        }
+        print "\n
"; } - print "
"; + else { + print "Failed to open $docname."; + } } -else { - print "Failed to open $docname."; -} -} -# Print a file without escaping HTML: - +# Print the contents of a file containing html sub print_html ($) { -my ($filename) = @_; -print `cat $filename 2>&1`; + my ($filename) = @_; + my($virtual) = ''; + my(@virtualresponse) = `/web/i-scream/nwww.cgi-bin/logo.cgi`; + open(FILE, $filename); + while() { + if(/$virtual/) { + s/$virtual/$virtualresponse[@virtualresponse-1]/; + } + print; + } + close FILE; }