🚀 GoDNS Project Requirements (Final)

Self‑hosted authoritative DNS server + lightweight management panel · Supports multiple record types

1. Project Overview


2. Technology Stack

LayerTechnology
BackendPHP 7.4+, SQLite (WAL mode + retry mechanism to prevent locking)
FrontendPlain CSS (no frameworks), consistent layout, “back to top” button
DeploymentDebian/Ubuntu + Nginx + PHP‑FPM + SQLite3
DependenciesNo Redis, no external cron (tasks simulated via register_shutdown_function or polling)

3. User Roles & Permissions


4. Feature Modules

4.1 User Frontend

FeatureDescription
Registration / LoginSupports email verification (SMTP), invitation‑code registration (toggleable in admin panel), and password recovery via email.
Domain ManagementAdd, delete, and edit domains (supports multiple record types).
Record ManagementAdd/edit/delete DNS records for a domain. Supported types: A, AAAA, CNAME, MX, TXT, NS, SRV, CAA, SOA (editable). Fields appear dynamically based on the type (e.g., MX requires priority and target; SRV requires service, protocol, port, weight, priority, etc.). Supports pagination, fuzzy search (by domain, record type, content), and adjustable items per page.
API ManagementGenerate an API Key (one per user), set IP whitelists (only whitelisted IPs can call the API), and enforce rate limiting (globally configured by admin).
Security SettingsUsers can enable “operation confirmation code”. Sensitive actions (deleting a domain or record) will then require a confirmation code sent to their email (via SMTP).
ProfileChange email (with verification), password, and backup email.
Invitation CodesUsers can generate invitation codes (quota controlled by admin) for others to register.
AnnouncementsHomepage shows unread announcement reminders; clicking displays full details.
Abuse ReportingUsers can submit reports (domain, record, reason) for admin handling.

4.2 Administrator Backend

FeatureDescription
User ManagementView all users (pagination, search, ban/unban/delete). Promote ordinary users to administrators. Click on a user to view their domains and record lists.
Administrator ManagementAdd new administrators (directly by email) or promote existing users.
System ConfigurationGlobal parameters: primary domain, site title, window title, subtitle, homepage content (English only);
Security: IP whitelist (on/off), rate limit (requests/second);
Registration mode: open / invitation‑only / closed;
Email whitelist (restrict allowed email suffixes);
Footer, Terms of Service, Privacy Policy (support HTML);
Allowed record types (admin can enable/disable which types users may add; all enabled by default).
System EmailConfigure SMTP server (sending email, password, server, port, encryption) for verification codes, etc.
Invitation Code ManagementView all invitation codes (with usage status) and batch‑generate admin invitation codes.
Announcement ManagementPublish, edit, and delete announcements (rich‑text supported). Unread indicators shown on the frontend.
Data Backup / RestoreManual backup of SQLite database (export as .sql or .db file) and one‑click import restore (automatically rebuilds tables).
Report ManagementView all reports, mark their handling status, and optionally send email feedback to the reporter.
Admin SettingsChange the admin login second‑factor confirmation code (current preset password + fixed confirmation code; old code required for changes).
Audit LogsAll operation logs (user logins, modifications, deletions, etc.) are written to a single file (e.g., logs/godns.log). Administrators can view and search logs online.

4.3 API (for External Use)

4.4 Domain Synchronisation (Master‑Slave)


5. Database Design (SQLite)

Main Table Structures (simplified)

users        – id, email, password_hash, role (0=admin, 1=ordinary), status, api_key, api_whitelist (JSON), confirm_code_enabled, reg_ip, created_at...
domains      – id, user_id, domain_name, created_at, updated_at
records      – id, domain_id, record_type, name, ttl, content, extra(JSON)  -- dynamic fields stored in extra
invite_codes – id, code, user_id (generator), used_by, used_at, created_at, expires_at
announcements– id, title, content, is_visible, created_at
reports      – id, user_id, domain_id, record_id, reason, status, handled_by, handled_at
settings     – key, value (stores all configuration items)
logs         – id, level, user_id, ip, action, detail, created_at (may also be written directly to a file)
🔒 Lock Prevention:
  • Enable SQLite WAL mode: PRAGMA journal_mode=WAL;
  • Use transactions for write operations and implement retry logic (e.g., up to 3 attempts) to handle busy errors.

6. User Interface & Experience


7. Security & Compliance

