forked from rDrama/rDrama
logging: create somewhat sane logging
parent
0106a4e340
commit
d395bcab69
|
@ -26,6 +26,9 @@ RUN mkdir /asset_submissions/marseys
|
|||
RUN mkdir /asset_submissions/hats
|
||||
RUN mkdir /asset_submissions/marseys/original
|
||||
RUN mkdir /asset_submissions/hats/original
|
||||
RUN mkdir /var/log/rdrama
|
||||
|
||||
RUN chown rdrama:rdrama /var/log/rdrama
|
||||
|
||||
ENV NODE_VERSION=16.13.0
|
||||
RUN apt install -y curl
|
||||
|
|
|
@ -14,6 +14,7 @@ from files.helpers.const import *
|
|||
from files.helpers.const_stateful import *
|
||||
from files.helpers.discord import discord_message_send
|
||||
from files.helpers.get import *
|
||||
from files.helpers.logging import log_file
|
||||
from files.helpers.sanitize import *
|
||||
from files.helpers.settings import get_setting
|
||||
from files.helpers.slots import check_slots_command
|
||||
|
@ -454,9 +455,8 @@ def execute_under_siege(v:User, target:Optional[Union[Submission, Comment]], bod
|
|||
if not v.is_banned: v.ban_reason = f"Under Siege"
|
||||
v.is_muted = True
|
||||
g.db.add(v)
|
||||
with open(f"/under_siege.log", "a", encoding="utf-8") as f:
|
||||
t = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(time.time()))
|
||||
f.write(f"[{t}] {v.id} @{v.username} {type} {v.age}s\n")
|
||||
t = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(time.time()))
|
||||
log_file(f"[{t}] {v.id} @{v.username} {type} {v.age}s")
|
||||
discord_message_send(UNDER_SIEGE_CHANNEL_ID,
|
||||
f"<{SITE_FULL}/id/{v.id}> `@{v.username} {type} {v.age}s`")
|
||||
return False
|
||||
|
|
|
@ -50,6 +50,7 @@ class Service(Enum):
|
|||
CLOUDFLARE_COOKIE_VALUE = "yes." # remember to change this in CloudFlare too
|
||||
|
||||
SETTINGS_FILENAME = '/site_settings.json'
|
||||
LOG_DIRECTORY = '/var/log/rdrama'
|
||||
|
||||
DEFAULT_RATELIMIT = "3/second;30/minute;200/hour;1000/day"
|
||||
DEFAULT_RATELIMIT_SLOWER = "1/second;30/minute;200/hour;1000/day"
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
from files.helpers.const import LOG_DIRECTORY
|
||||
|
||||
def log_file(log_str:str, log_filename="rdrama.log", append_newline=True):
|
||||
'''
|
||||
Simple method to log a string to a file
|
||||
'''
|
||||
log_target = f"{LOG_DIRECTORY}/{log_filename}"
|
||||
try:
|
||||
with open(log_target, "a", encoding="utf-8") as f:
|
||||
f.write(f"{log_str}{'\n' if append_newline else ''}")
|
||||
except Exception as e:
|
||||
print(f"Failed to log to file {log_target} due to {e.__class__.__name__}")
|
|
@ -10,6 +10,7 @@ from files.helpers.const import *
|
|||
from files.helpers.settings import get_setting
|
||||
from files.helpers.get import *
|
||||
from files.helpers.mail import send_mail, send_verification_email
|
||||
from files.helpers.logging import log_file
|
||||
from files.helpers.regex import *
|
||||
from files.helpers.security import *
|
||||
from files.helpers.useractions import badge_grant
|
||||
|
@ -115,12 +116,8 @@ def log_failed_admin_login_attempt(account:User, type:str):
|
|||
if not account or account.admin_level < PERMS['SITE_WARN_ON_INVALID_AUTH']: return
|
||||
ip = get_CF()
|
||||
print(f"Admin user from {ip} failed to login to account @{account.user_name} (invalid {type})")
|
||||
try:
|
||||
with open("/admin_failed_logins", "a+", encoding="utf-8") as f:
|
||||
t = time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(time.time()))
|
||||
f.write(f"{t}, {ip}, {account.username}, {type}\n")
|
||||
except:
|
||||
pass
|
||||
t = time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(time.time()))
|
||||
log_file(f"{t}, {ip}, {account.username}, {type}", "admin_failed_logins.log")
|
||||
|
||||
def on_login(account, redir=None):
|
||||
session["lo_user"] = account.id
|
||||
|
|
|
@ -5,6 +5,7 @@ from files.classes.clients import ClientAuth
|
|||
from files.helpers.alerts import *
|
||||
from files.helpers.const import *
|
||||
from files.helpers.get import get_account
|
||||
from files.helpers.logging import log_file
|
||||
from files.helpers.settings import get_setting
|
||||
from files.routes.routehelpers import validate_formkey
|
||||
from files.__main__ import app, db_session, limiter
|
||||
|
@ -60,11 +61,11 @@ def get_logged_in_user():
|
|||
|
||||
if AEVANN_ID and request.headers.get("Cf-Ipcountry") == 'EG':
|
||||
if v and not v.username.startswith('Aev') and v.truescore > 0:
|
||||
with open("/eg", "r+", encoding="utf-8") as f:
|
||||
with open(f"{LOG_DIRECTORY}/eg.log", "r+", encoding="utf-8") as f:
|
||||
ip = request.headers.get('CF-Connecting-IP')
|
||||
if f'@{v.username}, ' not in f.read():
|
||||
t = time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(time.time()))
|
||||
f.write(f'@{v.username}, {v.truescore}, {ip}, {t}\n')
|
||||
log_file(f'@{v.username}, {v.truescore}, {ip}, {t}\n', 'eg.log')
|
||||
return v
|
||||
|
||||
def auth_desired(f):
|
||||
|
|
|
@ -52,6 +52,9 @@ mkdir /asset_submissions/marseys
|
|||
mkdir /asset_submissions/hats
|
||||
mkdir /asset_submissions/marseys/original
|
||||
mkdir /asset_submissions/hats/original
|
||||
mkdir /var/log/rdrama
|
||||
|
||||
chown rdrama:rdrama /var/log/rdrama
|
||||
|
||||
git config --global --add safe.directory /songs
|
||||
git config --global --add safe.directory /images
|
||||
|
|
Loading…
Reference in New Issue