User Tools

Site Tools


perl:start

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
perl:start [13/09/2023 17:11] – created - external edit 127.0.0.1perl:start [10/05/2026 00:46] (current) – [my-ip.pl] andrew
Line 109: Line 109:
 exit (0); exit (0);
 </code> </code>
 +
 +
 +==== convert2html.pl ====
 +
 +Convert to HTML
 +
 +
 +<code>
 +#!/usr/bin/perl
 +#written by Andrew Stringer 30-04-2006
 +#this is intended to be run from an ssi:-
 +#<!--#include virtual="/cgi-bin/convert2html.pl?path/to/file.xml" -->
 +#it takes an html file or xml file and converts the < to &lt; etc. and
 +#prints to stdout enclosed in a <pre> </pre> tag. This allows code listings
 +#to appear in web pages correctly formatted.
 +
 +use warnings;
 +use strict;
 +
 +MAIN:
 +{
 +my $line;
 +#set prefix to path to webroot
 +my $prefix = '/data/rainsbrook/http';
 +my $query = $ENV{'QUERY_STRING'} ;
 +
 +my $debug = '0' ;
 +
 +#remove double dots (..) to prevent file system traversal
 +#Only naughty boys would want to do this, should not affect normal users.
 +$query =~ s/\.\.//g;
 +$query =~ s/\/\//\//g;
 +
 +#only allow files below the webroot to be readout
 +my $url = "$prefix/$query" ;
 +
 +open (FILE, "$url");
 +
 +print "Content-type: text/html\n\n" ;
 +
 +if($debug){
 +print "ENV{'QUERY_STRING'} is $query \n<br>\n" ;
 +print "URL is $url \n";
 +}
 +
 +print "<pre>\n";
 +
 +while ($line = <FILE>
 + {
 +#use /g to catch all occurances on each line
 + $line =~ s/\</\&lt\;/g;
 + $line =~ s/\>/\&gt\;/g;
 +
 + print $line;
 + }
 +print "</pre>\n";
 +
 +}
 +exit(0);
 +
 +</code>
 +
  
  
  
  
perl/start.1694625068.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki