[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Remote IRB shell (embedded in rails

Charles L.

5/4/2007 11:37:00 AM

I wasn't able to find this functionality in rails to begin with, so I
wrote a small wrapper to allow you to provide direct IRB shell access
into any long running app (for debug purposes, or as a way to control a
remote machine).

In your app, just require irb/server.rb (http://pastie.cabo...),
then run irb/client.rb (http://pastie.cabo...), passing it the
DRb url.

This allows me to run an IRB window on my local machine, with access to
the currently running rails app on my server.

Hope you find it useful...

--
Posted via http://www.ruby-....

7 Answers

eden li

5/5/2007 4:40:00 AM

0

Interesting... although it sounds a bit insecure since you don't
authenticate and it's being run in the clear over the wire.

I wonder if there's a way to get ruby to tunnel this via ssh.

On May 4, 7:37 pm, Charles Lowe <aquas...@gmail.com> wrote:
> I wasn't able to find this functionality in rails to begin with, so I
> wrote a small wrapper to allow you to provide direct IRB shell access
> into any long running app (for debug purposes, or as a way to control a
> remote machine).
>
> In your app, just require irb/server.rb (http://pastie.cabo...),
> then run irb/client.rb (http://pastie.cabo...), passing it the
> DRb url.
>
> This allows me to run an IRB window on my local machine, with access to
> the currently running rails app on my server.
>
> Hope you find it useful...
>
> --
> Posted viahttp://www.ruby-....


Marcin Raczkowski

5/5/2007 9:48:00 AM

0

On Saturday 05 May 2007 04:39, eden li wrote:
> Interesting... although it sounds a bit insecure since you don't
> authenticate and it's being run in the clear over the wire.
>
> I wonder if there's a way to get ruby to tunnel this via ssh.
>
ssh remote host
irb

or is it to simple for you?
but well it's insecure - but you can always add authentication and do it over
ssl
> On May 4, 7:37 pm, Charles Lowe <aquas...@gmail.com> wrote:
> > I wasn't able to find this functionality in rails to begin with, so I
> > wrote a small wrapper to allow you to provide direct IRB shell access
> > into any long running app (for debug purposes, or as a way to control a
> > remote machine).
> >
> > In your app, just require irb/server.rb (http://pastie.cabo...),
> > then run irb/client.rb (http://pastie.cabo...), passing it the
> > DRb url.
> >
> > This allows me to run an IRB window on my local machine, with access to
> > the currently running rails app on my server.
> >
> > Hope you find it useful...
> >
> > --
> > Posted viahttp://www.ruby-....

--
Marcin Raczkowski
---
Friends teach what you should know
Enemies Teach what you have to know

Robert Dober

5/5/2007 10:46:00 AM

0

On 5/5/07, eden li <eden.li@gmail.com> wrote:
> Interesting... although it sounds a bit insecure since you don't
> authenticate and it's being run in the clear over the wire.
>
> I wonder if there's a way to get ruby to tunnel this via ssh.
Unless ruby sends address information on the application layer (as
e.g. Corba does or in redirects) you can do ssh port forwarding.

Let you IRB server serve on server:4242, assuming an ssh server
listening on port 22 on the server and a user ruby just do the
following on the client machine

ssh -fNL 2222:localhost:4242 ruby@server # (1)

do not forget to kill the ssh process on the client eventually.

The ruby client connects to localhost:2222 on the client machine now.

(1) N.B. localhost is localhost at the server.

HTH
Robert

eden li

5/6/2007 4:59:00 AM

0

Nice, looks like this would work. Just have to make sure that 4242 is
firewalled or only bound to lo on the server side.

As far as I can tell, all traffic is tunneled via SSH, so unless
something is on your machine (or your server) sniffing your loopback
device (or unless my understanding of how tunneling works), it should
be totally protected.

On May 5, 6:46 pm, "Robert Dober" <robert.do...@gmail.com> wrote:
> On 5/5/07, eden li <eden...@gmail.com> wrote:> Interesting... although it sounds a bit insecure since you don't
> > authenticate and it's being run in the clear over the wire.
>
> > I wonder if there's a way to get ruby to tunnel this via ssh.
>
> Unless ruby sends address information on the application layer (as
> e.g. Corba does or in redirects) you can do ssh port forwarding.
>
> Let youIRBserver serve on server:4242, assuming an ssh server
> listening on port 22 on the server and a user ruby just do the
> following on the client machine
>
> ssh -fNL 2222:localhost:4242 ruby@server # (1)
>
> do not forget to kill the ssh process on the client eventually.
>
> The ruby client connects to localhost:2222 on the client machine now.
>
> (1) N.B. localhost is localhost at the server.
>
> HTH
> Robert


eden li

5/6/2007 5:02:00 AM

0

Yes :) The cool thing about this is you can get an irb shell right
into the ruby process running rails, which means you can do all sorts
of useful stuff like twiddling class variables and inspecting your
controller states directly.

Probably a bad idea to do this in production, but could be useful
during development.

On May 5, 5:48 pm, Marcin Raczkowski <swis...@mailx.expro.pl> wrote:
> ssh remote host
> irb
>
> or is it to simple for you?


Robert Dober

5/6/2007 8:03:00 AM

0

On 5/6/07, eden li <eden.li@gmail.com> wrote:
> Nice, looks like this would work. Just have to make sure that 4242 is
> firewalled or only bound to lo on the server side.
>
> As far as I can tell, all traffic is tunneled via SSH, so unless
> something is on your machine (or your server) sniffing your loopback
> device (or unless my understanding of how tunneling works), it should
> be totally protected.
Careful here, in our case everything is encrypted, but
if the port forwarding is forwarding a port from a different machine
that is not the case. Look at this command

ssh -fNL 4141:dbhost:mysqlport ruby@ssh-server

all traffic between the client and ssh-server is encrypted but the
forwarded traffic between ssh-server and dbhost is not.
I guess you are aware of that but not everybody is, nor was I before
warned by a colleague.

That still often is what you want especially if dbhost is in a DMZ, of course.

Robert


--
You see things; and you say Why?
But I dream things that never were; and I say Why not?
-- George Bernard Shaw

Charles L.

5/7/2007 7:54:00 AM

0

Eden Li wrote:
> Yes :) The cool thing about this is you can get an irb shell right
> into the ruby process running rails, which means you can do all sorts
> of useful stuff like twiddling class variables and inspecting your
> controller states directly.
>
> Probably a bad idea to do this in production, but could be useful
> during development.

Precisely. It's not intended to be exposed remotely. I've no idea what
DRb's ACL stuff offers etc, but that could be looked at.

The idea was to be able to execute code inside a running ruby
application. Initially this was because I had rails running as a windows
service, and wanted to debug the different environment.

One of the things my (internal) rails app does though, is being a job
process monitor, for scripts largely written in ruby. I can set some
flag, that allows me to not just hook into and monkey patch rails live
:), but also to capture exceptions in a running job, and rescue it
providing this sort of simplistic remote debugging.

At any rate, while it was easy to write, it seems a few things didn't
work with DRb as I thought they should.

I would've imagined that I could simply pass a local
ReadlineInputMethod, and StdioOutputMethod to the remote IRB::Irb#new,
but in fact that still did both input and output remotely - hence the
kind of cumbersome proxies.

Remote output still didn't work, but that seems to be an IRB issue.

--
Posted via http://www.ruby-....