diff --git a/back/test.py b/back/test.py new file mode 100644 index 0000000..870ad27 --- /dev/null +++ b/back/test.py @@ -0,0 +1,16 @@ +import requests + +if __name__ == "__main__": + sess = requests.Session() + + resp = sess.post("http://localhost:8888/api/v1/login", data={ + "username": "admin", + "password": "admin" + }) + print(resp.json()) + sess.headers.update({ + "Authorization": f"Bearer {resp.json()['access_token']}" + }) + + for _ in range(20): + print(sess.get("http://localhost:8888/api/v1/wg/generate_psk").json()) diff --git a/docker-compose.yaml b/docker-compose.yaml index 10da013..0810aae 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -50,6 +50,7 @@ services: CLIENT: 1 # If you want to connect to servers CLIENT_START_AUTOMATICALLY: 1 # If you want the client to start automatically CLIENT_1_NAME: "client-1" # Name of first client + CLIENT_1_ROUTES: "10.0.200.0/24" CLIENT_1_SERVER_HOST: "http://server:8888" # Endpoint of first server CLIENT_1_SERVER_INTERFACE: "wg0" # Interface of first server (to get config) CLIENT_1_API_KEY: "thisisasecretkeythatnobodyknows" # API-Key of first server (to get config) diff --git a/wg_dashboard_backend/script/wireguard.py b/wg_dashboard_backend/script/wireguard.py index e252bb6..d65f5d9 100644 --- a/wg_dashboard_backend/script/wireguard.py +++ b/wg_dashboard_backend/script/wireguard.py @@ -259,7 +259,7 @@ def retrieve_client_conf_from_server( return response.text -def create_client_config(sess: Session, configuration, client_name): +def create_client_config(sess: Session, configuration, client_name, client_routes): parser = configparser.ConfigParser() parser.read_string(configuration) @@ -332,7 +332,7 @@ def create_client_config(sess: Session, configuration, client_name): db_peer.private_key = parser["Interface"]["PrivateKey"] db_peer.public_key = "N/A" - db_peer.allowed_ips = parser["Peer"]["AllowedIPs"] + db_peer.allowed_ips = client_routes if client_routes else parser["Peer"]["AllowedIPs"] db_peer.configuration = configuration db_server.interface = f"client_{db_peer.name}" db_server.configuration = configuration @@ -368,6 +368,7 @@ def load_environment_clients(sess: Session): client_server_interface = os.getenv(f"CLIENT_{i}_SERVER_INTERFACE", None) client_server_host = os.getenv(f"CLIENT_{i}_SERVER_HOST", None) client_api_key = os.getenv(f"CLIENT_{i}_API_KEY", None) + client_routes = os.getenv(f"CLIENT_{i}_ROUTES", None) if client_api_key is None or \ client_server_interface is None or \ @@ -385,7 +386,7 @@ def load_environment_clients(sess: Session): server_api_key=client_api_key ) - create_client_config(sess, configuration=config, client_name=client_name) + create_client_config(sess, configuration=config, client_name=client_name, client_routes=client_routes) i += 1