Index: trunk/.gitignore
===================================================================
--- trunk/.gitignore	(revision 69)
+++ 	(revision )
@@ -1,2 +1,0 @@
-/marisa
-/marisa-trash
Index: trunk/COPYING
===================================================================
--- trunk/COPYING	(revision 69)
+++ 	(revision )
@@ -1,14 +1,0 @@
-Copyright (c) 2021 Willy Goiffon <contact@z3bra.org>
-Copyright (c) 2023-present Izuru Yakumo <eternal-servant@yakumo.dev>
-
-Permission to use, copy, modify, and/or distribute this software for any
-purpose with or without fee is hereby granted, provided that the above
-copyright notice and this permission notice appear in all copies.
-
-THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
-REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
-FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
-INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
-OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THIS SOFTWARE.
Index: trunk/LICENSE
===================================================================
--- trunk/LICENSE	(revision 69)
+++ 	(revision )
@@ -1,1 +1,0 @@
-link COPYING
Index: trunk/Makefile
===================================================================
--- trunk/Makefile	(revision 69)
+++ 	(revision )
@@ -1,21 +1,0 @@
-GO ?= go
-GOFLAGS ?= -v -ldflags "-w -X `${GO} list`.Version=${VERSION}"
-CGO ?= 0
-
-VERSION = 2024.02.10
-PREFIX ?= /usr/local
-
-all: marisa marisa-trash
-
-marisa:
-	CGO_ENABLED=${CGO} ${GO} build ${GOFLAGS} ./cmd/marisa
-marisa-trash:
-	CGO_ENABLED=${CGO} ${GO} build ${GOFLAGS} ./cmd/marisa-trash
-clean:
-	rm -f marisa marisa-trash
-install:
-	install -Dm0755 marisa ${PREFIX}/bin/marisa
-	install -Dm0755 marisa-trash ${PREFIX}/bin/marisa-trash
-	install -Dm0644 marisa.1 ${PREFIX}/man/man1/marisa.1
-	install -Dm0644 marisa.conf.5 ${PREFIX}/man/man5/marisa.conf.5
-.PHONY: marisa marisa-trash
Index: trunk/README.md
===================================================================
--- trunk/README.md	(revision 69)
+++ 	(revision )
@@ -1,36 +1,0 @@
-marisa
-======
-HTTP based File upload system.
-
-Features
---------
-+ Link expiration
-+ Mimetype support
-+ Random filenames
-+ Multiple file uploads
-+ Javascript not needed
-+ Privilege drop
-+ chroot(2) support
-+ FastCGI support
-
-Usage
------
-Refer to the marisa(1) manual page for details and examples.
-
-	marisa [-v] [-f marisa.conf]
-
-Configuration is done through its configuration file, marisa.conf(5).
-The format is that of the INI file format.
-
-Uploading files is done via PUT and POST requests. Multiple files can
-be sent via POST requests.
-
-	curl -T file.png http://domain.tld
-	curl -F file=file.png -F expiry=3600 http://domain.tld
-
-Installation
-------------
-Edit the `config.mk` file to match your setup, then run the following:
-
-        $ (b)make
-        # (b)make install
Index: trunk/config.mk
===================================================================
--- trunk/config.mk	(revision 1)
+++ trunk/config.mk	(revision 1)
@@ -0,0 +1,2 @@
+GO   = go
+GOOS = `{uname -s | tr A-Z a-z}
Index: trunk/go.mod
===================================================================
--- trunk/go.mod	(revision 69)
+++ trunk/go.mod	(revision 1)
@@ -1,10 +1,3 @@
-module mahou-no-mori.yakumo.dev/marisa
+module git.z3bra.org/partage
 
 go 1.17
-
-require (
-	github.com/dustin/go-humanize v1.0.0
-	gopkg.in/ini.v1 v1.63.2
-)
-
-require github.com/stretchr/testify v1.8.4 // indirect
Index: trunk/go.sum
===================================================================
--- trunk/go.sum	(revision 69)
+++ 	(revision )
@@ -1,20 +1,0 @@
-github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-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/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
-github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
-github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
-github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
-github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
-github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
-github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
-github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
-github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/ini.v1 v1.63.2 h1:tGK/CyBg7SMzb60vP1M03vNZ3VDu3wGQJwn7Sxi9r3c=
-gopkg.in/ini.v1 v1.63.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
-gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
-gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
-gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Index: trunk/marisa-trash.1
===================================================================
--- trunk/marisa-trash.1	(revision 69)
+++ 	(revision )
@@ -1,44 +1,0 @@
-.Dd $Mdocdate$
-.Dt MARISA-TRASH 1
-.Os
-.Sh NAME
-.Nm marisa-trash
-.Nd Purge expired share files
-.Sh SYNOPSIS
-.Nm marisa-trash
-.Op Fl v
-.Op Fl f Ar files
-.Op Fl m Ar metadata
-.Sh DESCRIPTION
-Upon each run,
-.Nm
-will check expiration times for files in the
-.Pa metadata
-directory, and delete the according file in the 
-.Pa files
-directory if the expiration time has passed.
-.Pp
-.Nm
-is best run as a
-.Xr cron 8
-job, as the same user as the
-.Xr marisa 1
-daemon.
-.Bl -tag -width Ds
-.It Fl v
-Turn on verbose logging to
-.Pa stderr
-.It Fl f Ar files
-Set the location of actual files to
-.Pa files
-.It Fl m Ar metadata
-Lookup metadata files in directory
-.Pa metadata
-.El
-.Sh SEE ALSO
-.Xr marisa 1
-.Sh AUTHOR
-.An Willy Goiffon Aq Mt dev@z3bra.org
-.Pp
-"Borrowed" by
-.An Izuru Yakumo Aq Mt eternal-servant@yakumo.dev
Index: trunk/marisa.1
===================================================================
--- trunk/marisa.1	(revision 69)
+++ 	(revision )
@@ -1,43 +1,0 @@
-.Dd $Mdocdate$
-.Dt MARISA 1
-.Os
-.Sh NAME
-.Nm marisa
-.Nd HTTP based file upload system
-.Sh SYNOPSIS
-.Nm marisa
-.Op Fl v
-.Op Fl f Ar file
-.Sh DESCRIPTION
-.Nm
-is an HTTP server that permits temporary file uploads using PUT and
-POST requests.
-.Pp
-Files uploaded are saved in a single directory and given random names
-while retaining their original extension.
-A configurable expiration time is set for each file, that can be used
-to cleanup expired files thanks to
-.Xr marisa-trash 1 .
-.Bl -tag -width Ds
-.It Fl v
-Turn on verbose logging to
-.Pa stderr
-.It Fl f Ar file
-Load configuration from
-.Pa file
-.El
-.Sh SEE ALSO
-.Xr marisa-trash 1 ,
-.Xr marisa.conf 5
-.Sh AUTHORS
-.An Willy Goiffon Aq Mt dev@z3bra.org
-.Pp
-"Borrowed" by
-.An Izuru Yakumo Aq Mt eternal-servant@yakumo.dev
-.Sh BUGS
-If you upload a file through the browser, and refresh the
-page, the file will get constantly reuploaded, which may
-exhaust the server's storage at some point.
-.Pp
-This shouldn't happen with a CLI, such as
-.Xr curl 1
Index: trunk/marisa.conf.5
===================================================================
--- trunk/marisa.conf.5	(revision 69)
+++ 	(revision )
@@ -1,94 +1,0 @@
-.Dd $Mdocdate$
-.Dt MARISA.CONF 5
-.Os
-.Sh NAME
-.Nm marisa.conf
-.Nd marisa configuration file format
-.Sh DESCRIPTION
-.Nm
-is the configuration file for the HTTP file sharing system,
-.Xr marisa 1 .
-.Sh CONFIGURATION
-Here are the settings that can be set:
-.Bl -tag -width Ds
-.It Ic listen Ar socket
-Have the program listen on
-.Ar socket .
-This socket can be specified either as a TCP socket:
-.Ar host:port
-or as a Unix socket:
-.Ar /path/to/marisa.sock .
-When using Unix sockets, the program will serve content using the
-.Em FastCGI
-protocol.
-.It Ic user Ar user
-Username that the program will drop privileges to upon startup. When
-using Unix sockets, the owner of the socket will be changed to this user.
-.It Ic group Ar group
-Group that the program will drop privileges to upon startup (require that
-.Ic user
-is set). When using Unix sockets, the owner group of the socket will be
-changed to this group.
-.It Ic chroot Pa dir
-Directory to chroot into upon startup. When specified, all other path
-must be set within the chroot directory.
-.It Ic baseuri Ar uri
-Base URI to use when constructing hyper links.
-.It Ic rootdir Pa dir
-Directory containing static files.
-.It Ic tmplpath Pa dir
-Directory containing template files.
-.It Ic filepath Pa dir
-Directory where uploaded files must be written to.
-.It Ic metapath Pa dir
-Directory where metadata for uploaded files will be saved.
-.It Ic filectx Pa context
-URI context to use for serving files.
-.It Ic maxsize Ar size
-Maximum size per file to accept for uploads.
-.It Ic expiry Ar time
-Default expiration time to set for uploads.
-.El
-.Sh EXAMPLE
-Configuration suitable for use with
-.Xr httpd 8
-using fastcgi:
-.Bd -literal -offset indent
-listen      = /run/marisa.sock
-baseuri     = https://domain.tld
-user        = www
-group       = daemon
-chroot      = /var/www
-rootdir     = /htdocs/static
-filepath    = /htdocs/files
-metapath    = /htdocs/meta
-tmplpath    = /htdocs/templates
-filectx     = /d/
-maxsize     = 10737418240 # 10 Gib
-expiry      = 86400       # 24 hours
-.Ed
-
-Mathing
-.Xr httpd.conf 5
-configuration:
-.Bd -literal -offset indent
-server "domain.tld" {
-	listen on * tls port 443
-	connection { max request body 10737418240 }
-	location "*" {
-		fastcgi socket "/run/marisa.sock"
-	}
-}
-types { include "/usr/share/misc/mime.types" }
-.Ed
-
-.Sh SEE ALSO
-.Xr marisa 1 ,
-.Xr marisa-trash 1 ,
-.Xr httpd 8,
-.Xr httpd.conf 5
-.Sh AUTHORS
-.An Willy Goiffon Aq Mt dev@z3bra.org
-.Pp
-"Borrowed" by
-.An Izuru Yakumo Aq Mt eternal-servant@yakumo.dev
Index: trunk/mkfile
===================================================================
--- trunk/mkfile	(revision 1)
+++ trunk/mkfile	(revision 1)
@@ -0,0 +1,21 @@
+<config.mk
+
+all:V: partage
+
+%: %.go
+	$GO build -o $stem
+
+clean:V:
+	rm -f partage
+
+install:V: partage
+	mkdir -p ${DESTDIR}${PREFIX}/bin
+	cp partage ${DESTDIR}${PREFIX}/bin/partage
+	chmod 755 ${DESTDIR}${PREFIX}/bin/partage
+	mkdir -p ${DESTDIR}${MANDIR}/man1
+	cp partage.1 ${DESTDIR}${MANDIR}/man1/partage.1
+	chmod 644 ${DESTDIR}${MANDIR}/man1/partage.1
+
+uninstall:V:
+	rm ${DESTDIR}${PREFIX}/bin/partage
+	rm ${DESTDIR}${MANDIR}/man1/partage.1
Index: trunk/partage.go
===================================================================
--- trunk/partage.go	(revision 1)
+++ trunk/partage.go	(revision 1)
@@ -0,0 +1,157 @@
+package main
+
+import (
+	"fmt"
+	"io"
+	"io/ioutil"
+	"net/http"
+	"os"
+	"path"
+	"path/filepath"
+)
+
+var conf struct {
+	bind     string
+	filepath string
+	rootdir  string
+	baseuri  string
+	maxsize  int64
+}
+
+func contenttype(f *os.File) string {
+	buffer := make([]byte, 512)
+
+	_, err := f.Read(buffer)
+	if err != nil {
+		return ""
+	}
+
+	mime := http.DetectContentType(buffer)
+
+	return mime
+}
+
+func writefile(f *os.File, s io.ReadCloser) int {
+	buffer := make([]byte, 4096)
+
+	var sz int
+
+	for {
+		n, err := s.Read(buffer)
+
+		if err != nil {
+			if err == io.EOF {
+				n, err := f.Write(buffer[:n])
+				if err != nil {
+					fmt.Println(err)
+				}
+				sz += n
+				break
+			}
+			fmt.Println(err)
+			return -1
+		}
+
+		n, err = f.Write(buffer[:n])
+		if err != nil {
+			fmt.Println(err)
+		}
+		sz += n
+	}
+
+	f.Sync()
+	return sz
+}
+
+func servefile(f *os.File, w http.ResponseWriter) {
+	buffer := make([]byte, 4096)
+
+	mime := contenttype(f)
+	w.Header().Set("Content-Type", mime)
+
+	f.Seek(0, 0)
+	for {
+		n, err := f.Read(buffer)
+
+		if err != nil {
+			if err == io.EOF {
+				_, err := w.Write(buffer[:n])
+				if err != nil {
+					fmt.Println(err)
+				}
+				break
+			}
+			fmt.Println(err)
+			return
+		}
+
+		_, err = w.Write(buffer[:n])
+		if err != nil {
+			fmt.Println(err)
+		}
+	}
+}
+
+func parse(w http.ResponseWriter, r *http.Request) {
+
+	fmt.Printf("%s %s\n", r.Method, r.URL.Path)
+
+	// Max 15 Gb uploads
+	if r.ContentLength > conf.maxsize {
+		w.WriteHeader(http.StatusRequestEntityTooLarge)
+		w.Write([]byte("File is too big"))
+	}
+
+	err := r.ParseForm()
+	if err != nil {
+		fmt.Printf("%s %s: %s", r.Method, r.URL.Path, err)
+	}
+
+	switch r.Method {
+	case "PUT":
+		tmp, _ := ioutil.TempFile(conf.filepath, "*"+path.Ext(r.URL.Path))
+		f, err := os.Create(tmp.Name())
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+		defer f.Close()
+
+		if writefile(f, r.Body) < 0 {
+			w.WriteHeader(http.StatusInternalServerError)
+			return
+		}
+
+		resp := conf.baseuri + "/" + filepath.Base(tmp.Name())
+		w.Write([]byte(resp))
+
+	case "GET":
+		// r.URL.Path is sanitized regarding "." and ".."
+		filename := r.URL.Path
+		if r.URL.Path == "/" {
+			filename = "/index.html"
+		}
+		
+		f, err := os.Open(conf.rootdir + filename)
+		if err != nil {
+			w.WriteHeader(http.StatusNotFound)
+			fmt.Println(err)
+			return
+		}
+		defer f.Close()
+
+		servefile(f, w)
+	}
+}
+
+func main() {
+
+	conf.bind = "0.0.0.0:8080"
+	conf.maxsize = 28 * 1024 * 1024
+	conf.filepath = "/tmp"
+	conf.rootdir = "./static"
+	conf.baseuri = "http://192.168.0.3:8080"
+
+	http.HandleFunc("/", parse)
+	http.ListenAndServe("0.0.0.0:8080", nil)
+}
Index: trunk/version.go
===================================================================
--- trunk/version.go	(revision 69)
+++ 	(revision )
@@ -1,15 +1,0 @@
-package marisa
-
-import (
-	"fmt"
-)
-
-var (
-	// Version release version
-	Version = "0.0.1"
-)
-
-// FullVersion display the full version and build
-func FullVersion() string {
-	return fmt.Sprintf("%s", Version)
-}
