473,466 Members | 1,613 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 3310
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.