From 55b83a7474f2f87187551eff453ee8a7ca229a00 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Sat, 8 Jun 2024 14:36:34 +0200 Subject: [PATCH] Add CINI parser (ECSC 2024) --- front/src/ctfnote/parsers/cini.ts | 58 ++++++++++++++++++++++++++++++ front/src/ctfnote/parsers/index.ts | 2 ++ 2 files changed, 60 insertions(+) create mode 100644 front/src/ctfnote/parsers/cini.ts diff --git a/front/src/ctfnote/parsers/cini.ts b/front/src/ctfnote/parsers/cini.ts new file mode 100644 index 00000000..3973010d --- /dev/null +++ b/front/src/ctfnote/parsers/cini.ts @@ -0,0 +1,58 @@ +import { ParsedTask, Parser } from '.'; +import { parseJson, parseJsonStrict } from '../utils'; + +interface Events { + gamePause?: unknown; + events: [ + { + id: number; + name: string; + sections: [ + { + id: number; + name: string; + challenges: [ + { + id: number; + title: string; + tags: string[]; + authors: string[]; + currentScore: number; + currentGlobalSolves: number; + hidden: boolean; + }, + ]; + }, + ]; + }, + ]; +} + +const CINIParser: Parser = { + name: 'Cybersecurity National Lab (CINI) platform, ECSC 2024 (Turin) parser', + hint: 'paste platform /api/challenges', + + parse(s: string): ParsedTask[] { + const tasks = []; + const data = parseJsonStrict(s); + if (!Array.isArray(data)) { + return []; + } + + for (const event of data.events) { + for (const section of event.sections) { + for (const chall of section.challenges) { + tasks.push({ title: chall.title, tags: chall.tags }); + } + } + } + + return tasks; + }, + isValid(s) { + const data = parseJson(s); + return Array.isArray(data); + }, +}; + +export default CINIParser; diff --git a/front/src/ctfnote/parsers/index.ts b/front/src/ctfnote/parsers/index.ts index f537cf92..9de03f6d 100644 --- a/front/src/ctfnote/parsers/index.ts +++ b/front/src/ctfnote/parsers/index.ts @@ -5,6 +5,7 @@ import HTBParser from './htb'; import PicoParser from './pico'; import justCTFParser from './justctf'; import AngstromParser from './angstrom'; +import CINIParser from './cini'; export type ParsedTask = { title: string; @@ -28,4 +29,5 @@ export default [ PicoParser, justCTFParser, AngstromParser, + CINIParser, ];