From 0e0e0706faaa29e51a547dd6382585ed6d6a89b2 Mon Sep 17 00:00:00 2001 From: crisis82 Date: Tue, 11 Jul 2023 17:22:45 +0200 Subject: [PATCH] added service and tick parameters --- configs/index.js | 6 ++- configs/package.json | 2 - configs/services.json | 5 ++ src/api/client-api.ts | 2 +- src/game-manager.ts | 1 + src/lib/models/flag.ts | 10 +++- src/lib/resolvers/flagResolver.ts | 45 ++++++++++++++---- src/next/components/flagRow.tsx | 4 +- src/next/components/flagsTable.tsx | 4 +- src/next/components/search.tsx | 73 +++++++++++++++++++++++++----- src/next/lib/graphql.ts | 19 ++++++-- src/next/lib/types.ts | 6 ++- src/pages/index.tsx | 8 ++-- 13 files changed, 146 insertions(+), 39 deletions(-) create mode 100644 configs/services.json diff --git a/configs/index.js b/configs/index.js index f0676b4..19328f5 100644 --- a/configs/index.js +++ b/configs/index.js @@ -1,21 +1,23 @@ const got = require('got'); -const SYSTEM_IP = 'http://10.10.0.1/flags'; +const FLAG_SERVER = 'http://10.10.0.1/flags'; const TEAM_TOKEN = '48638b31449aef540d6e8131733bb3ed'; const TIMEOUT_MS = 5000; const teams = require('./teams.json'); +const services = require('./services.json'); module.exports = { flagFormat: '[A-Z0-9]{31}=', submitInterval: 120, flagLifetime: 5 * 120, teams, + services, submitFlags: async (flags, onSubmit) => { const tot = flags.length; const chunkSize = 20; for (let i = 0; i < tot - chunkSize; i += chunkSize) { const answer = await got - .put(SYSTEM_IP, { + .put(FLAG_SERVER, { headers: { 'X-Team-Token': TEAM_TOKEN }, diff --git a/configs/package.json b/configs/package.json index 137e125..57ce06c 100644 --- a/configs/package.json +++ b/configs/package.json @@ -1,11 +1,9 @@ { "name": "server", - "version": "0.1.0", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, - "license": "UNLICENSED", "dependencies": { "got": "^11.8.1" } diff --git a/configs/services.json b/configs/services.json new file mode 100644 index 0000000..1a7c5cb --- /dev/null +++ b/configs/services.json @@ -0,0 +1,5 @@ +{ + "example service 1": "8000", + "example service 2": "3333", + "example service 3": "4123" +} diff --git a/src/api/client-api.ts b/src/api/client-api.ts index f5eda65..d371c6f 100644 --- a/src/api/client-api.ts +++ b/src/api/client-api.ts @@ -18,7 +18,7 @@ const makeClientApiRouter = async () => { for (const flag of flags) { flagsForInserion.push({ flag: flag.flag, - sploit: flag.sploit, + exploit: flag.exploit, team: flag.team, timestamp: new Date() }); diff --git a/src/game-manager.ts b/src/game-manager.ts index 1f95ef9..0a423a8 100644 --- a/src/game-manager.ts +++ b/src/game-manager.ts @@ -9,6 +9,7 @@ class GameManager { private game: any; getClientConfig() { return { + SERVICES: this.game.services, TEAMS: this.game.teams, FLAG_FORMAT: this.game.flagFormat, FLAG_LIFETIME: this.game.flagLifetime, diff --git a/src/lib/models/flag.ts b/src/lib/models/flag.ts index b831735..d05db1a 100644 --- a/src/lib/models/flag.ts +++ b/src/lib/models/flag.ts @@ -12,7 +12,7 @@ export default class Flag extends Model { @Field() @Column({ allowNull: false }) - sploit!: string; + exploit!: string; @Field() @Column({ allowNull: false }) @@ -22,6 +22,14 @@ export default class Flag extends Model { @Column({ allowNull: false }) timestamp!: Date; + @Field() + @Column({ allowNull: false }) + service!: string; + + @Field() + @Column({ allowNull: false }) + tick!: number; + @Field({ nullable: true }) @Column({ allowNull: true, defaultValue: 'QUEUED' }) @Index({ diff --git a/src/lib/resolvers/flagResolver.ts b/src/lib/resolvers/flagResolver.ts index 5649747..2e73913 100644 --- a/src/lib/resolvers/flagResolver.ts +++ b/src/lib/resolvers/flagResolver.ts @@ -21,12 +21,20 @@ class GetFlagsCountArgs { @IsOptional() @Field({ nullable: true }) - sploit?: string; + service?: string; + + @IsOptional() + @Field({ nullable: true }) + exploit?: string; @IsOptional() @Field({ nullable: true }) team?: string; + @IsOptional() + @Field({ nullable: true }) + tick?: number; + @IsOptional() @IsDate() @Field({ nullable: true }) @@ -63,7 +71,10 @@ class GetFlagsArgs extends GetFlagsCountArgs { @ObjectType() class SearchValues { @Field(type => [String]) - sploits: string[]; + service: string[]; + + @Field(type => [String]) + exploits: string[]; @Field(type => [String]) teams: string[]; @@ -75,12 +86,14 @@ class SearchValues { @Resolver() export class FlagResolver { static argumentsToQuery(args: GetFlagsCountArgs | GetFlagsArgs) { - const { flag, sploit, team, since, until, status, checksystem_response } = args; + const { flag, service, exploit, team, tick, since, until, status, checksystem_response } = args; const search: any = {}; if (flag) search.flag = { [Op.iLike]: '%' + flag + '%' }; - if (sploit) search.sploit = sploit; + if (service) search.service = service; + if (exploit) search.exploit = exploit; if (team) search.team = team; + if (tick) search.tick = tick; if (status) search.status = status; if (checksystem_response) search.checksystem_response = { [Op.iLike]: '%' + checksystem_response + '%' }; @@ -130,12 +143,19 @@ export class FlagResolver { @Query(returns => SearchValues) async getSearchValues(): Promise { - const sploitRes: [{ DISTINCT: string }] = await Flag.aggregate('sploit', 'DISTINCT', { + const serviceRes: [{ DISTINCT: string }] = await Flag.aggregate('service', 'DISTINCT', { plain: false, raw: true }); - const sploits = []; - for (const status of sploitRes) sploits.push(status.DISTINCT); + const services = []; + for (const status of serviceRes) services.push(status.DISTINCT); + + const exploitRes: [{ DISTINCT: string }] = await Flag.aggregate('exploit', 'DISTINCT', { + plain: false, + raw: true + }); + const exploits = []; + for (const status of exploitRes) exploits.push(status.DISTINCT); const teamRes: [{ DISTINCT: string }] = await Flag.aggregate('team', 'DISTINCT', { plain: false, @@ -144,6 +164,13 @@ export class FlagResolver { const teams = []; for (const status of teamRes) teams.push(status.DISTINCT); + const tickRes: [{ DISTINCT: number }] = await Flag.aggregate('tick', 'DISTINCT', { + plain: false, + raw: true + }); + const ticks = []; + for (const status of tickRes) ticks.push(status.DISTINCT); + const statusRes: [{ DISTINCT: string }] = await Flag.aggregate('status', 'DISTINCT', { plain: false, raw: true @@ -151,7 +178,7 @@ export class FlagResolver { const statuses = []; for (const status of statusRes) statuses.push(status.DISTINCT); - return { sploits, teams, statuses }; + return { services, exploits, teams, statuses }; } @Mutation(returns => Boolean) @@ -161,7 +188,7 @@ export class FlagResolver { for (const flag of flags) { flagsForInserion.push({ flag: flag, - sploit: 'MANUAL', + exploit: 'MANUAL', team: 'MANUAL', timestamp: new Date() }); diff --git a/src/next/components/flagRow.tsx b/src/next/components/flagRow.tsx index 1cd22e1..df4e6df 100644 --- a/src/next/components/flagRow.tsx +++ b/src/next/components/flagRow.tsx @@ -8,10 +8,12 @@ interface Props { const FlagRow: StatelessComponent = ({ flag }) => ( - {flag.sploit} + {flag.exploit} {flag.team} + {flag.service} {flag.flag} {moment(flag.timestamp).format('HH:mm:ss')} + {flag.tick} {flag.status} {flag.checksystem_response} diff --git a/src/next/components/flagsTable.tsx b/src/next/components/flagsTable.tsx index 343f206..c14af39 100644 --- a/src/next/components/flagsTable.tsx +++ b/src/next/components/flagsTable.tsx @@ -18,10 +18,12 @@ class FlagsTable extends Component { - + + + diff --git a/src/next/components/search.tsx b/src/next/components/search.tsx index eda7759..8e7ff93 100644 --- a/src/next/components/search.tsx +++ b/src/next/components/search.tsx @@ -12,10 +12,12 @@ interface Props { } interface State { - sploit: string; + service: string; + exploit: string; team: string; status: string; flag: string; + tick: string; since?: Date; until?: Date; checksystemResponse: string; @@ -26,17 +28,21 @@ class Search extends Component { super(props); this.state = { - sploit: props.searchParams.sploit || '', + service: props.searchParams.service || '', + exploit: props.searchParams.exploit || '', team: props.searchParams.team || '', status: props.searchParams.status || '', flag: props.searchParams.flag || '', + tick: props.searchParams.tick || '', since: props.searchParams.since && new Date(props.searchParams.since), until: props.searchParams.until && new Date(props.searchParams.until), checksystemResponse: props.searchParams.checksystem_response || '' }; - this.onSelectSploit = this.onSelectSploit.bind(this); + this.onSelectService = this.onSelectService.bind(this); + this.onSelectExploit = this.onSelectExploit.bind(this); this.onSelectTeam = this.onSelectTeam.bind(this); + this.onSelectTick = this.onSelectTick.bind(this); this.onSelectStatus = this.onSelectStatus.bind(this); this.onTextInputChanged = this.onTextInputChanged.bind(this); this.onResetClick = this.onResetClick.bind(this); @@ -47,7 +53,8 @@ class Search extends Component { //If searchParams object changed (needed for update on navigation) if (this.props.searchParams !== prevProps.searchParams) this.setState({ - sploit: this.props.searchParams.sploit || '', + service: this.props.searchParams.service || '', + exploit: this.props.searchParams.exploit || '', team: this.props.searchParams.team || '', status: this.props.searchParams.status || '', flag: this.props.searchParams.flag || '', @@ -57,9 +64,15 @@ class Search extends Component { }); } - onSelectSploit(event: any) { + + onSelectService(event: any) { + this.setState({ + service: event.target.value + }); + } + onSelectExploit(event: any) { this.setState({ - sploit: event.target.value + exploit: event.target.value }); } onSelectTeam(event: any) { @@ -67,6 +80,11 @@ class Search extends Component { team: event.target.value }); } + onSelectTick(event: any) { + this.setState({ + tick: event.target.value + }); + } onSelectStatus(event: any) { this.setState({ status: event.target.value @@ -84,8 +102,10 @@ class Search extends Component { onResetClick() { this.setState({ - sploit: '', + service: '', + exploit: '', team: '', + tick: '', status: '', flag: '', since: undefined, @@ -99,8 +119,10 @@ class Search extends Component { onSearchClick() { const payload: any = {}; - payload.sploit = this.state.sploit; + payload.service = this.state.service; + payload.exploit = this.state.exploit; payload.team = this.state.team; + payload.tick = this.state.tick; payload.status = this.state.status; payload.flag = this.state.flag; payload.since = this.state.since ? moment(this.state.since).format('HH:mm') : ''; @@ -118,14 +140,31 @@ class Search extends Component {

Show Flags

- + +
+
+ + +
SploitExploit TeamService Flag TimeTick Status Checksystem Response