From 7afe3809b921544793ea90cdef5238334d9cbb83 Mon Sep 17 00:00:00 2001 From: chenxudong2020 <872603935@qq.com> Date: Sun, 13 Oct 2024 07:38:34 +0800 Subject: [PATCH] aa --- .github/workflows/image-build.yml | 11 +- README.md | 8 +- build.sh | 6 +- copy.sh | 5 + deploy.sh | 2 +- patch/entrypoint.sh | 125 ---------------- patch/http_server.js | 71 --------- patch/mkworld_custom.cpp | 232 ------------------------------ zh.sh | 2 +- 9 files changed, 20 insertions(+), 442 deletions(-) create mode 100644 copy.sh delete mode 100755 patch/entrypoint.sh delete mode 100644 patch/http_server.js delete mode 100644 patch/mkworld_custom.cpp diff --git a/.github/workflows/image-build.yml b/.github/workflows/image-build.yml index 1577c92..57729fd 100644 --- a/.github/workflows/image-build.yml +++ b/.github/workflows/image-build.yml @@ -13,7 +13,16 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 + with: + repository: ${{secrets.REPOSITORY}} + submodules: true + show-progress: true + + - name: Modify + run : | + sh copy.sh + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 diff --git a/README.md b/README.md index dab3f11..a921969 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,5 @@ -TG交流群:https://t.me/+JduuWfhSEPdlNDk1 - -- QQ交流群1群(已满):692635772 -- QQ交流群2群(已满):785620313 -- QQ交流群3群:316239544 - **Feature:** -1. 支持Linux/AMD64、支持Linux/ARM64 +1. 支持Linux/AMD64 Linux/ARM64 2. docker 容器化部署 3. 支持URL下载planet、Moon配置 diff --git a/build.sh b/build.sh index 2346d14..d06b0f1 100755 --- a/build.sh +++ b/build.sh @@ -1,9 +1,7 @@ #!/bin/bash -USER=zerotier -REPO=ZeroTierOne -DOCKER_IMAGE="xubiaolin/zerotier-planet" +DOCKER_IMAGE="registry.cn-hangzhou.aliyuncs.com/dubux/zerotier-planet" -docker buildx build --platform linux/amd64 -t "$DOCKER_IMAGE":latest . +docker buildx build --platform linux/arm64,linux/amd64 -t "$DOCKER_IMAGE":latest --push . diff --git a/copy.sh b/copy.sh new file mode 100644 index 0000000..aa6587b --- /dev/null +++ b/copy.sh @@ -0,0 +1,5 @@ +#!/bin/sh +\cp -rf ./zh.sh ./docker-zerotier-planet/ +\cp -rf ./deploy.sh ./docker-zerotier-planet/ +\cp -rf ./Dockerfile ./docker-zerotier-planet/ +\cp -rf ./build.sh ./docker-zerotier-planet/ \ No newline at end of file diff --git a/deploy.sh b/deploy.sh index e841a4a..17e7536 100755 --- a/deploy.sh +++ b/deploy.sh @@ -5,7 +5,7 @@ ZEROTIER_PATH="$(pwd)/data/zerotier" CONFIG_PATH="${ZEROTIER_PATH}/config" DIST_PATH="${ZEROTIER_PATH}/dist" ZTNCUI_PATH="${ZEROTIER_PATH}/ztncui" -DOCKER_IMAGE="xubiaolin/zerotier-planet:latest" +DOCKER_IMAGE="registry.cn-hangzhou.aliyuncs.com/dubux/zerotier-planet:latest" print_message() { local message=$1 diff --git a/patch/entrypoint.sh b/patch/entrypoint.sh deleted file mode 100755 index 55b2b2b..0000000 --- a/patch/entrypoint.sh +++ /dev/null @@ -1,125 +0,0 @@ -#!/bin/sh - -set -x - -# 配置路径和端口 -ZEROTIER_PATH="/var/lib/zerotier-one" -APP_PATH="/app" -CONFIG_PATH="${APP_PATH}/config" -BACKUP_PATH="/bak" -ZTNCUI_PATH="${APP_PATH}/ztncui" -ZTNCUI_SRC_PATH="${ZTNCUI_PATH}/src" - -# 启动 ZeroTier 和 ztncui -function start() { - echo "Start ztncui and zerotier" - cd $ZEROTIER_PATH && ./zerotier-one -p$(cat ${CONFIG_PATH}/zerotier-one.port) -d || exit 1 - nohup node ${APP_PATH}/http_server.js &> ${APP_PATH}/server.log & - cd $ZTNCUI_SRC_PATH && npm start || exit 1 -} - -# 检查文件服务器端口配置文件 -function check_file_server() { - if [ ! -f "${CONFIG_PATH}/file_server.port" ]; then - echo "file_server.port does not exist, generating it" - echo "${FILE_SERVER_PORT}" > ${CONFIG_PATH}/file_server.port - else - echo "file_server.port exists, reading it" - FILE_SERVER_PORT=$(cat ${CONFIG_PATH}/file_server.port) - fi - echo "${FILE_SERVER_PORT}" -} - -# 初始化 ZeroTier 数据 -function init_zerotier_data() { - echo "Initializing ZeroTier data" - echo "${ZT_PORT}" > ${CONFIG_PATH}/zerotier-one.port - cp -r ${BACKUP_PATH}/zerotier-one/* $ZEROTIER_PATH - - cd $ZEROTIER_PATH - openssl rand -hex 16 > authtoken.secret - ./zerotier-idtool generate identity.secret identity.public - ./zerotier-idtool initmoon identity.public > moon.json - - IP_ADDR4=${IP_ADDR4:-$(curl -s https://ipv4.icanhazip.com/)} - IP_ADDR6=${IP_ADDR6:-$(curl -s https://ipv6.icanhazip.com/)} - - echo "IP_ADDR4=$IP_ADDR4" - echo "IP_ADDR6=$IP_ADDR6" - ZT_PORT=$(cat ${CONFIG_PATH}/zerotier-one.port) - echo "ZT_PORT=$ZT_PORT" - - if [ -n "$IP_ADDR4" ] && [ -n "$IP_ADDR6" ]; then - stableEndpoints="[\"$IP_ADDR4/${ZT_PORT}\",\"$IP_ADDR6/${ZT_PORT}\"]" - elif [ -n "$IP_ADDR4" ]; then - stableEndpoints="[\"$IP_ADDR4/${ZT_PORT}\"]" - elif [ -n "$IP_ADDR6" ]; then - stableEndpoints="[\"$IP_ADDR6/${ZT_PORT}\"]" - else - echo "IP_ADDR4 and IP_ADDR6 are both empty!" - exit 1 - fi - - echo "$IP_ADDR4" > ${CONFIG_PATH}/ip_addr4 - echo "$IP_ADDR6" > ${CONFIG_PATH}/ip_addr6 - echo "stableEndpoints=$stableEndpoints" - - jq --argjson newEndpoints "$stableEndpoints" '.roots[0].stableEndpoints = $newEndpoints' moon.json > temp.json && mv temp.json moon.json - ./zerotier-idtool genmoon moon.json && mkdir -p moons.d && cp ./*.moon ./moons.d - - ./mkworld - if [ $? -ne 0 ]; then - echo "mkmoonworld failed!" - exit 1 - fi - - mkdir -p ${APP_PATH}/dist/ - mv world.bin ${APP_PATH}/dist/planet - cp *.moon ${APP_PATH}/dist/ - echo "mkmoonworld success!" -} - -# 检查并初始化 ZeroTier -function check_zerotier() { - mkdir -p $ZEROTIER_PATH - if [ "$(ls -A $ZEROTIER_PATH)" ]; then - echo "$ZEROTIER_PATH is not empty, starting directly" - else - init_zerotier_data - fi -} - -# 初始化 ztncui 数据 -function init_ztncui_data() { - echo "Initializing ztncui data" - cp -r ${BACKUP_PATH}/ztncui/* $ZTNCUI_PATH - - echo "Configuring ztncui" - mkdir -p ${CONFIG_PATH} - echo "${API_PORT}" > ${CONFIG_PATH}/ztncui.port - cd $ZTNCUI_SRC_PATH - echo "HTTP_PORT=${API_PORT}" > .env - echo 'NODE_ENV=production' >> .env - echo 'HTTP_ALL_INTERFACES=true' >> .env - echo "ZT_ADDR=localhost:${ZT_PORT}" >> .env - cp -v etc/default.passwd etc/passwd - TOKEN=$(cat ${ZEROTIER_PATH}/authtoken.secret) - echo "ZT_TOKEN=$TOKEN" >> .env - echo "ztncui configuration successful!" -} - -# 检查并初始化 ztncui -function check_ztncui() { - mkdir -p $ZTNCUI_PATH - if [ "$(ls -A $ZTNCUI_PATH)" ]; then - echo "${API_PORT}" > ${CONFIG_PATH}/ztncui.port - echo "$ZTNCUI_PATH is not empty, starting directly" - else - init_ztncui_data - fi -} - -check_file_server -check_zerotier -check_ztncui -start diff --git a/patch/http_server.js b/patch/http_server.js deleted file mode 100644 index 3a994db..0000000 --- a/patch/http_server.js +++ /dev/null @@ -1,71 +0,0 @@ -const http = require('http'); -const fs = require('fs'); -const path = require('path'); -const url = require('url'); -const crypto = require('crypto'); -const port = process.env.FILE_SERVER_PORT; - -const SECRET_KEY = process.env.SECRET_KEY || crypto.randomBytes(8).toString('hex'); -const APP_PATH='/app' -const DIST_PATH = '/app/dist' - -// write to file -const secretKeyPath = '/app/config/file_server.key'; -fs.writeFile(secretKeyPath, SECRET_KEY, (err) => { - if (err) { - console.error('Error writing SECRET_KEY to file:', err); - } else { - console.log(`SECRET_KEY written to ${secretKeyPath}`); - } -}); - -const server = http.createServer((req, res) => { - const parsedUrl = url.parse(req.url, true); - - // check key - const key = parsedUrl.query.key; - if (!key || key !== SECRET_KEY) { - res.writeHead(401, { 'Content-Type': 'text/plain' }); - return res.end('Unauthorized'); - } - - let filePath = path.join(DIST_PATH, parsedUrl.pathname); - let extname = String(path.extname(filePath)).toLowerCase(); - let mimeTypes = { - '.html': 'text/html', - '.js': 'text/javascript', - '.css': 'text/css', - '.json': 'application/json', - '.png': 'image/png', - '.jpg': 'image/jpg', - '.gif': 'image/gif', - '.svg': 'image/svg+xml', - '.wav': 'audio/wav', - '.mp4': 'video/mp4', - '.woff': 'application/font-woff', - '.ttf': 'application/font-ttf', - '.eot': 'application/vnd.ms-fontobject', - '.otf': 'application/font-otf', - '.wasm': 'application/wasm' - }; - let contentType = mimeTypes[extname] || 'application/octet-stream'; - - fs.readFile(filePath, (err, content) => { - if (err) { - if (err.code == 'ENOENT') { - res.writeHead(404, { 'Content-Type': 'text/html' }); - res.end("404 - File Not Found"); - } else { - res.writeHead(500); - res.end(`Server Error: ${err.code}`); - } - } else { - res.writeHead(200, { 'Content-Type': contentType }); - res.end(content, 'utf-8'); - } - }); -}); - -server.listen(port, () => { - console.log(`Server running at http://localhost:${port}/`); -}); diff --git a/patch/mkworld_custom.cpp b/patch/mkworld_custom.cpp deleted file mode 100644 index 16830e8..0000000 --- a/patch/mkworld_custom.cpp +++ /dev/null @@ -1,232 +0,0 @@ -/* - * ZeroTier One - Network Virtualization Everywhere - * Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/ - * - * 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - /* - * This utility makes the World from the configuration specified below. - * It probably won't be much use to anyone outside ZeroTier, Inc. except - * for testing and experimentation purposes. - * - * If you want to make your own World you must edit this file. - * - * When run, it expects two files in the current directory: - * - * 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 - * - * If these files do not exist, they are both created with the same key pair - * and a self-signed initial World is born. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -using namespace ZeroTier; -using json = nlohmann::json; - -void printHelp() { - printf("Usage: mkworld [options]\n"); - printf("Options:\n"); - printf(" -h, --help Display this help message\n"); - printf(" -j, --json2bin Convert from JSON file to world.bin\n"); - printf(" -b, --bin2json Convert from world.bin to JSON format\n"); -} - -int jsonToBinary() { - std::string previous, current; - if ((!OSUtils::readFile("previous.c25519", previous)) || (!OSUtils::readFile("current.c25519", current))) { - C25519::Pair np(C25519::generate()); - previous = std::string(); - previous.append((const char*)np.pub.data, ZT_C25519_PUBLIC_KEY_LEN); - previous.append((const char*)np.priv.data, ZT_C25519_PRIVATE_KEY_LEN); - current = previous; - OSUtils::writeFile("previous.c25519", previous); - OSUtils::writeFile("current.c25519", current); - 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))) { - fprintf(stderr, "FATAL: previous.c25519 or current.c25519 empty or invalid" ZT_EOL_S); - return 1; - } - C25519::Pair previousKP; - 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); - C25519::Pair currentKP; - 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); - - // ========================================================================= - // EDIT BELOW HERE - - std::vector roots; - - const uint64_t id = ZT_WORLD_ID_EARTH; - const uint64_t ts = 1567191349589ULL; // August 30th, 2019 - - std::string fileContent; - if (!OSUtils::readFile("moon.json", fileContent)) { - fprintf(stderr, "Failed to open config file." ZT_EOL_S); - return 1; - } - - // 解析JSON数据 - json config = json::parse(fileContent); - - - for (auto& root : config["roots"]) { - roots.push_back(World::Root()); - roots.back().identity = Identity(root["identity"].get().c_str()); - for (auto& endpoint : root["stableEndpoints"]) { - roots.back().stableEndpoints.push_back(InetAddress(endpoint.get().c_str())); - } - } - - 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); - - Buffer outtmp; - nw.serialize(outtmp, false); - World testw; - testw.deserialize(outtmp, 0); - if (testw != nw) { - fprintf(stderr, "FATAL: serialization test failed!" ZT_EOL_S); - return 1; - } - - 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(stdout, ZT_EOL_S); - 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] = {"); - for (unsigned int i = 0; i < outtmp.size(); ++i) { - const unsigned char* d = (const unsigned char*)outtmp.data(); - if (i > 0) - fprintf(stdout, ","); - fprintf(stdout, "0x%.2x", (unsigned int)d[i]); - } - fprintf(stdout, "};" ZT_EOL_S); - return 0; -} - -void binaryToJson() { - // Read world.bin file into memory - std::string binContent; - if (!OSUtils::readFile("world.bin", binContent)) { - fprintf(stderr, "Failed to open world.bin file." ZT_EOL_S); - return; - } - - // Deserialize the binary data into a World object - Buffer binBuffer(binContent.data(), binContent.size()); - World world; - if (!world.deserialize(binBuffer, 0)) { - fprintf(stderr, "Failed to deserialize world.bin content." ZT_EOL_S); - return; - } - - // Create a JSON object to store the world data - json worldJson; - - - // Add roots array to the JSON object - json rootsJson; - for (const auto& root : world.roots()) { - json rootJson; - - // Add identity to the root JSON object - char identityStr[ZT_IDENTITY_STRING_BUFFER_LENGTH]; - root.identity.toString(true, identityStr); // Include private key - rootJson["identity"] = identityStr; - - // Add stableEndpoints array to the root JSON object - json stableEndpointsJson; - for (const auto& endpoint : root.stableEndpoints) { - char ipStr[64]; - endpoint.toString(ipStr); - stableEndpointsJson.push_back(ipStr); - } - rootJson["stableEndpoints"] = stableEndpointsJson; - - rootsJson.push_back(rootJson); - } - worldJson["roots"] = rootsJson; - std::string jsonStr = worldJson.dump(4); - printf("World JSON:\n%s\n", jsonStr.c_str()); - if (!OSUtils::writeFile("config.json", jsonStr.c_str(), jsonStr.size())) { - fprintf(stderr, "Failed to write JSON data to config.json." ZT_EOL_S); - } - else { - printf("JSON data successfully written to config.json." ZT_EOL_S); - } -} - - -int main(int argc, char** argv) -{ - bool json2bin = false; - bool bin2json = false; - - for (int i = 1; i < argc; ++i) { - std::string arg = argv[i]; - if (arg == "-h" || arg == "--help") { - printHelp(); - return 0; - } - else if (arg == "-j" || arg == "--json2bin") { - json2bin = true; - } - else if (arg == "-b" || arg == "--bin2json") { - bin2json = true; - } - } - - if (!(json2bin || bin2json)) { - // Default behavior: convert from JSON to world.bin - json2bin = true; - } - - if (json2bin && bin2json) { - printf("Error: Cannot specify both JSON to binary and binary to JSON conversion options.\n"); - printHelp(); - return 1; - } - - if (json2bin) { - jsonToBinary(); - } - else if (bin2json) { - binaryToJson(); - } - - return 0; -} diff --git a/zh.sh b/zh.sh index 7a565b3..1d9f90b 100644 --- a/zh.sh +++ b/zh.sh @@ -117,7 +117,7 @@ sed -i "s|) Cancel|) 取消|g" ztncui/src/views/dns.pug sed -i "s|network controller UI|网络控制器用户界面|g" ztncui/src/views/front_door.pug sed -i "s|Logout|注销|g" ztncui/src/views/head_layout.pug -sed -i "s|network controller UI by|网络控制器用户界面汉化作者|g" ztncui/src/views/index.pug +sed -i "s|network controller UI by|网络控制器用户界面汉化|g" ztncui/src/views/index.pug sed -i "s|a(href='https://key-networks.com' target='_blank') Key Networks|a(href='https://github.com/chenxudong2020/docker-zerotier-planet' target='_blank') |g" ztncui/src/views/index.pug sed -i "s|This network controller has a ZeroTier address of|该控制器的ZeroTier地址为|g" ztncui/src/views/index.pug sed -i "s|ZeroTier version|ZeroTier版本为|g" ztncui/src/views/index.pug