diff --git a/README.md b/README.md index 90f58aa..6bba28f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,121 @@ -Fork of [link](https://fsh.ee/) which adds query-string support. +Fork of [link](https://fsh.ee/) with extra features, a filesystem-based backend, and more. Please access this project on my [Gitea](https://git.swurl.xyz/swirl/link) instance, NOT GitHub. + +# Self-Hosting +You can host this yourself. + +Note: all commands here are done as root. + +## Building & Installing +To build this project, you'll need [Go](https://golang.org/doc/install) and [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git). Most Linux distributions should have these in their repositories, i.e.: +- `pacman -S go git` +- `emerge --ask dev-lang/go dev-vcs/git` +- `apt install go git` + +1. Clone this repository: + +```bash +git clone https://git.swurl.xyz/swirl/link && cd link +``` + +2. Compile: +```bash +make +``` + +3. Now, you need to install. NGINX and systemd files are provided in this project; you may choose not to install them. + +For all install commands, you may optionally provide `prefix` and `DESTDIR` options. This is useful for packagers; i.e. for a PKGBUILD: `make prefix=/usr DESTDIR=${pkgdir} install`. + +Available install commands are as follows: +- `make install` installs the executable, NGINX, and systemd files. +- `make install-bin` installs the executable file. +- `make install-systemd` installs the systemd file, as well as its environment file. +- `make install-nginx` installs the NGINX file. + +For example, on a non-systemd system using NGINX, you would run `make install-bin install-nginx`. + +4. If using systemd, change the environment file to reflect your desired options: +```bash +vim /etc/link.conf +``` + +5. You can now enable and start the service: +```bash +systemctl enable --now link +``` + +The server should now be running on localhost at port 8080. + +## NGINX Reverse Proxy +An NGINX file is provided with this project. Sorry, no support for Apache or lighttpd or anything else; should've chosen a better HTTP server. + +For this, you'll need [NGINX](https://nginx.org/en/download.html) (obviously), certbot, and its NGINX plugin. Most Linux distributions should have these in their repositories, i.e.: +- `pacman -S nginx certbot-nginx` +- `emerge --ask www-servers/nginx app-crypt/certbot-nginx` +- `apt install nginx python-certbot-nginx` + +This section assumes you've already followed the last. + +1. Change the domain in the NGINX file: +```bash +sed -i 's/your.doma.in/[DOMAIN HERE]' /etc/nginx/sites-available/link +``` + +2. Enable the site: +```bash +ln -s /etc/nginx/sites-{available,enabled}/link +``` + +3. Enable HTTPS for the site: +```bash +certbot --nginx -d [DOMAIN HERE] +``` + +4. Enable and start NGINX: +```bash +systemctl enable --now nginx +``` + +If it's already running, reload: +```bash +systemctl reload nginx +``` + +Your site should be running at https://your.doma.in. Test it by going there, and trying the examples. If they don't work, open an issue. + +# Contributions +Contributions are always welcome. + +# FAQ +## A user has made a link to a bad site! What do I do? +Clean it up, janny! + +Deleting a link can be done simply by running: +```bash +rm /srv/link/*/BADLINKHERE +``` + +Replace `/srv/link` with whatever your data directory is. + +## Can I prevent users from making links to specific sites (i.e. illegal content)? +Not currently. Might implement this in the future. + +## Can I run this in a subdirectory of my site? +Yes. Simply put the `proxy_pass` directive in a subdirectory, i.e.: +``` +location /shortener { + proxy_pass http://localhost:8080; +} +``` + +## Why'd you make this fork? +While link was by far the best link shortener I could find, it had a few problems: +- No query-string support: had to make POST requests +- Didn't decode URLs +- SQLite is not the greatest storage method out there +- No pre-provided systemd or NGINX files +- No `install` target for the makefile + +The first two are mostly problems when using them with specific services; i.e. PrivateBin, which expects to be able to use query-strings and encoded URLs. diff --git a/doc/link.conf b/doc/link.conf index 2a9a4dd..c64367a 100644 --- a/doc/link.conf +++ b/doc/link.conf @@ -1,6 +1,7 @@ -BIN="BINDIR/BINNAME" # replace this with the path to link (usually /usr/local/bin/linkserv by default) +BIN="BINDIR/BINNAME" +# replace this with the path to link (usually /usr/local/bin/linkserv by default) COPY="2021 you@your.doma.in" -DB="/srv/link/link.db" +DIR="/srv/link/" PORT=8080 SEED="secret" URL="https://your.doma.in" diff --git a/doc/link.service b/doc/link.service index 22576d9..5ed94a8 100644 --- a/doc/link.service +++ b/doc/link.service @@ -4,7 +4,7 @@ After=network.target [Service] EnvironmentFile=/etc/link.conf -ExecStart=/bin/sh -c '"${BIN}" -copy "${COPY}" -db "${DB}" -port ${PORT} -seed "${SEED}" -url "${URL}"' +ExecStart=/bin/sh -c '"${BIN}" -copy "${COPY}" -path "${DIR}" -port ${PORT} -seed "${SEED}" -url "${URL}"' [Install] WantedBy=multi-user.target diff --git a/go.mod b/go.mod index 0e543fc..1075be3 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,3 @@ module git.swurl.xyz/swirl/link go 1.16 - -require ( - golang.org/dl v0.0.0-20210805175753-70f86bf65abd // indirect - gorm.io/driver/sqlite v1.1.4 - gorm.io/gorm v1.21.9 -) diff --git a/go.sum b/go.sum index 1231ce5..e69de29 100644 --- a/go.sum +++ b/go.sum @@ -1,14 +0,0 @@ -github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= -github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= -github.com/jinzhu/now v1.1.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= -github.com/jinzhu/now v1.1.2 h1:eVKgfIdy9b6zbWBMgFpfDPoAMifwSZagU9HmEU6zgiI= -github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= -github.com/mattn/go-sqlite3 v1.14.5 h1:1IdxlwTNazvbKJQSxoJ5/9ECbEeaTTyeU7sEAZ5KKTQ= -github.com/mattn/go-sqlite3 v1.14.5/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI= -golang.org/dl v0.0.0-20210805175753-70f86bf65abd h1:zTi7rOU7NMmBInGr/IFQrDXBgYZ2VCO7BlylmxGpQTs= -golang.org/dl v0.0.0-20210805175753-70f86bf65abd/go.mod h1:IUMfjQLJQd4UTqG1Z90tenwKoCX93Gn3MAQJMOSBsDQ= -gorm.io/driver/sqlite v1.1.4 h1:PDzwYE+sI6De2+mxAneV9Xs11+ZyKV6oxD3wDGkaNvM= -gorm.io/driver/sqlite v1.1.4/go.mod h1:mJCeTFr7+crvS+TRnWc5Z3UvwxUN1BGBLMrf5LA9DYw= -gorm.io/gorm v1.20.7/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw= -gorm.io/gorm v1.21.9 h1:INieZtn4P2Pw6xPJ8MzT0G4WUOsHq3RhfuDF1M6GW0E= -gorm.io/gorm v1.21.9/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0= diff --git a/index.html b/index.html index c93ce1b..f88b866 100644 --- a/index.html +++ b/index.html @@ -1,17 +1,17 @@ - A Minimal, SQLite-Backed URL Shortener + A Minimal, Filesystem-Backed URL Shortener - +
-A Minimal, SQLite-Backed URL Shortener +A Minimal, Filesystem-Backed URL Shortener