├── .gitignore
├── .htaccess
├── README.md
├── _tmp
└── .htaccess
├── favicon.ico
├── favicon.svg
└── index.php
/.gitignore:
--------------------------------------------------------------------------------
1 | /_tmp/
2 |
--------------------------------------------------------------------------------
/.htaccess:
--------------------------------------------------------------------------------
1 | Options -Indexes
2 | RewriteEngine On
3 | RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?note=$1 [QSA]
4 |
5 |
6 | Header set X-Robots-Tag: "noindex, nofollow"
7 |
8 |
9 | # Uncomment the lines below to enable basic authentication.
10 | # See https://httpd.apache.org/docs/current/programs/htpasswd.html for generating your .htpasswd
11 |
12 | # AuthType basic
13 | # AuthName "website.name"
14 | # AuthUserFile "/home/user/update-path-to.htpasswd"
15 | # Require valid-user
16 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Minimalist Web Notepad
2 |
3 | This is an open-source clone of the now-defunct notepad.cc: "a piece of paper in the cloud".
4 |
5 | See demo at https://notes.orga.cat or https://notes.orga.cat/whatever.
6 |
7 | ## Installation
8 |
9 | Make sure the web server is allowed to write to the `_tmp` directory.
10 |
11 | ### On Apache
12 |
13 | You may need to enable mod_rewrite and allow `.htaccess` files in your site configuration.
14 | See [How To Set Up mod_rewrite for Apache](https://www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-14-04).
15 |
16 | ### On Nginx
17 |
18 | To enable URL rewriting, put something like this in your configuration file:
19 |
20 | If the project resides in the root directory:
21 | ```
22 | location / {
23 | rewrite ^/([a-zA-Z0-9_-]+)$ /index.php?note=$1;
24 | }
25 | ```
26 |
27 | If the project resides in a subdirectory:
28 | ```
29 | location ~* ^/notes/([a-zA-Z0-9_-]+)$ {
30 | try_files $uri /notes/index.php?note=$1;
31 | }
32 | ```
33 |
34 | If parameters need to be passed in Nginx (such as `?raw`), then `&$args` needs to be added to the end of the `$1` match:
35 | ```
36 | location ~* ^/notes/([a-zA-Z0-9_-]+)$ {
37 | try_files $uri /notes/index.php?note=$1&$args;
38 | }
39 | ```
40 |
41 | ## Usage (CLI)
42 |
43 | Using the command-line interface you can both save and retrieve notes. Here are some examples using `curl`:
44 |
45 | Retrieve a note's content and save it to a local file:
46 |
47 | ```
48 | curl https://example.com/notes/test > test.txt
49 | ```
50 |
51 | Save specific text to a note:
52 |
53 | ```
54 | curl https://example.com/notes/test -d 'hello,
55 |
56 | welcome to my pad!
57 | '
58 | ```
59 |
60 | Save the content of a local file (e.g., `/etc/hosts`) to a note:
61 |
62 | ```
63 | cat /etc/hosts | curl https://example.com/notes/hosts --data-binary @-
64 | ```
65 |
66 | ## Copyright and license
67 |
68 | Copyright 2012 Pere Orga
69 |
70 | Licensed under the Apache License, Version 2.0 (the "License");
71 | you may not use this work except in compliance with the License.
72 | You may obtain a copy of the License at:
73 |
74 | http://www.apache.org/licenses/LICENSE-2.0
75 |
76 | Unless required by applicable law or agreed to in writing, software
77 | distributed under the License is distributed on an "AS IS" BASIS,
78 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
79 | See the License for the specific language governing permissions and
80 | limitations under the License.
81 |
--------------------------------------------------------------------------------
/_tmp/.htaccess:
--------------------------------------------------------------------------------
1 |
2 | Require all denied
3 |
4 |
5 | Order allow,deny
6 |
7 |
--------------------------------------------------------------------------------
/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pereorga/minimalist-web-notepad/d630977d4b797e37110a5312feb4f7bf83b41029/favicon.ico
--------------------------------------------------------------------------------
/favicon.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/index.php:
--------------------------------------------------------------------------------
1 | 64 || !preg_match('/^[a-zA-Z0-9_-]+$/', $_GET['note'])) {
12 |
13 | // Generate a name with 5 random unambiguous characters. Redirect to it.
14 | header("Location: " . substr(str_shuffle('234579abcdefghjkmnpqrstwxyz'), -5));
15 | die;
16 | }
17 |
18 | $path = $save_path . '/' . $_GET['note'];
19 |
20 | if ($_SERVER['REQUEST_METHOD'] === 'POST') {
21 | $text = isset($_POST['text']) ? $_POST['text'] : file_get_contents("php://input");
22 | // Update file.
23 | file_put_contents($path, $text);
24 |
25 | // If provided input is empty, delete file.
26 | if (!strlen($text)) {
27 | unlink($path);
28 | }
29 | die;
30 | }
31 |
32 | // Print raw file when explicitly requested, or if the client is curl or wget.
33 | if (isset($_GET['raw']) || strpos($_SERVER['HTTP_USER_AGENT'], 'curl') === 0 || strpos($_SERVER['HTTP_USER_AGENT'], 'Wget') === 0) {
34 | if (is_file($path)) {
35 | header('Content-type: text/plain');
36 | readfile($path);
37 | } else {
38 | header('HTTP/1.0 404 Not Found');
39 | }
40 | die;
41 | }
42 | ?>
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
97 |
98 |
99 |