Skip to content

supports multi-planet and dns resolving #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/re
&& apk update\
&& mkdir -p /usr/include/nlohmann/ && cd /usr/include/nlohmann/ && wget https://ghself.markxu.online/https://github.com/nlohmann/json/releases/download/v3.10.5/json.hpp \
&& apk add --no-cache git python3 npm make g++ zerotier-one linux-headers\
&& mkdir /app -p && cd /app && git clone --progress https://ghself.markxu.online/https://github.com/key-networks/ztncui.git\
&& mkdir /app /var/lib -p && cd /app && git clone --progress https://ghself.markxu.online/https://github.com/key-networks/ztncui.git\
&& cd /app/ztncui/src \
&& cp /app/patch/binding.gyp .\
&& echo "开始配置npm环境"\
Expand All @@ -22,13 +22,17 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/re
&& echo 'HTTP_ALL_INTERFACES=true' >>.env \
&& echo "ZT_ADDR=localhost:${ZT_PORT}" >>.env\
&& echo "${ZT_PORT}" >/app/zerotier-one.port \
&& cp -v etc/default.passwd etc/passwd
&& cp -v etc/default.passwd etc/passwd

#ADD ./pztier/zerotier-one* /var/lib/
RUN cp -r /app/pztier/zerotier-one /var/lib/ || true

#RUN ls -al /var/lib/ /var/lib/zerotier-one/ |grep -v zerotier && sleep 20
RUN cd /app && git clone --progress https://ghself.markxu.online/https://github.com/zerotier/ZeroTierOne.git --depth 1\
&& zerotier-one -d && sleep 5s && ps -ef |grep zerotier-one |grep -v grep |awk '{print $1}' |xargs kill -9 \
&& cd /var/lib/zerotier-one && zerotier-idtool initmoon identity.public >moon.json\
&& cd /var/lib/zerotier-one && ( [ -f ./moon.json ] || zerotier-idtool initmoon identity.public >moon.json ) \
&& cd /app/patch && python3 patch.py \
&& cd /var/lib/zerotier-one && zerotier-idtool genmoon moon.json && mkdir moons.d && cp ./*.moon ./moons.d \
&& cd /var/lib/zerotier-one && zerotier-idtool genmoon moon.json && mkdir -p moons.d && cp ./*.moon ./moons.d \
&& cd /app/ZeroTierOne/attic/world/ && sh build.sh \
&& sleep 5s \
&& cd /app/ZeroTierOne/attic/world/ && ./mkworld \
Expand Down
10 changes: 7 additions & 3 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ function install() {
if [[ -n "$ipv6" ]]; then
ipv6_entry="${ipv6}/${port}"
endpoints="[\"$ipv4_entry\",\"$ipv6_entry\"]"
else
echo "[{\"stableEndpoints\":$endpoints}]" > ./patch/patch.json
elif [[ -n "$ipv4" ]]; then
endpoints="[\"$ipv4_entry\"]"
echo "[{\"stableEndpoints\":$endpoints}]" > ./patch/patch.json
fi
echo "{\"stableEndpoints\":$endpoints}" > ./patch/patch.json

echo "配置内容为:"
echo "`cat ./patch/patch.json`"
Expand Down Expand Up @@ -92,17 +93,20 @@ case "$choice" in
1)
echo "您选择了安装功能"
install
docker cp zerotier-planet:/var/lib/zerotier-one/ ./pztier/
;;
2)
echo "您选择了更新功能"
[ -f ./pztier/zerotier-one/moon.json ] && docker cp ./pztier/zerotier-one/moon.json zerotier-planet:/var/lib/zerotier-one/moon.json
[ -f ./pztier/zerotier-one/planet ] && docker cp ./pztier/zerotier-one/planet zerotier-planet:/var/lib/zerotier-one/planet
upgrade
;;
3)
echo "导出planet到当前目录"
docker cp zerotier-planet:/app/bin/planet .
;;
*)
echo "谢谢使用!"
echo "多planet:各planet执行完1之后,将各planet的stableendpoint合并到moon.json中,编辑好patch.json,planet0上重新执行1,将moon.json planet放到其他各planet中,重新执行2.谢谢使用!"
exit 0
;;
esac
2 changes: 1 addition & 1 deletion patch/patch.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"stableEndpoints":["175.29.122.43/9994"]}
[{"stableEndpoints":["175.29.122.43/9994"]},{"stableEndpoints":["t0.x.top/9994"]},{"stableEndpoints":["t1.x.top/9994"]}]
42 changes: 24 additions & 18 deletions patch/patch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import json
import re
from socket import getaddrinfo
from re import M


Expand All @@ -13,30 +15,34 @@ def get_patch():
with open("/app/patch/patch.json", "r") as 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():
moon = get_moon()
patch = get_patch()

identity = moon["roots"][0]["identity"]
moon["roots"][0]["stableEndpoints"] = patch["stableEndpoints"]

moons = get_moon()
patches = get_patch()
text = ''
for moon, patch in zip(moons["roots"], patches):
identity = moon["identity"]
patch["stableEndpoints"] = [replace_domain(url) for url in patch["stableEndpoints"]]
moon["stableEndpoints"] = patch["stableEndpoints"]

# 修改world
text += f"""
roots.push_back(World::Root());
roots.back().identity = Identity("{identity}");
"""

for i in patch["stableEndpoints"]:
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(moon,sort_keys=True, indent=2))
f.write(json.dumps(moons,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}"));'
print(moons)

# 生成文件
with open("/app/patch/mkworld.cpp", "r") as cpp:
Expand Down