Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit 4037e29

Browse files
committed
Regenerated yarn.lock
2 parents 5d191a6 + 8b8ecb8 commit 4037e29

33 files changed

+2502
-117
lines changed

.dockerignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# rDeploy files
2+
/.rdeploy
3+
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
/node_modules
9+
10+
/build
11+
/.env
12+
13+
.DS_Store
14+
Thumbs.db
15+
ehthumbs.db
16+
Desktop.ini
17+
$RECYCLE.BIN
18+
19+
*.swp
20+
21+
# nyc test runner
22+
/.nyc_output
23+
/coverage

.env.example

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
1-
RCTF_TOKEN_KEY=LMyfS/PlmrRQNVQMPPT1acfJf+XWh4JRPH6VX+9vNVY=
1+
# rCTF config
2+
RCTF_TOKEN_KEY=32_byte_long_base64_encoded_value_for_token
3+
RCTF_NAME=rCTF
4+
RCTF_ORIGIN=http://127.0.0.1
25
RCTF_DATABASE_URL=postgresql://user:[email protected]:5432/rctf
6+
RCTF_REDIS_URL=redis://:[email protected]:6379/0
7+
RCTF_SMTP_URL=smtp://user:[email protected]:587
8+
RCTF_EMAIL_FROM=[email protected]
9+
10+
# deployment config
11+
RCTF_RCTF_CPU_LIMIT=1
12+
RCTF_RCTF_MEM_LIMIT=500M
13+
RCTF_REDIS_CPU_LIMIT=1
14+
RCTF_REDIS_MEM_LIMIT=500M
15+
RCTF_POSTGRES_CPU_LIMIT=1
16+
RCTF_POSTGRES_MEM_LIMIT=500M

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# rDeploy files
2-
.rdeploy
2+
/.rdeploy
33

44
npm-debug.log*
55
yarn-debug.log*
@@ -19,5 +19,5 @@ $RECYCLE.BIN
1919
*.swp
2020

2121
# nyc test runner
22-
.nyc_output
23-
coverage
22+
/.nyc_output
23+
/coverage

Dockerfile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
FROM node:10
1+
FROM node:10-slim
22

3-
RUN mkdir /app
43
WORKDIR /app
54

6-
COPY package.json ./
7-
COPY yarn.lock ./
5+
ARG rctf_name
6+
ENV RCTF_NAME=${rctf_name}
87

9-
ENV NODE_ENV production
8+
COPY package.json yarn.lock ./
109
RUN yarn
11-
1210
COPY . .
11+
RUN yarn build && rm -r node_modules
12+
13+
ENV NODE_ENV production
14+
ENV PORT 8000
15+
RUN yarn
1316

14-
USER node
17+
EXPOSE 8000
1518

16-
CMD ["node", "index.js"]
19+
CMD ["node", "index.js"]

app.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
const path = require('path')
22
const express = require('express')
3-
const bodyParser = require('body-parser')
43

54
const app = express()
65

7-
app.use(bodyParser.json())
6+
app.use(express.raw({
7+
type: 'application/json'
8+
}))
89

9-
app.use('/api/v1', require(path.join(__dirname, '/server/api')))
10+
app.use('/api/v1', require('./server/api'))
1011

1112
const staticPath = path.join(__dirname, '/build')
1213
app.use(express.static(staticPath, { extensions: ['html'] }))

