diff --git a/.dockerignore b/.dockerignore old mode 100644 new mode 100755 diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index 2df2d69..6b0e765 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ files/ *.db -hardfiles \ No newline at end of file +hardfiles +todo \ No newline at end of file diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 8cda2d3..0000000 --- a/Dockerfile +++ /dev/null @@ -1,12 +0,0 @@ -FROM golang:1.21-alpine as builder -WORKDIR /build -COPY go.mod go.sum ./ -RUN go mod download -COPY *.go ./ -RUN go build -o hardfiles main.go - -FROM golang:1.21-alpine as app -WORKDIR /app -COPY --from=builder /build/hardfiles . -RUN mkdir files -CMD ["./hardfiles"] \ No newline at end of file diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/config.toml b/config.toml old mode 100644 new mode 100755 diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 071fb16..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,11 +0,0 @@ -services: - hardfiles: - container_name: hardfiles - image: git.supernets.org/supernets/hardfiles:latest - build: . - volumes: - - "$PWD/files:/app/files" - - "$PWD/www:/app/www" - - "$PWD/config.toml:/app/config.toml" - ports: - - "5000:5000" \ No newline at end of file diff --git a/go.mod b/go.mod old mode 100644 new mode 100755 index e051693..913e77b --- a/go.mod +++ b/go.mod @@ -12,6 +12,8 @@ require ( ) require ( + github.com/alecthomas/chroma/v2 v2.13.0 // indirect + github.com/dlclark/regexp2 v1.11.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.19 // indirect golang.org/x/net v0.17.0 // indirect diff --git a/go.sum b/go.sum old mode 100644 new mode 100755 index 974a340..ccd336e --- a/go.sum +++ b/go.sum @@ -1,8 +1,12 @@ github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/alecthomas/chroma/v2 v2.13.0 h1:VP72+99Fb2zEcYM0MeaWJmV+xQvz5v5cxRHd+ooU1lI= +github.com/alecthomas/chroma/v2 v2.13.0/go.mod h1:BUGjjsD+ndS6eX37YgTchSEG+Jg9Jv1GiZs9sqPqztk= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI= +github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= diff --git a/main.go b/main.go old mode 100644 new mode 100755 index 7574188..b1c1920 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "net/http" "os" "strconv" + "strings" "time" "github.com/BurntSushi/toml" @@ -110,13 +111,11 @@ func Exists(path string) bool { } func UploadHandler(w http.ResponseWriter, r *http.Request) { - // expiry time - var ttl int64 - - ttl = 0 + var ttl int64 = 0 //expiration file, _, err := r.FormFile("file") if err != nil { + log.Error().Err(err).Msg("empty file form field") w.WriteHeader(http.StatusBadRequest) return } @@ -180,9 +179,11 @@ func UploadHandler(w http.ResponseWriter, r *http.Request) { hostedurl := "https://" + conf.VHost + "/uploads/" + name - w.Header().Set("Location", hostedurl) + if strings.Contains(name, "jpeg") || strings.Contains(name, "png") || strings.Contains(name, "jpg") || strings.Contains(name, "txt") || strings.Contains(name, "csv") || strings.Contains(name, "pdf") { + w.Header().Set("Location", hostedurl) + } w.WriteHeader(http.StatusSeeOther) - w.Write([]byte(hostedurl)) + w.Write([]byte(hostedurl + "\n")) } func Cull() { @@ -229,6 +230,7 @@ func main() { if err = landlock.V2.BestEffort().RestrictPaths( landlock.RWDirs(conf.FileFolder), landlock.RWDirs(conf.Webroot), + // landlock.RWDirs("/tmp"), landlock.RWFiles(conf.DBFile), ); err != nil { log.Warn().Err(err).Msg("could not landlock") @@ -279,10 +281,12 @@ func main() { go Cull() serv := &http.Server{ - Addr: ":" + conf.LPort, - Handler: r, - ErrorLog: nil, - IdleTimeout: 20 * time.Second, + Addr: ":" + conf.LPort, + Handler: r, + ErrorLog: nil, + IdleTimeout: 60 * time.Second, + ReadTimeout: 600 * time.Second, + WriteTimeout: 600 * time.Second, } log.Warn().Msg("shredding is only effective on HDD volumes") diff --git a/www/delirious.gif b/www/delirious.gif new file mode 100755 index 0000000..5a65feb Binary files /dev/null and b/www/delirious.gif differ diff --git a/www/fist.ico b/www/fist.ico old mode 100644 new mode 100755 diff --git a/www/header.png b/www/header.png old mode 100644 new mode 100755 diff --git a/www/index.html b/www/index.html old mode 100644 new mode 100755 index bb8cab3..3f6e5ab --- a/www/index.html +++ b/www/index.html @@ -3,26 +3,107 @@
+