# t0reg - reg.t0.vc # MIT License import random import string from flask import abort, Flask, request, redirect PORT = 5005 URL = 'https://reg.t0.vc' POST = 'reg' registers = {} def help(nid): form = ( '
' '' '' '
'.format(URL, nid) ) return """
                        reg.t0.vc
NAME
    t0reg: command line key-value registers

USAGE
    <command> | curl -F '{0}=<-' {1}
    or upload from the web:

{2}
    The key {0} was randomly chosen for you.

DESCRIPTION
    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.

EXAMPLES
    ~$ echo "hello world" | curl -F '{0}=<-' {1}
    ~$ curl {1}/{0}
    hello world

    Add this to your .bashrc:

    alias push="curl -F '{0}=<-' {1}"
    alias pull="curl {1}/{0}"

    Now you can pipe directly into push!
    Get the data back with pull.

    To move a file:
    ~$ cat kitten.jpg | base64 | push
    ~$ pull | base64 -d > kitten.jpg

SOURCE CODE
    https://txt.t0.vc/SBSU

SEE ALSO
    https://txt.t0.vc
    https://pic.t0.vc
    https://url.t0.vc
""".format(nid, URL, form) 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(): return '{}'.format(help(new_id())) @flask_app.route('/', methods=['POST']) def new(): try: pairs = [x for x in request.form.items() if x[0] != 'web'] for key, value in pairs: print('Adding:', key) registers[key] = value if 'web' in request.form: return redirect(URL + '/' + key) else: return '', 200 except: abort(400) @flask_app.route('/', methods=['GET']) def get(rid): try: 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'} except: abort(404) flask_app.run(port=PORT)