Skip to content

Commit

Permalink
feat(admin): container instance manager
Browse files Browse the repository at this point in the history
  • Loading branch information
GZTimeWalker committed Jun 30, 2023
1 parent c51a373 commit d0c414b
Show file tree
Hide file tree
Showing 15 changed files with 670 additions and 54 deletions.
4 changes: 2 additions & 2 deletions src/GZCTF/ClientApp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-pdf": "^7.1.2",
"react-router": "^6.14.0",
"react-router-dom": "^6.14.0",
"react-router": "^6.14.1",
"react-router-dom": "^6.14.1",
"swr": "^2.2.0",
"vite-tsconfig-paths": "^4.2.0"
},
Expand Down
26 changes: 13 additions & 13 deletions src/GZCTF/ClientApp/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

199 changes: 176 additions & 23 deletions src/GZCTF/ClientApp/src/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,15 @@ export interface TeamUserInfoModel {

/** 队伍信息更改(Admin) */
export interface AdminTeamModel {
/** 队伍名称 */
/**
* 队伍名称
* @maxLength 15
*/
name?: string | null
/** 队伍签名 */
/**
* 队伍签名
* @maxLength 31
*/
bio?: string | null
/** 是否锁定 */
locked?: boolean | null
Expand Down Expand Up @@ -495,6 +501,107 @@ export interface WriteupInfoModel {
uploadTimeUTC?: string
}

/** 列表响应 */
export interface ArrayResponseOfContainerInstanceModel {
/** 数据 */
data: ContainerInstanceModel[]
/**
* 数据长度
* @format int32
*/
length: number
/**
* 总长度
* @format int32
*/
total?: number
}

/** 容器实例信息(Admin) */
export interface ContainerInstanceModel {
/** 队伍 */
team?: TeamModel | null
/** 题目 */
challenge?: ChallengeModel | null
/** 容器镜像 */
image?: string
/** 容器数据库 ID */
containerGuid?: string
/** 容器 ID */
containerId?: string
/**
* 容器创建时间
* @format date-time
*/
startedAt?: string
/**
* 容器期望终止时间
* @format date-time
*/
expectStopAt?: string
/** 公开 IP */
publicIP?: string | null
/**
* 公开端口
* @format int32
*/
publicPort?: number | null
}

/** 队伍信息 */
export interface TeamModel {
/**
* 队伍 ID
* @format int32
*/
id?: number
/** 队名 */
name?: string
}

/** 题目信息 */
export interface ChallengeModel {
/**
* 题目 ID
* @format int32
*/
id?: number
/** 题目名称 */
title?: string
/** 题目标签 */
tag?: ChallengeTag
}

/** 题目标签 */
export enum ChallengeTag {
Misc = 'Misc',
Crypto = 'Crypto',
Pwn = 'Pwn',
Web = 'Web',
Reverse = 'Reverse',
Blockchain = 'Blockchain',
Forensics = 'Forensics',
Hardware = 'Hardware',
Mobile = 'Mobile',
PPC = 'PPC',
}

/** 列表响应 */
export interface ArrayResponseOfLocalFile {
/** 数据 */
data: LocalFile[]
/**
* 数据长度
* @format int32
*/
length: number
/**
* 总长度
* @format int32
*/
total?: number
}

export interface LocalFile {
/**
* 文件哈希
Expand Down Expand Up @@ -785,20 +892,6 @@ export interface ChallengeEditDetailModel {
flags: FlagInfoModel[]
}

/** 题目标签 */
export enum ChallengeTag {
Misc = 'Misc',
Crypto = 'Crypto',
Pwn = 'Pwn',
Web = 'Web',
Reverse = 'Reverse',
Blockchain = 'Blockchain',
Forensics = 'Forensics',
Hardware = 'Hardware',
Mobile = 'Mobile',
PPC = 'PPC',
}

export enum ChallengeType {
StaticAttachment = 'StaticAttachment',
StaticContainer = 'StaticContainer',
Expand Down Expand Up @@ -2485,7 +2578,64 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
) => mutate<void>(`/api/admin/writeups/${id}/all`, data, options),

/**
* @description 使用此接口获取全部日志,需要Admin权限
* @description 使用此接口获取全部容器实例,需要Admin权限
*
* @tags Admin
* @name AdminInstances
* @summary 获取全部容器实例
* @request GET:/api/admin/instances
*/
adminInstances: (params: RequestParams = {}) =>
this.request<ArrayResponseOfContainerInstanceModel, RequestResponse>({
path: `/api/admin/instances`,
method: 'GET',
format: 'json',
...params,
}),
/**
* @description 使用此接口获取全部容器实例,需要Admin权限
*
* @tags Admin
* @name AdminInstances
* @summary 获取全部容器实例
* @request GET:/api/admin/instances
*/
useAdminInstances: (options?: SWRConfiguration, doFetch: boolean = true) =>
useSWR<ArrayResponseOfContainerInstanceModel, RequestResponse>(
doFetch ? `/api/admin/instances` : null,
options
),

/**
* @description 使用此接口获取全部容器实例,需要Admin权限
*
* @tags Admin
* @name AdminInstances
* @summary 获取全部容器实例
* @request GET:/api/admin/instances
*/
mutateAdminInstances: (
data?: ArrayResponseOfContainerInstanceModel | Promise<ArrayResponseOfContainerInstanceModel>,
options?: MutatorOptions
) => mutate<ArrayResponseOfContainerInstanceModel>(`/api/admin/instances`, data, options),

/**
* @description 使用此接口强制删除容器实例,需要Admin权限
*
* @tags Admin
* @name AdminDestroyInstance
* @summary 删除容器实例
* @request DELETE:/api/admin/instances/{id}
*/
adminDestroyInstance: (id: string, params: RequestParams = {}) =>
this.request<void, RequestResponse>({
path: `/api/admin/instances/${id}`,
method: 'DELETE',
...params,
}),

/**
* @description 使用此接口获取全部文件,需要Admin权限
*
* @tags Admin
* @name AdminFiles
Expand All @@ -2507,15 +2657,15 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
},
params: RequestParams = {}
) =>
this.request<LocalFile[], RequestResponse>({
this.request<ArrayResponseOfLocalFile, RequestResponse>({
path: `/api/admin/files`,
method: 'GET',
query: query,
format: 'json',
...params,
}),
/**
* @description 使用此接口获取全部日志,需要Admin权限
* @description 使用此接口获取全部文件,需要Admin权限
*
* @tags Admin
* @name AdminFiles
Expand All @@ -2538,10 +2688,13 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
options?: SWRConfiguration,
doFetch: boolean = true
) =>
useSWR<LocalFile[], RequestResponse>(doFetch ? [`/api/admin/files`, query] : null, options),
useSWR<ArrayResponseOfLocalFile, RequestResponse>(
doFetch ? [`/api/admin/files`, query] : null,
options
),

/**
* @description 使用此接口获取全部日志,需要Admin权限
* @description 使用此接口获取全部文件,需要Admin权限
*
* @tags Admin
* @name AdminFiles
Expand All @@ -2561,9 +2714,9 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
*/
skip?: number
},
data?: LocalFile[] | Promise<LocalFile[]>,
data?: ArrayResponseOfLocalFile | Promise<ArrayResponseOfLocalFile>,
options?: MutatorOptions
) => mutate<LocalFile[]>([`/api/admin/files`, query], data, options),
) => mutate<ArrayResponseOfLocalFile>([`/api/admin/files`, query], data, options),
}
assets = {
/**
Expand Down
13 changes: 11 additions & 2 deletions src/GZCTF/ClientApp/src/components/ActionIconWithConfirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,19 @@ export const ActionIconWithConfirm: FC<ActionIconWithConfirmProps> = (props) =>
</Popover.Target>
<Popover.Dropdown>
<Stack align="center" spacing={6}>
<Text size="sm" weight={500}>
<Text
size="sm"
weight="bold"
h="auto"
style={{
whiteSpace: 'pre-wrap',
textAlign: 'center',
}}
>
{props.message}
</Text>
<Group w="100%" style={{ justifyContent: 'space-evenly' }}>

<Group w="100%" position="apart">
<Button
size="xs"
py={2}
Expand Down
1 change: 0 additions & 1 deletion src/GZCTF/ClientApp/src/components/admin/TeamEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const TeamEditModal: FC<TeamEditModalProps> = (props) => {
useEffect(() => {
setTeamInfo({ ...team })
setActiveTeam(team)
console.log(team)
}, [team])

const onChangeTeamInfo = () => {
Expand Down
2 changes: 2 additions & 0 deletions src/GZCTF/ClientApp/src/components/admin/WithAdminTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
mdiAccountGroupOutline,
mdiFileDocumentOutline,
mdiSitemapOutline,
mdiPackageVariantClosed,
} from '@mdi/js'
import { Icon } from '@mdi/react'
import IconTabs from '@Components/IconTabs'
Expand All @@ -16,6 +17,7 @@ const pages = [
{ icon: mdiFlagOutline, title: '比赛管理', path: 'games', color: 'yellow' },
{ icon: mdiAccountGroupOutline, title: '队伍管理', path: 'teams', color: 'green' },
{ icon: mdiAccountCogOutline, title: '用户管理', path: 'users', color: 'cyan' },
{ icon: mdiPackageVariantClosed, title: '容器管理', path: 'instances', color: 'blue' },
{ icon: mdiFileDocumentOutline, title: '系统日志', path: 'logs', color: 'red' },
{ icon: mdiSitemapOutline, title: '全局设置', path: 'configs', color: 'orange' },
]
Expand Down
Loading

0 comments on commit d0c414b

Please sign in to comment.