Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading an existing config #2

Open
house-of-vanity opened this issue Feb 15, 2021 · 2 comments
Open

Reading an existing config #2

house-of-vanity opened this issue Feb 15, 2021 · 2 comments

Comments

@house-of-vanity
Copy link

house-of-vanity commented Feb 15, 2021

Hi, could you implement reading an existing config rather than rewriting it? I know that you cannot obtain servers pub and clients secrets from it. Anyway it will be convenient to migrate seamlessly to this tool. I moved my config with simple Python script.

import wgconfig # default iniparser cannot read WG configs.
import json

cfg_path = "/etc/wireguard/wg0.conf"
server_public_key = "IfhwVCps7GEtplKh44wGEHhj892leqpnDXeAKkAmAWg="
public_ip = "10.10.10.1"
dns = "8.8.8.8"

wg = wgconfig.WGConfig(cfg_path)
wg.read_file()

cfg = dict()

_id = 1
peers = list()
for pk, data in wg.peers.items():
    p = dict()
    p["Active"] = False
    p["ID"] = _id
    p["Name"] = data["PublicKey"][0:7]
    p["PrivateKey"] = None
    p["PublicKey"] = data["PublicKey"]
    p["VirtualIP"] = data["AllowedIPs"].split("/")[0]
    p["KeepAlive"] = 0
    peers.append(p)
    _id += 1


cfg["PublicIP"] = public_ip
cfg["PublicKey"] = server_public_key
cfg["DNS"] = dns
cfg["WgConfigPath"] = cfg_path
cfg["Port"] = str(wg.interface["ListenPort"])
cfg["VirtualIP"] = wg.interface["Address"].split("/")[0]
cfg["CIDR"] = wg.interface["Address"].split("/")[1]
cfg["PrivateKey"] = wg.interface["PrivateKey"]
cfg["Active"] = True
cfg["Peers"] = peers

print(json.dumps(cfg, indent=4))
@aos
Copy link
Owner

aos commented Feb 19, 2021

Hey there. That's a good idea. I originally implemented it to always overwrite because without a proper config file (with secrets, etc.) it basically doesn't work. I could make it a command-line option when starting the app. I think that might be the best way to do it. What do you think?

Also I've basically slowed down progress on this as I'm currently in the process of rewriting it in Rust.

@house-of-vanity
Copy link
Author

Sounds good.
Also I'd like to use Rust version too because I have some experience with Rust. Do you have any code already?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants