From 398312cd80537d49b3c8752425ab7fd8358c7bc0 Mon Sep 17 00:00:00 2001 From: Eugene Bujak Date: Wed, 6 Feb 2019 16:48:04 +0300 Subject: [PATCH] Move installation of /install handlers into a separate optional function --- app.go | 7 ++++++- control.go | 9 +++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app.go b/app.go index f72a9d08..e72a7f2c 100644 --- a/app.go +++ b/app.go @@ -145,9 +145,14 @@ func run(args options) { box := packr.NewBox("build/static") // if not configured, redirect / to /install.html, otherwise redirect /install.html to / http.Handle("/", postInstallHandler(optionalAuthHandler(http.FileServer(box)))) - http.Handle("/install.html", preInstallHandler(http.FileServer(box))) registerControlHandlers() + // add handlers for /install paths, we only need them when we're not configured yet + if config.firstRun { + http.Handle("/install.html", preInstallHandler(http.FileServer(box))) + registerInstallHandlers() + } + // this loop is used as an ability to change listening host and/or port for { address := net.JoinHostPort(config.BindHost, strconv.Itoa(config.BindPort)) diff --git a/control.go b/control.go index 912f3425..a310ab58 100644 --- a/control.go +++ b/control.go @@ -801,6 +801,11 @@ func handleInstallConfigure(w http.ResponseWriter, r *http.Request) { }() } +func registerInstallHandlers() { + http.HandleFunc("/control/install/get_addresses", preInstall(ensureGET(handleInstallGetAddresses))) + http.HandleFunc("/control/install/configure", preInstall(ensurePOST(handleInstallConfigure))) +} + func registerControlHandlers() { http.HandleFunc("/control/status", postInstall(optionalAuth(ensureGET(handleStatus)))) http.HandleFunc("/control/enable_protection", postInstall(optionalAuth(ensurePOST(handleProtectionEnable)))) @@ -839,8 +844,4 @@ func registerControlHandlers() { http.HandleFunc("/control/dhcp/interfaces", postInstall(optionalAuth(ensureGET(handleDHCPInterfaces)))) http.HandleFunc("/control/dhcp/set_config", postInstall(optionalAuth(ensurePOST(handleDHCPSetConfig)))) http.HandleFunc("/control/dhcp/find_active_dhcp", postInstall(optionalAuth(ensurePOST(handleDHCPFindActiveServer)))) - - // TODO: move to registerInstallHandlers() - http.HandleFunc("/control/install/get_addresses", preInstall(ensureGET(handleInstallGetAddresses))) - http.HandleFunc("/control/install/configure", preInstall(ensurePOST(handleInstallConfigure))) }