dsh-winrm 0.1.0
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.
- package/LICENSE +73 -0
- package/README.md +112 -0
- package/README.zh.md +119 -0
- package/RELEASING.md +75 -0
- package/cordis.patch.yml +8 -0
- package/lib/client.js +2076 -0
- package/lib/index.js +2458 -0
- package/lib/invariant.js +6 -0
- package/lib/types/client/api.d.ts +59 -0
- package/lib/types/client/index.d.ts +38 -0
- package/lib/types/client/locales.d.ts +231 -0
- package/lib/types/client/panel/ConsoleTab.d.ts +11 -0
- package/lib/types/client/panel/HostFormDialog.d.ts +12 -0
- package/lib/types/client/panel/HostsTab.d.ts +9 -0
- package/lib/types/client/panel/ProcessesTab.d.ts +7 -0
- package/lib/types/client/panel/ServicesTab.d.ts +7 -0
- package/lib/types/client/panel/TransferTab.d.ts +7 -0
- package/lib/types/client/panel/WinrmPanel.d.ts +12 -0
- package/lib/types/client/panel/WinrmPanelIcon.d.ts +8 -0
- package/lib/types/client/panel/helpers.d.ts +16 -0
- package/lib/types/engine/client.d.ts +49 -0
- package/lib/types/engine/console.d.ts +23 -0
- package/lib/types/engine.d.ts +58 -0
- package/lib/types/index.d.ts +44 -0
- package/lib/types/invariant.d.ts +3 -0
- package/lib/types/loopback.d.ts +24 -0
- package/lib/types/mount-once.d.ts +24 -0
- package/lib/types/powershell.d.ts +73 -0
- package/lib/types/protocol.d.ts +176 -0
- package/lib/types/routes.d.ts +26 -0
- package/lib/types/smb.d.ts +31 -0
- package/lib/types/store.d.ts +44 -0
- package/lib/types/tools.d.ts +20 -0
- package/package.json +111 -0
- package/scripts/enable-winrm.ps1 +0 -0
- package/scripts/postbuild.mjs +40 -0
- package/scripts/validate-manifest.mjs +18 -0
- package/src/client/api.ts +345 -0
- package/src/client/css-modules.d.ts +5 -0
- package/src/client/index.ts +82 -0
- package/src/client/locales.ts +243 -0
- package/src/client/panel/ConsoleTab.tsx +142 -0
- package/src/client/panel/HostFormDialog.tsx +142 -0
- package/src/client/panel/HostsTab.tsx +153 -0
- package/src/client/panel/ProcessesTab.tsx +119 -0
- package/src/client/panel/ServicesTab.tsx +123 -0
- package/src/client/panel/TransferTab.tsx +161 -0
- package/src/client/panel/WinrmPanel.tsx +85 -0
- package/src/client/panel/WinrmPanelIcon.tsx +27 -0
- package/src/client/panel/helpers.ts +33 -0
- package/src/client/panel/panel.module.css +1000 -0
- package/src/engine/client.ts +291 -0
- package/src/engine/console.ts +62 -0
- package/src/engine.ts +331 -0
- package/src/index.ts +142 -0
- package/src/invariant.ts +4 -0
- package/src/loopback.ts +63 -0
- package/src/mount-once.ts +48 -0
- package/src/powershell.ts +208 -0
- package/src/protocol.ts +178 -0
- package/src/routes.ts +490 -0
- package/src/smb.ts +129 -0
- package/src/store.ts +232 -0
- package/src/tools.ts +387 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
10
|
+
|
|
11
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
12
|
+
|
|
13
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
14
|
+
|
|
15
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
16
|
+
|
|
17
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
18
|
+
|
|
19
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
20
|
+
|
|
21
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
22
|
+
|
|
23
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
24
|
+
|
|
25
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
26
|
+
|
|
27
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
28
|
+
|
|
29
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
30
|
+
|
|
31
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
32
|
+
|
|
33
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
34
|
+
|
|
35
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
36
|
+
|
|
37
|
+
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
38
|
+
|
|
39
|
+
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
40
|
+
|
|
41
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
|
42
|
+
|
|
43
|
+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
44
|
+
|
|
45
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
46
|
+
|
|
47
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
48
|
+
|
|
49
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
50
|
+
|
|
51
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
52
|
+
|
|
53
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
54
|
+
|
|
55
|
+
END OF TERMS AND CONDITIONS
|
|
56
|
+
|
|
57
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
58
|
+
|
|
59
|
+
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
|
|
60
|
+
|
|
61
|
+
Copyright [yyyy] [name of copyright owner]
|
|
62
|
+
|
|
63
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
64
|
+
you may not use this file except in compliance with the License.
|
|
65
|
+
You may obtain a copy of the License at
|
|
66
|
+
|
|
67
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
68
|
+
|
|
69
|
+
Unless required by applicable law or agreed to in writing, software
|
|
70
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
71
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
72
|
+
See the License for the specific language governing permissions and
|
|
73
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# dsh-winrm — Windows 远程管理插件(WinRM / PowerShell Remoting)
|
|
2
|
+
|
|
3
|
+
[中文文档](README.zh.md) | English
|
|
4
|
+
|
|
5
|
+
仿照 [dsh-ssh](https://github.com/zhu1090093659/dsh-web-ui/tree/main/packages/dsh-ssh) 开发的 DSH 插件:用 Windows 原生的 **WinRM / PowerShell Remoting** 协议远程管理 Windows 服务器,**目标机不需要装 OpenSSH**。
|
|
6
|
+
|
|
7
|
+
## 功能
|
|
8
|
+
|
|
9
|
+
| 面 | 说明 |
|
|
10
|
+
| --- | --- |
|
|
11
|
+
| GUI 侧边栏「Windows」入口 | 居中面板:**主机** / **控制台** / **服务** / **进程** / **传输** 五个页签 |
|
|
12
|
+
| Agent 工具 | `winrm_list` `winrm_exec` `winrm_service` `winrm_process` `winrm_upload` `winrm_download` `winrm_cluster` |
|
|
13
|
+
| PowerShell 控制台 | WebSocket 命令会话(每条命令通过原生 Node WinRM 客户端执行,输出实时返回) |
|
|
14
|
+
| 服务管理 | 列出 / 启动 / 停止 / 重启 / 改启动类型(自动/手动/禁用) |
|
|
15
|
+
| 进程管理 | 列出(CPU/内存/路径)/ 按 PID 结束 |
|
|
16
|
+
| 文件传输 | base64 分块读写,**不依赖 SMB**,任意路径可传;上传自动建目录 |
|
|
17
|
+
| 集群 | 一条命令并发跑多台主机(按 aliases / environment / tags 过滤) |
|
|
18
|
+
|
|
19
|
+
## 认证与传输
|
|
20
|
+
|
|
21
|
+
- 使用原生 Node.js WinRM 客户端([winrm-client](https://github.com/shide1989/winrm-client)),按传输自动选择认证:HTTPS 优先 Basic、HTTP 优先 NTLM,两者均自动回退(HTTP Basic 仅限受信内网,公网必须使用 HTTPS)
|
|
22
|
+
- 本地账户可写 `Administrator`;域账户可写 `DOMAIN\user` 或 `user@domain`
|
|
23
|
+
- 本机无需 Python —— WinRM 走纯 Node 依赖(winrm-client),随插件一起安装
|
|
24
|
+
- 传输:HTTP(5985) 或 HTTPS(5986);HTTPS 可勾选「接受自签名证书」
|
|
25
|
+
- 中文输出不乱码:所有命令走 **UTF-8 base64 信封**(`-EncodedCommand` + `Out-String` 包装),绕过 WinRM 传输的代码页问题
|
|
26
|
+
- 命令结果的 `stderr` 已自动剥离 PowerShell 的 CLIXML 宿主机记录;真实的进程级 stderr(如 `[Console]::Error`)原样保留
|
|
27
|
+
|
|
28
|
+
## 目标机准备(一次性)
|
|
29
|
+
|
|
30
|
+
在要管理的 Windows 机器上,**以管理员身份**运行:
|
|
31
|
+
|
|
32
|
+
```powershell
|
|
33
|
+
powershell -ExecutionPolicy Bypass -File .\scripts\enable-winrm.ps1
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
脚本自动:启用 WinRM 服务与 5985 监听 → 开放 Basic/Negotiate 认证 → 允许 HTTP 明文(内网)→ WinRS 内存上限 512MB → 放行防火墙 → 打印本机 IP。
|
|
37
|
+
|
|
38
|
+
> ⚠️ **安全**:HTTP + Basic 是明文,仅限受信内网;公网请配置 HTTPS + 自签名证书,并在插件里勾选「接受自签名证书」。密码明文存于本机 `~/.dsh/dsh-winrm.json`(0600 权限,仅当前用户可读),插件界面永不回显。
|
|
39
|
+
|
|
40
|
+
## 安装
|
|
41
|
+
|
|
42
|
+
> 需要 DeepSeek Harness **0.1.7 系列**(`0.1.7-alpha.2` 及以后,含 `0.1.7-rc.1`)。插件的 `peerDependencies` 声明为 `^0.1.7-alpha.2`,DSH 启动时会据此校验:0.1.x 各版本可加载,`0.2.0` 起会被拒绝(确需冒险可用 `dsh plugin allow-version` 逐版本放行)。
|
|
43
|
+
|
|
44
|
+
从 [Releases](https://github.com/MoRanYue/dsh-winrm/releases) 下载最新的 `dsh-winrm-*.tgz`,加入 profile:
|
|
45
|
+
|
|
46
|
+
```powershell
|
|
47
|
+
dsh plugin --profile web add D:\downloads\dsh-winrm-0.1.0.tgz
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
也可以直接从 npm 安装:
|
|
51
|
+
|
|
52
|
+
```powershell
|
|
53
|
+
dsh plugin --profile web add dsh-winrm
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
本地开发可用 profile 链接安装:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
dsh plugin --profile web add link:D:\项目\dsh-winrm
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
安装后 **重启 dsh web**(退出再启动 `dsh web`)使插件生效。侧边栏出现「Windows」入口;对话中可直接用 `winrm_list` 等工具。
|
|
63
|
+
|
|
64
|
+
### 从源码构建
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
cd D:\项目\dsh-winrm
|
|
68
|
+
pnpm install
|
|
69
|
+
npm run build # tsc 声明 + tsdown 宿主/客户端打包 + postbuild 包装
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## 使用示例(agent 工具)
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
winrm_list # 列出已配置主机
|
|
76
|
+
winrm_exec alias=web1 command="Get-Service | Select -First 5 | Format-Table"
|
|
77
|
+
winrm_service alias=web1 name=W3SVC action=restart
|
|
78
|
+
winrm_process alias=web1 action=list
|
|
79
|
+
winrm_process alias=web1 id=1234 action=kill
|
|
80
|
+
winrm_upload alias=web1 localPath=D:\a.zip remotePath=C:\temp\a.zip
|
|
81
|
+
winrm_download alias=web1 remotePath=C:\logs\app.log localPath=D:\app.log
|
|
82
|
+
winrm_cluster command="Get-Date" tags=prod
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## 架构
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
src/
|
|
89
|
+
index.ts Cordis 插件入口(webServer/tools/systemPrompt 挂载 + 设置面板 + 公告)
|
|
90
|
+
engine.ts WinRmEngine 门面:exec / services / processes / ls / upload / download / console / cluster / test
|
|
91
|
+
store.ts ~/.dsh/dsh-winrm.json 主机存储(原子写,0600)
|
|
92
|
+
protocol.ts 宿主↔浏览器 wire 类型
|
|
93
|
+
powershell.ts PS 片段构造器(UTF-8 信封 / 服务 / 进程 / 目录 / 分块读写)
|
|
94
|
+
routes.ts /api/dsh-winrm 路由族 + 控制台 WebSocket(loopback 围栏)
|
|
95
|
+
tools.ts 7 个 winrm_* agent 工具
|
|
96
|
+
engine/client.ts winrm-client 传输层:进程内认证(NTLM/Basic)、UTF-8 信封、分块传输
|
|
97
|
+
engine/console.ts 流式 PowerShell 控制台会话
|
|
98
|
+
client/ 浏览器半:侧边栏入口 + 居中面板(5 页签)
|
|
99
|
+
scripts/
|
|
100
|
+
enable-winrm.ps1 目标机一键启用 WinRM
|
|
101
|
+
postbuild.mjs 客户端产物 __ModuleLoader__ 包装
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
传输依赖原生 Node.js 的 [winrm-client](https://github.com/shide1989/winrm-client)(NTLM/Basic,进程内认证);密码只在宿主进程内使用,不出现在任何子进程命令行参数中。
|
|
105
|
+
|
|
106
|
+
## 已知限制
|
|
107
|
+
|
|
108
|
+
- 控制台是命令会话,不保持 PowerShell 变量和当前目录状态;每条命令独立执行
|
|
109
|
+
- WinRM 单次响应受 150KB 信封上限约束,传输按 48KB 分块,大文件较慢(每块一次往返)
|
|
110
|
+
- 单命令默认 60s 超时,可传 `timeoutMs`
|
|
111
|
+
- 目标机需已启用 WinRM(见上);HTTP 明文 Basic 不应用于公网
|
|
112
|
+
- 面板关闭再打开会回到「主机」页签:面板是 `main` 插槽的占用者,切回对话时卸载,页签状态不跨开关保留
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# dsh-winrm — Windows 远程管理插件(WinRM / PowerShell Remoting)
|
|
2
|
+
|
|
3
|
+
仿照 [dsh-ssh](https://github.com/zhu1090093659/dsh-web-ui/tree/main/packages/dsh-ssh) 开发的 DSH 插件:用 Windows 原生的 **WinRM / PowerShell Remoting** 协议远程管理 Windows 服务器,**目标机不需要装 OpenSSH**。
|
|
4
|
+
|
|
5
|
+
## 功能
|
|
6
|
+
|
|
7
|
+
| 面 | 说明 |
|
|
8
|
+
| --- | --- |
|
|
9
|
+
| GUI 侧边栏「Windows」入口 | 居中面板:**主机** / **控制台** / **服务** / **进程** / **传输** 五个页签 |
|
|
10
|
+
| Agent 工具 | `winrm_list` `winrm_exec` `winrm_service` `winrm_process` `winrm_upload` `winrm_download` `winrm_cluster` |
|
|
11
|
+
| PowerShell 控制台 | WebSocket 命令会话(每条命令通过原生 Node WinRM 客户端执行,输出实时返回) |
|
|
12
|
+
| 服务管理 | 列出 / 启动 / 停止 / 重启 / 改启动类型(自动/手动/禁用) |
|
|
13
|
+
| 进程管理 | 列出(CPU/内存/路径)/ 按 PID 结束 |
|
|
14
|
+
| 文件传输 | base64 分块读写,**不依赖 SMB**,任意路径可传;上传自动建目录 |
|
|
15
|
+
| 集群 | 一条命令并发跑多台主机(按 aliases / environment / tags 过滤) |
|
|
16
|
+
|
|
17
|
+
## 认证与传输
|
|
18
|
+
|
|
19
|
+
- 使用原生 Node.js WinRM 客户端([winrm-client](https://github.com/shide1989/winrm-client)),按传输自动选择认证:HTTPS 优先 Basic、HTTP 优先 NTLM,两者均自动回退(HTTP Basic 仅限受信内网,公网必须使用 HTTPS)
|
|
20
|
+
- 本地账户可写 `Administrator`;域账户可写 `DOMAIN\\user` 或 `user@domain`
|
|
21
|
+
- 本机无需 Python —— WinRM 走纯 Node 依赖(winrm-client),随插件一起安装
|
|
22
|
+
- 传输:HTTP(5985) 或 HTTPS(5986);HTTPS 可勾选「接受自签名证书」
|
|
23
|
+
- 中文输出不乱码:所有命令走 **UTF-8 base64 信封**(`-EncodedCommand` + `Out-String` 包装),绕过 WinRM 传输的代码页问题
|
|
24
|
+
- 命令结果的 `stderr` 已自动剥离 PowerShell 的 CLIXML 宿主机记录;真实的进程级 stderr(如 `[Console]::Error`)原样保留
|
|
25
|
+
|
|
26
|
+
## 目标机准备(一次性)
|
|
27
|
+
|
|
28
|
+
在要管理的 Windows 机器上,**以管理员身份**运行:
|
|
29
|
+
|
|
30
|
+
```powershell
|
|
31
|
+
powershell -ExecutionPolicy Bypass -File .\scripts\enable-winrm.ps1
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
脚本自动:启用 WinRM 服务与 5985 监听 → 开放 Basic/Negotiate 认证 → 允许 HTTP 明文(内网)→ WinRS 内存上限 512MB → 放行防火墙 → 打印本机 IP。
|
|
35
|
+
|
|
36
|
+
> ⚠️ **安全**:HTTP + Basic 是明文,仅限受信内网;公网请配置 HTTPS + 自签名证书,并在插件里勾选「接受自签名证书」。密码明文存于本机 `~/.dsh/dsh-winrm.json`(0600 权限,仅当前用户可读),插件界面永不回显。
|
|
37
|
+
|
|
38
|
+
## 截图
|
|
39
|
+
|
|
40
|
+

|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
## 安装
|
|
44
|
+
|
|
45
|
+
> 需要 DeepSeek Harness **0.1.7 系列**(`0.1.7-alpha.2` 及以后,含 `0.1.7-rc.1`)。插件的 `peerDependencies` 声明为 `^0.1.7-alpha.2`,DSH 启动时会据此校验:0.1.x 各版本可加载,`0.2.0` 起会被拒绝(确需冒险可用 `dsh plugin allow-version` 逐版本放行)。
|
|
46
|
+
|
|
47
|
+
从 [Releases](https://github.com/MoRanYue/dsh-winrm/releases) 下载最新的 `dsh-winrm-*.tgz`,加入 profile:
|
|
48
|
+
|
|
49
|
+
```powershell
|
|
50
|
+
dsh plugin --profile web add D:\downloads\dsh-winrm-0.1.0.tgz
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
也可以直接从 npm 安装:
|
|
54
|
+
|
|
55
|
+
```powershell
|
|
56
|
+
dsh plugin --profile web add dsh-winrm
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
本地开发可用 profile 链接安装:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
dsh plugin --profile web add link:D:\项目\dsh-winrm
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
安装后 **重启 dsh web**(退出再启动 `dsh web`)使插件生效。侧边栏出现「Windows」入口;对话中可直接用 `winrm_list` 等工具。
|
|
66
|
+
|
|
67
|
+
### 从源码构建
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
cd D:\项目\dsh-winrm
|
|
71
|
+
pnpm install
|
|
72
|
+
npm run build # tsc 声明 + tsdown 宿主/客户端打包 + postbuild 包装
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## 使用示例(agent 工具)
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
winrm_list # 列出已配置主机
|
|
79
|
+
winrm_exec alias=web1 command="Get-Service | Select -First 5 | Format-Table"
|
|
80
|
+
winrm_service alias=web1 name=W3SVC action=restart
|
|
81
|
+
winrm_process alias=web1 action=list
|
|
82
|
+
winrm_process alias=web1 id=1234 action=kill
|
|
83
|
+
winrm_upload alias=web1 localPath=D:\a.zip remotePath=C:\temp\a.zip
|
|
84
|
+
winrm_download alias=web1 remotePath=C:\logs\app.log localPath=D:\app.log
|
|
85
|
+
winrm_cluster command="Get-Date" tags=prod
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## 架构
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
src/
|
|
92
|
+
index.ts Cordis 插件入口(webServer/tools/systemPrompt 挂载 + 设置面板 + 公告)
|
|
93
|
+
engine.ts WinRmEngine 门面:exec / services / processes / ls / upload / download / console / cluster / test
|
|
94
|
+
store.ts ~/.dsh/dsh-winrm.json 主机存储(原子写,0600)
|
|
95
|
+
protocol.ts 宿主↔浏览器 wire 类型
|
|
96
|
+
powershell.ts PS 片段构造器(UTF-8 信封 / 服务 / 进程 / 目录 / 分块读写)
|
|
97
|
+
routes.ts /api/dsh-winrm 路由族 + 控制台 WebSocket(loopback 围栏)
|
|
98
|
+
tools.ts 7 个 winrm_* agent 工具
|
|
99
|
+
engine/client.ts winrm-client 传输层:进程内认证(NTLM/Basic)、UTF-8 信封、分块传输
|
|
100
|
+
engine/console.ts 流式 PowerShell 控制台会话
|
|
101
|
+
client/ 浏览器半:侧边栏入口 + 居中面板(5 页签)
|
|
102
|
+
scripts/
|
|
103
|
+
enable-winrm.ps1 目标机一键启用 WinRM
|
|
104
|
+
postbuild.mjs 客户端产物 __ModuleLoader__ 包装
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
传输依赖原生 Node.js 的 [winrm-client](https://github.com/shide1989/winrm-client)(NTLM/Basic,进程内认证);密码只在宿主进程内使用,不出现在任何子进程命令行参数中。
|
|
108
|
+
|
|
109
|
+
## 已知限制
|
|
110
|
+
|
|
111
|
+
- 控制台是命令会话,不保持 PowerShell 变量和当前目录状态;每条命令独立执行
|
|
112
|
+
- WinRM 单次响应受 150KB 信封上限约束,传输按 48KB 分块,大文件较慢(每块一次往返)
|
|
113
|
+
- 单命令默认 60s 超时,可传 `timeoutMs`
|
|
114
|
+
- 目标机需已启用 WinRM(见上);HTTP 明文 Basic 不应用于公网
|
|
115
|
+
- 面板关闭再打开会回到「主机」页签:面板是 `main` 插槽的占用者,切回对话时卸载,页签状态不跨开关保留
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
English documentation: see [README.md](README.md).
|
package/RELEASING.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Releasing
|
|
2
|
+
|
|
3
|
+
The package publishes to npm as `dsh-winrm`. Releases are cut by pushing a
|
|
4
|
+
version tag; the [release workflow](.github/workflows/release.yml) then
|
|
5
|
+
publishes that exact commit.
|
|
6
|
+
|
|
7
|
+
## One-time bootstrap: the first version
|
|
8
|
+
|
|
9
|
+
**npm cannot publish a package's first version over OIDC.** Trusted publishing
|
|
10
|
+
is configured on the package's page on npmjs.com, and a package that does not
|
|
11
|
+
exist yet has no such page — a chicken-and-egg limit tracked in
|
|
12
|
+
[npm/cli#8544](https://github.com/npm/cli/issues/8544). The first release
|
|
13
|
+
therefore has to be published manually, with a token or `npm login`:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm login # or export a granular publish token
|
|
17
|
+
npm publish
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Verify the result, then finish the setup:
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
npm view dsh-winrm version
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Tagging that same commit (`git tag v0.1.0 && git push origin v0.1.0`) is safe:
|
|
27
|
+
the workflow checks the registry first and skips publishing a version that is
|
|
28
|
+
already there, so the bootstrap release does not fail the run.
|
|
29
|
+
|
|
30
|
+
## One-time bootstrap: authorize this workflow
|
|
31
|
+
|
|
32
|
+
After the first version exists, open the package on npmjs.com →
|
|
33
|
+
**Settings → Trusted publishing → GitHub Actions** and register:
|
|
34
|
+
|
|
35
|
+
| Field | Value |
|
|
36
|
+
| --- | --- |
|
|
37
|
+
| Organization or user | `MoRanYue` |
|
|
38
|
+
| Repository | `dsh-winrm` |
|
|
39
|
+
| Workflow filename | `release.yml` |
|
|
40
|
+
| Environment name | *(leave empty)* |
|
|
41
|
+
|
|
42
|
+
The workflow filename must match exactly, including the `.yml` extension;
|
|
43
|
+
npm does not validate the entry when it is saved, so a typo only shows up as an
|
|
44
|
+
`ENEEDAUTH` failure on the next release.
|
|
45
|
+
|
|
46
|
+
Once trusted publishing works, consider restricting token-based publishing
|
|
47
|
+
(Settings → Publishing access) and revoking unused automation tokens.
|
|
48
|
+
|
|
49
|
+
## Cutting a release
|
|
50
|
+
|
|
51
|
+
1. Update `version` in `package.json` and add a matching `CHANGELOG.md` entry.
|
|
52
|
+
2. Run the checks locally:
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
pnpm install
|
|
56
|
+
npm run check # typecheck + build + tests
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
3. Commit, then tag and push:
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
git tag v0.1.1
|
|
63
|
+
git push origin main v0.1.1
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The workflow rejects a tag whose version does not match `package.json`, and
|
|
67
|
+
`npm publish` runs the `prepack` script, so a revision that fails the checks is
|
|
68
|
+
never published. Provenance attestations are generated automatically: this is
|
|
69
|
+
a public package built from a public repository.
|
|
70
|
+
|
|
71
|
+
## Manual publish
|
|
72
|
+
|
|
73
|
+
The workflow is a convenience, not a requirement — a maintainer can always
|
|
74
|
+
publish by hand from a clean checkout (`npm run check && npm publish`). OIDC is
|
|
75
|
+
preferred because it needs no long-lived token in the repository.
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# dsh-winrm bundle patch: inserts the dual-face plugin row into the web
|
|
2
|
+
# profile roster. The row is a bare plugin by package name: the node half
|
|
3
|
+
# (exports ".") runs in the host process (WinRM engine, /api/dsh-winrm
|
|
4
|
+
# routes, agent tools), and the dsh.client declaration in package.json makes
|
|
5
|
+
# the browser half (exports "./client") load in the web GUI.
|
|
6
|
+
- insert:
|
|
7
|
+
- id: winrm
|
|
8
|
+
name: 'dsh-winrm'
|