huashengdun / webssh

:seedling: Web based ssh client
https://webssh.huashengdun.org/
MIT License
4.57k stars 1.3k forks source link

能否支持url中传递参数,然后直接连接到终端 #47

Closed yanxiaowuchris closed 5 years ago

yanxiaowuchris commented 5 years ago

我所希望的使用方式: 在我的web页面中,提供一个按钮,点击后,使用下面的方式 window.open("http://wsship:port/api?hostname=xx&port=xx&username=xx&password=xxx") 参数最好使用post,最好使用某种方式加密。

不知能否支持上述需求,谢谢!

huashengdun commented 5 years ago

web页面https是最好的加密方式 ,其它都不怎么安全的。

huashengdun commented 5 years ago

你可以这样使用,不支持跨域, var target_window = window.open('https://webssh.domain.com'); target_window.wssh.connect(ip, port, username, password);

yanxiaowuchris commented 5 years ago

好的,我试试看,非常感谢,刚才下拉最新的代码

huashengdun commented 5 years ago

已支持跨域链接了, 只要服务端有这个origin就行。 服务器启动时传个跨域的域名网址,

wssh --origin='http://www.example.com'

浏览器端代码示例,

var target_window = window.open('https://webssh.domain.com');
target_window.postMessage('hostname|port|username|password', '*');
// target_window.postMessage(JSON.stringify(['hostname', 'port', 'username', 'password']), '*');
huashengdun commented 5 years ago

已经加上了通过url传递参数的功能。 示例请看README。

sky800719 commented 5 years ago

能否支持命令也拼接到url串里面,登录后,直接执行url里面的命令,谢谢。

huashengdun commented 5 years ago

@sky800719 已经加了, 示例如下 http://localhost:8888/?command=ls -l

PhoenixPeca commented 5 years ago

Cross-domain links are supported, as long as the server has this origin. A cross-domain domain name URL is sent when the server starts.

wssh --origin='http://www.example.com'

Browser-side code example,

var target_window = window.open('https://webssh.domain.com');
target_window.postMessage('hostname|port|username|password', '*');
// target_window.postMessage(JSON.stringify(['hostname', 'port', 'username', 'password']), '*');

Hi I have tried this.. It doesnt seem to work.. :(

PhoenixPeca commented 5 years ago

How can I pass the parameters from another page to webssh by using only pure javascript without exposing the credentials to the URL? :(

PhoenixPeca commented 5 years ago

I tried to call the webssh api directly from another page to get the SSH websocket id as in:

{status: null, id: "139931239474768", encoding: "UTF-8"}

But I don't know how to pass it back to webssh to open an ssh window by just using the ID..

:(

PhoenixPeca commented 5 years ago

@huashengdun can you help me with this please?

huashengdun commented 5 years ago

Cross-domain links are supported, as long as the server has this origin. A cross-domain domain name URL is sent when the server starts.

wssh --origin='http://www.example.com'

Browser-side code example,

var target_window = window.open('https://webssh.domain.com');
target_window.postMessage('hostname|port|username|password', '*');
// target_window.postMessage(JSON.stringify(['hostname', 'port', 'username', 'password']), '*');

Hi I have tried this.. It doesnt seem to work.. :(

You need to wait for the webssh page fully loaded, then execute window.postMessage.