From 159b4322aeb0d4decb584a2f55182b67c17bf6d0 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Tue, 2 Jul 2019 20:04:39 +0200 Subject: file handler --- Makefile | 2 ++ main.go | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/Makefile b/Makefile index 918b612..b8fe777 100644 --- a/Makefile +++ b/Makefile @@ -4,5 +4,7 @@ demo: ./vpnweb -caCrt test/files/ca.crt -caKey test/files/ca.key clean: rm -f public/1/* + rm public/ca.crt populate: cp test/1/* public/1/ + cp test/files/ca.crt public/ diff --git a/main.go b/main.go index ffa9c5c..d52d5ac 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "strconv" ) +// TODO get this from the config yaml? const keySize = 2048 const expiryDays = 28 @@ -34,6 +35,12 @@ func doFilesSanityCheck(caCrt string, caKey string) { } } +func httpFileHandler(route string, path string) { + http.HandleFunc(route, func(w http.ResponseWriter, r *http.Request) { + http.ServeFile(w, r, path) + }) +} + func main() { var caCrt = flag.String("caCrt", "", "path to the CA public key") var caKey = flag.String("caKey", "", "path to the CA private key") @@ -53,6 +60,11 @@ func main() { ci := newCaInfo(*caCrt, *caKey) ch := certHandler{ci} + // add routes here http.HandleFunc("/1/cert", ch.certResponder) + httpFileHandler("/1/ca.crt", "./public/ca.crt") + httpFileHandler("/1/configs.json", "./public/1/configs.json") + httpFileHandler("/1/service.json", "./public/1/service.json") + log.Fatal(http.ListenAndServe(":"+strconv.Itoa(*port), nil)) } -- cgit v1.2.3