mirror of
https://github.com/MrUnknownDE/utools.git
synced 2026-04-12 02:53:44 +02:00
remove mac-lookup
This commit is contained in:
17
backend/package-lock.json
generated
17
backend/package-lock.json
generated
@@ -15,7 +15,6 @@
|
||||
"express": "^4.21.2",
|
||||
"express-rate-limit": "^7.5.0",
|
||||
"macaddress": "^0.5.3",
|
||||
"oui": "^13.0.5",
|
||||
"pino": "^9.6.0",
|
||||
"pino-pretty": "^13.0.0",
|
||||
"whois-json": "^2.0.4"
|
||||
@@ -905,22 +904,6 @@
|
||||
"wrappy": "1"
|
||||
}
|
||||
},
|
||||
"node_modules/oui": {
|
||||
"version": "13.0.5",
|
||||
"resolved": "https://registry.npmjs.org/oui/-/oui-13.0.5.tgz",
|
||||
"integrity": "sha512-bAXoXcLrl3SweuEuh8aWpdTsfHka6B7Gh1SxsTZMXtWi9QSxQk7CupxWlP2QQ4olTDifaWAiQbROMxfarAQZlQ==",
|
||||
"dependencies": {
|
||||
"oui-data": "^1.1.76"
|
||||
},
|
||||
"bin": {
|
||||
"oui": "bin/oui.js"
|
||||
}
|
||||
},
|
||||
"node_modules/oui-data": {
|
||||
"version": "1.1.314",
|
||||
"resolved": "https://registry.npmjs.org/oui-data/-/oui-data-1.1.314.tgz",
|
||||
"integrity": "sha512-F8r1LwdAucn6Fgq1KECZPMCpMgXPdhCblFOY/eQ6S83x5lfQQK9aRRIpz7dH6iQeAeqoSP1b4I8z4lqUaTwAvg=="
|
||||
},
|
||||
"node_modules/p-limit": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz",
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
"express": "^4.21.2",
|
||||
"express-rate-limit": "^7.5.0",
|
||||
"macaddress": "^0.5.3",
|
||||
"oui": "^13.0.5",
|
||||
"pino": "^9.6.0",
|
||||
"pino-pretty": "^13.0.0",
|
||||
"whois-json": "^2.0.4"
|
||||
|
||||
@@ -9,7 +9,7 @@ const dns = require('dns').promises;
|
||||
const pino = require('pino'); // Logging library
|
||||
const rateLimit = require('express-rate-limit'); // Rate limiting middleware
|
||||
const whois = require('whois-json'); // Hinzugefügt für WHOIS
|
||||
const oui = require('oui'); // Ersetzt macaddress für OUI Lookup
|
||||
// REMOVED: const oui = require('oui');
|
||||
|
||||
// --- Logger Initialisierung ---
|
||||
const logger = pino({
|
||||
@@ -86,21 +86,7 @@ function isValidDomain(domain) {
|
||||
return domainRegex.test(domain.trim());
|
||||
}
|
||||
|
||||
/**
|
||||
* Validiert eine MAC-Adresse.
|
||||
* @param {string} mac - Die zu validierende MAC-Adresse.
|
||||
* @returns {boolean} True, wenn gültig, sonst false.
|
||||
*/
|
||||
function isValidMac(mac) {
|
||||
if (!mac || typeof mac !== 'string') {
|
||||
return false;
|
||||
}
|
||||
// Erlaubt Formate wie 00:1A:2B:3C:4D:5E, 00-1A-2B-3C-4D-5E, 001A.2B3C.4D5E, 001a2b3c4d5e
|
||||
// Die oui Bibliothek ist tolerant gegenüber verschiedenen Formaten.
|
||||
const macRegex = /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$|^([0-9A-Fa-f]{4}\.){2}([0-9A-Fa-f]{4})$|^([0-9A-Fa-f]{12})$/;
|
||||
return macRegex.test(mac.trim());
|
||||
}
|
||||
|
||||
// REMOVED: isValidMac function
|
||||
|
||||
/**
|
||||
* Bereinigt eine IP-Adresse (z.B. entfernt ::ffff: Präfix von IPv4-mapped IPv6).
|
||||
@@ -259,7 +245,7 @@ function parseTracerouteLine(line) {
|
||||
}
|
||||
|
||||
|
||||
// --- Initialisierung (MaxMind DBs laden & OUI DB laden) ---
|
||||
// --- Initialisierung (MaxMind DBs laden) ---
|
||||
async function initialize() {
|
||||
try {
|
||||
logger.info('Loading MaxMind databases...');
|
||||
@@ -270,10 +256,7 @@ async function initialize() {
|
||||
asnReader = await geoip.Reader.open(asnDbPath);
|
||||
logger.info('MaxMind databases loaded successfully.');
|
||||
|
||||
// OUI Datenbank laden (kann beim ersten Aufruf etwas dauern)
|
||||
logger.info('Loading OUI database...');
|
||||
await oui.update(); // Sicherstellen, dass die DB aktuell ist (optional, aber empfohlen)
|
||||
logger.info('OUI database loaded/updated.');
|
||||
// REMOVED: OUI database loading
|
||||
|
||||
} catch (error) {
|
||||
logger.fatal({ error: error.message, stack: error.stack }, 'Could not initialize databases. Exiting.');
|
||||
@@ -306,7 +289,7 @@ app.use('/api/traceroute', generalLimiter);
|
||||
app.use('/api/lookup', generalLimiter);
|
||||
app.use('/api/dns-lookup', generalLimiter);
|
||||
app.use('/api/whois-lookup', generalLimiter);
|
||||
app.use('/api/mac-lookup', generalLimiter);
|
||||
// REMOVED: app.use('/api/mac-lookup', generalLimiter);
|
||||
|
||||
|
||||
// --- Routen ---
|
||||
@@ -687,39 +670,7 @@ app.get('/api/whois-lookup', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// MAC Address Lookup Endpunkt (mit 'oui' Bibliothek)
|
||||
app.get('/api/mac-lookup', async (req, res) => {
|
||||
const macRaw = req.query.mac;
|
||||
const mac = typeof macRaw === 'string' ? macRaw.trim() : macRaw;
|
||||
const requestIp = req.ip || req.socket.remoteAddress;
|
||||
|
||||
logger.info({ requestIp, mac }, 'MAC lookup request received');
|
||||
|
||||
if (!isValidMac(mac)) {
|
||||
logger.warn({ requestIp, mac }, 'Invalid MAC address format for lookup');
|
||||
return res.status(400).json({ success: false, error: 'Invalid MAC address format provided.' });
|
||||
}
|
||||
|
||||
try {
|
||||
// Verwende die oui Bibliothek für den Lookup. Sie sollte verschiedene Formate verarbeiten können.
|
||||
// oui() gibt den Vendor-String oder null zurück. Es kann beim ersten Mal die DB laden.
|
||||
const vendor = await oui(mac); // Verwende await, falls oui.update() im Hintergrund läuft
|
||||
|
||||
if (vendor) {
|
||||
logger.info({ requestIp, mac, vendor }, 'MAC lookup successful');
|
||||
res.json({ success: true, mac: mac, vendor: vendor });
|
||||
} else {
|
||||
logger.info({ requestIp, mac }, 'MAC lookup successful, but no vendor found');
|
||||
res.json({ success: true, mac: mac, vendor: null, message: 'Vendor not found for this MAC address prefix.' });
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
// Fehler können auftreten, wenn die interne DB nicht geladen werden kann oder andere Probleme auftreten
|
||||
logger.error({ requestIp, mac, error: error.message }, 'MAC lookup failed');
|
||||
res.status(500).json({ success: false, error: `MAC lookup failed: ${error.message}` });
|
||||
}
|
||||
});
|
||||
|
||||
// REMOVED: MAC Address Lookup Endpunkt
|
||||
|
||||
// Version Endpunkt
|
||||
app.get('/api/version', (req, res) => {
|
||||
@@ -740,7 +691,7 @@ initialize().then(() => {
|
||||
logger.info(` http://localhost:${PORT}/api/lookup?targetIp=<ip>`);
|
||||
logger.info(` http://localhost:${PORT}/api/dns-lookup?domain=<domain>&type=<type>`);
|
||||
logger.info(` http://localhost:${PORT}/api/whois-lookup?query=<domain_or_ip>`);
|
||||
logger.info(` http://localhost:${PORT}/api/mac-lookup?mac=<mac_address>`);
|
||||
// REMOVED: MAC lookup log message
|
||||
logger.info(` http://localhost:${PORT}/api/version`);
|
||||
});
|
||||
}).catch(error => {
|
||||
|
||||
@@ -92,7 +92,7 @@
|
||||
<li><a href="subnet-calculator.html">Subnetz Rechner</a></li>
|
||||
<li><a href="dns-lookup.html">DNS Lookup</a></li>
|
||||
<li><a href="whois-lookup.html">WHOIS Lookup</a></li>
|
||||
<li><a href="mac-lookup.html">MAC Lookup</a></li>
|
||||
<!-- REMOVED: MAC Lookup Link -->
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>MAC Address Lookup - uTools</title>
|
||||
<!-- Tailwind CSS Play CDN -->
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<!-- Eigene Styles -->
|
||||
<style>
|
||||
/* Einfacher Lade-Spinner */
|
||||
.loader {
|
||||
border: 4px solid rgba(168, 85, 247, 0.3); /* Lila transparent */
|
||||
border-left-color: #a855f7; /* Lila */
|
||||
border-radius: 50%;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
/* Navigations-Styling */
|
||||
nav ul { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 1rem; }
|
||||
nav a { color: #c4b5fd; text-decoration: none; white-space: nowrap; }
|
||||
nav a:hover { color: #a78bfa; text-decoration: underline; }
|
||||
header { background-color: #374151; padding: 1rem; margin-bottom: 1.5rem; border-radius: 0.5rem; display: flex; flex-direction: column; align-items: center; gap: 0.5rem; }
|
||||
@media (min-width: 768px) { header { flex-direction: row; justify-content: space-between; } }
|
||||
header h1 { font-size: 1.5rem; font-weight: bold; color: #e5e7eb; }
|
||||
.hidden { display: none; }
|
||||
</style>
|
||||
</head>
|
||||
<body class="bg-gray-900 text-gray-200 font-sans p-4 md:p-8">
|
||||
|
||||
<header>
|
||||
<h1>uTools Network Suite</h1>
|
||||
<nav>
|
||||
<ul>
|
||||
<li><a href="index.html">IP Info & Tools</a></li>
|
||||
<li><a href="subnet-calculator.html">Subnetz Rechner</a></li>
|
||||
<li><a href="dns-lookup.html">DNS Lookup</a></li>
|
||||
<li><a href="whois-lookup.html">WHOIS Lookup</a></li>
|
||||
<li><a href="mac-lookup.html">MAC Lookup</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<div class="container mx-auto max-w-4xl bg-gray-800 rounded-lg shadow-xl p-6">
|
||||
|
||||
<h1 class="text-3xl font-bold mb-6 text-purple-400 text-center">MAC Address Lookup</h1>
|
||||
|
||||
<!-- Bereich für MAC Address Lookup -->
|
||||
<div class="mt-8 p-4 bg-gray-700 rounded">
|
||||
<div class="flex flex-col sm:flex-row gap-2 mb-4">
|
||||
<input type="text" id="mac-input" placeholder="Enter MAC address (e.g., 00:1A:2B:3C:4D:5E)"
|
||||
class="flex-grow px-3 py-2 bg-gray-800 border border-gray-600 rounded text-gray-200 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent font-mono">
|
||||
<button id="mac-lookup-button"
|
||||
class="bg-purple-600 hover:bg-purple-700 text-white font-bold py-2 px-4 rounded transition duration-150 ease-in-out">
|
||||
Lookup MAC Vendor
|
||||
</button>
|
||||
</div>
|
||||
<div id="mac-lookup-error" class="text-red-400 mb-4 hidden"></div>
|
||||
<div id="mac-lookup-results-section" class="hidden mt-4 border-t border-gray-600 pt-4">
|
||||
<h3 class="text-lg font-semibold text-purple-300 mb-2">MAC Vendor for: <span id="mac-lookup-query" class="font-mono text-purple-400"></span></h3>
|
||||
<div id="mac-lookup-loader" class="loader hidden mb-2"></div>
|
||||
<p id="mac-lookup-output" class="text-lg"></p> <!-- Ergebnisbereich (einfacher Text) -->
|
||||
<p id="mac-lookup-notfound" class="text-gray-400 hidden">Vendor not found for this MAC address prefix.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Globaler Fehlerbereich -->
|
||||
<div id="global-error" class="mt-6 p-4 bg-red-800 text-red-100 rounded hidden"></div>
|
||||
|
||||
<!-- Footer für Version -->
|
||||
<footer class="mt-8 pt-4 border-t border-gray-600 text-center text-xs text-gray-500">
|
||||
<p>© 2025 <a href="https://johanneskr.de" class="text-purple-400 hover:underline">Johannes Krüger</a></p>
|
||||
<p>Version: <span id="commit-sha" class="font-mono">loading...</span></p>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Eigene JS-Logik für diese Seite -->
|
||||
<script src="mac-lookup.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,135 +0,0 @@
|
||||
// frontend/mac-lookup.js
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
// --- DOM Elements (MAC Lookup) ---
|
||||
const macInput = document.getElementById('mac-input');
|
||||
const macLookupButton = document.getElementById('mac-lookup-button');
|
||||
const macLookupErrorEl = document.getElementById('mac-lookup-error');
|
||||
const macLookupResultsSection = document.getElementById('mac-lookup-results-section');
|
||||
const macLookupQueryEl = document.getElementById('mac-lookup-query');
|
||||
const macLookupLoader = document.getElementById('mac-lookup-loader');
|
||||
const macLookupOutputEl = document.getElementById('mac-lookup-output');
|
||||
const macLookupNotFoundEl = document.getElementById('mac-lookup-notfound');
|
||||
|
||||
// --- DOM Elements (Common) ---
|
||||
const globalErrorEl = document.getElementById('global-error');
|
||||
const commitShaEl = document.getElementById('commit-sha');
|
||||
|
||||
// --- Configuration ---
|
||||
const API_BASE_URL = '/api'; // Anpassen, falls nötig
|
||||
|
||||
// --- Helper Functions ---
|
||||
|
||||
/** Zeigt globale Fehler an */
|
||||
function showGlobalError(message) {
|
||||
if (!globalErrorEl) return;
|
||||
globalErrorEl.textContent = `Error: ${message}`;
|
||||
globalErrorEl.classList.remove('hidden');
|
||||
}
|
||||
|
||||
/** Versteckt globale Fehler */
|
||||
function hideGlobalError() {
|
||||
if (!globalErrorEl) return;
|
||||
globalErrorEl.classList.add('hidden');
|
||||
}
|
||||
|
||||
/**
|
||||
* Generische Funktion zum Abrufen und Anzeigen von Lookup-Ergebnissen.
|
||||
* @param {string} endpoint - Der API-Endpunkt (z.B. '/mac-lookup').
|
||||
* @param {object} params - Query-Parameter als Objekt (z.B. { mac: '...' }).
|
||||
* @param {HTMLElement} resultsSection - Der Container für die Ergebnisse.
|
||||
* @param {HTMLElement} loaderElement - Das Loader-Element.
|
||||
* @param {HTMLElement} errorElement - Das Fehleranzeige-Element für diesen Lookup.
|
||||
* @param {HTMLElement} queryElement - Das Element zur Anzeige der Suchanfrage.
|
||||
* @param {HTMLElement} outputElement - Das Element zur Anzeige der Ergebnisse (<pre> oder <p>).
|
||||
* @param {function} displayFn - Funktion zur Formatierung und Anzeige der Daten im outputElement.
|
||||
*/
|
||||
async function fetchAndDisplay(endpoint, params, resultsSection, loaderElement, errorElement, queryElement, outputElement, displayFn) {
|
||||
resultsSection.classList.remove('hidden');
|
||||
loaderElement.classList.remove('hidden');
|
||||
errorElement.classList.add('hidden');
|
||||
outputElement.textContent = ''; // Clear previous results
|
||||
if (macLookupNotFoundEl) macLookupNotFoundEl.classList.add('hidden'); // Hide 'not found' specifically for MAC
|
||||
if (queryElement) queryElement.textContent = Object.values(params).join(', '); // Display query
|
||||
hideGlobalError(); // Hide global errors before new request
|
||||
|
||||
const urlParams = new URLSearchParams(params);
|
||||
const url = `${API_BASE_URL}${endpoint}?${urlParams.toString()}`;
|
||||
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
const data = await response.json();
|
||||
|
||||
if (!response.ok || !data.success) {
|
||||
throw new Error(data.error || `Request failed with status ${response.status}`);
|
||||
}
|
||||
|
||||
console.log(`Received ${endpoint} data:`, data);
|
||||
displayFn(data, outputElement); // Call the specific display function
|
||||
|
||||
} catch (error) {
|
||||
console.error(`Failed to fetch ${endpoint}:`, error);
|
||||
errorElement.textContent = `Error: ${error.message}`;
|
||||
errorElement.classList.remove('hidden');
|
||||
outputElement.textContent = ''; // Clear output on error
|
||||
} finally {
|
||||
loaderElement.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
/** Ruft die Versionsinformationen (Commit SHA) ab */
|
||||
async function fetchVersionInfo() {
|
||||
if (!commitShaEl) return; // Don't fetch if element doesn't exist
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}/version`);
|
||||
if (!response.ok) throw new Error(`Network response: ${response.statusText} (${response.status})`);
|
||||
const data = await response.json();
|
||||
commitShaEl.textContent = data.commitSha || 'unknown';
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch version info:', error);
|
||||
commitShaEl.textContent = 'error';
|
||||
// Optionally show global error
|
||||
// showGlobalError(`Could not load version info: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
// --- MAC Lookup Specific Functions ---
|
||||
function displayMacResults(data, outputEl) {
|
||||
macLookupNotFoundEl.classList.add('hidden'); // Hide not found message first
|
||||
if (data.vendor) {
|
||||
outputEl.textContent = data.vendor;
|
||||
} else {
|
||||
outputEl.textContent = ''; // Clear vendor text
|
||||
macLookupNotFoundEl.classList.remove('hidden'); // Show not found message
|
||||
}
|
||||
}
|
||||
|
||||
function handleMacLookupClick() {
|
||||
const mac = macInput.value.trim();
|
||||
if (!mac) {
|
||||
macLookupErrorEl.textContent = 'Please enter a MAC address.';
|
||||
macLookupErrorEl.classList.remove('hidden');
|
||||
return;
|
||||
}
|
||||
// Clear previous 'not found' message
|
||||
macLookupNotFoundEl.classList.add('hidden');
|
||||
fetchAndDisplay(
|
||||
'/mac-lookup',
|
||||
{ mac },
|
||||
macLookupResultsSection,
|
||||
macLookupLoader,
|
||||
macLookupErrorEl,
|
||||
macLookupQueryEl,
|
||||
macLookupOutputEl, // Pass the <p> element
|
||||
displayMacResults
|
||||
);
|
||||
}
|
||||
|
||||
// --- Initial Load & Event Listeners ---
|
||||
fetchVersionInfo(); // Lade Versionsinfo für Footer
|
||||
|
||||
macLookupButton.addEventListener('click', handleMacLookupClick);
|
||||
macInput.addEventListener('keypress', (event) => {
|
||||
if (event.key === 'Enter') handleMacLookupClick();
|
||||
});
|
||||
|
||||
}); // End DOMContentLoaded
|
||||
Reference in New Issue
Block a user