Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the SSH link for customer easier to save it in browser bookmark. #368

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
## 我的修改
增加生成SSH Link功能,方便收藏,下次使用不需要输入密码。
![image](https://github.com/crazypeace/huashengdun-webssh/assets/665889/123a33bd-9514-46a5-8e64-d7a82b7f6f19)

SSH Link 可以带一个命令参数. 登录完成后就执行命令.
[![](https://res.cloudinary.com/marcomontalbano/image/upload/v1726912439/video_to_markdown/images/youtube--hCoAy06NA4k-c05b58ac6eb4c4700831b2b3070cd403.jpg)](https://www.youtube.com/watch?v=hCoAy06NA4k "")

部署到容器的教程:

https://zelikk.blogspot.com/2023/10/huashengdun-webssh-codesandbox.html

补充 部署到Hugging Face的教程 / 作者 Xiang xjfkkk

https://linux.do/t/topic/135264

<details>
<summary>原项目readme (点击展开)</summary>

## WebSSH

[![python](https://github.com/huashengdun/webssh/actions/workflows/python.yml/badge.svg)](https://github.com/huashengdun/webssh/actions/workflows/python.yml)
Expand Down Expand Up @@ -210,3 +228,5 @@ wssh --port=8080 --sslport=4433 --certfile='cert.crt' --keyfile='cert.key' --xhe
* For whatever deployment choice you choose, don't forget to enable SSL.
* By default plain http requests from a public network will be either redirected or blocked and being redirected takes precedence over being blocked.
* Try to use reject policy as the missing host key policy along with your verified known_hosts, this will prevent man-in-the-middle attacks. The idea is that it checks the system host keys file("~/.ssh/known_hosts") and the application host keys file("./known_hosts") in order, if the ssh server's hostname is not found or the key is not matched, the connection will be aborted.

</details>
70 changes: 70 additions & 0 deletions user.js/Build-SSH-Link.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// ==UserScript==
// @name Build SSH Link
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Build SSH link for huashengdun-webssh
// @author ǝɔ∀ǝdʎz∀ɹɔ 👽
// @match https://ssh.vps.vc/*
// @match https://ssh.hax.co.id/*
// @match https://ssh-crazypeace.koyeb.app/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=koyeb.app
// @grant none
// ==/UserScript==


(function() {
'use strict';

// Your code here...
// 获取 form 元素
var form = document.getElementById("connect");

/////////////////////
// 创建 `<button>` 元素
var buildLinkBtn = document.createElement("button");

// 设置 `<button>` 的属性
buildLinkBtn.type="button";
buildLinkBtn.className="btn btn-info";
buildLinkBtn.innerHTML="buildSSHLink";
buildLinkBtn.id="sshlinkBtnA";

// 将 `<button>` 添加到 `<form>` 元素范围内部的尾部
form.appendChild(buildLinkBtn);

////////////////////
// 创建 `<div>` 元素
var sshlinkdiv = document.createElement("div");

// 设置 `<div>` 的属性
sshlinkdiv.id = "sshlinkA";

// 将 `<div>` 添加到 `<form>` 元素范围内部的尾部
form.appendChild(sshlinkdiv);

////////////////////
// 让按钮的click事件 调用 updateSSHlinkA 函数
document.querySelector('#sshlinkBtnA').addEventListener("click", updateSSHlinkA);
})();

function updateSSHlinkA() {
var thisPageProtocol = window.location.protocol;
var thisPageUrl = window.location.host;

var hostnamestr = document.getElementById("hostname").value;
var portstr = document.getElementById("port").value;
if (portstr == "") {
portstr = "22"
}
var usrnamestr = document.getElementById("username").value;
if (usrnamestr == "") {
portstr = "root"
}
var passwdstr = document.getElementById("password").value;
var passwdstrAfterBase64 = window.btoa(passwdstr);

var sshlinkstr;
sshlinkstr = thisPageProtocol+"//"+thisPageUrl+"/?hostname="+hostnamestr+"&port="+portstr+"&username="+usrnamestr+"&password="+passwdstrAfterBase64;

document.getElementById("sshlinkA").innerHTML = sshlinkstr;
}
2 changes: 1 addition & 1 deletion webssh/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def print_version(flag):
define('maxconn', type=int, default=20,
help='Maximum live connections (ssh sessions) per client')
define('font', default='', help='custom font filename')
define('encoding', default='',
define('encoding', default='utf-8',
help='''The default character encoding of ssh servers.
Example: --encoding='utf-8' to solve the problem with some switches&routers''')
define('version', type=bool, help='Show version information',
Expand Down
Binary file added webssh/static/css/fonts/Consolas.ttf
Binary file not shown.
26 changes: 26 additions & 0 deletions webssh/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,34 @@ var wssh = {};
data[name] = value;
};
}

document.querySelector('#sshlinkBtn').addEventListener("click", updateSSHlink);
}());

function updateSSHlink() {
var thisPageProtocol = window.location.protocol;
var thisPageUrl = window.location.host;

var hostnamestr = document.getElementById("hostname").value;
var portstr = document.getElementById("port").value;
if (portstr == "") {
portstr = "22"
}
var usrnamestr = document.getElementById("username").value;
if (usrnamestr == "") {
portstr = "root"
}
var passwdstr = document.getElementById("password").value;
var passwdstrAfterBase64 = window.btoa(passwdstr);

var initcmdstr = document.getElementById("initcmd").value;
var initcmdstrAfterURI = encodeURIComponent(initcmdstr);

var sshlinkstr;
sshlinkstr = thisPageProtocol+"//"+thisPageUrl+"/?hostname="+hostnamestr+"&port="+portstr+"&username="+usrnamestr+"&password="+passwdstrAfterBase64+"&command="+initcmdstrAfterURI;

document.getElementById("sshlink").innerHTML = sshlinkstr;
}

jQuery(function($){
var status = $('#status'),
Expand Down
6 changes: 6 additions & 0 deletions webssh/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,18 @@
<input class="form-control" type="password" id="totp" name="totp" value="">
</div>
<div class="col">
<label for="InitCmd">Init Command (execute the command after login)</label>
<input class="form-control" type="text" id="initcmd" name="initcmd" value="">
</div>
</div>
<input type="hidden" id="term" name="term" value="xterm-256color">
{% module xsrf_form_html() %}
<button type="submit" class="btn btn-primary">Connect</button>
<button type="reset" class="btn btn-danger">Reset</button>
<button type="button" class="btn btn-info" id="sshlinkBtn">SSH Link</button>
<div id="sshlink"></div>
<div>Github: <a href="https://github.com/crazypeace/huashengdun-webssh">https://github.com/crazypeace/huashengdun-webssh</a></div>
<div>自建教程: <a href="https://zelikk.blogspot.com/search/label/webssh">https://zelikk.blogspot.com/search/label/webssh</a></div>
</form>
</div>

Expand Down