1 /* 2 Copyright 2012 The Perkeep Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package server 18 19 import ( 20 "fmt" 21 "net/http" 22 23 "go4.org/jsonconfig" 24 "perkeep.org/pkg/auth" 25 "perkeep.org/pkg/blobserver" 26 ) 27 28 // SetupHandler handles serving the wizard setup page. 29 type SetupHandler struct { 30 config jsonconfig.Obj 31 } 32 33 func init() { 34 blobserver.RegisterHandlerConstructor("setup", newSetupFromConfig) 35 } 36 37 func newSetupFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (h http.Handler, err error) { 38 wizard := &SetupHandler{config: conf} 39 return wizard, nil 40 } 41 42 func (sh *SetupHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) { 43 if !auth.IsLocalhost(req) { 44 fmt.Fprintf(rw, 45 "<html><body>Setup only allowed from localhost"+ 46 "<p><a href='/'>Back</a></p>"+ 47 "</body></html>\n") 48 return 49 } 50 http.Redirect(rw, req, "https://perkeep.org/doc/server-config", http.StatusMovedPermanently) 51 return 52 53 // TODO: this file and the code in wizard-html.go is outdated. Anyone interested enough 54 // can take care of updating it as something nicer which would fit better with the 55 // react UI. But in the meantime we don't link to it anymore. 56 57 // if req.Method == "POST" { 58 // err := req.ParseMultipartForm(10e6) 59 // if err != nil { 60 // httputil.ServeError(rw, req, err) 61 // return 62 // } 63 // if len(req.Form) > 0 { 64 // handleSetupChange(rw, req) 65 // } 66 // return 67 // } 68 69 // sendWizard(rw, req, false) 70 }