garymgordon
Programmer
I have a script that looks like this:
#!/usr/bin/perl
if ($ARGV[0] eq "see-script" {
print "Content-type: text/plain\n\n";
open(IN, "wpbcv.cgi"
print while <IN>;
exit 0;
}
#require "sys/socket.ph";
use Socket;
require "./common.pl";
$sockaddr = "S n a4 x8";
($name,$aliases,$proto) = getprotobyname('tcp');
push(@INC, "/usr/local/etc/httpd/bin"
push(@INC, split(':', $ENV{"PATH"}));
require "cgi-lib.pl";
&ReadParse;
if ($in{'url'} !~ m@^[^\.]+\.)+[^\.]+@) {
print "Content-type: text/html\n\n";
print "Sorry, I can only handle URLs.\n";
print "You typed in `<tt>$in{'url'}</tt>'.\n";
exit 0;
}
$in{'url'} .= "/" unless $in{'url'} =~ m@
if ($in{'img'} && $in{'table'} && $in{'frame'} && $in{'font'}
&& $in{'body'} && $in{'center'} && $in{'applet'} && $in{'script'}
&& !$in{'img_sizeless'} && !$in{'img_altless'} && !$in{'marquee'}) {
# They didn't ask for anything useful!
print "Location: $in{'url'}\n";
print "Content-type: text/html\n\n";
print "You didn't select anything useful\n";
exit 0;
}
$agent = $in{'agent'};
if ($in{'agent'} eq $ENV{"HTTP_USER_AGENT"}) {
delete $in{'agent'};
}
print "Content-type: text/html\n\n";
$u = $in{'url'};
$u =~ s/\&/&/g;
$file = &webget($u);
print "<base href=\"$in{'url'}\">\n";
($urlhead,$urlpath) = $in{'url'} =~ m@([^/]+/+[^/]+)(.*)@;
$urlpath =~ s@/[^/]+$@/@;
$urlpath = "/" unless $urlpath;
$me = "
for $o (keys %in) {
$v = $in{$o};
print "<!-- $o = $v -->\n";
$v =~ s/([^a-zA-Z0-9])/sprintf("%%%2x", ord($1));/ge;
push(@o, "$o=$v" unless $o eq "url";
$toprint .= "<input type=hidden name=$o value=\"$v\">\n" unless $o eq "url";
}
$me .= join("&", @o);
$me .= "&url=";
if ($file !~ /<frameset/i) {
print "<title>WPBCV: $in{'url'}</title><center>\n";
print "<form method=\"GET\" action=\"
print "<!-- Filtered by -->\n";
print $toprint;
open(BURST, "burst.inc"
print while <BURST>;
close(BURST);
print "<br><small><i><a href=\" Page Backwards Compatibility Viewer</a>\n";
print "WPBCV: <input name=url value=\"$in{'url'}\" size=80><br>\n";
print "<i>This service is intended to be used only by content developers, on their own pages.</i>\n";
print "<hr noshade size=2></small></form></center>\n";
}
$file =~ s@<br>([ \t\r\n]*<br>)+@<br>@gi;
for $l (split('<', $file)) {
($t,$text) = split('>', $l, 2);
if ($t =~ /\S/) {
$t = '<' . $t . '>';
$t =~ s/\n/ /g;
($end,$tag) = ($t =~ m@<(/?)([a-zA-Z]+).*@);
$tag =~ tr/A-Z/a-z/;
# print "<!-- tag eq `$tag' t eq `$t' -->\n";
if ($tag eq "head" && $end) {
print "<base href=\"$in{'url'}\">\n";
}
if ($tag eq "a" && !$end) {
$t =~ s/href=\"([^\"]+)\"/&rebase_url("href", $1)/gioe; #"
$t =~ s/href=([^\"> ]+)([ >])/&rebase_url("href", $1,$2)/gioe; #"
if (! $in{'script'}) {
$t =~ s/\son([a-zA-Z]+\s*=)/ XX$1/g;
}
}
if ($tag eq "img" {
if ($t =~ /src\s*=\s*[^\"\s]/i) {
$t =~ s@src\s*=\s*([^\s>]+)@src="$1"@i; #"
}
}
if ($tag eq "img" && ! $in{'img'}) {
if ($in{'img_broken'}) {
#$t =~ s@src="[^\"]+"@src="this-is-a-broken-image.gif"@
$t =~ s@src="[^\"]+"@src=" } elsif ($t =~ /alt=\"/i) { #"
$t =~ s/.* alt=\"([^\"]*)\".*/$1/i; #"
} elsif ($t =~ /alt=/i) {
$t =~ s/.* alt=([^\s>]*).*/$1/i;
} else {
$t = "[IMAGE]";
}
}
elsif ($tag eq "img" {
if ($in{'img_altless'}) {
#$t =~ s@src="[^\"]+"@src="this-is-an-altless-image.gif"@
$t =~ s@src="[^\"]+"@src=" unless $t =~ /alt=/i;
}
if ($in{'img_sizeless'}) {
unless ($t =~ /width=/i && $t =~ /height=/i) {
if ($t =~ /no-alt.gif/) {
#$t =~ s@src="[^\"]+"@src="this-is-a-sizeless-altless-image.gif"@;
$t =~ s@src="[^\"]+"@src=" } else {
#$t =~ s@src="[^\"]+"@src="this-is-a-sizeless-image.gif"@;
$t =~ s@src="[^\"]+"@src=" }
}
}
}
elsif (($tag eq "table" || $tag eq "tr" || $tag eq "td" || $tag eq "th"
|| $tag eq "thead" || $tag eq "tbody"
&& ! $in{'table'}) {
$t = "";
if ($in{'table_br'} && ($tag eq "td" || $tag eq "th") {
$t = "<p>";
}
}
elsif (($tag eq "frame" || $tag eq "frameset" || $tag eq "noframes"
&& ! $in{'frame'}) {
if ($tag eq "frame" {
($src) = $t =~ m@src=\"?([^\"]+)\"?@i;
$src2 = &rebase_url(undef, $src);
print "Frame: <a href=\"$src2\">$src</a><br>\n";
}
$t = "";
}
elsif ($tag eq "frame" && !$end) {
$t =~ s/src=\"([^\"]+)\"/&rebase_url("src", $1)/gioe; #"
$t =~ s/src=([^\"> ]+)([ >])/&rebase_url("src", $1,$2)/gioe; #"
}
elsif ($tag eq "font" && ! $in{'font'}) {
$t = "";
}
elsif ($tag eq "blink" && ! $in{'blink'}) {
$t = "";
}
elsif ($tag eq "body" && ! $in{'body'}) {
$t = "<body>";
}
elsif ($tag eq "center" && ! $in{'center'}) {
$t = "";
}
elsif ($tag eq "applet" && ! $in{'applet'}) {
$t = "";
}
elsif ($tag eq "script" && ! $in{'script'}) {
$t = "";
}
elsif ($tag eq "noscript" && ! $in{'script'}) {
$t = "";
}
#ADDED : removes style tags <gocubs@bigfoot.com>
elsif ($tag eq "style" && ! $in{'style'}) {
$t = "";
}
elsif ($tag eq "link" && ! $in{'style'}) {
$t = "";
}
elsif (! $in{'style'}) {
$t =~ s/\s(style\s*=)/ XX$1/g;
}
elsif ($tag eq "marquee" && ! $in{'marquee'}) {
$t = "";
}
elsif ($tag =! m@^(input|select|textarea)$@ && ! $in{'script'}) {
$t =~ s/\son([a-zA-Z]+\s*=)/ XX$1/g;
}
print $t;
}
print $text;
}
===================
But I am getting an error.
I am not sure if the error:
"Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request."
is due to the fact that I don't have a specific module installed, or what? Or is the code missing something.
But if someone can look at this and tell me either what I need or what is wrong I'd appreciate it.
But, if I need a module to be installed, I will need a work around so all code that is needed , ... is in the script itself.
Is this possible???
Help?
Gary
Gary M. Gordon, LLC
webmaster@garymgordon.com
Certified Web Developer ::
Application Programmer
#!/usr/bin/perl
if ($ARGV[0] eq "see-script" {
print "Content-type: text/plain\n\n";
open(IN, "wpbcv.cgi"
print while <IN>;
exit 0;
}
#require "sys/socket.ph";
use Socket;
require "./common.pl";
$sockaddr = "S n a4 x8";
($name,$aliases,$proto) = getprotobyname('tcp');
push(@INC, "/usr/local/etc/httpd/bin"
push(@INC, split(':', $ENV{"PATH"}));
require "cgi-lib.pl";
&ReadParse;
if ($in{'url'} !~ m@^[^\.]+\.)+[^\.]+@) {
print "Content-type: text/html\n\n";
print "Sorry, I can only handle URLs.\n";
print "You typed in `<tt>$in{'url'}</tt>'.\n";
exit 0;
}
$in{'url'} .= "/" unless $in{'url'} =~ m@
if ($in{'img'} && $in{'table'} && $in{'frame'} && $in{'font'}
&& $in{'body'} && $in{'center'} && $in{'applet'} && $in{'script'}
&& !$in{'img_sizeless'} && !$in{'img_altless'} && !$in{'marquee'}) {
# They didn't ask for anything useful!
print "Location: $in{'url'}\n";
print "Content-type: text/html\n\n";
print "You didn't select anything useful\n";
exit 0;
}
$agent = $in{'agent'};
if ($in{'agent'} eq $ENV{"HTTP_USER_AGENT"}) {
delete $in{'agent'};
}
print "Content-type: text/html\n\n";
$u = $in{'url'};
$u =~ s/\&/&/g;
$file = &webget($u);
print "<base href=\"$in{'url'}\">\n";
($urlhead,$urlpath) = $in{'url'} =~ m@([^/]+/+[^/]+)(.*)@;
$urlpath =~ s@/[^/]+$@/@;
$urlpath = "/" unless $urlpath;
$me = "
for $o (keys %in) {
$v = $in{$o};
print "<!-- $o = $v -->\n";
$v =~ s/([^a-zA-Z0-9])/sprintf("%%%2x", ord($1));/ge;
push(@o, "$o=$v" unless $o eq "url";
$toprint .= "<input type=hidden name=$o value=\"$v\">\n" unless $o eq "url";
}
$me .= join("&", @o);
$me .= "&url=";
if ($file !~ /<frameset/i) {
print "<title>WPBCV: $in{'url'}</title><center>\n";
print "<form method=\"GET\" action=\"
print "<!-- Filtered by -->\n";
print $toprint;
open(BURST, "burst.inc"
print while <BURST>;
close(BURST);
print "<br><small><i><a href=\" Page Backwards Compatibility Viewer</a>\n";
print "WPBCV: <input name=url value=\"$in{'url'}\" size=80><br>\n";
print "<i>This service is intended to be used only by content developers, on their own pages.</i>\n";
print "<hr noshade size=2></small></form></center>\n";
}
$file =~ s@<br>([ \t\r\n]*<br>)+@<br>@gi;
for $l (split('<', $file)) {
($t,$text) = split('>', $l, 2);
if ($t =~ /\S/) {
$t = '<' . $t . '>';
$t =~ s/\n/ /g;
($end,$tag) = ($t =~ m@<(/?)([a-zA-Z]+).*@);
$tag =~ tr/A-Z/a-z/;
# print "<!-- tag eq `$tag' t eq `$t' -->\n";
if ($tag eq "head" && $end) {
print "<base href=\"$in{'url'}\">\n";
}
if ($tag eq "a" && !$end) {
$t =~ s/href=\"([^\"]+)\"/&rebase_url("href", $1)/gioe; #"
$t =~ s/href=([^\"> ]+)([ >])/&rebase_url("href", $1,$2)/gioe; #"
if (! $in{'script'}) {
$t =~ s/\son([a-zA-Z]+\s*=)/ XX$1/g;
}
}
if ($tag eq "img" {
if ($t =~ /src\s*=\s*[^\"\s]/i) {
$t =~ s@src\s*=\s*([^\s>]+)@src="$1"@i; #"
}
}
if ($tag eq "img" && ! $in{'img'}) {
if ($in{'img_broken'}) {
#$t =~ s@src="[^\"]+"@src="this-is-a-broken-image.gif"@
$t =~ s@src="[^\"]+"@src=" } elsif ($t =~ /alt=\"/i) { #"
$t =~ s/.* alt=\"([^\"]*)\".*/$1/i; #"
} elsif ($t =~ /alt=/i) {
$t =~ s/.* alt=([^\s>]*).*/$1/i;
} else {
$t = "[IMAGE]";
}
}
elsif ($tag eq "img" {
if ($in{'img_altless'}) {
#$t =~ s@src="[^\"]+"@src="this-is-an-altless-image.gif"@
$t =~ s@src="[^\"]+"@src=" unless $t =~ /alt=/i;
}
if ($in{'img_sizeless'}) {
unless ($t =~ /width=/i && $t =~ /height=/i) {
if ($t =~ /no-alt.gif/) {
#$t =~ s@src="[^\"]+"@src="this-is-a-sizeless-altless-image.gif"@;
$t =~ s@src="[^\"]+"@src=" } else {
#$t =~ s@src="[^\"]+"@src="this-is-a-sizeless-image.gif"@;
$t =~ s@src="[^\"]+"@src=" }
}
}
}
elsif (($tag eq "table" || $tag eq "tr" || $tag eq "td" || $tag eq "th"
|| $tag eq "thead" || $tag eq "tbody"
&& ! $in{'table'}) {
$t = "";
if ($in{'table_br'} && ($tag eq "td" || $tag eq "th") {
$t = "<p>";
}
}
elsif (($tag eq "frame" || $tag eq "frameset" || $tag eq "noframes"
&& ! $in{'frame'}) {
if ($tag eq "frame" {
($src) = $t =~ m@src=\"?([^\"]+)\"?@i;
$src2 = &rebase_url(undef, $src);
print "Frame: <a href=\"$src2\">$src</a><br>\n";
}
$t = "";
}
elsif ($tag eq "frame" && !$end) {
$t =~ s/src=\"([^\"]+)\"/&rebase_url("src", $1)/gioe; #"
$t =~ s/src=([^\"> ]+)([ >])/&rebase_url("src", $1,$2)/gioe; #"
}
elsif ($tag eq "font" && ! $in{'font'}) {
$t = "";
}
elsif ($tag eq "blink" && ! $in{'blink'}) {
$t = "";
}
elsif ($tag eq "body" && ! $in{'body'}) {
$t = "<body>";
}
elsif ($tag eq "center" && ! $in{'center'}) {
$t = "";
}
elsif ($tag eq "applet" && ! $in{'applet'}) {
$t = "";
}
elsif ($tag eq "script" && ! $in{'script'}) {
$t = "";
}
elsif ($tag eq "noscript" && ! $in{'script'}) {
$t = "";
}
#ADDED : removes style tags <gocubs@bigfoot.com>
elsif ($tag eq "style" && ! $in{'style'}) {
$t = "";
}
elsif ($tag eq "link" && ! $in{'style'}) {
$t = "";
}
elsif (! $in{'style'}) {
$t =~ s/\s(style\s*=)/ XX$1/g;
}
elsif ($tag eq "marquee" && ! $in{'marquee'}) {
$t = "";
}
elsif ($tag =! m@^(input|select|textarea)$@ && ! $in{'script'}) {
$t =~ s/\son([a-zA-Z]+\s*=)/ XX$1/g;
}
print $t;
}
print $text;
}
===================
But I am getting an error.
I am not sure if the error:
"Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request."
is due to the fact that I don't have a specific module installed, or what? Or is the code missing something.
But if someone can look at this and tell me either what I need or what is wrong I'd appreciate it.
But, if I need a module to be installed, I will need a work around so all code that is needed , ... is in the script itself.
Is this possible???
Help?
Gary
Gary M. Gordon, LLC
webmaster@garymgordon.com
Certified Web Developer ::
Application Programmer