WEBrick for a local application?

J

Jeremy Bear

Hello!

I'm considering writing a dream journaling program for a small group
of friends, and we're on different platforms. I'm on Linux, one is on
FreeBSD, and others are on WindowsXP. Basically, I wanted to do
something that would yield a nice cross-platform GUI. I've looked at
using Tk, but I know that on the Linux/BSD platforms, it's rather
ugly. I thought about making a Web based gui for the program, since I
could use CSS and such to really make the interface look nice.

I've looked at the WEBrick docs and samples, and, it looks like it
could yield a decent solution. I've played around with it a little,
and I realized that starting it up at all makes an open port to the
outside world if you're online. That isn't exactly what I wanted to
do.

My main question, I guess, is this: Is there any way that I can use
WEBrick in a local setting only that will not open up a persons
computer to the outside world? I think that it could make a nice
application base, but I don't want to compromise one's security while
using it.

I really wanted to keep downloads for these people to be kept to a
minimum, so I didn't really want to make them download a bunch of
extra GUI libraries. I also wanted something that would run fairly
quick, and would be easy to use. (for some reason I have had a hard
time grasping Fox, although Tk was easy enough)

Am I barking up the wrong tree with this?

Thanks,
Jeremy
 
J

Joao Pedrosa

Hi,

Hello!

I'm considering writing a dream journaling program for a small group
of friends, and we're on different platforms. I'm on Linux, one is on
FreeBSD, and others are on WindowsXP. Basically, I wanted to do
something that would yield a nice cross-platform GUI. I've looked at
using Tk, but I know that on the Linux/BSD platforms, it's rather
ugly. I thought about making a Web based gui for the program, since I
could use CSS and such to really make the interface look nice.

I've looked at the WEBrick docs and samples, and, it looks like it
could yield a decent solution. I've played around with it a little,
and I realized that starting it up at all makes an open port to the
outside world if you're online. That isn't exactly what I wanted to
do.

My main question, I guess, is this: Is there any way that I can use
WEBrick in a local setting only that will not open up a persons
computer to the outside world? I think that it could make a nice
application base, but I don't want to compromise one's security while
using it.

I really wanted to keep downloads for these people to be kept to a
minimum, so I didn't really want to make them download a bunch of
extra GUI libraries. I also wanted something that would run fairly
quick, and would be easy to use. (for some reason I have had a hard
time grasping Fox, although Tk was easy enough)

Am I barking up the wrong tree with this?

WEBrick rocks.

You can use :BindAddress => local_ip and it will be LAN accessible only. Like:

:BindAddress => 192.168.0.100, :port => 2000

See its code, as I use Wee and its a bit different, like:
Wee::WEBrickAdaptor.register('/app' => app).start:)BindAddress =>
'192.168.0.100', :port => 2000)

Cheers,
Joao
 
V

vruz

My main question, I guess, is this: Is there any way that I can use
WEBrick in a local setting only that will not open up a persons
computer to the outside world? I think that it could make a nice
application base, but I don't want to compromise one's security while
using it.

Bind the webserver to the 127.0.0.1 IP address and it will be only
accesible from the local host

Web-based applications are very common nowadays, I don't think anyone
will be surprised by that.

cheers,
vruz
 
J

Joao Pedrosa

Hi,

Hi,



WEBrick rocks.

You can use :BindAddress => local_ip and it will be LAN accessible only. Like:

:BindAddress => 192.168.0.100, :port => 2000

See its code, as I use Wee and its a bit different, like:
Wee::WEBrickAdaptor.register('/app' => app).start:)BindAddress =>
'192.168.0.100', :port => 2000)

I could have asked, do you know Wee already? It's very capable in
delivering Web-Apps. After a day or so you will have your solution
partly done already.

See: http://rubyforge.org/projects/wee/

WEBrick is its main backend so far.

Cheers,
Joao
 
J

Jeremy Bear

My main question, I guess, is this: Is there any way that I can use
WEBrick rocks.

You can use :BindAddress => local_ip and it will be LAN accessible only. Like:

:BindAddress => 192.168.0.100, :port => 2000

See its code, as I use Wee and its a bit different, like:
Wee::WEBrickAdaptor.register('/app' => app).start:)BindAddress =>
'192.168.0.100', :port => 2000)

Ah, okay. This seems simple enough. My question regarding this,
though, is: What if I don't know what they have their local IP set to?
Does it need to match their IP, or is there a more "generic" one I
can use, such as the 127.0.0.1 address that vruz mentioned, that will
work no matter what for the local host?

Thanks all for the extremely quick responses!

Jeremy
 
L

Luke Graham

Ah, okay. This seems simple enough. My question regarding this,
though, is: What if I don't know what they have their local IP set to?
Does it need to match their IP, or is there a more "generic" one I
can use, such as the 127.0.0.1 address that vruz mentioned, that will
work no matter what for the local host?

