diff --git a/.gitignore b/.gitignore index 30f3cc6..7e18c7a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +*.crt +*.key + + # ---> VisualStudioCode .vscode/* !.vscode/settings.json diff --git a/wg-p2p-client.py b/wg-p2p-client.py index eaa4cdc..f7430c3 100644 --- a/wg-p2p-client.py +++ b/wg-p2p-client.py @@ -2,9 +2,10 @@ import hashlib from time import sleep import yaml import requests +from pathlib import Path from wgconfig import WireGuardConfig, wg_showconf, wg_syncconf -with open("wg-p2p-client.conf") as f: - cfg = yaml.safe_load(f) + +cfg = yaml.safe_load(Path(__file__).with_suffix(".conf").read_text()) last_hash = "" last_local_hash = "" url = f"{cfg['url']}/hash/{cfg['remote_wg']}" @@ -20,9 +21,13 @@ while True: for peer in cfg["peers"]: if p := local_cfg.get_peer(peer): url2 = f"{urlpat2}/{peer}" - res = requests.get(url2).json() + res = requests.get( + url2, + cert=("client1.crt", "client1.key"), + verify=False, + ).json() p["Endpoint"] = res["Endpoint"] wg_syncconf(cfg["local_wg"], str(local_cfg)) last_hash = new_hash last_local_hash = new_local_hash - sleep(5) \ No newline at end of file + sleep(5) diff --git a/wg-p2p-server.conf b/wg-p2p-server.conf new file mode 100644 index 0000000..e69de29 diff --git a/wg-p2p-server.py b/wg-p2p-server.py index 8537891..424610c 100644 --- a/wg-p2p-server.py +++ b/wg-p2p-server.py @@ -1,10 +1,14 @@ from fastapi import FastAPI, Response from wgconfig import WireGuardConfig, wg_showconf, wg_syncconf from dataclasses import dataclass +from pathlib import Path import hashlib +import yaml app = FastAPI() +cfg = yaml.safe_load(Path(__file__).with_suffix(".conf").read_text()) + @app.get("/peers/{ifname}") def get_all_peer(ifname: str):