Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

net_require

0 views
Skip to first unread message

Jack Dempsey

unread,
Jan 7, 2002, 1:16:11 AM1/7/02
to
To Mark and others interested: the following code could be used to try requiring a file and if its not able to do so, go to a repository site and download it...that's all it does currently, but with security issues being discussed along the way, i think it might prove useful to those who'd care to use it:
 
#!/usr/bin/ruby
 
require 'net/http'
 
def net_require(file)
   begin
    require file
   rescue LoadError
    net_download(file)
    #could now require the file here
   end
end
 
def net_download(file)
  site = 'www.ruby-lang.org'
  #file << '.rb' if !(file =~ /.rb/)
  begin
    h = Net::HTTP.new(site,80)
    resp, data = h.get(file)
    filename = file.split('/').pop
    puts filename
    File.open(filename,'w') do |line|
      line.puts data
    end
  rescue => err
    puts "Error: #{err}"
    exit
  end  
end
 
if $0 == __FILE__
  net_require '/en/index.html'
end

Mark Hahn

unread,
Jan 7, 2002, 1:26:55 AM1/7/02
to
> the following code could be used to try requiring a file
 
Do you have a test case for this?  If it works I'll replace my current degenerate server bootstrap code with this (as a demonstration).
 
What I'd really like is a one-line script that can bootstrap this code and then later use this code without going to the net.

Tanaka Akira

unread,
Jan 7, 2002, 1:32:21 AM1/7/02
to
In article <OE59qHNwK39FM...@hotmail.com>,
"Jack Dempsey" <dabi...@hotmail.com> writes:

> To Mark and others interested: the following code could be used to try requiring a file and if its not able to do so, go to a repository site and download it...that's all it does currently, but with security issues being discussed along the way, i think it might prove useful to those who'd care to use it:

I had similar idea few weeks ago.
http://www.ruby-lang.org/en/raa-list.rhtml?name=net-require

Since it redefines `require' method, it works without modification of
application except -rnet-require option for ruby command.
--
Tanaka Akira

Mark Hahn

unread,
Jan 7, 2002, 1:32:15 AM1/7/02
to

Amazing coincidence. The name even matches.

-----Original Message-----
From: Tanaka Akira [mailto:a...@m17n.org]
Sent: Sunday, January 06, 2002 10:27 PM
To: ruby-talk ML

Mark Hahn

unread,
Jan 7, 2002, 2:25:26 AM1/7/02
to
This is getting really big, but how about this bootstrap code that uses the
file after the first time instead of the net:

begin;require'net_require';rescue LoadError
require'socket';File.open('net_require.rb','w'){|f|
f.write TCPSocket.new('216.101.169.124',8).read} retry end

require 'xxx'

Note that net_require.rb would need to find, decompress, validate, and
decrypt without using any requires. If any language can do this Ruby can.
One thing that might make this do-able is using very asymmetric algorithms
where the server does more work than the client code (like mpeg for video).
This preparation can be done in advance for each download unit.

-----Original Message-----
From: Jack Dempsey [mailto:dabi...@hotmail.com]

Sent: Sunday, January 06, 2002 10:39 PM
To: Mark Hahn
Subject: Re: net_require


if you wanted to strip this down and just save the file you could do this:
require 'net/http';
def net_require
resp,data = Net::HTTP.new('www.site.com',80).get('filename')
File.open('filename','w') do |line| line.puts data end
end

then require where you need...
and you can test it with any file, i used the index.html of ruby-lang.org


----- Original Message -----
From: "Mark Hahn" <mch...@facelink.com>
To: "ruby-talk ML" <ruby...@ruby-lang.org>
Sent: Monday, January 07, 2002 1:24 AM
Subject: RE: net_require


> the following code could be used to try requiring a file

Do you have a test case for this? If it works I'll replace my current


degenerate server bootstrap code with this (as a demonstration).

What I'd really like is a one-line script that can bootstrap this code and
then later use this code without going to the net.
-----Original Message-----
From: Jack Dempsey [mailto:dabi...@hotmail.com]

Sent: Sunday, January 06, 2002 9:38 PM
To: ruby-talk ML
Subject: [ruby-talk:30440] net_require


To Mark and others interested: the following code could be used to try
requiring a file and if its not able to do so, go to a repository site and
download it...that's all it does currently, but with security issues being
discussed along the way, i think it might prove useful to those who'd care
to use it:

#!/usr/bin/ruby

Michal Rokos

unread,
Jan 10, 2002, 2:50:53 PM1/10/02
to
Hello Mark,

Mark Hahn <mch...@facelink.com> wrote:
> Note that net_require.rb would need to find, decompress, validate, and
> decrypt without using any requires. If any language can do this Ruby can.
> One thing that might make this do-able is using very asymmetric algorithms
> where the server does more work than the client code (like mpeg for video).
> This preparation can be done in advance for each download unit.

You can maybe use 'OpenSSL for Ruby' - it has RSA signing, SSL
Sockets (from Gotou Yuuzou), ciphers, digests and so on...

Michal

--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Michal Rokos Czech Technical University, Prague
E-mail: m.r...@sh.cvut.cz Jabber: ma...@jabber.cz, ICQ: 36118339
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

0 new messages