Compare commits
No commits in common. "04cdd47521f51a60e81d214ed84dd9fc322b4f9b" and "0529f2e4c9c997315b05970b23d44e2416182115" have entirely different histories.
04cdd47521
...
0529f2e4c9
|
|
@ -28,10 +28,6 @@ function connectWS() {
|
||||||
} else if (msg.type === 'rootme_flag') {
|
} else if (msg.type === 'rootme_flag') {
|
||||||
renderRootme(rootmeCache);
|
renderRootme(rootmeCache);
|
||||||
showNotif(`FLAG ! ${msg.login} +${msg.gained} PTS — TOTAL : ${msg.newScore} PTS`);
|
showNotif(`FLAG ! ${msg.login} +${msg.gained} PTS — TOTAL : ${msg.newScore} PTS`);
|
||||||
} else if (msg.type === 'geo_news') {
|
|
||||||
showGeoBanner(msg.title, msg.link);
|
|
||||||
} else if (msg.type === 'anssi_news') {
|
|
||||||
showNotif(`Nouveau bulletin ANSSI : ${msg.title}`);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -207,6 +203,7 @@ function updateClock() {
|
||||||
|
|
||||||
const anssiList = document.getElementById('anssi-list');
|
const anssiList = document.getElementById('anssi-list');
|
||||||
const anssiStatus = document.getElementById('anssi-status');
|
const anssiStatus = document.getElementById('anssi-status');
|
||||||
|
let seenAnssiLinks = null;
|
||||||
|
|
||||||
async function loadAnssi() {
|
async function loadAnssi() {
|
||||||
anssiStatus.textContent = '...';
|
anssiStatus.textContent = '...';
|
||||||
|
|
@ -222,6 +219,17 @@ async function loadAnssi() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const currentAnssiLinks = new Set(items.map(i => i.link));
|
||||||
|
if (seenAnssiLinks === null) {
|
||||||
|
seenAnssiLinks = currentAnssiLinks;
|
||||||
|
} else {
|
||||||
|
const newItems = items.filter(i => !seenAnssiLinks.has(i.link));
|
||||||
|
if (newItems.length) {
|
||||||
|
showNotif(`Nouveau bulletin ANSSI : ${newItems[0].title}`);
|
||||||
|
seenAnssiLinks = currentAnssiLinks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
const li = document.createElement('li');
|
const li = document.createElement('li');
|
||||||
li.className = 'anssi-item';
|
li.className = 'anssi-item';
|
||||||
|
|
@ -250,6 +258,7 @@ async function loadAnssi() {
|
||||||
|
|
||||||
const geoList = document.getElementById('geo-list');
|
const geoList = document.getElementById('geo-list');
|
||||||
const geoStatus = document.getElementById('geo-status');
|
const geoStatus = document.getElementById('geo-status');
|
||||||
|
let seenGeoLinks = null;
|
||||||
|
|
||||||
async function loadGeo() {
|
async function loadGeo() {
|
||||||
geoStatus.textContent = '...';
|
geoStatus.textContent = '...';
|
||||||
|
|
@ -265,6 +274,19 @@ async function loadGeo() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const currentLinks = new Set(items.map(i => i.link));
|
||||||
|
|
||||||
|
if (seenGeoLinks === null) {
|
||||||
|
// Premier chargement : on mémorise sans jouer
|
||||||
|
seenGeoLinks = currentLinks;
|
||||||
|
} else {
|
||||||
|
const newGeoItems = items.filter(i => !seenGeoLinks.has(i.link));
|
||||||
|
if (newGeoItems.length) {
|
||||||
|
showGeoBanner(newGeoItems[0].title, newGeoItems[0].link);
|
||||||
|
seenGeoLinks = currentLinks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
const li = document.createElement('li');
|
const li = document.createElement('li');
|
||||||
li.className = 'anssi-item';
|
li.className = 'anssi-item';
|
||||||
|
|
|
||||||
237
server.js
237
server.js
|
|
@ -88,95 +88,61 @@ app.delete('/api/alert', (req, res) => {
|
||||||
res.json({ ok: true });
|
res.json({ ok: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── Feed pollers (détection server-side, broadcast WS) ──────────────────────
|
// ANSSI / CERT-FR RSS feed
|
||||||
|
app.get('/api/feeds/anssi', async (req, res) => {
|
||||||
const FEED_POLL_MS = 5 * 60 * 1000;
|
|
||||||
|
|
||||||
// ANSSI
|
|
||||||
let anssiCache = null;
|
|
||||||
let seenAnssiLinks = null;
|
|
||||||
|
|
||||||
async function pollAnssi() {
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('https://www.cert.ssi.gouv.fr/feed/', {
|
const response = await fetch('https://www.cert.ssi.gouv.fr/feed/', {
|
||||||
headers: { 'User-Agent': 'CyberDashboard/1.0' }, timeout: 10000
|
headers: { 'User-Agent': 'CyberDashboard/1.0' },
|
||||||
|
timeout: 10000
|
||||||
});
|
});
|
||||||
const xml = await response.text();
|
const xml = await response.text();
|
||||||
const parser = new XMLParser({ ignoreAttributes: false });
|
const parser = new XMLParser({ ignoreAttributes: false });
|
||||||
const items = parser.parse(xml)?.rss?.channel?.item || [];
|
const parsed = parser.parse(xml);
|
||||||
|
const items = parsed?.rss?.channel?.item || [];
|
||||||
const entries = (Array.isArray(items) ? items : [items])
|
const entries = (Array.isArray(items) ? items : [items])
|
||||||
.map(item => ({ title: item.title || '', link: item.link || '', pubDate: item.pubDate || '', description: item.description || '' }))
|
.map(item => ({
|
||||||
|
title: item.title || '',
|
||||||
|
link: item.link || '',
|
||||||
|
pubDate: item.pubDate || '',
|
||||||
|
description: item.description || ''
|
||||||
|
}))
|
||||||
.sort((a, b) => new Date(b.pubDate) - new Date(a.pubDate))
|
.sort((a, b) => new Date(b.pubDate) - new Date(a.pubDate))
|
||||||
.slice(0, 7);
|
.slice(0, 7);
|
||||||
|
res.json(entries);
|
||||||
anssiCache = entries;
|
|
||||||
const currentLinks = new Set(entries.map(i => i.link));
|
|
||||||
if (seenAnssiLinks === null) {
|
|
||||||
seenAnssiLinks = currentLinks;
|
|
||||||
} else {
|
|
||||||
const newItems = entries.filter(i => !seenAnssiLinks.has(i.link));
|
|
||||||
if (newItems.length) {
|
|
||||||
broadcast({ type: 'anssi_news', title: newItems[0].title, link: newItems[0].link });
|
|
||||||
seenAnssiLinks = currentLinks;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('[anssi] poll error:', err.message);
|
res.status(502).json({ error: 'Feed fetch failed', detail: err.message });
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
app.get('/api/feeds/anssi', async (req, res) => {
|
|
||||||
if (anssiCache) return res.json(anssiCache);
|
|
||||||
// Premier appel avant le premier poll
|
|
||||||
await pollAnssi();
|
|
||||||
res.json(anssiCache || []);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Géopolitique — Google News RSS
|
// Géopolitique — Google News RSS (conflits, cyberattaques, Ukraine, Iran…)
|
||||||
let geoCache = null;
|
app.get('/api/feeds/geo', async (req, res) => {
|
||||||
let seenGeoLinks = null;
|
const query = encodeURIComponent(
|
||||||
|
|
||||||
const GEO_QUERY_URL = (() => {
|
|
||||||
const q = encodeURIComponent(
|
|
||||||
'Ukraine OR Russie OR Iran OR "Moyen-Orient" OR OTAN OR guerre OR conflit' +
|
'Ukraine OR Russie OR Iran OR "Moyen-Orient" OR OTAN OR guerre OR conflit' +
|
||||||
' OR cyberattaque OR ransomware OR APT OR "zero-day" OR vulnérabilité OR hack OR malware OR breach'
|
' OR cyberattaque OR ransomware OR APT OR "zero-day" OR vulnérabilité OR hack OR malware OR breach'
|
||||||
);
|
);
|
||||||
return `https://news.google.com/rss/search?q=${q}&hl=fr&gl=FR&ceid=FR:fr`;
|
const url = `https://news.google.com/rss/search?q=${query}&hl=fr&gl=FR&ceid=FR:fr`;
|
||||||
})();
|
|
||||||
|
|
||||||
async function pollGeo() {
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(GEO_QUERY_URL, {
|
const response = await fetch(url, {
|
||||||
headers: { 'User-Agent': 'CyberDashboard/1.0' }, timeout: 10000
|
headers: { 'User-Agent': 'CyberDashboard/1.0' },
|
||||||
|
timeout: 10000
|
||||||
});
|
});
|
||||||
const xml = await response.text();
|
const xml = await response.text();
|
||||||
const parser = new XMLParser({ ignoreAttributes: false });
|
const parser = new XMLParser({ ignoreAttributes: false });
|
||||||
const items = parser.parse(xml)?.rss?.channel?.item || [];
|
const parsed = parser.parse(xml);
|
||||||
|
const items = parsed?.rss?.channel?.item || [];
|
||||||
const entries = (Array.isArray(items) ? items : [items])
|
const entries = (Array.isArray(items) ? items : [items])
|
||||||
.map(item => ({ title: item.title || '', link: item.link || '', pubDate: item.pubDate || '', source: item.source?.['#text'] || item.source || '' }))
|
.map(item => ({
|
||||||
|
title: item.title || '',
|
||||||
|
link: item.link || '',
|
||||||
|
pubDate: item.pubDate || '',
|
||||||
|
source: item.source?.['#text'] || item.source || ''
|
||||||
|
}))
|
||||||
.sort((a, b) => new Date(b.pubDate) - new Date(a.pubDate))
|
.sort((a, b) => new Date(b.pubDate) - new Date(a.pubDate))
|
||||||
.slice(0, 7);
|
.slice(0, 7);
|
||||||
|
res.json(entries);
|
||||||
geoCache = entries;
|
|
||||||
const currentLinks = new Set(entries.map(i => i.link));
|
|
||||||
if (seenGeoLinks === null) {
|
|
||||||
seenGeoLinks = currentLinks;
|
|
||||||
} else {
|
|
||||||
const newItems = entries.filter(i => !seenGeoLinks.has(i.link));
|
|
||||||
if (newItems.length) {
|
|
||||||
broadcast({ type: 'geo_news', title: newItems[0].title, link: newItems[0].link });
|
|
||||||
seenGeoLinks = currentLinks;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('[geo] poll error:', err.message);
|
res.status(502).json({ error: 'Geo feed fetch failed', detail: err.message });
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
app.get('/api/feeds/geo', async (req, res) => {
|
|
||||||
if (geoCache) return res.json(geoCache);
|
|
||||||
await pollGeo();
|
|
||||||
res.json(geoCache || []);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── ICS / Calendar ──────────────────────────────────────────────────────────
|
// ── ICS / Calendar ──────────────────────────────────────────────────────────
|
||||||
|
|
@ -254,14 +220,17 @@ app.get('/api/calendar', async (req, res) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Root-me ranking
|
// Root-me ranking
|
||||||
// Polling rotatif : on poll un joueur à la fois en rotation continue.
|
const ROOTME_POLL_MS = 10 * 60 * 1000;
|
||||||
// Avec N joueurs et un intervalle cible de 2 min : délai entre chaque = 2min / N.
|
|
||||||
const ROOTME_TARGET_INTERVAL_MS = 2 * 60 * 1000; // refresh cible par joueur
|
|
||||||
const ROOTME_MIN_DELAY_MS = 10_000; // plancher anti-429
|
|
||||||
|
|
||||||
let rootmeCache = null;
|
let rootmeCache = null;
|
||||||
let rootmePrevScores = {}; // login → last known score
|
let rootmePrevScores = {}; // login → last known score
|
||||||
|
|
||||||
|
const ROOTME_REQUEST_DELAY_MS = 500;
|
||||||
|
const ROOTME_RETRY_BASE_MS = 2 * 60 * 1000; // 2 min, doublé à chaque échec
|
||||||
|
const ROOTME_RETRY_MAX = 3;
|
||||||
const rootmePlayerCache = {}; // id → { login, score, rank }
|
const rootmePlayerCache = {}; // id → { login, score, rank }
|
||||||
|
const retryQueue = new Map(); // id → { attempts, nextRetry }
|
||||||
|
|
||||||
|
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
|
||||||
function parseRootmeUser(profile, id) {
|
function parseRootmeUser(profile, id) {
|
||||||
const profileRaw = Array.isArray(profile) ? profile[0] : profile;
|
const profileRaw = Array.isArray(profile) ? profile[0] : profile;
|
||||||
|
|
@ -270,61 +239,117 @@ function parseRootmeUser(profile, id) {
|
||||||
return { login: user.nom || id, score: Number(user.score) || 0, rank: user.position || null };
|
return { login: user.nom || id, score: Number(user.score) || 0, rank: user.position || null };
|
||||||
}
|
}
|
||||||
|
|
||||||
function startRootmePoller() {
|
async function fetchRootmeRanking(apiKey) {
|
||||||
const apiKey = process.env.ROOTME_API_KEY;
|
const raw = fs.readFileSync(path.resolve('logins.txt'), 'utf8');
|
||||||
if (!apiKey) return;
|
const ids = raw.split('\n').map(l => l.trim()).filter(Boolean);
|
||||||
|
|
||||||
let ids;
|
|
||||||
try {
|
|
||||||
ids = fs.readFileSync(path.resolve('logins.txt'), 'utf8')
|
|
||||||
.split('\n').map(l => l.trim()).filter(Boolean);
|
|
||||||
} catch (err) {
|
|
||||||
console.error('[rootme] cannot read logins.txt:', err.message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!ids.length) return;
|
|
||||||
|
|
||||||
const delayMs = Math.max(ROOTME_MIN_DELAY_MS, Math.floor(ROOTME_TARGET_INTERVAL_MS / ids.length));
|
|
||||||
const headers = { 'Cookie': `api_key=${apiKey}`, 'User-Agent': 'CyberDashboard/1.0' };
|
const headers = { 'Cookie': `api_key=${apiKey}`, 'User-Agent': 'CyberDashboard/1.0' };
|
||||||
|
|
||||||
rootmeCache = [];
|
const results = [];
|
||||||
let idx = 0;
|
for (const id of ids) {
|
||||||
|
try {
|
||||||
|
const resp = await fetch(
|
||||||
|
`https://api.www.root-me.org/auteurs/${id}`,
|
||||||
|
{ headers, timeout: 10000 }
|
||||||
|
);
|
||||||
|
if (resp.status === 429) {
|
||||||
|
console.warn(`[rootme] rate-limited on id "${id}", scheduling retry`);
|
||||||
|
if (rootmePlayerCache[id]) results.push(rootmePlayerCache[id]);
|
||||||
|
retryQueue.set(id, { attempts: 1, nextRetry: Date.now() + ROOTME_RETRY_BASE_MS });
|
||||||
|
} else {
|
||||||
|
const entry = parseRootmeUser(await resp.json(), id);
|
||||||
|
if (entry) { rootmePlayerCache[id] = entry; results.push(entry); }
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`[rootme] fetch error for id "${id}":`, err.message);
|
||||||
|
if (rootmePlayerCache[id]) results.push(rootmePlayerCache[id]);
|
||||||
|
}
|
||||||
|
await sleep(ROOTME_REQUEST_DELAY_MS);
|
||||||
|
}
|
||||||
|
|
||||||
async function pollNext() {
|
return results.sort((a, b) => b.score - a.score);
|
||||||
const id = ids[idx];
|
}
|
||||||
idx = (idx + 1) % ids.length;
|
|
||||||
|
async function retryRateLimited() {
|
||||||
|
const apiKey = process.env.ROOTME_API_KEY;
|
||||||
|
if (!apiKey || retryQueue.size === 0) return;
|
||||||
|
|
||||||
|
const now = Date.now();
|
||||||
|
const headers = { 'Cookie': `api_key=${apiKey}`, 'User-Agent': 'CyberDashboard/1.0' };
|
||||||
|
|
||||||
|
for (const [id, state] of retryQueue) {
|
||||||
|
if (now < state.nextRetry) continue;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const resp = await fetch(`https://api.www.root-me.org/auteurs/${id}`, { headers, timeout: 10000 });
|
const resp = await fetch(
|
||||||
|
`https://api.www.root-me.org/auteurs/${id}`,
|
||||||
|
{ headers, timeout: 10000 }
|
||||||
|
);
|
||||||
|
|
||||||
if (resp.status === 429) {
|
if (resp.status === 429) {
|
||||||
console.warn(`[rootme] 429 pour id "${id}", prochain tour dans ${delayMs / 1000}s`);
|
if (state.attempts >= ROOTME_RETRY_MAX) {
|
||||||
|
console.warn(`[rootme] retry exhausted for id "${id}", giving up until next poll`);
|
||||||
|
retryQueue.delete(id);
|
||||||
|
} else {
|
||||||
|
state.attempts++;
|
||||||
|
state.nextRetry = Date.now() + ROOTME_RETRY_BASE_MS * Math.pow(2, state.attempts - 1);
|
||||||
|
console.warn(`[rootme] retry 429 for id "${id}" (attempt ${state.attempts}/${ROOTME_RETRY_MAX}), next in ${Math.round((state.nextRetry - Date.now()) / 60000)} min`);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const entry = parseRootmeUser(await resp.json(), id);
|
const entry = parseRootmeUser(await resp.json(), id);
|
||||||
if (entry) {
|
if (entry) {
|
||||||
rootmePlayerCache[id] = entry;
|
|
||||||
const prev = rootmePrevScores[entry.login];
|
const prev = rootmePrevScores[entry.login];
|
||||||
if (prev !== undefined && entry.score > prev) {
|
if (prev !== undefined && entry.score > prev) {
|
||||||
const gained = entry.score - prev;
|
const gained = entry.score - prev;
|
||||||
console.log(`[rootme] FLAG ! ${entry.login} +${gained} pts (${prev} → ${entry.score})`);
|
console.log(`[rootme] FLAG (retry) ! ${entry.login} +${gained} pts`);
|
||||||
broadcast({ type: 'rootme_flag', login: entry.login, gained, newScore: entry.score });
|
broadcast({ type: 'rootme_flag', login: entry.login, gained, newScore: entry.score });
|
||||||
}
|
}
|
||||||
|
rootmePlayerCache[id] = entry;
|
||||||
rootmePrevScores[entry.login] = entry.score;
|
rootmePrevScores[entry.login] = entry.score;
|
||||||
|
if (rootmeCache) {
|
||||||
const i = rootmeCache.findIndex(u => u.login === entry.login);
|
const idx = rootmeCache.findIndex(u => u.login === entry.login);
|
||||||
if (i !== -1) rootmeCache[i] = entry; else rootmeCache.push(entry);
|
if (idx !== -1) rootmeCache[idx] = entry; else rootmeCache.push(entry);
|
||||||
rootmeCache.sort((a, b) => b.score - a.score);
|
rootmeCache.sort((a, b) => b.score - a.score);
|
||||||
broadcast({ type: 'rootme_update', ranking: rootmeCache });
|
broadcast({ type: 'rootme_update', ranking: rootmeCache });
|
||||||
}
|
}
|
||||||
|
console.log(`[rootme] retry OK for id "${id}" (${entry.login})`);
|
||||||
|
}
|
||||||
|
retryQueue.delete(id);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`[rootme] erreur pour id "${id}":`, err.message);
|
console.error(`[rootme] retry error for id "${id}":`, err.message);
|
||||||
|
retryQueue.delete(id);
|
||||||
|
}
|
||||||
|
await sleep(ROOTME_REQUEST_DELAY_MS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function pollRootme() {
|
||||||
|
const apiKey = process.env.ROOTME_API_KEY;
|
||||||
|
if (!apiKey) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ranking = await fetchRootmeRanking(apiKey);
|
||||||
|
|
||||||
|
// Detect score gains and broadcast flag events
|
||||||
|
const isFirstPoll = Object.keys(rootmePrevScores).length === 0;
|
||||||
|
if (!isFirstPoll) {
|
||||||
|
ranking.forEach(user => {
|
||||||
|
const prev = rootmePrevScores[user.login];
|
||||||
|
if (prev !== undefined && user.score > prev) {
|
||||||
|
const gained = user.score - prev;
|
||||||
|
console.log(`[rootme] FLAG ! ${user.login} +${gained} pts (${prev} -> ${user.score})`);
|
||||||
|
broadcast({ type: 'rootme_flag', login: user.login, gained, newScore: user.score });
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(pollNext, delayMs);
|
ranking.forEach(u => { rootmePrevScores[u.login] = u.score; });
|
||||||
|
rootmeCache = ranking;
|
||||||
|
broadcast({ type: 'rootme_update', ranking });
|
||||||
|
console.log(`[rootme] polled — ${ranking.length} joueur(s)`);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('[rootme] poll error:', err.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`[rootme] démarrage polling rotatif — ${ids.length} joueur(s), 1 requête toutes les ${delayMs / 1000}s → refresh ~${Math.round(ROOTME_TARGET_INTERVAL_MS / 60000)} min/joueur`);
|
|
||||||
pollNext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
app.get('/api/rootme', (req, res) => {
|
app.get('/api/rootme', (req, res) => {
|
||||||
|
|
@ -335,9 +360,7 @@ app.get('/api/rootme', (req, res) => {
|
||||||
|
|
||||||
server.listen(PORT, () => {
|
server.listen(PORT, () => {
|
||||||
console.log(`Cyber Dashboard running on http://localhost:${PORT}`);
|
console.log(`Cyber Dashboard running on http://localhost:${PORT}`);
|
||||||
pollAnssi();
|
pollRootme();
|
||||||
setInterval(pollAnssi, FEED_POLL_MS);
|
setInterval(pollRootme, ROOTME_POLL_MS);
|
||||||
pollGeo();
|
setInterval(retryRateLimited, 30 * 1000);
|
||||||
setInterval(pollGeo, FEED_POLL_MS);
|
|
||||||
startRootmePoller();
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue