Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
347da4c
update git ignore
Nov 30, 2021
745b553
remove graphql.schema.json from git (dev dep)
Nov 30, 2021
a57d749
Added ical link
Nov 30, 2021
03065b4
change random to gen_random_bytes
Nov 30, 2021
b97d1f6
Merge branch 'ical-link' of https://github.com/TFNS/CTFNote into upst…
frereit Feb 7, 2022
9eaa2f7
Update number of ical link migration
frereit Feb 7, 2022
950e01f
Fix outdated wrapNotify call
frereit Feb 7, 2022
58f2de2
Add back graphql schema.
frereit Feb 7, 2022
5280b8c
Add iCal Link
frereit Feb 7, 2022
6ecb4fc
Add option to disable iCal password
frereit Feb 7, 2022
1e40eff
eslint fixes
frereit Feb 7, 2022
9799e0f
Add missing dependencies
frereit Feb 8, 2022
123fcdd
Change pool to use getDbUrl
frereit Feb 8, 2022
63f174f
Minor fixes
frereit Feb 14, 2022
a6cd463
Fix crash when host is invalid.
frereit Apr 5, 2022
55c35c0
Add /ctf/:ctfId route as an alias
frereit Apr 8, 2022
b2249c1
Make calendar links by id-only.
frereit Apr 8, 2022
373e473
Merge branch 'dev' of github.com:TFNS/CTFNote into upstream-ical-link
frereit Apr 8, 2022
f1e09b6
Make taskSlug optional
frereit Apr 8, 2022
fe82564
Fix pagination of past CTF table
JJ-8 Mar 3, 2023
6ac72ae
Sort past CTFs when added to the list
JJ-8 Mar 3, 2023
804f4af
Add ML category to HTB parser
JJ-8 Mar 24, 2023
8103d41
Upgrade api packages to latest versions
JJ-8 Mar 24, 2023
ae2f512
Upgrade packages of frontend to latest versions
JJ-8 Mar 24, 2023
6749ff7
Fix typo in CSS scoped tag
JJ-8 Mar 24, 2023
c36bb48
Fix return typing issue
JJ-8 Mar 24, 2023
cec5ee2
Merge branch 'new-htb-category'
JJ-8 Mar 24, 2023
e2a49cb
Merge branch '0-fix-past-ctf-table'
JJ-8 Mar 24, 2023
2a2b816
Merge branch 'main' into 0-upstream-ical-link-fix
JJ-8 May 5, 2023
b6ad6bb
Remove wrong dark color of ical popup
JJ-8 May 5, 2023
e85de24
Make ical password hidden by default
JJ-8 May 5, 2023
e4b4abb
Replace CTF link in ical with actual CTF URL
JJ-8 May 5, 2023
11ff3aa
Change click action of link to copy to clipboard
JJ-8 May 5, 2023
952acb4
Change ical migration ID to 43
JJ-8 May 5, 2023
05ba570
Merge remote-tracking branch 'upstream/main' into 0-upstream-ical-lin…
JJ-8 May 9, 2023
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: 5 additions & 0 deletions api/migrations/43-ical-link.sql
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;

1 change: 1 addition & 0 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"graphile-utils": "^4.13.0",
"graphql": "^16.6.0",
"graphql-upload-ts": "^2.0.5",
"ical-generator": "^3.2.1",
"postgraphile": "^4.13.0",
"postgraphile-plugin-connection-filter": "^2.3.0",
"postgres-migrations": "^5.3.0"
Expand Down
9 changes: 8 additions & 1 deletion api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import createTasKPlugin from "./plugins/createTask";
import importCtfPlugin from "./plugins/importCtf";
import uploadLogoPlugin from "./plugins/uploadLogo";
import uploadScalar from "./plugins/uploadScalar";
import { Pool } from "pg";
import { icalRoute } from "./routes/ical";
import ConnectionFilterPlugin from "postgraphile-plugin-connection-filter";

function getDbUrl(role: "user" | "admin") {
Expand Down Expand Up @@ -75,6 +77,10 @@ function createOptions() {
}

function createApp(postgraphileOptions: PostGraphileOptions) {
const pool = new Pool({
connectionString: getDbUrl("user"),
});

const app = express();
app.use(graphqlUploadExpress());
app.use(
Expand All @@ -85,7 +91,8 @@ function createApp(postgraphileOptions: PostGraphileOptions) {
},
})
);
app.use(postgraphile(getDbUrl("user"), "ctfnote", postgraphileOptions));
app.use(postgraphile(pool, "ctfnote", postgraphileOptions));
app.use("/calendar.ics", icalRoute(pool));
return app;
}

Expand Down
66 changes: 66 additions & 0 deletions api/src/routes/ical.ts
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);
};
}
Loading