dnsmgr (彩虹聚合DNS管理系统)

repository·main·Indexed 23 days ago

https://github.com/netcccyun/dnsmgr

A centralized DNS management platform built on ThinkPHP for managing domain resolution across multiple cloud providers, including Alibaba Cloud, Tencent Cloud, Huawei Cloud, Baidu Cloud, Cloudflare, and others. It features automated disaster recovery based on health checks, scheduled record updates, SSL certificate management and deployment, and Cloudflare IP optimization. The system supports multi-user permissions and multi-channel notifications via Email, Telegram, and other platforms.

Tokens
9K
Snippets
5
Records
50
Agent score
80%

What's inside dnsmgr

  1. Core Features of dnsmgr

    main

    The dnsmgr system is a ThinkPHP-based platform for managing DNS records across multiple providers from a single interface.

    Key Capabilities:

    • Multi-Platform Management: Supports Alibaba Cloud, Tencent Cloud, Huawei Cloud, Baidu Cloud, Western Digital (西部数码), Volcengine (火山引擎), DNSLA, Cloudflare, Namesilo, and PowerDNS.
    • Multi-User Management: Assign specific domain resolution permissions to different users.
    • API Integration: Provides API endpoints to retrieve individual domain login links, facilitating integration with IDC systems.
    • Disaster Recovery (容灾切换): Automatically pause or modify DNS records based on ping, tcp, or http(s) health checks, with notification support.
    • Scheduled Switching: Automatically modify, enable, pause, or delete DNS records based on specific times or cycles.
    • Cloudflare Optimization: Fetches the latest Cloudflare optimized IPs and automatically updates DNS records.
    • SSL Management: Requests SSL certificates (e.g., from Let's Encrypt) and automatically deploys them to various panels, cloud providers, or servers.
    • Multi-Channel Notifications: Supports Email, WeChat Official Account, Telegram, DingTalk, Feishu, and Enterprise WeChat.
  2. Deploy dnsmgr via Self-Hosting

    main

    You can deploy dnsmgr on any environment supporting PHP and MySQL (e.g., BT Panel, Kangle).

    Requirements:

    • PHP 8.0+
    • MySQL 5.6+

    Steps:

    1. Download the installation package from the Releases page.
    2. Set the website running directory to public.
    3. Configure pseudo-static (rewrite) rules based on your web server (see Nginx/Apache sections).
    4. If using the Source code package, install dependencies via Composer:
      composer install --no-dev
    5. Access the website URL; it will automatically redirect to the installation page. Follow the prompts to complete setup.
    6. Log in to the control panel via the homepage.

    Updating: To update, simply upload and overwrite the existing files with a new installation package.

    composer install --no-dev
  3. Deploy dnsmgr using docker-compose

    main

    Use docker-compose to run dnsmgr with a dedicated MySQL container.

    1. Prepare Directories and Configuration: Create the necessary local directories:

    mkdir -p ./web
    mkdir -p ./mysql/conf
    mkdir -p ./mysql/logs
    mkdir -p ./mysql/data

    Create mysql/conf/my.cnf with the following content:

    [mysqld]
    sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

    2. Initialize Database: After running the compose file, log into the MySQL container to create the dnsmgr database:

    docker exec -it dnsmgr-mysql /bin/bash
    mysql -uroot -p123456
    create database dnsmgr;

    3. Installation: During the web installation process, when prompted for the database IP, enter dnsmgr-mysql (the service name defined in the compose file).

    docker-compose.yml:

    services:
      dnsmgr-web:
        container_name: dnsmgr-web
        stdin_open: true
        tty: true
        ports:
          - 8081:80
        volumes:
          - ./web:/app/www
        image: netcccyun/dnsmgr
        depends_on:
          - dnsmgr-mysql
        networks:
          - dnsmgr-network
    
      dnsmgr-mysql:
        container_name: dnsmgr-mysql
        restart: always
        ports:
          - 3306:3306
        volumes:
          - ./mysql/conf/my.cnf:/etc/mysql/my.cnf
          - ./mysql/logs:/logs
          - ./mysql/data:/var/lib/mysql
        environment:
          - MYSQL_ROOT_PASSWORD=123456
          - TZ=Asia/Shanghai
        image: mysql:5.7
        networks:
          - dnsmgr-network
    
    networks:
      dnsmgr-network:
        driver: bridge
    services:
      dnsmgr-web:
        container_name: dnsmgr-web
        stdin_open: true
        tty: true
        ports:
          - 8081:80
        volumes:
          - ./web:/app/www
        image: netcccyun/dnsmgr
        depends_on:
          - dnsmgr-mysql
        networks:
          - dnsmgr-network
    
      dnsmgr-mysql:
        container_name: dnsmgr-mysql
        restart: always
        ports:
          - 3306:3306
        volumes:
          - ./mysql/conf/my.cnf:/etc/mysql/my.cnf
          - ./mysql/logs:/logs
          - ./mysql/data:/var/lib/mysql
        environment:
          - MYSQL_ROOT_PASSWORD=123456
          - TZ=Asia/Shanghai
        image: mysql:5.7
        networks:
          - dnsmgr-network
    
    networks:
      dnsmgr-network:
        driver: bridge
  4. Deploy dnsmgr using Docker

    main

    Run dnsmgr as a single container. The application will listen on port 8081 by default.

    Run Command:

    docker run --name dnsmgr -dit -p 8081:80 -v /var/dnsmgr:/app/www netcccyun/dnsmgr

    Notes:

    • If the disaster recovery switching (容灾切换) does not start automatically after installation, restart the container:
      docker restart dnsmgr
    - To pull from a domestic (China) mirror:
      ```bash
    docker pull swr.cn-east-3.myhuaweicloud.com/netcccyun/dnsmgr:latest
  5. Configure connection pool settings

    main

    The connection pool behavior is governed by configuration keys. When defining your database connection configuration, you can specify:

    • pool_size: The maximum number of connections to maintain in the pool. Defaults to 32 if not specified.
    • pool_timeout: The maximum time (in seconds) to wait for a connection to become available from the pool. Defaults to 3 if not specified.
  6. Configure application settings in config/app.php

    main

    The config/app.php file defines the core behavior of the DNS Management System, including routing, timezones, and application mapping. These settings are used to control how the system handles multiple applications and domain bindings.

    Key Configuration Options

    KeyDescription
    app_hostThe application host URL (retrieved from env('app.host')).
    app_namespaceThe application namespace.
    with_routeBoolean to enable or disable routing.
    default_appThe default application to use (e.g., 'index').
    default_timezoneThe default system timezone (e.g., 'Asia/Shanghai').
    app_mapMapping for automatic multi-application mode.
    domain_bindDomain binding settings for automatic multi-application mode.
    deny_app_listA list of applications that are prohibited from URL access.
    show_error_msgBoolean to determine if error messages should be displayed.
    error_messageThe custom error message shown when an error occurs (active in non-debug mode).
    exception_tmplThe template file path used for exception pages.
    versionThe current application version.
    dbversionThe current database version.
    return [
        'app_host'         => env('app.host', ''),
        'app_namespace'    => '',
        'with_route'       => true,
        'default_app'      => 'index',
        'default_timezone' => 'Asia/Shanghai',
        'app_map'          => [],
        'domain_bind'      => [],
        'deny_app_list'    => [],
        'error_message'    => '页面错误!请稍后再试~',
        'show_error_msg'   => true,
        'version' => '1051',
        'dbversion' => '1049'
    ];
  7. Manage user password

    main

    The setpwd method allows users to update their password. This requires administrative permission.

    Request Requirements:

    • Method: POST
    • Parameters:
      • oldpwd: The current password.
      • newpwd: The new password.
      • newpwd2: The new password repeated for verification.

    Responses:

    • `{
  8. Configure Nginx and Apache rewrite rules for dnsmgr

    main

    To ensure dnsmgr (built on ThinkPHP) functions correctly, you must configure the appropriate rewrite rules for your web server.

    Nginx Configuration:

    location ~* (runtime|application)/ {
        return 403;
    }
    location / {
        if (!-e $request_filename) {
            rewrite ^(.*)$ /index.php?s=$1 last; break;
        }
    }

    Apache Configuration:

    <IfModule mod_rewrite.c>
      Options +FollowSymlinks -Multiviews
      RewriteEngine On
    
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
    </IfModule>
    location ~* (runtime|application)/ {
        return 403;
    }
    location / {
        if (!-e $request_filename) {
            rewrite ^(.*)$ /index.php?s=$1 last; break;
        }
    }
    
    <IfModule mod_rewrite.c>
      Options +FollowSymlinks -Multiviews
      RewriteEngine On
    
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
    </IfModule>
  9. Make TOS-specific requests with tos_request()

    main

    The tos_request() method is a specialized request handler designed for TOS (TOS4) services. It uses different header requirements, specifically X-Tos-Date and X-Tos-Content-Sha256 for signature verification.

    Parameters:

    • $method (string): The HTTP method (e.g., 'GET', 'POST').
    • $params (array, optional): The request parameters. If the method is not 'GET', these are JSON-encoded into the request body.
    • $query (array, optional): Query parameters to be appended to the URL.

    Returns:

    • Returns the contents of the Result key from the JSON response on success.
    • Returns true if the response is successful but contains no Result key.

    Throws:

    • Exception: Thrown on cURL errors or API error responses.
  10. Reference the DNS Management API endpoints

    main

    The system provides a dedicated API group under the /api prefix. All routes in this group are protected by the AuthApi middleware. These endpoints are intended for programmatic access to domain and record data.

    API Routes:

    • POST /api/domain/:id -> domain/domain_info (Get domain info)
    • POST /api/domain -> domain/domain_data (Submit domain data)
    • POST /api/record/data/:id -> domain/record_data (Get record data)
    • POST /api/record/add/:id -> domain/record_add (Add a record)
    • POST /api/record/update/:id -> domain/record_update (Update a record)
    • POST /api/record/delete/:id -> domain/record_delete (Delete a record)
    • POST /api/record/status/:id -> domain/record_status (Check record status)
    • POST /api/record/batch/:id -> domain/record_batch (Batch record operations)
    • POST /api/cert/order -> cert/order_info (Get certificate order info)
  11. Make requests with Ctyun::request()

    main

    Use the request() method to perform HTTP operations against the China Telecom Cloud API. The method handles canonicalization, signature generation (Eop-Authorization), and JSON encoding for request bodies.

    Parameters:

    • $method (string): The HTTP method (e.g., 'GET', 'POST').
    • $path (string): The API resource path.
    • $query (array|null): Key-value pairs for URL query parameters.
    • $params (array|null): Key-value pairs for the JSON request body.
    • $header (array|null): Additional custom HTTP headers.

    Returns:

    • Returns the contents of returnObj from the API response on success.
    • Throws an Exception if the API returns an error message or if a cURL error occurs.