Capturing a display on remote (linux) server from (windows) web browser

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hemanth

    Capturing a display on remote (linux) server from (windows) web browser

    Hello there,

    I've a utility that runs on a linux machine. Basically, it opens
    a window, draws a figure and captures the image (screen) and stores
    it as a jpeg file. The utility requires a window to be open
    (or displayed) inorder to save the image. Also, this utility is
    in the form of an executable, so I can't possibly alter it.

    I want to run this utility from a windows web browser and display
    the saved jpeg file. I pass some command line parameters to change
    the figure it draws. The php code I use is as below:

    <?php

    putenv("VIEWER_ HOME=/path/to/viewer_home");

    //putenv("DISPLAY servername:45") ;

    $prgfile="viewe r -m save.mac";
    exec($prgfile, $output, $rc);
    foreach($output as $row) echo "<br>$row";
    echo "<br>";
    print_r($rc);

    ?>

    I connect to the linux server from my windows desktop using RealVNC
    and the php script works when I run it from the server shell
    prompt (using "php <scriptname>" ). It opens a display, captures the
    image and closes the display. But when I run the script from windows
    web browser I get an error (in the apache "error_log" file).

    "Error: Can't open display"

    Is there a way I can make this work?



    TIA,
    Hemanth

    P.S: I'm not sure if my question is entirely relevant to this group
    but any pointers to the right group will be helpful.

  • Daniel Tryba

    #2
    Re: Capturing a display on remote (linux) server from (windows) web browser

    Hemanth <hemanth.singam setty@gmail.com > wrote:[color=blue]
    > I connect to the linux server from my windows desktop using RealVNC
    > and the php script works when I run it from the server shell
    > prompt (using "php <scriptname>" ). It opens a display, captures the
    > image and closes the display. But when I run the script from windows
    > web browser I get an error (in the apache "error_log" file).
    >
    > "Error: Can't open display"
    >
    > Is there a way I can make this work?[/color]

    You can...
    [color=blue]
    > P.S: I'm not sure if my question is entirely relevant to this group
    > but any pointers to the right group will be helpful.[/color]

    A linux group offcourse, related to X: comp.os.linux.x (or simply misc)
    might be better. If you don;t understand below take it there :)

    The difference is that when you run the script from commandline in vnc,
    it's running as you and it has an readily available display to write to.

    Apache is running under an other user and knows not of any display to
    write to.

    Solution:
    Q&D: give apache access to your vnc session (which from then on will
    need to be running always on a known port), with 'xhost localhost' and
    set the DISPLAY variable in your script to that display:
    putenv('DISPLAY =localhost:45') ;

    This will give _ANY_ user on localhost access to your display, enabling
    them to read every key you type and your entire screen.

    Less Q&D: run an vnc session as the apache user, you can then leave out
    the xhost part.

    BTW what program are you running (just curious)?

    Comment

    • Hemanth

      #3
      Re: Capturing a display on remote (linux) server from (windows) web browser

      Daniel,

      Sorry for a late reply. Could you please elaborate on your first
      solution.
      Normally, I run a startup script to open a vnc session. I tried to do
      the same from the web browser (trying to start a vnc session using
      apache user on port 99). The startup script I used is as follows:

      Xvnc -geometry 800x600 -depth 24 :99 &
      sleep 4
      setenv DISPLAY "$HOST":99
      sleep 4
      /usr/bin/startkde &

      The script works when I run it using myuserid. But I get this error
      message (in apache error_log) when run from webbrowser.

      Fatal server error:
      Cannot establish any listening sockets - Make sure an X server isn't
      already running
      sh: setenv: command not found
      Cannot create temp file //KDE.startkde.3J rTHi
      /usr/bin/startkde: $testfile_home: ambiguous redirect
      _XSERVTransSock etUNIXCreateLis tener: ...SocketCreate Listener() failed
      _XSERVTransMake AllCOTSServerLi steners: server already running


      Could you pls throw some light on it.

      - Hemanth

      Comment

      • Hemanth

        #4
        Re: Capturing a display on remote (linux) server from (windows) web browser

        BTW, the viewer program I'm running is K2 Quickview.

        - Hemanth

        Comment

        Working...