473,568 Members | 2,905 Online
Bytes | Software Development & Data Engineering Community
+ 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=@s sh2_connect("10 .72.xx.xx"))) {
echo "[FAILED]<br />";
exit(1);
}
echo "[OK]<br />";

// Authentificatio n by login/passwd
echo "Authentificati on ";
if (!@ssh2_auth_pa ssword($resourc e,"myusername", "mypassword ")) {
echo "[FAILED]<br />";
exit(1);
}
echo "[OK]<br />";

// We need a shell
echo "Shell stdio ";
if (!($stdio = @ssh2_shell($re source,"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 3318
br***********@g mail.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***********@g mail.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***********@g mail.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=@s sh2_connect("10 .72.64.xx"))) {
echo "[FAILED]<br />";
exit(1);
}
echo "[OK]<br />";

// Authentication by login/passwd
echo "Authentica tion ";
if (!@ssh2_auth_pa ssword($resourc e,"myusername", "mypassword ")) {
echo "[FAILED]<br />";
exit(1);
}
echo "[OK]<br />";

// Exec a program
echo "Shell exec ";
if (!($stdio = @ssh2_exec($res ource,'/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
1633
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 . the ssh2 module looks to work correctly but sftp functions cause a big delay causing server timeout and ssh2_exec can't read the output. Tryed many...
2
4901
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 'robotics'... If not feasible, he wants to use the graphical-tool that comes with it... Would you suggest: 1. Using LegOS (http://legos.sourceforge.net/) and...
9
2038
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 it, import the module. That's it. Upon import it will assign sys.stderr. In the normal case, your code is perfect so nothing ever gets written to...
1
3470
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 on sequences, referencial integrity, views, & the basics. What books/documentation would you recommend to learn more about...
0
4664
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, sftp subsystem-connect works too:
4
1703
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 problems with this? Know how to fix? Fill me in on what is going on?
0
1468
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); That's the code. One line PHP. I've tried connecting to localhost as well. Still no love.
0
2495
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 don't work nearly as well as they should, even for analysts and power users. The reason they haven't reached the masses is because most of the tools...
8
6599
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 ability for the page to start a file browser via PHP's exec() function. I can't get this working under Ubuntu though e.g. <?php exec('nautilus...
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7917
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7665
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6277
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.