Move installation of /install handlers into a separate optional function

This commit is contained in:
Eugene Bujak 2019-02-06 16:48:04 +03:00
parent 06a28a461d
commit 398312cd80
2 changed files with 11 additions and 5 deletions

7
app.go
View File

@ -145,9 +145,14 @@ func run(args options) {
box := packr.NewBox("build/static") box := packr.NewBox("build/static")
// if not configured, redirect / to /install.html, otherwise redirect /install.html to / // if not configured, redirect / to /install.html, otherwise redirect /install.html to /
http.Handle("/", postInstallHandler(optionalAuthHandler(http.FileServer(box)))) http.Handle("/", postInstallHandler(optionalAuthHandler(http.FileServer(box))))
http.Handle("/install.html", preInstallHandler(http.FileServer(box)))
registerControlHandlers() 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 // this loop is used as an ability to change listening host and/or port
for { for {
address := net.JoinHostPort(config.BindHost, strconv.Itoa(config.BindPort)) address := net.JoinHostPort(config.BindHost, strconv.Itoa(config.BindPort))

View File

@ -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() { func registerControlHandlers() {
http.HandleFunc("/control/status", postInstall(optionalAuth(ensureGET(handleStatus)))) http.HandleFunc("/control/status", postInstall(optionalAuth(ensureGET(handleStatus))))
http.HandleFunc("/control/enable_protection", postInstall(optionalAuth(ensurePOST(handleProtectionEnable)))) 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/interfaces", postInstall(optionalAuth(ensureGET(handleDHCPInterfaces))))
http.HandleFunc("/control/dhcp/set_config", postInstall(optionalAuth(ensurePOST(handleDHCPSetConfig)))) http.HandleFunc("/control/dhcp/set_config", postInstall(optionalAuth(ensurePOST(handleDHCPSetConfig))))
http.HandleFunc("/control/dhcp/find_active_dhcp", postInstall(optionalAuth(ensurePOST(handleDHCPFindActiveServer)))) 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)))
} }