2020-05-03 23:02:56 +00:00
|
|
|
# t0reg - reg.t0.vc
|
2019-08-07 21:01:29 +00:00
|
|
|
# MIT License
|
|
|
|
|
|
|
|
import random
|
|
|
|
import string
|
|
|
|
|
|
|
|
from flask import abort, Flask, request, redirect
|
|
|
|
|
2020-05-03 23:02:56 +00:00
|
|
|
PORT = 5005
|
|
|
|
URL = 'https://reg.t0.vc'
|
|
|
|
POST = 'reg'
|
2019-08-07 21:01:29 +00:00
|
|
|
|
2020-05-03 23:02:56 +00:00
|
|
|
registers = {}
|
|
|
|
|
|
|
|
def help(nid):
|
2019-08-07 21:01:29 +00:00
|
|
|
form = (
|
|
|
|
'<form action="{0}" method="POST" accept-charset="UTF-8">'
|
|
|
|
'<input name="web" type="hidden" value="true">'
|
2020-05-03 23:02:56 +00:00
|
|
|
'<input name="{1}">'
|
|
|
|
'<br><button type="submit">Submit</button></form>'.format(URL, nid)
|
2019-08-07 21:01:29 +00:00
|
|
|
)
|
|
|
|
return """
|
2024-02-26 01:34:52 +00:00
|
|
|
<meta name="color-scheme" content="light dark" />
|
|
|
|
<meta name="viewport" content="width=1%" />
|
2019-08-07 21:01:29 +00:00
|
|
|
<pre>
|
2020-05-03 23:02:56 +00:00
|
|
|
reg.t0.vc
|
2019-08-07 21:01:29 +00:00
|
|
|
NAME
|
2020-05-03 23:02:56 +00:00
|
|
|
t0reg: command line key-value registers
|
2019-08-07 21:01:29 +00:00
|
|
|
|
|
|
|
USAGE
|
|
|
|
<command> | curl -F '{0}=<-' {1}
|
|
|
|
or upload from the web:
|
|
|
|
|
|
|
|
{2}
|
2020-05-03 23:02:56 +00:00
|
|
|
The key {0} was randomly chosen for you.
|
2019-08-07 21:01:29 +00:00
|
|
|
|
|
|
|
DESCRIPTION
|
2020-05-03 23:02:56 +00:00
|
|
|
This lets you POST data to a key of your choice.
|
|
|
|
You can then GET the data at that key.
|
|
|
|
This is useful for moving data / files between servers.
|
|
|
|
All the data is stored temporarily.
|
|
|
|
Make your key random if you don't want people guessing.
|
2019-08-07 21:01:29 +00:00
|
|
|
|
|
|
|
EXAMPLES
|
2020-05-03 23:02:56 +00:00
|
|
|
~$ echo "hello world" | curl -F '{0}=<-' {1}
|
|
|
|
~$ curl {1}/{0}
|
|
|
|
hello world
|
2019-08-07 21:01:29 +00:00
|
|
|
|
|
|
|
Add this to your .bashrc:
|
|
|
|
|
2020-05-03 23:02:56 +00:00
|
|
|
alias push="curl -F '{0}=<-' {1}"
|
|
|
|
alias pull="curl {1}/{0}"
|
|
|
|
|
|
|
|
Now you can pipe directly into push!
|
|
|
|
Get the data back with pull.
|
2019-08-07 21:01:29 +00:00
|
|
|
|
2020-05-03 23:02:56 +00:00
|
|
|
To move a file:
|
|
|
|
~$ cat kitten.jpg | base64 | push
|
|
|
|
~$ pull | base64 -d > kitten.jpg
|
2019-08-07 21:01:29 +00:00
|
|
|
|
|
|
|
SOURCE CODE
|
2020-05-03 23:02:56 +00:00
|
|
|
https://txt.t0.vc/SBSU
|
2019-08-07 21:01:29 +00:00
|
|
|
|
|
|
|
SEE ALSO
|
2020-05-03 23:02:56 +00:00
|
|
|
https://txt.t0.vc
|
2019-08-07 21:01:29 +00:00
|
|
|
https://pic.t0.vc
|
|
|
|
https://url.t0.vc
|
2020-05-03 23:02:56 +00:00
|
|
|
</pre>""".format(nid, URL, form)
|
2019-08-07 21:01:29 +00:00
|
|
|
|
|
|
|
def new_id():
|
|
|
|
return ''.join(random.choice(string.ascii_uppercase) for _ in range(4))
|
|
|
|
|
|
|
|
flask_app = Flask(__name__)
|
|
|
|
|
|
|
|
@flask_app.route('/', methods=['GET'])
|
|
|
|
def index():
|
2020-05-03 23:02:56 +00:00
|
|
|
return '<html><body>{}</body></html>'.format(help(new_id()))
|
2019-08-07 21:01:29 +00:00
|
|
|
|
|
|
|
@flask_app.route('/', methods=['POST'])
|
|
|
|
def new():
|
|
|
|
try:
|
2020-05-03 23:02:56 +00:00
|
|
|
pairs = [x for x in request.form.items() if x[0] != 'web']
|
|
|
|
for key, value in pairs:
|
|
|
|
print('Adding:', key)
|
|
|
|
registers[key] = value
|
2019-08-07 21:01:29 +00:00
|
|
|
|
|
|
|
if 'web' in request.form:
|
2020-05-03 23:02:56 +00:00
|
|
|
return redirect(URL + '/' + key)
|
2019-08-07 21:01:29 +00:00
|
|
|
else:
|
2020-05-03 23:02:56 +00:00
|
|
|
return '', 200
|
2019-08-07 21:01:29 +00:00
|
|
|
except:
|
|
|
|
abort(400)
|
|
|
|
|
2020-05-03 23:02:56 +00:00
|
|
|
@flask_app.route('/<rid>', methods=['GET'])
|
|
|
|
def get(rid):
|
2019-08-07 21:01:29 +00:00
|
|
|
try:
|
2022-08-11 20:33:56 +00:00
|
|
|
if rid.endswith(':'):
|
|
|
|
response = 'Namespace ' + rid + '\n\n'
|
|
|
|
pairs = []
|
|
|
|
for key, value in registers.items():
|
|
|
|
if key.startswith(rid):
|
|
|
|
pairs.append(key.split(':')[1] + ':\n' + value)
|
|
|
|
response += '\n\n'.join(sorted(pairs))
|
|
|
|
else:
|
|
|
|
response = registers[rid]
|
|
|
|
return response, 200, {'Content-Type': 'text/plain; charset=utf-8'}
|
2019-08-07 21:01:29 +00:00
|
|
|
except:
|
|
|
|
abort(404)
|
|
|
|
|
|
|
|
flask_app.run(port=PORT)
|