Compare commits

..

126 commits

Author SHA1 Message Date
ZizzyDizzyMC
c8f7c32649 Updating go modules and sum for building on newer go versions. 2024-06-27 18:37:03 +00:00
ZizzyDizzyMC
df761a39c3
Update README.md
Had a question if the repo was still maintained, and the answer is yes, but I've not had a lot of time to do so.
2024-06-27 01:19:51 -04:00
ZizzyDizzyMC
57f867811a
Merge pull request #19 from BBaoVanC/file-locking
Lock files while they're being written
2024-06-27 01:17:16 -04:00
ZizzyDizzyMC
573c6b8afc
Merge pull request #34 from urandom2/test
remove broken test

Clearing up old pulls, this was a test that never seen use outside of development and it hadn't worked when I originally added a bunch of features to Linx as an extension of Andre's work.
2024-05-18 20:27:23 -04:00
ZizzyDizzyMC
16b5111d17
Merge pull request #14 from BBaoVanC/fix-linx-randomize-put
Don't randomize filename if Linx-Randomize is not "yes"

This code is so stable and life's been a mess, but it's time to clear up some old pulls.  Looks good.
2024-05-18 20:24:13 -04:00
Colin Arnott
40b8cf7fb3
remove broken test
TestPostJSONUploadMaxExpiry has been broken since at least
90e47f049b. How it breaks seems to change
over time, but there has not been any effort to actually fix it, and the
referenced issues and context, andreimarcu/linx-server#111, have been
lost to the annals of time. As such, we have removed this test.
2022-12-13 22:02:16 +00:00
BBaoVanC
3b57cef637
Fix some naming and other modules that I missed 2021-12-28 18:42:37 -06:00
BBaoVanC
181e65bd21
Create locks path in Dockerfile 2021-12-28 18:42:36 -06:00
BBaoVanC
953f72da76
Make the locks dir with 755 instead of 700 2021-12-28 18:42:36 -06:00
BBaoVanC
4a9a4f7be2
Add check for locks in cleanup.go 2021-12-28 18:42:36 -06:00
BBaoVanC
4512264e84
Support file locking
TODO: Actually check for locks in cleanup.go
2021-12-28 18:42:36 -06:00
ZizzyDizzyMC
3f503442f1
Merge pull request #10 from luckman212/add-default-expiry
add default expiry config parameter
2021-12-24 16:57:26 -05:00
Luke Hamburg
702b0fb193
Merge pull request #1 from boba-best/add-default-expiry
Use default expiry in API
2021-12-23 16:59:26 -05:00
BBaoVanC
e26fb92394
Use default expiry with API 2021-12-17 23:53:23 -06:00
BBaoVanC
c3a2f2d132
Don't randomize filename if Linx-Randomize is not "yes" 2021-12-12 17:19:35 -06:00
ZizzyDizzyMC
a327bb8dbe
Merge pull request #6 from binaryoverload/master
Introduce Twitter Card Metadata into Image Template
2021-10-10 16:29:49 -04:00
luckman212
d63a875b12
add default expiry config parameter 2021-10-09 11:36:53 -04:00
ZizzyDizzyMC
084ac233ff Repo Link update.
Added link to this fork of Linx-server.
2021-08-20 12:13:58 -04:00
William Oldham
7d0950e54c
Update image.html 2021-07-11 00:09:57 +01:00
ZizzyDizzyMC
5b774469ea Update README.md 2021-03-17 19:34:36 -04:00
ZizzyDizzyMC
ac7c088e91 Merge remote-tracking branch 'upstream/master' 2021-03-17 19:24:07 -04:00
ZizzyDizzyMC
20543c46d3 Merge branch 'master' of https://github.com/ZizzyDizzyMC/linx-server 2021-03-07 23:05:03 -05:00
ZizzyDizzyMC
d43dcf4acd Update default text for new features. 2021-03-07 23:04:52 -05:00
ZizzyDizzyMC
fae511f7d5
Update Readme to include new feature descriptions. 2021-03-03 00:06:44 -05:00
ZizzyDizzyMC
59cf8dbfee Update index.html 2021-02-27 21:53:29 -05:00
ZizzyDizzyMC
4579be1048 Update index.html 2021-02-27 21:42:19 -05:00
ZizzyDizzyMC
0f45bce481 Default Random Filename flag. 2021-02-27 21:37:06 -05:00
ZizzyDizzyMC
ee762ba596 Updating the re-worked ShareX Custom Upload export. 2021-02-22 21:04:17 -05:00
ZizzyDizzyMC
040e20548e Update paste template for disable-access-key option. 2021-02-22 13:48:13 -05:00
ZizzyDizzyMC
90e47f049b Fix missing bool struct for disableAccessKey 2021-02-22 13:33:58 -05:00
ZizzyDizzyMC
cd79f0db40 Disable Access Key option. 2021-02-22 13:32:38 -05:00
ZizzyDizzyMC
797a61cf5c Update upload.go 2021-02-22 00:27:21 -05:00
ZizzyDizzyMC
c49e1e62d5 Update upload.go 2021-02-22 00:21:26 -05:00
ZizzyDizzyMC
2f2470220d Update upload.go 2021-02-22 00:20:55 -05:00
ZizzyDizzyMC
605773decc Adding in Large Files adjustable expiry limit. 2021-02-22 00:13:04 -05:00
ZizzyDizzyMC
7953f31ff5 Update upload.go 2021-02-21 22:55:51 -05:00
ZizzyDizzyMC
26030e78fb Update upload.go 2021-02-21 22:54:49 -05:00
ZizzyDizzyMC
20c3d65e30 Update upload.go 2021-02-21 22:54:20 -05:00
ZizzyDizzyMC
238b612860 Update upload.go 2021-02-21 22:43:02 -05:00
ZizzyDizzyMC
4b755bafea Update upload.go 2021-02-21 22:41:34 -05:00
ZizzyDizzyMC
bab8916372 Update upload.go 2021-02-21 22:32:07 -05:00
ZizzyDizzyMC
e479f46510 Update upload.go 2021-02-21 22:30:30 -05:00
ZizzyDizzyMC
eeb7c95cbb Update upload.go 2021-02-21 22:29:19 -05:00
ZizzyDizzyMC
354714708f Update upload.go 2021-02-21 22:12:37 -05:00
ZizzyDizzyMC
0b39245c09 Update upload.go 2021-02-21 22:11:06 -05:00
ZizzyDizzyMC
84b9b36d35 Update upload.go 2021-02-21 22:09:56 -05:00
ZizzyDizzyMC
718dc08ca7 Update upload.go 2021-02-21 21:57:53 -05:00
ZizzyDizzyMC
416a0b1dcc Update upload.go 2021-02-21 21:57:19 -05:00
ZizzyDizzyMC
93ec408815 Revert "Update upload.go"
This reverts commit 74d3a42eff.
2021-02-21 21:52:06 -05:00
ZizzyDizzyMC
74d3a42eff Update upload.go 2021-02-21 21:51:16 -05:00
ZizzyDizzyMC
6d818c543d Update upload.go 2021-02-21 21:49:33 -05:00
ZizzyDizzyMC
60f91c88f0 Update upload.go 2021-02-21 21:48:38 -05:00
ZizzyDizzyMC
3967ecd3d1 Update upload.go 2021-02-21 21:48:10 -05:00
ZizzyDizzyMC
2842d0c9dc Update upload.go 2021-02-21 21:41:20 -05:00
ZizzyDizzyMC
baa3c3c1d3 Update upload.go 2021-02-21 21:40:48 -05:00
ZizzyDizzyMC
afbb8abd81 Update upload.go 2021-02-21 21:39:45 -05:00
ZizzyDizzyMC
07a333e0a4 Update upload.go 2021-02-21 21:35:17 -05:00
ZizzyDizzyMC
dcf2b4fc29 Update upload.go 2021-02-21 21:28:25 -05:00
ZizzyDizzyMC
5ca1a60754 Update upload.go 2021-02-21 21:21:42 -05:00
ZizzyDizzyMC
0156fdb15b Update upload.go 2021-02-21 21:14:31 -05:00
ZizzyDizzyMC
17441020c2 Update upload.go 2021-02-21 21:01:07 -05:00
ZizzyDizzyMC
7635abf2dc Update upload.go 2021-02-21 20:56:38 -05:00
ZizzyDizzyMC
357f1b1883 Update upload.go 2021-02-21 20:56:12 -05:00
ZizzyDizzyMC
b61c08ac13 Update upload.go 2021-02-21 20:54:31 -05:00
ZizzyDizzyMC
ddb89bdc66 Update upload.go 2021-02-21 20:52:18 -05:00
ZizzyDizzyMC
5c3ace8829 Update upload.go 2021-02-21 20:51:32 -05:00
ZizzyDizzyMC
c4f40d2747 Update upload.go 2021-02-21 20:49:22 -05:00
ZizzyDizzyMC
486e4ed836 Update upload.go 2021-02-21 20:45:13 -05:00
ZizzyDizzyMC
fb1ec8a64c Update upload.go 2021-02-21 20:43:38 -05:00
ZizzyDizzyMC
49161feb7a Update upload.go 2021-02-21 20:40:53 -05:00
ZizzyDizzyMC
b8f4b55f05 Content-Length rejection if specified larger than allowed size. 2021-02-21 20:40:10 -05:00
ZizzyDizzyMC
9d9f5b3a69 Deletion via GET request (URL) is now possible.
This enables better compatibility with ShareX, an open source screenshot tool.
2021-02-21 00:45:07 -05:00
ZizzyDizzyMC
5f8ed2aa47 Update delete.go 2021-02-21 00:29:53 -05:00
ZizzyDizzyMC
84f455da41 Update delete.go 2021-02-21 00:28:25 -05:00
ZizzyDizzyMC
d8e0398919 Update delete.go 2021-02-21 00:27:16 -05:00
ZizzyDizzyMC
0f0753ad60 ShareX URL Delete compatibility 2021-02-21 00:15:30 -05:00
ZizzyDizzyMC
df5b563de5 Add more time options.
A requested feature was to add multiple other time options for manual uploads.
2021-02-19 21:30:31 -05:00
ZizzyDizzyMC
5ac71915de Update Sample.md 2021-02-19 14:13:22 -05:00
ZizzyDizzyMC
0a63826e4d Creating a sample demonstration. 2021-02-19 14:10:14 -05:00
ZizzyDizzyMC
83da9c898d Update server.go 2021-02-12 22:27:19 -05:00
ZizzyDizzyMC
a4465764da remove container test 2021-02-11 21:38:08 -05:00
ZizzyDizzyMC
1d7db84090 Update audio.html 2021-02-11 21:36:26 -05:00
ZizzyDizzyMC
9f98db8319 testing container 2021-02-11 21:32:11 -05:00
ZizzyDizzyMC
f9d0158586 Update audio.html 2021-02-11 21:28:36 -05:00
ZizzyDizzyMC
d265987475 Update audio.html 2021-02-11 21:24:23 -05:00
ZizzyDizzyMC
3b4dac997c Update audio.html 2021-02-11 21:19:26 -05:00
ZizzyDizzyMC
affa55cedd Testing audio embed card. 2021-02-11 21:16:16 -05:00
ZizzyDizzyMC
c47f6ba19d Update audio.html 2021-02-10 23:56:47 -05:00
ZizzyDizzyMC
1e8d4e2ff9 Update audio.html 2021-02-10 23:43:38 -05:00
ZizzyDizzyMC
8e5ec6e09c Update audio.html 2021-02-10 23:42:10 -05:00
ZizzyDizzyMC
b952ec4e70 Update audio.html 2021-02-10 23:38:24 -05:00
ZizzyDizzyMC
3e7e0ab975 Update audio.html 2021-02-10 23:37:04 -05:00
ZizzyDizzyMC
58274c9107 Update audio.html 2021-02-10 23:30:42 -05:00
ZizzyDizzyMC
d3373ba623 Update video.html 2021-02-10 23:22:49 -05:00
ZizzyDizzyMC
5b6ae7f0ea Update server.go 2021-02-10 22:55:25 -05:00
ZizzyDizzyMC
362ebaad6d revert all changes 2021-02-10 22:20:59 -05:00
ZizzyDizzyMC
1489848240 test 2021-02-10 22:07:41 -05:00
ZizzyDizzyMC
fe345872b6 test 2021-02-10 21:54:04 -05:00
ZizzyDizzyMC
1a9a630577 testing the reverse order. 2021-02-10 21:33:08 -05:00
ZizzyDizzyMC
90f1d2006c Update base.html 2021-02-10 21:22:59 -05:00
ZizzyDizzyMC
b056391e68 Update base.html 2021-02-10 21:21:19 -05:00
ZizzyDizzyMC
9133cf5071 test 2021-02-10 21:11:56 -05:00
ZizzyDizzyMC
d958745a2a Update base.html 2021-02-10 21:06:51 -05:00
ZizzyDizzyMC
a02663324e Update video.html 2021-02-10 21:03:51 -05:00
root
c0bad40c90 Changing permissions 2021-02-10 20:50:32 -05:00
ZizzyDizzyMC
3f05a148c7 test 2021-02-10 20:46:59 -05:00
ZizzyDizzyMC
3133c911ec Embed rework. 2021-02-10 20:42:59 -05:00
ZizzyDizzyMC
f49f553f18 Update metalog.sh 2021-02-10 19:44:17 -05:00
ZizzyDizzyMC
29eb962d9a Meta Log Cron File 2021-02-10 19:33:38 -05:00
ZizzyDizzyMC
26aeb87d42 Update s3.go 2021-02-09 23:10:35 -05:00
ZizzyDizzyMC
2624427b6c Update upload.go 2021-02-09 23:07:18 -05:00
ZizzyDizzyMC
cb69d98032 Update upload.go 2021-02-09 22:59:23 -05:00
ZizzyDizzyMC
654a1f0a84 Update upload.go 2021-02-09 22:53:27 -05:00
ZizzyDizzyMC
d6ebc29483 Update upload.go 2021-02-09 22:52:18 -05:00
ZizzyDizzyMC
5effb947e3 Update upload.go 2021-02-09 22:47:08 -05:00
ZizzyDizzyMC
f87914a2a2 Update upload.go 2021-02-09 22:44:04 -05:00
ZizzyDizzyMC
de6b3bc23f Improved Security Logging 2021-02-09 22:36:14 -05:00
ZizzyDizzyMC
b8fdab8822 Update base.html 2021-02-09 20:07:45 -05:00
ZizzyDizzyMC
3ef06652a8 Update server.go 2021-02-09 20:05:09 -05:00
ZizzyDizzyMC
5a42af9611 Update server.go 2021-02-09 20:02:21 -05:00
ZizzyDizzyMC
63975c2019 Extra footer text block test. 2021-02-09 20:00:20 -05:00
Andrei Marcu
94f63c2045
Update README.md 2021-01-25 11:29:55 -08:00
Steven Tang
486cc6ff77
Remove entrypoint from sample docker-compose.yml (#252)
Resolves #225

Entrypoint in Dockerfile specifies default bind, filespath, metapath.
Having entrypoint in docker-compose.yml will remove those defaults.
Without the entrypoint line, the command executed is:
`/usr/local/bin/linx-server -bind=0.0.0.0:8080 -filespath=/data/files/ -metapath=/data/meta/ -config /data/linx-server.conf`
2020-11-29 11:09:53 -08:00
Andrei Marcu
91b9885ac6 Update README.md 2020-10-16 16:57:09 -07:00
tuxx
ef99024433
Add LinxShare android client to README.md (#246) 2020-10-16 16:55:11 -07:00
Andrei Marcu
9a5fc11dff Fix GH action (again) 2020-08-14 00:52:25 -07:00
29 changed files with 319 additions and 182 deletions

View file

@ -27,7 +27,7 @@ jobs:
--build-arg VERSION=${VERSION} \
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg VCS_REF=${GITHUB_SHA::8} \
${TAGS} --file ./test/Dockerfile ./test
${TAGS} --file Dockerfile .
-
name: Set up Docker Buildx
uses: crazy-max/ghaction-docker-buildx@v3

View file

@ -18,11 +18,11 @@ ENV SSL_CERT_FILE /etc/ssl/cert.pem
COPY static /go/src/github.com/andreimarcu/linx-server/static/
COPY templates /go/src/github.com/andreimarcu/linx-server/templates/
RUN mkdir -p /data/files && mkdir -p /data/meta && chown -R 65534:65534 /data
RUN mkdir -p /data/files && mkdir -p /data/meta && mkdir -p /data/locks && chown -R 65534:65534 /data
VOLUME ["/data/files", "/data/meta"]
VOLUME ["/data/files", "/data/meta", "/data/locks"]
EXPOSE 8080
USER nobody
ENTRYPOINT ["/usr/local/bin/linx-server", "-bind=0.0.0.0:8080", "-filespath=/data/files/", "-metapath=/data/meta/"]
ENTRYPOINT ["/usr/local/bin/linx-server", "-bind=0.0.0.0:8080", "-filespath=/data/files/", "-metapath=/data/meta/", "-lockspath=/data/locks/"]
CMD ["-sitename=linx", "-allowhotlink"]

View file

@ -1,19 +1,30 @@
linx-server
======
[![Build Status](https://travis-ci.org/andreimarcu/linx-server.svg?branch=master)](https://travis-ci.org/andreimarcu/linx-server)
Self-hosted file/media sharing website.
### Is this still active?
Yes, though the repo may be old, it's still active and I'll try and fix any major issues that occur with my limited time.
### Demo
You can see what it looks like using the demo: [https://demo.linx-server.net/](https://demo.linx-server.net/)
You can see what it looks like using the demo: [https://put.icu/](https://put.icu/)
### Clients
**Official**
- CLI: **linx-client** - [Source](https://github.com/andreimarcu/linx-client)
**Unofficial**
- Android: **LinxShare** - [Source](https://github.com/iksteen/LinxShare/) | [Google Play](https://play.google.com/store/apps/details?id=org.thegraveyard.linxshare)
- CLI: **golinx** - [Source](https://github.com/mutantmonkey/golinx)
### Features
- Display common filetypes (image, video, audio, markdown, pdf)
- Display syntax-highlighted code with in-place editing
- Documented API with keys if need to restrict uploads (can use [linx-client](https://github.com/andreimarcu/linx-client) for uploading through command-line)
- Documented API with keys for restricting uploads
- Torrent download of files using web seeding
- File expiry, deletion key, file access key, and random filename options
@ -45,7 +56,6 @@ services:
linx-server:
container_name: linx-server
image: andreimarcu/linx-server
entrypoint: /usr/local/bin/linx-server
command: -config /data/linx-server.conf
volumes:
- /path/to/files:/data/files
@ -60,8 +70,8 @@ Ideally, you would use a reverse proxy such as nginx or caddy to handle TLS cert
#### Using a binary release
1. Grab the latest binary from the [releases](https://github.com/andreimarcu/linx-server/releases)
2. Run ```./linx-server```
1. Grab the latest binary from the [releases](https://github.com/andreimarcu/linx-server/releases), then run ```go install```
2. Run ```linx-server -config path/to/linx-server.conf```
Usage
@ -98,6 +108,11 @@ maxexpiry = 86400
| ```nologs = true``` | (optionally) disable request logs in stdout
| ```force-random-filename = true``` | (optionally) force the use of random filenames
| ```custompagespath = custom_pages/``` | (optionally) specify path to directory containing markdown pages (must end in .md) that will be added to the site navigation (this can be useful for providing contact/support information and so on). For example, custom_pages/My_Page.md will become My Page in the site navigation
| ```extra-footer-text = "..."``` | (optionally) Extra text above the footer for notices.
| ```max-duration-time = 0``` | Time till expiry for files over max-duration-size. (Default is 0 for no-expiry.)
| ```max-duration-size = 4294967296``` | Size of file before max-duration-time is used to determine expiry max time. (Default is 4GB)
| ```disable-access-key = true``` | Disables access key usage. (Default is false.)
| ```default-random-filename = true``` | Makes it so the random filename is not default if set false. (Default is true.)
#### Cleaning up expired files

View file

@ -2,6 +2,7 @@ package localfs
import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"net/http"
@ -16,6 +17,7 @@ import (
type LocalfsBackend struct {
metaPath string
filesPath string
locksPath string
}
type MetadataJSON struct {
@ -25,6 +27,7 @@ type MetadataJSON struct {
Mimetype string `json:"mimetype"`
Size int64 `json:"size"`
Expiry int64 `json:"expiry"`
SrcIp string `json:"srcip,omitempty"`
ArchiveFiles []string `json:"archive_files,omitempty"`
}
@ -106,6 +109,8 @@ func (b LocalfsBackend) writeMetadata(key string, metadata backends.Metadata) er
Sha256sum: metadata.Sha256sum,
Expiry: metadata.Expiry.Unix(),
Size: metadata.Size,
SrcIp: metadata.SrcIp,
}
dst, err := os.Create(metaPath)
@ -124,7 +129,42 @@ func (b LocalfsBackend) writeMetadata(key string, metadata backends.Metadata) er
return nil
}
func (b LocalfsBackend) Put(key string, r io.Reader, expiry time.Time, deleteKey, accessKey string) (m backends.Metadata, err error) {
func (b LocalfsBackend) Lock(filename string) (err error) {
lockPath := path.Join(b.locksPath, filename)
lock, err := os.Create(lockPath)
if err != nil {
return err
}
lock.Close()
return
}
func (b LocalfsBackend) Unlock(filename string) (err error) {
lockPath := path.Join(b.locksPath, filename)
err = os.Remove(lockPath)
if err != nil {
return err
}
return
}
func (b LocalfsBackend) CheckLock(filename string) (locked bool, err error) {
lockPath := path.Join(b.locksPath, filename)
if _, err := os.Stat(lockPath); errors.Is(err, os.ErrNotExist) {
return false, nil
} else {
return true, nil
}
return false, err
}
func (b LocalfsBackend) Put(key string, r io.Reader, expiry time.Time, deleteKey, accessKey string, srcIp string) (m backends.Metadata, err error) {
filePath := path.Join(b.filesPath, key)
dst, err := os.Create(filePath)
@ -153,6 +193,7 @@ func (b LocalfsBackend) Put(key string, r io.Reader, expiry time.Time, deleteKey
m.Expiry = expiry
m.DeleteKey = deleteKey
m.AccessKey = accessKey
m.SrcIp = srcIp
m.ArchiveFiles, _ = helpers.ListArchiveFiles(m.Mimetype, m.Size, dst)
err = b.writeMetadata(key, m)
@ -197,9 +238,10 @@ func (b LocalfsBackend) List() ([]string, error) {
return output, nil
}
func NewLocalfsBackend(metaPath string, filesPath string) LocalfsBackend {
func NewLocalfsBackend(metaPath string, filesPath string, locksPath string) LocalfsBackend {
return LocalfsBackend{
metaPath: metaPath,
filesPath: filesPath,
locksPath: locksPath,
}
}

View file

@ -12,6 +12,7 @@ type Metadata struct {
Mimetype string
Size int64
Expiry time.Time
SrcIp string
ArchiveFiles []string
}

View file

@ -3,6 +3,7 @@ package s3
import (
"io"
"io/ioutil"
"log"
"net/http"
"os"
"strconv"
@ -125,6 +126,7 @@ func mapMetadata(m backends.Metadata) map[string]*string {
"Mimetype": aws.String(m.Mimetype),
"Sha256sum": aws.String(m.Sha256sum),
"AccessKey": aws.String(m.AccessKey),
"SrcIp": aws.String(m.SrcIp),
}
}
@ -155,7 +157,22 @@ func unmapMetadata(input map[string]*string) (m backends.Metadata, err error) {
return
}
func (b S3Backend) Put(key string, r io.Reader, expiry time.Time, deleteKey, accessKey string) (m backends.Metadata, err error) {
func (b S3Backend) Lock(filename string) (err error) {
log.Printf("Locking is not supported on S3")
return
}
func (b S3Backend) Unlock(filename string) (err error) {
log.Printf("Locking is not supported on S3")
return
}
func (b S3Backend) CheckLock(filename string) (locked bool, err error) {
log.Printf("Locking is not supported on S3")
return
}
func (b S3Backend) Put(key string, r io.Reader, expiry time.Time, deleteKey, accessKey string, srcIp string) (m backends.Metadata, err error) {
tmpDst, err := ioutil.TempFile("", "linx-server-upload")
if err != nil {
return m, err

View file

@ -12,7 +12,10 @@ type StorageBackend interface {
Exists(key string) (bool, error)
Head(key string) (Metadata, error)
Get(key string) (Metadata, io.ReadCloser, error)
Put(key string, r io.Reader, expiry time.Time, deleteKey, accessKey string) (Metadata, error)
Lock(filename string) (error)
Unlock(filename string) (error)
CheckLock(filename string) (bool, error)
Put(key string, r io.Reader, expiry time.Time, deleteKey, accessKey string, srcIp string) (Metadata, error)
PutMetadata(key string, m Metadata) error
ServeFile(key string, w http.ResponseWriter, r *http.Request) error
Size(key string) (int64, error)

View file

@ -8,8 +8,8 @@ import (
"github.com/andreimarcu/linx-server/expiry"
)
func Cleanup(filesDir string, metaDir string, noLogs bool) {
fileBackend := localfs.NewLocalfsBackend(metaDir, filesDir)
func Cleanup(filesDir string, metaDir string, locksDir string, noLogs bool) {
fileBackend := localfs.NewLocalfsBackend(metaDir, filesDir, locksDir)
files, err := fileBackend.List()
if err != nil {
@ -17,6 +17,15 @@ func Cleanup(filesDir string, metaDir string, noLogs bool) {
}
for _, filename := range files {
locked, err := fileBackend.CheckLock(filename)
if err != nil {
log.Printf("Error checking if %s is locked: %s", filename, err)
}
if locked {
log.Printf("%s is locked, it will be ignored", filename)
continue
}
metadata, err := fileBackend.Head(filename)
if err != nil {
if !noLogs {
@ -33,10 +42,12 @@ func Cleanup(filesDir string, metaDir string, noLogs bool) {
}
}
func PeriodicCleanup(minutes time.Duration, filesDir string, metaDir string, noLogs bool) {
func PeriodicCleanup(minutes time.Duration, filesDir string, metaDir string, locksDir string, noLogs bool) {
c := time.Tick(minutes)
for range c {
Cleanup(filesDir, metaDir, noLogs)
log.Printf("Running periodic cleanup")
Cleanup(filesDir, metaDir, locksDir, noLogs)
log.Printf("Finished periodic cleanup")
}
}

View file

@ -20,6 +20,7 @@ func TestContentSecurityPolicy(t *testing.T) {
Config.siteURL = "http://linx.example.org/"
Config.filesDir = path.Join(os.TempDir(), generateBarename())
Config.metaDir = Config.filesDir + "_meta"
Config.locksDir = Config.filesDir + "_locks"
Config.maxSize = 1024 * 1024 * 1024
Config.noLogs = true
Config.siteName = "linx"

View file

@ -10,9 +10,13 @@ import (
func deleteHandler(c web.C, w http.ResponseWriter, r *http.Request) {
requestKey := r.Header.Get("Linx-Delete-Key")
if len(r.URL.Query().Get("linx-delete-key")) > 0 {
requestKey = r.URL.Query().Get("linx-delete-key")
}
filename := c.URLParams["name"]
// Ensure that file exists and delete key is correct
metadata, err := storageBackend.Head(filename)
if err == backends.NotFoundErr {

View file

@ -11,6 +11,10 @@ var defaultExpiryList = []uint64{
60,
300,
3600,
7200,
14400,
28800,
43200,
86400,
604800,
2419200,

38
go.mod
View file

@ -1,19 +1,33 @@
module github.com/andreimarcu/linx-server
go 1.14
go 1.21
toolchain go1.22.4
require (
github.com/GeertJohan/go.rice v1.0.0
github.com/aws/aws-sdk-go v1.29.19
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5
github.com/dustin/go-humanize v1.0.0
github.com/flosch/pongo2 v0.0.0-20190707114632-bbf5a6c351f4
github.com/gabriel-vasile/mimetype v1.1.1
github.com/microcosm-cc/bluemonday v1.0.2
github.com/minio/sha256-simd v0.1.1
github.com/russross/blackfriday v1.5.1
github.com/GeertJohan/go.rice v1.0.3
github.com/aws/aws-sdk-go v1.54.9
github.com/dchest/uniuri v1.2.0
github.com/dustin/go-humanize v1.0.1
github.com/flosch/pongo2 v0.0.0-20200913210552-0d938eb266f3
github.com/gabriel-vasile/mimetype v1.4.4
github.com/microcosm-cc/bluemonday v1.0.26
github.com/minio/sha256-simd v1.0.1
github.com/russross/blackfriday v1.6.0
github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de
github.com/zeebo/bencode v1.0.0
github.com/zenazn/goji v0.9.0
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073
github.com/zenazn/goji v1.0.1
golang.org/x/crypto v0.24.0
)
require (
github.com/aymerick/douceur v0.2.0 // indirect
github.com/daaku/go.zipexe v1.0.2 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/kr/text v0.2.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sys v0.21.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)

109
go.sum
View file

@ -1,76 +1,69 @@
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
github.com/GeertJohan/go.rice v1.0.0 h1:KkI6O9uMaQU3VEKaj01ulavtF7o1fWT7+pk/4voiMLQ=
github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtixis4Tib9if0=
github.com/GeertJohan/go.rice v1.0.3 h1:k5viR+xGtIhF61125vCE1cmJ5957RQGXG6dmbaWZSmI=
github.com/GeertJohan/go.rice v1.0.3/go.mod h1:XVdrU4pW00M4ikZed5q56tPf1v2KwnIKeIdc9CBYNt4=
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/aws/aws-sdk-go v1.29.19 h1:+jifYixffn6kzWygtGWFWQMv0tDGyISZHNwugF9V2sE=
github.com/aws/aws-sdk-go v1.29.19/go.mod h1:1KvfttTE3SPKMpo8g2c6jL3ZKfXtFvKscTgahTma5Xg=
github.com/daaku/go.zipexe v1.0.0 h1:VSOgZtH418pH9L16hC/JrgSNJbbAL26pj7lmD1+CGdY=
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
github.com/aws/aws-sdk-go v1.54.9 h1:e0Czh9AhrCVPuyaIUnibYmih3cYexJKlqlHSJ2eMKbI=
github.com/aws/aws-sdk-go v1.54.9/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/daaku/go.zipexe v1.0.2 h1:Zg55YLYTr7M9wjKn8SY/WcpuuEi+kR2u4E8RhvpyXmk=
github.com/daaku/go.zipexe v1.0.2/go.mod h1:5xWogtqlYnfBXkSB1o9xysukNP9GTvaNkqzUZbt3Bw8=
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/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5 h1:RAV05c0xOkJ3dZGS0JFybxFKZ2WMLabgx3uXnd7rpGs=
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5/go.mod h1:GgB8SF9nRG+GqaDtLcwJZsQFhcogVCJ79j4EdT0c2V4=
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/flosch/pongo2 v0.0.0-20190707114632-bbf5a6c351f4 h1:GY1+t5Dr9OKADM64SYnQjw/w99HMYvQ0A8/JoUkxVmc=
github.com/flosch/pongo2 v0.0.0-20190707114632-bbf5a6c351f4/go.mod h1:T9YF2M40nIgbVgp3rreNmTged+9HrbNTIQf1PsaIiTA=
github.com/gabriel-vasile/mimetype v1.1.1 h1:qbN9MPuRf3bstHu9zkI9jDWNfH//9+9kHxr9oRBBBOA=
github.com/gabriel-vasile/mimetype v1.1.1/go.mod h1:6CDPel/o/3/s4+bp6kIbsWATq8pmgOisOPG40CJa6To=
github.com/go-check/check v0.0.0-20180628173108-788fd7840127 h1:0gkP6mzaMqkmpcJYCFOLkIBwI7xFExG03bbkOkCvUPI=
github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/dchest/uniuri v1.2.0 h1:koIcOUdrTIivZgSLhHQvKgqdWZq5d7KdMEWF1Ud6+5g=
github.com/dchest/uniuri v1.2.0/go.mod h1:fSzm4SLHzNZvWLvWJew423PhAzkpNQYq+uNLq4kxhkY=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/flosch/pongo2 v0.0.0-20200913210552-0d938eb266f3 h1:fmFk0Wt3bBxxwZnu48jqMdaOR/IZ4vdtJFuaFV8MpIE=
github.com/flosch/pongo2 v0.0.0-20200913210552-0d938eb266f3/go.mod h1:bJWSKrZyQvfTnb2OudyUjurSG4/edverV7n82+K3JiM=
github.com/gabriel-vasile/mimetype v1.4.4 h1:QjV6pZ7/XZ7ryI2KuyeEDE8wnh7fHP9YnQy+R0LnH8I=
github.com/gabriel-vasile/mimetype v1.4.4/go.mod h1:JwLei5XPtWdGiMFB5Pjle1oEeoSeEuJfJE+TtfvdB/s=
github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8=
github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5 h1:rhqTjzJlm7EbkELJDKMTU7udov+Se0xZkWmugr6zGok=
github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5/go.mod h1:W54LbzXuIE0boCoNJfwqpmkKJ1O4TCTZMetAt6jGk7Q=
github.com/juju/loggo v0.0.0-20180524022052-584905176618 h1:MK144iBQF9hTSwBW/9eJm034bVoG30IshVm688T2hi8=
github.com/juju/loggo v0.0.0-20180524022052-584905176618/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U=
github.com/juju/testing v0.0.0-20180920084828-472a3e8b2073 h1:WQM1NildKThwdP7qWrNAFGzp4ijNLw8RlgENkaI4MJs=
github.com/juju/testing v0.0.0-20180920084828-472a3e8b2073/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM=
github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw=
github.com/microcosm-cc/bluemonday v1.0.2 h1:5lPfLTTAvAbtS0VqT+94yOtFnGfUWYyx0+iToC3Os3s=
github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc=
github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKUJU=
github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM=
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/microcosm-cc/bluemonday v1.0.26 h1:xbqSvqzQMeEHCqMi64VAs4d8uy6Mequs3rQ0k/Khz58=
github.com/microcosm-cc/bluemonday v1.0.26/go.mod h1:JyzOCs9gkyQyjs+6h10UEVSe02CGwkhd72Xdqh78TWs=
github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM=
github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nkovacs/streamquote v1.0.0/go.mod h1:BN+NaZ2CmdKqUuTUXUEm9j95B2TRbpOWpxbJYzzgUsc=
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/russross/blackfriday v1.5.1 h1:B8ZN6pD4PVofmlDCDUdELeYrbsVIDM/bpjW3v3zgcRc=
github.com/russross/blackfriday v1.5.1/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww=
github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de h1:fkw+7JkxF3U1GzQoX9h69Wvtvxajo5Rbzy6+YMMzPIg=
github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de/go.mod h1:irMhzlTz8+fVFj6CH2AN2i+WI5S6wWFtK3MBCIxIpyI=
github.com/zeebo/bencode v1.0.0 h1:zgop0Wu1nu4IexAZeCZ5qbsjU4O1vMrfCrVgUjbHVuA=
github.com/zeebo/bencode v1.0.0/go.mod h1:Ct7CkrWIQuLWAy9M3atFHYq4kG9Ao/SsY5cdtCXmp9Y=
github.com/zenazn/goji v0.9.0 h1:RSQQAbXGArQ0dIDEq+PI6WqN6if+5KHu6x2Cx/GXLTQ=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20181221001348-537d06c36207/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
github.com/zenazn/goji v1.0.1 h1:4lbD8Mx2h7IvloP7r2C0D6ltZP6Ufip8Hn0wmSK5LR8=
github.com/zenazn/goji v1.0.1/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce h1:xcEWjVhvbDy+nHP67nPDDpbYrY+ILlfndk4bRioVHaU=
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

View file

@ -9,15 +9,18 @@ import (
func main() {
var filesDir string
var metaDir string
var locksDir string
var noLogs bool
flag.StringVar(&filesDir, "filespath", "files/",
"path to files directory")
flag.StringVar(&metaDir, "metapath", "meta/",
"path to metadata directory")
flag.StringVar(&locksDir, "lockspath", "locks/",
"path to locks directory")
flag.BoolVar(&noLogs, "nologs", false,
"don't log deleted files")
flag.Parse()
cleanup.Cleanup(filesDir, metaDir, noLogs)
cleanup.Cleanup(filesDir, metaDir, locksDir, noLogs)
}

7
metalog.sh Executable file
View file

@ -0,0 +1,7 @@
#!/bin/bash
# For setting up cron with a logging function for metadata only.
# Add to crontab with "crontab -e"
# Paste "*/1 * * * * /path/to/metalog.sh /path/to/meta/source/ /path/to/meta-log"
# Change it to source and log directory paths.
# The slash after source/ is important. It means everyhitng *inside* the source directory.
rsync -a ${1} ${2}

View file

@ -21,9 +21,10 @@ const (
func indexHandler(c web.C, w http.ResponseWriter, r *http.Request) {
err := renderTemplate(Templates["index.html"], pongo2.Context{
"maxsize": Config.maxSize,
"expirylist": listExpirationTimes(),
"forcerandom": Config.forceRandomFilename,
"maxsize": Config.maxSize,
"expirylist": listExpirationTimes(),
"expirydefault": Config.defaultExpiry,
"forcerandom": Config.forceRandomFilename,
}, r, w)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
@ -32,8 +33,9 @@ func indexHandler(c web.C, w http.ResponseWriter, r *http.Request) {
func pasteHandler(c web.C, w http.ResponseWriter, r *http.Request) {
err := renderTemplate(Templates["paste.html"], pongo2.Context{
"expirylist": listExpirationTimes(),
"forcerandom": Config.forceRandomFilename,
"expirylist": listExpirationTimes(),
"expirydefault": Config.defaultExpiry,
"forcerandom": Config.forceRandomFilename,
}, r, w)
if err != nil {
oopsHandler(c, w, r, RespHTML, "")

14
put.icu.sxcu Normal file
View file

@ -0,0 +1,14 @@
{
"Version": "13.1.0",
"DestinationType": "ImageUploader, TextUploader, FileUploader",
"RequestMethod": "PUT",
"RequestURL": "https://put.icu/upload/",
"Headers": {
"Accept": "application/json",
"Linx-Delete-Key": null,
"Linx-Access-Key": null
},
"Body": "Binary",
"URL": "$json:url$",
"DeletionURL": "https://put.icu/delete/$json:filename$?linx-delete-key=$json:delete_key$"
}

View file

@ -43,6 +43,7 @@ var Config struct {
bind string
filesDir string
metaDir string
locksDir string
siteName string
siteURL string
sitePath string
@ -56,6 +57,7 @@ var Config struct {
xFrameOptions string
maxSize int64
maxExpiry uint64
defaultExpiry uint64
realIp bool
noLogs bool
allowHotlink bool
@ -74,6 +76,11 @@ var Config struct {
accessKeyCookieExpiry uint64
customPagesDir string
cleanupEveryMinutes uint64
extraFooterText string
maxDurationTime uint64
maxDurationSize int64
disableAccessKey bool
defaultRandomFilename bool
}
var Templates = make(map[string]*pongo2.Template)
@ -131,6 +138,11 @@ func setup() *web.Mux {
log.Fatal("Could not create metadata directory:", err)
}
err = os.MkdirAll(Config.locksDir, 0755)
if err != nil {
log.Fatal("Could not create locks directory:", err)
}
if Config.siteURL != "" {
// ensure siteURL ends wth '/'
if lastChar := Config.siteURL[len(Config.siteURL)-1:]; lastChar != "/" {
@ -155,9 +167,9 @@ func setup() *web.Mux {
if Config.s3Bucket != "" {
storageBackend = s3.NewS3Backend(Config.s3Bucket, Config.s3Region, Config.s3Endpoint, Config.s3ForcePathStyle)
} else {
storageBackend = localfs.NewLocalfsBackend(Config.metaDir, Config.filesDir)
storageBackend = localfs.NewLocalfsBackend(Config.metaDir, Config.filesDir, Config.locksDir)
if Config.cleanupEveryMinutes > 0 {
go cleanup.PeriodicCleanup(time.Duration(Config.cleanupEveryMinutes)*time.Minute, Config.filesDir, Config.metaDir, Config.noLogs)
go cleanup.PeriodicCleanup(time.Duration(Config.cleanupEveryMinutes)*time.Minute, Config.filesDir, Config.metaDir, Config.locksDir, Config.noLogs)
}
}
@ -211,7 +223,9 @@ func setup() *web.Mux {
mux.Put(Config.sitePath+"upload/:name", uploadPutHandler)
mux.Delete(Config.sitePath+":name", deleteHandler)
// Adding new delete path method to make linx-server usable with ShareX.
mux.Get(Config.sitePath+"delete/:name", deleteHandler)
mux.Get(Config.sitePath+"static/*", staticHandler)
mux.Get(Config.sitePath+"favicon.ico", staticHandler)
mux.Get(Config.sitePath+"robots.txt", staticHandler)
@ -241,6 +255,8 @@ func main() {
"path to files directory")
flag.StringVar(&Config.metaDir, "metapath", "meta/",
"path to metadata directory")
flag.StringVar(&Config.locksDir, "lockspath", "locks/",
"path to locks directory")
flag.BoolVar(&Config.basicAuth, "basicauth", false,
"allow logging by basic auth password")
flag.BoolVar(&Config.noLogs, "nologs", false,
@ -257,6 +273,8 @@ func main() {
"maximum upload file size in bytes (default 4GB)")
flag.Uint64Var(&Config.maxExpiry, "maxexpiry", 0,
"maximum expiration time in seconds (default is 0, which is no expiry)")
flag.Uint64Var(&Config.defaultExpiry, "default-expiry", 86400,
"default expiration time in seconds (default is 86400, which is 1 day)")
flag.StringVar(&Config.certFile, "certfile", "",
"path to ssl certificate (for https)")
flag.StringVar(&Config.keyFile, "keyfile", "",
@ -283,7 +301,7 @@ func main() {
flag.StringVar(&Config.fileReferrerPolicy, "filereferrerpolicy",
"same-origin",
"value of Referrer-Policy header for file access")
flag.StringVar(&Config.xFrameOptions, "xframeoptions", "SAMEORIGIN",
flag.StringVar(&Config.xFrameOptions, "xframeoptions", "",
"value of X-Frame-Options header")
flag.Var(&Config.addHeaders, "addheader",
"Add an arbitrary header to the response. This option can be used multiple times.")
@ -304,7 +322,12 @@ func main() {
"path to directory containing .md files to render as custom pages")
flag.Uint64Var(&Config.cleanupEveryMinutes, "cleanup-every-minutes", 0,
"How often to clean up expired files in minutes (default is 0, which means files will be cleaned up as they are accessed)")
flag.StringVar(&Config.extraFooterText, "extra-footer-text", "",
"Extra text above the footer for notices.")
flag.Uint64Var(&Config.maxDurationTime, "max-duration-time", 0, "Time till expiry for files over max-duration-size. (Default is 0 for no-expiry.)")
flag.Int64Var(&Config.maxDurationSize, "max-duration-size", 4*1024*1024*1024, "Size of file before max-duration-time is used to determine expiry max time. (Default is 4GB)")
flag.BoolVar(&Config.disableAccessKey, "disable-access-key", false, "Disables access key usage. (Default is false.)")
flag.BoolVar(&Config.defaultRandomFilename, "default-random-filename", true, "Makes it so the random filename is not default if set false. (Default is true.)")
iniflags.Parse()
mux := setup()

View file

@ -33,6 +33,7 @@ func TestSetup(t *testing.T) {
Config.siteURL = "http://linx.example.org/"
Config.filesDir = path.Join(os.TempDir(), generateBarename())
Config.metaDir = Config.filesDir + "_meta"
Config.locksDir = Config.filesDir + "_locks"
Config.maxSize = 1024 * 1024 * 1024
Config.noLogs = true
Config.siteName = "linx"
@ -446,63 +447,6 @@ func TestPostJSONUpload(t *testing.T) {
}
}
func TestPostJSONUploadMaxExpiry(t *testing.T) {
mux := setup()
Config.maxExpiry = 300
// include 0 to test edge case
// https://github.com/andreimarcu/linx-server/issues/111
testExpiries := []string{"86400", "-150", "0"}
for _, expiry := range testExpiries {
w := httptest.NewRecorder()
filename := generateBarename() + ".txt"
var b bytes.Buffer
mw := multipart.NewWriter(&b)
fw, err := mw.CreateFormFile("file", filename)
if err != nil {
t.Fatal(err)
}
fw.Write([]byte("File content"))
mw.Close()
req, err := http.NewRequest("POST", "/upload/", &b)
req.Header.Set("Content-Type", mw.FormDataContentType())
req.Header.Set("Accept", "application/json")
req.Header.Set("Linx-Expiry", expiry)
if err != nil {
t.Fatal(err)
}
mux.ServeHTTP(w, req)
if w.Code != 200 {
t.Log(w.Body.String())
t.Fatalf("Status code is not 200, but %d", w.Code)
}
var myjson RespOkJSON
err = json.Unmarshal([]byte(w.Body.String()), &myjson)
if err != nil {
t.Fatal(err)
}
myExp, err := strconv.ParseInt(myjson.Expiry, 10, 64)
if err != nil {
t.Fatal(err)
}
expected := time.Now().Add(time.Duration(Config.maxExpiry) * time.Second).Unix()
if myExp != expected {
t.Fatalf("File expiry is not %d but %s", expected, myjson.Expiry)
}
}
Config.maxExpiry = 0
}
func TestPostExpiresJSONUpload(t *testing.T) {
mux := setup()
w := httptest.NewRecorder()
@ -1255,6 +1199,7 @@ func TestInferSiteURLHTTPSFastCGI(t *testing.T) {
func TestShutdown(t *testing.T) {
os.RemoveAll(Config.filesDir)
os.RemoveAll(Config.metaDir)
os.RemoveAll(Config.locksDir)
}
func TestPutAndGetCLI(t *testing.T) {

3
static/mdpages/Sample.md Normal file
View file

@ -0,0 +1,3 @@
A sample custom page for use with the custom pages plugin.
`custompagespath = /path/to/linx-server/static/mdpages`

View file

@ -1,3 +1,3 @@
User-agent: *
Allow: /$
Disallow: *

View file

@ -87,6 +87,11 @@ func renderTemplate(tpl *pongo2.Template, context pongo2.Context, r *http.Reques
context["sitepath"] = Config.sitePath
context["selifpath"] = Config.selifPath
context["custom_pages_names"] = customPagesNames
// Add the context for Config.extraFooterText
context["extra_footer_text"] = Config.extraFooterText
// Add the context for Config.disableAccessKey
context["disable_access_key"] = Config.disableAccessKey
context["default_randomize"] = Config.defaultRandomFilename
var a string
if Config.authFile == "" {

View file

@ -29,9 +29,8 @@
</div>
{% block content %}{% endblock %}
<div id="footer">
<a href="https://github.com/andreimarcu/linx-server">linx-server</a>
<p>{{ extra_footer_text }} </p><a href="https://github.com/zizzydizzymc/linx-server">linx-server</a>
</div>
</div>

View file

@ -2,6 +2,7 @@
{% block head %}
<meta property="og:audio" content="{{ siteurl }}{{ sitepath }}{{ selifpath }}{{ filename }}" />
<meta property="og:audio:secure_url" content="{{ siteurl }}{{ sitepath }}{{ selifpath }}{{ filename }}" />
{% endblock %}
{% block main %}

View file

@ -1,6 +1,7 @@
{% extends "base.html" %}
{% block head %}
<meta name="twitter:card" content="summary_large_image">
<meta property="og:image" content="{{ siteurl }}{{ sitepath }}{{ selifpath }}{{ filename }}" />
{% endblock %}
@ -8,4 +9,4 @@
<a href="{{ sitepath }}{{ selifpath }}{{ filename }}">
<img class="display-image" src="{{ sitepath }}{{ selifpath }}{{ filename }}" />
</a>
{% endblock %}
{% endblock %}

View file

@ -1,6 +1,7 @@
{% extends "base.html" %}
{% block head %}
<meta property="og:type" content="video.other">
<meta property="og:video" content="{{ siteurl }}{{ sitepath }}{{ selifpath }}{{ filename }}" />
{% endblock %}

View file

@ -21,19 +21,20 @@
<span class="hint--top hint--bounce"
data-hint="Replace the filename with random characters. The file extension is retained">
<label><input {% if forcerandom %} disabled {% endif %} name="randomize" id="randomize" type="checkbox"
checked /> Randomize filename</label>
{% if (default_randomize && !( forcerandom)) || forcerandom %} checked {% endif %} /> Randomize filename</label>
</span>
<div id="expiry">
<label>File expiry:
<select name="expires" id="expires">
{% for expiry in expirylist %}
<option value="{{ expiry.Seconds }}" {% if forloop.Last %} selected{% endif %}>
<option value="{{ expiry.Seconds }}" {% if (expiry.Seconds == expirydefault) %} selected {% endif %}>
{{ expiry.Human }}</option>
{% endfor %}
</select>
</label>
</div>
{% if disable_access_key != true %}
<div id="access_key">
<span class="hint--top hint--bounce"
data-hint="Require password to access (this does not encrypt the file but only limits access)">
@ -44,6 +45,7 @@
<input id="access_key_input" name="access_key" type="text" placeholder="Access password" />
</span>
</div>
{% endif %}
</div>
<div class="clear"></div>
</form>

View file

@ -14,14 +14,15 @@
id="extension" class="codebox" name='extension' type='text' value="" placeholder="txt" /></span>
</div>
<div>
{% if disable_access_key != true %}
<span class="hint--top hint--bounce" data-hint="Require password to access (leave empty to disable)">
<input class="codebox" name="access_key" type="text" placeholder="password" />
</span>
{% endif %}
<select id="expiry" name="expires">
<option disabled>Expires:</option>
{% for expiry in expirylist %}
<option value="{{ expiry.Seconds }}" {% if forloop.Last %} selected{% endif %}>{{ expiry.Human }}
<option value="{{ expiry.Seconds }}" {% if (expiry.Seconds == expirydefault) %} selected {% endif %}>{{ expiry.Human }}
</option>
{% endfor %}
</select>

View file

@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"log"
"net/http"
"net/url"
"path"
@ -22,7 +23,6 @@ import (
"github.com/gabriel-vasile/mimetype"
"github.com/zenazn/goji/web"
)
var FileTooLargeError = errors.New("File too large.")
var fileBlacklist = map[string]bool{
"favicon.ico": true,
@ -42,6 +42,7 @@ type UploadRequest struct {
deleteKey string // Empty string if not defined
randomBarename bool
accessKey string // Empty string if not defined
srcIp string // Empty string if not defined
}
// Metadata associated with a file as it would actually be stored
@ -60,7 +61,6 @@ func uploadPostHandler(c web.C, w http.ResponseWriter, r *http.Request) {
uploadHeaderProcess(r, &upReq)
contentType := r.Header.Get("Content-Type")
if strings.HasPrefix(contentType, "multipart/form-data") {
file, headers, err := r.FormFile("file")
if err != nil {
@ -91,11 +91,10 @@ func uploadPostHandler(c web.C, w http.ResponseWriter, r *http.Request) {
upReq.expiry = parseExpiry(r.PostFormValue("expires"))
upReq.accessKey = r.PostFormValue(accessKeyParamName)
if r.PostFormValue("randomize") == "true" {
upReq.randomBarename = true
}
upReq.srcIp = r.Header.Get("X-Forwarded-For")
upload, err := processUpload(upReq)
if strings.EqualFold("application/json", r.Header.Get("Accept")) {
@ -126,11 +125,11 @@ func uploadPostHandler(c web.C, w http.ResponseWriter, r *http.Request) {
func uploadPutHandler(c web.C, w http.ResponseWriter, r *http.Request) {
upReq := UploadRequest{}
uploadHeaderProcess(r, &upReq)
defer r.Body.Close()
upReq.filename = c.URLParams["name"]
upReq.src = http.MaxBytesReader(w, r.Body, Config.maxSize)
upReq.srcIp = r.Header.Get("X-Forwarded-For")
upload, err := processUpload(upReq)
if strings.EqualFold("application/json", r.Header.Get("Accept")) {
@ -195,14 +194,14 @@ func uploadRemote(c web.C, w http.ResponseWriter, r *http.Request) {
oopsHandler(c, w, r, RespAUTO, "Could not retrieve URL")
return
}
upReq.filename = filepath.Base(grabUrl.Path)
upReq.src = http.MaxBytesReader(w, resp.Body, Config.maxSize)
upReq.deleteKey = r.FormValue("deletekey")
upReq.accessKey = r.FormValue(accessKeyParamName)
upReq.randomBarename = r.FormValue("randomize") == "yes"
upReq.expiry = parseExpiry(r.FormValue("expiry"))
upReq.srcIp = r.Header.Get("X-Forwarded-For")
upload, err := processUpload(upReq)
if strings.EqualFold("application/json", r.Header.Get("Accept")) {
@ -231,11 +230,11 @@ func uploadRemote(c web.C, w http.ResponseWriter, r *http.Request) {
func uploadHeaderProcess(r *http.Request, upReq *UploadRequest) {
if r.Header.Get("Linx-Randomize") == "yes" {
upReq.randomBarename = true
} else {
upReq.randomBarename = false
}
upReq.deleteKey = r.Header.Get("Linx-Delete-Key")
upReq.accessKey = r.Header.Get(accessKeyHeaderName)
// Get seconds until expiry. Non-integer responses never expire.
expStr := r.Header.Get("Linx-Expiry")
upReq.expiry = parseExpiry(expStr)
@ -322,19 +321,45 @@ func processUpload(upReq UploadRequest) (upload Upload, err error) {
return upload, errors.New("Prohibited filename")
}
// Lock the upload
log.Printf("Lock %s", upload.Filename)
err = storageBackend.Lock(upload.Filename)
if err != nil {
return upload, err
}
// Get the rest of the metadata needed for storage
var fileExpiry time.Time
maxDurationTime := time.Duration(Config.maxDurationTime) * time.Second
if upReq.expiry == 0 {
fileExpiry = expiry.NeverExpire
if upReq.size > Config.maxDurationSize && maxDurationTime > 0 {
fileExpiry = time.Now().Add(maxDurationTime)
} else {
fileExpiry = expiry.NeverExpire
}
} else {
fileExpiry = time.Now().Add(upReq.expiry)
if upReq.size > Config.maxDurationSize && upReq.expiry > maxDurationTime {
fileExpiry = time.Now().Add(maxDurationTime)
} else {
fileExpiry = time.Now().Add(upReq.expiry)
}
}
if upReq.deleteKey == "" {
upReq.deleteKey = uniuri.NewLen(30)
}
if Config.disableAccessKey == true {
upReq.accessKey = ""
}
log.Printf("Write %s", upload.Filename)
upload.Metadata, err = storageBackend.Put(upload.Filename, io.MultiReader(bytes.NewReader(header), upReq.src), fileExpiry, upReq.deleteKey, upReq.accessKey, upReq.srcIp)
if err != nil {
return upload, err
}
upload.Metadata, err = storageBackend.Put(upload.Filename, io.MultiReader(bytes.NewReader(header), upReq.src), fileExpiry, upReq.deleteKey, upReq.accessKey)
// Unlock the upload
log.Printf("Unlock %s", upload.Filename)
err = storageBackend.Unlock(upload.Filename)
if err != nil {
return upload, err
}
@ -398,11 +423,11 @@ func barePlusExt(filename string) (barename, extension string) {
func parseExpiry(expStr string) time.Duration {
if expStr == "" {
return time.Duration(Config.maxExpiry) * time.Second
return time.Duration(Config.defaultExpiry) * time.Second
} else {
fileExpiry, err := strconv.ParseUint(expStr, 10, 64)
if err != nil {
return time.Duration(Config.maxExpiry) * time.Second
return time.Duration(Config.defaultExpiry) * time.Second
} else {
if Config.maxExpiry > 0 && (fileExpiry > Config.maxExpiry || fileExpiry == 0) {
fileExpiry = Config.maxExpiry