Erb/apache problem

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

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

···

On Sat, Jun 04, 2005 at 01:50:24AM +0900, HAL 9000 wrote:

Any ideas how to debug this one?

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

--
http://david.holroyd.me.uk/

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

The file ends up zero length...

Thanks, though...

More ideas, anyone?

HF

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

···

On 03/06/05, HAL 9000 <hal9000@hypermetrics.com> wrote:

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

The file ends up zero length...

Thanks, though...

More ideas, anyone?

HF

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

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

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

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

···

On 6/3/05, HAL 9000 <hal9000@hypermetrics.com> wrote:

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

The file ends up zero length...

Thanks, though...

More ideas, anyone?

HF

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.