diff --git a/worker.py b/worker.py index a1f7564..14fd853 100644 --- a/worker.py +++ b/worker.py @@ -311,7 +311,7 @@ PersistentKeepalive = {persistent_keepalive} # Main function to create and configure the server -def run(config, provider, location, server_type): +def run(config, provider, location, server_type, endpoint_only): if provider == "hetzner": location = location or config["hetzner"]["location"] server_type = server_type or config["hetzner"]["server_type"] @@ -374,6 +374,10 @@ def run(config, provider, location, server_type): listen_port = config["wireguard"]["listen_port"] persistent_keepalive = config["wireguard"]["peer_persistent_keepalive"] + if endpoint_only: + print(f"[{server_ip}]:{listen_port}") + return + peer_config = f""" [Peer] PublicKey = {public_key} @@ -383,7 +387,6 @@ Endpoint = [{server_ip}]:{listen_port} PersistentKeepalive = {persistent_keepalive} """ - print("Wireguard Configuration:") print(peer_config) @@ -405,6 +408,7 @@ def main(): ) parser.add_argument("--location", type=str, help="Server location") parser.add_argument("--server_type", type=str, help="Server type") + parser.add_argument("--endpoint-only", action="store_true", help="Return Wireguard endpoint (host:port) instead of full configuration") args = parser.parse_args() # Check if the configuration has all the required sections @@ -415,7 +419,7 @@ def main(): raise ValueError(f"Missing section {section} in config.ini") # Run the main function with parsed arguments - run(config, args.provider, args.location, args.server_type) + run(config, args.provider, args.location, args.server_type, args.endpoint_only) if __name__ == "__main__":