MeasureDescription
Injection PreventionPDO prepared statements used; all user input is sanitised.
XSS / CSRFOutput escaping; CSRF tokens used in forms.
Second‑Factor Confirmation CodeAdmin login: requires preset password + a fixed confirmation code (changeable in admin settings).
User sensitive operations: if enabled, the user must enter a 6‑digit code sent to their email (valid for 5 minutes).
IP WhitelistEnforced for all API calls; can be globally toggled by admin.
Rate LimitingRequest counting per IP (stored in SQLite); returns HTTP 429 when limit is exceeded.

8. Deployment & Operations (No Control Panel, Manual Setup)

8.1 Environment Requirements

8.2 Installation Steps (Manual)

  1. Install system dependencies
    apt update && apt install -y nginx php-fpm php-sqlite3 php-json php-mbstring php-session sqlite3 git
  2. Download the project code
    cd /var/www
    git clone https://github.com/yourname/godns.git
    cd godns
  3. Set directory permissions
    chown -R www-data:www-data /var/www/godns
    chmod 755 /var/www/godns
    mkdir -p /var/www/godns/logs /var/www/godns/data
    chmod 755 /var/www/godns/logs /var/www/godns/data
  4. Configure Nginx virtual host (example – adapt to your domain)

    Create /etc/nginx/sites-available/godns.conf:

    server {
        listen 80;
        server_name your-domain.com;
        root /var/www/godns/public;
        index index.php;
    
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
    
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        }
    
        location ~ /\.ht {
            deny all;
        }
    }

    Enable the site and restart Nginx:

    ln -s /etc/nginx/sites-available/godns.conf /etc/nginx/sites-enabled/
    nginx -t && systemctl restart nginx
  5. First‑visit automatic installation
    Visit http://your-domain.com. The system detects that the database does not exist and runs the installation script:
    • Creates all tables
    • Writes default configuration (site title, primary domain, etc.)
    • Redirects to the registration page; the first registered user becomes the administrator.
  6. Optional scheduled tasks (e.g., daily backup)
    0 3 * * * /usr/bin/php /var/www/godns/cli/backup.php

8.3 Configuration Management


9. Development & Maintenance Recommendations


10. Testing & Release


11. Non‑functional Requirements


12. Future Extensions

Remarks: This document fully supports multiple record types while retaining all previous adjustments (no control panel, multiple administrators, 30‑user scope, English‑only interface, no mass email feature). The development can prioritise five common types (A, AAAA, CNAME, MX, TXT, NS) and implement the rest later.

📅 Last updated: August 2026

🚀 GoDNS 项目需求文档(最终版)

自托管权威 DNS 服务器 + 轻量管理面板 · 支持多记录类型

1. 项目概述


2. 技术栈

层级技术
后端PHP 7.4+,SQLite 数据库(WAL 模式 + 重试机制防锁)
前端纯 CSS(无框架),统一布局,含“回到顶部”按钮
部署环境Debian/Ubuntu + Nginx + PHP‑FPM + SQLite3
依赖无 Redis,无外部 cron(任务通过 register_shutdown_function 或轮询模拟)

3. 用户角色与权限


4. 功能模块

4.1 用户前台

功能说明
注册/登录支持邮箱验证(需 SMTP)、邀请码注册(后台开关)、密码找回(邮件)
域名管理增删改域名,支持多种记录类型
记录管理增删改 DNS 记录,支持 A, AAAA, CNAME, MX, TXT, NS, SRV, CAA, SOA;字段动态展示(如 MX 需优先级和目标,SRV 需服务、协议、端口等)。支持分页、模糊搜索(域名/类型/内容),可调每页条数
API 管理生成 API Key(每用户一个)、设置 IP 白名单、速率限制(全局配置)
安全设置开启“操作确认码”:敏感操作(删除域名/记录)需邮件发送的 6 位验证码
个人资料修改邮箱(需验证)、密码、备用邮箱
邀请码生成邀请码(管理员控制配额)供他人注册
公告首页显示未读提醒,点击查看完整内容
举报用户可提交举报(域名、记录、原因)供管理员处理

4.2 管理员后台

