[RFC] framework of Ruby/Tk + VNC

Discussion in 'Ruby' started by Hidetoshi NAGAI, Jun 10, 2005.

  1. Hi,

    I'm working on a framework of Ruby/Tk + VNC.
    Its purpose is to put GUI applications of Ruby/Tk on internet view.
    The concept of the framework is,

    * Use VNC (RFB protocol)

    * A GUI application is running on a safe (safe-Tk) based
    slave interpreter (usually, $SAFE == 4).
    If required, you can also use a non-safe based slave.

    * Never use general window managers to decrease security risk.
    Except a VNC server, only one Ruby/Tk process is running.
    # In the future, it may be expected that Ruby/Tk has
    # RFB server functions and no VNC server is required
    # for this purpose.

    * A canvas widget of the master interpreter works like
    as a window manager. The canvas widget administers the
    slave interpreter's root/toplevel widgets by window items
    embedded them.

    By comparison with using tclplugin, probably, the followings
    are advantages.

    * If the user already has a kind of VNC viewer,
    he can use it to access the application.

    * When the user access the application by a web browser,
    the application server can send a JAVA viewer applet.
    Therefore, the user doesn't need to install any plugins.

    * Even if the application uses some Tcl/Tk extensions,
    the user doesn't need to install such extensions.

    * No need to send the source of the application.
    Funcamentally, interchanged data are only window events
    and display images on RFB protocol.
    So, it can decrease the cost of care for security.

    Disadvantages are,

    * Slow, because it is remote access through networks.

    * Much resources are required on the server.

    A sample script based on this concept is attached
    at the end of this mail.
    That requires 2005/06/08 or later version of Ruby.
    Please note that, because of using multi-tk library,
    the description of script on the slave interpreter is
    almost same as the description of usual Ruby/Tk script.

    Although it is an old and slow machine and is not
    decided how long term it is available to use,
    there is a server to try the sample script.
    Please access 131.206.154.81:33 by VNC viewer,
    or http://131.206.154.81/ by web browser.
    Of course, Ruby is not required on user's machine.

    # When by a web browser, a dialog to require password is shown.
    # Please ignore it and press the "OK" button with empty password.

    Any comments (or wish to participate in the development ;-))
    are welcome.

    Hidetoshi NAGAI ()

    ---------------------------------------------------------------
    The following is the sample script.
    ===============================================================
    #!/usr/bin/env ruby
    #
    # Ruby/Tk+VNC :: concept example
    #
    # by Hidetoshi NAGAI ()
    #
    require 'multi-tk'
    require 'singleton'

    class VNC_Wall < TkCanvas
    include Singleton

    def initialize
    @new_relx = 0.4
    @new_rely = 0.4

    super:)width=>TkWinfo.screenwidth('.'),
    :height=>TkWinfo.screenheight('.'))
    self.pack
    end

    ######################################

    class Window_Frame < TkcWindow
    def _title_bind
    @titlebar.bind('ButtonPress-1',
    proc{|rx, ry|
    @rx = rx; @ry = ry; @sx, @sy = self.coords
    @base.raise
    }, '%X', '%Y')

    @titlebar.bind('B1-Motion',
    proc{|rx, ry|
    wx = @wall.winfo_rootx; wy = @wall.winfo_rooty
    if rx > wx && rx < wx + @wall.width &&
    ry > wy && ry < wy + @wall.height
    self.coords = [@sx + (rx - @rx), @sy + (ry - @ry)]
    end
    }, '%X', '%Y')
    end
    private :_title_bind

    def initialize(wall, title, coords, keys={})
    @wall = wall
    @base = TkFrame.new(@wall, :borderwidth=>3, :relief=>:ridge)
    @titlebar = TkLabel.new(@base, :text=>" #{title} ", :relief=>:raised,
    :foreground=>'white',
    :background=>'midnight blue').pack:)fill=>:x)
    @container = TkFrame.new(@base, :container=>true).pack:)fill=>:both,
    :expand=>true)
    super(@wall, coords[0], coords[1], keys)
    self.window = @base
    _title_bind
    end

    def winid
    @container.winfo_id
    end

    def title(txt)
    @titlebar.text(txt)
    end
    end

    ######################################

    def new_window(title, coords, keys={})
    keys = _symbolkey2str(keys)
    keys['anchor'] = 'nw'
    Window_Frame.new(self, title, coords, keys)
    end

    def new_root(keys={})
    keys = _symbolkey2str(keys)
    coords = keys.delete('coords') ||
    [self.width * @new_relx, self.height * @new_rely]
    title = keys.delete('title') || 'root'
    new_window(title, coords, keys)
    end
    private :new_root

    ######################################

    class TOPLEVEL_ARG < Exception
    alias value message
    end

    ######################################

    def new_toplevel(slave_ip, top,
    coords=[self.width * @new_relx, self.height * @new_rely])
    w = new_window("toplevel(#{top})", coords)
    MultiTkIp.invoke_hidden(slave_ip, 'toplevel', top, '-use', w.winid)
    end

    def replace_toplevel_cmd(slave_ip)
    th = Thread.new(slave_ip){|ip|
    begin
    Thread.stop
    rescue TOPLEVEL_ARG => arg
    begin
    new_toplevel(ip, arg.value)
    rescue Exception => e
    end
    retry
    end
    }

    cmd = TkComm._get_eval_string(proc{|t|
    th.raise(TOPLEVEL_ARG.new(t))
    until slave_ip.eval_proc{TkWinfo.exist?(t)}
    Thread.pass
    Tk.update
    end
    })
    slave_ip._eval("proc toplevel {path} {#{cmd} $path}")
    end

    ######################################

    def new_slave(safe=nil, keys={}, &b)
    if safe.kind_of?(Hash)
    keys = _symbolkey2str(safe)
    safe = keys.delete('safe')
    end
    w = new_root(keys)
    ip = MultiTkIp.new_trusted_slave(safe, {:use=>w.winid}, &b)
    MultiTkIp.hide_cmd(ip, 'toplevel')
    replace_toplevel_cmd(ip)
    ip
    end
    alias new_trusted_slave new_slave

    def new_safe_slave(safe=4, keys={}, &b)
    if safe.kind_of?(Hash)
    keys = _symbolkey2str(safe)
    safe = keys.delete('safe') || 4
    end
    w = new_root(keys)
    ip = MultiTkIp.new_safe_slave(safe, {:use=>w.winid}, &b)
    replace_toplevel_cmd(ip)
    ip
    end
    alias new_safeTk new_safe_slave
    end

    #===============================================================

    if $0 == __FILE__
    timeout = 60

    wall = VNC_Wall.instance
    wall[:background] = 'skyblue'

    #-----------------------------------------------------------

    TkcText.new(wall, 150, 50, :fill=>'navyblue', :font=>'courier -14',
    :text=>"Ruby/Tk+VNC :: concept example")
    TkcText.new(wall, 370, 170, :text=><<EOT)
    The root window of the safeTk IP is
    embedded in Master IP's frame widget.

    You can move the root window by
    'Button-1 + Motion' on the titlebar.
    Master IP works like as a window manager.

    No window manager on the VNC server.
    Running one Ruby/Tk process only.
    EOT
    #'
    TkcText.new(wall, 150, 300,
    :text=>"This example will exit in #{timeout} seconds.")
    TkcText.new(wall, 350, 350,
    :text=>"This is Master IP's canvas widget.\n\t($SAFE==#{$SAFE})")

    #-----------------------------------------------------------

    # ip = wall.new_trusted_slave:)title=>'slave root', :coords=>[50, 70]){
    # ip = wall.new_safeTk(3, :title=>'slave root', :coords=>[50, 70]){
    ip = wall.new_safeTk:)title=>'slave root', :coords=>[50, 70]){
    TkLabel.new:)text=>"safeTk interpreter's root").pack:)padx=>10, :pady=>5)

    top = nil
    cnt = 0

    b1 = TkButton.new:)text=>'create Toplevel')

    b2 = TkButton.new:)text=>'add label to the toplevel', :state=>:disabled,
    :command=>proc{
    cnt += 1
    TkLabel.new(top,
    :text=>"Pressed(#{cnt})!! $SAFE=#{$SAFE}"
    ).pack
    })

    b1.command = proc{
    top = TkToplevel.new
    b1[:state] = :disabled
    b2[:state] = :active
    TkLabel.new(top,
    :text=>'New toplevel of slaveIP').pack:)padx=>20, :pady=>30)
    }

    label = TkLabel.new:)foreground=>'red', :text=>"\n")
    timer = TkTimer.new(500, 1, proc{label.text = "\n"})
    TkButton.new:)text=>'BUTTON',
    :command=>proc{
    timer.cancel
    label.text = "button is pressed!!\n($SAFE==#{$SAFE})"
    timer.start
    }).pack:)padx=>5, :pady=>5, :fill=>:x)
    label.pack

    Tk.pack(b1, b2, :fill=>:x, :padx=>5, :pady=>5)
    }

    #-----------------------------------------------------------

    Tk.after(timeout * 1000){exit}
    Tk.mainloop
    end
     
    Hidetoshi NAGAI, Jun 10, 2005
    #1
    1. Advertising

  2. On 6/9/05, Hidetoshi NAGAI <> wrote:
    > Hi,
    >=20
    > I'm working on a framework of Ruby/Tk + VNC.
    > Its purpose is to put GUI applications of Ruby/Tk on internet view.
    > The concept of the framework is,
    >=20
    > * Use VNC (RFB protocol)
    >=20
    > * A GUI application is running on a safe (safe-Tk) based
    > slave interpreter (usually, $SAFE =3D=3D 4).
    > If required, you can also use a non-safe based slave.
    >=20
    > * Never use general window managers to decrease security risk.
    > Except a VNC server, only one Ruby/Tk process is running.
    > # In the future, it may be expected that Ruby/Tk has
    > # RFB server functions and no VNC server is required
    > # for this purpose.
    >=20
    > * A canvas widget of the master interpreter works like
    > as a window manager. The canvas widget administers the
    > slave interpreter's root/toplevel widgets by window items
    > embedded them.
    >=20
    > By comparison with using tclplugin, probably, the followings
    > are advantages.
    >=20
    > * If the user already has a kind of VNC viewer,
    > he can use it to access the application.
    >=20
    > * When the user access the application by a web browser,
    > the application server can send a JAVA viewer applet.
    > Therefore, the user doesn't need to install any plugins.
    >=20
    > * Even if the application uses some Tcl/Tk extensions,
    > the user doesn't need to install such extensions.
    >=20
    > * No need to send the source of the application.
    > Funcamentally, interchanged data are only window events
    > and display images on RFB protocol.
    > So, it can decrease the cost of care for security.
    >=20
    > Disadvantages are,
    >=20
    > * Slow, because it is remote access through networks.
    >=20
    > * Much resources are required on the server.
    >=20
    > A sample script based on this concept is attached
    > at the end of this mail.
    > That requires 2005/06/08 or later version of Ruby.
    > Please note that, because of using multi-tk library,
    > the description of script on the slave interpreter is
    > almost same as the description of usual Ruby/Tk script.
    >=20
    > Although it is an old and slow machine and is not
    > decided how long term it is available to use,
    > there is a server to try the sample script.
    > Please access 131.206.154.81:33 by VNC viewer,
    > or http://131.206.154.81/ by web browser.
    > Of course, Ruby is not required on user's machine.
    >=20
    > # When by a web browser, a dialog to require password is shown.
    > # Please ignore it and press the "OK" button with empty password.
    >=20
    > Any comments (or wish to participate in the development ;-))
    > are welcome.
    >=20
    > Hidetoshi NAGAI ()
    >=20

    =20

    Neat! Once upon a time I read up on the RFB protocol, I don't believe
    it would be too difficult to make a Tk/RFB server assuming Tk's
    drawing and input layers are abstracted (which I am sure they are
    since it is so portable).
     
    Logan Capaldo, Jun 10, 2005
    #2
    1. Advertising

  3. Hidetoshi NAGAI

    gregarican Guest

    Re: framework of Ruby/Tk + VNC

    Hidetoshi NAGAI wrote:

    >* Never use general window managers to decrease security risk.
    > Except a VNC server, only one Ruby/Tk process is running.
    > # In the future, it may be expected that Ruby/Tk has
    > # RFB server functions and no VNC server is required
    > # for this purpose.


    This is a very interesting project. One question. The server isn't
    running a window manager and the Ruby/Tk process is acting as the
    window manager through the TkCanvas object, correct? What I don't
    understand is how a VNC client automatically connects to this TkCanvas
    object that's acting as the VNC server's window manager. Is there some
    static mapping or correlation that has to be made manually on the
    server? How does the VNC server bind itself to the Ruby/Tk process?
     
    gregarican, Jun 10, 2005
    #3
  4. From: Logan Capaldo <>
    Subject: Re: [RFC] framework of Ruby/Tk + VNC
    Date: Fri, 10 Jun 2005 20:35:56 +0900
    Message-ID: <>
    > Neat! Once upon a time I read up on the RFB protocol, I don't believe
    > it would be too difficult to make a Tk/RFB server assuming Tk's
    > drawing and input layers are abstracted (which I am sure they are
    > since it is so portable).


    I think so too. :)
    But, unfortunately, I couldn't find such Tk/RFB server.
    --
    Hidetoshi NAGAI ()
     
    Hidetoshi NAGAI, Jun 10, 2005
    #4
  5. Re: framework of Ruby/Tk + VNC

    From: "gregarican" <>
    Subject: Re: framework of Ruby/Tk + VNC
    Date: Fri, 10 Jun 2005 22:55:28 +0900
    Message-ID: <>
    > This is a very interesting project.


    Thank you. :)

    > One question. The server isn't
    > running a window manager and the Ruby/Tk process is acting as the
    > window manager through the TkCanvas object, correct?


    The TkCanvas object is not a real window manager.
    So, at present, I don't expect running other window applications
    at same time.
    However, I want to make the TkCanvas object a window manager for
    the slave interpreter.

    > What I don't
    > understand is how a VNC client automatically connects to this TkCanvas
    > object that's acting as the VNC server's window manager. Is there some
    > static mapping or correlation that has to be made manually on the
    > server? How does the VNC server bind itself to the Ruby/Tk process?


    In this case, I use the following way.

    * Xvnc is started from inetd and connected to X Display Manager
    (Xvnc -inet -query localhost ...).

    * X Display Manager starts up a greeter on the X (Xvnc) server.
    But the greeter is replaced to a Ruby/Tk application launcher.

    * The application launcher do setup steps (if needed),
    and executes Ruby/Tk.
    So, the Ruby/Tk process is placed on a window manager proces.

    * When the Ruby/Tk process is finished,
    Xvnc treats it as the end of Xsession, and shuts down the socket.

    --
    Hidetoshi NAGAI ()
     
    Hidetoshi NAGAI, Jun 10, 2005
    #5
  6. Hidetoshi NAGAI

    gregarican Guest

    Re: framework of Ruby/Tk + VNC

    Hidetoshi NAGAI wrote:

    > In this case, I use the following way.
    >
    > * Xvnc is started from inetd and connected to X Display Manager
    > (Xvnc -inet -query localhost ...).
    >
    >
    > * X Display Manager starts up a greeter on the X (Xvnc) server.
    > But the greeter is replaced to a Ruby/Tk application launcher.
    >
    >
    > * The application launcher do setup steps (if needed),
    > and executes Ruby/Tk.
    > So, the Ruby/Tk process is placed on a window manager proces.
    >
    >
    > * When the Ruby/Tk process is finished,
    > Xvnc treats it as the end of Xsession, and shuts down the socket.
    >
    >
    >--
    >


    Oh I see now. In the past I have used VNC on everything from Sharp
    Zaurus PDA's to Linux boxes to my Windows boxes. But I hadn't looked
    "under the hood" to see how it connected for sessions. In terms of the
    Ruby/Tk framwork for it I was thinking in terms of my Windows
    environment. And I wasn't sure of a way to redirect a VNC session from
    the default window manager (i.e. - Windows itself). But this makes
    sense how you can redirect things through the Xvnc/XDM session for the
    non-Windows world. There's a lot more flexibility there.

    Great work. I must say I am constantly impressed with the Ruby
    community. It is friendly, knowledgeable, and has a very mature
    application/binding collection. This is just another example.
     
    gregarican, Jun 10, 2005
    #6
  7. Re: framework of Ruby/Tk + VNC

    From: "gregarican" <>
    Subject: Re: framework of Ruby/Tk + VNC
    Date: Sat, 11 Jun 2005 03:10:29 +0900
    Message-ID: <>
    > Oh I see now. In the past I have used VNC on everything from Sharp
    > Zaurus PDA's to Linux boxes to my Windows boxes. But I hadn't looked
    > "under the hood" to see how it connected for sessions. In terms of the
    > Ruby/Tk framwork for it I was thinking in terms of my Windows
    > environment. And I wasn't sure of a way to redirect a VNC session from
    > the default window manager (i.e. - Windows itself).


    Although I don't know details of Windows version of VNC server,
    I heard that a (some?) kind of VNC server on Windows supports
    to treat only one window under a VNC session.
    If that is true, by supplying the master-IP's root window of
    the framework on such VNC server, you'll be able to make a
    multi-window application which allows restricted access to
    your Windows boxes.
    --
    Hidetoshi NAGAI ()
     
    Hidetoshi NAGAI, Jun 12, 2005
    #7
  8. On Fri, Jun 10, 2005 at 12:43:28PM +0900, Hidetoshi NAGAI wrote:
    > Hi,

    Hello
    >
    > I'm working on a framework of Ruby/Tk + VNC.
    > Its purpose is to put GUI applications of Ruby/Tk on internet view.
    > The concept of the framework is,
    >
    > * Use VNC (RFB protocol)
    >
    > * A GUI application is running on a safe (safe-Tk) based
    > slave interpreter (usually, $SAFE == 4).
    > If required, you can also use a non-safe based slave.
    >
    > * Never use general window managers to decrease security risk.
    > Except a VNC server, only one Ruby/Tk process is running.
    > # In the future, it may be expected that Ruby/Tk has
    > # RFB server functions and no VNC server is required
    > # for this purpose.

    Isn't there already some rfb support for tk? I beleive I found it while
    seaching for widget toolkits for vnc a fwe weeks ago. Given that the
    only one I found was tk I decided I will use web instead.

    Thanks

    Michal Suchanek
     
    Michal 'hramrach' Suchanek, Jun 12, 2005
    #8
  9. Hidetoshi NAGAI

    gregarican Guest

    Re: framework of Ruby/Tk + VNC

    You are correct. There are options under the various Windows VNC
    flavors that allows you to specify which window to share for a VNC
    session, as opposed to sharing the entire Windows desktop as a whole.
    So I suppose this could be very possible on the Win32 platform as well.
     
    gregarican, Jun 12, 2005
    #9
  10. From: Michal 'hramrach' Suchanek <>
    Subject: Re: [RFC] framework of Ruby/Tk + VNC
    Date: Mon, 13 Jun 2005 00:17:22 +0900
    Message-ID: <>
    > Isn't there already some rfb support for tk? I beleive I found it while
    > seaching for widget toolkits for vnc a fwe weeks ago.


    I couldn't find such library.
    Although I could find tclRFB library, it doesn't seem to treat
    Tk widgets directly.
    If you know a download site of such RFB for Tk widgets,
    please tell me the URL.
    I'll create Ruby/Tk's wrapper library for the library.
    --
    Hidetoshi NAGAI ()
     
    Hidetoshi NAGAI, Jun 13, 2005
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TWlrZQ==?=

    VNC using ASP.NEt

    =?Utf-8?B?TWlrZQ==?=, Feb 19, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,211
    Nick Gilbert
    Feb 19, 2004
  2. Alberto Vera

    OT: software like VNC

    Alberto Vera, May 5, 2004, in forum: Python
    Replies:
    2
    Views:
    321
    Richie Hindle
    May 5, 2004
  3. scott

    Logging VNC Hits

    scott, Oct 5, 2004, in forum: Python
    Replies:
    1
    Views:
    343
    Peter L Hansen
    Oct 6, 2004
  4. Ivan Shmakov
    Replies:
    3
    Views:
    1,156
    Kari Hurtta
    Feb 13, 2012
  5. Hidetoshi NAGAI

    [RFC] framework of Ruby/Tk + VNC

    Hidetoshi NAGAI, Oct 7, 2005, in forum: Ruby
    Replies:
    0
    Views:
    168
    Hidetoshi NAGAI
    Oct 7, 2005
Loading...

Share This Page