mirror of
https://github.com/xubiaolin/docker-zerotier-planet.git
synced 2025-01-22 12:48:14 -05:00
修复加速链接以及planet的bug
This commit is contained in:
parent
62e6164c67
commit
2c413ed4e7
54
Dockerfile
54
Dockerfile
@ -1,42 +1,12 @@
|
|||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
|
|
||||||
ADD ./server.sh /app/
|
ADD ./init.sh /app/
|
||||||
ADD ./patch /opt/patch/
|
ADD ./gen_world.sh /app/
|
||||||
|
ADD ./patch /opt/patch/
|
||||||
VOLUME ["/var/lib/zerotier-one/"]
|
|
||||||
|
VOLUME ["/var/lib/zerotier-one/"]
|
||||||
|
|
||||||
|
RUN cd /app && sh init.sh
|
||||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories &&\
|
|
||||||
apk update &&\
|
WORKDIR /app/
|
||||||
apk add git python3 nodejs npm make g++ linux-headers zerotier-one &&\
|
CMD /bin/sh -c "zerotier-one -d; cd /opt/ztncui/src;npm start"
|
||||||
npm config set registry http://registry.npm.taobao.org &&\
|
|
||||||
|
|
||||||
# 安装ztncui
|
|
||||||
cd /opt && git clone https://github.91chi.fun/https://github.com/key-networks/ztncui.git &&\
|
|
||||||
cd ztncui/src && npm install -g node-gyp && npm install &&\
|
|
||||||
cp -pv ./etc/default.passwd ./etc/passwd &&\
|
|
||||||
echo 'HTTP_PORT=3443' > .env&&\
|
|
||||||
echo 'NODE_ENV=production' >> .env &&\
|
|
||||||
echo 'HTTP_ALL_INTERFACES=true' >> .env &&\
|
|
||||||
|
|
||||||
# 添加补丁
|
|
||||||
cd /opt && \
|
|
||||||
git clone https://github.91chi.fun/https://github.com/zerotier/ZeroTierOne.git && \
|
|
||||||
|
|
||||||
cd /var/lib/zerotier-one && \
|
|
||||||
zerotier-idtool generate identity.public identity.secret &&\
|
|
||||||
zerotier-idtool initmoon identity.public >> moon.json &&\
|
|
||||||
|
|
||||||
cp /opt/patch/* . &&\
|
|
||||||
python3 patch.py &&\
|
|
||||||
zerotier-idtool genmoon moon.json &&\
|
|
||||||
mkdir moons.d && cp ./*.moon ./moons.d &&\
|
|
||||||
|
|
||||||
rm /opt/ZeroTierOne/attic/world/mkworld.cpp &&\
|
|
||||||
cp mkworld.cpp /opt/ZeroTierOne/attic/world/ &&\
|
|
||||||
cd /opt/ZeroTierOne/attic/world/ && \
|
|
||||||
sh build.sh
|
|
||||||
|
|
||||||
WORKDIR /app/
|
|
||||||
CMD ["sh","./server.sh"]
|
|
||||||
|
190
README.md
190
README.md
@ -1,97 +1,93 @@
|
|||||||
# Docker-zerotier-planet
|
# Docker-zerotier-planet
|
||||||
私有部署zeroteir-planet服务
|
私有部署 `zeroteir-planet` 服务
|
||||||
|
|
||||||
zerotier是一个非常好用的私有组网的软件,但是官方提供的服务器离我们比较远,自建planet服务器可以帮我们解决很多与网络有关的问题
|
zerotier 是一个非常好用的私有组网的软件,但是官方提供的服务器离我们比较远,自建planet服务器可以帮我们解决很多与网络有关的问题
|
||||||
|
|
||||||
|
|
||||||
# 准备条件
|
# 一:准备条件
|
||||||
- 具有公网ip的服务器(需要开放3443/tcp端口,9992/tcp端口,9992/udp端口)
|
- 具有公网ip的服务器(需要开放3443/tcp端口,9993/tcp端口,9993/udp端口)
|
||||||
- 安装docker
|
- 安装docker
|
||||||
|
|
||||||
# 开始
|
# 二:开始
|
||||||
## 1.下载项目源码
|
## 1.下载项目源码
|
||||||
```
|
```
|
||||||
git clone https://github.com.cnpmjs.org/xubiaolin/docker-zerotier-planet.git
|
git clone http://github.markxu.vip/https://github.com/xubiaolin/docker-zerotier-planet.git
|
||||||
```
|
```
|
||||||
## 2.修改项目中的patch/patch.json
|
## 2.修改配置
|
||||||
|
|
||||||
将其中的ip地址修改为你服务器的ip地址,端口保留不变即可
|
修改项目中的patch/patch.json,将其中的ip地址修改为你服务器的ip地址,端口保留不变即可
|
||||||
|
|
||||||
|
## 3.一键部署
|
||||||
## 3.在包含Dockerfile的目录下打包镜像
|
启动时会关闭9993端口的服务,请注意
|
||||||
如果您不是第一次使用该项目,您需要先执行以下命令
|
```
|
||||||
```
|
cd docker-zerotier-planet
|
||||||
rm -rf /opt/zerotier-planet
|
./deploy.sh
|
||||||
docker stop zerotier-planet
|
```
|
||||||
docker rm zerotier-planet
|
打包预计需要3-5分钟,具体需要看网络与机型
|
||||||
docker rmi zerotier-planet
|
|
||||||
```
|
|
||||||
打包镜像
|
**防火墙需要开放 `3443/tcp, 9993/tcp, 9993/udp` 这三个端口**
|
||||||
```
|
|
||||||
docker build -t zerotier-planet:latest .
|
**planet 文件在`/opt/planet`, 客户端直连时需要替换客户端的planet**
|
||||||
```
|
|
||||||
打包预计需要2-5分钟,具体需要看网络与机型
|
# 三:创建网络
|
||||||
|
访问 http://ip:3443 即可进入controller页面
|
||||||
|
|
||||||
# 启动项目
|
![ui](webui.png)
|
||||||
|
|
||||||
启动服务
|
|
||||||
```
|
使用默认账号为:`admin`
|
||||||
docker run -d --name zerotier-planet -p 3443:3443 -p 9992:9993 -p 9992:9993/udp -v /opt/zerotier-planet:/var/lib/zerotier-one --restart unless-stopped zerotier-planet:latest
|
|
||||||
```
|
默认密码为:`password`
|
||||||
|
|
||||||
|
进入后创建一个网络,可以得到一个网络ID
|
||||||
# 创建网络
|
# 四:客户端配置
|
||||||
服务器需要开放3443端口
|
首先将服务器 `/opt/zerotier-planet` 目录下的 planet 文件下载到本地以备用
|
||||||
然后访问http://ip:3443 即可进入管理后台
|
|
||||||
|
## 4.1linux 客户端配置
|
||||||
![ui](webui.png)
|
安装zerotier-one客户端
|
||||||
|
```
|
||||||
|
curl -s https://install.zerotier.com | sudo bash
|
||||||
使用默认账号为:admin
|
```
|
||||||
|
进入`/var/lib/zerotier-one`目录下,
|
||||||
默认密码为:password
|
删除目录下的planet文件,然后把从服务器下载的planet文件替换过来
|
||||||
|
|
||||||
进入后创建一个网络,可以得到一个网络ID
|
重启一下zerotier-one服务
|
||||||
通过官方的app就可以直接连接这个网络ID了,下面的步骤为可选操作。
|
debian系使用命令
|
||||||
|
```
|
||||||
# 【可选】客户端配置
|
service zerotier-one restart
|
||||||
首先将服务器/opt/zerotier-planet 目录下的planet文件下载到本地以备用
|
```
|
||||||
|
|
||||||
## linux 客户端配置
|
执行 `zerotier-cli listpeers` 可以查看 peers
|
||||||
安装zerotier-one客户端
|
|
||||||
```
|
![linux_ok](linux_planet_ok.png)
|
||||||
curl -s https://install.zerotier.com | sudo bash
|
|
||||||
```
|
如果和上图一样出现了PLANET字样,则表示成功了
|
||||||
进入/var/lib/zerotier-one目录下,
|
|
||||||
删除目录下的planet文件,然后把从服务器下载的planet文件替换过来
|
----------------------------------------
|
||||||
|
|
||||||
重启一下zerotier-one服务
|
执行`zerotier-cli join 网络ID`,可以加入到网络中,
|
||||||
debian系使用命令
|
|
||||||
```
|
成功后可以在管理后台上面看到一个新增的 members ,此时我们需要授权,否则将无法访问。
|
||||||
service zerotier-one restart
|
|
||||||
```
|
![auth](auth.png)
|
||||||
|
|
||||||
然后执行zerotier-cli join 网络ID
|
其他客户端加入也是一样要进行授权操作操作
|
||||||
|
|
||||||
成功后可以在管理后台上面看到一个新增的members,此时我们需要授权,否则将无法访问。
|
## 4.2 windows 客户端配置
|
||||||
|
windows
|
||||||
![auth](auth.png)
|
将 planet 文件覆盖粘贴到`C:\ProgramData\ZeroTier\One`中
|
||||||
|
|
||||||
其他客户端加入也是一样要进行授权操作操作
|
windows 搜索服务,并重启 zeroiter-one
|
||||||
|
|
||||||
## windows 客户端配置
|
powershell(admin)中执行`zerotier-cli listpeers`查看 planet 是否生效
|
||||||
windows
|
![win_ok](win_planet_ok.png)
|
||||||
将planet文件覆盖粘贴到C:\ProgramData\ZeroTier\One中
|
|
||||||
|
|
||||||
windows搜索服务,并重启zeroiter-one
|
## 4.3 安卓客户端配置
|
||||||
|
[Zerotier 非官方安卓客户端发布:支持自建 Moon 节点 - V2EX](https://www.v2ex.com/t/768628)
|
||||||
powershell(admin)中执行zerotier-cli listpeers查看planet是否生效
|
|
||||||
|
# 参考链接
|
||||||
## 安卓客户端配置
|
[zerotier-虚拟局域网详解](https://www.glimmer.ltd/2021/3299983056/)
|
||||||
[Zerotier 非官方安卓客户端发布:支持自建 Moon 节点 - V2EX](https://www.v2ex.com/t/768628)
|
|
||||||
|
[五分钟自建 ZeroTier 的 Planet/Controller](https://v2ex.com/t/799623)
|
||||||
# 参考链接
|
|
||||||
[zerotier-虚拟局域网详解](https://www.glimmer.ltd/2021/3299983056/)
|
|
||||||
|
|
||||||
[五分钟自建 ZeroTier 的 Planet/Controller](https://v2ex.com/t/799623)
|
|
||||||
|
17
deploy.sh
Normal file → Executable file
17
deploy.sh
Normal file → Executable file
@ -1,15 +1,26 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
imageName="zerotier-planet"
|
imageName="zerotier-planet"
|
||||||
|
|
||||||
|
docker network create zerotier
|
||||||
|
|
||||||
echo "清除原有内容"
|
echo "清除原有内容"
|
||||||
rm -rf /opt/$imageName
|
rm /opt/planet
|
||||||
docker stop $imageName
|
docker stop $imageName
|
||||||
docker rm $imageName
|
docker rm $imageName
|
||||||
docker rmi $imageName
|
docker rmi $imageName
|
||||||
|
|
||||||
|
|
||||||
echo "打包镜像"
|
echo "打包镜像"
|
||||||
docker build -t $imageName:latest .
|
docker build --network zerotier -t $imageName .
|
||||||
|
|
||||||
echo "启动服务"
|
echo "启动服务"
|
||||||
for i in $(lsof -i:9993 -t);do kill -2 $i;done
|
for i in $(lsof -i:9993 -t);do kill -2 $i;done
|
||||||
docker run -d --network host --name $imageName -p 3443:3443 -p 9993:9993 -p 9993:9993/udp -v /opt/$imageName:/var/lib/zerotier-one --restart unless-stopped $imageName:latest
|
docker run -d --network zerotier --name $imageName -p 3443:3443 -p 9993:9993 -p 9993:9993/udp --dns 223.5.5.5 --dns 223.6.6.6 --restart unless-stopped $imageName
|
||||||
|
|
||||||
|
sleep 10s
|
||||||
|
echo "生成世界"
|
||||||
|
docker exec -it $imageName sh /app/gen_world.sh
|
||||||
|
docker cp $imageName:/opt/ZeroTierOne/attic/world/world.bin /opt/planet
|
||||||
|
|
||||||
|
echo "------------------"
|
||||||
|
echo "现在已经配置好了,planet文件在/opt/planet, 客户端连接时需要替换该planet"
|
10
gen_world.sh
Normal file
10
gen_world.sh
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
cd /var/lib/zerotier-one && zerotier-idtool initmoon identity.public > moon.json
|
||||||
|
|
||||||
|
# 添加补丁
|
||||||
|
cd /opt/patch && python3 patch.py
|
||||||
|
cd /var/lib/zerotier-one && zerotier-idtool genmoon moon.json && mkdir moons.d && cp ./*.moon ./moons.d
|
||||||
|
|
||||||
|
# 生成世界
|
||||||
|
cd /opt/ZeroTierOne/attic/world/
|
||||||
|
sh build.sh
|
||||||
|
./mkworld
|
21
init.sh
Normal file
21
init.sh
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
|
||||||
|
apk update
|
||||||
|
apk add git python3 nodejs npm make g++ linux-headers zerotier-one
|
||||||
|
npm config set registry http://registry.npm.taobao.org && npm install -g node-gyp
|
||||||
|
|
||||||
|
echo "下载源码中,源码文件较大,请耐心等待;如果源码下载失败,请重新执行该脚本"
|
||||||
|
# 下载源码
|
||||||
|
cd /opt && git clone http://github.markxu.vip/https://github.com/key-networks/ztncui.git
|
||||||
|
if [ "$?"-ne 0]; then echo "下载源码出错,请重试"; exit 1; fi
|
||||||
|
|
||||||
|
cd /opt && git clone http://github.markxu.vip/https://github.com/zerotier/ZeroTierOne.git
|
||||||
|
if [ "$?"-ne 0]; then echo "下载源码出错,请重试"; exit 1; fi
|
||||||
|
|
||||||
|
# 配置ztncui
|
||||||
|
cd /opt/ztncui/src && npm install
|
||||||
|
cp -pv ./etc/default.passwd ./etc/passwd
|
||||||
|
echo 'HTTP_PORT=3443' >.env
|
||||||
|
echo 'NODE_ENV=production' >>.env
|
||||||
|
echo 'HTTP_ALL_INTERFACES=true' >>.env
|
||||||
|
|
||||||
|
|
BIN
linux_planet_ok.png
Normal file
BIN
linux_planet_ok.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
@ -1,119 +1,119 @@
|
|||||||
/*
|
/*
|
||||||
* ZeroTier One - Network Virtualization Everywhere
|
* ZeroTier One - Network Virtualization Everywhere
|
||||||
* Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/
|
* Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This utility makes the World from the configuration specified below.
|
* This utility makes the World from the configuration specified below.
|
||||||
* It probably won't be much use to anyone outside ZeroTier, Inc. except
|
* It probably won't be much use to anyone outside ZeroTier, Inc. except
|
||||||
* for testing and experimentation purposes.
|
* for testing and experimentation purposes.
|
||||||
*
|
*
|
||||||
* If you want to make your own World you must edit this file.
|
* If you want to make your own World you must edit this file.
|
||||||
*
|
*
|
||||||
* When run, it expects two files in the current directory:
|
* When run, it expects two files in the current directory:
|
||||||
*
|
*
|
||||||
* previous.c25519 - key pair to sign this world (key from previous world)
|
* previous.c25519 - key pair to sign this world (key from previous world)
|
||||||
* current.c25519 - key pair whose public key should be embedded in this world
|
* current.c25519 - key pair whose public key should be embedded in this world
|
||||||
*
|
*
|
||||||
* If these files do not exist, they are both created with the same key pair
|
* If these files do not exist, they are both created with the same key pair
|
||||||
* and a self-signed initial World is born.
|
* and a self-signed initial World is born.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include <node/Constants.hpp>
|
#include <node/Constants.hpp>
|
||||||
#include <node/World.hpp>
|
#include <node/World.hpp>
|
||||||
#include <node/C25519.hpp>
|
#include <node/C25519.hpp>
|
||||||
#include <node/Identity.hpp>
|
#include <node/Identity.hpp>
|
||||||
#include <node/InetAddress.hpp>
|
#include <node/InetAddress.hpp>
|
||||||
#include <osdep/OSUtils.hpp>
|
#include <osdep/OSUtils.hpp>
|
||||||
|
|
||||||
using namespace ZeroTier;
|
using namespace ZeroTier;
|
||||||
|
|
||||||
int main(int argc,char **argv)
|
int main(int argc,char **argv)
|
||||||
{
|
{
|
||||||
std::string previous,current;
|
std::string previous,current;
|
||||||
if ((!OSUtils::readFile("previous.c25519",previous))||(!OSUtils::readFile("current.c25519",current))) {
|
if ((!OSUtils::readFile("previous.c25519",previous))||(!OSUtils::readFile("current.c25519",current))) {
|
||||||
C25519::Pair np(C25519::generate());
|
C25519::Pair np(C25519::generate());
|
||||||
previous = std::string();
|
previous = std::string();
|
||||||
previous.append((const char *)np.pub.data,ZT_C25519_PUBLIC_KEY_LEN);
|
previous.append((const char *)np.pub.data,ZT_C25519_PUBLIC_KEY_LEN);
|
||||||
previous.append((const char *)np.priv.data,ZT_C25519_PRIVATE_KEY_LEN);
|
previous.append((const char *)np.priv.data,ZT_C25519_PRIVATE_KEY_LEN);
|
||||||
current = previous;
|
current = previous;
|
||||||
OSUtils::writeFile("previous.c25519",previous);
|
OSUtils::writeFile("previous.c25519",previous);
|
||||||
OSUtils::writeFile("current.c25519",current);
|
OSUtils::writeFile("current.c25519",current);
|
||||||
fprintf(stderr,"INFO: created initial world keys: previous.c25519 and current.c25519 (both initially the same)" ZT_EOL_S);
|
fprintf(stderr,"INFO: created initial world keys: previous.c25519 and current.c25519 (both initially the same)" ZT_EOL_S);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((previous.length() != (ZT_C25519_PUBLIC_KEY_LEN + ZT_C25519_PRIVATE_KEY_LEN))||(current.length() != (ZT_C25519_PUBLIC_KEY_LEN + ZT_C25519_PRIVATE_KEY_LEN))) {
|
if ((previous.length() != (ZT_C25519_PUBLIC_KEY_LEN + ZT_C25519_PRIVATE_KEY_LEN))||(current.length() != (ZT_C25519_PUBLIC_KEY_LEN + ZT_C25519_PRIVATE_KEY_LEN))) {
|
||||||
fprintf(stderr,"FATAL: previous.c25519 or current.c25519 empty or invalid" ZT_EOL_S);
|
fprintf(stderr,"FATAL: previous.c25519 or current.c25519 empty or invalid" ZT_EOL_S);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
C25519::Pair previousKP;
|
C25519::Pair previousKP;
|
||||||
memcpy(previousKP.pub.data,previous.data(),ZT_C25519_PUBLIC_KEY_LEN);
|
memcpy(previousKP.pub.data,previous.data(),ZT_C25519_PUBLIC_KEY_LEN);
|
||||||
memcpy(previousKP.priv.data,previous.data() + ZT_C25519_PUBLIC_KEY_LEN,ZT_C25519_PRIVATE_KEY_LEN);
|
memcpy(previousKP.priv.data,previous.data() + ZT_C25519_PUBLIC_KEY_LEN,ZT_C25519_PRIVATE_KEY_LEN);
|
||||||
C25519::Pair currentKP;
|
C25519::Pair currentKP;
|
||||||
memcpy(currentKP.pub.data,current.data(),ZT_C25519_PUBLIC_KEY_LEN);
|
memcpy(currentKP.pub.data,current.data(),ZT_C25519_PUBLIC_KEY_LEN);
|
||||||
memcpy(currentKP.priv.data,current.data() + ZT_C25519_PUBLIC_KEY_LEN,ZT_C25519_PRIVATE_KEY_LEN);
|
memcpy(currentKP.priv.data,current.data() + ZT_C25519_PUBLIC_KEY_LEN,ZT_C25519_PRIVATE_KEY_LEN);
|
||||||
|
|
||||||
// =========================================================================
|
// =========================================================================
|
||||||
// EDIT BELOW HERE
|
// EDIT BELOW HERE
|
||||||
|
|
||||||
std::vector<World::Root> roots;
|
std::vector<World::Root> roots;
|
||||||
|
|
||||||
const uint64_t id = ZT_WORLD_ID_EARTH;
|
const uint64_t id = ZT_WORLD_ID_EARTH;
|
||||||
const uint64_t ts = 1567191349589ULL; // August 30th, 2019
|
const uint64_t ts = 1567191349589ULL; // August 30th, 2019
|
||||||
|
|
||||||
//__PATCH_REPLACE__
|
//__PATCH_REPLACE__
|
||||||
|
|
||||||
// END WORLD DEFINITION
|
// END WORLD DEFINITION
|
||||||
// =========================================================================
|
// =========================================================================
|
||||||
|
|
||||||
fprintf(stderr,"INFO: generating and signing id==%llu ts==%llu" ZT_EOL_S,(unsigned long long)id,(unsigned long long)ts);
|
fprintf(stderr,"INFO: generating and signing id==%llu ts==%llu" ZT_EOL_S,(unsigned long long)id,(unsigned long long)ts);
|
||||||
|
|
||||||
World nw = World::make(World::TYPE_PLANET,id,ts,currentKP.pub,roots,previousKP);
|
World nw = World::make(World::TYPE_PLANET,id,ts,currentKP.pub,roots,previousKP);
|
||||||
|
|
||||||
Buffer<ZT_WORLD_MAX_SERIALIZED_LENGTH> outtmp;
|
Buffer<ZT_WORLD_MAX_SERIALIZED_LENGTH> outtmp;
|
||||||
nw.serialize(outtmp,false);
|
nw.serialize(outtmp,false);
|
||||||
World testw;
|
World testw;
|
||||||
testw.deserialize(outtmp,0);
|
testw.deserialize(outtmp,0);
|
||||||
if (testw != nw) {
|
if (testw != nw) {
|
||||||
fprintf(stderr,"FATAL: serialization test failed!" ZT_EOL_S);
|
fprintf(stderr,"FATAL: serialization test failed!" ZT_EOL_S);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
OSUtils::writeFile("world.bin",std::string((const char *)outtmp.data(),outtmp.size()));
|
OSUtils::writeFile("world.bin",std::string((const char *)outtmp.data(),outtmp.size()));
|
||||||
fprintf(stderr,"INFO: world.bin written with %u bytes of binary world data." ZT_EOL_S,outtmp.size());
|
fprintf(stderr,"INFO: world.bin written with %u bytes of binary world data." ZT_EOL_S,outtmp.size());
|
||||||
|
|
||||||
fprintf(stdout,ZT_EOL_S);
|
fprintf(stdout,ZT_EOL_S);
|
||||||
fprintf(stdout,"#define ZT_DEFAULT_WORLD_LENGTH %u" ZT_EOL_S,outtmp.size());
|
fprintf(stdout,"#define ZT_DEFAULT_WORLD_LENGTH %u" ZT_EOL_S,outtmp.size());
|
||||||
fprintf(stdout,"static const unsigned char ZT_DEFAULT_WORLD[ZT_DEFAULT_WORLD_LENGTH] = {");
|
fprintf(stdout,"static const unsigned char ZT_DEFAULT_WORLD[ZT_DEFAULT_WORLD_LENGTH] = {");
|
||||||
for(unsigned int i=0;i<outtmp.size();++i) {
|
for(unsigned int i=0;i<outtmp.size();++i) {
|
||||||
const unsigned char *d = (const unsigned char *)outtmp.data();
|
const unsigned char *d = (const unsigned char *)outtmp.data();
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
fprintf(stdout,",");
|
fprintf(stdout,",");
|
||||||
fprintf(stdout,"0x%.2x",(unsigned int)d[i]);
|
fprintf(stdout,"0x%.2x",(unsigned int)d[i]);
|
||||||
}
|
}
|
||||||
fprintf(stdout,"};" ZT_EOL_S);
|
fprintf(stdout,"};" ZT_EOL_S);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"stableEndpoints": [
|
"stableEndpoints": [
|
||||||
"82.157.68.236/9993"
|
"82.157.68.236/9993"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
102
patch/patch.py
102
patch/patch.py
@ -1,51 +1,51 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
from re import M
|
||||||
|
|
||||||
def patch_moon():
|
|
||||||
patch_data = dict()
|
def get_moon():
|
||||||
with open("patch.json", "r") as f:
|
with open("/var/lib/zerotier-one/moon.json", "r") as f:
|
||||||
patch_data = json.load(f)
|
moon = json.load(f)
|
||||||
|
return moon
|
||||||
moon = dict()
|
|
||||||
with open("moon.json", "r") as f:
|
|
||||||
moon = json.load(f)
|
def get_patch():
|
||||||
|
with open("/opt/patch/patch.json", "r") as f:
|
||||||
endpoint_patch = patch_data.get("stableEndpoints", [])
|
return json.load(f)
|
||||||
if len(endpoint_patch) == 0:
|
|
||||||
print("请配置endpoint!")
|
|
||||||
exit(1)
|
def patch():
|
||||||
|
moon = get_moon()
|
||||||
moon["roots"][0]["stableEndpoints"] = endpoint_patch
|
patch = get_patch()
|
||||||
|
|
||||||
with open("moon.json", "w+") as f:
|
identity = moon["roots"][0]["identity"]
|
||||||
f.write(json.dumps(moon))
|
moon["roots"][0]["stableEndpoints"] = patch["stableEndpoints"]
|
||||||
|
|
||||||
|
# 修改moon
|
||||||
def patch_world():
|
with open("/var/lib/zerotier-one/moon.json", "w") as f:
|
||||||
moon = dict()
|
f.write(json.dumps(moon,sort_keys=True, indent=2))
|
||||||
|
|
||||||
file_moon = open("moon.json", "r")
|
print("修改后的moon")
|
||||||
moon = json.load(file_moon)
|
print(moon)
|
||||||
file_moon.close()
|
|
||||||
|
# 修改world
|
||||||
middle = '''
|
moon["roots"][0]["stableEndpoints"] = get_patch()["stableEndpoints"]
|
||||||
//China
|
text = f"""// Los Angeles
|
||||||
roots.push_back(World::Root());
|
roots.push_back(World::Root());
|
||||||
roots.back().identity = Identity("{}");'''.format(moon["roots"][0]["identity"])
|
roots.back().identity = Identity("{identity}");
|
||||||
|
"""
|
||||||
for i in moon["roots"][0]["stableEndpoints"]:
|
|
||||||
middle += '\n roots.back().stableEndpoints.push_back(InetAddress("{}"));'.format(i)
|
for i in get_patch()["stableEndpoints"]:
|
||||||
|
text += f'\n roots.back().stableEndpoints.push_back(InetAddress("{i}"));'
|
||||||
with open("mkworld.cpp", "r") as cpp:
|
|
||||||
code = "".join(cpp.readlines())
|
# 生成文件
|
||||||
|
with open("/opt/patch/mkworld.cpp", "r") as cpp:
|
||||||
with open("mknewworld.cpp", "w+") as cpp:
|
world = "".join(cpp.readlines())
|
||||||
code = code.replace(" //__PATCH_REPLACE__", middle)
|
world = world.replace("//__PATCH_REPLACE__", text)
|
||||||
print(code)
|
|
||||||
cpp.write(code)
|
with open("/opt/ZeroTierOne/attic/world/mkworld.cpp", "w") as cpp:
|
||||||
|
cpp.write(world)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
patch_moon()
|
if __name__ == '__main__':
|
||||||
patch_world()
|
patch()
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
echo "开始执行"
|
|
||||||
zerotier-one -d
|
|
||||||
|
|
||||||
cd /opt/ztncui/src
|
|
||||||
npm start
|
|
BIN
win_planet_ok.png
Normal file
BIN
win_planet_ok.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 27 KiB |
Loading…
Reference in New Issue
Block a user