Skip to content

Commit aa280d9

Browse files
committed
0.8.1
- Disable registration function - Added strikethrough, tables support to markdown - Fixed some bugs
1 parent 4755e0b commit aa280d9

16 files changed

+174
-123
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ Feel free to take a look at the screenshots below for a peek at what the platfor
1212
- **Announcements** with markdown support
1313
- **Markdown supported Challenge Descriptions** that allow you to add **code blocks with syntax highlighting, math** and more
1414
- **Writeup links** per challenge (along with the option to only release writeups after submitting the flag)
15+
- **Challenge Creator Role** so as to allow challenge authors to submit challenges without having full admin access
1516
- Links to each challenge so that individual challenges can be shared
1617
- Easy management of challenges and users
17-
- ReactJS Modern Design (lol)
18+
- Disable registration, change permissions etc.
19+
- Juicy React-Spring transitions
1820

1921
## Screenshots
2022

api/api.js

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ console.info('Initialization complete');
8989
MongoDB.MongoClient.connect('mongodb://localhost:27017', {
9090
useNewUrlParser: true,
9191
useUnifiedTopology: true
92-
}).then(client => {
92+
}).then(async (client) => {
9393
const db = client.db('ctf');
9494
const collections = {
9595
users: db.collection('users'),
@@ -101,6 +101,20 @@ MongoDB.MongoClient.connect('mongodb://localhost:27017', {
101101
};
102102
console.info('MongoDB connected');
103103

104+
createCache = async () => {
105+
try {
106+
await collections.cache.insertOne({ announcements: 0, challenges: 0, registerDisable: false });
107+
console.info("Cache created")
108+
}
109+
catch (err) {
110+
errors(err);
111+
}
112+
113+
}
114+
115+
let cache = await collections.cache.findOne(null, { projection: { _id: 0 } })
116+
if (cache === null) await createCache()
117+
104118
async function checkPermissions(username) {
105119
if (permissions.includes(username)) return permissions.username;
106120
const type = (await collections.users.findOne({ username: username }, { projection: { type: 1, _id: 0 } }));
@@ -111,14 +125,55 @@ MongoDB.MongoClient.connect('mongodb://localhost:27017', {
111125
}
112126
}
113127

114-
createCache = async () => {
115-
await collections.cache.insertOne({ announcements: 0, challenges: 0 })
116-
console.log('Cache created')
117-
return 0;
118-
}
128+
app.get('/v1/account/disableCreate', async (req, res) => {
129+
try {
130+
if (req.headers.authorization == undefined) throw new Error('MissingToken');
131+
const username = signer.unsign(req.headers.authorization);
132+
if (await checkPermissions(username) < 2) throw new Error('Permissions');
133+
res.send({
134+
success: true,
135+
state: (await collections.cache.findOne(null, { projection: { _id: 0, registerDisable: 1 } })).registerDisable
136+
});
137+
}
138+
catch (err) {
139+
errors(err, res);
140+
}
141+
});
142+
143+
144+
app.post('/v1/account/disableCreate', async (req, res) => {
145+
try {
146+
if (req.headers.authorization == undefined) throw new Error('MissingToken');
147+
const username = signer.unsign(req.headers.authorization);
148+
if (await checkPermissions(username) < 2) throw new Error('Permissions');
149+
if ((await collections.cache.updateOne({}, { "$set": { registerDisable: req.body.disable } })).matchedCount > 0) {
150+
res.send({
151+
success: true
152+
});
153+
}
154+
else {
155+
throw new Error('Unknown');
156+
}
157+
158+
}
159+
catch (err) {
160+
errors(err, res);
161+
}
162+
});
119163

120164
app.post('/v1/account/create', async (req, res) => {
165+
166+
let admin = false
121167
try {
168+
169+
if (req.headers.authorization !== undefined) {
170+
const username = signer.unsign(req.headers.authorization);
171+
if (await checkPermissions(username) >= 2) admin = true
172+
}
173+
if (!admin && ((await collections.cache.findOne(null, { projection: { _id: 0, registerDisable: 1 } })).registerDisable)) {
174+
return res.send({ success: false, error: 'registration-disabled' })
175+
}
176+
122177
if (!/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(req.body.email)) throw new Error('BadEmail');
123178
await collections.users.insertOne({
124179
username: req.body.username.toLowerCase(),
@@ -349,7 +404,7 @@ MongoDB.MongoClient.connect('mongodb://localhost:27017', {
349404
const permissions = await checkPermissions(username);
350405
if (permissions === false) throw new Error('BadToken');
351406

352-
let announcement = await collections.announcements.findOne({_id: MongoDB.ObjectID(req.params.id)}, { projection: { _id: 0} })
407+
let announcement = await collections.announcements.findOne({ _id: MongoDB.ObjectID(req.params.id) }, { projection: { _id: 0 } })
353408
if (announcement !== null) {
354409
res.send({
355410
success: true,
@@ -1043,7 +1098,7 @@ MongoDB.MongoClient.connect('mongodb://localhost:27017', {
10431098
if (await checkPermissions(signer.unsign(req.headers.authorization)) === false) throw new Error('BadToken');
10441099
const score = (await collections.users.findOne({ username: req.params.username }, { projection: { score: 1, type: 1, _id: 0 } }));
10451100
if (score === null) throw new Error('NotFound');
1046-
if (score.type === 2) return res.send({success: true, score: "hidden" })
1101+
if (score.type === 2) return res.send({ success: true, score: "hidden" })
10471102
res.send({
10481103
success: true,
10491104
score: score.score

client/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ This project was bootstrapped with [Create React App](https://github.com/faceboo
44

55
In the project directory, you can run:
66

7-
### `yarn start`
7+
### `npm start`
88

99
Runs the app in the development mode.<br />
1010
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
1111

1212
The page will reload if you make edits.<br />
1313
You will also see any lint errors in the console.
1414

15-
### `yarn test`
15+
### `npm test`
1616

1717
Launches the test runner in the interactive watch mode.<br />
1818
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
1919

20-
### `yarn build`
20+
### `npm build`
2121

2222
Builds the app for production to the `build` folder.<br />
2323
It correctly bundles React in production mode and optimizes the build for the best performance.
@@ -27,7 +27,7 @@ Your app is ready to be deployed!
2727

2828
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
2929

30-
### `yarn eject`
30+
### `npm eject`
3131

3232
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
3333

@@ -65,4 +65,4 @@ This section has moved here: https://facebook.github.io/create-react-app/docs/de
6565

6666
### `yarn build` fails to minify
6767

68-
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
68+
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify

client/package-lock.json

Lines changed: 0 additions & 83 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"react": "^17.0.1",
1414
"react-dimensions": "^1.3.1",
1515
"react-dom": "^17.0.1",
16-
"react-jsx-parser": "^1.28.1",
1716
"react-markdown": "^6.0.2",
1817
"react-mathjax": "^1.0.1",
1918
"react-router": "^5.2.0",

client/src/App.css

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44
}
55

66
.buttonHover:hover {
7-
background-color: #15395b
7+
background-color: #15395b;
88
}
99

1010
.ant-layout-sider {
1111
width: "10vw"!important;
12-
min-width: "5vw"!important
12+
min-width: "5vw"!important;
13+
}
14+
15+
.challengeModal ul {
16+
display: inline-block;
17+
text-align: left;
1318
}
1419

1520
@keyframes slideInFromLeft {

client/src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class App extends React.Component {
264264

265265
</Menu>
266266
<div style={{ textAlign: "center", marginTop: "3ch", color: "#8c8c8c" }}>
267-
<p>Sieberrsec CTF Platform 0.8 <a href="https://github.com/IRS-Cybersec/ctf_platform" target="_blank">Contribute <GithubOutlined /></a></p>
267+
<p>Sieberrsec CTF Platform 0.8.1 <a href="https://github.com/IRS-Cybersec/ctf_platform" target="_blank">Contribute <GithubOutlined /></a></p>
268268
</div>
269269
</Sider>
270270

client/src/App.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/src/MarkdownRenderer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import rehypeRaw from 'rehype-raw';
55
import 'katex/dist/katex.min.css';
66
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
77
import { atomDark } from 'react-syntax-highlighter/dist/esm/styles/prism';
8+
import gfm from 'remark-gfm';
9+
810

911
function MarkdownRender(props) {
1012
const components = {
@@ -21,7 +23,7 @@ function MarkdownRender(props) {
2123
//rehypeRaw is to render HTML to support older challenge descriptions which were written in JSX
2224
//should be removed in the future
2325
return (
24-
<ReactMarkdown remarkPlugins={[remarkMath]} rehypePlugins={[rehypeKatex, rehypeRaw]} components={components} children={props.children} />
26+
<ReactMarkdown remarkPlugins={[remarkMath, gfm]} rehypePlugins={[rehypeKatex, rehypeRaw]} components={components} children={props.children} />
2527
);
2628
}
2729

client/src/adminChallengeCreate.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ const CreateChallengeForm = (props) => {
172172
type="inner"
173173
bordered={true}
174174
bodyStyle={{ backgroundColor: "#262626", textAlign: "center" }}
175+
className="challengeModal"
175176
>
176177
<MarkdownRender>{editorValue}</MarkdownRender>
177178
</Card>
@@ -505,6 +506,7 @@ class AdminChallengeCreate extends React.Component {
505506
visible={this.state.previewModal}
506507
footer={null}
507508
bodyStyle={{ textAlign: "center" }}
509+
className="challengeModal"
508510
onCancel={() => { this.setState({ previewModal: false }) }}
509511
>
510512
<Tabs defaultActiveKey="challenge">

0 commit comments

Comments
 (0)