2022-02-20 07:25:08 -05:00
|
|
|
import os
|
|
|
|
import json
|
|
|
|
from re import M
|
|
|
|
|
|
|
|
|
|
|
|
def get_moon():
|
|
|
|
with open("/var/lib/zerotier-one/moon.json", "r") as f:
|
|
|
|
moon = json.load(f)
|
|
|
|
return moon
|
|
|
|
|
|
|
|
|
|
|
|
def get_patch():
|
2022-04-14 02:15:48 -04:00
|
|
|
with open("/app/patch/patch.json", "r") as f:
|
2022-02-20 07:25:08 -05:00
|
|
|
return json.load(f)
|
|
|
|
|
|
|
|
|
|
|
|
def patch():
|
|
|
|
moon = get_moon()
|
|
|
|
patch = get_patch()
|
|
|
|
|
|
|
|
identity = moon["roots"][0]["identity"]
|
|
|
|
moon["roots"][0]["stableEndpoints"] = patch["stableEndpoints"]
|
|
|
|
|
|
|
|
# 修改moon
|
|
|
|
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
|
|
|
|
moon["roots"][0]["stableEndpoints"] = get_patch()["stableEndpoints"]
|
|
|
|
text = f"""// Los Angeles
|
|
|
|
roots.push_back(World::Root());
|
|
|
|
roots.back().identity = Identity("{identity}");
|
|
|
|
"""
|
|
|
|
|
|
|
|
for i in get_patch()["stableEndpoints"]:
|
|
|
|
text += f'\n roots.back().stableEndpoints.push_back(InetAddress("{i}"));'
|
|
|
|
|
|
|
|
# 生成文件
|
2022-04-14 02:15:48 -04:00
|
|
|
with open("/app/patch/mkworld.cpp", "r") as cpp:
|
2022-02-20 07:25:08 -05:00
|
|
|
world = "".join(cpp.readlines())
|
|
|
|
world = world.replace("//__PATCH_REPLACE__", text)
|
|
|
|
|
|
|
|
with open("/opt/ZeroTierOne/attic/world/mkworld.cpp", "w") as cpp:
|
|
|
|
cpp.write(world)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
patch()
|