tMerge branch 'master' of git.z3bra.org:partage - partage - File upload system
 (HTM) git clone git://git.z3bra.org/partage.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 8f28d1b7592f40f814ce9884d07a2e0fcb380bbd
 (DIR) parent 5a7dddc8f51ee7a5d05525fd81702259d0b952eb
 (HTM) Author: Willy Goiffon <dev@z3bra.org>
       Date:   Tue, 18 Jan 2022 07:46:54 +0100
       
       Merge branch 'master' of git.z3bra.org:partage
       
       Diffstat:
         M mkfile                              |       6 +++---
         A partage-trash/partage-trash.1       |      41 +++++++++++++++++++++++++++++++
         A partage.1                           |      33 +++++++++++++++++++++++++++++++
         A partage.conf.5                      |      91 +++++++++++++++++++++++++++++++
         M partage.go                          |      10 +++++++++-
       
       5 files changed, 177 insertions(+), 4 deletions(-)
       ---
 (DIR) diff --git a/mkfile b/mkfile
       t@@ -15,9 +15,9 @@ install:V: partage partage-trash/partage-trash
                chmod 755 ${DESTDIR}${PREFIX}/bin/partage
                chmod 755 ${DESTDIR}${PREFIX}/bin/partage-trash
                mkdir -p ${DESTDIR}${MANDIR}/man1
       -        cp man/partage.1 ${DESTDIR}${MANDIR}/man1/partage.1
       -        cp man/partage-trash.1 ${DESTDIR}${MANDIR}/man1/partage-trash.1
       -        cp man/partage.conf.5 ${DESTDIR}${MANDIR}/man5/partage.conf.5
       +        cp partage.1 ${DESTDIR}${MANDIR}/man1/partage.1
       +        cp partage-trash/partage-trash.1 ${DESTDIR}${MANDIR}/man1/partage-trash.1
       +        cp partage.conf.5 ${DESTDIR}${MANDIR}/man5/partage.conf.5
                chmod 644 ${DESTDIR}${MANDIR}/man1/partage.1
                chmod 644 ${DESTDIR}${MANDIR}/man1/partage-trash.1
                chmod 644 ${DESTDIR}${MANDIR}/man5/partage.conf.5
 (DIR) diff --git a/partage-trash/partage-trash.1 b/partage-trash/partage-trash.1
       t@@ -0,0 +1,41 @@
       +.Dd 2021-11-03
       +.Dt PARTAGE-TRASH 1
       +.Os POSIX.1-2017
       +.Sh NAME
       +.Nm partage-trash
       +.Nd Purge expired share files
       +.Sh SYNOPSIS
       +.Nm partage-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 partage 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 partage 1
       +.Sh AUTHOR
       +.An Willy Goiffon Aq Mt dev@z3bra.org
 (DIR) diff --git a/partage.1 b/partage.1
       t@@ -0,0 +1,33 @@
       +.Dd 2021-11-03
       +.Dt PARTAGE 1
       +.Os POSIX.1-2017
       +.Sh NAME
       +.Nm partage
       +.Nd HTTP based file upload system
       +.Sh SYNOPSIS
       +.Nm partage
       +.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 partage-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 partage-trash 1 ,
       +.Xr partage.conf 5
       +.Sh AUTHOR
       +.An Willy Goiffon Aq Mt dev@z3bra.org
 (DIR) diff --git a/partage.conf.5 b/partage.conf.5
       t@@ -0,0 +1,91 @@
       +.Dd 2021-11-03
       +.Dt PARTAGE.CONF 5
       +.Os POSIX.1-2017
       +.Sh NAME
       +.Nm partage.conf
       +.Nd partage configuration file format
       +.Sh DESCRIPTION
       +.Nm
       +is the configuration file for the HTTP file sharing system,
       +.Xr partage 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/partage.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/partage.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/partage.sock"
       +        }
       +}
       +types { include "/usr/share/misc/mime.types" }
       +.Ed
       +
       +.Sh SEE ALSO
       +.Xr partage 1 ,
       +.Xr partage-trash 1 ,
       +.Xr httpd 8,
       +.Xr httpd.conf 5
       +.Sh AUTHORS
       +.An Willy Goiffon Aq Mt dev@z3bra.org
 (DIR) diff --git a/partage.go b/partage.go
       t@@ -92,6 +92,10 @@ func writemeta(filename string, expiry int64) error {
                size := stat.Size()
                f.Close()
        
       +        if expiry < 0 {
       +                expiry = conf.expiry
       +        }
       +
                meta := metadata{
                        Filename: filepath.Base(filename),
                        Size:     size,
       t@@ -196,7 +200,11 @@ func uploaderPost(w http.ResponseWriter, r *http.Request) {
                                return
                        }
        
       -                writemeta(tmp.Name(), conf.expiry)
       +                expiry, err := strconv.Atoi(r.PostFormValue("expiry"))
       +                if err != nil || expiry < 0 {
       +                        expiry = int(conf.expiry)
       +                }
       +                writemeta(tmp.Name(), int64(expiry))
        
                        link := conf.baseuri + conf.filectx + filepath.Base(tmp.Name())
                        links = append(links, link)