473,246 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

ssh2 & php & graphical apps

I'm trying to use the ssh2 functions to run a graphical app. I have no
problem opening ssh2_shell and running something like "/bin/ls /tmp".
However when I try to do something like:
fwrite($stdio,"/usr/X11R6/bin/xclock -display some-other-machine:0\n");

It doesn't work. I've tried wrapping the xclock command in a shell
script and a C program and still no luck. In both instances I can ssh
into the remote machine and run the commands just fine. Is this
something that just doesn't work? Or does someone have a tip for how
to get that to display back? Should I be looking at ssh2_exec?

-Brian Vincent

Full code below using some sample PHP code:
<?php
echo "Connexion SSH ";
if (!($resource=@ssh2_connect("10.72.xx.xx"))) {
echo "[FAILED]<br />";
exit(1);
}
echo "[OK]<br />";

// Authentification by login/passwd
echo "Authentification ";
if (!@ssh2_auth_password($resource,"myusername","mypa ssword")) {
echo "[FAILED]<br />";
exit(1);
}
echo "[OK]<br />";

// We need a shell
echo "Shell stdio ";
if (!($stdio = @ssh2_shell($resource,"xterm"))) {
echo "[FAILED]<br />";
exit(1);
}
echo "[OK]<br />";

// Execution of any command
// Be careful to add an '\n' at the end of the command
$command = "/usr/X11R6/bin/xclock -display
some-other-machine:0\n";
fwrite($stdio,$command);

// IMPORTANT
// For some obscur reasons, just after ur command, u need to
make a sleep to be sure, that the command has reached the server and is
running
sleep(1);

// Then u can fetch the stream to see what happens on stdio
while($line = fgets($stdio)) {
flush();
echo $line."<br />";
}
// It's always cleaner to close all stream
fclose($stdio);
?>

Jul 17 '05 #1
7 3298
br***********@gmail.com wrote:
I'm trying to use the ssh2 functions to run a graphical app. I have no
problem opening ssh2_shell and running something like "/bin/ls /tmp".
However when I try to do something like:
fwrite($stdio,"/usr/X11R6/bin/xclock -display some-other-machine:0\n");

It doesn't work.


How are you running your script?

Jul 17 '05 #2
I'm not sure I know what you mean. I'm embedding that PHP script in
index.php and then opening the page in a remote web browser on
some-other-machine. I've actually heard rumors that this will work,
but I can't seem to figure it out.

-Brian

Jul 17 '05 #3
br***********@gmail.com wrote:
I'm not sure I know what you mean. I'm embedding that PHP script in
index.php and then opening the page in a remote web browser on
some-other-machine. I've actually heard rumors that this will work,
but I can't seem to figure it out.


The question should have been:
Who/what is executing the script?

My guess is that you don't know how X11 authenticates and authorizes the
usage of the display (==server) by an application (==client).

If you run the script by accessing an URL on a httpd, the httpd must
have access to the server that will display a client. So where is the
display and where is the httpd running?

Jul 17 '05 #4
> The question should have been:
Who/what is executing the script? My guess is that you don't know how X11 authenticates and authorizes the
usage of the display (==server) by an application (==client).


Ah. I see.

This is part of the reason I'm using ssh.

So the process should be:

