py-web-ssh 0.1.2__tar.gz → 0.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {py_web_ssh-0.1.2 → py_web_ssh-0.1.3}/PKG-INFO +3 -1
- {py_web_ssh-0.1.2 → py_web_ssh-0.1.3}/README.md +3 -1
- {py_web_ssh-0.1.2 → py_web_ssh-0.1.3}/pyproject.toml +1 -1
- {py_web_ssh-0.1.2 → py_web_ssh-0.1.3}/webssh/__init__.py +1 -1
- {py_web_ssh-0.1.2 → py_web_ssh-0.1.3}/webssh/app.py +13 -3
- py_web_ssh-0.1.3/webssh/client_session.py +64 -0
- {py_web_ssh-0.1.2 → py_web_ssh-0.1.3}/webssh/static/app.js +38 -0
- {py_web_ssh-0.1.2 → py_web_ssh-0.1.3}/webssh/static/index.html +49 -26
- {py_web_ssh-0.1.2 → py_web_ssh-0.1.3}/webssh/static/styles.css +45 -1
- {py_web_ssh-0.1.2 → py_web_ssh-0.1.3}/LICENSE +0 -0
- {py_web_ssh-0.1.2 → py_web_ssh-0.1.3}/webssh/auth.py +0 -0
- {py_web_ssh-0.1.2 → py_web_ssh-0.1.3}/webssh/files.py +0 -0
- {py_web_ssh-0.1.2 → py_web_ssh-0.1.3}/webssh/history.py +0 -0
- {py_web_ssh-0.1.2 → py_web_ssh-0.1.3}/webssh/models.py +0 -0
- {py_web_ssh-0.1.2 → py_web_ssh-0.1.3}/webssh/session.py +0 -0
- {py_web_ssh-0.1.2 → py_web_ssh-0.1.3}/webssh/ssh_client.py +0 -0
- {py_web_ssh-0.1.2 → py_web_ssh-0.1.3}/webssh/static/logs.html +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: py-web-ssh
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: A Python web SSH client with xterm.js, reconnectable sessions, logs, and file transfer.
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
License-File: LICENSE
|
|
@@ -35,6 +35,8 @@ Description-Content-Type: text/markdown
|
|
|
35
35
|
- 日志页面:`/sessions/{uuid}/logs` 展示完整连接、认证、错误和文件传输日志。
|
|
36
36
|
- 文件传输:优先 SFTP;SFTP 不可用时参考 `simple-ssh-copy` 思路,使用远端 `base64` shell 命令 fallback 上传/下载。
|
|
37
37
|
- 可选 PIN 门禁:服务端传入 `--pin` 后,网页启动时必须先输入正确 PIN;验证成功后浏览器会保存加盐哈希 cookie,后端会保护 HTTP API、日志页面、文件接口和 WebSocket。
|
|
38
|
+
- 浏览器客户端 session:首次访问时服务端会分配独立的浏览器 session UUID,并写入 HttpOnly cookie;它与 SSH 会话 UUID 分离。
|
|
39
|
+
- 左侧控制面板:连接、会话、文件三个栏目改为互斥折叠面板,一次最多展开一个,也可以全部折叠。
|
|
38
40
|
|
|
39
41
|
## 安装
|
|
40
42
|
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
- 终端恢复:服务端保存 SSH 输出流,浏览器定期回传 xterm serialize 快照;重连时先恢复快照,再补放快照之后的输出。
|
|
13
13
|
- 日志页面:`/sessions/{uuid}/logs` 展示完整连接、认证、错误和文件传输日志。
|
|
14
14
|
- 文件传输:优先 SFTP;SFTP 不可用时参考 `simple-ssh-copy` 思路,使用远端 `base64` shell 命令 fallback 上传/下载。
|
|
15
|
-
- 可选 PIN 门禁:服务端传入 `--pin` 后,网页启动时必须先输入正确 PIN;验证成功后浏览器会保存加盐哈希 cookie,后端会保护 HTTP API、日志页面、文件接口和 WebSocket。
|
|
15
|
+
- 可选 PIN 门禁:服务端传入 `--pin` 后,网页启动时必须先输入正确 PIN;验证成功后浏览器会保存加盐哈希 cookie,后端会保护 HTTP API、日志页面、文件接口和 WebSocket。
|
|
16
|
+
- 浏览器客户端 session:首次访问时服务端会分配独立的浏览器 session UUID,并写入 HttpOnly cookie;它与 SSH 会话 UUID 分离。
|
|
17
|
+
- 左侧控制面板:连接、会话、文件三个栏目改为互斥折叠面板,一次最多展开一个,也可以全部折叠。
|
|
16
18
|
|
|
17
19
|
## 安装
|
|
18
20
|
|
|
@@ -13,6 +13,7 @@ from fastapi.staticfiles import StaticFiles
|
|
|
13
13
|
from . import __version__
|
|
14
14
|
from . import auth
|
|
15
15
|
from .auth import add_pin_argument, configure_pin
|
|
16
|
+
from .client_session import ensure_client_session_cookie
|
|
16
17
|
from .files import download_file, filename_for_download, upload_file
|
|
17
18
|
from .models import ConnectRequest, CreateSessionResponse, FileTransferResponse
|
|
18
19
|
from .session import SessionManager
|
|
@@ -32,9 +33,18 @@ sessions = SessionManager()
|
|
|
32
33
|
@app.middleware("http")
|
|
33
34
|
async def require_pin_cookie(request: Request, call_next):
|
|
34
35
|
path = request.url.path
|
|
35
|
-
if
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
if not (
|
|
37
|
+
path.startswith("/static/")
|
|
38
|
+
or path in PUBLIC_PATHS
|
|
39
|
+
or auth.pin_auth.is_request_authorized(request)
|
|
40
|
+
):
|
|
41
|
+
response = JSONResponse({"detail": "PIN authentication required."}, status_code=401)
|
|
42
|
+
ensure_client_session_cookie(request, response)
|
|
43
|
+
return response
|
|
44
|
+
|
|
45
|
+
response = await call_next(request)
|
|
46
|
+
ensure_client_session_cookie(request, response)
|
|
47
|
+
return response
|
|
38
48
|
|
|
39
49
|
|
|
40
50
|
@app.get("/", response_class=HTMLResponse)
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import secrets
|
|
4
|
+
import threading
|
|
5
|
+
import uuid
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
from datetime import datetime, timezone
|
|
8
|
+
|
|
9
|
+
from fastapi import Request
|
|
10
|
+
from fastapi.responses import Response
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
COOKIE_NAME = "py_web_ssh_client_session"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass
|
|
17
|
+
class ClientSession:
|
|
18
|
+
session_id: str
|
|
19
|
+
created_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc))
|
|
20
|
+
updated_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class ClientSessionStore:
|
|
24
|
+
def __init__(self) -> None:
|
|
25
|
+
self._lock = threading.RLock()
|
|
26
|
+
self._sessions: dict[str, ClientSession] = {}
|
|
27
|
+
|
|
28
|
+
def get_or_create(self, session_id: str | None) -> tuple[ClientSession, bool]:
|
|
29
|
+
with self._lock:
|
|
30
|
+
if session_id and session_id in self._sessions:
|
|
31
|
+
session = self._sessions[session_id]
|
|
32
|
+
session.updated_at = datetime.now(timezone.utc)
|
|
33
|
+
return session, False
|
|
34
|
+
|
|
35
|
+
session = ClientSession(session_id=str(uuid.uuid4()))
|
|
36
|
+
self._sessions[session.session_id] = session
|
|
37
|
+
return session, True
|
|
38
|
+
|
|
39
|
+
def get(self, session_id: str) -> ClientSession | None:
|
|
40
|
+
with self._lock:
|
|
41
|
+
return self._sessions.get(session_id)
|
|
42
|
+
|
|
43
|
+
def count(self) -> int:
|
|
44
|
+
with self._lock:
|
|
45
|
+
return len(self._sessions)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
client_sessions = ClientSessionStore()
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def ensure_client_session_cookie(request: Request, response: Response) -> ClientSession:
|
|
52
|
+
session, created = client_sessions.get_or_create(request.cookies.get(COOKIE_NAME))
|
|
53
|
+
request.state.client_session_id = session.session_id
|
|
54
|
+
if created:
|
|
55
|
+
response.set_cookie(
|
|
56
|
+
COOKIE_NAME,
|
|
57
|
+
session.session_id,
|
|
58
|
+
httponly=True,
|
|
59
|
+
samesite="lax",
|
|
60
|
+
secure=False,
|
|
61
|
+
path="/",
|
|
62
|
+
max_age=30 * 24 * 60 * 60,
|
|
63
|
+
)
|
|
64
|
+
return session
|
|
@@ -8,6 +8,7 @@ const pinGate = document.querySelector("#pin-gate");
|
|
|
8
8
|
const pinForm = document.querySelector("#pin-form");
|
|
9
9
|
const pinInput = document.querySelector("#pin-input");
|
|
10
10
|
const pinError = document.querySelector("#pin-error");
|
|
11
|
+
const panelToggles = document.querySelectorAll(".panel-toggle");
|
|
11
12
|
|
|
12
13
|
const term = new Terminal({
|
|
13
14
|
cursorBlink: true,
|
|
@@ -56,6 +57,7 @@ if (activeSessionId) {
|
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
checkPinGate();
|
|
60
|
+
bindControlPanels();
|
|
59
61
|
|
|
60
62
|
window.addEventListener("resize", () => {
|
|
61
63
|
fitAddon.fit();
|
|
@@ -185,6 +187,42 @@ document.querySelectorAll(".tab").forEach((button) => {
|
|
|
185
187
|
});
|
|
186
188
|
});
|
|
187
189
|
|
|
190
|
+
function bindControlPanels() {
|
|
191
|
+
panelToggles.forEach((button) => {
|
|
192
|
+
button.addEventListener("click", () => {
|
|
193
|
+
const panelId = button.getAttribute("aria-controls");
|
|
194
|
+
const isOpen = button.getAttribute("aria-expanded") === "true";
|
|
195
|
+
closeControlPanels();
|
|
196
|
+
if (!isOpen) {
|
|
197
|
+
openControlPanel(panelId);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
document.querySelectorAll("[data-open-panel]").forEach((button) => {
|
|
203
|
+
button.addEventListener("click", () => {
|
|
204
|
+
openControlPanel(button.dataset.openPanel);
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function openControlPanel(panelId) {
|
|
210
|
+
closeControlPanels();
|
|
211
|
+
const panel = document.querySelector(`#${panelId}`);
|
|
212
|
+
const toggle = document.querySelector(`[aria-controls="${panelId}"]`);
|
|
213
|
+
if (!panel || !toggle) return;
|
|
214
|
+
panel.hidden = false;
|
|
215
|
+
toggle.setAttribute("aria-expanded", "true");
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function closeControlPanels() {
|
|
219
|
+
panelToggles.forEach((button) => {
|
|
220
|
+
button.setAttribute("aria-expanded", "false");
|
|
221
|
+
const panel = document.querySelector(`#${button.getAttribute("aria-controls")}`);
|
|
222
|
+
if (panel) panel.hidden = true;
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
188
226
|
function connectWebSocket(sessionId) {
|
|
189
227
|
if (ws) {
|
|
190
228
|
sendSnapshot();
|
|
@@ -26,9 +26,16 @@
|
|
|
26
26
|
<p>Web SSH client</p>
|
|
27
27
|
</header>
|
|
28
28
|
|
|
29
|
-
<section class="panel">
|
|
30
|
-
<
|
|
31
|
-
|
|
29
|
+
<section class="panel collapsible-panel">
|
|
30
|
+
<button class="panel-toggle" type="button" aria-expanded="false" aria-controls="connect-panel">
|
|
31
|
+
连接
|
|
32
|
+
</button>
|
|
33
|
+
<form id="connect-panel" class="stack panel-body" hidden>
|
|
34
|
+
<div class="section-tabs" aria-label="连接栏目">
|
|
35
|
+
<button class="section-tab active" type="button">连接</button>
|
|
36
|
+
<button class="section-tab" type="button" data-open-panel="session-panel">会话</button>
|
|
37
|
+
<button class="section-tab" type="button" data-open-panel="files-panel">文件</button>
|
|
38
|
+
</div>
|
|
32
39
|
<label>
|
|
33
40
|
目标服务器
|
|
34
41
|
<input id="host" name="host" required autocomplete="off" placeholder="192.168.1.10" />
|
|
@@ -65,9 +72,16 @@
|
|
|
65
72
|
</form>
|
|
66
73
|
</section>
|
|
67
74
|
|
|
68
|
-
<section class="panel">
|
|
69
|
-
<
|
|
70
|
-
|
|
75
|
+
<section class="panel collapsible-panel">
|
|
76
|
+
<button class="panel-toggle" type="button" aria-expanded="false" aria-controls="session-panel">
|
|
77
|
+
会话
|
|
78
|
+
</button>
|
|
79
|
+
<div id="session-panel" class="stack panel-body" hidden>
|
|
80
|
+
<div class="section-tabs" aria-label="会话栏目">
|
|
81
|
+
<button class="section-tab" type="button" data-open-panel="connect-panel">连接</button>
|
|
82
|
+
<button class="section-tab active" type="button">会话</button>
|
|
83
|
+
<button class="section-tab" type="button" data-open-panel="files-panel">文件</button>
|
|
84
|
+
</div>
|
|
71
85
|
<label>
|
|
72
86
|
UUID
|
|
73
87
|
<input id="session-id" autocomplete="off" spellcheck="false" />
|
|
@@ -80,26 +94,35 @@
|
|
|
80
94
|
</div>
|
|
81
95
|
</section>
|
|
82
96
|
|
|
83
|
-
<section class="panel">
|
|
84
|
-
<
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
<section class="panel collapsible-panel">
|
|
98
|
+
<button class="panel-toggle" type="button" aria-expanded="false" aria-controls="files-panel">
|
|
99
|
+
文件
|
|
100
|
+
</button>
|
|
101
|
+
<div id="files-panel" class="panel-body" hidden>
|
|
102
|
+
<div class="section-tabs" aria-label="文件栏目">
|
|
103
|
+
<button class="section-tab" type="button" data-open-panel="connect-panel">连接</button>
|
|
104
|
+
<button class="section-tab" type="button" data-open-panel="session-panel">会话</button>
|
|
105
|
+
<button class="section-tab active" type="button">文件</button>
|
|
106
|
+
</div>
|
|
107
|
+
<form id="upload-form" class="stack">
|
|
108
|
+
<label>
|
|
109
|
+
上传到远端路径
|
|
110
|
+
<input id="upload-path" placeholder="/tmp/file.txt" />
|
|
111
|
+
</label>
|
|
112
|
+
<label>
|
|
113
|
+
本地文件
|
|
114
|
+
<input id="upload-file" type="file" />
|
|
115
|
+
</label>
|
|
116
|
+
<button type="submit">上传</button>
|
|
117
|
+
</form>
|
|
118
|
+
<form id="download-form" class="stack compact">
|
|
119
|
+
<label>
|
|
120
|
+
下载远端路径
|
|
121
|
+
<input id="download-path" placeholder="/tmp/file.txt" />
|
|
122
|
+
</label>
|
|
123
|
+
<button type="submit">下载</button>
|
|
124
|
+
</form>
|
|
125
|
+
</div>
|
|
103
126
|
</section>
|
|
104
127
|
</aside>
|
|
105
128
|
|
|
@@ -136,7 +136,51 @@ label {
|
|
|
136
136
|
|
|
137
137
|
.panel {
|
|
138
138
|
display: grid;
|
|
139
|
-
gap:
|
|
139
|
+
gap: 8px;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.panel-toggle {
|
|
143
|
+
display: flex;
|
|
144
|
+
align-items: center;
|
|
145
|
+
justify-content: space-between;
|
|
146
|
+
width: 100%;
|
|
147
|
+
min-height: 38px;
|
|
148
|
+
font-weight: 700;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.panel-toggle::after {
|
|
152
|
+
content: "+";
|
|
153
|
+
color: var(--muted);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.panel-toggle[aria-expanded="true"]::after {
|
|
157
|
+
content: "-";
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.panel-body {
|
|
161
|
+
display: grid;
|
|
162
|
+
gap: 10px;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.panel-body[hidden] {
|
|
166
|
+
display: none;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.section-tabs {
|
|
170
|
+
display: grid;
|
|
171
|
+
grid-template-columns: repeat(3, minmax(0, 1fr));
|
|
172
|
+
gap: 6px;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.section-tab {
|
|
176
|
+
min-height: 30px;
|
|
177
|
+
padding: 0 6px;
|
|
178
|
+
font-size: 12px;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.section-tab.active {
|
|
182
|
+
border-color: var(--accent);
|
|
183
|
+
color: var(--accent);
|
|
140
184
|
}
|
|
141
185
|
|
|
142
186
|
.panel h2 {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|