main.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package main
  2. var dir string
  3. func main() {
  4. /*
  5. dirFlag := flag.String("d", "./", "Directory to serve from. Default is CWD")
  6. httpPort := flag.Int("p", 80, "Port to serve on (Plain HTTP)")
  7. httpsPort := flag.Int("ps", 443, "Port to serve TLS on")
  8. serveSecure := flag.Bool("s", false, "Serve HTTPS. Default false")
  9. flag.Parse()
  10. dir = *dirFlag
  11. srv := &webdav.Handler{
  12. FileSystem: webdav.Dir(dir),
  13. LockSystem: webdav.NewMemLS(),
  14. Logger: func(r *http.Request, err error) {
  15. if err != nil {
  16. log.Printf("WEBDAV [%s]: %s, ERROR: %s\n", r.Method, r.URL, err)
  17. } else {
  18. log.Printf("WEBDAV [%s]: %s \n", r.Method, r.URL)
  19. }
  20. },
  21. }
  22. http.Handle("/", srv)
  23. if *serveSecure == true {
  24. if _, err := os.Stat("./cert.pem"); err != nil {
  25. fmt.Println("[x] No cert.pem in current directory. Please provide a valid cert")
  26. return
  27. }
  28. if _, er := os.Stat("./key.pem"); er != nil {
  29. fmt.Println("[x] No key.pem in current directory. Please provide a valid cert")
  30. return
  31. }
  32. go http.ListenAndServeTLS(fmt.Sprintf(":%d", *httpsPort), "cert.pem", "key.pem", nil)
  33. }
  34. if err := http.ListenAndServe(fmt.Sprintf(":%d", *httpPort), nil); err != nil {
  35. log.Fatalf("Error with WebDAV server: %v", err)
  36. }
  37. */
  38. }