summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2020-02-04 20:36:29 +0100
committerkali kaneko (leap communications) <kali@leap.se>2020-02-04 20:38:13 +0100
commit0c97e08ed3319b3e2da47862148fb9cea069e6f3 (patch)
treeec4bb4b5fc3687a93c4184e8db1a1f09f4c7d84d
parent819adbbb708076bcf9d3ee6443c704303aad5a80 (diff)
[feat] configurable api paths
- Resolves: #6
-rwxr-xr-xconfig/CONFIG3
-rw-r--r--main.go12
-rw-r--r--pkg/config/config.go (renamed from pkg/config/main.go)42
3 files changed, 40 insertions, 17 deletions
diff --git a/config/CONFIG b/config/CONFIG
index 9a99584..939393d 100755
--- a/config/CONFIG
+++ b/config/CONFIG
@@ -14,3 +14,6 @@ export VPNWEB_SIP_HOST="localhost"
export VPNWEB_SIP_PORT="6001"
export VPNWEB_SIP_LIBR_LOCATION=testlibrary
export VPNWEB_SIP_TERMINATOR="\r"
+
+#export VPNWEB_API_PATH="./public"
+#export VPNWEB_PROVIDER_CA="./public/ca.crt"
diff --git a/main.go b/main.go
index 48c3efa..2d7492c 100644
--- a/main.go
+++ b/main.go
@@ -27,12 +27,12 @@ func main() {
/* TODO -- pass static file path in options */
- web.HttpFileHandler("/3/configs.json", "./public/3/configs.json")
- web.HttpFileHandler("/3/service.json", "./public/3/service.json")
- web.HttpFileHandler("/3/config/eip-service.json", "./public/3/eip-service.json")
- web.HttpFileHandler("/3/ca.crt", "./public/ca.crt")
- web.HttpFileHandler("/provider.json", "./public/provider.json")
- web.HttpFileHandler("/ca.crt", "./public/ca.crt")
+ web.HttpFileHandler("/3/configs.json", opts.ApiPath+"/3/configs.json")
+ web.HttpFileHandler("/3/service.json", opts.ApiPath+"/3/service.json")
+ web.HttpFileHandler("/3/config/eip-service.json", opts.ApiPath+"/3/eip-service.json")
+ web.HttpFileHandler("/provider.json", opts.ApiPath+"provider.json")
+ web.HttpFileHandler("/ca.crt", opts.ProviderCaPath)
+ web.HttpFileHandler("/3/ca.crt", opts.ProviderCaPath)
pstr := ":" + opts.Port
log.Println("Listening in port", opts.Port)
diff --git a/pkg/config/main.go b/pkg/config/config.go
index 1ce00aa..76b4e4e 100644
--- a/pkg/config/main.go
+++ b/pkg/config/config.go
@@ -24,14 +24,23 @@ import (
const DefaultAuthenticationModule string = "anon"
type Opts struct {
- Tls bool
- CaCrt string
- CaKey string
- TlsCrt string
- TlsKey string
- Port string
- Auth string
- AuthSecret string
+ Tls bool
+ CaCrt string
+ CaKey string
+ TlsCrt string
+ TlsKey string
+ Port string
+ Auth string
+ AuthSecret string
+ ApiPath string
+ ProviderCaPath string
+}
+
+func checkPathExists(path string) bool {
+ if _, err := os.Stat(path); os.IsNotExist(err) {
+ return false
+ }
+ return true
}
func FallbackToEnv(variable *string, envVar, defaultVar string) {
@@ -72,14 +81,16 @@ func NewOpts() *Opts {
}
func initializeFlags(opts *Opts) {
- flag.StringVar(&opts.CaCrt, "caCrt", "", "Path to the CA public key used for VPN certificates")
- flag.StringVar(&opts.CaKey, "caKey", "", "Path to the CA private key used for VPN certificates")
+ flag.StringVar(&opts.CaCrt, "vpnCaCrt", "", "Path to the CA public key used for VPN certificates")
+ flag.StringVar(&opts.CaKey, "vpnCaKey", "", "Path to the CA private key used for VPN certificates")
flag.BoolVar(&opts.Tls, "tls", false, "Enable TLS on the service")
flag.StringVar(&opts.TlsCrt, "tlsCrt", "", "Path to the cert file for TLS")
flag.StringVar(&opts.TlsKey, "tlsKey", "", "Path to the key file for TLS")
flag.StringVar(&opts.Port, "port", "", "Port where the server will listen (default: 8000)")
- flag.StringVar(&opts.Auth, "auth", "", "Authentication module (anonymous, sip)")
+ flag.StringVar(&opts.Auth, "auth", "", "Authentication module (ano, sip2)")
flag.StringVar(&opts.AuthSecret, "authSecret", "", "Authentication secret (optional)")
+ flag.StringVar(&opts.ApiPath, "apiPath", "", "Path to the API public files")
+ flag.StringVar(&opts.ProviderCaPath, "providerCaCrt", "", "Path to the provider CA certificate")
flag.Parse()
FallbackToEnv(&opts.CaCrt, "VPNWEB_CACRT", "")
@@ -89,6 +100,8 @@ func initializeFlags(opts *Opts) {
FallbackToEnv(&opts.Port, "VPNWEB_PORT", "8000")
FallbackToEnv(&opts.Auth, "VPNWEB_AUTH", DefaultAuthenticationModule)
FallbackToEnv(&opts.AuthSecret, "VPNWEB_AUTH_SECRET", "")
+ FallbackToEnv(&opts.ApiPath, "VPNWEB_API_PATH", "/etc/leap/config/vpn")
+ FallbackToEnv(&opts.ProviderCaPath, "VPNWEB_PROVIDER_CA", "/etc/leap/ca/ca.crt")
}
func checkConfigurationOptions(opts *Opts) {
@@ -113,5 +126,12 @@ func checkConfigurationOptions(opts *Opts) {
doTlsFilesSanityCheck(opts.TlsCrt, opts.TlsKey)
}
+ if !checkPathExists(opts.ApiPath) {
+ log.Fatal("Configured API path does not exist: ", opts.ApiPath)
+ }
+ if !checkPathExists(opts.ProviderCaPath) {
+ log.Fatal("Configured provider CA path does not exist: ", opts.ProviderCaPath)
+ }
+
log.Println("Authentication module:", opts.Auth)
}