summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2020-01-29 12:46:23 -0600
committerkali kaneko (leap communications) <kali@leap.se>2020-01-29 12:46:23 -0600
commit6ba23c4e3de16181857d5703198d2e817928f1ba (patch)
tree05e4fab5dcfeaf45e4fbe9db1437ee7fcd86cdcb /main.go
parent0c15f2abae7bddbf3311d83aca33aca1aa5761c8 (diff)
fixes after review
Diffstat (limited to 'main.go')
-rw-r--r--main.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..d719149
--- /dev/null
+++ b/main.go
@@ -0,0 +1,45 @@
+package main
+
+import (
+ "log"
+ "net/http"
+
+ "0xacab.org/leap/vpnweb/pkg/auth"
+ "0xacab.org/leap/vpnweb/pkg/config"
+ "0xacab.org/leap/vpnweb/pkg/web"
+)
+
+func main() {
+ opts := config.NewOpts()
+ ch := web.NewCertHandler(opts.CaCrt, opts.CaKey)
+
+ /* protected routes */
+
+ /* TODO https://0xacab.org/leap/vpnweb/issues/4
+ http.HandleFunc("/3/refresh-token", auth.RefreshAuthMiddleware(opts.Auth))
+ */
+
+ http.Handle("/3/cert", auth.RestrictedMiddleware(opts, ch))
+ http.HandleFunc("/3/auth", auth.AuthenticatorMiddleware(opts))
+
+ /* static files */
+
+ /* 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")
+
+ pstr := ":" + opts.Port
+ log.Println("Listening in port", opts.Port)
+
+ if opts.tls == true {
+ log.Fatal(http.ListenAndServeTLS(pstr, opts.TlsCrt, opts.TlsKey, nil))
+ } else {
+ log.Fatal(http.ListenAndServe(pstr, nil))
+
+ }
+}