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

commit 78e2c60e82be30d42b3c11cb61999a1e24acb4e7
parent 2a79f1d6301e26c804c58a758db012fd142dc737
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date:   Tue,  6 Aug 2024 12:19:17 +0200

feat: add option for a PHP uploader

Diffstat:
MREADME.md | 23+++++++++++++++++++++--
Aconfig/config.php | 8++++++++
Mindex.html | 55+++++++++++++++++++++++++++++++++++++++++++++++++------
Aindex.php | 103+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpastesrv.sh | 20+++++++++++++-------
5 files changed, 194 insertions(+), 15 deletions(-)

diff --git a/README.md b/README.md @@ -1,7 +1,7 @@ # pastesrv Please send patches or remarks to -[jayvii[AT]posteo[DOT]de](mailto:jayvii[AT]posteo[DOT]de) +[jayvii[stesrvAT]posteo[DOT]de](mailto:jayvii+pastesrv[AT]posteo[DOT]de) Super simple selfhosted paste server inspired / copy-cat'ed from: [codemadness](https://www.codemadness.org/paste-service.html) @@ -20,7 +20,7 @@ chown paste:www-data -R /var/www/pastesrv chmod 770 -R /var/www/pastesrv ``` -Optionally, set a password for the "paste" user. Or, better yet use an SSH-key. +Optionally, set a password for the "paste" user. Or instead, use an SSH-key. See: [Arch Wiki: SSH keys](https://wiki.archlinux.org/title/SSH_keys) Copy the apache-config and edit it accordingly @@ -38,6 +38,21 @@ cp index.html /var/www/pastesrv/paste/index.html cp 404.html /var/www/pastesrv/paste/404.html ``` +**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: + +```bash +# 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=$(echo "MY-SECURE-PASSWORD" | sha256sum | awk '{print $1}') +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](https://www.codemadness.org/paste-service.html), which I adapted a little bit. You can also find it in this repository as @@ -68,3 +83,7 @@ paste-service: 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` diff --git a/config/config.php b/config/config.php @@ -0,0 +1,8 @@ +<?php + +/* Set password as SHA-256 string. In bash: +echo "MY-SECURE-PASSWORD" | sha256sum | awk '{print $1}' +*/ +$auth="PW_PLACEHOLDER"; + +?> diff --git a/index.html b/index.html @@ -1,5 +1,6 @@ <!DOCTYPE html> <html lang="en"> + <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> @@ -7,18 +8,60 @@ <link rel="stylesheet" type="text/css" href="/assets/css/simple.min.css" /> <title>pastesrv</title> </head> + <body> + <header> <h1>pastesrv</h1> + <a class="button" href="/"> + Home + </a> + <a class="button" href="#about"> + About + </a> + <a href="button" href="#how"> + How + </a> <a class="button" href="https://src.jayvii.de/pub/pastesrv"> Source </a> </header> - <section> - <p> - Super simple selfhosted paste server, based around minimal and basic - tools, which you can selfhost within seconds without much effort. - </p> - </section> + + <!-- About Section --> + <section id="about"> + <h2>About pastesrv</h2> + <p> + Super simple selfhosted paste server, based around minimal and basic + tools, which you can selfhost within seconds without much effort. + </p> + </section> + + <!-- How To Use --> + <section id="how"> + <h2>How to use</h2> + <p> + The original functionality is described in a blogpost on + <a + href="https://www.codemadness.org/paste-service.html" + target="_blank" + > + codemadness.org + </a> + </p> + <p> + Using the + <code> + <a + href="https://src.jayvii.de/pub/pastesrv/file/pastesrv.sh.html" + target="_blank" + > + pastesrv.sh + </a> + </code> + function, you can pipe any content to the paste service through SSH. + </p> + </section> + </body> + </html> diff --git a/index.php b/index.php @@ -0,0 +1,103 @@ +<!DOCTYPE html> +<html lang="en"> + + <head> + <meta charset="UTF-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <link rel="stylesheet" type="text/css" href="/assets/css/simple.min.css" /> + <title>pastesrv</title> + </head> + + <body> + + <header> + <h1>pastesrv</h1> + <a class="button" href="/"> + Home + </a> + <a class="button" href="#about"> + About + </a> + <a href="button" href="#how"> + How + </a> + <a class="button" href="https://src.jayvii.de/pub/pastesrv"> + Source + </a> + </header> + + <!-- About Section --> + <section id="about"> + <h2>About pastesrv</h2> + <p> + Super simple selfhosted paste server, based around minimal and basic + tools, which you can selfhost within seconds without much effort. + </p> + </section> + + <!-- How To Use --> + <section id="how"> + <h2>How to use</h2> + <p> + The original functionality is described in a blogpost on + <a + href="https://www.codemadness.org/paste-service.html" + target="_blank" + > + codemadness.org + </a> + </p> + <p> + Using the + <code> + <a + href="https://src.jayvii.de/pub/pastesrv/file/pastesrv.sh.html" + target="_blank" + > + pastesrv.sh + </a> + </code> + function, you can pipe any content to the paste service through SSH. + </p> + </section> + + <?php + /* Load Configuration */ + include("config/config.php"); + /* If auth is successfull, show uploader or process file */ + if (hash("sha256", $_GET["auth"]) === $auth_hash) { + ?> + + <!-- Uploader --> + <section id="upload"> + <h2>Upload File</h2> + <p> + You may also upload a file here directly + </p> + <form action="index.php" target="_self" method="post"> + <input id="file" name="file" type="file"> + <input type="submit" value="Paste!"> + </form> + </section> + + <?php + + /* Process file if available */ + if (!is_null($_FILES["file"]["tmp_name"])) { + + /* Create Hash Name */ + $hash = hash("sha256", time()); + + /* Move file to designated place */ + move_uploaded_file($_FILES["file"]["tmp_name"], "./" . $hash); + + } /* File exists */ + + } /* Auth is correct */ + + ?> + + </body> + +</html> diff --git a/pastesrv.sh b/pastesrv.sh @@ -1,12 +1,18 @@ #!/usr/bin/env bash +# SPDX-License-Identifier: AGPL-3.0-or-later +# SPDX-FileCopyrightText: 2024 JayVii <jayvii[AT]posteo[DOT]de> +# SPDX-FileCopyrightText: 2024 Codemadness <hiltjo[AT]codemadness[DOT]org> -# put following function in your ~/.bashrc +# put following function in your ~/.bashrc and adjust accordingly 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}" + # configuration: adjust accordingly + SSH_PASTESRV="paste[AT]paste[DOT]example.com" + WEB_PASTESRV="https://paste.example.com" + # set default file name if none is given + HASH=$(date +%s | sha256sum | awk '{ print $1 }') + # forward stdin to the server + ssh "$SSH_PASTESRV" "cat > ~/paste/${1:-$HASH}" + # output for user + echo "File available under: $WEB_PASTESRV/${1:-$HASH}" }