~fabrixxm/remotami

69a5815e086daff21901e734a3bc95cc41610bbb — fabrixxm 1 year, 8 months ago 5548bff
Update remotamid
2 files changed, 15 insertions(+), 4 deletions(-)

M server/localrun.sh
M server/remotamid.py
M server/localrun.sh => server/localrun.sh +1 -1
@@ 1,4 1,4 @@
#!/bin/bash
export FLASK_ENV=development
export FLASK_APP=remotamid.py
flask run
flask run --host=0.0.0.0

M server/remotamid.py => server/remotamid.py +14 -3
@@ 7,7 7,7 @@ from sshpubkeys import SSHKey

app = Flask("lesanaweb")
authkeyfile = Path.home() / ".ssh" / "authorized_keys"
portsdir = Path.home() / "remotami"
portsdir = Path.home() / ".cache" / "remotamid" / "ports"
portsdir.mkdir(mode=0o700, parents=True, exist_ok=True)




@@ 19,6 19,7 @@ def is_key_authorized(key):


def authorize_key(key):
    authkeyfile.parent.mkdir(mode=0o700, exist_ok=True)
    authkeyfile.touch(mode=0o600, exist_ok=True)
    with open(authkeyfile, "a") as f:
        f.write(key.keydata + "\n")


@@ 50,15 51,25 @@ def port():
        portfile.touch(exist_ok=True)
    else:
        n = len(list(portsdir.glob("*.port")))
        port = str(5900 + n)
        port = 5900 + n
        if port >= 6000:
            # this is just to put a limit
            # port files should be deleted once in a while
            abort(503)
        port = str(port)
        portfile.write_text(port)
    return make_response(port)


@app.route('/remoteport', methods=['GET'])
def remoteport():
    uid = request.args.get('u', None)
    if uid is None or uid == "":
        abort(400)
    portfile = portsdir / (uid + ".port")
    if not portfile.exists():
        abort(404)
    port = portfile.read_text()
    return make_response(port)

@app.route('/', methods=['GET'])
def index():