Skip to content

Commit a6b8fe6

Browse files
authored
Merge pull request #37 from lactf/instancer-support
Add instancer support
2 parents 42a1ac7 + ca173cd commit a6b8fe6

File tree

20 files changed

+105
-65
lines changed

20 files changed

+105
-65
lines changed

client/src/api/challenges.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { request, handleResponse } from './util'
2-
import { privateProfile } from './profile'
32

43
export const getChallenges = async () => {
54
const resp = await request('GET', '/challs')
@@ -13,20 +12,6 @@ export const getChallenges = async () => {
1312
return handleResponse({ resp, valid: ['goodChallenges'] })
1413
}
1514

16-
export const getPrivateSolves = async () => {
17-
const { data, error } = await privateProfile()
18-
19-
if (error) {
20-
return { error }
21-
}
22-
return {
23-
solves: data.solves,
24-
// LA CTF: track bloods
25-
bloods: data.bloods,
26-
// --------------------
27-
}
28-
}
29-
3015
export const getSolves = ({ challId, limit, offset }) => {
3116
return request('GET', `/challs/${encodeURIComponent(challId)}/solves`, {
3217
limit,

client/src/components/ctftime-additional.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default withStyles({
6060
}, [handleRegister])
6161

6262
// Try login with CTFtime token only, if fails prompt for name
63-
useEffect(handleRegister, [])
63+
useEffect(handleRegister, [handleRegister])
6464

6565
return (
6666
<div class='row u-center'>

client/src/components/ctftime-button.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default withStyles({
6060

6161
render ({ classes, ...props }) {
6262
return (
63-
<div {...props} >
63+
<div {...props}>
6464
<button class={classes.ctftimeButton} onClick={this.handleClick}>
6565
<Ctftime />
6666
</button>

client/src/components/form.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default withStyles({
2222
{
2323
[].concat(children).map(input => {
2424
if (input.props === undefined) {
25-
return
25+
return null
2626
}
2727
if (!input.props.name) {
2828
return input

client/src/components/problem.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,13 @@ export default withStyles({
183183
// LA CTF: track bloods
184184
blood: {
185185
'& a': {
186-
color: '#fff',
186+
color: '#fff'
187187
},
188188
'& .markup a': {
189189
textDecoration: 'underline'
190190
},
191191
'& input': {
192-
backgroundColor: 'var(--bg-darker) !important',
192+
backgroundColor: 'var(--bg-darker) !important'
193193
}
194194
},
195195
blood1: {

client/src/components/profile/members-card.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const MembersCard = withStyles({
111111
members.length !== 0 &&
112112
<div class='row'>
113113
{
114-
members.map(data => <MemberRow setMembers={setMembers} {...data} />)
114+
members.map(data => <MemberRow key={data.id} setMembers={setMembers} {...data} />)
115115
}
116116
</div>
117117
}

client/src/components/solves-dialog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const SolvesDialog = withStyles({
109109
<div class={classes.label}>Team</div>
110110
<div class={classes.label}>Solve time</div>
111111
{solves.map((solve, i) => (
112-
<Fragment>
112+
<Fragment key={solve.userId}>
113113
<div class={`${classes.inlineLabel} ${classes.number}`}>#</div>
114114
<div class={classes.number}>{(page - 1) * pageSize + i + 1}</div>
115115
<div class={classes.inlineLabel}>Team</div>

client/src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ export default withStyles({
167167
#f4b42c 82.8125%,
168168
#ffd99f 100%
169169
)`,
170-
'--blood-gold': `linear-gradient(120deg, #daa42e 0%, #d77774 100%)`,
171-
'--blood-silver': `linear-gradient(120deg, #6facc3 0%, #80728f 100%)`,
172-
'--blood-bronze': `linear-gradient(120deg, #ac593a 0%, #5d4e4f 100%)`,
173-
'--blood-gold-shadow': `#daa42e`,
170+
'--blood-gold': 'linear-gradient(120deg, #daa42e 0%, #d77774 100%)',
171+
'--blood-silver': 'linear-gradient(120deg, #6facc3 0%, #80728f 100%)',
172+
'--blood-bronze': 'linear-gradient(120deg, #ac593a 0%, #5d4e4f 100%)',
173+
'--blood-gold-shadow': '#daa42e'
174174
},
175175
'@media (min-aspect-ratio: 1440/514)': {
176176
'@global :root': {

client/src/routes/challs.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import Problem from '../components/problem'
66
import NotStarted from '../components/not-started'
77
import { useToast } from '../components/toast'
88

9-
import { getChallenges, getPrivateSolves } from '../api/challenges'
9+
import { privateProfile } from '../api/profile'
10+
import { getChallenges } from '../api/challenges'
1011

1112
const loadStates = {
1213
pending: 0,
@@ -84,25 +85,30 @@ const Challenges = ({ classes }) => {
8485
}
8586
})
8687

87-
setProblems(data)
88-
setCategories(newCategories)
89-
}
90-
action()
91-
}, [toast, categories, problems])
92-
93-
useEffect(() => {
94-
const action = async () => {
95-
const { solves, bloods, error } = await getPrivateSolves()
96-
if (error) {
97-
toast({ body: error, type: 'error' })
88+
const { data: profileData, error: profileError } = await privateProfile()
89+
if (profileError) {
90+
toast({ body: profileError, type: 'error' })
9891
return
9992
}
10093

101-
setSolveIDs(solves.map(solve => solve.id))
102-
setBloods(new Map(bloods.map(x => [x.id, x.rank])))
94+
setSolveIDs(profileData.solves.map(solve => solve.id))
95+
setBloods(new Map(profileData.bloods.map(x => [x.id, x.rank])))
96+
97+
const instancerPlaceholderRegex = /\{instancer:([a-zA-Z0-9-]+)\}/g
98+
if (config.instancerUrl !== '') {
99+
data.forEach(problem => {
100+
problem.description = problem.description.replaceAll('{instancer}', `[Deploy challenge](${encodeURI(config.instancerUrl)}/chall/${problem.id}?token=${encodeURIComponent(profileData.instancerToken)})`)
101+
problem.description = problem.description.replaceAll('{instancer_token}', encodeURIComponent(profileData.instancerToken))
102+
problem.description = problem.description.replaceAll('{instancer_url}', encodeURI(config.instancerUrl))
103+
problem.description = problem.description.replaceAll(instancerPlaceholderRegex, `${encodeURI(config.instancerUrl)}/chall/$1?token=${encodeURIComponent(profileData.instancerToken)}`)
104+
})
105+
}
106+
107+
setProblems(data)
108+
setCategories(newCategories)
103109
}
104110
action()
105-
}, [toast])
111+
}, [toast, categories, problems])
106112

107113
useEffect(() => {
108114
localStorage.challPageState = JSON.stringify({ categories, showSolved })

client/src/routes/profile.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,27 @@ const TeamCodeCard = withStyles({
150150
)
151151
})
152152

153+
const InstancerCodeCard = withStyles({
154+
btn: {
155+
marginRight: '10px'
156+
}
157+
}, ({ instancerToken, classes }) => {
158+
const instancerURL = `${config.instancerUrl}/login?token=${encodeURIComponent(instancerToken)}`
159+
160+
return (
161+
<div class='card'>
162+
<div class='content'>
163+
<p>Instancer Login</p>
164+
<p class='font-thin'>Use this link to login to the challenge instancer.</p>
165+
166+
<a href={instancerURL} target='_blank' rel='noreferrer'>
167+
<button class={`${classes.btn} btn-info u-center`} name='btn' value='submit' type='button'>Instancer Login</button>
168+
</a>
169+
</div>
170+
</div>
171+
)
172+
})
173+
153174
const UpdateCard = withStyles({
154175
form: {
155176
'& button': {
@@ -303,6 +324,7 @@ const Profile = ({ uuid, classes }) => {
303324
score,
304325
solves,
305326
teamToken,
327+
instancerToken,
306328
ctftimeId,
307329
allowedDivisions
308330
} = data
@@ -371,6 +393,7 @@ const Profile = ({ uuid, classes }) => {
371393
{isPrivate && (
372394
<div class={classes.privateCol}>
373395
<TeamCodeCard {...{ teamToken }} />
396+
{ config.instancerUrl !== '' && <InstancerCodeCard instancerToken={instancerToken} /> }
374397
<UpdateCard {...{ name, email, divisionId, allowedDivisions, onUpdate: onProfileUpdate }} />
375398
{config.ctftime && (
376399
<CtftimeCard {...{ ctftimeId, onUpdate: onProfileUpdate }} />
@@ -385,10 +408,10 @@ const Profile = ({ uuid, classes }) => {
385408
{isPrivate
386409
? (
387410
<PrivateSolvesCard solves={solves} />
388-
)
411+
)
389412
: (
390413
<PublicSolvesCard solves={solves} />
391-
)}
414+
)}
392415
</div>
393416
</div>
394417
)

0 commit comments

Comments
 (0)