This commit is contained in:
2026-06-11 13:18:22 +03:00
parent 7525a20a70
commit a874ba9692
3 changed files with 450 additions and 111 deletions
+118 -111
View File
@@ -58,56 +58,46 @@ class FileServerHandler(BaseHTTPRequestHandler):
def handle_main_page(self):
content = f"""
<!DOCTYPE html>
<html>
<head>
<title>SimpliestFS</title>
<style>
body {{ font-family: sans-serif; margin: 40px; font-size: 1em; }}
.btn {{ font-size: 1.5em; display: inline-block; padding: 10px 20px; margin: 10px; background: #eee; border: 1px solid #ccc; text-decoration: none; color: #333; }}
.btn:hover {{ background: #ddd; }}
.disclaimer {{ margin-top: 30px; font-size: 0.9em; color: #666; }}
h1 a {{ text-decoration: none; color: inherit; }}
</style>
</head>
<body>
<h1><a href="/">SimpliestFS</a></h1>
<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 (prefered): <a href="https://t.me/justuser_31">@justuser_31</a></p>
<p>
<a class="btn" href="/register">Register</a>
<a class="btn" href="/login">Login</a>
<a class="btn" href="/explore">Explore Files</a>
</p>
<div class="disclaimer">
Note: NO ENCRYPTION, no external databases. As simple as possible.
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>SimpliestFS</title>
<link rel="stylesheet" href="/static/style.css">
</head>
<body class="main-page">
<h1><a href="/">SimpliestFS</a></h1>
<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 (prefered): <a href="https://t.me/justuser_31">@justuser_31</a></p>
<p>
<a class="btn" href="/register">Register</a>
<a class="btn" href="/login">Login</a>
<a class="btn" href="/explore">Explore Files</a>
</p>
<div class="disclaimer">
Note: NO ENCRYPTION, no external databases. As simple as possible.
</div>
</body>
</html>
"""
self.send_html(content)
def handle_register_page(self):
content = f"""
<!DOCTYPE html>
<html>
<head>
<title>Register - SimpliestFS</title>
<style>
body {{ font-family: sans-serif; margin: 40px; font-size: 2em; }}
.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>
</head>
<body>
<h1><a href="/">SimpliestFS</a></h1>
<h2>Register</h2>
<p>{CONFIG["ui"]["register_info"]}</p>
<p><a class="back-btn" href="/">Back to Home</a></p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Register - SimpliestFS</title>
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<h1><a href="/">SimpliestFS</a></h1>
<h2>Register</h2>
<p>{CONFIG["ui"]["register_info"]}</p>
<p><a class="back-btn" href="/">Back to Home</a></p>
</body>
</html>
"""
self.send_html(content)
@@ -161,31 +151,24 @@ class FileServerHandler(BaseHTTPRequestHandler):
def render_login_form(self, error=""):
content = f"""
<!DOCTYPE html>
<html>
<head>
<title>Login - SimpliestFS</title>
<style>
body {{ font-family: sans-serif; margin: 40px; font-size: 1em; }}
form {{ max-width: 300px; }}
input, button {{ width: 100%; padding: 8px; margin: 5px 0; font-size: 2vh; }}
.error {{ color: red; }}
.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>
</head>
<body>
<h1><a href="/">SimpliestFS</a></h1>
<h2>Login</h2>
{f'<p class="error">{error}</p>' if error else ""}
<form method="POST">
<input type="text" name="username" placeholder="Username" required>
<input type="password" name="password" placeholder="Password" required>
<button type="submit">Login</button>
</form>
<p><a class="back-btn" href="/">Back to Home</a></p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Login - SimpliestFS</title>
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<h1><a href="/">SimpliestFS</a></h1>
<h2>Login</h2>
{f'<p class="error">{error}</p>' if error else ""}
<form method="POST" class="login-form">
<input type="text" name="username" placeholder="Username" required>
<input type="password" name="password" placeholder="Password" required>
<button type="submit">Login</button>
</form>
<p><a class="back-btn" href="/">Back to Home</a></p>
</body>
</html>
"""
return content
@@ -227,37 +210,30 @@ class FileServerHandler(BaseHTTPRequestHandler):
"""
content = f"""
<!DOCTYPE html>
<html>
<head>
<title>My Files - SimpliestFS</title>
<style>
body {{ font-family: sans-serif; margin: 40px; font-size: 1.5em; }}
.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; }}
.quota-info {{ margin: 20px 0; font-size: 0.9em; color: #666; }}
.regular-button {{ font-size: 1em; }}
h1 a {{ text-decoration: none; color: inherit; }}
</style>
</head>
<body>
<h1><a href="/">SimpliestFS</a></h1>
<h2>My Files</h2>
<div class="quota-info">
Quota: {available_mb} MB | Used: {used_mb:.2f} MB
</div>
<form method="POST" enctype="multipart/form-data" action="/upload">
<input class = "regular-button" type="file" name="file" required>
<button class = "regular-button" type="submit">Upload</button>
</form>
<hr>
{files_html if files_html else "<p>No files yet.</p>"}
<p>
<a class="back-btn" href="/logout">Logout</a>
<a class="back-btn" href="/">Back to Home</a>
</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>My Files - SimpliestFS</title>
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<h1><a href="/">SimpliestFS</a></h1>
<h2>My Files</h2>
<div class="quota-info">
Quota: {available_mb} MB | Used: {used_mb:.2f} MB
</div>
<form method="POST" enctype="multipart/form-data" action="/upload">
<input class="regular-button" type="file" name="file" required>
<button class="regular-button" type="submit">Upload</button>
</form>
<hr>
{files_html if files_html else "<p>No files yet.</p>"}
<p>
<a class="back-btn" href="/logout">Logout</a>
<a class="back-btn" href="/">Back to Home</a>
</p>
</body>
</html>
"""
self.send_html(content)
@@ -405,11 +381,7 @@ class FileServerHandler(BaseHTTPRequestHandler):
<html>
<head>
<title>Explore Files - SimpliestFS</title>
<style>
body {{ font-family: sans-serif; margin: 40px; font-size: 1.5em; }}
.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>
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<h1><a href="/">SimpliestFS</a></h1>
@@ -448,11 +420,7 @@ class FileServerHandler(BaseHTTPRequestHandler):
<html>
<head>
<title>{username}'s Files - SimpliestFS</title>
<style>
body {{ font-family: sans-serif; margin: 40px; font-size: 1em; }}
.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>
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<h1><a href="/">SimpliestFS</a></h1>
@@ -573,6 +541,41 @@ class FileServerHandler(BaseHTTPRequestHandler):
database.DB_CONN.commit()
self.send_html("<h1>Account deleted</h1>")
def handle_static_file(self):
if self.path.startswith("/static/"):
file_path = self.path[1:] # Remove leading slash
try:
with open(file_path, "r") as file:
content = file.read()
if file_path.endswith(".css"):
self.send_response(200)
self.send_header("Content-type", "text/css")
self.end_headers()
self.wfile.write(content.encode())
else:
self.send_error(404)
except FileNotFoundError:
self.send_error(404)
return True
return False
def handle_favicon(self):
if self.path == "/favicon.ico":
file_path = os.path.join("static", self.path[1:])
try:
with open(file_path, "rb") as file: # Open in binary mode
content = file.read()
self.send_response(200)
self.send_header(
"Content-type", "image/x-icon"
) # Correct MIME type
self.end_headers()
self.wfile.write(content) # Write bytes directly
except FileNotFoundError:
self.send_error(404)
return True
return False
def do_GET(self):
parsed_path = urlparse(self.path)
path = parsed_path.path
@@ -597,6 +600,10 @@ class FileServerHandler(BaseHTTPRequestHandler):
else:
username = parts[0]
self.handle_explore_user(username)
elif path.startswith("/static/") and not path.endswith("/"):
self.handle_static_file()
elif path == "/favicon.ico":
self.handle_favicon()
else:
self.send_html("<h1>Not Found</h1>", 404)