back

pub / pastesrv

Paste service setup for paste.jayvii.de
git clone https://src.jayvii.de/pub/pastesrv.git
Home | Log | Files | Exports | Refs | README | RSS

Activity: Jun, 2024 - Aug, 2024

Less More

pastesrv

Please send patches or remarks to jayvii+pastesrv[AT]posteo[DOT]de

Super simple selfhosted paste server inspired / copy-cat’ed from: codemadness

Setup

Let’s assume you are running Debian on your server, OpenSSH is already setup and you are using Apache as your webserver with “paste.example.com”.

Create a new user for the paste service on your server:

useradd -d /var/www/pastesrv -G www-data -m paste
mkdir -p /var/www/pastesrv/paste
chown paste:www-data -R /var/www/pastesrv
chmod 770 -R /var/www/pastesrv

Optionally, set a password for the “paste” user. Or instead, use an SSH-key. See: Arch Wiki: SSH keys

Copy the apache-config and edit it accordingly

cp pastesrv-apache.conf /etc/apache2/sites-available/
# now edit it accordingly
a2ensite pastesrv-apache

Copy the index and 404 page to the web-root:

cp index.html /var/www/pastesrv/paste/index.html
cp 404.html /var/www/pastesrv/paste/404.html
cp -r assets /var/www/pastesrv/paste/assets

Alternatively you can also use the index.php file for your index page, enables you to use a web-based uploader for pastes if the correct authentification code is given:

# use the PHP script rather than the HTML index page
rm /var/www/pastesrv/paste/index.html
cp index.php /var/www/pastesrv/paste/index.php
cp -r config /var/www/pastesrv/paste/config

# Replace MY-SECURE-PASSWORD with the password you want to use in the config
HASH=$(php ./config/create_hashed_pw.php "MY-SECURE-PASSWORD")
sed -e "s/PW_PLACEHOLDER/$HASH/" -i /var/www/pastesrv/paste/config/config.php

The service is ready now. Next, setup your client accordingly. The codemadness blog has a nifty bash-function, which I adapted a little bit. You can also find it in this repository as pastesrv.sh:

pastesrv() {
# set default file name if none is given
HASH=$(date +%s | sha256sum | awk '{ print $1 }')
# forward stdin to the server
ssh paste[AT]paste[DOT]example.com "cat > ~/paste/${1:-$HASH}"
# output for user
echo "https://paste.example.com/${1:-$HASH}"
}

The function reads from stdin, so whatever you pipe to it, will be send to the paste-service:

# sending the current date to the server as unnamed paste
date | pastesrv

# sending some script file to the server as named paste
cat my_script.sh | pastesrv "check_out_my_script.sh"

# make a screenshot (wayland) and upload it immediately
grim - | pastesrv

If you use the PHP index page, you can also upload pastes by adding the ?auth parameter to the URL in your web browser:

https://paste.example.com?auth=MY-SECURE-PASSWORD


Clone this repository via:
git clone https://src.jayvii.de/pub/pastesrv.git