0

I want people to access switch, servers on my site thank to putty. Users will see the list of all the devices. When they will click on one of them, I want putty to open with the good protocol (ssh or telnet) and the good address. If they click on another name this will open putty on another address.

Ex.: putty.exe -ssh 192.168.0.1

My idea was to start cmd and to execute this command in it.

I first tried PHP (system(), exec(), shell_exec()) but didn't work. I'm now looking for solution with JavaScript. Already tried exec() and execute() but doesn't worked for me.

So far the only solution I found was making script.bat and put the command in it But this is not what I'm looking for!. Moreover It only works with IE and I need a lot of script because there is a lot of devices.

Edit:

My wish is to make it functionnal on IE AND Mozilla.

  1. I tried a direct link with but in Mozilla it asks if you want to download the file and not execute it.
  2. Using a JScript that use WshShell.Run and save the page as .hta makes it work but it literally takes 1 minute to open Putty.
  3. Using a link to the JScript doesn't work, it asks me if I want to download it and not execute it.

The server can be Windows or Linux, but the users will use Windows to access the site. I only want to use JScript / PHP on this site. In addition I don't want user need to change their putty, I wish this could be accessible to every user that got putty installed (and added to PATH).

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Herolex
  • 1
  • 1
  • 3
  • 3
    Possible duplicate of [Launch application from a browser](http://stackoverflow.com/questions/3057576/launch-application-from-a-browser) – Martin Prikryl Jan 04 '17 at 09:03
  • Unless you have some control over a configuration of the local machine. But you have to tell us. – Martin Prikryl Jan 04 '17 at 09:04
  • If you are trying to set up a SSH connection you might want to look at the [phpseclib library](https://packagist.org/packages/phpseclib/phpseclib). – Luceos Jan 04 '17 at 09:31
  • Sadly, I'm supposed to use putty ... moreover for the moment we can't connect to all devices with ssh, I also need telnet. – Herolex Jan 04 '17 at 09:34
  • If you have access to the windows machines, you can look into something like this: https://gist.github.com/sbiffi/11256316 Something like this would allow putty to launch on the windows box using a telnet://hostname or ssh://hostname link in the browser. I believe that telnet:// will work out of the box if putty is installed. – Jeff Block Jan 04 '17 at 09:36
  • @JeffBlock Thx for the answer, I already have functionnal script (batch) that can run the different command. But I would prefer not using external script and make everything inside the site code. – Herolex Jan 04 '17 at 09:42
  • So what do you want? Execute SSH command on some SSH server or run PuTTY? These are two distinct tasks. With distinct solutions. Or do you need both? To allow the user to interact with a local SSH client (PuTTY) running some command? What you ask for looks generally as a bad approach. So you might want to give us some explanation, why you are taking this approach. – Martin Prikryl Jan 04 '17 at 10:03
  • Have you seen this post on superuser ? http://superuser.com/questions/204066/make-ssh-links-open-with-putty – Mouradif Jan 04 '17 at 10:05
  • It seems @ubomb did it works on this post [link](http://stackoverflow.com/questions/29523066/how-do-i-get-internet-explorer-to-handle-custom-protocol-handlers-correctly/29548740#29548740), but I don't understand how registry keys works and how to use :/ – Herolex Jan 04 '17 at 10:28

2 Answers2

1

While Martin is correct that this is a duplicate of Launch Application From Browser, the answers there are not very good.

HTML defines a telnet scheme - so you can launch a telnet session by adding (for example)

<a href="telnet://server.example.com">Run insecure telnet session</a>

However this has never been officially revised to allow for ssh support (some browsers support customer schemes).

Nearly every browser allows you to configure a default action when it downloads a data file of a specific mimetype - and the mime type is usually extendable. But unlike the RDP file in the linked question, PuTTY does not support providing connection data via a file, only on the command line. It would be possible to write a fairly simple client which read the data from a downloaded file and then invoked putty, populating the command line with the target host - but that would also require the client to be deployed on all target devices.

The other option would be to use a ssh client running in the browser rather than natively on the client. There are also several Java apps in aditiona to the resources listed in the previous link.

Community
  • 1
  • 1
symcbean
  • 47,736
  • 6
  • 59
  • 94
  • 1
    +1 - Actually, you are right that I've chosen a bad duplicate, this one is much more accurate: [HTML code to open PuTTY client from browser](http://stackoverflow.com/q/17670067/850848). – Martin Prikryl Jan 04 '17 at 10:42
  • Well this would be a duplicate if I wish to use batch script... I did change a line so you can understand that I'm not looking for batch script that will start putty. I wanna use PHP or JavaScript to do this job ! – Herolex Jan 04 '17 at 10:52
  • @Herolex The problem is that you still do not understand that 1) You cannot execute a local application using an PHP script running on a remote server. That's technically not possible. 2) You cannot execute a local application using JavaScript. While this would be technically possible, as JavaScript runs locally, it would be a security nightmare. So it's not allowed. – Martin Prikryl Jan 04 '17 at 12:46
  • Actually, it can be done securely with Javascript - as per the link I provided, there is at least 1 javascript implementation of ssh. But running within the default sandbox, it will only connect to the host it was served from. To escape the sandbox you need to use signed javascript files - but signed javascript sandbox escapes are very much an edge case and browser support is likely to be limited (AFAIK Microsoft have never supported signed Javascript). i.e. its possible in theory, but a bad idea in practice. – symcbean Jan 04 '17 at 12:57
0

Now that I know it's impossible with PHP and really hard with JavaScript (didn't worked for me) there is only 2 solutions left :

  1. Using batch file that start putty with the good parameters but this works only on IE. This is what the script should contain : start "" "C:\path_to_putty\putty.exe" -ssh address"
  2. Using "FireSSH" add-on on mozilla and chrome to connect in ssh to my devices.

I've choosed the second one. Thanks everyone for helping ! :)

Herolex
  • 1
  • 1
  • 3