功能说明
用户管理查看所有用户(分页/搜索)、封禁/解封/删除;提升管理员;点击查看其域名和记录
管理员管理直接通过邮箱添加管理员,或提升现有用户
系统配置全局参数:主域名、站点标题、窗口标题、副标题、首页内容(仅英文);
安全:IP 白名单开关、速率限制(请求/秒);
注册模式:开放/邀请/关闭;
邮箱白名单(限制后缀);
页脚、服务条款、隐私政策(支持 HTML);
允许的记录类型(管理员可启用/禁用,默认全部开启)
系统邮件配置 SMTP 服务器(发件邮箱、密码、服务器、端口、加密方式)
邀请码管理查看所有邀请码及使用状态,批量生成管理员邀请码
公告管理发布、编辑、删除公告(支持富文本),前台显示未读标记
数据备份/恢复手动备份 SQLite 数据库(导出 .sql 或 .db),一键导入恢复(自动重建表)
举报管理查看所有举报,标记处理状态,可选择邮件反馈给举报人
管理员设置修改管理员登录二次确认码(当前预设密码 + 固定确认码,更改需旧码)
审计日志所有操作日志(登录、修改、删除等)写入 logs/godns.log,管理员可在线查看和搜索

4.3 API(供外部调用)

4.4 域名同步(主从)


5. 数据库设计(SQLite)

主要表结构(简化)

users        – id, email, password_hash, role, status, api_key, api_whitelist(JSON), confirm_code_enabled, reg_ip, created_at...
domains      – id, user_id, domain_name, created_at, updated_at
records      – id, domain_id, record_type, name, ttl, content, extra(JSON)  -- 动态字段存储在 extra
invite_codes – id, code, user_id(生成者), used_by, used_at, created_at, expires_at
announcements– id, title, content, is_visible, created_at
reports      – id, user_id, domain_id, record_id, reason, status, handled_by, handled_at
settings     – key, value (所有配置项)
logs         – id, level, user_id, ip, action, detail, created_at (也可直接写入文件)
🔒 防锁机制:
  • 启用 SQLite WAL 模式:PRAGMA journal_mode=WAL;
  • 写操作使用事务,并实现重试逻辑(最多 3 次)处理 busy 错误。

6. 用户界面与体验


7. 安全与合规

措施说明
注入防护PDO 预处理,所有输入过滤
XSS / CSRF输出转义,表单使用 CSRF Token
二次确认码管理员登录:预设密码 + 固定确认码(后台可改);
用户敏感操作:邮件发送 6 位数字码(有效期 5 分钟)
IP 白名单对所有 API 调用生效,可全局开关
速率限制按 IP 计数(存于 SQLite),超限返回 HTTP 429

8. 部署与运维(无面板,手动配置)

8.1 环境要求

8.2 安装步骤(手动)

  1. 安装依赖
    apt update && apt install -y nginx php-fpm php-sqlite3 php-json php-mbstring php-session sqlite3 git
  2. 下载代码
    cd /var/www
    git clone https://github.com/yourname/godns.git
    cd godns
  3. 设置目录权限
    chown -R www-data:www-data /var/www/godns
    chmod 755 /var/www/godns
    mkdir -p /var/www/godns/logs /var/www/godns/data
    chmod 755 /var/www/godns/logs /var/www/godns/data
  4. 配置 Nginx 虚拟主机(示例,请替换域名)

    创建 /etc/nginx/sites-available/godns.conf:

    server {
        listen 80;
        server_name your-domain.com;
        root /var/www/godns/public;
        index index.php;
    
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
    
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        }
    
        location ~ /\.ht {
            deny all;
        }
    }

    启用并重启 Nginx:

    ln -s /etc/nginx/sites-available/godns.conf /etc/nginx/sites-enabled/
    nginx -t && systemctl restart nginx
  5. 首次访问自动安装
    访问 http://your-domain.com,系统检测到数据库不存在,自动运行安装脚本:
    • 创建所有表
    • 写入默认配置(站点标题、主域名等)
    • 跳转至注册页,首位注册用户成为管理员。
  6. 可选定时任务(例如每日备份)
    0 3 * * * /usr/bin/php /var/www/godns/cli/backup.php

8.3 配置管理


9. 开发与维护建议


10. 测试与发布


11. 非功能性需求


12. 未来扩展

备注:本文档完整支持多记录类型,同时保留了所有前期调整(无面板、多管理员、30 用户规模、英文界面、无群发邮件)。开发可优先实现 A、AAAA、CNAME、MX、TXT、NS 六种常用类型,其余后续迭代。

📅 最后更新:2026 年 8 月