Skip to content

lrstanley/links

Repository files navigation

logo

🔗 Table of Contents

💻 Installation

Check out the releases page for prebuilt versions.

🐳 Container Images (ghcr)

$ docker run -it --rm ghcr.io/lrstanley/links:master
$ docker run -it --rm ghcr.io/lrstanley/links:0.9.0
$ docker run -it --rm ghcr.io/lrstanley/links:latest
$ docker run -it --rm ghcr.io/lrstanley/links:0.8.0
$ docker run -it --rm ghcr.io/lrstanley/links:0.7.0
$ docker run -it --rm ghcr.io/lrstanley/links:0.6.0

🧰 Source

Note that you must have Go installed (latest is usually best).

$ git clone https://github.com/lrstanley/links.git && cd links
$ make
$ ./links --help

⚙️ Usage

$ links --help
Usage:
  links [OPTIONS] [add | delete]

Application Options:
  -s, --site-name=                      site url, used for url generation (default: https://links.wtf) [$SITE_URL]
      --session-dir=                    optional location to store temporary sessions [$SESSION_DIR]
  -q, --quiet                           don't log to stdout [$QUIET]
      --debug                           enable debugging (pprof endpoints) [$DEBUG]
  -b, --http=                           ip:port pair to bind to (default: :8080) [$HTTP]
  -p, --behind-proxy                    if X-Forwarded-For headers should be trusted [$PROXY]
  -d, --db=                             path to database file (default: store.db) [$DB_PATH]
      --key-length=                     default length of key (uuid) for generated urls (default: 4) [$KEY_LENGTH]
      --http-pre-include=               HTTP include which is included directly after css is included (near top of the page)
                                        [$HTTP_PRE_INCLUDE]
      --http-post-include=              HTTP include which is included directly after js is included (near bottom of the page)
                                        [$HTTP_POST_INCLUDE]
  -e, --export-file=                    file to export db to (default: links.export)
      --export-json                     export db to json elements
  -v, --version                         display the version of links.wtf and exit

TLS Options:
      --tls.enable                      run tls server rather than standard http [$TLS_ENABLE]
  -c, --tls.cert=                       path to ssl cert file [$TLS_CERT_PATH]
  -k, --tls.key=                        path to ssl key file [$TLS_KEY_PATH]

Safe Browsing Support:
      --safebrowsing.api-key=           Google API Key used for querying SafeBrowsing, disabled if not provided (see:
                                        https://github.com/lrstanley/links#google-safebrowsing) [$SAFEBROWSING_API_KEY]
      --safebrowsing.db=                path to SafeBrowsing database file (default: safebrowsing.db) [$SAFEBROWSING_DB_PATH]
      --safebrowsing.update-period=     duration between updates to the SafeBrowsing API local database (default: 1h)
                                        [$SAFEBROWSING_UPDATE_PERIOD]
      --safebrowsing.redirect-fallback  if the SafeBrowsing request fails (local cache, and remote hit), this still lets the
                                        redirect happen [$SAFEBROWSING_REDIRECT_FALLBACK]

Prometheus Metrics:
      --prom.enabled                    enable exposing of prometheus metrics (on std port, or --prometheus.addr) [$PROM_ENABLED]
      --prom.addr=                      expose on custom address/port, e.g. ':9001' (all ips) or 'localhost:9001' (local only)
                                        [$PROM_ADDR]
      --prom.endpoint=                  endpoint to expose metrics on (default: /metrics) [$PROM_ENDPOINT]

Help Options:
  -h, --help                            Show this help message

Available commands:
  add     add a link
  delete  delete a link, id, or link matching an author

Dot-env

Links also supports a .env file for loading environment variables. Example:

SAFEBROWSING_API_KEY=<your-secret-key>
FOO=BAR

Example

$ links -s "http://your-domain.com" -b "0.0.0.0:80" -d links.db

Google SafeBrowsing

Links supports utilizing Google SafeBrowsing, (see Safe Browsing Support under ##Usage). This helps prevent users being redirected to malicious or otherwise harmful websites. It does require a Google Developer account (free).

  1. Go to the Google Developer Console
  2. Create a new project (dropdown top left, click NEW PROJECT)
  3. Enable the "Safe Browsing" API
  4. Create a new credential (API key)

Screenshot example:

Using as a library

Links also has a Go client library which you can use, which adds a simple wrapper around an http call, to make shortening links simpler. Download it using the following go get command:

$ go get -u github.com/lrstanley/links/client

View the documentation here

Example

package main

import (
	"fmt"
	"log"

	links "github.com/lrstanley/links/client"
)

func main() {
	uri, err := links.Shorten("https://your-long-link.com/longer/link", "", nil)
	if err != nil {
		log.Fatalf("unable to shorten link: %s", err)
	}

	fmt.Printf("shortened: %s
", uri.String())
}

API

Shortening a link is quite easy. simply send a POST request to https://example.com/add, which will return JSON-safe information as shown below:

$ curl --data "url=http://google.com" https://example.com/add
{"url": "https://example.com/27f4", "success": true}

Password protection

You can also password protect a link, simply by adding a password variable to the payload:

$ curl --data 'url=https://google.com/example&encrypt=y0urp4$$w0rd' https://example.com/add
{"url": "https://example.com/abc123", "success": true}

🙋‍♂️ Support & Assistance

  • ❤️ Please review the Code of Conduct for guidelines on ensuring everyone has the best experience interacting with the community.
  • 🙋‍♂️ Take a look at the support document on guidelines for tips on how to ask the right questions.
  • 🐞 For all features/bugs/issues/questions/etc, head over here.

🤝 Contributing

  • ❤️ Please review the Code of Conduct for guidelines on ensuring everyone has the best experience interacting with the community.
  • 📋 Please review the contributing doc for submitting issues/a guide on submitting pull requests and helping out.
  • 🗝️ For anything security related, please review this repositories security policy.

⚖️ License

MIT License

Copyright (c) 2014 Liam Stanley <me@liamstanley.io>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Also located here