paste.cf

This is a public pastebin server. You may upload files up to 10MB in size and have them shared publically. FTP is used to upload files to the server.

The very minimal code needed for this server is open sourced under the 3-Clause BSD License and can be found further down on this page or at this git repo. The full license can be found at paste.cf/LICENSE.md

Why

I often paste things (code, text, logs, pics, gifs, etc) I want to share with friends, forums, or irc online, but it feels like every time I got used to a pastebin or imagehosting site it went down or had major issues within a year or two. So I figured I could spare a few dollars a month on a vps to host my own paste server as that's the only way you KNOW it will last.

Turns out all the paste server software out there I could find was very bloated. A paste server doesn't need frameworks, dynamic servers, ads, fluff, a web gui, fonts, or complex slow clients. FTP, an HTTP server, inotify, cron, and 2 <100 line scripts is the most it should ever be. That will ensure your paste server never requires more than a cheap $5 vps even with thousands of uploads per day.

Usage

Uploading to paste.cf is quite simple. Using your favourite FTP client you can ftp paste.cf, cd incoming (the public upload directory), and put file.whatever then run sha1sum on your file and the public address will be paste.cf/yoursha1.extension

Your pastes will be deleted eventually. Storage space costs money; if you need your files hosted forever read the section below and have your own private server running very easily.

To make uploading a bit quicker I wrote a tiny client that FTPs the file to the server, calculates the hash, and prints what the resulting url should be. Basically pcf notes.md will return the (soon to be) live url. Then you can download the client here or scroll further down to read the code. Obviously you can combine pcf with other programs to do cool stuff. Like take a screenshot, upload it, and put the url in your clipboard. scrot -q 85 scrot.png && pcf scrot.png | xclip -in -selection c At some point I plan on creating a video showing off some usage of paste.cf.

How

This server runs an FTP server configured to allow public uploads into a specific directory. It also runs a simple static web server. That public FTP directory is watched for linux inotify updates with incrond. Incrond is configured to run a python script (found below) when new files are placed in the public FTP directory. The script only does a few things. First it checks that the file is under 10Mb (the size can be specified). Then it caculates the sha1sum of the file and renames + moves the file into the web server's public directory (wherever you specify that to be).

Additionally the server uses cron to run another script once every hour. This script checks if the disk usage is above a certain percentage, if so it deletes uploaded files based on age That script can also be found below.

With basic computer knowledge you should be able to duplicate this server for yourself (and even have your own private version if you'd like). Below are basic setup instructions as well as the aforementioned scripts.

  1. Install a reasonable server operating system. My favourites are alpine, debian, and arch. Linux 2.6.13+ will make this much easier, but with some effort this can be setup on *BSD.
  2. Install cron, incron, an ftp server (or sftp for a private server), a web server, and python 3.
  3. Optionally get a domain name to point to your server and use letsencrypt to get a free https cert.
  4. Configure your ftp server to allow anonymous uploads. Or use sftp and setup a user plus keys to make things easier for yourself. You probably wont need to do any web server configuration (other than maybe adding the ssl certs from above). You simply need to know which directory is being served. It is probably /var/www/html/ or similar.
  5. Create a user on your server to run the scripts. On debian adduser --no-create-home paste will do that.
  6. Make sure incrond and crond are running on your system and enabled at startup. On debian they are enabled and running if you installed them with apt, you can verify with systemctl status crond, figure out how the init system on your operating system works and this should be pretty simple.
  7. Add the rename.py script to your system and make sure it's marked executable chmod +x rename.py. Do the same thing for remove.py.
  8. Login as your paste user, su paste, then edit your incron tab with incrontab -e so that it says something like /public/ftp/directory/here/ IN_CLOSE_WRITE,IN_MOVE_TO /path/to/rename.py --file $# --hold /public/ftp/directory --web /public/web/directory --max 10. Read incrontab(1), incrontab(5), and rename.py --help for more info. If you we're unable to run incrontab -e you probably need to add your username to /etc/incron.allow
  9. Now for remove.py, edit the script so that the web_dir variable at the top points to the webdirectory with all the pictures. Then you can simply place the script in /etc/cron.hourly/ if that doesn't exist on your system you'll need to also edit your cron tab to run that script once per hour.
  10. Consider donating to one or more of the open source projects you used to build your paste server, without them much of the internet would not exist.

Scripts

  1. rename.py
  2. remove.py
  3. pcf.py

Privacy and Permanency

Do not upload anything which must remain private to paste.cf as everything that is uploaded is public.

Additionally anything you upload may be removed at any time so do not rely on paste.cf as your only copy of something important. The fact that things can be removed does not guarantee their removal. In fact virtually any uploaded file could be crawled and archived elsewhere.

Finally it should be noted that the FTP server running on paste.cf is configured to log IPs for each uploaded file. Meaning if illegal content is uploaded and the authories send me a letter I'm handing them your IP. I'm a broke ass college student and I'm simply not interested in fighting your legal battles for you.

You have been warned. If you need to upload something private or permanent follow the instructions above and setup your own paste server. A server just like this one can be rented for $5 a month and give you and your mates plenty of bandwidth and storage.