package webdav import ( "fmt" "log" "net/http" "os" "golang.org/x/net/webdav" "imuslab.com/bokofs/bokofsd/mod/bokoworker" ) /* WebDAV module This module handle the interfacing to the underlying file system through the middle ware */ type Options struct { ListeningAddress string //Listening address, e.g. 0.0.0.0:8443 SecureServe bool //Use TLS to serve the WebDAV request PublicKeyPath string PrivateKeyPath string } type Server struct { LoadedWorkers *bokoworker.Worker } func NewWebdavInterfaceServer() *Server { return &Server{} } func (s *Server) Start() error { srv := &webdav.Handler{ FileSystem: webdav.Dir(dir), LockSystem: webdav.NewMemLS(), Logger: func(r *http.Request, err error) { if err != nil { log.Printf("WEBDAV [%s]: %s, ERROR: %s\n", r.Method, r.URL, err) } else { log.Printf("WEBDAV [%s]: %s \n", r.Method, r.URL) } }, } http.Handle("/", srv) if *serveSecure == true { if _, err := os.Stat("./cert.pem"); err != nil { fmt.Println("[x] No cert.pem in current directory. Please provide a valid cert") return } if _, er := os.Stat("./key.pem"); er != nil { fmt.Println("[x] No key.pem in current directory. Please provide a valid cert") return } go http.ListenAndServeTLS(fmt.Sprintf(":%d", *httpsPort), "cert.pem", "key.pem", nil) } if err := http.ListenAndServe(fmt.Sprintf(":%d", *httpPort), nil); err != nil { log.Fatalf("Error with WebDAV server: %v", err) } }