forked from TFNS/CTFNote
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 0-last-active-downstream
- Loading branch information
Showing
33 changed files
with
3,523 additions
and
3,676 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: "Build and publish Docker images to GHCR" | ||
|
||
on: | ||
workflow_call: | ||
push: | ||
branches: | ||
- "main" | ||
|
||
jobs: | ||
build_and_publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v2 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ github.token }} | ||
- name: PrepareReg Names | ||
run: | | ||
echo IMAGE_REPOSITORY=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV | ||
echo IMAGE_TAG=$(echo ${{ github.ref }} | tr '[:upper:]' '[:lower:]' | awk '{split($0,a,"/"); print a[3]}') >> $GITHUB_ENV | ||
- name: Build and push | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: ./front | ||
push: true | ||
tags: ghcr.io/${{env.IMAGE_REPOSITORY}}/front:latest | ||
- name: Build and push | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: ./api | ||
push: true | ||
tags: ghcr.io/${{env.IMAGE_REPOSITORY}}/api:latest | ||
- name: Build and push | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: ./db | ||
push: true | ||
tags: ghcr.io/${{env.IMAGE_REPOSITORY}}/db:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ALTER TABLE ctfnote.settings | ||
ADD COLUMN "ical_password" TEXT DEFAULT encode(gen_random_bytes(16), 'hex'); | ||
|
||
GRANT SELECT ("ical_password") ON ctfnote.settings TO user_guest; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE ctfnote.ctf ADD CONSTRAINT no_illegal_end_time CHECK (end_time >= start_time); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { ICalCalendar } from "ical-generator"; | ||
import { Request, Response, Handler } from "express"; | ||
import { Pool } from "pg"; | ||
|
||
type CtfRow = { | ||
id: number; | ||
title: string; | ||
start_time: string; | ||
end_time: string; | ||
ctf_url: string; | ||
description: string; | ||
}; | ||
|
||
type IcalPasswordRow = { | ||
ical_password: string; | ||
}; | ||
|
||
export function icalRoute(pool: Pool): Handler { | ||
async function checkIcalPassword( | ||
userPass: string | undefined | ||
): Promise<boolean> { | ||
const r = await pool.query<IcalPasswordRow>( | ||
"SELECT ical_password FROM ctfnote.settings" | ||
); | ||
const db_password = r.rows[0].ical_password; | ||
// If the password is null or empty allow any user | ||
if (!db_password) return true; | ||
return db_password === userPass; | ||
} | ||
|
||
async function getCtfs(): Promise<CtfRow[]> { | ||
const r = await pool.query<CtfRow>( | ||
"SELECT id, title, start_time, end_time, ctf_url, description FROM ctfnote.ctf" | ||
); | ||
|
||
return r.rows; | ||
} | ||
|
||
return async function (req: Request, res: Response): Promise<void> { | ||
const { key } = req.query; | ||
|
||
if ( | ||
!(typeof key == "string" || key == undefined) || | ||
!(await checkIcalPassword(key)) | ||
) { | ||
res.status(403); | ||
res.send("Forbidden\n"); | ||
return; | ||
} | ||
|
||
const cal = new ICalCalendar(); | ||
const ctfs = await getCtfs(); | ||
|
||
for (const ctf of ctfs) { | ||
cal.createEvent({ | ||
start: ctf.start_time, | ||
end: ctf.end_time, | ||
description: ctf.description, | ||
summary: ctf.title, | ||
url: ctf.ctf_url, | ||
}); | ||
} | ||
|
||
cal.serve(res); | ||
}; | ||
} |
Oops, something went wrong.