FilterChecker-WebUI/index.html
2024-07-28 19:39:37 -05:00

303 lines
10 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FilterChecker</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #333 /*#2b2b2b*/;
color: #f5f5f5;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
padding: 20px;
box-sizing: border-box;
}
#container {
background: #333;
padding: 20px;
border-radius: 8px;
/*box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);*/
text-align: center;
width: 100%;
max-width: 600px;
box-sizing: border-box;
}
.input-group {
display: flex;
width: 100%;
align-items: center;
}
input {
flex: 1;
padding: 10px;
margin: 0;
border: 1px solid #444;
border-radius: 4px;
background-color: #555;
color: #f5f5f5;
box-sizing: border-box;
transition: border-radius 0.1s;
}
button {
padding: 10px 20px;
border: none;
background-color: #28a745;
color: #fff;
border-radius: 4px;
cursor: pointer;
box-sizing: border-box;
margin-left: 10px;
}
button:hover {
background-color: #218838;
}
#results {
text-align: left;
}
.result {
padding: 10px;
border-bottom: 1px solid #444;
}
.loading-container {
display: flex;
justify-content: center;
align-items: center;
height: 100px;
}
.spinner {
border: 4px solid rgba(255, 255, 255, 0.3);
border-top: 4px solid #fff;
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
#rawResultContainer {
margin-top: 20px;
text-align: center;
}
.raw-button {
padding: 10px 20px;
background-color: #28a745;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
margin-top: 10px;
}
.raw-button:hover {
background-color: #218838;
}
.error {
color: #ff4d4d;
text-align: center;
}
h2 {
margin-top: 20px;
text-align: center;
}
@media (max-width: 600px) {
body {
background-color: #333;
}
#container {
background: none;
box-shadow: none;
padding: 10px;
}
.input-group {
flex-direction: column;
align-items: stretch;
}
input {
margin-bottom: 10px;
}
button {
margin-left: 0;
width: 100%;
}
}
</style>
</head>
<body>
<div id="container">
<h1>FilterChecker</h1>
<div class="input-group">
<input type="text" id="inputUrl" placeholder="URL to check..." onkeypress="handleKeyPress(event)" />
<button onclick="checkFilter()">Check</button>
</div>
<div id="results"></div>
<div id="rawResultContainer"></div>
<div id="loading" class="loading-container" style="display: none;">
<div class="spinner"></div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
const urlParams = new URLSearchParams(window.location.search);
const domain = urlParams.get('domain');
if (domain) {
document.getElementById('inputUrl').value = domain;
checkFilter();
}
});
function handleKeyPress(event) {
if (event.key === 'Enter') {
checkFilter();
}
}
function isValidDomain(domain) {
const regex = /^(?!:\/\/)([a-zA-Z0-9-_]+\.)*[a-zA-Z0-9][a-zA-Z0-9-_]+\.[a-zA-Z]{2,11}?$/;
return regex.test(domain);
}
const filterMapping = {
"lightspeed": "lightspeed",
"ls": "lightspeed",
"fortiguard": "fortiguard",
"forti": "fortiguard",
"paloalto": "paloalto",
"palo": "paloalto"
};
async function checkFilter() {
let url = document.getElementById('inputUrl').value.trim();
const resultsDiv = document.getElementById('results');
const rawResultContainer = document.getElementById('rawResultContainer');
const loadingDiv = document.getElementById('loading');
resultsDiv.innerHTML = '';
rawResultContainer.innerHTML = '';
loadingDiv.style.display = 'flex';
url = url.replace(/^https?:\/\//, '');
if (!url) {
resultsDiv.innerHTML = '<p class="error">Please enter a URL.</p>';
loadingDiv.style.display = 'none';
return;
}
if (!isValidDomain(url)) {
resultsDiv.innerHTML = '<p class="error">Please enter a valid domain.</p>';
loadingDiv.style.display = 'none';
return;
}
try {
const encodedUrl = encodeURIComponent(url);
const urlParams = new URLSearchParams(window.location.search);
const filter = urlParams.get('filter');
const jsonResponse = await fetch(`api/check/${encodedUrl}/results.json`);
if (!jsonResponse.ok) {
const errorText = await jsonResponse.text();
console.error(`Error text: ${errorText}`);
throw new Error(`Network response for JSON was not ok: ${errorText}`);
}
const dataJson = await jsonResponse.json();
const textResponse = await fetch(`api/check/${encodedUrl}/results.txt`);
if (!textResponse.ok) {
const errorText = await textResponse.text();
console.error(`Error text: ${errorText}`);
throw new Error(`Network response for TXT was not ok: ${errorText}`);
}
let dataTxt = await textResponse.text();
if (filter) {
const normalizedFilter = filterMapping[filter.toLowerCase()];
if (normalizedFilter) {
const filteredData = { [normalizedFilter]: dataJson[normalizedFilter] };
dataTxt = JSON.stringify(filteredData, null, 2);
}
}
const blob = new Blob([dataTxt], { type: 'text/plain' });
const blobUrl = URL.createObjectURL(blob);
displayResults(dataJson, url, filter);
const rawButton = document.createElement('button');
rawButton.innerText = 'Show Raw';
rawButton.className = 'raw-button';
rawButton.onclick = () => {
window.open(blobUrl, '_blank');
};
rawResultContainer.appendChild(rawButton);
} catch (error) {
resultsDiv.innerHTML = `<p class="error">Error: ${error.message}</p>`;
} finally {
loadingDiv.style.display = 'none';
}
}
function displayResults(data, url, filter) {
const resultsDiv = document.getElementById('results');
resultsDiv.innerHTML = `<h2>FilterChecker Report for ${url}:</h2>`;
if (!data || typeof data !== 'object') {
resultsDiv.innerHTML = '<p class="error">No filters found.</p>';
return;
}
const normalizedFilter = filter ? filterMapping[filter.toLowerCase()] : null;
if (normalizedFilter) {
if (data[normalizedFilter]) {
const resultContent = generateFilterContent(normalizedFilter, data[normalizedFilter]);
resultsDiv.innerHTML += `
<div class="result">
${resultContent}
</div>
`;
} else {
resultsDiv.innerHTML = `<p class="error">Filter ${filter} not found.</p>`;
}
} else {
for (const key in data) {
if (data.hasOwnProperty(key)) {
const resultContent = generateFilterContent(key, data[key]);
resultsDiv.innerHTML += `
<div class="result">
${resultContent}
</div>
`;
}
}
}
}
function generateFilterContent(filterName, filterData) {
let content = `<p><strong>${(filterName.charAt(0).toUpperCase() + filterName.slice(1)).replace('Paloalto', 'Palo Alto')}:</strong></p>`;
if (filterName === "lightspeed") {
content += `<p>LS Filter: ${filterData[0]}</p>`;
content += `<p>LS Rocket: ${filterData[1]}</p>`;
} else if (filterName === "fortiguard") {
content += `<p>Category: ${filterData}</p>`;
} else if (filterName === "paloalto") {
content += `<p>Risk: ${filterData[1]}</p>`;
content += `<p>Category: ${filterData[0]}</p>`;
}
return content;
}
</script>
</body>
</html>