Compare commits

..
10 Commits
Author SHA1 Message Date
tanner 5734ae1c2f Upgrade dependencies 2024-06-30 19:41:58 +00:00
tanner 45f6240849 Add dark mode, viewport meta 2024-02-26 01:32:37 +00:00
Tanner Collin 69a12c1352 Merge pull request #1 from tannercollin/dependabot/pip/jinja2-2.11.3
Bump jinja2 from 2.10.1 to 2.11.3
2022-06-12 21:29:46 +00:00
tanner 21f2c45d89 Add Captcha to t0url 2022-06-12 21:22:58 +00:00
dependabot[bot] 084535544f Bump jinja2 from 2.10.1 to 2.11.3
Bumps [jinja2](https://github.com/pallets/jinja) from 2.10.1 to 2.11.3.
- [Release notes](https://github.com/pallets/jinja/releases)
- [Changelog](https://github.com/pallets/jinja/blob/master/CHANGES.rst)
- [Commits](https://github.com/pallets/jinja/compare/2.10.1...2.11.3)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-20 01:28:04 +00:00
tanner 55f8cef56f Return error messages on exceptions 2020-10-04 20:47:35 +00:00
tanner 71305eaa45 Fix copy/paste error 2019-10-16 05:47:54 +00:00
tanner fa632165b1 Add link to Github 2019-10-16 05:45:45 +00:00
tanner f7121153c2 Add readme 2019-10-16 05:45:04 +00:00
tanner 71d760d9ef Add MIT license file 2019-10-16 05:36:40 +00:00
4 changed files with 171 additions and 16 deletions
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2019 Tanner Collin
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+113
View File
@@ -0,0 +1,113 @@
# t0url
## Website
[url.t0.vc](https://url.t0.vc)
## Description
Command line URL shortener.
This allows you to submit URLs from your command line or browser. A short URL is returned.
## Usage
`<command> | curl -F 'url=<-' https://url.t0.vc`
You can also submit from the web at [url.t0.vc](https://url.t0.vc).
## Example
```text
$ cat yourfile | curl -F 'url=<-' https://url.t0.vc
https://url.t0.vc/VFAR
$ firefox https://url.t0.vc/VFAR
```
### Bash Alias
Add this to your .bashrc, then `source ~/.bashrc`:
```text
alias url="curl -F 'url=<-' https://url.t0.vc"
```
Now you can pipe a URL directly into url!
```text
$ cat yourfile | url
https://url.t0.vc/VFAR
$ firefox https://url.t0.vc/VFAR
```
## Self-hosting
Install dependencies:
```text
$ sudo apt install python3 python3-pip python-virtualenv python3-virtualenv
```
Clone repo, create a venv, activate it, and install:
```text
$ git clone https://github.com/tannercollin/t0url.git
$ cd t0url
$ virtualenv -p python3 env
$ source env/bin/activate
(env) $ pip install -r requirements.txt
```
You can now run it directly:
```text
(env) $ python t0url.py
```
It's recommended to run t0url as its own Linux user, kept alive with [supervisor](https://pypi.org/project/supervisor/):
```text
[program:t0url]
user=t0url
directory=/home/t0url/t0url
command=/home/t0url/t0url/env/bin/python -u t0url.py
autostart=true
autorestart=true
stderr_logfile=/var/log/t0url.log
stderr_logfile_maxbytes=1MB
stdout_logfile=/var/log/t0url.log
stdout_logfile_maxbytes=1MB
```
To expose t0url to http / https, you should configure nginx to reverse proxy:
```text
server {
listen 80;
root /var/www/html;
index index.html index.htm;
server_name url.t0.vc;
location / {
proxy_pass http://127.0.0.1:5002/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
```
Then run `sudo certbot --nginx` and follow the prompts.
## See Also
Pastebin: [txt.t0.vc](https://txt.t0.vc) - [Source Code](https://github.com/tannercollin/t0txt)
Image host: [pic.t0.vc](https://pic.t0.vc) - [Source Code](https://github.com/tannercollin/t0pic)
## License
This program is free and open-source software licensed under the MIT License. Please see the `LICENSE` file for details.
That means you have the right to study, change, and distribute the software and source code to anyone and for any purpose. You deserve these rights. Please take advantage of them because I like pull requests and would love to see this code put to use.
## Acknowledgements
Thanks to all the devs behind Flask and Python.
+10 -10
View File
@@ -1,10 +1,10 @@
Click==7.0 blinker==1.8.2
decorator==4.4.0 click==8.1.7
Flask==1.1.1 flask==3.0.3
itsdangerous==1.1.0 importlib-metadata==8.0.0
Jinja2==2.10.1 itsdangerous==2.2.0
MarkupSafe==1.1.1 jinja2==3.1.4
pkg-resources==0.0.0 MarkupSafe==2.1.5
six==1.12.0 validators==0.28.3
validators==0.13.0 werkzeug==3.0.3
Werkzeug==0.15.5 zipp==3.19.2
+27 -6
View File
@@ -7,6 +7,7 @@ import string
import validators import validators
from flask import abort, Flask, request, redirect from flask import abort, Flask, request, redirect
from werkzeug.exceptions import HTTPException
DB = 'data/t0url' DB = 'data/t0url'
PORT = 5004 PORT = 5004
@@ -18,10 +19,14 @@ def help():
form = ( form = (
'<form action="{0}" method="POST" accept-charset="UTF-8">' '<form action="{0}" method="POST" accept-charset="UTF-8">'
'<input name="web" type="hidden" value="true">' '<input name="web" type="hidden" value="true">'
'<input name="{1}">' '<input name="name" style="border: none;">'
'<br>URL: <input name="{1}">'
'<br>CAPTCHA: Who owns this site? <input name="captcha">'
'<br><button type="submit">Submit</button></form>'.format(URL, POST) '<br><button type="submit">Submit</button></form>'.format(URL, POST)
) )
return """ return """
<meta name="color-scheme" content="light dark" />
<meta name="viewport" content="width=1%" />
<pre> <pre>
url.t0.vc url.t0.vc
NAME NAME
@@ -46,10 +51,10 @@ EXAMPLES
SOURCE CODE SOURCE CODE
https://txt.t0.vc/RWFA https://txt.t0.vc/RWFA
https://github.com/tannercollin/t0url
SEE ALSO SEE ALSO
https://txt.t0.vc https://txt.t0.vc
https://pic.t0.vc
</pre>""".format(POST, URL, form) </pre>""".format(POST, URL, form)
def new_id(): def new_id():
@@ -64,6 +69,20 @@ def index():
@flask_app.route('/', methods=['POST']) @flask_app.route('/', methods=['POST'])
def new(): def new():
try: try:
is_web = 'web' in request.form
name = request.form.get('name', None)
if name:
# TODO: fail if name field is filled out
print('Name filled out:', name)
captcha = request.form.get('captcha', None)
if is_web and 'tanner' not in captcha.lower() and 'collin' not in captcha.lower():
print('Captcha failed:', captcha)
return redirect('https://txt.t0.vc/LPPZ')
else:
print('Captcha passed:', captcha)
with shelve.open(DB) as db: with shelve.open(DB) as db:
nid = new_id() nid = new_id()
while nid in db: while nid in db:
@@ -71,19 +90,21 @@ def new():
url = request.form['url'].strip() url = request.form['url'].strip()
if not url: raise if not url: abort(400, 'Error: URL missing')
if DOMAIN in url: raise if DOMAIN in url: abort(400, 'Error: use a different URL')
if not url.startswith('http'): if not url.startswith('http'):
url = 'http://' + url url = 'http://' + url
if not validators.url(url): raise if not validators.url(url): abort(400, 'Error: invalid URL')
db[nid] = url db[nid] = url
print('Adding url {}:\n{}'.format(nid, url)) print('Adding url {}:\n{}'.format(nid, url))
return '{}/{}'.format(URL, nid) + '\n' return '{}/{}'.format(URL, nid) + '\n'
except HTTPException:
raise
except: except:
abort(400) abort(400, 'Error: unknown problem')
@flask_app.route('/<nid>', methods=['GET']) @flask_app.route('/<nid>', methods=['GET'])
def get(nid): def get(nid):