Link shortener in Rust. https://s.42l.fr/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
neil 730be29377 Updating instructions and contributing guide 1 month ago
assets way lighter background, 1.3MB -> 0.38MB 1 month ago
db Don't delete the db folder; don't push blacklists 1 month ago
migrations Initial commit, version 1.0.0 1 month ago
src 1.1.0 release 1 month ago
templates Initial commit, version 1.0.0 1 month ago
.gitignore Don't delete the db folder; don't push blacklists 1 month ago
Cargo.toml 1.1.0 release 1 month ago
LICENSE Initial commit, version 1.0.0 1 month ago
README.md Updating instructions and contributing guide 1 month ago
lang.json 1.1.0 release 1 month ago

README.md

rs-short

Link shortener in Rust.

Developed to be as minimalist and lightweight as possible.

Powered by the Rocket framework using (server-side) Handlebars templates.

  • Less than 1000 lines of code, including 20% of comments
  • Consumes between 5MB and 20MB of RAM
  • No JS
  • No CSS framework ; CSS is handmade and all rules are prefixed to avoid rule conflicts
  • No tracking features at all
  • No unsafe block

Features:

  • Includes a captcha as a minimal protection against spamming
  • Easily customizable assets
  • Only needs a SQLite database to work
  • Localization (available in French and English)
  • Counting clicks
  • Allows shortcut deletion

Official instance: https://s.42l.fr/

Running an instance

First, you must install Cargo and the latest stable version of Rust by following the instructions on this website. Alternatively, you can use the liuchong/rustup Docker image.

  • Clone the project:
git clone https://git.42l.fr/42l/rs-short.git
  • Edit what you need. You might want to change the following elements:

    • constant INSTANCE_HOSTNAME in main.rs: replace with your instance hostname
    • constant HOSTER_HOSTNAME in main.rs: replace with the hostname of the organization hosting the project
    • assets/hoster-logo.png: replace with the logo of your organization
    • assets/logo.svg: the software logo
    • assets/background.jpg: the default background
  • Create a file named Rocket.toml at the project root, containing the following:

[global]
address = "<ADDRESS>"
template_dir = "templates"
secret_key = "<SECRET KEY>"

[global.databases.sqlite_database]
url = "db/db.sqlite"
  • Replace <ADDRESS> by the address to listen on
  • Replace <SECRET KEY> by the result of the command openssl rand -base64 32
  • Eventually change the database storage path. You can specify more parameters following the Rocket documentation.

  • Create the banned_url_to.list file and enter keywords that causes IPs submitting links to get a 403 Forbidden if their links contain those keywords. Example:

://bit.ly
google

You can configure a fail2ban instance to watch your favourite reverse-proxy logs to see which IPs are getting a 403 and ban accordingly.

  • cargo run --release

Contributing

The initial version of the software has been developed in one week ; there’s still a lot to do.

Here are many ways to contribute:

  • Translate!
    • Add your entries in the lang.json file.
    • Once you’re done, edit templates.rs and add your language in the ValidLanguages structure.
  • Improve the software modularity
    • Add a configuration file
    • Configure instance and hoster’s hostname from the configuration file
    • Toggle captcha
  • Add postgresql compatibility
  • Add different CSS themes (a dark theme would be a great start!)
  • Develop a more resilient protection to spambots
    • Improve hostname blacklisting ?
    • Blacklist shortcut names ?
    • Integrate a ban / ratelimiting system ? (the current system relies entirely on a separate fail2ban instance)
  • Clean up the code
    • Restructure the rocket routes in main.rs to something more readable
    • Make a better usage of template contexts
    • Improve the forms if you’re knowledgeable in Rocket forms
    • Separate the code into more files if necessary

This software is mainly developed and maintained by Neil for the Association 42l.

If you like the work done on this project, please consider to donate or join the association. Thank you!

Graphical credits