| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- import json
- import threading
- import urllib.request
- import config
- from core.file_manager import load_panel_settings, load_adblock_lists, load_custom_rules
- def broadcast_to_cluster(action, domain):
- def task():
- # FIX: Το σωστό όνομα του αρχείου είναι dns_manager!
- from core import dns_manager as dns
- import urllib.request, json
-
- settings = load_panel_settings()
- nodes = settings.get('cluster_nodes', [])
-
- masters = dns.get_zone_masters_list(domain)
- if not masters:
- master_ip = settings.get('server_public_ip', '').strip()
- if master_ip: masters = [master_ip]
- for node in nodes:
- try:
- url = f"{node['url'].rstrip('/')}/api/v1/cluster/zone"
- headers = {"X-API-Key": node['api_key'], "Content-Type": "application/json"}
- payload = {"domain": domain, "masters": masters}
-
- proxy_handler = urllib.request.ProxyHandler({})
- https_handler = urllib.request.HTTPSHandler(context=config.ssl_ctx)
- opener = urllib.request.build_opener(proxy_handler, https_handler)
-
- if action == 'add_slave':
- req = urllib.request.Request(url, data=json.dumps(payload).encode('utf-8'), headers=headers, method='POST')
- elif action == 'delete_zone':
- req = urllib.request.Request(f"{url}/{domain}", headers=headers, method='DELETE')
-
- opener.open(req, timeout=10)
- print(f"Cluster Sync OK: {node['name']} ({action} {domain})")
- except Exception as e:
- print(f"Cluster Sync FAIL: {node['name']} -> {e}")
-
- import threading
- threading.Thread(target=task, daemon=True).start()
-
- import threading
- threading.Thread(target=task, daemon=True).start()
-
- import threading
- threading.Thread(target=task, daemon=True).start()
- def broadcast_adblock_to_cluster(action):
- def task():
- s = load_panel_settings()
- lists = load_adblock_lists()
- rules = load_custom_rules()
- count = s.get('adblock_domains_count', 0)
- update_time = s.get('adblock_last_update', 'Never')
-
- for node in s.get('cluster_nodes', []):
- try:
- url = f"{node['url'].rstrip('/')}/api/v1/cluster/adblock"
- headers = {"X-API-Key": node['api_key'], "Content-Type": "application/json"}
- payload = {
- "action": action,
- "lists": lists,
- "rules": rules,
- "count": count,
- "time": update_time
- }
- req = urllib.request.Request(url, data=json.dumps(payload).encode(), headers=headers, method='POST')
- urllib.request.urlopen(req, timeout=10, context=config.ssl_ctx)
- print(f"Cluster AdBlock Sync OK: {node['name']} ({action})")
- except Exception as e:
- print(f"Cluster AdBlock Sync FAIL: {node['name']} -> {e}")
- threading.Thread(target=task, daemon=True).start()
|