127.0.0.1 is the standard loopback address, it works on windows and unix,
and most other places as well.
 
B

Bill Guindon

Ah, okay. This seems simple enough. My question regarding this,
though, is: What if I don't know what they have their local IP set to?
Does it need to match their IP, or is there a more "generic" one I
can use, such as the 127.0.0.1 address that vruz mentioned, that will
work no matter what for the local host?

127.0.01 is the IP for 'localhost' (ie: "this machine"), so it's a
safe bet that.
The only time I could see it being an issue is if they're already
running another server of some kind on the same port (unlikely).
 
J

Joao Pedrosa

Hi,

Ah, okay. This seems simple enough. My question regarding this,
though, is: What if I don't know what they have their local IP set to?
Does it need to match their IP, or is there a more "generic" one I
can use, such as the 127.0.0.1 address that vruz mentioned, that will
work no matter what for the local host?

127.0.0.1 is suitable as well, but this is accessible from the same
machine only. The 192.168.0.100 approach is useful if you need the
same WEBrick shared in a LAN, as if all the three of you were somehow
connected in the same LAN, but I guess not.

Cheers,
Joao
 
E

Eko Budi Setiyo

Bill said:
127.0.01 is the IP for 'localhost' (ie: "this machine"), so it's a
safe bet that.
The only time I could see it being an issue is if they're already
running another server of some kind on the same port (unlikely).
Is Webrick can be use for single point of entry (every request served by
index.rb).

regards
Eko
 
V

vruz

Ah, okay. This seems simple enough. My question regarding this,
though, is: What if I don't know what they have their local IP set to?
Does it need to match their IP, or is there a more "generic" one I
can use, such as the 127.0.0.1 address that vruz mentioned, that will
work no matter what for the local host?

yes, 127.0.0.1 is your safest bet.

It won't be useful if you need to access the app from other machines
in the local network though.

If you need the app to be accessible from other machines in the local
network you may have to detect the available local addresses
(generally something in the 192.168.xxx.xxx range)
but that detection is probably system-dependent.

cheers,
vruz
 
J

Jeremy Bear

Is Webrick can be use for single point of entry (every request served by
index.rb).

Eko,

The concept makes sense, but I have to admit that finding
documentation for WEBrick has been... challenging. Could you
elaborate on this a bit? What do you mean by a single point of entry?

Thanks,
Jeremy
 
E

Eko Budi Setiyo

Jeremy said:
Eko,

The concept makes sense, but I have to admit that finding
documentation for WEBrick has been... challenging. Could you
elaborate on this a bit? What do you mean by a single point of entry?

Thanks,
Jeremy
Actually, I believe in the single point of entry power.
I used it in FuseLogic(php) and QLogic (ruby). index.php or index.rb
will decide which module will be executed base on the user response
(REQUES_URI).
One example of the benefit among the others is, lets say I change my
hosting company and some how the install ruby on difference path. What I
have to do is just change
the first line from #!/bin/ruby to #!/user/bin/ruby (this is example
only!) in the index.rb

The reason I ask is I already try to use Webrick and doesn't do what I
want.
What happen to my scripts is, lets say I already use my browser to hit
http://127.0.0.1/index.rb/init/version than after that I hit
http://127.0.0.1/index.rb/bittorrents/main ,
Webrick will always give the same result as
http://127.0.0.1/index.rb/init/version

I really want to use webrick also for my RubyToday project

May be I am doing some thing wrong here. I don't know



Regards
Eko
 
V

vruz

Actually, I believe in the single point of entry power.
I used it in FuseLogic(php) and QLogic (ruby). index.php or index.rb
will decide which module will be executed base on the user response
(REQUES_URI).
One example of the benefit among the others is, lets say I change my
hosting company and some how the install ruby on difference path. What I
have to do is just change
the first line from #!/bin/ruby to #!/user/bin/ruby (this is example
only!) in the index.rb
The reason I ask is I already try to use Webrick and doesn't do what I
want.
What happen to my scripts is, lets say I already use my browser to hit
http://127.0.0.1/index.rb/init/version than after that I hit
http://127.0.0.1/index.rb/bittorrents/main ,
Webrick will always give the same result as
http://127.0.0.1/index.rb/init/version

I really want to use webrick also for my RubyToday project

May be I am doing some thing wrong here. I don't know

Regards
Eko


Jeremy, the confusion arises because Eko is asking about a completely
different , unrelated, problem in this thread.

Eko, maybe if you post some source code to look at ?

That will make it way much easier to find what's your your problem about

cheers,
vruz
 
B

Bill Guindon

Actually, I believe in the single point of entry power.
I used it in FuseLogic(php) and QLogic (ruby). index.php or index.rb
will decide which module will be executed base on the user response
(REQUES_URI).
One example of the benefit among the others is, lets say I change my
hosting company and some how the install ruby on difference path. What I
have to do is just change
the first line from #!/bin/ruby to #!/user/bin/ruby (this is example
only!) in the index.rb

