Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have a script that looks like thi 5

Status
Not open for further replies.

garymgordon

Programmer
Apr 5, 2000
307
US
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 &quot;sys/socket.ph&quot;;
use Socket;
require &quot;./common.pl&quot;;

$sockaddr = &quot;S n a4 x8&quot;;

($name,$aliases,$proto) = getprotobyname('tcp');

push(@INC, &quot;/usr/local/etc/httpd/bin&quot;);
push(@INC, split(':', $ENV{&quot;PATH&quot;}));
require &quot;cgi-lib.pl&quot;;
&ReadParse;

if ($in{'url'} !~ m@^[^\.]+\.)+[^\.]+@) {
print &quot;Content-type: text/html\n\n&quot;;
print &quot;Sorry, I can only handle URLs.\n&quot;;
print &quot;You typed in `<tt>$in{'url'}</tt>'.\n&quot;;
exit 0;
}

$in{'url'} .= &quot;/&quot; 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 &quot;Location: $in{'url'}\n&quot;;
print &quot;Content-type: text/html\n\n&quot;;
print &quot;You didn't select anything useful\n&quot;;
exit 0;
}

$agent = $in{'agent'};
if ($in{'agent'} eq $ENV{&quot;HTTP_USER_AGENT&quot;}) {
delete $in{'agent'};
}

print &quot;Content-type: text/html\n\n&quot;;

$u = $in{'url'};
$u =~ s/\&amp;/&/g;

$file = &webget($u);

print &quot;<base href=\&quot;$in{'url'}\&quot;>\n&quot;;

($urlhead,$urlpath) = $in{'url'} =~ m@([^/]+/+[^/]+)(.*)@;
$urlpath =~ s@/[^/]+$@/@;
$urlpath = &quot;/&quot; unless $urlpath;

$me = &quot;
for $o (keys %in) {
$v = $in{$o};
print &quot;<!-- $o = $v -->\n&quot;;
$v =~ s/([^a-zA-Z0-9])/sprintf(&quot;%%%2x&quot;, ord($1));/ge;
push(@o, &quot;$o=$v&quot;) unless $o eq &quot;url&quot;;
$toprint .= &quot;<input type=hidden name=$o value=\&quot;$v\&quot;>\n&quot; unless $o eq &quot;url&quot;;
}
$me .= join(&quot;&amp;&quot;, @o);
$me .= &quot;&url=&quot;;

if ($file !~ /<frameset/i) {
print &quot;<title>WPBCV: $in{'url'}</title><center>\n&quot;;

print &quot;<form method=\&quot;GET\&quot; action=\&quot;
print &quot;<!-- Filtered by -->\n&quot;;
print $toprint;
open(BURST, &quot;burst.inc&quot;);
print while <BURST>;
close(BURST);
print &quot;<br><small><i><a href=\&quot; Page Backwards Compatibility Viewer</a>\n&quot;;
print &quot;WPBCV: <input name=url value=\&quot;$in{'url'}\&quot; size=80><br>\n&quot;;
print &quot;<i>This service is intended to be used only by content developers, on their own pages.</i>\n&quot;;
print &quot;<hr noshade size=2></small></form></center>\n&quot;;
}

$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 &quot;<!-- tag eq `$tag' t eq `$t' -->\n&quot;;

if ($tag eq &quot;head&quot; && $end) {
print &quot;<base href=\&quot;$in{'url'}\&quot;>\n&quot;;
}

if ($tag eq &quot;a&quot; && !$end) {
$t =~ s/href=\&quot;([^\&quot;]+)\&quot;/&rebase_url(&quot;href&quot;, $1)/gioe; #&quot;
$t =~ s/href=([^\&quot;> ]+)([ >])/&rebase_url(&quot;href&quot;, $1,$2)/gioe; #&quot;
if (! $in{'script'}) {
$t =~ s/\son([a-zA-Z]+\s*=)/ XX$1/g;
}
}

if ($tag eq &quot;img&quot;) {
if ($t =~ /src\s*=\s*[^\&quot;\s]/i) {
$t =~ s@src\s*=\s*([^\s>]+)@src=&quot;$1&quot;@i; #&quot;
}
}

if ($tag eq &quot;img&quot; && ! $in{'img'}) {
if ($in{'img_broken'}) {
#$t =~ s@src=&quot;[^\&quot;]+&quot;@src=&quot;this-is-a-broken-image.gif&quot;@
$t =~ s@src=&quot;[^\&quot;]+&quot;@src=&quot; } elsif ($t =~ /alt=\&quot;/i) { #&quot;
$t =~ s/.* alt=\&quot;([^\&quot;]*)\&quot;.*/$1/i; #&quot;
} elsif ($t =~ /alt=/i) {
$t =~ s/.* alt=([^\s>]*).*/$1/i;
} else {
$t = &quot;[IMAGE]&quot;;
}
}

elsif ($tag eq &quot;img&quot;) {
if ($in{'img_altless'}) {
#$t =~ s@src=&quot;[^\&quot;]+&quot;@src=&quot;this-is-an-altless-image.gif&quot;@
$t =~ s@src=&quot;[^\&quot;]+&quot;@src=&quot; unless $t =~ /alt=/i;
}
if ($in{'img_sizeless'}) {
unless ($t =~ /width=/i && $t =~ /height=/i) {
if ($t =~ /no-alt.gif/) {
#$t =~ s@src=&quot;[^\&quot;]+&quot;@src=&quot;this-is-a-sizeless-altless-image.gif&quot;@;
$t =~ s@src=&quot;[^\&quot;]+&quot;@src=&quot; } else {
#$t =~ s@src=&quot;[^\&quot;]+&quot;@src=&quot;this-is-a-sizeless-image.gif&quot;@;
$t =~ s@src=&quot;[^\&quot;]+&quot;@src=&quot; }
}
}
}

elsif (($tag eq &quot;table&quot; || $tag eq &quot;tr&quot; || $tag eq &quot;td&quot; || $tag eq &quot;th&quot;
|| $tag eq &quot;thead&quot; || $tag eq &quot;tbody&quot;)
&& ! $in{'table'}) {
$t = &quot;&quot;;
if ($in{'table_br'} && ($tag eq &quot;td&quot; || $tag eq &quot;th&quot;)) {
$t = &quot;<p>&quot;;
}
}

elsif (($tag eq &quot;frame&quot; || $tag eq &quot;frameset&quot; || $tag eq &quot;noframes&quot;)
&& ! $in{'frame'}) {
if ($tag eq &quot;frame&quot;) {
($src) = $t =~ m@src=\&quot;?([^\&quot;]+)\&quot;?@i;
$src2 = &rebase_url(undef, $src);
print &quot;Frame: <a href=\&quot;$src2\&quot;>$src</a><br>\n&quot;;
}
$t = &quot;&quot;;
}

elsif ($tag eq &quot;frame&quot; && !$end) {
$t =~ s/src=\&quot;([^\&quot;]+)\&quot;/&rebase_url(&quot;src&quot;, $1)/gioe; #&quot;
$t =~ s/src=([^\&quot;> ]+)([ >])/&rebase_url(&quot;src&quot;, $1,$2)/gioe; #&quot;
}

elsif ($tag eq &quot;font&quot; && ! $in{'font'}) {
$t = &quot;&quot;;
}

elsif ($tag eq &quot;blink&quot; && ! $in{'blink'}) {
$t = &quot;&quot;;
}

elsif ($tag eq &quot;body&quot; && ! $in{'body'}) {
$t = &quot;<body>&quot;;
}

elsif ($tag eq &quot;center&quot; && ! $in{'center'}) {
$t = &quot;&quot;;
}

elsif ($tag eq &quot;applet&quot; && ! $in{'applet'}) {
$t = &quot;&quot;;
}

elsif ($tag eq &quot;script&quot; && ! $in{'script'}) {
$t = &quot;&quot;;
}
elsif ($tag eq &quot;noscript&quot; && ! $in{'script'}) {
$t = &quot;&quot;;
}

#ADDED : removes style tags <gocubs@bigfoot.com>
elsif ($tag eq &quot;style&quot; && ! $in{'style'}) {
$t = &quot;&quot;;
}
elsif ($tag eq &quot;link&quot; && ! $in{'style'}) {
$t = &quot;&quot;;
}
elsif (! $in{'style'}) {
$t =~ s/\s(style\s*=)/ XX$1/g;
}


elsif ($tag eq &quot;marquee&quot; && ! $in{'marquee'}) {
$t = &quot;&quot;;
}

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:

&quot;Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.&quot;

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
 
For starters, add the following to the beginning of your script, just after the bash:
use CGI;
use CGI::Carp qw(fatalsToBrowser);


If this doesn't help, then break your script down into components and check the first, then the first & second, and so on until you hit your error. There's always a better way...
 
Make sure you are FTPing any plain-text files (such as perl code) between a Windows machine and a unix/linux machine using ASCII format. Make sure to chmod 775 so that the script is executable. If these have been done, then either checking the error logs or doing the &quot;fatalsToBrowser&quot; as tviman suggested should give you a description of your error. Please let us know what the error is if you are still having trouble.

BTW, hello neighbor... I'm right up the Turnpike from you.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top