summarylogtreecommitdiffstats
path: root/runtinyfecvpn
blob: 3c3336c7896b0d072db81c001926f37c412268ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/python
import subprocess
import json

CONF_FILE = "/etc/tinyfecvpn/conf.json"
BIN = "/usr/bin/tinyvpn"

def main():
    f = open(CONF_FILE)
    conf = json.load(f)
    cmd_args = []
    cmd_args.append(BIN)
    opts = ("key", "sub-net", "tun-dev", "fec", "timeout", "mode", "fec-mode", "report", "keep-reconnect", "mtu"
            "jitter", "interval", "random-drop", "disable-obscure", "log-level")

    if conf["mode"] == "server":
        cmd_args.append("-s")
        cmd_args.append("-l")
        cmd_args.append(str(conf["server"]) + ":" + str(conf["port"]))
    elif conf["mode"] == "client":
        cmd_args.append("-c")
        cmd_args.append("-r")
        cmd_args.append(str(conf["server"]) + ":" + str(conf["port"]))

    for key, value in conf.items():
        if key == "fec":
            cmd_args.append("--fec")
            cmd_args.append(str(value[0]) + ":" + str(value[1]))
        elif key == "fec-mode":
            cmd_args.append("--mode")
            cmd_args.append(str(value))
        elif key == "key":
            cmd_args.append("-k")
            cmd_args.append(str(value))
        elif key in ("mode", "server", "port"):
            pass
        elif key in opts:
            cmd_args.append("--" + key)
            cmd_args.append(str(value))
        else:
            raise ValueError("Invalid conif")
    
    subprocess.run(cmd_args)


if __name__ == "__main__":
    main()