Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/pages/assignments/student/[code].jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/pages/assignments/teacher/[code].jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
43 changes: 41 additions & 2 deletions src/pages/challenges/[...id].jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({});
Expand Down Expand Up @@ -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');
Expand All @@ -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);
Expand Down Expand Up @@ -334,7 +348,13 @@ export default function Challenge() {
{selectedWriteup ? (
<WriteupModal isOpen={true} onClose={() => setSelectedWriteup(null)} writeup={selectedWriteup} />
) : (
<selectedTab.element cache={cache} setCache={setCache} onWriteupSelect={handleWriteupSelect} />
<selectedTab.element
cache={cache}
setCache={setCache}
onWriteupSelect={handleWriteupSelect}
fileIDName={fileIDName} // Pass fileIDName as prop
fileIDLink={fileIDLink} // Pass fileIDLink as prop
/>
)}
<div className='flex w-full h-full grow basis-0'></div>
<div className="shrink-0 bg-neutral-800 h-12 w-full">
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -786,6 +806,25 @@ function DescriptionPage({ cache }) {

<ReactMarkdown></ReactMarkdown>
{challenge ? <MarkdownViewer content={challenge.content}></MarkdownViewer> : <Skeleton baseColor="#333" highlightColor="#666" count={8} />}

<hr className="border-neutral-700 mt-4"></hr>
<h1 className="text-xl font-semibold mt-4">Associated Files</h1>
{fileIDName && fileIDLink ? (
fileIDName !== "This challenge does not have any associated files." ? (
<div className="mt-1 bg-neutral-700/50 hover:bg-neutral-700/90 duration-100 hover:cursor-pointer px-5 py-2 w-full text-white flex mx-auto items-center ">
<i className="fas fa-file-alt text-blue-500 mr-2 "></i>
<a href={fileIDLink} className="text-blue-500" target="_blank" rel="noopener noreferrer">
{fileIDName}
</a>
</div>
) : (
<p>{fileIDName}</p>
)
) : (
<p>You may need to boot the terminal to see the associated files.</p>
)}


</div >
<div className="shrink-0 bg-neutral-800 h-10 w-full"></div>
</>
Expand Down
9 changes: 6 additions & 3 deletions src/utils/terminal-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
};

Expand Down