diff --git a/.gitignore b/.gitignore index ad22606..0d00df9 100644 --- a/.gitignore +++ b/.gitignore @@ -174,4 +174,5 @@ dist # Finder (MacOS) folder config .DS_Store -build \ No newline at end of file +build +dockerapi.d.ts \ No newline at end of file diff --git a/LICENSE b/LICENSE index 4621ad2..e39cbb9 100644 --- a/LICENSE +++ b/LICENSE @@ -25,6 +25,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. EXCEPTIONS: ANY ORGANIZATION REPRESENTING 42 (Central) IS NOT ALLOWED TO USE THIS -UNLESS EXPLICIT PERMISSION IS GIVEN! ANY CODE COPIED, USED, ... FROM BEFORE OR AFTER THIS LICENSE WILL BE MET WITH A LEGAL RESPONSE! - -HOWEVER THE ENTITY KNOWN AS CODAM CODING COLLEGE IS ALLOWED TO USE THIS SOFTWARE. \ No newline at end of file +UNLESS EXPLICIT PERMISSION IS GIVEN! ANY CODE COPIED, USED, ... FROM BEFORE OR AFTER THIS LICENSE +WITH THE EXCEPTIONS OF CODAM CODING COLLEGE AND ACTIVE STUDENTS (NONE STAFF) OF THE 42 NETWORK. +INVIDIVUAL 42 CAMPUSES WITH THE EXCEPTION OF PARIS ARE ALLOWED TO USE THIS SOFTWARE \ No newline at end of file diff --git a/README.md b/README.md index ac49e3b..21d980d 100644 --- a/README.md +++ b/README.md @@ -73,11 +73,13 @@ curl -XPOST -H "Content-type: application/json" -d '{ "branch": "master", "commit": "67dc80a" } -}' 'http://localhost:3001/evaluate/git/libc' +}' 'http://localhost:3001/evaluate/git/lib' ``` ```bash # For single files +# Note: This example will not work as the code is invalid +# Fork bombs won't work on the server curl -XPOST -H "Content-type: application/json" -d '{ "data": { "args": [], diff --git a/bun.lockb b/bun.lockb index 5d7c51d..d8e651c 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/docker/git/Dockerfile b/docker/git/Dockerfile index 34ef22b..4c5d316 100644 --- a/docker/git/Dockerfile +++ b/docker/git/Dockerfile @@ -22,8 +22,8 @@ RUN apt-get update && apt-get install -y \ COPY start.sh /usr/local/bin/init.sh RUN chmod 755 /usr/local/bin/init.sh -RUN addgroup --gid 1337 nxtdmy -RUN adduser --shell /bin/bash runner && adduser runner nxtdmy +#RUN addgroup --gid 1337 nxtdmy +#RUN adduser --shell /bin/bash runner && adduser runner nxtdmy -USER runner +USER bun ENTRYPOINT [ "init.sh" ] \ No newline at end of file diff --git a/docker/single/Dockerfile b/docker/single/Dockerfile index 3d8db8f..b6e254a 100644 --- a/docker/single/Dockerfile +++ b/docker/single/Dockerfile @@ -15,8 +15,10 @@ RUN apt-get update && apt-get install -y \ build-essential \ && rm -rf /var/lib/apt/lists/* -RUN useradd runner --shell /bin/bash --create-home -COPY start.sh . -COPY entry.sh /usr/local/bin/entry.sh -ENTRYPOINT [ "entry.sh" ] \ No newline at end of file +COPY ./start.sh . +COPY ./entry.sh /usr/local/bin/entry.sh +RUN chmod +x /usr/local/bin/entry.sh + +#USER bun +ENTRYPOINT [ "/usr/local/bin/entry.sh" ] \ No newline at end of file diff --git a/docker/single/start.sh b/docker/single/start.sh index 89a502e..461e709 100644 --- a/docker/single/start.sh +++ b/docker/single/start.sh @@ -5,7 +5,7 @@ set -e ID=$(xxd -l 16 -ps /dev/urandom | tr -d " \n") Dir="/tmp/$ID" File="$dir/user.c" -Home="/home/runner/" +Home="/home/bun/" # Build #============================================================================== @@ -24,4 +24,4 @@ IFS=';' read -ra ARGS <<< "$CODE_ARGS" #============================================================================== echo "[+] Running file..." -su - runner -s /bin/bash -c "pwd; ls -l; ./a.out ${ARGS[@]}" \ No newline at end of file +su - bun -s /bin/bash -c "pwd; ls -l; ./a.out ${ARGS[@]}" \ No newline at end of file diff --git a/projects/balls/start.sh b/projects/balls/start.sh index d13629b..4e6f296 100644 --- a/projects/balls/start.sh +++ b/projects/balls/start.sh @@ -4,7 +4,7 @@ ID=$(xxd -l 16 -ps /dev/urandom | tr -d " \n") ProjectDIR="/tmp/$ID/project" ObjectsDIR="/tmp/$ID/objects" -Home="/home/runner/" +Home="/home/bun/" # Functions #============================================================================== diff --git a/src/router.ts b/src/router.ts index 1a72292..67e1dc2 100644 --- a/src/router.ts +++ b/src/router.ts @@ -3,21 +3,26 @@ // See README in the root of the project for license details. // ============================================================================ -import Container from './docker/container' -import Git from './git' -import { AutoRouter, json, type IRequest, type ResponseHandler, error, status, StatusError } from 'itty-router' -import type { FileBody, GitBody } from './types' -import { $ } from 'bun' -import Single from './single' +import Git from "./git"; +import { + AutoRouter, + json, + type IRequest, + type ResponseHandler, + error, + StatusError, +} from "itty-router"; +import type { FileBody, GitBody } from "./types"; +import Single from "./single"; // Middleware // ============================================================================ const withHeaders: ResponseHandler = (response: IRequest) => { - response.headers.set('X-Server', Bun.env.SERVER ?? 'robopeer') - response.headers.set('X-Powered-By', 'itty-router') - response.headers.set('X-Runtime', `Bun ${Bun.version}`) -} + response.headers.set("X-Server", Bun.env.SERVER ?? "robopeer"); + response.headers.set("X-Powered-By", "itty-router"); + response.headers.set("X-Runtime", `Bun ${Bun.version}`); +}; // ============================================================================ @@ -26,27 +31,35 @@ const router = AutoRouter({ finally: [withHeaders], format: json, catch: error, -}) +}); -router.post('/evaluate/git/:project', async (req) => { - let body: GitBody = await req.json() - .catch(() => { throw new StatusError(400, 'Invalid JSON body.') }) +router.post("/evaluate/git/:project", async (req) => { + let body: GitBody = await req + .json() + .catch(() => { + throw new StatusError(400, "Invalid JSON body."); + }) .then((data) => data); if (!body.data.branch || !body.data.commit || !body.data.repo) { - throw new StatusError(400, 'Invalid JSON body.') + throw new StatusError(400, "Invalid JSON body."); } - if (!await Bun.file(`./projects/${req.params.project}/index.test.ts`).exists()) { - throw new StatusError(404, 'Project not found.') + if ( + !(await Bun.file(`./projects/${req.params.project}/index.test.ts`).exists()) + ) { + throw new StatusError(404, "Project not found."); } - return await Git.run(req.params.project, body) -}) + return await Git.run(req.params.project, body); +}); -router.post('/evaluate/code', async (req) => { - let body: FileBody = await req.json() - .catch(() => { throw new StatusError(400, 'Invalid JSON body.') }) +router.post("/evaluate/code", async (req) => { + let body: FileBody = await req + .json() + .catch(() => { + throw new StatusError(400, "Invalid JSON body."); + }) .then((data) => data); if ( @@ -55,14 +68,14 @@ router.post('/evaluate/code', async (req) => { !body.data.flags || !body.data.lang ) { - throw new StatusError(400, 'Invalid JSON body.') + throw new StatusError(400, "Invalid JSON body."); } - return await Single.run(body) -}) + return await Single.run(body); +}); -console.log(`Running: https://localhost:${Bun.env.PORT ?? 8080}`); +console.log(`Running: http://localhost:${Bun.env.PORT ?? 8080}`); // ============================================================================ -export default router +export default router;