Skip to content

Commit

Permalink
New module route guard, custom route logs
Browse files Browse the repository at this point in the history
  • Loading branch information
woXrooX committed Jun 17, 2023
1 parent 115a39b commit a662833
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 17 additions & 9 deletions source/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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):
Expand Down
69 changes: 69 additions & 0 deletions source/python/modules/routeGuard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
if __name__ != "__main__":
from main import request, redirect, url_for
from python.modules.Logger import Log

def routeLogs():
# request
# <Request 'http://localhost:5000/js/pages/home.js' [GET]>
# 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])

0 comments on commit a662833

Please sign in to comment.