Переглянути джерело

【文档】更新项目文档并添加适配指南

- 新增 README.en.md 文件,提供英文版本的项目说明
- 更新 README.md 文件,增加项目依赖和适配指南等内容
- 新增设计适配文档 design-adapter.md,详细说明如何适配自定义登录页面
- 更新项目信息,包括许可证、仓库地址和关键词
- 添加 GitHub Pages 部署工作流 deploy.yaml
- 更新 Cargo.lock 和 Cargo.toml 文件,将项目版本号升至 1.1.1
PJ568 1 рік тому
батько
коміт
0179da2d0f
6 змінених файлів з 329 додано та 7 видалено
  1. 43 0
      .github/workflows/deploy.yaml
  2. 1 1
      Cargo.lock
  3. 1 1
      Cargo.toml
  4. 81 0
      README.en.md
  5. 44 5
      README.md
  6. 159 0
      doc/design-adapter.md

+ 43 - 0
.github/workflows/deploy.yaml

@@ -0,0 +1,43 @@
+name: 部署文档到 GitHub Pages
+
+on:
+  workflow_dispatch:
+  push:
+
+concurrency:
+  group: "pages"
+  cancel-in-progress: true
+
+permissions:
+  contents: read
+  pages: write
+  id-token: write
+
+jobs:
+  deployment:
+    runs-on: ubuntu-latest
+    env:
+      TZ: Asia/Shanghai
+    steps:
+
+    - name: 检出仓库
+      uses: actions/checkout@v4
+    
+    - name: 删除不需要部署的文件
+      run: |
+        rm -rf Cargo.lock
+        rm -rf .gitHub/
+    
+    - name: 部署 markdown.html
+      uses: PJ-568/[email protected]
+
+    - name: 配置 Pages
+      uses: actions/configure-pages@v4
+
+    - name: 上传 Pages Artifact
+      uses: actions/upload-pages-artifact@v3
+      with:
+        path: '.'
+
+    - name: 部署到 GitHub Pages
+      uses: actions/deploy-pages@v4

+ 1 - 1
Cargo.lock

@@ -600,7 +600,7 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
 
 [[package]]
 name = "pageos-greet"
