--- /dev/null
+RemoveHandler .cgi
+ForceType text/plain
\ No newline at end of file
--- /dev/null
+# httpd.conf +=
+
+AddHandler plp-document .plp
+Action plp-document /cgi-bin/plp.cgi
+
+# /cgi-bin/ can be any globaly existing directory (I use /COMMON/ because
+# cgi-bin's are local (mod_vhost_alias))
+
+# read http://plp.juerd.nl/
\ No newline at end of file
use strict;
use vars qw($VERSION %INTERNAL %get %post %fields %header %cookie %BLOCK $DEBUG $output);
-$VERSION = '2.21';
+$VERSION = '2.22';
$DEBUG = 1;
+# We put most everything in %INTERNAL, just so the user won't screw it.
+# We could also have used packages, but let's keep it simple.
+
$INTERNAL{file} = $ENV{PATH_TRANSLATED};
unless (-e $INTERNAL{file}){
$ENV{REDIRECT_STATUS} = '404';
$INTERNAL{qq} = "\10"; #^P
$INTERNAL{q} = "\17"; #^Q
-$header{'content-type'} = 'text/html';
-$header{status} = '200 OK';
+$header{'Content-Type'} = 'text/html';
+$header{Status} = '200 OK';
$INTERNAL{code} = ReadFile($INTERNAL{file});
$INTERNAL{code} =~ s(<\[([^>]*?):(.*?)\]>)($BLOCK{"${1}-1"}$2$BLOCK{"${1}-2"})g;
$INTERNAL{code} =~ s(<\[(?!/)(.*?)\]>)($BLOCK{"${1}-1"})g;
$INTERNAL{code} =~ s(<\[/(.*?)\]>)($BLOCK{"${1}-2"})g;
+
+
$INTERNAL{code} =~ s(<{[ \08\09]*)($INTERNAL{q};print qq$INTERNAL{qq})g;
$INTERNAL{code} =~ s([ \08\09]*}>)($INTERNAL{qq};print q$INTERNAL{q})g;
$INTERNAL{code} = "print q$INTERNAL{q}$INTERNAL{code}$INTERNAL{q};";
}
}
-for (keys %header){
- print "$_: $header{$_}\n";
+print "\n\n" if $DEBUG == 2;
+
+{
+ my %HEADER;
+ for (sort keys %header){ # Sort, so lowercase and underscores come first)
+ my $copy = $_;
+ tr/_/-/;
+ s/\b(\w)(\w*)/\U$1\E\L$2\E/g;
+ $HEADER{$_} = $header{$copy};
+ }
+ for (keys %HEADER){
+ print "$_: $HEADER{$_}\n";
+ }
+ print "\n";
}
-print "\n";
{
no strict;
s/</</g;
s/>/>/g;
s/\n/<br>\n/g;
- s/\t/ /eg;
+ s/\t/ /g;
s/ / /g;
};
if ($@){ return defined wantarray ? @_ : undef }
}
sub AutoURL($){
+ # This sub assumes your string does not match /(["<>])\cC\1/
my $ref;
if (defined wantarray){
$ref = \(my $copy = $_[0]);
$ref = \$_[0];
}
eval {
- my ($p, $b, $c);
- $$ref =~ s/"/"\cC"/g;
- $$ref =~ s/>/>\cC>/g;
+ $$ref =~ s/"/"\cC"/g; # Single characters are easier to match :)
+ $$ref =~ s/>/>\cC>/g; # so we can just use a character class []
$$ref =~ s/</<\cC</g;
+
# Now this is a big, ugly regex! But hey - it works :)
$$ref =~ s{((\w+://|www\.|WWW\.)[a-zA-Z0-9\.\@:-]+[^\"\'>< \r\t\n]*)}{
- local $_ = $1, $p = $2, ((($b) = /([\.,!\?\(\)\[\]]+$)/) ? s/// :
- undef), s/&(?!\x23?\w+;)/&/g, s/\"/"/g, $c =
- ($p eq 'www.' || $p eq 'WWW.' ? "http://$_" : $_),
- qq{<a href="$c" target="_blank">$_</a>$b}
+ local $_ = $1;
+ my $scheme = $2;
+ s/// if (my $trailing) = /([\.,!\?\(\)\[\]]+$)/;
+ s/&(?!\x23?\w+;)/&/g;
+ s/\"/"/g;
+ my $href = ($scheme =~ /www\./i ? "http://$_" : $_);
+ qq{<a href="$href" target="_blank">$_</a>$trailing};
}eg;
-
$$ref =~ s/"\cC"/"/g;
$$ref =~ s/>\cC>/>/g;
$$ref =~ s/<\cC</</g;