fix
This commit is contained in:
parent
80220e1250
commit
47e321134e
@ -81,12 +81,14 @@ def get_device_type(user_agent):
|
||||
|
||||
# Logging function that uses the singleton connection.
|
||||
def log_file_access(rel_path, filesize, mime, ip_address, user_agent, device_id, cached):
|
||||
global file_access_temp
|
||||
timestamp = datetime.now() # Use datetime object directly
|
||||
with log_db.connection.cursor() as cursor:
|
||||
cursor.execute('''
|
||||
INSERT INTO file_access_log (timestamp, rel_path, filesize, mime, ip_address, user_agent, device_id, cached)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)
|
||||
''', (timestamp, rel_path, filesize, mime, ip_address, user_agent, device_id, cached))
|
||||
file_access_temp.insert(0, [timestamp, rel_path, filesize, mime, ip_address, user_agent, device_id, cached])
|
||||
return timestamp.isoformat()
|
||||
|
||||
def return_file_access():
|
||||
|
||||
29
app.py
29
app.py
@ -4,7 +4,6 @@ from PIL import Image
|
||||
import io
|
||||
from functools import wraps
|
||||
import mimetypes
|
||||
import sqlite3
|
||||
from datetime import datetime, date, timedelta
|
||||
import diskcache
|
||||
import threading
|
||||
@ -15,7 +14,7 @@ import geoip2.database
|
||||
from functools import lru_cache
|
||||
from urllib.parse import urlparse, unquote
|
||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||
|
||||
import re
|
||||
|
||||
import auth
|
||||
import analytics as a
|
||||
@ -39,7 +38,17 @@ app.add_url_rule('/connections', view_func=a.connections)
|
||||
app.add_url_rule('/mylinks', view_func=auth.mylinks)
|
||||
app.add_url_rule('/remove_secret', view_func=auth.remove_secret, methods=['POST'])
|
||||
|
||||
socketio = SocketIO(app, async_mode='eventlet')
|
||||
# Grab the HOST_RULE environment variable
|
||||
host_rule = os.getenv("HOST_RULE", "")
|
||||
# Use a regex to extract domain names between backticks in patterns like Host(`something`)
|
||||
pattern = r"Host\(`([^`]+)`\)"
|
||||
allowed_domains = re.findall(pattern, host_rule)
|
||||
|
||||
socketio = SocketIO(
|
||||
app,
|
||||
async_mode='eventlet',
|
||||
cors_allowed_origins=allowed_domains
|
||||
)
|
||||
background_thread_running = False
|
||||
|
||||
# Global variables to track the number of connected clients and the background thread
|
||||
@ -355,8 +364,11 @@ def query_recent_connections():
|
||||
{
|
||||
'timestamp': datetime.strptime(row[0], '%Y-%m-%dT%H:%M:%S.%f').strftime('%d.%m.%Y %H:%M:%S'),
|
||||
'full_path': row[1],
|
||||
'ip_address': row[2],
|
||||
'user_agent': row[3]
|
||||
'filesize' : row[2],
|
||||
'mime-typ' : row[3],
|
||||
'ip_address': row[4],
|
||||
'user_agent': row[5],
|
||||
'cached': row[7]
|
||||
}
|
||||
for row in rows
|
||||
]
|
||||
@ -393,8 +405,11 @@ def handle_request_initial_data():
|
||||
{
|
||||
'timestamp': datetime.strptime(row[0], '%Y-%m-%dT%H:%M:%S.%f').strftime('%d.%m.%Y %H:%M:%S'),
|
||||
'full_path': row[1],
|
||||
'ip_address': row[2],
|
||||
'user_agent': row[3]
|
||||
'filesize' : row[2],
|
||||
'mime-typ' : row[3],
|
||||
'ip_address': row[4],
|
||||
'user_agent': row[5],
|
||||
'cached': row[7]
|
||||
}
|
||||
for row in rows
|
||||
]
|
||||
|
||||
@ -53,8 +53,7 @@ services:
|
||||
gunicorn --worker-class eventlet -w 1 -b 0.0.0.0:5000 app:app"
|
||||
|
||||
postgres:
|
||||
image: postgres:15
|
||||
container_name: "${CONTAINER_NAME}-db"
|
||||
image: postgres:17
|
||||
restart: always
|
||||
environment:
|
||||
POSTGRES_USER: ${DB_USER:?}
|
||||
|
||||
@ -41,6 +41,9 @@
|
||||
<th>IP Address</th>
|
||||
<th>User Agent</th>
|
||||
<th>File Path</th>
|
||||
<td>File Size</td>
|
||||
<td>MIME-Typ</td>
|
||||
<td>Cached</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="connectionsTableBody">
|
||||
@ -71,6 +74,9 @@
|
||||
<td>${record.ip_address}</td>
|
||||
<td>${record.user_agent}</td>
|
||||
<td>${record.full_path}</td>
|
||||
<td>${record.filesize}</td>
|
||||
<td>${record.mime-typ}</td>
|
||||
<td>${record.cached}</td>
|
||||
`;
|
||||
tbody.appendChild(row);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user