Can an .rbx file send it's own code?

Hello,

I was wondering if there’s a way to make a web page (generated in Ruby) with
a link which, when clicked, would send itself… not the generated page, but
the actual page-generating Ruby program, the whole .rbx file.

I can’t figure out any easy way to do this… any thoughts?

Chris

Without getting into all of the cgi processing…

script = nil
open(‘selfname’, ‘r’) { |fh| script = fh.read }

send the appopriate header and puts script. Theres a variable that contains the
name of the script, but I can recall what it is right now.

···

On Sat, Dec 14, 2002 at 02:27:03AM +0900, Chris Pine wrote:

Hello,

I was wondering if there’s a way to make a web page (generated in Ruby) with
a link which, when clicked, would send itself… not the generated page, but
the actual page-generating Ruby program, the whole .rbx file.

I can’t figure out any easy way to do this… any thoughts?

Chris


Alan Chen
Digikata Computing
http://digikata.com

Scripsit ille Chris Pine nemo@hellotree.com:

I was wondering if there’s a way to make a web page (generated in Ruby) with
a link which, when clicked, would send itself… not the generated page, but
the actual page-generating Ruby program, the whole .rbx file.

Is it called via CGI?

puts “Content-type: text/plain”
puts
IO.foreach(ENV[‘SCRIPT_FILENAME’]) do |l|
print l
end

Do that if a certain CGI parameter in the query string is set.

What should I use instead of ENV[‘SCRIPT_FILENAME’] if the script is not
necessarily called via CGI (instead, via the shell or using mod_ruby)?

···


“Note that if I can get you to “su and say” something just by asking,
you have a very serious security problem on your system and you should
look into it.”
– (By Paul Vixie, vixie-cron 3.0.1 installation notes)

Hi,

···

At Sat, 14 Dec 2002 02:27:03 +0900, Chris Pine wrote:

I was wondering if there’s a way to make a web page (generated in Ruby) with
a link which, when clicked, would send itself… not the generated page, but
the actual page-generating Ruby program, the whole .rbx file.

I can’t figure out any easy way to do this… any thoughts?

DATA.rewind
print DATA.read
END

I suspect it doesn’t work with eRuby/mod_ruby.


Nobu Nakada

I was wondering if there’s a way to make a web page (generated in Ruby) with
a link which, when clicked, would send itself… not the generated page, but
the actual page-generating Ruby program, the whole .rbx file.

···

On Sat, 14 Dec 2002, Chris Pine wrote:

#!/usr/bin/ruby

putfile.rbx

puts “Content-type: text/plain/n/n”
filename = cgi[‘filename’]

goodfiles = [‘scriptone.rbx’,‘foo.rbx’,‘bar.rbx’,‘baz.rbx’]
if goodfiles.index(filename,‘r’)
fd = open(filename)
puts fd.readlines
fd.close
else
puts “You do not have permission to read that file”
end

Then in your scripts

foo.rbx



puts “<a href="putfile.rbx?filename=$0">Source code to this file”

Hope that helps.

  • Greg.


Greg Millam
walker at deafcode.com

i put this simple test at the front of the main body of the script:

···

On Friday, December 13, 2002, at 12:27 , Chris Pine wrote:

Hello,

I was wondering if there’s a way to make a web page (generated in Ruby)
with
a link which, when clicked, would send itself… not the generated
page, but
the actual page-generating Ruby program, the whole .rbx file.

I can’t figure out any easy way to do this… any thoughts?

Chris


cgi = CGI.new ## or whatever CGI library you use

if cgi.has_key? ‘source’
out = Array.new
out << “Content-type: text/plain\n\n”
File.open $0, ‘r’ do |file|
out << file.read
end
puts out
exit
end

when i want to show the source, simply load the page with ‘source’ as
the cgi argument:

http://tin.2y.net/scripts/bookmarker.rb?source

create a link with ‘source’ in the normally
generated page

-Justin

http://eli.fsl.noaa.gov/cgi-bin/source.cgi

install this in your cgi-bin dir.

when called with

http://your.host.com/cgi-bin/source.cgi?source=filename.cgi

it will display the source named in the query string. the all cgi’s simply
need a link to this program with cgi.script_name as the source.

-a

···

On Sat, 14 Dec 2002 nobu.nokada@softhome.net wrote:

Hi,

At Sat, 14 Dec 2002 02:27:03 +0900, > Chris Pine wrote:

I was wondering if there’s a way to make a web page (generated in Ruby) with
a link which, when clicked, would send itself… not the generated page, but
the actual page-generating Ruby program, the whole .rbx file.

I can’t figure out any easy way to do this… any thoughts?

====================================

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================

Then in your scripts

foo.rbx



puts “<a href="putfile.rbx?filename=$0">Source code to this file”

My bad, that should be #{$0} otherwise it won’t get eval’d.
You might want to put that into a variable at the very start of the
filename, as $0 might be overwritten by regexps.

myfilename=$0

puts “<a href="putfile.rbx?filename=#{myfilename}">Source code to this
file”

Greg.

···


Greg Millam
walker at deafcode.com