You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

75 lines
2.0 KiB

  1. /*
  2. The MIT License (MIT)
  3. Copyright (c) 2014-2017 DutchCoders [https://github.com/dutchcoders/]
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. */
  20. package server
  21. import (
  22. // _ "transfer.sh/app/handlers"
  23. // _ "transfer.sh/app/utils"
  24. "fmt"
  25. "io"
  26. "log"
  27. "net/http"
  28. "time"
  29. clamd "github.com/dutchcoders/go-clamd"
  30. "github.com/gorilla/mux"
  31. )
  32. func (s *Server) scanHandler(w http.ResponseWriter, r *http.Request) {
  33. vars := mux.Vars(r)
  34. filename := sanitize(vars["filename"])
  35. contentLength := r.ContentLength
  36. contentType := r.Header.Get("Content-Type")
  37. s.logger.Printf("Scanning %s %d %s", filename, contentLength, contentType)
  38. var reader io.Reader
  39. reader = r.Body
  40. c := clamd.NewClamd(s.ClamAVDaemonHost)
  41. abort := make(chan bool)
  42. response, err := c.ScanStream(reader, abort)
  43. if err != nil {
  44. log.Printf("%s", err.Error())
  45. http.Error(w, err.Error(), 500)
  46. return
  47. }
  48. select {
  49. case s := <-response:
  50. w.Write([]byte(fmt.Sprintf("%v\n", s.Status)))
  51. case <-time.After(time.Second * 60):
  52. abort <- true
  53. }
  54. close(abort)
  55. }