Some fixes for maintenance mode.
This commit is contained in:
@@ -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 })
|
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)
|
zone: null # zone of your domain name (such as example.com)
|
||||||
ddnsBroadcastCode: code-here # IMPORTANT: Replace it that only you know
|
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:
|
For dns item, use this template:
|
||||||
@@ -53,8 +54,8 @@ For dns item, use this template:
|
|||||||
"name": "www.example.com", # DNS name
|
"name": "www.example.com", # DNS name
|
||||||
"proxied": false, # Enable proxy (Enable this if you want to hide your server's real IP)
|
"proxied": false, # Enable proxy (Enable this if you want to hide your server's real IP)
|
||||||
"type": "A", # or "CNAME", "AAA", "TEXT", "MX"
|
"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.
|
Remember to restart the tool after you save the config file.
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
from urllib.parse import urlparse
|
||||||
import requests
|
import requests
|
||||||
from utils.yaml import yaml_parser, yaml_writer
|
from utils.yaml import yaml_parser, yaml_writer
|
||||||
from settings import CONFIG_DIR
|
from settings import CONFIG_DIR
|
||||||
@@ -31,6 +32,7 @@ cf_config = {
|
|||||||
"allowedBroadcastServer": [
|
"allowedBroadcastServer": [
|
||||||
],
|
],
|
||||||
"ddnsBroadcastCode": "code-here",
|
"ddnsBroadcastCode": "code-here",
|
||||||
|
"maintenancePageDNS": "",
|
||||||
"maintenancePageURL": ""
|
"maintenancePageURL": ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,14 +233,14 @@ class CloudflareHelper(Helper):
|
|||||||
self.logger.error("An error occurred while getting DNS records: {}".format(e))
|
self.logger.error("An error occurred while getting DNS records: {}".format(e))
|
||||||
return
|
return
|
||||||
|
|
||||||
maintenance_url = self.config.get('maintenancePageURL')
|
maintenance_dns = self.get_maintenance_page_dns()
|
||||||
start_maintenance = False
|
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...")
|
self.logger.info("Maintenance mode is on. Redirecting support dns records to maintenance page...")
|
||||||
start_maintenance = True
|
start_maintenance = True
|
||||||
elif self.is_maintenance and not maintenance_url:
|
elif self.is_maintenance:
|
||||||
self.logger.warning("Maintenance mode is on but maintenancePageURL is not set yet. Ignoring...")
|
self.logger.warning("Maintenance mode is on but maintenancePageDNS is not set yet. Ignoring...")
|
||||||
|
|
||||||
for item in domains:
|
for item in domains:
|
||||||
domain = item.get("name", None)
|
domain = item.get("name", None)
|
||||||
@@ -269,7 +271,7 @@ class CloudflareHelper(Helper):
|
|||||||
request_data = {
|
request_data = {
|
||||||
"type": domain_type if not start_maintenance or not allow_maintenance else "CNAME",
|
"type": domain_type if not start_maintenance or not allow_maintenance else "CNAME",
|
||||||
"name": domain,
|
"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,
|
"ttl": 120,
|
||||||
"proxied": proxied
|
"proxied": proxied
|
||||||
}
|
}
|
||||||
@@ -293,6 +295,22 @@ class CloudflareHelper(Helper):
|
|||||||
self.logger.error(f"Unable to update dns record for domain name {domain}: {e}")
|
self.logger.error(f"Unable to update dns record for domain name {domain}: {e}")
|
||||||
continue
|
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):
|
def parse_allowed_broadcast_channels(self):
|
||||||
raw = self.config.get("allowedBroadcastServer", [])
|
raw = self.config.get("allowedBroadcastServer", [])
|
||||||
allowed = {}
|
allowed = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user