#!/usr/bin/env python3.9

from flask import Flask, make_response

app = Flask(__name__)

@app.route('/')
def index():
    return ("\x3cpre\x3e\x3ccode\x3e%s\x3c/code\x3e\x3c/pre\x3e")% \
        open(__file__).read().replace('\x3c', '<').replace('\x3e', '>')

@app.route('/docker')
def docker():
    return ("\x3cpre\x3e\x3ccode\x3e%s\x3c/code\x3e\x3c/pre\x3e")%open("Dockerfile").read()

@app.route('/file/', defaults={'path': ''})
@app.route('/file/<path:path>')
def get_file(path):
    try:
        print(path)
        path = path.replace('/..', '').replace('../', '')
        resp = make_response(open(path).read())
        resp.mimetype = 'text/plain'
        return resp
    except:
        return "File not found.", 404

app.run('0.0.0.0', 1005)