From ce218694408d7d563219e7b40d0f2da3768fbe47 Mon Sep 17 00:00:00 2001 From: Wei Hong Date: Fri, 29 May 2026 23:17:02 +0800 Subject: [PATCH] Some fixes for maintenance mode. --- README.md | 7 ++++--- helper.py | 28 +++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 46330f5..c095cfa 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,8 @@ doUpdate: true # set it to true to enable updater domains: [] # subdomains that you want auto-update (Example: { "name": "www.example.com", "proxied": true }) zone: null # zone of your domain name (such as example.com) ddnsBroadcastCode: code-here # IMPORTANT: Replace it that only you know -maintenancePageURL: "" # Maintenance page url (set it to an existing URL if you would use maintenance mode) +maintenancePageDNS: "" # Maintenance page DNS name, such as maintenance.example.com +maintenancePageURL: "" # Deprecated fallback. Use maintenancePageDNS instead. ``` For dns item, use this template: @@ -53,8 +54,8 @@ For dns item, use this template: "name": "www.example.com", # DNS name "proxied": false, # Enable proxy (Enable this if you want to hide your server's real IP) "type": "A", # or "CNAME", "AAA", "TEXT", "MX" - "allowMaintenance": true # Redirect to maintenancePage if maintenance mode is enabled. + "allowMaintenance": true # Redirect to maintenancePageDNS if maintenance mode is enabled. } ``` -Remember to restart the tool after you save the config file. \ No newline at end of file +Remember to restart the tool after you save the config file. diff --git a/helper.py b/helper.py index 7b5d7ae..96e04fc 100644 --- a/helper.py +++ b/helper.py @@ -4,6 +4,7 @@ import os import sys import threading import time +from urllib.parse import urlparse import requests from utils.yaml import yaml_parser, yaml_writer from settings import CONFIG_DIR @@ -31,6 +32,7 @@ cf_config = { "allowedBroadcastServer": [ ], "ddnsBroadcastCode": "code-here", + "maintenancePageDNS": "", "maintenancePageURL": "" } @@ -231,14 +233,14 @@ class CloudflareHelper(Helper): self.logger.error("An error occurred while getting DNS records: {}".format(e)) return - maintenance_url = self.config.get('maintenancePageURL') + maintenance_dns = self.get_maintenance_page_dns() start_maintenance = False - if self.is_maintenance and maintenance_url is not None: + if self.is_maintenance and maintenance_dns: self.logger.info("Maintenance mode is on. Redirecting support dns records to maintenance page...") start_maintenance = True - elif self.is_maintenance and not maintenance_url: - self.logger.warning("Maintenance mode is on but maintenancePageURL is not set yet. Ignoring...") + elif self.is_maintenance: + self.logger.warning("Maintenance mode is on but maintenancePageDNS is not set yet. Ignoring...") for item in domains: domain = item.get("name", None) @@ -269,7 +271,7 @@ class CloudflareHelper(Helper): request_data = { "type": domain_type if not start_maintenance or not allow_maintenance else "CNAME", "name": domain, - "content": self.ip if not start_maintenance or not allow_maintenance else maintenance_url, + "content": self.ip if not start_maintenance or not allow_maintenance else maintenance_dns, "ttl": 120, "proxied": proxied } @@ -293,6 +295,22 @@ class CloudflareHelper(Helper): self.logger.error(f"Unable to update dns record for domain name {domain}: {e}") continue + def get_maintenance_page_dns(self): + value = self.config.get("maintenancePageDNS") or self.config.get("maintenancePageURL") + + if value is None: + return None + + value = str(value).strip() + if value == "": + return None + + parsed = urlparse(value) + if parsed.hostname: + return parsed.hostname + + return value.rstrip("/") + def parse_allowed_broadcast_channels(self): raw = self.config.get("allowedBroadcastServer", []) allowed = {}