Compare commits
10
Commits
cf9392c5dd
...
5734ae1c2f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5734ae1c2f | ||
|
|
45f6240849 | ||
|
|
69a12c1352 | ||
|
|
21f2c45d89 | ||
|
|
084535544f | ||
|
|
55f8cef56f | ||
|
|
71305eaa45 | ||
|
|
fa632165b1 | ||
|
|
f7121153c2 | ||
|
|
71d760d9ef |
@@ -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.
|
||||
@@ -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
@@ -1,10 +1,10 @@
|
||||
Click==7.0
|
||||
decorator==4.4.0
|
||||
Flask==1.1.1
|
||||
itsdangerous==1.1.0
|
||||
Jinja2==2.10.1
|
||||
MarkupSafe==1.1.1
|
||||
pkg-resources==0.0.0
|
||||
six==1.12.0
|
||||
validators==0.13.0
|
||||
Werkzeug==0.15.5
|
||||
blinker==1.8.2
|
||||
click==8.1.7
|
||||
flask==3.0.3
|
||||
importlib-metadata==8.0.0
|
||||
itsdangerous==2.2.0
|
||||
jinja2==3.1.4
|
||||
MarkupSafe==2.1.5
|
||||
validators==0.28.3
|
||||
werkzeug==3.0.3
|
||||
zipp==3.19.2
|
||||
|
||||
@@ -7,6 +7,7 @@ import string
|
||||
import validators
|
||||
|
||||
from flask import abort, Flask, request, redirect
|
||||
from werkzeug.exceptions import HTTPException
|
||||
|
||||
DB = 'data/t0url'
|
||||
PORT = 5004
|
||||
@@ -18,10 +19,14 @@ def help():
|
||||
form = (
|
||||
'<form action="{0}" method="POST" accept-charset="UTF-8">'
|
||||
'<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)
|
||||
)
|
||||
return """
|
||||
<meta name="color-scheme" content="light dark" />
|
||||
<meta name="viewport" content="width=1%" />
|
||||
<pre>
|
||||
url.t0.vc
|
||||
NAME
|
||||
@@ -46,10 +51,10 @@ EXAMPLES
|
||||
|
||||
SOURCE CODE
|
||||
https://txt.t0.vc/RWFA
|
||||
https://github.com/tannercollin/t0url
|
||||
|
||||
SEE ALSO
|
||||
https://txt.t0.vc
|
||||
https://pic.t0.vc
|
||||
</pre>""".format(POST, URL, form)
|
||||
|
||||
def new_id():
|
||||
@@ -64,6 +69,20 @@ def index():
|
||||
@flask_app.route('/', methods=['POST'])
|
||||
def new():
|
||||
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:
|
||||
nid = new_id()
|
||||
while nid in db:
|
||||
@@ -71,19 +90,21 @@ def new():
|
||||
|
||||
url = request.form['url'].strip()
|
||||
|
||||
if not url: raise
|
||||
if DOMAIN in url: raise
|
||||
if not url: abort(400, 'Error: URL missing')
|
||||
if DOMAIN in url: abort(400, 'Error: use a different URL')
|
||||
if not url.startswith('http'):
|
||||
url = 'http://' + url
|
||||
if not validators.url(url): raise
|
||||
if not validators.url(url): abort(400, 'Error: invalid URL')
|
||||
|
||||
db[nid] = url
|
||||
|
||||
print('Adding url {}:\n{}'.format(nid, url))
|
||||
|
||||
return '{}/{}'.format(URL, nid) + '\n'
|
||||
except HTTPException:
|
||||
raise
|
||||
except:
|
||||
abort(400)
|
||||
abort(400, 'Error: unknown problem')
|
||||
|
||||
@flask_app.route('/<nid>', methods=['GET'])
|
||||
def get(nid):
|
||||
|
||||
Reference in New Issue
Block a user