platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
59
selective-vpn-api/app/cli/autoloop.go
Normal file
59
selective-vpn-api/app/cli/autoloop.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
type AutoloopParams struct {
|
||||
Iface string
|
||||
Table string
|
||||
MTU int
|
||||
StateDir string
|
||||
DefaultLocation string
|
||||
}
|
||||
|
||||
type AutoloopDeps struct {
|
||||
StateDirDefault string
|
||||
ResolveIface func(flagIface string) string
|
||||
Run func(params AutoloopParams)
|
||||
Stderr io.Writer
|
||||
}
|
||||
|
||||
func RunAutoloop(args []string, deps AutoloopDeps) int {
|
||||
if deps.ResolveIface == nil || deps.Run == nil {
|
||||
return 1
|
||||
}
|
||||
stderr := deps.Stderr
|
||||
if stderr == nil {
|
||||
stderr = os.Stderr
|
||||
}
|
||||
|
||||
fs := flag.NewFlagSet("autoloop", flag.ContinueOnError)
|
||||
fs.SetOutput(stderr)
|
||||
iface := fs.String("iface", "", "VPN interface (empty/auto = detect active)")
|
||||
table := fs.String("table", "agvpn", "routing table name")
|
||||
mtu := fs.Int("mtu", 1380, "MTU for default route")
|
||||
stateDir := fs.String("state-dir", deps.StateDirDefault, "state directory")
|
||||
defaultLoc := fs.String("default-location", "Austria", "default location")
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return 2
|
||||
}
|
||||
|
||||
resolvedIface := deps.ResolveIface(*iface)
|
||||
if resolvedIface == "" {
|
||||
fmt.Fprintln(stderr, "autoloop: cannot resolve VPN interface (set --iface or preferred iface)")
|
||||
return 1
|
||||
}
|
||||
|
||||
deps.Run(AutoloopParams{
|
||||
Iface: resolvedIface,
|
||||
Table: *table,
|
||||
MTU: *mtu,
|
||||
StateDir: *stateDir,
|
||||
DefaultLocation: *defaultLoc,
|
||||
})
|
||||
return 0
|
||||
}
|
||||
Reference in New Issue
Block a user