diff --git a/src/pages/assignments/student/[code].jsx b/src/pages/assignments/student/[code].jsx index b81d6c0a..2482d867 100644 --- a/src/pages/assignments/student/[code].jsx +++ b/src/pages/assignments/student/[code].jsx @@ -147,8 +147,11 @@ export default function Slug() { const cookie = getCookie('idToken'); const data = jwtDecode(cookie); const token = data.id; - const [created, termId] = await api.buildTerminal(challenge, token); + const [created, termId, fileIDs] = await api.buildTerminal(challenge, token); + + console.log('Pengiouns here:', created, termId); + if (created) { if (skipToCheckStatus) { console.log('Skipping to check status', termId); diff --git a/src/pages/assignments/teacher/[code].jsx b/src/pages/assignments/teacher/[code].jsx index 17b625c3..ae869c98 100644 --- a/src/pages/assignments/teacher/[code].jsx +++ b/src/pages/assignments/teacher/[code].jsx @@ -157,7 +157,8 @@ export default function Id() { const cookie = getCookie('idToken'); const data = jwtDecode(cookie); const token = data.id; - const [created, termId] = await api.buildTerminal(challenge, token); + const [created, termId, fileIDs] = await api.buildTerminal(challenge, token); + console.log('Pengiouns here:', created, termId); if(created) { if(skipToCheckStatus) { diff --git a/src/pages/challenges/[...id].jsx b/src/pages/challenges/[...id].jsx index 6567d4cb..00e243d7 100644 --- a/src/pages/challenges/[...id].jsx +++ b/src/pages/challenges/[...id].jsx @@ -32,6 +32,8 @@ export default function Challenge() { // I hate this const [urlChallengeId, urlSelectedTab, urlWriteupId] = (router ?? {})?.query?.id ?? [undefined, undefined, undefined]; + const [fileIDName, setFileIDName] = useState(""); + const [fileIDLink, setFileIDLink] = useState(""); // Very primitive cache system const [cache, _setCache] = useState({}); @@ -129,6 +131,7 @@ export default function Challenge() { const [terminalUrl, setTerminalUrl] = useState(""); const [loadingMessage, setLoadingMessage] = useState('Connecting to terminal service...'); + const createTerminal = async (skipToCheckStatus) => { const challenge = cache.challenge; const cookie = getCookie('idToken'); @@ -144,6 +147,17 @@ export default function Challenge() { setPassword(data.terminalUserPassword); setUserName(data.terminalUserName); + if (data.fileIDs) { + + // CLEAN UP FILE IDS AS IT IS STRING AND CONVERT TO ARRAY + + + setFileIDName(data.fileIDs.split('#')[0]); + setFileIDLink(data.fileIDs.split('#')[1]); + } else { + setFileIDName("This challenge does not have any associated files."); + setFileIDLink("https://ctfguide.com"); + } setContainerId(data.containerId); setFoundTerminal(true); setMinutesRemaining(60); @@ -334,7 +348,13 @@ export default function Challenge() { {selectedWriteup ? ( setSelectedWriteup(null)} writeup={selectedWriteup} /> ) : ( - + )}
@@ -690,7 +710,7 @@ function HintsPage({ cache }) { } -function DescriptionPage({ cache }) { +function DescriptionPage({ cache, fileIDName, fileIDLink }) { const { challenge } = cache; const [challengeData, setChallengeData] = useState(null); const [authorPfp, setAuthorPfp] = useState(null); @@ -786,6 +806,25 @@ function DescriptionPage({ cache }) { {challenge ? : } + +
+

Associated Files

+ {fileIDName && fileIDLink ? ( + fileIDName !== "This challenge does not have any associated files." ? ( + + ) : ( +

{fileIDName}

+ ) + ) : ( +

You may need to boot the terminal to see the associated files.

+ )} + +
diff --git a/src/utils/terminal-api.js b/src/utils/terminal-api.js index 6800d406..30c08c21 100644 --- a/src/utils/terminal-api.js +++ b/src/utils/terminal-api.js @@ -58,18 +58,21 @@ const buildTerminal = async (challenge, token, type) => { while (!result.done) { let stat = textDecoder.decode(result.value); if(stat.toLowerCase() !== 'terminal created') { - console.log('Failed to create the terminal line 40'); + console.log('Failed to create the terminal line 60'); return [false, null]; } result = await reader.read(); } + + + console.log('Terminal created successfully!'); - return [true, code+""]; + return [true, code+"", fileIDs]; } catch (err) { console.log('Failed to create the terminal'); console.log(err); - return [false, null]; + return [false, null, null]; } };