-version = "1.1.0"
+version = "1.1.1"
 dependencies = [
  "axum",
  "clap",

+ 1 - 1
Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "pageos-greet"
-version = "1.1.0"
+version = "1.1.1"
 authors = ["PJ568 <[email protected]>"]
 edition = "2024"
 license = "MPL-2.0"

+ 81 - 0
README.en.md

@@ -0,0 +1,81 @@
+# pageos-greet
+
+> [简体中文](README.md) | English
+
+A login interface server written in Rust. Includes a minimal web server and built-in login page.
+
+This project is a subproject of [pageos](https://github.com/swaybien/pageos).
+
+Core principles:
+
+- Minimal implementation by leveraging existing software as much as possible.
+
+## Usage
+
+This project depends on [greetd](https://git.sr.ht/~kennylevinsen/greetd),
+and may require additional components like a desktop environment (e.g. [cage](https://github.com/cage-kiosk/cage))
+and browser (e.g. [Firefox](https://github.com/mozilla-firefox/firefox)) depending on your needs.
+
+Available command line arguments (excluding help):
+
+- `--port`: Listening port, defaults to 12801
+- `--page`: Path to custom login HTML file (recommended to store in `/usr/local/lib/pageos-greet/`).
+  If not specified, uses the built-in HTML from `src/server.rs` ([HTML](doc/login.html))
+- `--launch-command`: Command to run when starting pageos-greet, typically used to launch a kiosk browser to display the login page.
+  This command will be terminated when pageos-greet exits.
+- `--session-command`: Command to execute after successful login, defaults to `$SHELL` or `/usr/bin/bash`
+
+Example:
+
+```shell
+pageos-greet \
+  --port 12801 \
+  --page /path/to/login.html \
+  --launch-command "cage -s -- firefox --kiosk --no-remote http://127.0.0.1:12801" \
+  --session-command "pageos-core -p 12800 --command \"cage -s -- firefox --kiosk --no-remote http://127.0.0.1:12800\""
+```
+
+When configuring `/etc/greetd/greetd.toml`, add commands to set up a temporary Home directory to prevent Firefox startup issues:
+
+```toml
+[default_session]
+command = "bash -c 'mkdir -p /tmp/pageos-greet; export HOME=/tmp/pageos-greet; pageos-greet --launch-command \"cage -s -- firefox --kiosk --no-remote http://127.0.0.1:12801\" --session-command \"pageos-core -p 12800 --command \\"cage -s -- firefox --kiosk --no-remote http://127.0.0.1:12800\\"\"'"
+```
+
+## Contributing
+
+See [CONTRIBUTING.md](CONTRIBUTING.md) for contribution guidelines.```markdown
+
+### Adaptation
+
+_Ey bro, how do I adapt my page or Scratch to use the pageos-greet login manager?_
+
+Yes! Bro! You just need to do these two things:
+
+1. **Mode Detection**: Determine whether currently in login state.
+   Check the domain and port at the very beginning of page initialization. If matched, initialize and enter the login page.
+   For example, if your OS specifies the login page at `127.0.0.1:12801`, the condition would be:
+
+   ```javascript
+   if (
+     (window.location.hostname === "127.0.0.1" ||
+       window.location.hostname === "localhost") &&
+     window.location.port === "12801"
+   ) {
+     // Initialize login page
+   }
+   ```
+
+2. **Interface Adaptation**: Ensure your page/project contains all display (output) and input controls, and adapts to the login logic/message format.
+   Reference:
+   - [Example web page](doc/login.html)
+   - [Adapter details](doc/design-adapter.md)
+
+```
+
+## Project Info
+
+- License: MPL-2.0
+- Repository: https://github.com/swaybien/pageos-greet
+- Keywords: greetd, login, web-server, authentication
+```

+ 44 - 5
README.md

@@ -1,5 +1,7 @@
 # pageos-greet
 
+> 简体中文 | [English](README.en.md)
+
 Rust 语言编写的登录界面服务器。包含一个最小网页服务器和内置的登录页面。
 
 本项目是 [pageos](https://github.com/swaybien/pageos) 项目的一个子项目。
@@ -10,8 +12,18 @@ Rust 语言编写的登录界面服务器。包含一个最小网页服务器和
 
 ## 使用方法
 
+本项目依赖 [greetd](https://git.sr.ht/~kennylevinsen/greetd),
+根据您的需求可能还需搭配其它桌面环境(如 [cage](https://github.com/cage-kiosk/cage))和浏览器(如 [Firefox](https://github.com/mozilla-firefox/firefox))。
+
 以下是除帮助参数外可用参数:
 
+- `--port`:监听端口,默认为 12801;
+- `--page`:传入自定义登录界面 HTML 文件路径(建议存放在 `/usr/local/lib/pageos-greet/` 下),未指定时默认使用内嵌在 `src/server.rs` 中的 [HTML](doc/login.html);
+- `--launch-command`:启动 pageos-greet 时运行的命令,一般用来启动 kiosk 浏览器界面以显示登录页面,在 pageos-greet 退出一同关闭;
+- `--session-command`:用户登录成功后执行的命令,默认为 `$SHELL` 的值或 `/usr/bin/bash`;
+
+案例:
+
 ```shell
 pageos-greet \
   --port 12801 \
@@ -27,9 +39,36 @@ pageos-greet \
 command = "bash -c 'mkdir -p /tmp/pageos-greet; export HOME=/tmp/pageos-greet; pageos-greet --launch-command \"cage -s -- firefox --kiosk --no-remote http://127.0.0.1:12801\" --session-command \"pageos-core -p 12800 --command \\"cage -s -- firefox --kiosk --no-remote http://127.0.0.1:12800\\"\"'"
 ```
 
-## 指标
+## 贡献
+
+详见 [CONTRIBUTING.md](CONTRIBUTING.md)。
+
+### 适配
+
+_不是哥们,那我要怎么适配我的页面或 Scratch 以使用 pageos-greet 这个登录管理器?_
+
+是!哥们!您只需要做到以下两点:
+
+1. 模式判断:判断当前是否处于登录状态;
+
+   在页面初始化最开始检查域名和端口号,如果匹配则初始化进入登录页面。
+   假如您的操作系统规定登录页面在 127.0.0.1:12801,则判断条件为:
+
+   ```javascript
+   if (
+     (window.location.hostname === "127.0.0.1" ||
+       window.location.hostname === "localhost") &&
+     window.location.port === "12801"
+   ) {
+     // 初始化登录页面
+   }
+   ```
+2. 接口适配:保证您的页面或项目中包含所有的显示(输出)和输入控件并适配了登录逻辑和消息格式;
+
+   可参考[示例网页](doc/login.html)和[适配详解](doc/design-adapter.md)
+
+## 项目信息
 
-- 登录界面:
-  - 显示管理器采用 `greetd`;
-  - 默认的 HTML 登录页面内置在主程序 `pageos-greet` 中;
-  - 如果需要自定义登录界面,则使用参数传入自定义 HTML;
+- 许可:MPL-2.0
+- 仓库:https://github.com/swaybien/pageos-greet
+- 关键词:greetd, login, web-server, authentication

+ 159 - 0
doc/design-adapter.md

@@ -0,0 +1,159 @@
+# PageOS-Greet 适配器设计文档
+
+## 1. 概述
+
+PageOS-Greet 是一个基于 Web 的登录管理器,使用 WebSocket 协议与后端通信。本文档详细说明如何适配自定义登录页面或 Scratch 项目以兼容 PageOS-Greet 系统。
+
+## 2. 登录流程
+
+```mermaid
+stateDiagram-v2
+    [*] --> 连接建立
+    连接建立 --> 用户名输入: WebSocket 连接成功
+    用户名输入 --> 认证请求: 提交用户名
+    认证请求 --> 认证提示: 收到 AUTH_PROMPT
+    认证提示 --> 认证响应: 用户输入
+    认证响应 --> 认证成功: 收到 AUTH_SUCCESS
+    认证响应 --> 认证失败: 收到 AUTH_ERROR
+    认证成功 --> 会话启动: 发送 START_SESSION
+    认证失败 --> 用户名输入: 重置表单
+    会话启动 --> [*]: 会话结束
+```
+
+## 3. 适配要求
+
+### 3.1 模式判断
+
+在页面初始化时需判断当前是否处于登录模式:
+
+```javascript
+if (
+  (window.location.hostname === "127.0.0.1" ||
+    window.location.hostname === "localhost") &&
+  window.location.port === "12801"
+) {
+  // 进入登录模式
+}
+```
+
+### 3.2 接口适配
+
+必须实现以下核心功能组件:
+
+- 用户名输入框
+- 密码输入框(当需要时。也可与用户名输入框共用)
+- 状态显示区域
+- 错误提示区域
+- 高级选项区域(可选)
+
+## 4. WebSocket 通信协议
+
+### 4.1 连接建立
+
+```javascript
+const ws = new WebSocket(`ws://${window.location.host}/ws`);
+```
+
+### 4.2 消息类型
+
+#### 客户端发送消息:
+
+1. 认证请求
+
+```json
+{
+  "type": "AUTH_REQUEST",
+  "username": "用户名"
+}
+```
+
+2. 认证响应
+
+```json
+{
+  "type": "AUTH_RESPONSE",
+  "response": "用户输入"
+}
+```
+
+#### 服务端发送消息:
+
+1. 认证提示
+
+```json
+{
+  "type": "AUTH_PROMPT",
+  "message_type": "SECRET|VISIBLE|INFO|ERROR",
+  "message": "提示信息"
+}
+```
+
+2. 认证成功
+
+```json
+{
+  "type": "AUTH_SUCCESS"
+}
+```
+
+3. 认证失败
+
+```json
+{
+  "type": "AUTH_ERROR",
+  "reason": "错误原因"
+}
+```
+
+## 5. 界面要求
+
+### 5.1 基本元素
+
+- 包含 `.auth-container` 容器
+- 包含 `.loading` 加载状态显示
+- 包含 `.interface` 交互区域
+- 包含 `.log` 日志区域(可选但推荐)
+
+### 5.2 状态管理
+
+需实现以下状态函数:
+
+```javascript
+function showLoading(message) {}
+function hideLoading() {}
+function logMessage(msg, type) {}
+function addPrompt(text, type) {}
+function clearPrompt() {}
+```
+
+## 6. 会话启动参数
+
+需提供以下输入项:
+
+```html
+<input id="session-env" type="text" placeholder="环境变量" />
+<input
+  id="session-cmd"
+  type="text"
+  placeholder="启动命令"
+  value="%SESSION_COMMAND%"
+/>
+```
+
+> `%SESSION_COMMAND%` 会在页面加载时被 pageos-greet 替换为实际启动命令。
+
+## 7. 完整适配示例
+
+参考 [login.html](login.html) 实现完整的登录流程处理,包括:
+
+1. WebSocket 连接管理
+2. 认证状态机处理
+3. 错误处理和日志记录
+4. 会话启动参数处理
+
+## 8. 测试建议
+
+1. 使用不同用户名和密码组合测试
+2. 测试网络中断后的恢复能力
+3. 验证会话启动参数的正确传递
+4. 检查错误消息的显示效果