1. me (on machine #1) hits the web server
2. the PHP script (on machine #2) initiates an ssh connection using
ssh2_shell either to itself or to machine #3 (I don't think it matters)

3. the ssh shell authenticates as a specific user and attempts to run
a graphical app back to machine #1.

Now, on machine #1 I've just done an "xhost +" to completely disable
authentication checking (for testing only).

I know X is fine since I can ssh from machine #1 and run the same
command line manually on machine #2 to fire up xclock. I suspected
maybe something wasn't being set up correctly in the environment, but
comparing the 'env' output from a normal ssh session and one initiated
by ssh2_shell() doesn't show many differences. No problems running
/usr/bin/env through ssh2_shell and capturing the output of the stream,
so I know non-graphical apps work.

Now, maybe if I tell you the Big Picture idea you can think of another
way to do it. I'm basically trying to create an application server. A
user will need to authenticate and once they do so it will
automatically fire up a graphical app residing on the remote server and
display it back on the client. The apps need to utilize custom
settings based on the user, so using something like ssh2_shell to
execute it seems to a logical way to do it.

Thanks for thinking about this so far. I'm somewhat stumped.

-Brian

Jul 17 '05 #5
br***********@gmail.com wrote:
Now, maybe if I tell you the Big Picture idea you can think of another
way to do it. I'm basically trying to create an application server. A
user will need to authenticate and once they do so it will
automatically fire up a graphical app residing on the remote server and
display it back on the client. The apps need to utilize custom
settings based on the user, so using something like ssh2_shell to
execute it seems to a logical way to do it.

Thanks for thinking about this so far. I'm somewhat stumped.


Me too, after an "xhost +" (which is offcourse BAD (ssh-ing into an
account that has any valid X display should be enough for your
solution)) any input should be allowed.

The only small difference I can think of might be that if you run the
commands yourself you are actually getting the results by tunneling the
X protocol so the effect will be that remote xclients effectively
connect to "localhost". Your httpd doesn't have a valid display so any
ssh session started from it will lack the X forwarding, if you try to
display to a remote machine it should talk to it thru the usual TCP
networking protocol. In many cases the Xserver will be started by
[xkg]dm, some installations (eg Debian) will disable tcp support in the
Xserver so that remote hosts can't connect with a simple
"-display remote:0.0". Scan for '-nolisten tcp' to see if this might be
the cause.

If this isn't it, I can't think of anything else :)

Jul 17 '05 #6
> "-display remote:0.0". Scan for '-nolisten tcp' to see if this might be
the cause.


Already removed. Previous to that I couldn't run the X app over a
normal ssh connection and afterwards I could.

-Brian

Jul 17 '05 #7
Alright.. well, in case someone else ever runs into this I should post
something that works. I still have a lot to figure out. For example,
I can get xterm to run but not xclock. I also used ssh2_exec() rather
than ssh2_shell(). That's fine for me though, ssh2_exec() will work.
Anyway, I still have a long way to go to turning this into production
quality, but the basic concept seems to be there. Also, I'm running
all this locally right now. The web server, the ssh calls, and the
display are all on one box. Eventually I think I need to move it onto
three boxes. Anyway, this works (assuming you have a bunch other
little things configured correctly and xhost + set, which is a bad
idea.)

By the way, with the case of xclock failing, I could at least get the
process running on my box with ssh2_exec. I have no idea why it
wouldn't display, but it sat there in the process list.

It is somewhat neat to reload a web page and watch xterm pop up.

<?php
echo "Connexion SSH ";
if (!($resource=@ssh2_connect("10.72.64.xx"))) {
echo "[FAILED]<br />";
exit(1);
}
echo "[OK]<br />";

// Authentication by login/passwd
echo "Authentication ";
if (!@ssh2_auth_password($resource,"myusername","mypa ssword")) {
echo "[FAILED]<br />";
exit(1);
}
echo "[OK]<br />";

// Exec a program
echo "Shell exec ";
if (!($stdio = @ssh2_exec($resource,'/usr/X11R6/bin/xterm
-display 10.72.64.xx:0'))) {
echo "[FAILED]<br />";
exit(1);
}
echo "[OK]<br />";

// It's always cleaner to close all stream
fclose($stdio);
?>

-Brian

Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: gonchi | last post by:
Hi, Something very strangne happens with the function ssh2_exec, i can't read the stream answer after execution in the remote computer. I work with apache 1.3.30 and php 4.3.10 , libssh 2.0.5 ....
2
by: Venkat B | last post by:
Hi all, I have a question re the use of Python to control a robot built with the LEGO Mindstorm system. This is to help my 11yr old with his increased interest in 'programming' and...
9
by: Bryan Olson | last post by:
Here's a module to show stderr output from console-less Python apps, and stay out of the way otherwise. I plan to make a ASPN recipe of it, but I thought I'd run it by this group first. To use...
1
by: Lane Beneke | last post by:
All, New to the list and a relative newbie to PostgreSQL. Please forgive stupid questions. Designing an application server for a work order processing (et al) database. I have a good handle...
0
by: Bernhard Günther | last post by:
Hello friends of php, PhP-Version is 4 on a FreeBSD-System using apache. Got a problem using ssh2.sftp. Installed correctly (libssh2, ssh2.so-module). Connecting with publickey works,...
4
by: Adam Knight | last post by:
Hi all, I am using a dreamweaver template for a web app i am working on. Each time i update the template my page directives at the top of the associated pages gets removed. Anyone had...
0
by: FishGills | last post by:
For the life of me I can not figure out why I am getting this error: Error starting up SSH connection(-5): Unable to exchange encryption keys $connect = ssh2_connect('d50-1.s50', 22); ...
0
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that...
8
by: r0g | last post by:
Hi There, I'm trying to migrate a locally hosted page from windows to a private Ubuntu development server and one of the key bits of functionality (which used to work fine in Windows) was the...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.