client/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
preact build client/src --service-worker false --prerender false --template client/index.html
22
rm -r build/ssr-build build/manifest.json build/polyfills* build/push-manifest.json build/sw.js build/assets/icon.png
3+
mv build/*.js* build/assets
34
cp -r static/* build

client/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8">
5-
<title>rCTF</title>
5+
<title><%= htmlWebpackPlugin.options.view.ctfName %></title>
66
<meta name="viewport" content="width=device-width,initial-scale=1">
77
<meta name="mobile-web-app-capable" content="yes">
88
<meta name="apple-mobile-web-app-capable" content="yes">
99
</head>
1010
<body>
11-
<script src="<%= htmlWebpackPlugin.files.chunks['bundle'].entry %>"></script>
11+
<script src="<%= htmlWebpackPlugin.options.view.assetsPrefix %><%= htmlWebpackPlugin.files.chunks['bundle'].entry %>"></script>
1212
</body>
1313
</html>

config/index.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
module.exports = {
22
rDeployDirectory: '.rdeploy',
3-
tokenKey: process.env.RCTF_TOKEN_KEY
3+
verifyEmail: true,
4+
tokenKey: process.env.RCTF_TOKEN_KEY,
5+
ctfName: process.env.RCTF_NAME,
6+
origin: process.env.RCTF_ORIGIN,
7+
databaseUrl: process.env.RCTF_DATABASE_URL,
8+
redisUrl: process.env.RCTF_REDIS_URL,
9+
smtpUrl: process.env.RCTF_SMTP_URL,
10+
emailFrom: process.env.RCTF_EMAIL_FROM,
11+
divisions: {
12+
eligible: 0,
13+
ineligible: 1
14+
},
15+
loginTimeout: 10 * 60 * 1000
416
}

docker-compose.yml

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,45 @@
1-
version: "3"
1+
version: '2.2'
22
services:
3-
example:
4-
build: .
5-
ports:
6-
- 3000:8000
7-
environment:
8-
- PORT=8000
9-
expose:
10-
- 8000
3+
rctf:
4+
user: 999:999
5+
build:
6+
context: .
7+
args:
8+
rctf_name: ${RCTF_NAME}
119
restart: always
10+
ports:
11+
- '127.0.0.1:8000:8000'
12+
networks:
13+
- rctf
14+
env_file:
15+
- .env
16+
volumes:
17+
- /var/data/rctf-rdeploy:/app/.rdeploy
18+
depends_on:
19+
- redis
20+
- postgres
21+
cpus: ${RCTF_RCTF_CPU_LIMIT}
22+
mem_limit: ${RCTF_RCTF_MEM_LIMIT}
23+
redis:
24+
user: 999:999
25+
image: redis:5.0.7
26+
restart: always
27+
networks:
28+
- rctf
29+
volumes:
30+
- /var/data/rctf-redis:/data
31+
cpus: ${RCTF_REDIS_CPU_LIMIT}
32+
mem_limit: ${RCTF_REDIS_MEM_LIMIT}
33+
postgres:
34+
user: '999:999'
35+
image: postgres:9.6.17
36+
restart: always
37+
networks:
38+
- rctf
39+
volumes:
40+
- /var/data/rctf-postgres:/var/lib/postgresql/data
41+
cpus: ${RCTF_POSTGRES_CPU_LIMIT}
42+
mem_limit: ${RCTF_POSTGRES_MEM_LIMIT}
43+
44+
networks:
45+
rctf: {}

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
require('dotenv').config()
1+
try {
2+
require('dotenv').config()
3+
} catch (e) {}
24

35
const app = require('./app')
46

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
exports.up = function (pgm) {
2+
pgm.dropColumns('users', ['password'])
3+
}
4+
5+
exports.down = function (pgm) {
6+
pgm.addColumns('users', {
7+
password: { type: 'string', notNull: true }
8+
})
9+
}

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
"build": "sh client/build.sh",
1212
"watch": "preact watch --src client/src --template client/index.html",
1313
"dev": "nodemon index.js",
14-
"test": "nyc ava"
14+
"test": "nyc ava",
15+
"client:build": "sh client/build.sh",
16+
"client:watch": "preact watch --src client/src --template client/index.html"
1517
},
1618
"husky": {
1719
"hooks": {
@@ -20,16 +22,19 @@
2022
},
2123
"dependencies": {
2224
"ajv": "^6.11.0",
23-
"body-parser": "^1.19.0",
24-
"dotenv": "^8.2.0",
25+
"email-validator": "^2.0.4",
2526
"express": "^4.17.1",
27+
"mustache": "^4.0.0",
2628
"node-pg-migrate": "^4.2.2",
29+
"nodemailer": "^6.4.2",
2730
"pg": "^7.18.1",
31+
"redis": "^3.0.2",
2832
"supertest": "^4.0.2",
2933
"uuid": "^3.4.0"
3034
},
3135
"devDependencies": {
3236
"ava": "^3.3.0",
37+
"dotenv": "^8.2.0",
3338
"husky": "^4.2.1",
3439
"jss": "^10.0.4",
3540
"jss-camel-case": "^6.1.0",

preact.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require('dotenv').config()
2+
const config = require('./config')
3+
4+
export default (webpackConfig, env, helpers) => {
5+
if (env.ssr) {
6+
return
7+
}
8+
const { plugin } = helpers.getPluginsByName(webpackConfig, 'HtmlWebpackPlugin')[0]
9+
plugin.options.view = {
10+
assetsPrefix: env.production ? '/assets' : '',
11+
ctfName: config.ctfName
12+
}
13+
}

server/api/auth-login.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
1+
const database = require('../database')
2+
const auth = require('../auth')
13
const { responses } = require('../responses')
24

35
module.exports = {
46
method: 'post',
57
path: '/auth/login',
6-
requireAuth: true,
8+
requireAuth: false,
79
schema: {
810
body: {
911
type: 'object',
1012
properties: {
11-
email: {
12-
type: 'string'
13-
},
14-
password: {
13+
teamToken: {
1514
type: 'string'
1615
}
1716
},
18-
required: ['email', 'password']
17+
required: ['teamToken']
1918
}
2019
},
21-
handler: async ({ req, uuid }) => {
20+
handler: async ({ req }) => {
21+
const uuid = await auth.token.getData(auth.token.tokenKinds.team, req.body.teamToken)
22+
if (uuid === null) {
23+
return responses.badToken
24+
}
25+
const user = await database.auth.getUserById({ id: uuid })
26+
if (user === undefined) {
27+
return responses.badUnknownUser
28+
}
29+
const authToken = await auth.token.getToken(auth.token.tokenKinds.auth, uuid)
2230
return [responses.goodLogin, {
23-
uuid
31+
authToken
2432
}]
2533
}
2634
}

server/api/auth-submit.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
const uuidv4 = require('uuid/v4')
2+
const emailValidator = require('email-validator')
3+
const cache = require('../cache')
4+
const database = require('../database')
5+
const util = require('../util')
6+
const auth = require('../auth')
7+
const verifyEndpoint = require('./auth-verify')
8+
const config = require('../../config')
9+
const { responses } = require('../responses')
10+
11+
module.exports = {
12+
method: 'post',
13+
path: '/auth/submit',
14+
requireAuth: false,
15+
schema: {
16+
body: {
17+
type: 'object',
18+
properties: {
19+
email: {
20+
type: 'string'
21+
},
22+
name: {
23+
type: 'string'
24+
},
25+
division: {
26+
type: 'number',
27+
enum: Object.values(config.divisions)
28+
},
29+
register: {
30+
type: 'boolean'
31+
}
32+
},
33+
required: ['email', 'name', 'division', 'register']
34+
}
35+
},
36+
handler: async ({ req }) => {
37+
const email = req.body.email.trim().toLowerCase()
38+
if (!emailValidator.validate(email)) {
39+
return responses.badEmail
40+
}
41+
const user = await database.auth.getUserByEmail({ email })
42+
if (user === undefined && !req.body.register) {
43+
return responses.badUnknownEmail
44+
}
45+
if (user !== undefined && req.body.register) {
46+
return responses.badKnownEmail
47+
}
48+
const uuid = uuidv4()
49+
await cache.login.makeLogin({ id: uuid })
50+
const verifyToken = await auth.token.getToken(auth.token.tokenKinds.verify, {
51+
id: uuid,
52+
email,
53+
name: req.body.name,
54+
division: req.body.division,
55+
register: req.body.register
56+
})
57+
58+
if (config.verifyEmail) {
59+
await util.email.sendVerification({
60+
email,
61+
token: verifyToken
62+
})
63+
return responses.goodVerifySent
64+
} else {
65+
// Pretend user sent token to verify endpoint
66+
return verifyEndpoint.handleToken(verifyToken)
67+
}
68+
}
69+
}

server/api/auth-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const { responses } = require('../responses')
2+
3+
module.exports = {
4+
method: 'get',
5+
path: '/auth/test',
6+
requireAuth: true,
7+
handler: async () => {
8+
return responses.validToken
9+
}
10+
}

0 commit comments

Comments
 (0)