linted code
This commit is contained in:
@@ -20,6 +20,7 @@ TASK_CONFIG = {
|
|||||||
"run_when_loaded": True,
|
"run_when_loaded": True,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# ----------------------
|
# ----------------------
|
||||||
# TASK LOGIC
|
# TASK LOGIC
|
||||||
# ----------------------
|
# ----------------------
|
||||||
@@ -38,9 +39,9 @@ def main():
|
|||||||
|
|
||||||
# Reflect the database structure
|
# Reflect the database structure
|
||||||
metadata.reflect(bind=engine)
|
metadata.reflect(bind=engine)
|
||||||
output_file = os.path.join(config.backups_path,"db_dump.sql")
|
output_file = os.path.join(config.backups_path, "db_dump.sql")
|
||||||
|
|
||||||
with open(output_file, 'w') as f:
|
with open(output_file, "w") as f:
|
||||||
# Write header
|
# Write header
|
||||||
app_logger.info(f"[Background Task] {task_name} started database dump")
|
app_logger.info(f"[Background Task] {task_name} started database dump")
|
||||||
|
|
||||||
@@ -49,18 +50,20 @@ def main():
|
|||||||
|
|
||||||
# Dump schema (CREATE TABLE statements)
|
# Dump schema (CREATE TABLE statements)
|
||||||
f.write("-- Schema\n")
|
f.write("-- Schema\n")
|
||||||
f.write("-- " + "="*70 + "\n\n")
|
f.write("-- " + "=" * 70 + "\n\n")
|
||||||
|
|
||||||
for table_name in metadata.tables:
|
for table_name in metadata.tables:
|
||||||
table = metadata.tables[table_name]
|
table = metadata.tables[table_name]
|
||||||
app_logger.info(f"[Background Task] {task_name} dumping {table} table schema")
|
app_logger.info(
|
||||||
|
f"[Background Task] {task_name} dumping {table} table schema"
|
||||||
|
)
|
||||||
|
|
||||||
# Create table statement
|
# Create table statement
|
||||||
create_stmt = str(CreateTable(table).compile(engine))
|
create_stmt = str(CreateTable(table).compile(engine))
|
||||||
f.write(f"{create_stmt};\n\n")
|
f.write(f"{create_stmt};\n\n")
|
||||||
|
|
||||||
f.write("\n-- Data\n")
|
f.write("\n-- Data\n")
|
||||||
f.write("-- " + "="*70 + "\n\n")
|
f.write("-- " + "=" * 70 + "\n\n")
|
||||||
|
|
||||||
with engine.connect() as conn:
|
with engine.connect() as conn:
|
||||||
for table_name in metadata.tables:
|
for table_name in metadata.tables:
|
||||||
@@ -73,19 +76,27 @@ def main():
|
|||||||
rows = result.fetchall()
|
rows = result.fetchall()
|
||||||
|
|
||||||
if rows:
|
if rows:
|
||||||
app_logger.info(f"[Background Task] {task_name} dumping {table} content")
|
app_logger.info(
|
||||||
|
f"[Background Task] {task_name} dumping {table} content"
|
||||||
|
)
|
||||||
for row in rows:
|
for row in rows:
|
||||||
# Build INSERT statement
|
# Build INSERT statement
|
||||||
columns = ', '.join([col.name for col in table.columns])
|
columns = ", ".join([col.name for col in table.columns])
|
||||||
values = ', '.join([repr(value) for value in row])
|
values = ", ".join([repr(value) for value in row])
|
||||||
f.write(f"INSERT INTO {table_name} ({columns}) VALUES ({values});\n")
|
f.write(
|
||||||
|
f"INSERT INTO {table_name} ({columns}) VALUES ({values});\n"
|
||||||
|
)
|
||||||
|
|
||||||
f.write("\n")
|
f.write("\n")
|
||||||
else:
|
else:
|
||||||
f.write(f"-- No data in {table_name}\n\n")
|
f.write(f"-- No data in {table_name}\n\n")
|
||||||
app_logger.info(f"[Background Task] {task_name} no data in {table}")
|
app_logger.info(
|
||||||
|
f"[Background Task] {task_name} no data in {table}"
|
||||||
|
)
|
||||||
|
|
||||||
app_logger.info(f"[Background Task] {task_name} Database dump completed: {output_file}")
|
app_logger.info(
|
||||||
|
f"[Background Task] {task_name} Database dump completed: {output_file}"
|
||||||
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
app_logger.error(f"[Background Task] {task_name} failed: {e}")
|
app_logger.error(f"[Background Task] {task_name} failed: {e}")
|
||||||
|
|||||||
@@ -50,9 +50,7 @@ def generate_dashboard(stats: dict, dashboard_path: str = "") -> str:
|
|||||||
|
|
||||||
# Generate suspicious accesses rows with clickable IPs
|
# Generate suspicious accesses rows with clickable IPs
|
||||||
suspicious_rows = (
|
suspicious_rows = (
|
||||||
"\n".join(
|
"\n".join([f"""<tr class="ip-row" data-ip="{_escape(log["ip"])}">
|
||||||
[
|
|
||||||
f"""<tr class="ip-row" data-ip="{_escape(log["ip"])}">
|
|
||||||
<td class="ip-clickable">{_escape(log["ip"])}</td>
|
<td class="ip-clickable">{_escape(log["ip"])}</td>
|
||||||
<td>{_escape(log["path"])}</td>
|
<td>{_escape(log["path"])}</td>
|
||||||
<td style="word-break: break-all;">{_escape(log["user_agent"][:60])}</td>
|
<td style="word-break: break-all;">{_escape(log["user_agent"][:60])}</td>
|
||||||
@@ -64,10 +62,7 @@ def generate_dashboard(stats: dict, dashboard_path: str = "") -> str:
|
|||||||
<div class="loading">Loading stats...</div>
|
<div class="loading">Loading stats...</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>"""
|
</tr>""" for log in stats["recent_suspicious"][-10:]])
|
||||||
for log in stats["recent_suspicious"][-10:]
|
|
||||||
]
|
|
||||||
)
|
|
||||||
or '<tr><td colspan="4" style="text-align:center;">No suspicious activity detected</td></tr>'
|
or '<tr><td colspan="4" style="text-align:center;">No suspicious activity detected</td></tr>'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user