diff --git a/.gitignore b/.gitignore index ae412d6..972062a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -env/ \ No newline at end of file +env/ +.vscode/ \ No newline at end of file diff --git a/app/app.py b/app/app.py index 4a18f26..79afbe3 100644 --- a/app/app.py +++ b/app/app.py @@ -1,47 +1,63 @@ from flask import Flask, abort, request, send_file from pprint import pprint -import os.path +import os import string import random -useSpecialChars = False -basePath="/app" -domain = "https://upload.lovelynet.net" +import configparser + +basePath = "/app" +# domain = "https://upload.lovelynet.net" +# secret = "thisistheshit" letters = string.ascii_letters -if useSpecialChars: - letters = letters + string.punctuation +if os.environ.get('UPDOMAIN') and os.environ.get('UPSECRET'): + domain = os.environ.get('UPDOMAIN') + secret = os.environ.get('UPSECRET') +else: + config = configparser.ConfigParser() + config.read('app/config.ini') + domain = config['VARS']['domain'] + secret = config['VARS']['secret'] + +print(domain, secret) # Functions + + def randomName(nameLength, ext): name = "" - for x in range(0,nameLength): - num = random.randint(0,len(letters)) - #print(num) + for x in range(0, nameLength): + num = random.randint(0, len(letters)) name += letters[num - 1] name = checkDuplicateName(name, ext) return f"{name}.{ext}" + def checkDuplicateName(name, ext): if os.path.isfile(f'{basePath}/imgs/{name}.{ext}'): name = randomName(5, ext) return name + def checkFileExists(name): if os.path.isfile(f'{basePath}/imgs/{name}'): return True return False + def saveIMG(imageData, name): imageData.save(f'{basePath}/imgs/' + name) + app = Flask(__name__) app.config['DEBUG'] = True + @app.route('/', methods=['POST', 'GET']) def index(): try: - if 'thisistheshit' in request.headers['X-AUTH']: + if secret in request.headers['X-AUTH']: if request.form['type'] == 'img': name = randomName(5, "png") saveIMG(request.files['image.png'], name) @@ -54,6 +70,7 @@ def index(): except: return "" + @app.route('/') def getImage(path): if (checkFileExists(path)): @@ -63,8 +80,8 @@ def getImage(path): @app.errorhandler(404) def page_not_found(error): - return "File not found", 404 + return "File not found", 404 -if __name__ == '__main__': - app.run(host='0.0.0.0') +# if __name__ == '__main__': +# app.run(host='0.0.0.0') diff --git a/app/config.ini b/app/config.ini new file mode 100644 index 0000000..c732fb4 --- /dev/null +++ b/app/config.ini @@ -0,0 +1,3 @@ +[VARS] +domain = https://this.domain.tld +secret = secretcode \ No newline at end of file