The reason I ask is I already try to use Webrick and doesn't do what I
want.
What happen to my scripts is, lets say I already use my browser to hit
http://127.0.0.1/index.rb/init/version than after that I hit
http://127.0.0.1/index.rb/bittorrents/main ,
Webrick will always give the same result as
http://127.0.0.1/index.rb/init/version

I really want to use webrick also for my RubyToday project

May be I am doing some thing wrong here. I don't know

What are you doing in index.rb? I'd think a simple 'include' would do
it after you parse the URI, but I could be missing something.
 
E

Eko Budi Setiyo

vruz said:
Jeremy, the confusion arises because Eko is asking about a completely
different , unrelated, problem in this thread.

Eko, maybe if you post some source code to look at ?

That will make it way much easier to find what's your your problem about

cheers,
vruz
Ok, here is my code

#-----------------------------------------------------------------
#
#File Name = class.index.rb
#
#

class Index < HTTPServlet::AbstractServlet

def do_GET(req,resp)
temp = req.unparsed_uri.to_s
temp = temp.str_ireplace('/index.rb/','')
temp = 'fuse='+temp
ARGV[0] = temp
load('coreLoader.rb')
resp.body = $Layout
end

def Index.get_instance config, *options
load __FILE__
load('coreLoader.rb')
Index.new config, *options
end

end


#----------------------------------------------------------------------
#
#file name = start_webrick.rb
#

require 'webrick'

class String
def str_replace(what,with)
re = Regexp.new(Regexp.quote(what))
self.gsub(re,with)
end
def str_ireplace(what,with)
re = Regexp.new(Regexp.quote(what), Regexp::IGNORECASE)
self.gsub(re,with)
end
end

$Layout = ''
def puts(string = '')
$Layout += "\n"+string.to_s
super
end

include WEBrick

load('class.index.rb')

def start_webrick(config = {})
##config.update:)Port => 8080)
config.update:)Port => 80)
config.update:)DirectoryIndex => 'a.rb')
$server = HTTPServer.new(config)
yield server if block_given?
['INT','TERM'].each { |signal|
trap(signal) {server.shutdown}
}
$server.mount('/index',Index)
$server.start
end

start_webrick:)DocumentRoot => File.dirname(__FILE__))

regards
Eko
 
E

Eko Budi Setiyo

Bill said:
What are you doing in index.rb? I'd think a simple 'include' would do
it after you parse the URI, but I could be missing something.
index.rb is the gate off all the module. inside module there are
submodule or "fuse'
index.rb is some kind of the gate to "Front Controller"

regards
Eko
 
L

Lee Braiden

Hello!

I'm considering writing a dream journaling program for a small group
of friends, and we're on different platforms. I'm on Linux, one is on
FreeBSD, and others are on WindowsXP. Basically, I wanted to do
something that would yield a nice cross-platform GUI. I've looked at
using Tk, but I know that on the Linux/BSD platforms, it's rather
ugly.

Ruby has GTK and Qt APIs too.
I've looked at the WEBrick docs and samples, and, it looks like it
could yield a decent solution.

I'd suggest looking at Rails. It's a very elegant ruby-based web development
solution that can be used to create simple database front ends VERY quickly.
For example, if you wanted a simple log of entries by different users, that
would mean adding a table to a database, running about four commands to setup
rails, editing two files with a few lines of text, and you're done.
Obviously, you have more work to do if you want to customise the looks etc.,
but it's basically what you'd expect to be doing. Just feels "right" to
me :)

It's also WEBrick based, but has the option of using Apache etc. too. Either
way, there's no problem with running it (or any other web-based solution) on
a private LAN, if you need too. As others have said, you just pick and
internal IP. Even a normal web server with access control would work, if
you're desperate. And there's the secondary layer of a firewall to limit
access too.
 
A

Alan Chen

If you dig around in the Ruwiki distribution on rubyforge, I believe we
have a webrick configuration which assigns a connection acception
callback. The "localhost" callback only allows connections from a list
of ips. If you only want your machine... 127.0.0.1 should be the only
ip in the list. Here are the applicable snippets: (though you might
want to browse through the ruwiki_servlet files for more context)

@server = WEBrick::HTTPServer.new:)Port => opts.port.to_i,
:StartThreads =>
opts.threads.to_i,
:AcceptCallback => localonly,
:Logger => logger)

localonly = proc do |sock|
if not opts.addresses.include?(sock.peeraddr[3])
msg = "Rejected peer address #{sock.peeraddr[3]}. Connections are
only accepted from: #{opts.addresses.join(", ")}."
raise WEBrick::ServerError, msg
end
end
 

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

Forum statistics

Threads
473,780
Messages
2,569,607
Members
45,240
Latest member
pashute

Latest Threads

Top