{"id":49915903,"url":"https://github.com/rexlevin/cb-hostsbox","last_synced_at":"2026-05-16T16:13:02.317Z","repository":{"id":334008972,"uuid":"1139585324","full_name":"rexlevin/cb-hostsbox","owner":"rexlevin","description":"Hosts management tool on Canbox | canbox上的hosts管理小工具","archived":false,"fork":false,"pushed_at":"2026-01-29T11:21:23.000Z","size":1526,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-30T01:31:48.630Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rexlevin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-22T06:33:39.000Z","updated_at":"2026-01-29T11:21:26.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/rexlevin/cb-hostsbox","commit_stats":null,"previous_names":["rexlevin/cb-hostsbox"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rexlevin/cb-hostsbox","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rexlevin%2Fcb-hostsbox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rexlevin%2Fcb-hostsbox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rexlevin%2Fcb-hostsbox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rexlevin%2Fcb-hostsbox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rexlevin","download_url":"https://codeload.github.com/rexlevin/cb-hostsbox/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rexlevin%2Fcb-hostsbox/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33109466,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T04:41:52.686Z","status":"ssl_error","status_checked_at":"2026-05-16T04:41:52.009Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-05-16T16:12:56.055Z","updated_at":"2026-05-16T16:13:02.306Z","avatar_url":"https://github.com/rexlevin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HostsBox\n\n基于 Canbox 的 hosts 文件管理工具。\n\n## 功能特性\n\n- ✅ 创建、编辑、删除 hosts 配置\n- ✅ 一键激活/失效 hosts 配置\n- ✅ 查看系统 hosts 文件内容（只读）\n- ✅ 编辑默认 hosts 配置并应用到系统\n- ✅ 语法高亮显示（CodeMirror + properties）\n- ✅ 支持多平台（Windows、macOS、Linux）\n- ✅ 权限提升和危险操作确认\n- ✅ 数据持久化存储（canbox.db）\n- ✅ 快捷键支持（Ctrl+S 保存）\n\n## 开发\n\n### 安装依赖\n\n```bash\nnpm install\n```\n\n### 启动开发服务器\n\n```bash\nnpm run dev\n```\n\n### 构建生产版本\n\n```bash\nnpm run build\n```\n\n### 预览构建结果\n\n```bash\nnpm run preview\n```\n\n## 集成到 Canbox\n\n### 作为开发应用加载（推荐用于开发测试）\n\n1. 启动 Canbox\n2. 点击 \"添加开发应用\"\n3. 选择 cb-hostsbox 的 `app.json` 文件\n4. 在应用列表中找到 HostsBox 并启动\n\n### 作为生产应用打包（推荐用于发布）\n\n#### 步骤 1: 构建前端\n\n```bash\nnpm run build\n```\n\n#### 步骤 2: 准备打包目录\n\n确保 `cb.build.json` 文件存在。\n\n#### 步骤 3: 使用 Canbox 打包工具\n\n通过 Canbox UI 将 cb-hostsbox 打包成 asar 文件。\n\n## 技术栈\n\n- **框架**: Vue 3 + Vite\n- **UI组件**: Element Plus\n- **代码高亮**: Prism.js\n- **图标**: @element-plus/icons-vue\n- **提权**: sudo-prompt（Windows: UAC, Linux: sudo, macOS: sudo）\n- **存储**: Canbox PouchDB (canbox.db)\n\n## 项目结构\n\n```\ncb-hostsbox/\n├── src/\n│   ├── App.vue                 # 主应用组件（UI层）\n│   ├── main.js                 # 入口文件\n│   ├── style.css               # 样式文件\n│   ├── composables/\n│   │   └── useHostsEntries.js  # hosts 配置管理业务逻辑\n│   └── utils/\n│       └── hostsHighlight.js   # 代码高亮工具函数\n├── public/\n│   └── logo*.png               # 图标资源\n├── types/\n│   └── canbox.d.ts             # Canbox 类型定义\n├── app.json                    # Canbox 应用配置\n├── preload.js                  # 预加载脚本（包含 hosts 操作和数据库API）\n├── cb.build.json               # 打包配置\n├── package.json\n└── vite.config.js\n```\n\n## 数据结构\n\n### Hosts Entry (存储在 canbox.db)\n\n所有 hosts 配置（包括系统默认配置和用户自定义配置）都存储在 canbox.db 的 `hosts_entry` 类型文档中。\n\n```json\n{\n  _id: string,           // 文档 ID（自动生成）\n  _rev: string,          // 版本号（CouchDB/PouchDB 自动管理）\n  type: 'hosts_entry',   // 文档类型标识，用于区分不同类型的数据\n  name: string,          // 配置名称\n  content: string,       // hosts 文件内容\n  active: boolean,       // 是否激活（true 表示应用到系统 hosts 文件）\n  createTime: number     // 创建时间戳（毫秒）\n}\n```\n\n### 配置类型\n\n#### 1. 系统默认配置（default）\n\n- **name**: 固定为 `\"default\"`\n- **content**: 系统原始 hosts 文件的完整内容\n- **active**: 始终为 `false`\n- **保存时机**：\n  - 第一次启动应用时，自动备份系统 hosts 文件并保存到数据库\n  - 后续启动时，如果数据库中已存在 `name=\"default\"` 的配置，则不再重复保存\n- **用途**：保存系统原始 hosts，方便恢复和参考\n\n#### 2. 用户自定义配置\n\n- **name**: 用户指定的配置名称，如 `\"test01\"`、`\"开发环境\"` 等\n- **content**: 用户编辑的 hosts 配置内容\n- **active**: 可切换激活状态\n- **保存时机**：\n  - 创建配置时立即保存到数据库\n  - 编辑配置内容时实时更新\n  - 激活/失效配置时更新状态\n- **用途**：用户创建的 hosts 配置，可以激活应用到系统\n\n### 数据区分方式\n\n系统 hosts 和用户配置通过以下方式区分：\n\n1. **查询方式**：使用 `selector: { type: 'hosts_entry' }` 查询所有 hosts 配置\n2. **区分字段**：通过 `name` 字段区分\n   - `name === 'default'`：默认配置（首次启动时保存的系统 hosts）\n   - 其他值：用户自定义配置\n3. **应用方式**：\n   - **系统 Hosts**：显示当前系统 hosts 文件内容 = default + 所有激活的配置（只读）\n   - **默认配置**：可编辑，保存后会将 default + 所有激活的配置合并并覆盖系统 hosts 文件\n   - **用户自定义配置**：只有 `active === true` 的配置会被合并并写入系统 hosts 文件\n\n### 界面说明\n\n#### 左侧导航栏\n\n1. **系统 Hosts**：显示当前系统 hosts 文件的实际内容（default + 所有激活的配置），只读不可编辑\n2. **默认**：显示保存的 default 配置内容，默认只读，点击\"编辑\"按钮后可编辑，保存后应用到系统\n3. **自定义配置**：用户创建的 hosts 配置列表，可激活/失效\n\n## 安全说明\n\n### 权限处理机制\n\n- **Windows**: `sudo-prompt` 通过 UAC 提示用户确认\n- **macOS/Linux**: `sudo-prompt` 使用 sudo 提示输入密码\n\n## 许可证\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frexlevin%2Fcb-hostsbox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frexlevin%2Fcb-hostsbox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frexlevin%2Fcb-hostsbox/lists"}