210 lines
7.9 KiB
Plaintext
210 lines
7.9 KiB
Plaintext
<%
|
|
const palette = ['#cee5ff', '#39a8ff', '#ffcf5f', '#ff7a7a', '#c08bff', '#5ff0d0', '#ff9f43', '#8fbf00', '#ff5fd2', '#7a8cff'];
|
|
const flag = (cc) => {
|
|
if (!cc || cc.length !== 2) { return ''; }
|
|
return String.fromCodePoint(...[...cc.toUpperCase()].map(c => 0x1F1E6 + c.charCodeAt(0) - 65));
|
|
};
|
|
const colorMap = {};
|
|
countryStats.forEach((c, i) => { if (c.code) { colorMap[c.code] = palette[i % palette.length]; } });
|
|
const countryMax = countryStats.reduce((m, c) => Math.max(m, c.count), 0) || 1;
|
|
const providerMax = providerStats.reduce((m, p) => Math.max(m, p.count), 0) || 1;
|
|
const countryCount = new Set(countryStats.map(c => c.code).filter(Boolean)).size;
|
|
%>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<%- include('../partials/head'); -%>
|
|
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
|
|
<%- include('../partials/admin-stalker-css'); -%>
|
|
<title>Admin - IP Map</title>
|
|
<style>
|
|
#map {
|
|
height: 560px;
|
|
}
|
|
|
|
.map-legend {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 0.5rem 1rem;
|
|
margin-top: 0.85rem;
|
|
font-size: 0.8rem;
|
|
}
|
|
|
|
.map-legend .lg-item {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 0.4rem;
|
|
color: #ccc;
|
|
}
|
|
|
|
.map-legend .swatch {
|
|
width: 11px;
|
|
height: 11px;
|
|
border-radius: 0;
|
|
display: inline-block;
|
|
}
|
|
|
|
.leaflet-popup-content {
|
|
font-family: var(--font-body);
|
|
font-size: 0.82rem;
|
|
line-height: 1.5;
|
|
}
|
|
|
|
.leaflet-popup-content .pp-head {
|
|
font-size: 0.95rem;
|
|
font-weight: 600;
|
|
margin-bottom: 0.35rem;
|
|
}
|
|
|
|
.leaflet-popup-content .pp-row {
|
|
color: #ccc;
|
|
}
|
|
|
|
.leaflet-popup-content .pp-row b {
|
|
color: var(--admin-accent);
|
|
}
|
|
|
|
.leaflet-popup-content a {
|
|
color: var(--admin-accent);
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<%- include('../winter'); -%>
|
|
|
|
<div class="admin-shell admin-shell--wide">
|
|
<div class="page-head">
|
|
<a class="btn btn-back" href="<%= endpoint %>/dashboard">Back to dashboard</a>
|
|
<h1>IP Map</h1>
|
|
<div class="spacer"></div>
|
|
<span class="chip"><%= points.length %> locations</span>
|
|
<span class="chip"><%= countryCount %> countries</span>
|
|
<span class="chip accent"><%= totalVisits %> visits</span>
|
|
</div>
|
|
|
|
<form class="toolbar" method="get">
|
|
<label class="sub">Start date
|
|
<input type="date" name="start" value="<%= startDate ? startDate.toISOString().slice(0,10) : '' %>">
|
|
</label>
|
|
<label class="sub">End date
|
|
<input type="date" name="end" value="<%= endDate ? endDate.toISOString().slice(0,10) : '' %>">
|
|
</label>
|
|
<button class="btn" type="submit">Apply</button>
|
|
<a class="btn btn-back" href="<%= endpoint %>/stalker-map">Reset</a>
|
|
</form>
|
|
|
|
<section class="card">
|
|
<h2>Locations <span class="hint">marker size scales with visits, colour follows country</span></h2>
|
|
<div id="map"></div>
|
|
<% if (countryStats.length) { %>
|
|
<div class="map-legend">
|
|
<% countryStats.slice(0, 10).forEach((c, i) => { if (!c.code) { return; } %>
|
|
<span class="lg-item">
|
|
<span class="swatch" style="background: <%= palette[i % palette.length] %>;"></span>
|
|
<span class="flag"><%= flag(c.code) %></span>
|
|
<%= c.country %> (<%= c.count %>)
|
|
</span>
|
|
<% }) %>
|
|
</div>
|
|
<% } %>
|
|
</section>
|
|
|
|
<div class="grid grid-2">
|
|
<section class="card">
|
|
<h2>Visits by country</h2>
|
|
<% if (countryStats.length) { %>
|
|
<div class="bars">
|
|
<% countryStats.forEach((c, i) => { %>
|
|
<div class="bar-row">
|
|
<span class="bar-label" title="<%= c.country %>"><span class="flag"><%= flag(c.code) %></span> <%= c.country %></span>
|
|
<span class="bar-track"><span class="bar-fill" style="width: <%= Math.round((c.count / countryMax) * 100) %>%; background: <%= palette[i % palette.length] %>;"></span></span>
|
|
<span class="bar-value"><%= c.count %></span>
|
|
</div>
|
|
<% }) %>
|
|
</div>
|
|
<% } else { %>
|
|
<p class="none">No geolocation data in this range.</p>
|
|
<% } %>
|
|
</section>
|
|
|
|
<section class="card">
|
|
<h2>Visits by provider</h2>
|
|
<% if (providerStats.length) { %>
|
|
<div class="bars">
|
|
<% providerStats.forEach(p => { %>
|
|
<div class="bar-row">
|
|
<span class="bar-label" title="<%= p.provider %>"><%= p.provider %></span>
|
|
<span class="bar-track"><span class="bar-fill" style="width: <%= Math.round((p.count / providerMax) * 100) %>%"></span></span>
|
|
<span class="bar-value"><%= p.count %></span>
|
|
</div>
|
|
<% }) %>
|
|
</div>
|
|
<% } else { %>
|
|
<p class="none">No provider data in this range.</p>
|
|
<% } %>
|
|
</section>
|
|
</div>
|
|
</div>
|
|
|
|
<%- include('../footer'); -%>
|
|
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
|
|
<script>
|
|
const points = <%- JSON.stringify(points) %>;
|
|
const colorMap = <%- JSON.stringify(colorMap) %>;
|
|
const detailBase = <%- JSON.stringify(endpoint + "/stalker/") %>;
|
|
|
|
const esc = (v) => String(v == null ? '' : v).replace(/[&<>"']/g, (c) => ({
|
|
'&': '&', '<': '<', '>': '>', '"': '"', "'": '''
|
|
}[c]));
|
|
|
|
const map = L.map('map').setView([20, 0], 2);
|
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
attribution: '© OpenStreetMap contributors'
|
|
}).addTo(map);
|
|
|
|
const markers = [];
|
|
points.forEach(p => {
|
|
const d = p.data ? (() => { try { return JSON.parse(p.data); } catch { return null; } })() : null;
|
|
const cc = d?.countryCode || '';
|
|
const color = colorMap[cc] || '#cee5ff';
|
|
const visits = p.visits || 0;
|
|
const radius = Math.min(6 + Math.sqrt(visits) * 3, 26);
|
|
|
|
const rows = [
|
|
d?.country ? `<div class="pp-row"><b>Country:</b> ${esc(d.country)}${d.countryCode ? ` (${esc(d.countryCode)})` : ''}</div>` : '',
|
|
d?.regionName ? `<div class="pp-row"><b>Region:</b> ${esc(d.regionName)}</div>` : '',
|
|
d?.city ? `<div class="pp-row"><b>City:</b> ${esc(d.city)}</div>` : '',
|
|
d?.isp ? `<div class="pp-row"><b>ISP:</b> ${esc(d.isp)}</div>` : '',
|
|
d?.org ? `<div class="pp-row"><b>Org:</b> ${esc(d.org)}</div>` : '',
|
|
d?.as ? `<div class="pp-row"><b>ASN:</b> ${esc(d.as)}</div>` : '',
|
|
d?.timezone ? `<div class="pp-row"><b>Timezone:</b> ${esc(d.timezone)}</div>` : '',
|
|
].filter(Boolean).join('');
|
|
|
|
const html = `
|
|
<div class="pp-head"><a href="${detailBase}${p.id}">${esc(p.ip)}</a></div>
|
|
<div class="pp-row"><b>Visits:</b> ${visits}</div>
|
|
<div class="pp-row"><b>Last seen:</b> ${esc(new Date(p.lastUsed).toLocaleString())}</div>
|
|
${rows}
|
|
`;
|
|
|
|
const marker = L.circleMarker([p.lat, p.lon], {
|
|
radius,
|
|
color,
|
|
fillColor: color,
|
|
fillOpacity: 0.35,
|
|
weight: 2,
|
|
}).addTo(map).bindPopup(html);
|
|
|
|
markers.push(marker);
|
|
});
|
|
|
|
if (points.length === 1) {
|
|
map.setView([points[0].lat, points[0].lon], 8);
|
|
} else if (points.length > 1) {
|
|
const bounds = L.latLngBounds(points.map(p => [p.lat, p.lon]));
|
|
map.fitBounds(bounds, { padding: [30, 30] });
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|