all repos — fsrv @ 935cd56cdb007397f802d5f870f1c08496d87d19

filehost server for x.icyphox.sh

Redirect if User-Agent is not curl
Anirudh Oppiliappan x@icyphox.sh
Fri, 06 Aug 2021 17:49:38 +0530
commit

935cd56cdb007397f802d5f870f1c08496d87d19

parent

f2531467f400563a56c2192b34815d07b97ed9ed

1 files changed, 7 insertions(+), 1 deletions(-)

jump to
M main.gomain.go

@@ -9,6 +9,7 @@ "math/rand"

"net/http" "os" "path/filepath" + "strings" "time" )

@@ -34,6 +35,7 @@ func (s *settings) uploadFile(w http.ResponseWriter, r *http.Request) {

switch r.Method { case "POST": key := r.FormValue("key") + useragent := r.Header.Get("User-Agent") fmt.Println(key) if key != s.key { fmt.Fprintf(w, "incorrect key")

@@ -61,7 +63,11 @@ os.WriteFile(diskFile, fileBytes, 0644)

log.Printf("wrote: %+v", diskFile) fileUrl := s.url + "/" + newFile - fmt.Fprintf(w, "%v", fileUrl) + if strings.Contains(useragent, "curl/") { + fmt.Fprintf(w, "%v", fileUrl) + } else { + http.Redirect(w, r, fileUrl, http.StatusSeeOther) + } case "GET": http.ServeFile(w, r, s.index) default: