[feat] rainbox

This commit is contained in:
He
2026-04-06 08:54:29 +08:00
parent 9b61ce3b61
commit 4bb9455b36
10 changed files with 346 additions and 62 deletions
+96
View File
@@ -0,0 +1,96 @@
---
outline: deep
order: 4
---
# 开发
## 配置文件
API Key 保存在 `C:\Users\[user]\.rain\config.json` 中,配置文件格式示例:
```json
{
"api_key": "xxxxxxxxxx",
"servers": [
{ "id": "123456", "name": "my-server" },
{ "id": "789012", "name": "production" }
]
}
```
## 开发环境依赖
```cmd
pip install requests
```
## 打包
```cmd
nuitka --standalone --windows-console-mode=force --include-package=charset_normalizer --output-filename=rain.exe --windows-icon-from-ico=ico.ico 1.py
```
## 安装包
[Inno Setup](https://jrsoftware.org/isinfo.php)是一个非常好用的安装包制作软件。您可以参考一下步骤编辑iss脚本为安装包添加"添加到用户环境变量 PATH"选项:
1.`[Setup]`中,添加`gesEnvironment=yes`
2.`[Tasks]`中,添加选项
```
Name: "addtopath"; Description: "添加到用户环境变量 PATH"; GroupDescription: "其他任务:"; Flags: unchecked
```
3. 在任意位置添加以下脚本
```
[Registry]
; 仅当用户勾选 addtopath 且路径不存在时才添加
Root: HKCU; Subkey: "Environment"; ValueType: expandsz; ValueName: "Path"; \
ValueData: "{olddata};{app}"; Check: NeedsAddPath(ExpandConstant('{app}')); \
Tasks: addtopath
[Code]
const
EnvironmentKey = 'Environment';
// 检查路径是否已存在于 PATH 中
function NeedsAddPath(Param: string): boolean;
var
OrigPath: string;
begin
if not RegQueryStringValue(HKEY_CURRENT_USER, EnvironmentKey, 'Path', OrigPath) then
begin
Result := True;
exit;
end;
// 前后加分号判断,避免误匹配
Result := Pos(';' + Param + ';', ';' + OrigPath + ';') = 0;
end;
// 从 PATH 中移除指定路径(卸载时调用,幂等操作)
procedure RemovePath(Path: string);
var
Paths: string;
P: Integer;
begin
if not RegQueryStringValue(HKEY_CURRENT_USER, EnvironmentKey, 'Path', Paths) then
exit;
// 确保路径前后有分号进行匹配
P := Pos(';' + Path + ';', ';' + Paths + ';');
if P = 0 then exit;
if P > 1 then P := P - 1;
Delete(Paths, P, Length(Path) + 1);
// 清理首尾可能残留的分号
while (Length(Paths) > 0) and (Paths[1] = ';') do Delete(Paths, 1, 1);
while (Length(Paths) > 0) and (Paths[Length(Paths)] = ';') do Delete(Paths, Length(Paths), 1);
// 如果 PATH 变为空字符串,则删除该值;否则写入新值
if Paths = '' then
RegDeleteValue(HKEY_CURRENT_USER, EnvironmentKey, 'Path')
else
RegWriteStringValue(HKEY_CURRENT_USER, EnvironmentKey, 'Path', Paths);
end;
// 卸载时自动清理 PATH
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
if CurUninstallStep = usUninstall then
RemovePath(ExpandConstant('{app}'));
end;
```
+32
View File
@@ -0,0 +1,32 @@
---
outline: deep
order: 3
---
# 错误提示
## 输入格式错误
| 错误信息 | 触发条件 |
|---------|----------|
| `错误:缺少子命令` | `rain key` 无参数;`rain server` 无子命令 |
| `错误: 缺少服务器 ID` | `rain server add` 后未提供 ID |
| `错误: 缺少服务器标识` | `rain server remove` 后未提供标识符 |
| `错误: 缺少服务器` | `rain start``rain stop``rain reboot``rain <服务器>` 无参数 |
## 配置相关错误
| 错误信息 | 触发条件 |
|---------|----------|
| `错误: 服务器 ID 不能为空` | `add_server` 收到空 ID |
| `错误: 服务器 ID {id} 已存在` | 添加重复 ID |
| `错误: 服务器名称 {name} 已存在` | 添加重复名称 |
| `错误: 未找到服务器 '{identifier}'` | 操作指定了不存在的服务器 |
| `错误:未配置服务器` | `rain server list``rain status` 无服务器时 |
| `错误:未设置 API Key` | 执行需要 API 的操作但未配置 key|
## 网络与 API 错误
| 错误信息 | 触发条件 |
|---------|----------|
| `错误: requests 库不存在` | 未安装 requests |
| `请求失败: {code}` | API 返回其他非 2xx 状态码 |
| `错误: 获取服务器状态失败` | `get_server_status` `display_server_status` 返回 None toggle 命令中获取状态失败 |
| `错误: 当前状态为 '{status}',无法互换(仅支持 running/stopped` | toggle 时服务器状态不是 running 或 stopped |
+15
View File
@@ -0,0 +1,15 @@
---
outline: deep
order: 5
---
# HTML版本
> 实际上,HTML版本才是Rainbox的最初版本
如果对您而言,安装软件来使用Rainbox太复杂了,您还可以使用HTML版本,您可按照以下步骤来配置:
1. 打开[Github仓库](https://github.com/gtxykn0504/rainbox),下载`rainbox.html`文件
2. 打开页面,点击系统配置,输入API密钥与服务器ID,点击保存
3. 查看并检查是否正常运行
+20
View File
@@ -0,0 +1,20 @@
---
outline: deep
order: 1
---
# 雨云的盒子
Rainbox 是一款轻量、高效的命令行工具,专为雨云RCS 云服务器产品设计,让您无需登录网页,即可在终端中快速完成服务器的日常管理操作。
1. 一键开关机 – 快速启动、停止或重启您的 RCS 实例
2. 状态监控 – 实时查看服务器运行状态、IP 地址、CPU 及内存使用率
3. 智能切换 – 输入服务器标识即可自动判断当前状态,执行开机或关机(toggle)
4. 多服务器管理 – 支持添加、删除、列表展示多个服务器,并可为每个服务器设置易记的名称
5. 交互式 Shell 双击运行 rain.exe 直接进入 rain> 提示符,支持 help 查看帮助,exit 退出,方便日常快速操作
6. 命令行兼容 – 所有功能均支持在 CMD、PowerShell 或终端中直接调用,适合集成到脚本或自动化任务中
+112
View File
@@ -0,0 +1,112 @@
---
outline: deep
order: 2
---
# 两种模式
Rainbox支持通过交互式 Shell 或者 命令行使用,但在使用前,请您先完成初始化。
## 安装
1. 下载 [Github Repo中的安装包](https://github.com/gtxykn0504/rainbox)。
2. 运行安装程序,按照提示完成安装。
3. **可选**:勾选“添加到用户环境变量 PATH”,安装完成后可在任意命令行窗口直接使用 `rain` 命令。
::: danger 重要提示
使用命令行窗口输入命令时,务必带有`rain`,而在交互模式(双击打开)无需。
:::
4. 安装完成后,可选择立即启动 Rainbox(进入交互模式)。
## 初始化
### 获取 API Key
1. 登录 [雨云控制台](https://www.rainyun.com/)。
2. 进入 **API 密钥管理** 页面,点击“创建 API Key”,复制生成的密钥。
### 设置 API Key
```cmd
(rain) key xxxxxxxxxxxxxx
```
成功后会显示 `✓ API Key 已保存`
## 添加服务器
### 获取服务器 ID
1. 登录雨云控制台,进入 **RCS 云服务器** 产品页面。
2. 每个服务器都有一个数字 ID(例如 `123456`)。
### 添加服务器
```cmd
(rain) server add 123456 my-server
```
- `123456`:服务器 ID
- `my-server`:自定义名称
### 查看已添加的服务器
```cmd
(rain) server list
```
### 删除服务器
```cmd
(rain) server remove my-server
```
可使用 ID 或名称删除。
## 常用操作
### 查看服务器状态
- **查看单个服务器**
```cmd
(rain) status my-server
```
- **查看所有已配置服务器**
```cmd
(rain) status
```
### 启动服务器
```cmd
(rain) start my-server
```
### 停止服务器
```cmd
(rain) stop my-server
```
### 重启服务器
```cmd
(rain) reboot my-server
```
### 智能切换(Toggle
根据服务器当前状态自动执行开机或关机:
- 若服务器 **运行中** → 执行关机
- 若服务器 **已停止** → 执行开机
- 其他状态(如启动中、错误等)会提示无法切换
```cmd
(rain) my-server
```
## 命令
| 输入 | 作用 |
|------|------|
| `(rain) help` | 显示帮助信息 |
| `(rain) key <KEY>` | 设置 API Key |
| `(rain) server add <ID> [名称]` | 添加服务器 |
| `(rain) server remove <服务器>` | 删除服务器 |
| `(rain) server list` | 列出所有服务器 |
| `(rain) status [服务器]` | 查看状态(未指定服务器则显示所有服务器状态) |
| `(rain) start <服务器>` | 开机 |
| `(rain) stop <服务器>` | 关机 |
| `(rain) reboot <服务器>` | 重启 |
| `<服务器>` | 智能切换(toggle |