mirror of
https://github.com/xubiaolin/docker-zerotier-planet.git
synced 2025-03-15 00:38:15 -04:00
support multi planet and dns
This commit is contained in:
parent
5c5b506075
commit
44b03d9e82
@ -1,5 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
import re
|
||||||
|
from socket import getaddrinfo
|
||||||
from re import M
|
from re import M
|
||||||
|
|
||||||
|
|
||||||
@ -13,30 +15,34 @@ def get_patch():
|
|||||||
with open("/app/patch/patch.json", "r") as f:
|
with open("/app/patch/patch.json", "r") as f:
|
||||||
return json.load(f)
|
return json.load(f)
|
||||||
|
|
||||||
|
def replace_domain(url):
|
||||||
|
domain = re.search(r'\w[\w\.-]+', url).group()
|
||||||
|
ip = getaddrinfo(domain, 80)[0][-1][0]
|
||||||
|
return url.replace(domain, ip)
|
||||||
|
|
||||||
def patch():
|
def patch():
|
||||||
moon = get_moon()
|
moons = get_moon()
|
||||||
patch = get_patch()
|
patches = get_patch()
|
||||||
|
text = ''
|
||||||
identity = moon["roots"][0]["identity"]
|
for moon, patch in zip(moons["roots"], patches):
|
||||||
moon["roots"][0]["stableEndpoints"] = patch["stableEndpoints"]
|
identity = moon["identity"]
|
||||||
|
patch["stableEndpoints"] = [replace_domain(url) for url in patch["stableEndpoints"]]
|
||||||
# 修改moon
|
moon["stableEndpoints"] = patch["stableEndpoints"]
|
||||||
with open("/var/lib/zerotier-one/moon.json", "w") as f:
|
|
||||||
f.write(json.dumps(moon,sort_keys=True, indent=2))
|
|
||||||
|
|
||||||
print("修改后的moon")
|
|
||||||
print(moon)
|
|
||||||
|
|
||||||
# 修改world
|
# 修改world
|
||||||
moon["roots"][0]["stableEndpoints"] = get_patch()["stableEndpoints"]
|
text += f"""
|
||||||
text = f"""// Los Angeles
|
|
||||||
roots.push_back(World::Root());
|
roots.push_back(World::Root());
|
||||||
roots.back().identity = Identity("{identity}");
|
roots.back().identity = Identity("{identity}");
|
||||||
"""
|
"""
|
||||||
|
|
||||||
for i in get_patch()["stableEndpoints"]:
|
for i in patch["stableEndpoints"]:
|
||||||
text += f'\n roots.back().stableEndpoints.push_back(InetAddress("{i}"));'
|
text += f'\n roots.back().stableEndpoints.push_back(InetAddress("{i}"));'
|
||||||
|
# 修改moon
|
||||||
|
with open("/var/lib/zerotier-one/moon.json", "w") as f:
|
||||||
|
f.write(json.dumps(moons,sort_keys=True, indent=2))
|
||||||
|
|
||||||
|
print("修改后的moon")
|
||||||
|
print(moons)
|
||||||
|
|
||||||
# 生成文件
|
# 生成文件
|
||||||
with open("/app/patch/mkworld.cpp", "r") as cpp:
|
with open("/app/patch/mkworld.cpp", "r") as cpp:
|
||||||
|
Loading…
Reference in New Issue
Block a user