-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
106 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,6 +91,7 @@ Create a .env on the root folder of the project with the following variables: | |
13. SMTP_DOMAIN=smtp.xamfra.net | ||
14. SMTP_USER=[email protected] | ||
15. DISCORD_LOGIN_NOTIFICATIONS | ||
16. DISCORD_LOGIN_NOTIFICATIONS_ALERT | ||
|
||
### FRONTEND | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from flask import current_app, request | ||
from flask_login import current_user | ||
|
||
|
||
def get_ip(): | ||
try: | ||
if request.environ.get("HTTP_X_FORWARDED_FOR") is None: | ||
return request.environ["REMOTE_ADDR"] | ||
else: | ||
return request.environ["HTTP_X_FORWARDED_FOR"] # if behind a proxy | ||
except: | ||
return "?" | ||
|
||
|
||
def try_get_email(): | ||
try: | ||
return current_user.email | ||
except: | ||
return "?" | ||
|
||
|
||
def audit_log(level: str, message: str): | ||
try: | ||
emoji = "⚠️" if level == "warn" else "🚨" if level == "alert" else "✅" | ||
dest = current_app.config["DISCORD_LOGIN_NOTIFICATIONS_ALERT"] if level == "alert" else current_app.config["DISCORD_LOGIN_NOTIFICATIONS"] | ||
requests.post( | ||
dest, | ||
json={ | ||
"content": f"{emoji} [email: {try_get_email()}] [ip: {get_ip()}] {message}" | ||
}) | ||
except: | ||
print(f"Failed to post audit log") | ||
|
||
|
||
def audit_log_info(message: str): | ||
return audit_log("info", message) | ||
|
||
|
||
def audit_log_warn(message: str): | ||
return audit_log("warn", message) | ||
|
||
|
||
def audit_log_alert(message: str): | ||
return audit_log("alert", message) |