P10-B adds delete_path, move_path and create_folder, and the switch they need. Reusing McpFileTransfer would have been wrong: uploading overwrites a file, deleting destroys a tree, and an operator who wants one may well not want the other. McpFileWrite is therefore a separate key, off by default, wired the way every other switch is - read from settings.ini at startup, reported as get_server_status.switches.file_write, and exposed with its own checkbox in the MCP settings dialog. The tools additionally require readonly to be off: a read-only server has no business modifying a host. No client change was needed: COMMAND_DELETE_FILE, COMMAND_DELETE_DIRECTORY, COMMAND_CREATE_FOLDER and COMMAND_RENAME_FILE already existed in the Windows file manager. The chain reuses the file-manager sub-connection and adds a phase - the main connection asks for the drive list, the sub-connection's first packet hands it to OnDriveList which sends the write command, and the client's TOKEN_*_FINISH ack moves the pending request from phase 0 to 1, where the tool sends COMMAND_LIST_FILES for the parent so the ack and the confirmation share one timeout. Only the IO thread touches the sub-connection; the tool thread just waits on the shared condvar, which keeps the sub-connection's lifetime out of its reach. The confirmation exists because the client answers unconditionally: it ignores the return values of DeleteFile, MoveFile and MakeSureDirectoryPathExists and there is no error token. ok therefore only means "the command arrived", and verified is the real answer - true when the parent listing shows the expected post-state, false when it shows the opposite, null when the listing itself did not come back (timeout or disconnect), since reporting that as false would be a lie. Linux, macOS and Android hosts are refused outright: those clients decode these paths as GBK while the server speaks UTF-8 to them for list_files, so a non-ASCII path would corrupt rather than fail. Paths are validated as UTF-8, converted to GBK exactly once, and reject %VAR%, relative paths, drive and share roots, and - for delete_path and for move_path's source - the Windows, Program Files, ProgramData, $Recycle.Bin and System Volume Information trees. create_folder gets no system-directory ban, because writing there is the same permission upload_file already has. Two defects surfaced while exercising this against a real client: create_folder's wire path has to end with a backslash, because MakeSureDirectoryPathExists treats a non-terminated last component as a file name and only creates the intermediate levels; and ResolveFileOpVerified(LookupInListing(...), isDir, ...) read isDir before the lookup ever set it - argument evaluation order is unspecified and MSVC evaluates right to left - so every create_folder reported verified=false even when the directory existed. Verified on a Debug x64 build against a Windows client over MCP: nested create_folder, upload, rename, delete, delete a tree, the failure shapes (delete with recursive=false on a directory, create_folder onto an existing file name, delete of a non-existent target) and every refusal (drive root, C:\Windows\Temp, C:\Users, %TEMP%, relative, empty, over-long, from==to, offline host, non-numeric id), with a Chinese-named directory created, renamed and deleted end to end; no file-manager window appeared in the server process during any of it. The smoke test gained section [4c], opt-in through -FileWriteDir, which asserts verified and never ok and walks a sandbox through the same path; two runs passed 69 checks with the sandbox removed afterwards. Bin/settings.ini was restored byte-exact and the Release instance was left alone. Co-Authored-By: deepseek-flash
77 lines
3.3 KiB
C++
77 lines
3.3 KiB
C++
#pragma once
|
||
|
||
#include <afxwin.h>
|
||
#include <afxcmn.h>
|
||
#include <vector>
|
||
|
||
// 「MCP设置」配置对话框:启用 MCP / 端口 / 绑定地址 / Token / HTTPS 与证书。
|
||
// 因 2015Remote.rc 为 UTF-16 编码、不宜手工编辑,参照 ZstaPickerDlg 用
|
||
// InitModalIndirect + 内存 DLGTEMPLATE 程序化创建(见 docs/Mcp_Design.md §3.8)。
|
||
class CMcpSettingsDlg : public CDialog
|
||
{
|
||
public:
|
||
explicit CMcpSettingsDlg(CWnd* parent = nullptr);
|
||
|
||
virtual INT_PTR DoModal();
|
||
|
||
protected:
|
||
virtual BOOL OnInitDialog();
|
||
virtual void OnOK();
|
||
|
||
afx_msg void OnHttpsToggle();
|
||
afx_msg void OnBrowseCert();
|
||
afx_msg void OnBrowseKey();
|
||
|
||
DECLARE_MESSAGE_MAP()
|
||
|
||
private:
|
||
enum CtrlId {
|
||
IDC_MCP_ENABLE = 1001, // 「启用 MCP」复选框
|
||
IDC_MCP_PORT = 1002, // 端口编辑框
|
||
IDC_MCP_BIND = 1003, // 绑定地址编辑框
|
||
IDC_MCP_TOKEN = 1004, // Token 编辑框
|
||
IDC_MCP_READONLY = 1005, // 「只读模式」复选框(默认勾选,禁 exec_command)
|
||
IDC_MCP_WHITELIST = 1006, // 命令白名单编辑框(多行,逗号/换行分隔,空 = 内置只读前缀)
|
||
IDC_MCP_TERMINAL = 1007, // 「启用持久终端」复选框(全命令,无白名单,要求只读关)
|
||
IDC_MCP_REMOTECONTROL = 1008, // 「启用远程控制」复选框(AI 操控桌面,要求只读关)
|
||
IDC_MCP_FILETRANSFER = 1009, // 「启用文件传输」复选框(download_file,不要求只读关)
|
||
IDC_MCP_MANAGE = 1010, // 「启用管理操作」复选框(kill/窗口/服务/电源,要求只读关)
|
||
IDC_MCP_MACHINE = 1011, // 「启用主机管理」复选框(host_* 工具族)
|
||
IDC_MCP_MACHINE_DANGEROUS = 1012, // 「启用危险主机操作」复选框(冻结/停止/重启)
|
||
IDC_MCP_CHAT = 1013, // 「启用远程交谈」复选框(chat_* 工具族,不要求只读关)
|
||
IDC_MCP_KEYLOG = 1014, // 「启用键盘记录」复选框(get_keylog,不要求只读关)
|
||
IDC_MCP_HTTPS = 1015, // 「启用 HTTPS」复选框(MCP 端口同时接受 TLS)
|
||
IDC_MCP_CERT = 1016, // 证书路径编辑框(PEM)
|
||
IDC_MCP_KEY = 1017, // 私钥路径编辑框(PKCS#8)
|
||
IDC_MCP_CERT_BROWSE = 1018, // 证书路径「浏览」按钮
|
||
IDC_MCP_KEY_BROWSE = 1019, // 私钥路径「浏览」按钮
|
||
IDC_MCP_FILEWRITE = 1020, // 「启用文件写入」复选框(删除/改名/建目录,要求只读关)
|
||
};
|
||
|
||
CButton m_btnEnable;
|
||
CStatic m_lblPort, m_lblBind, m_lblToken;
|
||
CEdit m_editPort, m_editBind, m_editToken;
|
||
CButton m_btnReadonly;
|
||
CButton m_btnTerminal;
|
||
CButton m_btnRemoteControl;
|
||
CButton m_btnFileTransfer;
|
||
CButton m_btnFileWrite;
|
||
CButton m_btnManage;
|
||
CButton m_btnMachine;
|
||
CButton m_btnMachineDangerous;
|
||
CButton m_btnChat;
|
||
CButton m_btnKeylog;
|
||
CStatic m_lblWhitelist;
|
||
CEdit m_editWhitelist;
|
||
CButton m_btnHttps;
|
||
CStatic m_lblCert, m_lblKey;
|
||
CEdit m_editCert, m_editKey;
|
||
CButton m_btnCertBrowse, m_btnKeyBrowse;
|
||
CButton m_btnOK, m_btnCancel;
|
||
|
||
std::vector<BYTE> m_Template; // 内存 DLGTEMPLATE 字节
|
||
|
||
void LayoutControls(int cx, int cy);
|
||
void UpdateHttpsState(); // 勾选 HTTPS 才允许编辑证书/私钥
|
||
};
|