generated from justuser-31/mrl_v1_license
* Добавлено кликабельное название вверху
* Добавлено логирование * Проверка на авторизацию сразу в /login
This commit is contained in:
parent
1805846241
commit
d7e0efee42
62
main.py
62
main.py
@ -23,6 +23,11 @@ STORAGE_ROOT = ""
|
|||||||
# Global DB connection
|
# Global DB connection
|
||||||
DB_CONN = None
|
DB_CONN = None
|
||||||
|
|
||||||
|
# Logging utility
|
||||||
|
def log(message):
|
||||||
|
if CONFIG.get("logging", {}).get("enabled", True):
|
||||||
|
print(f"[{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}] {message}")
|
||||||
|
|
||||||
# Load config
|
# Load config
|
||||||
def load_config():
|
def load_config():
|
||||||
global CONFIG, STORAGE_ROOT
|
global CONFIG, STORAGE_ROOT
|
||||||
@ -156,7 +161,7 @@ class FileServerHandler(BaseHTTPRequestHandler):
|
|||||||
|
|
||||||
def log_message(self, format, *args):
|
def log_message(self, format, *args):
|
||||||
# Override to avoid logging to stderr
|
# Override to avoid logging to stderr
|
||||||
pass
|
log(format % args)
|
||||||
|
|
||||||
def send_html(self, content, status=200):
|
def send_html(self, content, status=200):
|
||||||
self.send_response(status)
|
self.send_response(status)
|
||||||
@ -185,25 +190,28 @@ class FileServerHandler(BaseHTTPRequestHandler):
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>{CONFIG['ui']['title']}</title>
|
<title>SimpliestFS</title>
|
||||||
<style>
|
<style>
|
||||||
body {{ font-family: sans-serif; margin: 40px; }}
|
body {{ font-family: sans-serif; margin: 40px; }}
|
||||||
.btn {{ display: inline-block; padding: 10px 20px; margin: 10px; background: #eee; border: 1px solid #ccc; text-decoration: none; color: #333; }}
|
.btn {{ display: inline-block; padding: 10px 20px; margin: 10px; background: #eee; border: 1px solid #ccc; text-decoration: none; color: #333; }}
|
||||||
.btn:hover {{ background: #ddd; }}
|
.btn:hover {{ background: #ddd; }}
|
||||||
.disclaimer {{ margin-top: 30px; font-size: 0.9em; color: #666; }}
|
.disclaimer {{ margin-top: 30px; font-size: 0.9em; color: #666; }}
|
||||||
|
h1 a {{ text-decoration: none; color: inherit; }}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>{CONFIG['ui']['title']}</h1>
|
<h1><a href="/">SimpliestFS</a></h1>
|
||||||
<p>{CONFIG['ui']['disclaimer']}</p>
|
<p>EN: {CONFIG['ui']['disclaimer']}</p>
|
||||||
|
<p>RU: {CONFIG['ui']['disclaimer_ru']}</p>
|
||||||
<p>Contact: <a href="mailto:{CONFIG['ui']['contact_email']}">{CONFIG['ui']['contact_email']}</a></p>
|
<p>Contact: <a href="mailto:{CONFIG['ui']['contact_email']}">{CONFIG['ui']['contact_email']}</a></p>
|
||||||
|
<p>Contact (prefered): <a href="https://t.me/justuser_31">@justuser_31</a></p>
|
||||||
<p>
|
<p>
|
||||||
<a class="btn" href="/register">Register</a>
|
<a class="btn" href="/register">Register</a>
|
||||||
<a class="btn" href="/login">Login</a>
|
<a class="btn" href="/login">Login</a>
|
||||||
<a class="btn" href="/explore">Explore Files</a>
|
<a class="btn" href="/explore">Explore Files</a>
|
||||||
</p>
|
</p>
|
||||||
<div class="disclaimer">
|
<div class="disclaimer">
|
||||||
Note: All files are stored locally. No encryption. No external databases.
|
Note: NO ENCRYPTION, no external databases. As simple as possible.
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@ -215,14 +223,16 @@ class FileServerHandler(BaseHTTPRequestHandler):
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Register - {CONFIG['ui']['title']}</title>
|
<title>Register - SimpliestFS</title>
|
||||||
<style>
|
<style>
|
||||||
body {{ font-family: sans-serif; margin: 40px; }}
|
body {{ font-family: sans-serif; margin: 40px; }}
|
||||||
.back-btn {{ display: inline-block; padding: 5px 10px; background: #eee; border: 1px solid #ccc; text-decoration: none; color: #333; }}
|
.back-btn {{ display: inline-block; padding: 5px 10px; background: #eee; border: 1px solid #ccc; text-decoration: none; color: #333; }}
|
||||||
|
h1 a {{ text-decoration: none; color: inherit; }}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Register</h1>
|
<h1><a href="/">SimpliestFS</a></h1>
|
||||||
|
<h2>Register</h2>
|
||||||
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
|
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
|
||||||
<p><a class="back-btn" href="/">Back to Home</a></p>
|
<p><a class="back-btn" href="/">Back to Home</a></p>
|
||||||
</body>
|
</body>
|
||||||
@ -260,6 +270,11 @@ class FileServerHandler(BaseHTTPRequestHandler):
|
|||||||
self.send_html(content, 401)
|
self.send_html(content, 401)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# If already authorized
|
||||||
|
username = self.get_session_user()
|
||||||
|
if username:
|
||||||
|
self.send_redirect("/files")
|
||||||
|
return
|
||||||
# GET /login
|
# GET /login
|
||||||
content = self.render_login_form()
|
content = self.render_login_form()
|
||||||
self.send_html(content)
|
self.send_html(content)
|
||||||
@ -269,17 +284,19 @@ class FileServerHandler(BaseHTTPRequestHandler):
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Login - {CONFIG['ui']['title']}</title>
|
<title>Login - SimpliestFS</title>
|
||||||
<style>
|
<style>
|
||||||
body {{ font-family: sans-serif; margin: 40px; }}
|
body {{ font-family: sans-serif; margin: 40px; }}
|
||||||
form {{ max-width: 300px; }}
|
form {{ max-width: 300px; }}
|
||||||
input, button {{ width: 100%; padding: 8px; margin: 5px 0; }}
|
input, button {{ width: 100%; padding: 8px; margin: 5px 0; }}
|
||||||
.error {{ color: red; }}
|
.error {{ color: red; }}
|
||||||
.back-btn {{ display: inline-block; padding: 5px 10px; background: #eee; border: 1px solid #ccc; text-decoration: none; color: #333; }}
|
.back-btn {{ display: inline-block; padding: 5px 10px; background: #eee; border: 1px solid #ccc; text-decoration: none; color: #333; }}
|
||||||
|
h1 a {{ text-decoration: none; color: inherit; }}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Login</h1>
|
<h1><a href="/">SimpliestFS</a></h1>
|
||||||
|
<h2>Login</h2>
|
||||||
{f'<p class="error">{error}</p>' if error else ''}
|
{f'<p class="error">{error}</p>' if error else ''}
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
<input type="text" name="username" placeholder="Username" required>
|
<input type="text" name="username" placeholder="Username" required>
|
||||||
@ -327,16 +344,18 @@ class FileServerHandler(BaseHTTPRequestHandler):
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>My Files - {CONFIG['ui']['title']}</title>
|
<title>My Files - SimpliestFS</title>
|
||||||
<style>
|
<style>
|
||||||
body {{ font-family: sans-serif; margin: 40px; }}
|
body {{ font-family: sans-serif; margin: 40px; }}
|
||||||
.upload-btn {{ display: inline-block; padding: 5px 10px; background: #eee; border: 1px solid #ccc; text-decoration: none; color: #333; }}
|
.upload-btn {{ display: inline-block; padding: 5px 10px; background: #eee; border: 1px solid #ccc; text-decoration: none; color: #333; }}
|
||||||
.back-btn {{ display: inline-block; padding: 5px 10px; background: #eee; border: 1px solid #ccc; text-decoration: none; color: #333; }}
|
.back-btn {{ display: inline-block; padding: 5px 10px; background: #eee; border: 1px solid #ccc; text-decoration: none; color: #333; }}
|
||||||
.quota-info {{ margin: 20px 0; font-size: 0.9em; color: #666; }}
|
.quota-info {{ margin: 20px 0; font-size: 0.9em; color: #666; }}
|
||||||
|
h1 a {{ text-decoration: none; color: inherit; }}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>My Files</h1>
|
<h1><a href="/">SimpliestFS</a></h1>
|
||||||
|
<h2>My Files</h2>
|
||||||
<div class="quota-info">
|
<div class="quota-info">
|
||||||
Quota: {CONFIG['storage']['default_quota_mb']} MB | Used: {used_mb:.2f} MB
|
Quota: {CONFIG['storage']['default_quota_mb']} MB | Used: {used_mb:.2f} MB
|
||||||
</div>
|
</div>
|
||||||
@ -346,7 +365,10 @@ class FileServerHandler(BaseHTTPRequestHandler):
|
|||||||
</form>
|
</form>
|
||||||
<hr>
|
<hr>
|
||||||
{files_html if files_html else "<p>No files yet.</p>"}
|
{files_html if files_html else "<p>No files yet.</p>"}
|
||||||
<p><a class="back-btn" href="/logout">Logout</a></p>
|
<p>
|
||||||
|
<a class="back-btn" href="/logout">Logout</a>
|
||||||
|
<a class="back-btn" href="/">Back to Home</a>
|
||||||
|
</p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
"""
|
"""
|
||||||
@ -495,14 +517,16 @@ class FileServerHandler(BaseHTTPRequestHandler):
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Explore Files - {CONFIG['ui']['title']}</title>
|
<title>Explore Files - SimpliestFS</title>
|
||||||
<style>
|
<style>
|
||||||
body {{ font-family: sans-serif; margin: 40px; }}
|
body {{ font-family: sans-serif; margin: 40px; }}
|
||||||
.back-btn {{ display: inline-block; padding: 5px 10px; background: #eee; border: 1px solid #ccc; text-decoration: none; color: #333; }}
|
.back-btn {{ display: inline-block; padding: 5px 10px; background: #eee; border: 1px solid #ccc; text-decoration: none; color: #333; }}
|
||||||
|
h1 a {{ text-decoration: none; color: inherit; }}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Explore Files</h1>
|
<h1><a href="/">SimpliestFS</a></h1>
|
||||||
|
<h2>Explore Files</h2>
|
||||||
<p>All users:</p>
|
<p>All users:</p>
|
||||||
{users_html if users_html else "<p>No users yet.</p>"}
|
{users_html if users_html else "<p>No users yet.</p>"}
|
||||||
<p><a class="back-btn" href="/">Back to Home</a></p>
|
<p><a class="back-btn" href="/">Back to Home</a></p>
|
||||||
@ -536,14 +560,16 @@ class FileServerHandler(BaseHTTPRequestHandler):
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>{username}'s Files - {CONFIG['ui']['title']}</title>
|
<title>{username}'s Files - SimpliestFS</title>
|
||||||
<style>
|
<style>
|
||||||
body {{ font-family: sans-serif; margin: 40px; }}
|
body {{ font-family: sans-serif; margin: 40px; }}
|
||||||
.back-btn {{ display: inline-block; padding: 5px 10px; background: #eee; border: 1px solid #ccc; text-decoration: none; color: #333; }}
|
.back-btn {{ display: inline-block; padding: 5px 10px; background: #eee; border: 1px solid #ccc; text-decoration: none; color: #333; }}
|
||||||
|
h1 a {{ text-decoration: none; color: inherit; }}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>{username}'s Files</h1>
|
<h1><a href="/">SimpliestFS</a></h1>
|
||||||
|
<h2>{username}'s Files</h2>
|
||||||
{files_html if files_html else "<p>No files.</p>"}
|
{files_html if files_html else "<p>No files.</p>"}
|
||||||
<p><a class="back-btn" href="/explore">Back to All Users</a></p>
|
<p><a class="back-btn" href="/explore">Back to All Users</a></p>
|
||||||
</body>
|
</body>
|
||||||
@ -724,6 +750,9 @@ def main():
|
|||||||
load_config()
|
load_config()
|
||||||
init_db()
|
init_db()
|
||||||
|
|
||||||
|
# Log startup
|
||||||
|
log("Starting SimpliestFS server...")
|
||||||
|
|
||||||
# Start session cleanup thread
|
# Start session cleanup thread
|
||||||
cleanup_thread = threading.Thread(target=session_cleanup, daemon=True)
|
cleanup_thread = threading.Thread(target=session_cleanup, daemon=True)
|
||||||
cleanup_thread.start()
|
cleanup_thread.start()
|
||||||
@ -731,6 +760,7 @@ def main():
|
|||||||
# Start server
|
# Start server
|
||||||
server_address = (CONFIG["server"]["host"], CONFIG["server"]["port"])
|
server_address = (CONFIG["server"]["host"], CONFIG["server"]["port"])
|
||||||
httpd = HTTPServer(server_address, FileServerHandler)
|
httpd = HTTPServer(server_address, FileServerHandler)
|
||||||
|
log(f"SimpliestFS server running on {CONFIG['server']['host']}:{CONFIG['server']['port']}")
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user