added download button
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
# Krawl Honeypot Configuration
|
# Krawl Honeypot Configuration
|
||||||
|
|
||||||
server:
|
server:
|
||||||
port: 5000
|
port: 1234
|
||||||
delay: 100 # Response delay in milliseconds
|
delay: 100 # Response delay in milliseconds
|
||||||
timezone: null # e.g., "America/New_York", "Europe/Paris" or null for system default
|
timezone: null # e.g., "America/New_York", "Europe/Paris" or null for system default
|
||||||
|
|
||||||
|
|||||||
1
src/exports/malicious_ips.txt
Normal file
1
src/exports/malicious_ips.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
127.0.0.1
|
||||||
@@ -408,7 +408,8 @@ class Handler(BaseHTTPRequestHandler):
|
|||||||
try:
|
try:
|
||||||
stats = self.tracker.get_stats()
|
stats = self.tracker.get_stats()
|
||||||
timezone = str(self.config.timezone) if self.config.timezone else 'UTC'
|
timezone = str(self.config.timezone) if self.config.timezone else 'UTC'
|
||||||
self.wfile.write(generate_dashboard(stats, timezone).encode())
|
dashboard_path = self.config.dashboard_secret_path
|
||||||
|
self.wfile.write(generate_dashboard(stats, timezone, dashboard_path).encode())
|
||||||
except BrokenPipeError:
|
except BrokenPipeError:
|
||||||
pass
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -442,6 +443,35 @@ class Handler(BaseHTTPRequestHandler):
|
|||||||
self.wfile.write(json.dumps({'error': str(e)}).encode())
|
self.wfile.write(json.dumps({'error': str(e)}).encode())
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# API endpoint for downloading malicious IPs file
|
||||||
|
if self.config.dashboard_secret_path and self.path == f"{self.config.dashboard_secret_path}/api/download/malicious_ips.txt":
|
||||||
|
import os
|
||||||
|
file_path = os.path.join(os.path.dirname(__file__), 'exports', 'malicious_ips.txt')
|
||||||
|
try:
|
||||||
|
if os.path.exists(file_path):
|
||||||
|
with open(file_path, 'rb') as f:
|
||||||
|
content = f.read()
|
||||||
|
self.send_response(200)
|
||||||
|
self.send_header('Content-type', 'text/plain')
|
||||||
|
self.send_header('Content-Disposition', 'attachment; filename="malicious_ips.txt"')
|
||||||
|
self.send_header('Content-Length', str(len(content)))
|
||||||
|
self.end_headers()
|
||||||
|
self.wfile.write(content)
|
||||||
|
else:
|
||||||
|
self.send_response(404)
|
||||||
|
self.send_header('Content-type', 'text/plain')
|
||||||
|
self.end_headers()
|
||||||
|
self.wfile.write(b'File not found')
|
||||||
|
except BrokenPipeError:
|
||||||
|
pass
|
||||||
|
except Exception as e:
|
||||||
|
self.app_logger.error(f"Error serving malicious IPs file: {e}")
|
||||||
|
self.send_response(500)
|
||||||
|
self.send_header('Content-type', 'text/plain')
|
||||||
|
self.end_headers()
|
||||||
|
self.wfile.write(b'Internal server error')
|
||||||
|
return
|
||||||
|
|
||||||
self.tracker.record_access(client_ip, self.path, user_agent, method='GET')
|
self.tracker.record_access(client_ip, self.path, user_agent, method='GET')
|
||||||
|
|
||||||
self.analyzer.infer_user_category(client_ip)
|
self.analyzer.infer_user_category(client_ip)
|
||||||
|
|||||||
@@ -38,12 +38,13 @@ def format_timestamp(iso_timestamp: str, timezone: str = 'UTC', time_only: bool
|
|||||||
return iso_timestamp.split("T")[1][:8] if "T" in iso_timestamp else iso_timestamp
|
return iso_timestamp.split("T")[1][:8] if "T" in iso_timestamp else iso_timestamp
|
||||||
|
|
||||||
|
|
||||||
def generate_dashboard(stats: dict, timezone: str = 'UTC') -> str:
|
def generate_dashboard(stats: dict, timezone: str = 'UTC', dashboard_path: str = '') -> str:
|
||||||
"""Generate dashboard HTML with access statistics
|
"""Generate dashboard HTML with access statistics
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
stats: Statistics dictionary
|
stats: Statistics dictionary
|
||||||
timezone: IANA timezone string (e.g., 'Europe/Paris', 'America/New_York')
|
timezone: IANA timezone string (e.g., 'Europe/Paris', 'America/New_York')
|
||||||
|
dashboard_path: The secret dashboard path for generating API URLs
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Generate IP rows with clickable functionality for dropdown stats
|
# Generate IP rows with clickable functionality for dropdown stats
|
||||||
@@ -164,12 +165,36 @@ def generate_dashboard(stats: dict, timezone: str = 'UTC') -> str:
|
|||||||
.container {{
|
.container {{
|
||||||
max-width: 1400px;
|
max-width: 1400px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
position: relative;
|
||||||
}}
|
}}
|
||||||
h1 {{
|
h1 {{
|
||||||
color: #58a6ff;
|
color: #58a6ff;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin-bottom: 40px;
|
margin-bottom: 40px;
|
||||||
}}
|
}}
|
||||||
|
.download-section {{
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
}}
|
||||||
|
.download-btn {{
|
||||||
|
display: inline-block;
|
||||||
|
padding: 8px 14px;
|
||||||
|
background: #238636;
|
||||||
|
color: #ffffff;
|
||||||
|
text-decoration: none;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 13px;
|
||||||
|
transition: background 0.2s;
|
||||||
|
border: 1px solid #2ea043;
|
||||||
|
}}
|
||||||
|
.download-btn:hover {{
|
||||||
|
background: #2ea043;
|
||||||
|
}}
|
||||||
|
.download-btn:active {{
|
||||||
|
background: #1f7a2f;
|
||||||
|
}}
|
||||||
.stats-grid {{
|
.stats-grid {{
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||||
@@ -450,6 +475,11 @@ def generate_dashboard(stats: dict, timezone: str = 'UTC') -> str:
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
<div class="download-section">
|
||||||
|
<a href="{dashboard_path}/api/download/malicious_ips.txt" class="download-btn" download>
|
||||||
|
Export Malicious IPs
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
<h1>Krawl Dashboard</h1>
|
<h1>Krawl Dashboard</h1>
|
||||||
|
|
||||||
<div class="stats-grid">
|
<div class="stats-grid">
|
||||||
@@ -599,6 +629,7 @@ def generate_dashboard(stats: dict, timezone: str = 'UTC') -> str:
|
|||||||
<script>
|
<script>
|
||||||
// Server timezone configuration
|
// Server timezone configuration
|
||||||
const SERVER_TIMEZONE = '{timezone}';
|
const SERVER_TIMEZONE = '{timezone}';
|
||||||
|
const DASHBOARD_PATH = '{dashboard_path}';
|
||||||
|
|
||||||
// Convert UTC timestamp to configured timezone
|
// Convert UTC timestamp to configured timezone
|
||||||
function formatTimestamp(isoTimestamp) {{
|
function formatTimestamp(isoTimestamp) {{
|
||||||
@@ -704,7 +735,7 @@ def generate_dashboard(stats: dict, timezone: str = 'UTC') -> str:
|
|||||||
if (dropdown) {{
|
if (dropdown) {{
|
||||||
dropdown.innerHTML = '<div class="loading">Loading stats...</div>';
|
dropdown.innerHTML = '<div class="loading">Loading stats...</div>';
|
||||||
try {{
|
try {{
|
||||||
const response = await fetch(`${{window.location.pathname}}/api/ip-stats/${{ip}}`, {{
|
const response = await fetch(`${{DASHBOARD_PATH}}/api/ip-stats/${{ip}}`, {{
|
||||||
cache: 'no-store',
|
cache: 'no-store',
|
||||||
headers: {{
|
headers: {{
|
||||||
'Cache-Control': 'no-cache',
|
'Cache-Control': 'no-cache',
|
||||||
|
|||||||
Reference in New Issue
Block a user