diff --git a/README.md b/README.md index 2a13f2f..1d432aa 100644 --- a/README.md +++ b/README.md @@ -23,13 +23,13 @@ in the best possible VPN bandwidth and throughput. ### Debian (stretch) ``` -# apt install build-essential lua5.2 lua5.2-dev lua-posix lua-luaossl lua-cqueues libssl-dev liblzo2-dev +# apt install build-essential lua5.2 lua5.2-dev lua-cliargs lua-posix lua-luaossl lua-cqueues libssl-dev liblzo2-dev ``` ### Ubuntu 17.10 ``` -# apt install build-essential lua liblua5.2-dev lua-posix lua-luaossl lua-cqueues libssl-dev liblzo2-dev +# apt install build-essential lua liblua5.2-dev lua-cliargs lua-posix lua-luaossl lua-cqueues libssl-dev liblzo2-dev ``` ## Build it diff --git a/frivpn_client.lua b/frivpn_client.lua index adac912..5822be9 100755 --- a/frivpn_client.lua +++ b/frivpn_client.lua @@ -12,6 +12,7 @@ local x509 = require "openssl.x509" local castore = require "openssl.x509.store" local pkey = require "openssl.pkey" local posix = require "posix" +local cli = require "cliargs" require "libfrivpn" require "utils" @@ -65,6 +66,14 @@ local syscalls = { } +function prequire(...) + local status, lib = pcall(require, ...) + if status then + return lib + end + return nil +end + function lookup_ip(host) local res = posix.getaddrinfo(host, 1195) return res[1].addr @@ -464,6 +473,11 @@ function vpn:connect(host, port) end end +local function print_version() + print("frivpn_client: version 0.0.1") + os.exit(0) +end + function ssl_preload() local a, b = csock.pair() -- do a dummy checktls so cqueues socket loads & keeps the ossl module @@ -475,13 +489,29 @@ end ssl_preload() +-- cliargs handling +cli:set_name("frivpn_client") +cli:argument("CONFIG", "config module to load (e.g. configs/ipredator)") +cli:flag("-v, --version", "print frivpn's version", print_version) +cli:flag("--notun", "creates no tun device") + +local args, err = cli:parse(arg) +if not args and err then + print(string.format('%s: %s', cli.name, err)) + os.exit(1) +end + -- load config -local config = require(arg[1]) -config.port = config.port or 1195 +local config = prequire(args["CONFIG"]) +if not config then + print(string.format("Could not load config module %s", arg[1])) + os.exit(1) +end +config.port = config.port or 1195 local tun = nil -if arg[2] ~= "notun" then +if not args["notun"] then local status, tun_fd, tun_dev = pcall(tun_create) if status then local tun_pipe, tun_pid = tun_fork(tun_dev, config.netmask, config.on_connected)