Sign/Log in page was added with good layout, visuals and responsiveness

This commit is contained in:
Always-Amulya7
2025-09-04 22:04:47 +05:30
parent d75b15c7bd
commit 23cc0ab100
7 changed files with 445 additions and 104 deletions
+57 -90
View File
@@ -1,54 +1,64 @@
from flask import Flask, render_template_string, send_file, request, Response
from flask import Flask, render_template, send_file, request, Response, redirect, url_for, make_response, render_template_string
import os
from functools import wraps
import pyfiglet
print(r"""
__ __ _ ____
\ \ / /__| |__ / ___| ___ _ ____ _____ _ __
\ \ /\ / / _ \ '_ \ \___ \ / _ \ '__\ \ / / _ \ '__|
\ V V / __/ |_) | ___) | __/ | \ V / __/ |
\_/\_/ \___|_.__/ |____/ \___|_| \_/ \___|_|
# Use pyfiglet for CLI art
ascii_banner = pyfiglet.figlet_format("Web Server")
print(ascii_banner)
app = Flask(__name__, static_folder="Sign in")
Github:https://github.com/Stalin-143
""")
# Ask user where the log file is
log_file_path = input("Enter the full path for the log file (e.g., /path/to/logfile.txt): ")
# Secret key for sessions
app.secret_key = 'your_super_secret_key_here'
# Serve login/signup page
@app.route('/login')
def login():
return send_file('Sign in/index.html')
# Handle login form submission
@app.route('/login', methods=['POST'])
def handle_login():
username = request.form.get('username')
password = request.form.get('password')
if username and password:
resp = make_response(redirect(url_for('home')))
resp.set_cookie('session_id', 'authenticated_user', max_age=3600, httponly=True)
return resp
return 'Invalid Credentials', 401
@app.route('/')
def home():
session_id = request.cookies.get('session_id')
app = Flask(__name__)
if session_id == 'authenticated_user':
if os.path.exists(log_file_path):
with open(log_file_path, 'r') as file:
log_contents = file.read()
else:
log_contents = "Log file not found."
return render_template_string(HTML_TEMPLATE, log_file_path=log_file_path, log_contents=log_contents)
return redirect(url_for('login'))
@app.route('/download')
def download_log():
session_id = request.cookies.get('session_id')
if session_id == 'authenticated_user':
if os.path.exists(log_file_path):
return send_file(log_file_path, as_attachment=True)
return "Log file not found."
return redirect(url_for('login'))
# Specify the location of the log file (this should be provided by the user)
log_file_path = input("Enter the file path: ")
# Change this as needed
# Logout
@app.route('/logout')
def logout():
resp = make_response(redirect(url_for('login')))
resp.set_cookie('session_id', '', expires=0)
return resp
# Basic Authentication
USERNAME = 'admin'
PASSWORD = 'admin'
# Function to prompt for username and password if not authenticated
def check_auth(username, password):
return username == USERNAME and password == PASSWORD
# Function to require authentication for routes
def authenticate():
return Response(
'Unauthorized Access. Please log in with correct credentials.', 401,
{'WWW-Authenticate': 'Basic realm="Login Required"'})
# Decorator to enforce authentication
def requires_auth(f):
@wraps(f)
def decorated(*args, **kwargs):
auth = request.authorization
if not auth or not check_auth(auth.username, auth.password):
return authenticate()
return f(*args, **kwargs)
return decorated
# HTML template to display the log contents and provide a download link
HTML_TEMPLATE = '''
<!DOCTYPE html>
<html lang="en">
@@ -57,68 +67,25 @@ HTML_TEMPLATE = '''
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Keylogger Log Viewer</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 20px;
}
h1 {
color: #333;
}
pre {
background-color: #fff;
padding: 15px;
border: 1px solid #ccc;
max-height: 400px;
overflow-y: scroll;
}
.button {
padding: 10px 15px;
background-color: #4CAF50;
color: white;
text-align: center;
border: none;
cursor: pointer;
margin-top: 20px;
text-decoration: none;
}
.button:hover {
background-color: #45a049;
}
body { font-family: Arial, sans-serif; background-color: #f0f0f0; margin: 0; padding: 20px; }
h1 { color: #333; }
pre { background-color: #fff; padding: 15px; border: 1px solid #ccc; max-height: 400px; overflow-y: scroll; }
.button { padding: 10px 15px; background-color: #4CAF50; color: white; text-align: center; border: none; cursor: pointer; margin-top: 20px; text-decoration: none; }
.button:hover { background-color: #45a049; }
.logout { background-color: #f44336; margin-left: 10px; }
.logout:hover { background-color: #d32f2f; }
</style>
</head>
<body>
<h1>Log File: {{ log_file_path }}</h1>
<h2>Log File Contents:</h2>
<pre>{{ log_contents }}</pre>
<a href="{{ url_for('download_log') }}" class="button">Download Log File</a>
<a href="{{ url_for('logout') }}" class="button logout">Logout</a>
</body>
</html>
'''
# Route to display the log file contents and provide a download link
@app.route('/')
@requires_auth
def home():
if os.path.exists(log_file_path):
with open(log_file_path, 'r') as file:
log_contents = file.read()
else:
log_contents = "Log file not found."
return render_template_string(HTML_TEMPLATE, log_file_path=log_file_path, log_contents=log_contents)
# Route to download the log file
@app.route('/download')
@requires_auth
def download_log():
if os.path.exists(log_file_path):
return send_file(log_file_path, as_attachment=True)
return "Log file not found."
if __name__ == '__main__':
debug_mode = os.getenv('FLASK_DEBUG', 'False').lower() in ['true', '1', 't']
app.run(debug=debug_mode)