This commit is contained in:
ghostersk
2025-07-16 15:39:28 +01:00
commit cb13605d85
17 changed files with 4014 additions and 0 deletions

92
web/dns.html Normal file
View File

@@ -0,0 +1,92 @@
<!DOCTYPE html>
<html>
<head>
<title>DNS Tools</title>
<link rel="stylesheet" href="/static/style.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
.dns-tools-container { max-width: 900px; margin: 0 auto; }
.dns-query-form { display: flex; gap: 10px; margin-bottom: 10px; }
.dns-query-form input, .dns-query-form select { padding: 7px; border-radius: 4px; border: 1px solid #444; background: #232323; color: #e0e0e0; }
.dns-query-form button { padding: 7px 16px; }
.dns-results { margin-top: 10px; }
.dns-result-block { background: #232323; border-radius: 6px; margin-bottom: 12px; padding: 12px; box-shadow: 0 2px 4px rgba(0,0,0,0.12); }
.dns-result-block pre { white-space: pre-wrap; word-break: break-word; font-size: 1em; }
.save-btns { margin-bottom: 10px; }
</style>
</head>
<body>
<nav>
<a href="/">Analyze New Header</a>
<a href="/dns">DNS Tools</a>
<a href="/password">Password Generator</a>
</nav>
<div class="dns-tools-container">
<h1>DNS Tools</h1>
<form class="dns-query-form" id="dnsForm" onsubmit="return false;">
<input type="text" id="dnsInput" placeholder="Enter domain or IP" required>
<select id="dnsType">
<option value="A">A</option>
<option value="AAAA">AAAA</option>
<option value="MX">MX</option>
<option value="TXT">TXT</option>
<option value="NS">NS</option>
<option value="CNAME">CNAME</option>
<option value="PTR">PTR</option>
<option value="SOA">SOA</option>
<option value="SPF">SPF</option>
<option value="DKIM">DKIM</option>
<option value="DMARC">DMARC</option>
<option value="WHOIS">WHOIS</option>
</select>
<input type="text" id="dnsServer" placeholder="Custom DNS server (optional)" style="width:180px;" autocomplete="off">
<button type="submit">Query</button>
</form>
<div class="save-btns">
<button onclick="saveResults('csv')">Save as CSV</button>
<button onclick="saveResults('txt')">Save as TXT</button>
</div>
<div class="dns-results" id="dnsResults"></div>
</div>
<script>
let results = [];
function renderResults() {
const container = document.getElementById('dnsResults');
container.innerHTML = '';
results.forEach(r => {
const block = document.createElement('div');
block.className = 'dns-result-block';
block.innerHTML = `<b>${r.type} for ${r.query}</b><br><pre>${r.result}</pre>`;
container.appendChild(block);
});
}
document.getElementById('dnsForm').addEventListener('submit', async function() {
const query = document.getElementById('dnsInput').value.trim();
const type = document.getElementById('dnsType').value;
let url = `/api/dns?query=${encodeURIComponent(query)}&type=${encodeURIComponent(type)}`;
const dnsServer = document.getElementById('dnsServer').value.trim();
if (dnsServer) url += `&server=${encodeURIComponent(dnsServer)}`;
let res = await fetch(url);
let data = await res.text();
results.unshift({query, type, result: data});
renderResults();
});
function saveResults(format) {
let content = '';
if (format === 'csv') {
content = 'Type,Query,Result\n' + results.map(r => `${r.type},${r.query},"${r.result.replace(/"/g, '""')}"`).join('\n');
} else {
content = results.map(r => `${r.type} for ${r.query}\n${r.result}\n`).join('\n');
}
const blob = new Blob([content], {type: 'text/plain'});
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = `dnswhois_results.${format}`;
link.click();
}
</script>
</body>
</html>

BIN
web/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

BIN
web/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

374
web/index.html Normal file
View File

@@ -0,0 +1,374 @@
<!DOCTYPE html>
<html>
<head>
<title>Email Header Analyzer</title>
<link rel="stylesheet" href="/static/style.css">
<script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<nav>
<a href="/">Analyze New Header</a>
<a href="/dns">DNS Tools</a>
<a href="/password">Password Generator</a>
</nav>
<div class="container">
<h1>Email Header Analyzer</h1>
{{if not .From}}
<form method="POST">
<textarea name="headers" placeholder="Paste email headers here..."></textarea>
<br>
<button type="submit">Analyze Headers</button>
</form>
{{end}}
{{if .From}}
<div id="report" class="container">
<div class="section" style="display: flex; align-items: flex-start; justify-content: space-between; gap: 30px;">
<div style="flex: 1 1 0; min-width: 0;">
<h2>Sender Identification</h2>
<div class="grid">
<div>
<p><b>Envelope Sender (Return-Path):</b> {{.EnvelopeSender}}</p>
<p><b>From Domain:</b> {{.FromDomain}}</p>
<p><b>Sending Server:</b> {{.SendingServer}}</p>
</div>
<div class="score-indicators">
<span class="status {{if .SPFPass}}good{{else}}error{{end}}" title="SPF">SPF {{if .SPFPass}}✓{{else}}✗{{end}}</span>
<span class="status {{if .DMARCPass}}good{{else}}error{{end}}" title="DMARC">DMARC {{if .DMARCPass}}✓{{else}}✗{{end}}</span>
<span class="status {{if .DKIMPass}}good{{else}}error{{end}}" title="DKIM">DKIM {{if .DKIMPass}}✓{{else}}✗{{end}}</span>
<span class="status {{if .Encrypted}}good{{else}}error{{end}}" title="Encrypted">Encrypted {{if .Encrypted}}✓{{else}}✗{{end}}</span>
{{if .Blacklists}}
<span class="status error" title="{{range .Blacklists}}{{.}}, {{end}}">Blacklisted {{len .Blacklists}} times</span>
{{else}}
<span class="status good">Not listed on major blacklists</span>
{{end}}
</div>
</div>
{{if .SenderRep}}
<div>
<b><span>Sender Reputation: </span></b><div class="status {{if contains .SenderRep "EXCELLENT"}}good{{else if contains .SenderRep "GOOD"}}good{{else if contains .SenderRep "FAIR"}}warning{{else}}error{{end}}">
{{.SenderRep}}
</div>
</div>
{{end}}
<div class="explanation">
<small>
<b>Envelope Sender</b> is the real sender used for delivery (can differ from From).<br>
<b>From Domain</b> is the domain shown to the recipient.<br>
<b>Sending Server</b> is the host or IP that actually sent the message (from first Received header).<br>
If these differ, the message may be sent on behalf of another user or via a third-party service.
</small>
</div>
</div>
</div>
<details id="all-headers" class="section" style="margin-top:10px;">
<summary><b style="font-size: 1.5em;">All Email Headers Table</b></summary>
<div style="margin-bottom:10px;">
<input type="text" id="headerSearch" placeholder="Search headers..." style="width: 100%; max-width: 350px; padding: 5px; border-radius: 4px; border: 1px solid #444; background: #232323; color: #e0e0e0;">
</div>
<div style="overflow-x:auto;">
<table id="headersTable" style="width:100%; border-collapse:collapse; border:1px solid #444;">
<thead>
<tr>
<th style="text-align:left; padding:4px 8px; border:1px solid #444; width: 180px; background:#232323;">Header Name</th>
<th style="text-align:left; padding:4px 8px; border:1px solid #444; background:#232323;">Value</th>
</tr>
</thead>
<tbody>
{{range $k, $v := .AllHeaders}}
<tr>
<td style="vertical-align:top; padding:4px 8px; border:1px solid #444; word-break:break-word;">{{$k}}</td>
<td style="vertical-align:top; padding:4px 8px; border:1px solid #444; white-space:pre-wrap; word-break:break-word;">{{$v}}</td>
</tr>
{{end}}
</tbody>
</table>
</div>
</details>
<div class="section">
<h2>Basic Information</h2>
<div class="grid">
<div>
<p><b>From:</b> {{.From}}</p>
<p><b>To:</b> {{.To}}</p>
<p><b>Subject:</b> {{.Subject}}</p>
<p><b>Date:</b> {{.Date}}</p>
{{if .ReplyTo}}<p><b>Reply-To:</b> {{.ReplyTo}}</p>{{end}}
</div>
<div>
<p><b>Message-ID:</b> {{.MessageID}}</p>
<p><b>Priority:</b> {{.Priority}}</p>
<p><b>Content Type:</b> {{.ContentType}}</p>
<p><b>Encoding:</b> {{.Encoding}}</p>
</div>
</div>
</div>
<div class="section">
<h2>Mail Flow</h2>
<ul class="mail-flow">
{{range .Received}}<li>{{.}}</li>{{end}}
</ul>
</div>
{{if ne .DeliveryDelay "Insufficient data for delay analysis"}}
<div class="section">
<h2>Delivery Analysis</h2>
<p><b>Delivery Timing:</b> {{.DeliveryDelay}}</p>
{{if .GeoLocation}}<p><b>Geographic Info:</b> {{.GeoLocation}}</p>{{end}}
</div>
{{end}}
<div class="section">
<h2>Security Analysis</h2>
<div class="security-analysis-vertical">
<div class="section">
<h3>SPF Authentication</h3>
<div class="status {{if .SPFPass}}good{{else}}error{{end}}">
{{if .SPFPass}}✓ Passed{{else}}✗ Failed{{end}}
</div>
<p>{{.SPFDetails}}</p>
{{if .SPFRecord}}<pre>{{.SPFRecord}}</pre>{{end}}
{{if .SPFHeader}}
<details class="details"><summary>Show SPF Header</summary><pre>{{.SPFHeader}}</pre></details>
{{end}}
</div>
<div class="section">
<h3>DMARC Policy</h3>
<div class="status {{if .DMARCPass}}good{{else}}error{{end}}">
{{if .DMARCPass}}✓ Passed{{else}}✗ Failed{{end}}
</div>
<p>{{.DMARCDetails}}</p>
{{if .DMARCRecord}}<pre>{{.DMARCRecord}}</pre>{{end}}
{{if .DMARCHeader}}
<details class="details"><summary>Show DMARC Header</summary><pre>{{.DMARCHeader}}</pre></details>
{{end}}
</div>
<div class="section">
<h3>DKIM Signature</h3>
<div class="status {{if .DKIMPass}}good{{else}}error{{end}}">
{{if .DKIMPass}}✓ Present{{else}}✗ Missing{{end}}
</div>
<p>{{.DKIMDetails}}</p>
{{if .DKIM}}
<details class="details"><summary>Show DKIM Header</summary><pre>{{.DKIM}}</pre></details>
{{else if .DKIMHeader}}
<details class="details"><summary>Show DKIM Header</summary><pre>{{.DKIMHeader}}</pre></details>
{{end}}
</div>
</div>
</div>
<div class="section">
<h2>Encryption</h2>
<div class="status {{if .Encrypted}}good{{else}}error{{end}}">
{{if .Encrypted}}Encrypted (TLS){{else}}Not Encrypted{{end}}
</div>
<details><summary>Show Encryption Details</summary><pre>{{.EncryptionDetail}}</pre></details>
</div>
{{if .Warnings}}
<div class="section">
<h2>Warnings</h2>
<ul>
{{range .Warnings}}<li class="status warning">⚠️ {{.}}</li>{{end}}
</ul>
</div>
{{end}}
{{if .SecurityFlags}}
<div class="section">
<h2>Security Flags</h2>
<ul>
{{range .SecurityFlags}}<li class="status">🔒 {{.}}</li>{{end}}
</ul>
</div>
{{end}}
{{if .Blacklists}}
<div class="section">
<h2>Blacklist Status</h2>
<div style="margin-bottom: 6px;">
<b>Checked:</b>
{{if .SendingServer}}IP {{.SendingServer}}{{else if .FromDomain}}Domain {{.FromDomain}}{{end}}
</div>
<div class="status error">⚠️ Listed on the following blacklists:</div>
<ul>
{{range .Blacklists}}<li>{{.}}</li>{{end}}
</ul>
</div>
{{end}}
{{if .SpamFlags}}
<div class="section">
<h2>Spam Analysis</h2>
<div class="status {{if gt (len .SpamFlags) 0}}warning{{else}}good{{end}}">
{{if gt (len .SpamFlags) 0}}⚠️ Spam Indicators Found{{else}}✓ No Spam Indicators{{end}}
</div>
{{if .SpamScore}}<p><b>Spam Score:</b> {{.SpamScore}}</p>{{end}}
{{if .SpamFlags}}
<ul>
{{range .SpamFlags}}<li>{{.}}</li>{{end}}
</ul>
{{end}}
</div>
{{end}}
{{if ne .VirusInfo "No virus scanning information found"}}
<div class="section">
<h2>Virus Scanning</h2>
<div class="status good">🛡️ Virus Scanning Information</div>
<p>{{.VirusInfo}}</p>
</div>
{{end}}
{{if .PhishingRisk}}
<div class="section">
<h2>Security Risk Assessment</h2>
<div class="security-analysis-vertical">
<div class="section">
<h3>Phishing Risk</h3>
<div class="status {{if eq (index (splitString .PhishingRisk " ") 0) "HIGH"}}error{{else if eq (index (splitString .PhishingRisk " ") 0) "MEDIUM"}}warning{{else}}good{{end}}">
{{.PhishingRisk}}
</div>
</div>
<div class="section">
<h3>Spoofing Risk</h3>
<div class="status {{if contains .SpoofingRisk "POTENTIAL"}}warning{{else}}good{{end}}">
{{.SpoofingRisk}}
</div>
</div>
</div>
</div>
{{end}}
{{if .ListInfo}}
<div class="section">
<h2>Mailing List Information</h2>
<ul>
{{range .ListInfo}}<li>{{.}}</li>{{end}}
</ul>
{{if .AutoReply}}<p class="status">📧 Auto-reply message detected</p>{{end}}
{{if .BulkEmail}}<p class="status">📬 Bulk/marketing email detected</p>{{end}}
</div>
{{end}}
{{if .Compliance}}
<div class="section">
<h2>Compliance Information</h2>
<ul>
{{range .Compliance}}<li class="status good">✓ {{.}}</li>{{end}}
</ul>
</div>
{{end}}
{{if .ARC}}
<div class="section">
<h2>ARC (Authenticated Received Chain)</h2>
<details><summary>Show ARC Headers</summary>
<ul>
{{range .ARC}}<li><pre>{{.}}</pre></li>{{end}}
</ul>
</details>
</div>
{{end}}
{{if ne .BIMI "No BIMI record found"}}
<div class="section">
<h2>Brand Indicators (BIMI)</h2>
<p>{{.BIMI}}</p>
</div>
{{end}}
{{if .Attachments}}
<div class="section">
<h2>Attachment Information</h2>
<ul>
{{range .Attachments}}<li>{{.}}</li>{{end}}
</ul>
</div>
{{end}}
{{if .URLs}}
<div class="section">
<h2>URL Information</h2>
<ul>
{{range .URLs}}<li>{{.}}</li>{{end}}
</ul>
</div>
{{end}}
{{if ne .ThreadInfo "No threading information available"}}
<div class="section">
<h2>Message Threading</h2>
<details><summary>Show Threading Information</summary>
<pre>{{.ThreadInfo}}</pre>
</details>
</div>
{{end}}
<div class="section">
<button onclick="exportPDF()" type="button">Export as PDF</button>
<button onclick="exportImage()" type="button">Save as Image</button>
</div>
</div>
{{end}}
<script>
// Template helper functions for the enhanced features
function splitString(str, delimiter) {
return str.split(delimiter);
}
function contains(str, substr) {
return str.includes(substr);
}
function exportImage() {
html2canvas(document.querySelector("#report")).then(canvas => {
let link = document.createElement("a");
link.download = "email-analysis.png";
link.href = canvas.toDataURL();
link.click();
});
}
function exportPDF() {
// Expand all details before export
document.querySelectorAll('#report details').forEach(d => d.open = true);
document.getElementById('all-headers').open = true;
const element = document.getElementById('report');
const opt = {
margin: 0.1,
filename: 'email-analysis.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2, useCORS: true },
jsPDF: { unit: 'in', format: 'a4', orientation: 'portrait', putOnlyUsedFonts:true }
};
html2pdf().set(opt).from(element).save();
}
// Header table search
document.addEventListener('DOMContentLoaded', function() {
var search = document.getElementById('headerSearch');
if (search) {
search.addEventListener('input', function() {
var filter = search.value.toLowerCase();
var rows = document.querySelectorAll('#headersTable tbody tr');
rows.forEach(function(row) {
var text = row.textContent.toLowerCase();
row.style.display = text.indexOf(filter) > -1 ? '' : 'none';
});
});
}
});
</script>
</body>
</html>

664
web/password.html Normal file
View File

@@ -0,0 +1,664 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Password Generator - HeaderAnalyzer</title>
<link rel="stylesheet" href="/static/style.css">
<style>
.password-generator {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.password-output {
background: #1a1a1a;
border: 2px solid #333;
border-radius: 8px;
padding: 20px;
margin: 20px 0;
font-family: 'Courier New', monospace;
font-size: 18px;
word-break: break-all;
position: relative;
}
.password-text {
color: #00ff88;
font-weight: bold;
margin-bottom: 10px;
}
.copy-btn {
background: #007acc;
color: white;
border: none;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
}
.copy-btn:hover {
background: #005999;
}
.copy-btn.copied {
background: #00aa44;
}
.controls {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 30px;
margin: 20px 0;
}
.control-group {
background: #1a1a1a;
border: 1px solid #333;
border-radius: 8px;
padding: 20px;
}
.control-group h3 {
margin-top: 0;
color: #00ff88;
border-bottom: 1px solid #333;
padding-bottom: 10px;
}
.form-row {
margin: 15px 0;
display: flex;
align-items: center;
gap: 10px;
}
.form-row label {
flex: 1;
color: #ccc;
}
.form-row input[type="number"],
.form-row input[type="text"],
.form-row select {
background: #2a2a2a;
border: 1px solid #444;
color: #fff;
padding: 8px;
border-radius: 4px;
width: 120px;
}
.form-row input[type="text"] {
width: 200px;
}
.form-row input[type="checkbox"] {
width: auto;
}
.generate-btn {
background: #00aa44;
color: white;
border: none;
padding: 15px 30px;
border-radius: 8px;
cursor: pointer;
font-size: 16px;
font-weight: bold;
width: 100%;
margin: 20px 0;
}
.generate-btn:hover {
background: #008833;
}
.tab-buttons {
display: flex;
margin-bottom: 20px;
border-radius: 8px;
overflow: hidden;
border: 1px solid #333;
}
.tab-btn {
flex: 1;
background: #2a2a2a;
color: #ccc;
border: none;
padding: 15px;
cursor: pointer;
font-size: 16px;
}
.tab-btn.active {
background: #007acc;
color: white;
}
.tab-btn:hover:not(.active) {
background: #333;
}
.passphrase-controls {
display: none;
}
.passphrase-controls.active {
display: block;
}
.url-share {
background: #2a2a2a;
border: 1px solid #444;
border-radius: 8px;
padding: 15px;
margin: 20px 0;
}
.url-share input {
background: #1a1a1a;
border: 1px solid #333;
color: #ccc;
padding: 8px;
border-radius: 4px;
width: 100%;
font-size: 12px;
}
@media (max-width: 768px) {
.controls {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<nav>
<div class="nav-container">
<div class="nav-links">
<a href="/">Email Analysis</a>
<a href="/dns">DNS Tools</a>
<a href="/password" class="active">Password Generator</a>
</div>
</div>
</nav>
<div class="container password-generator">
<h1>🔐 Password Generator</h1>
<div class="tab-buttons">
<button class="tab-btn" id="randomTab">Random Password</button>
<button class="tab-btn active" id="passphraseTab">Passphrase</button>
</div>
<div class="password-output">
<div class="password-text" id="passwordDisplay">Click "Generate Password" to create a secure password</div>
<button class="copy-btn" id="copyBtn" onclick="copyPassword()" style="display: none;">Copy to Clipboard</button>
</div>
<button class="generate-btn" onclick="generatePassword()">🎲 Generate Password</button>
<div class="controls">
<div class="control-group">
<h3>🔧 Basic Settings</h3>
<div class="form-row">
<label for="length">Password Length:</label>
<input type="number" id="length" min="4" max="128" value="12">
</div>
<div class="form-row">
<label for="includeUpper">Include Uppercase (A-Z):</label>
<input type="checkbox" id="includeUpper" checked>
</div>
<div class="form-row">
<label for="includeLower">Include Lowercase (a-z):</label>
<input type="checkbox" id="includeLower" checked>
</div>
<div class="form-row">
<label for="numberCount">Number of Digits:</label>
<input type="number" id="numberCount" min="0" max="20" value="1">
</div>
<div class="form-row">
<label for="specialChars">Special Characters:</label>
<input type="text" id="specialChars" value="!@#$%^&*-_=+">
</div>
<div class="form-row">
<label for="noConsecutive">No consecutive identical characters:</label>
<input type="checkbox" id="noConsecutive">
</div>
</div>
<div class="control-group">
<h3>🎯 Advanced Settings</h3>
<div class="passphrase-controls active" id="passphraseControls">
<div class="form-row">
<label for="wordCount">Number of Words:</label>
<input type="number" id="wordCount" min="2" max="10" value="3">
</div>
<div class="form-row">
<label for="passphraseUseNumbers">Include Numbers:</label>
<input type="checkbox" id="passphraseUseNumbers" checked>
</div>
<div class="form-row">
<label for="passphraseUseSpecial">Include Special Characters:</label>
<input type="checkbox" id="passphraseUseSpecial" checked>
</div>
<div class="form-row">
<label for="numberPosition">Number Position:</label>
<select id="numberPosition">
<option value="end">At End</option>
<option value="start">At Start</option>
<option value="each">After Each Word</option>
</select>
</div>
</div>
<div class="form-row">
<label>Strength Indicator:</label>
<div id="strengthIndicator" style="color: #999;">Generate a password to see strength</div>
</div>
<div class="form-row">
<label>Word List Status:</label>
<div id="wordListStatus" style="color: #999; font-size: 12px;">Loading...</div>
</div>
<div class="form-row">
<label for="enableHistory">Save Password History (7 days):</label>
<input type="checkbox" id="enableHistory">
</div>
</div>
</div>
<div id="historySection" style="display: none; margin-top: 20px;">
<div class="control-group" style="max-width: 100%;">
<h3>📜 Password History</h3>
<div style="max-height: 300px; overflow-y: auto;">
<table id="historyTable" style="width: 100%; border-collapse: collapse;">
<thead>
<tr style="background: #2a2a2a;">
<th style="padding: 8px; border: 1px solid #444; text-align: left; color: #ccc;">Timestamp</th>
<th style="padding: 8px; border: 1px solid #444; text-align: left; color: #ccc;">Password</th>
<th style="padding: 8px; border: 1px solid #444; text-align: left; color: #ccc;">Type</th>
<th style="padding: 8px; border: 1px solid #444; text-align: left; color: #ccc;">Action</th>
</tr>
</thead>
<tbody id="historyBody">
</tbody>
</table>
</div>
</div>
</div>
</div>
<script>
let currentMode = 'passphrase'; // Default to passphrase
// Load settings from cookies and URL parameters
window.addEventListener('load', function() {
loadSettings();
updateShareUrl();
loadWordListInfo();
// Auto-generate if URL has parameters
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.toString()) {
generatePassword();
}
});
async function loadWordListInfo() {
try {
const response = await fetch('/api/password/info');
if (response.ok) {
const info = await response.json();
document.getElementById('wordListStatus').innerHTML =
`${info.wordCount} words from ${info.source}<br><small>Last updated: ${info.lastUpdate}</small>`;
} else {
document.getElementById('wordListStatus').textContent = 'Failed to load word list info';
}
} catch (error) {
document.getElementById('wordListStatus').textContent = 'Error loading word list info';
}
}
function switchTab(mode) {
currentMode = mode;
document.getElementById('randomTab').classList.toggle('active', mode === 'random');
document.getElementById('passphraseTab').classList.toggle('active', mode === 'passphrase');
document.getElementById('passphraseControls').classList.toggle('active', mode === 'passphrase');
saveSettings();
updateShareUrl();
}
document.getElementById('randomTab').addEventListener('click', () => switchTab('random'));
document.getElementById('passphraseTab').addEventListener('click', () => switchTab('passphrase'));
function getConfig() {
return {
length: parseInt(document.getElementById('length').value),
includeUpper: document.getElementById('includeUpper').checked,
includeLower: document.getElementById('includeLower').checked,
numberCount: parseInt(document.getElementById('numberCount').value),
specialChars: document.getElementById('specialChars').value,
noConsecutive: document.getElementById('noConsecutive').checked,
usePassphrase: currentMode === 'passphrase',
wordCount: parseInt(document.getElementById('wordCount').value),
numberPosition: document.getElementById('numberPosition').value,
passphraseUseNumbers: document.getElementById('passphraseUseNumbers').checked,
passphraseUseSpecial: document.getElementById('passphraseUseSpecial').checked,
enableHistory: document.getElementById('enableHistory').checked
};
}
function setConfig(config) {
document.getElementById('length').value = config.length || 12;
document.getElementById('includeUpper').checked = config.includeUpper !== false;
document.getElementById('includeLower').checked = config.includeLower !== false;
document.getElementById('numberCount').value = config.numberCount || 1;
document.getElementById('specialChars').value = config.specialChars || '!@#$%^&*-_=+';
document.getElementById('noConsecutive').checked = config.noConsecutive || false;
document.getElementById('wordCount').value = config.wordCount || 3;
document.getElementById('numberPosition').value = config.numberPosition || 'end';
document.getElementById('passphraseUseNumbers').checked = config.passphraseUseNumbers !== false;
document.getElementById('passphraseUseSpecial').checked = config.passphraseUseSpecial !== false;
document.getElementById('enableHistory').checked = config.enableHistory || false;
if (config.usePassphrase !== false) { // Default to passphrase
switchTab('passphrase');
} else {
switchTab('random');
}
}
function saveSettings() {
const config = getConfig();
config.mode = currentMode;
document.cookie = 'passwordGenSettings=' + encodeURIComponent(JSON.stringify(config)) + '; max-age=31536000; path=/';
}
function loadSettings() {
// First try URL parameters
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.toString()) {
const config = {};
for (const [key, value] of urlParams) {
if (key === 'includeUpper' || key === 'includeLower' || key === 'noConsecutive' || key === 'usePassphrase' || key === 'passphraseUseNumbers' || key === 'passphraseUseSpecial' || key === 'enableHistory') {
config[key] = value === 'true';
} else if (key === 'length' || key === 'numberCount' || key === 'wordCount') {
config[key] = parseInt(value);
} else {
config[key] = value;
}
}
setConfig(config);
return;
}
// Then try cookies
const cookies = document.cookie.split(';');
for (const cookie of cookies) {
const [name, value] = cookie.trim().split('=');
if (name === 'passwordGenSettings') {
try {
const config = JSON.parse(decodeURIComponent(value));
setConfig(config);
currentMode = config.mode || 'passphrase'; // Default to passphrase
switchTab(currentMode);
} catch (e) {
console.error('Failed to parse cookie settings:', e);
// Set defaults on error
switchTab('passphrase');
}
break;
}
}
}
function updateShareUrl() {
const config = getConfig();
const params = new URLSearchParams();
for (const [key, value] of Object.entries(config)) {
params.set(key, value.toString());
}
const newUrl = window.location.pathname + '?' + params.toString();
// Update browser URL without page reload
if (window.history && window.history.pushState) {
window.history.replaceState({}, '', newUrl);
}
}
// Add event listeners to update settings
document.querySelectorAll('input, select').forEach(element => {
element.addEventListener('change', function() {
saveSettings();
updateShareUrl();
});
});
async function generatePassword() {
const config = getConfig();
try {
const response = await fetch('/api/password', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(config)
});
if (!response.ok) {
throw new Error('Failed to generate password');
}
const result = await response.text();
document.getElementById('passwordDisplay').textContent = result;
document.getElementById('copyBtn').style.display = 'inline-block';
// Save to history
const passwordType = config.usePassphrase ? 'Passphrase' : 'Random';
savePasswordToHistory(result, passwordType);
// Update strength indicator
updateStrengthIndicator(result, config);
// Refresh word list info if using passphrase
if (config.usePassphrase) {
loadWordListInfo();
}
} catch (error) {
document.getElementById('passwordDisplay').textContent = 'Error: ' + error.message;
document.getElementById('copyBtn').style.display = 'none';
}
}
function updateStrengthIndicator(password, config) {
let score = 0;
let feedback = [];
// Length score
if (password.length >= 12) score += 25;
else if (password.length >= 8) score += 15;
else score += 5;
// Character variety
if (/[a-z]/.test(password)) score += 10;
if (/[A-Z]/.test(password)) score += 10;
if (/[0-9]/.test(password)) score += 10;
if (/[^a-zA-Z0-9]/.test(password)) score += 15;
// Length bonus
if (password.length >= 16) score += 10;
if (password.length >= 20) score += 10;
// Passphrase bonus
if (config.usePassphrase) score += 10;
// No consecutive bonus
if (config.noConsecutive) score += 5;
let strength, color;
if (score >= 80) {
strength = "Very Strong 💪";
color = "#00aa44";
} else if (score >= 60) {
strength = "Strong 🔒";
color = "#007acc";
} else if (score >= 40) {
strength = "Medium ⚠️";
color = "#ff8800";
} else {
strength = "Weak ❌";
color = "#cc0000";
}
document.getElementById('strengthIndicator').innerHTML =
`<span style="color: ${color}">${strength}</span> (Score: ${score}/100)`;
}
function copyPassword() {
const passwordText = document.getElementById('passwordDisplay').textContent;
navigator.clipboard.writeText(passwordText).then(function() {
const btn = document.getElementById('copyBtn');
btn.textContent = 'Copied! ✓';
btn.classList.add('copied');
setTimeout(function() {
btn.textContent = 'Copy to Clipboard';
btn.classList.remove('copied');
}, 2000);
}).catch(function(err) {
console.error('Failed to copy: ', err);
});
}
// Password History Management
function savePasswordToHistory(password, type) {
if (!document.getElementById('enableHistory').checked) {
return;
}
const history = getPasswordHistory();
const timestamp = new Date().toLocaleString();
history.unshift({
timestamp: timestamp,
password: password,
type: type,
date: new Date().getTime()
});
// Keep only last 50 passwords and remove entries older than 7 days
const sevenDaysAgo = new Date().getTime() - (7 * 24 * 60 * 60 * 1000);
const filteredHistory = history
.filter(item => item.date > sevenDaysAgo)
.slice(0, 50);
localStorage.setItem('passwordHistory', JSON.stringify(filteredHistory));
updateHistoryDisplay();
}
function getPasswordHistory() {
try {
const history = localStorage.getItem('passwordHistory');
return history ? JSON.parse(history) : [];
} catch (e) {
console.error('Failed to parse password history:', e);
return [];
}
}
function clearPasswordHistory() {
localStorage.removeItem('passwordHistory');
updateHistoryDisplay();
}
function updateHistoryDisplay() {
const historyEnabled = document.getElementById('enableHistory').checked;
const historySection = document.getElementById('historySection');
if (!historyEnabled) {
historySection.style.display = 'none';
return;
}
const history = getPasswordHistory();
const tbody = document.getElementById('historyBody');
if (history.length === 0) {
historySection.style.display = 'none';
return;
}
historySection.style.display = 'block';
tbody.innerHTML = '';
history.forEach(item => {
const row = document.createElement('tr');
row.innerHTML = `
<td style="padding: 8px; border: 1px solid #444; font-size: 12px; color: #ccc;">${item.timestamp}</td>
<td style="padding: 8px; border: 1px solid #444; font-family: monospace; word-break: break-all; color: #00ff88;">${item.password}</td>
<td style="padding: 8px; border: 1px solid #444; font-size: 12px; color: #ccc;">${item.type}</td>
<td style="padding: 8px; border: 1px solid #444;">
<button onclick="copyPasswordFromHistory('${item.password}')" style="background: #007acc; color: white; border: none; padding: 4px 8px; border-radius: 4px; cursor: pointer; font-size: 12px;">Copy</button>
</td>
`;
tbody.appendChild(row);
});
}
function copyPasswordFromHistory(password) {
navigator.clipboard.writeText(password).then(function() {
// Visual feedback could be added here
console.log('Password copied from history');
}).catch(function(err) {
console.error('Failed to copy password from history: ', err);
});
}
// History toggle event listener
document.getElementById('enableHistory').addEventListener('change', function() {
if (!this.checked) {
clearPasswordHistory();
}
updateHistoryDisplay();
saveSettings();
});
// Load settings from cookies and URL parameters
window.addEventListener('load', function() {
loadSettings();
updateShareUrl();
loadWordListInfo();
updateHistoryDisplay();
// Auto-generate if URL has parameters
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.toString()) {
generatePassword();
}
});
</script>
</body>
</html>

307
web/style.css Normal file
View File

@@ -0,0 +1,307 @@
:root {
--bg-color: #1e1e1e;
--text-color: #e0e0e0;
--section-bg: #2d2d2d;
--border-color: #404040;
--highlight: #3c5c7c;
--success: #4caf50;
--warning: #ff9800;
--error: #f44336;
}
body {
background-color: var(--bg-color);
color: var(--text-color);
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
line-height: 1.6;
margin: 0;
padding: 20px;
}
h1, h2, h3 {
color: var(--text-color);
border-bottom: 1px solid var(--border-color);
padding-bottom: 10px;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
textarea {
width: 100%;
height: 120px;
background-color: var(--section-bg);
color: var(--text-color);
border: 1px solid var(--border-color);
padding: 6px;
border-radius: 4px;
font-family: monospace;
margin-bottom: 10px;
}
button {
background-color: #4CAF50;
border: none;
color: white;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 14px;
margin: 4px 2px;
cursor: pointer;
border-radius: 4px;
transition: background-color 0.3s;
}
button:hover {
background-color: #45a049;
}
.section {
background-color: var(--section-bg);
border-radius: 8px;
padding: 12px 15px;
margin: 10px 0;
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.score-container {
text-align: center;
padding: 20px;
margin: 20px 0;
}
.score-flex {
display: flex;
align-items: center;
justify-content: center;
gap: 60px;
width: 100%;
}
.score-left {
display: flex;
flex-direction: column;
align-items: center;
min-width: 180px;
}
.score-indicators {
display: flex;
flex-wrap: wrap;
gap: 8px;
align-items: center;
}
.score-container h2 {
font-size: 1.3em;
margin-bottom: 8px;
border-bottom: none;
padding-bottom: 0;
}
.score-circle {
width: 110px;
height: 110px;
border-radius: 50%;
margin: 0 auto;
position: relative;
background: conic-gradient(var(--success) 0%, var(--success) var(--score), #444 var(--score), #444 100%);
}
.score-inner {
position: absolute;
width: 90px;
height: 90px;
background: var(--section-bg);
border-radius: 50%;
top: 10px;
left: 10px;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.7em;
font-weight: bold;
}
.status {
padding: 8px 12px;
margin: 5px 0;
border-radius: 4px;
display: inline-block;
font-weight: bold;
}
.status.good {
background-color: #2d5a2d;
color: #90EE90;
border-left: 4px solid #4CAF50;
}
.status.warning {
background-color: #5a4d2d;
color: #FFD700;
border-left: 4px solid #FF9800;
}
.status.error {
background-color: #5a2d2d;
color: #FFB6C1;
border-left: 4px solid #f44336;
}
.grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
align-items: start;
margin: 10px 0;
width: 100%;
}
pre, code {
background-color: var(--bg-color);
padding: 6px;
border-radius: 4px;
overflow-x: auto;
white-space: pre-wrap;
word-break: break-word;
font-size: 0.97em;
max-width: 100%;
}
.details pre {
white-space: pre-wrap;
word-break: break-word;
}
.mail-flow {
position: relative;
list-style: none;
padding-left: 20px;
}
.mail-flow li {
position: relative;
padding: 10px;
margin: 10px 0;
background-color: var(--bg-color);
border-radius: 4px;
}
.mail-flow li::before {
content: "↓";
position: absolute;
left: -20px;
color: white;
}
.mail-flow li:first-child::before {
display: none;
}
.compact-score {
padding: 10px 15px;
margin: 10px 0 10px 0;
}
/* Security Analysis vertical layout */
.security-analysis-vertical {
display: flex;
flex-direction: column;
gap: 18px;
}
.security-analysis-vertical .section {
margin-bottom: 15px;
padding: 10px;
border-left: 3px solid #555;
background: none;
box-shadow: none;
}
nav {
width: 100%;
background: #181818;
padding: 0.5em 0 0.5em 1.5em;
margin-bottom: 18px;
box-shadow: 0 2px 4px rgba(0,0,0,0.12);
display: flex;
align-items: center;
}
nav a {
color: #fff;
text-decoration: none;
font-weight: bold;
font-size: 1.1em;
margin-right: 2em;
letter-spacing: 0.5px;
}
nav a:hover {
text-decoration: underline;
}
.container, .section, .grid {
word-break: break-word;
overflow-wrap: anywhere;
}
.explanation {
background-color: #2a2a2a;
border-left: 4px solid #555;
padding: 10px;
margin: 10px 0;
border-radius: 0 4px 4px 0;
}
.explanation small {
color: #ccc;
line-height: 1.4;
}
@media print {
body {
background-color: white;
color: black;
}
.section {
background-color: white;
color: black;
box-shadow: none;
border: 1px solid #ccc;
}
.score-circle, .score-inner {
background: white;
color: black;
}
pre, code {
background: #f5f5f5;
color: black;
border: 1px solid #ccc;
white-space: pre-wrap;
word-break: break-word;
}
}
@media (max-width: 700px) {
.score-flex {
flex-direction: column;
align-items: stretch;
gap: 15px;
}
.score-indicators {
flex-direction: row;
gap: 8px;
min-width: 0;
justify-content: center;
}
}
@media (max-width: 768px) {
.grid {
grid-template-columns: 1fr;
}
}