create simple resolver
This commit is contained in:
@ -66,6 +66,9 @@ def wireguard():
|
||||
"vpn",
|
||||
]
|
||||
)
|
||||
subprocess.run(
|
||||
["nsenter", "--net=/proc/1/ns/net", "/snacks/wireguard/scripts/create_conf.py"],
|
||||
)
|
||||
subprocess.run(
|
||||
["/snacks/wireguard/scripts/inner_basic.sh"],
|
||||
)
|
||||
|
39
scripts/create_conf.py
Normal file
39
scripts/create_conf.py
Normal file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env python3
|
||||
import pydantic
|
||||
from typing import Optional
|
||||
import socket
|
||||
|
||||
|
||||
class Config(pydantic.BaseModel):
|
||||
public_key: str
|
||||
host: str
|
||||
port: int
|
||||
private_key: str
|
||||
|
||||
|
||||
def write_wg(config: Config):
|
||||
wg_conf = (
|
||||
"[Interface]\n"
|
||||
f"privatekey = {config.private_key}\n\n"
|
||||
"[Peer]\n"
|
||||
f"publickey = {config.public_key}\n"
|
||||
f"endpoint = {config.host}:{config.port}\n"
|
||||
"persistentkeepalive = 20\n"
|
||||
"allowedips = 0.0.0.0/0, ::/0\n"
|
||||
)
|
||||
|
||||
try:
|
||||
with open("/run/vpnclient/wg.conf", mode="w", encoding="utf-8") as f:
|
||||
f.write(wg_conf)
|
||||
except IOError:
|
||||
pass
|
||||
|
||||
|
||||
def get_config() -> Optional[Config]:
|
||||
with open("/snacks/wireguard/wg.json", "r", encoding="utf-8") as f:
|
||||
config = Config.parse_raw(f.read())
|
||||
config.host = socket.gethostbyname(config.host)
|
||||
return config
|
||||
|
||||
|
||||
write_wg(get_config())
|
Reference in New Issue
Block a user