erb/apache problem

H

HAL 9000

Hi, all. Posting from work via Google.

I have an Apache server that I don't administer or configure. It
doesn't have mod_ruby, and at this point I don't want to ask for
it to be installed.

I had the idea of using erb via a shebang line in a .cgi file.
It didn't quite work, somehow related to the fact that erb is
a script. (This is on a Sun.) I'm not entirely sure why that is,
but I wrapped it in a simple C program that calls system(), and
it works fine.

So my shebang line looks like: #!/home/prod/bin/erbc
and the rest of the .cgi is just HTML and emnedded Ruby. (If this
is dumb, tell me a better way.)

In most cases, this works fine. I start out each .cgi with a
line like this: <%= "Content-type: text/html\r\n\r\n" %>
and all is well.

However, *one* of them has a problem. It gives me a "premature
end of header" error, although the header is the same as the
others. (I've noticed it seems to give this error, slightly
misleadingly, when some piece of non-header text is output
before/instead of a header.)

I'm guessing that somehow the generated erb program is writing
a warning or error or something that Apache is seeing *before*
the header. If it is, I'm not seeing that information anywhere.

I have run the script directly from the command line, and the
output is fully correct. So it only fails when the web server
runs it. Sounds like some kind of user or permission issue.
The embedded code does read some files, but they all seem to
be world-readable.

Any ideas how to debug this one?

For example, can I "see what the web server sees" (but doesn't
write to the log)?


Thanks,
Hal
 
D

David Holroyd

Any ideas how to debug this one?

For example, can I "see what the web server sees" (but doesn't
write to the log)?

You could write a shell script .cgi that invokes your problem cgi, and
pipes the target's output through tee(1)

Something like...

#!/bin/sh

/path/to/problem.cgi 2>&1 | tee /path/for/log.txt

...maybe?


dave
 
H

HAL 9000

A very reasonable idea, but it doesn't work for me. :(

The file ends up zero length...

Thanks, though...

More ideas, anyone?

HF
 
B

Brian Schröder

A very reasonable idea, but it doesn't work for me. :(
=20
The file ends up zero length...
=20
Thanks, though...
=20
More ideas, anyone?
=20
HF
=20
=20
Why don't you use ruby in cgi mode. Like:

---8<-------8<----
#!/usr/bin/ruby

puts "content-type:text/plain\r\n\r\n"

puts "CGI-Output:"
system "/my/problem.cgi"
puts "---"
---8<-------8<----

regards,

Brian

--=20
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/
 
A

Andre Nathan

HAL 9000 said:
More ideas, anyone?

You could install ethereal (www.ethereal.com) in your machine, and
capture the traffic between you and the webserver (just using the
webserver name as the capture filter should be enough). Then
righ-click on one of the HTTP packets and choose "follow tcp stream".
This will show you the whole talk between browser and server, and
probably will give a hint on what the problem is.

HTH
Andre
 
P

Paul

This is how I got 1.6 to work on an unamed popular (read cheap) host.

Added to .htaccess in /htdocs ....
AddHandler cgi-script .rb
Action application/x-httpd-ruby /usr/local/bin/ruby16?

AddHandler rubypage .rhtml .rtml
Action rubypage /erbrun.cgi?
.....

created erbrun.cgi, placed in /htdocs ....
#!/usr/local/bin/ruby16 -I/www/m/mysite/cgi-bin/ruby/lib/ruby/1.8
puts "Content-type: text/html\n\n"
require 'erb/erb'
fh = File.new( ENV['DOCUMENT_ROOT'] +
ARGV[0] )
eruby_script = fh.read
erb = ERb.new(eruby_script)
print erb.result( binding

)
..... placed in /htdocs

create try.rhtml & place on server somewhere ....
<html>
<head>
<title>eruby example</title>
</head>
<body>
<h1>Enumeration</h1>
<ul>
<%(1..10).each do|i|%>
<li>number <%=i%></li>
<%end%>
</ul>
<h1>Environment variables</h1>
<table>
<%ENV.keys.sort.each do |key|%>
<tr>
<th><%=key%></th><td><%=ENV[key]%></td>
</tr>
<%end%>
</table>
</body>
</html>
..... browse to www.mysite.com/somewhere/try.rhtml and it works .

create testruby.rb somewher on the server ....
#!/usr/local/bin/ruby16
puts "Content-type: text/html\n\n"
puts "<HTML><PRE>Test\n"
print `ls -alF /usr/local/lib/ruby/1.6/`
.....

testruby.rb also works from the browser.

Hope this helps.
 
L

Logan Capaldo

A very reasonable idea, but it doesn't work for me. :(
=20
The file ends up zero length...
=20
Thanks, though...
=20
More ideas, anyone?
=20
HF
=20
=20
=20

Well that's the beginning of your problem. Its getting EOF before
there are any headers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top