README.md (2809B)
1 # pastesrv
2
3 Please send patches or remarks to
4 [jayvii+pastesrv[AT]posteo[DOT]de](mailto:jayvii+pastesrv[AT]posteo[DOT]de)
5
6 Super simple selfhosted paste server inspired / copy-cat'ed from:
7 [codemadness](https://www.codemadness.org/paste-service.html)
8
9 ## Setup
10
11 Let's assume you are running Debian on your server, OpenSSH is already setup
12 and you are using Apache as your webserver with "paste.example.com".
13
14 Create a new user for the paste service on your server:
15
16 ```bash
17 useradd -d /var/www/pastesrv -G www-data -m paste
18 mkdir -p /var/www/pastesrv/paste
19 chown paste:www-data -R /var/www/pastesrv
20 chmod 770 -R /var/www/pastesrv
21 ```
22
23 Optionally, set a password for the "paste" user. Or instead, use an SSH-key.
24 See: [Arch Wiki: SSH keys](https://wiki.archlinux.org/title/SSH_keys)
25
26 Copy the apache-config and edit it accordingly
27
28 ```bash
29 cp pastesrv-apache.conf /etc/apache2/sites-available/
30 # now edit it accordingly
31 a2ensite pastesrv-apache
32 ```
33
34 Copy the index and 404 page to the web-root:
35
36 ```bash
37 cp index.html /var/www/pastesrv/paste/index.html
38 cp 404.html /var/www/pastesrv/paste/404.html
39 cp -r assets /var/www/pastesrv/paste/assets
40 ```
41
42 **Alternatively** you can also use the `index.php` file for your index page,
43 enables you to use a web-based uploader for pastes if the correct
44 authentification code is given:
45
46 ```bash
47 # use the PHP script rather than the HTML index page
48 rm /var/www/pastesrv/paste/index.html
49 cp index.php /var/www/pastesrv/paste/index.php
50 cp -r config /var/www/pastesrv/paste/config
51
52 # Replace MY-SECURE-PASSWORD with the password you want to use in the config
53 HASH=$(php ./config/create_hashed_pw.php "MY-SECURE-PASSWORD")
54 sed -e "s/PW_PLACEHOLDER/$HASH/" -i /var/www/pastesrv/paste/config/config.php
55 ```
56
57 The service is ready now. Next, setup your client accordingly. The codemadness
58 blog has a [nifty bash-function](https://www.codemadness.org/paste-service.html),
59 which I adapted a little bit. You can also find it in this repository as
60 `pastesrv.sh`:
61
62 ```bash
63 pastesrv() {
64 # set default file name if none is given
65 HASH=$(date +%s | sha256sum | awk '{ print $1 }')
66 # forward stdin to the server
67 ssh paste[AT]paste[DOT]example.com "cat > ~/paste/${1:-$HASH}"
68 # output for user
69 echo "https://paste.example.com/${1:-$HASH}"
70 }
71 ```
72
73 The function reads from stdin, so whatever you pipe to it, will be send to the
74 paste-service:
75
76 ```bash
77 # sending the current date to the server as unnamed paste
78 date | pastesrv
79
80 # sending some script file to the server as named paste
81 cat my_script.sh | pastesrv "check_out_my_script.sh"
82
83 # make a screenshot (wayland) and upload it immediately
84 grim - | pastesrv
85 ```
86
87 If you use the PHP index page, you can also upload pastes by adding the `?auth`
88 parameter to the URL in your web browser:
89
90 `https://paste.example.com?auth=MY-SECURE-PASSWORD`