diff --git a/.gitignore b/.gitignore index 35702a69..96e7c4ff 100755 --- a/.gitignore +++ b/.gitignore @@ -44,6 +44,7 @@ source/python/modules/* !source/python/modules/pageGuard.py !source/python/modules/PDF.py !source/python/modules/response.py +!source/python/modules/routeGuard.py !source/python/modules/SendGrid.py !source/python/modules/tools.py !source/python/modules/User.py diff --git a/source/main.py b/source/main.py index 7cd19ec9..57d77d93 100755 --- a/source/main.py +++ b/source/main.py @@ -8,20 +8,22 @@ Log.brand() -#################################################### Globals -from python.modules.Globals import Globals - - #################################################### Initializing File Structure from python.modules.FileSystem import FileSystem FileSystem.init() +#################################################### Globals +from python.modules.Globals import Globals + + #################################################### Setting Up MySQL from python.modules.MySQL import MySQL ######## If Database Enabled -if "database" in Globals.CONF and Globals.CONF["database"]["enabled"] == True: - +if ( + Globals.CONF.get("database", {}).get("enabled") is True and + Globals.CONF.get("database", {}).get("MySQL", {}).get("enabled") is True +): ######## Set Up Connection MySQL.setUp( Globals.CONF["database"]["MySQL"]["user"], @@ -51,14 +53,20 @@ app.secret_key = Globals.CONF["flask"]["secret_key"] +#################################################### routeGuard +from python.modules.routeGuard import routeGuard, routeLogs + + #################################################### Decorations # @app.before_first_request # def app_init(): # return None -# @app.before_request -# def before_request(): -# pass +@app.before_request +def before_request(): + routeLogs() + # routeGuard() + # @app.after_request # def after_request(response): diff --git a/source/python/modules/routeGuard.py b/source/python/modules/routeGuard.py new file mode 100644 index 00000000..d43997f8 --- /dev/null +++ b/source/python/modules/routeGuard.py @@ -0,0 +1,69 @@ +if __name__ != "__main__": + from main import request, redirect, url_for + from python.modules.Logger import Log + + def routeLogs(): + # request + # + # Log.info(request) + + # method + # Log.info(request.method) + + # url + # http://localhost:5000/js/pages/home.js + # Log.info(request.url) + + # path + # /js/pages/home.js + # Log.info(request.path) + + # args - ImmutableMultiDict([]) + # Log.info(request.args) + # Log.info(request.args.get('key')) + # Log.info(request.args.keys()) + # Log.info(request.args.values()) + + # cookies - ImmutableMultiDict([]) + # Log.info(request.cookies) + + # headers + # Log.info(request.headers) + + # Log.info(request.content_type) + # Log.info(request.form) + # Log.info(request.files) + # Log.info(request.get_json) + + # Log Structure + # [method] [url] [content_type] [form] [files] [get_json] + + Log.info(f"[{request.method}] [{request.url}]") + + if request.content_type is None: pass + + elif "multipart/form-data;" in request.content_type: + Log.center(f"Contet-Type: {request.content_type}", '-') + + for key, value in request.form.items(): print(f"{key}: {value}") + + if len(request.files) > 0: + for key, value in request.files.items(): print(f"{key}: {value}") + + + Log.center('', '-') + + # logText += f" [{request.form}]" + # logText += f" [{request.files}]" if len(request.files) > 0 else '' + + elif request.content_type == "application/json": + Log.center(f"Contet-Type: {request.content_type}", '-') + for key, value in request.get_json().items(): print(f"{key}: {value}") + + Log.center('', '-') + + + def routeGuard(): + pass + # Log.info(request.path) + # Log.warning(request.path.split("/")[1]) \ No newline at end of file