feat(network): integrate NetBird clients, profiles and private backups
This commit is contained in:
@@ -16,7 +16,7 @@ def main():
|
||||
parser.add_argument("--file", type=Path, required=True)
|
||||
parser.add_argument("--sha256", required=True)
|
||||
parser.add_argument("--version", required=True)
|
||||
parser.add_argument("--kind", choices=("node", "vps-arnavi", "vps-wireguard"), required=True)
|
||||
parser.add_argument("--kind", choices=("node", "vps-arnavi", "vps-wireguard", "vps-netbird"), required=True)
|
||||
args = parser.parse_args()
|
||||
if not re.fullmatch(r"[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9]+)?", args.version):
|
||||
raise ValueError("Invalid release version")
|
||||
@@ -59,6 +59,12 @@ def main():
|
||||
"Скопируйте пакет на VPS. Запустите: sudo python3 mission-core-wireguard-vps.pyz",
|
||||
"Дождитесь завершения установки. Файл подключения: /var/lib/ndc-wireguard-vps/mission-core-wireguard.json.",
|
||||
"Перенесите файл подключения на этот компьютер и загрузите его в настройках связи БК."])
|
||||
if args.kind == "vps-netbird":
|
||||
value.update(label="Сервер NetBird", os="Ubuntu Server 24.04 LTS · x86-64", instructions=[
|
||||
"Направьте домен сети на адрес VPS. Перенесите установщик на сервер.",
|
||||
"Проверьте план: sudo python3 mission-core-netbird-vps.pyz plan --domain ДОМЕН",
|
||||
"Примените план: sudo python3 mission-core-netbird-vps.pyz apply --domain ДОМЕН --plan-sha256 ХЕШ_ПЛАНА",
|
||||
"Адрес сети и файл доступа администратора появятся после установки."])
|
||||
temporary = root / (args.kind + ".json.new")
|
||||
temporary.write_text(json.dumps(value, ensure_ascii=False, indent=2) + "\n")
|
||||
temporary.chmod(0o600)
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Fetch exactly the reviewed vendor release into a portable local catalog."""
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import os
|
||||
import tempfile
|
||||
import time
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
from k1link.fleet.netbird.assets import LOCK, directory, verify
|
||||
|
||||
|
||||
def publish(root: Path, identifiers: list[str]) -> None:
|
||||
folder = directory(root)
|
||||
folder.mkdir(parents=True, exist_ok=True, mode=0o700)
|
||||
for row in LOCK["items"]:
|
||||
if identifiers and row["id"] not in identifiers:
|
||||
continue
|
||||
try:
|
||||
verify(root, row["id"])
|
||||
print(row["id"], "already verified", flush=True)
|
||||
continue
|
||||
except (OSError, ValueError):
|
||||
pass
|
||||
fd, temporary = tempfile.mkstemp(prefix=".download-", dir=folder)
|
||||
try:
|
||||
digest, count, deadline = hashlib.sha256(), 0, time.monotonic() + 600
|
||||
with (
|
||||
os.fdopen(fd, "wb") as output,
|
||||
urllib.request.urlopen(
|
||||
urllib.request.Request(
|
||||
row["source_url"], headers={"User-Agent": "MissionCoreRelease"}
|
||||
),
|
||||
timeout=30,
|
||||
) as source,
|
||||
):
|
||||
while chunk := source.read(256 * 1024):
|
||||
count += len(chunk)
|
||||
if count > row["bytes"] or time.monotonic() > deadline:
|
||||
raise ValueError("Download size/time limit")
|
||||
digest.update(chunk)
|
||||
output.write(chunk)
|
||||
output.flush()
|
||||
os.fsync(output.fileno())
|
||||
if count != row["bytes"] or digest.hexdigest() != row["sha256"]:
|
||||
raise ValueError("Vendor checksum mismatch")
|
||||
os.replace(temporary, folder / row["filename"])
|
||||
verify(root, row["id"])
|
||||
print(row["id"], count, "verified", flush=True)
|
||||
finally:
|
||||
Path(temporary).unlink(missing_ok=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--fleet-root", required=True, type=Path)
|
||||
parser.add_argument(
|
||||
"--client", action="append", choices=[r["id"] for r in LOCK["items"]], default=[]
|
||||
)
|
||||
arguments = parser.parse_args()
|
||||
publish(arguments.fleet_root, arguments.client)
|
||||
Reference in New Issue
Block a user