aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2018-05-22 19:43:13 +0200
committerRigel Kent <par@rigelk.eu>2018-05-22 19:44:34 +0200
commitff2c1fe8133f9556f6aaa52058cd8b83c40085e6 (patch)
treebc92cde25bf5a1d74b1413d7145179ef7abfd670 /server/controllers
parente2f1dad83607aa610ee33b234a81b07664f4304c (diff)
downloadPeerTube-ff2c1fe8133f9556f6aaa52058cd8b83c40085e6.tar.gz
PeerTube-ff2c1fe8133f9556f6aaa52058cd8b83c40085e6.tar.zst
PeerTube-ff2c1fe8133f9556f6aaa52058cd8b83c40085e6.zip
feature: IP filtering on signup page
disable registration form on IP not in range checking the CIDR list before filtering with it placing the cidr filters as an attribute object in the config
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/api/config.ts6
-rw-r--r--server/controllers/api/users.ts2
2 files changed, 6 insertions, 2 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts
index 12074a80e..f678e3c4a 100644
--- a/server/controllers/api/config.ts
+++ b/server/controllers/api/config.ts
@@ -4,7 +4,7 @@ import { ServerConfig, UserRight } from '../../../shared'
4import { About } from '../../../shared/models/server/about.model' 4import { About } from '../../../shared/models/server/about.model'
5import { CustomConfig } from '../../../shared/models/server/custom-config.model' 5import { CustomConfig } from '../../../shared/models/server/custom-config.model'
6import { unlinkPromise, writeFilePromise } from '../../helpers/core-utils' 6import { unlinkPromise, writeFilePromise } from '../../helpers/core-utils'
7import { isSignupAllowed } from '../../helpers/utils' 7import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/utils'
8import { CONFIG, CONSTRAINTS_FIELDS, reloadConfig } from '../../initializers' 8import { CONFIG, CONSTRAINTS_FIELDS, reloadConfig } from '../../initializers'
9import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' 9import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares'
10import { customConfigUpdateValidator } from '../../middlewares/validators/config' 10import { customConfigUpdateValidator } from '../../middlewares/validators/config'
@@ -36,6 +36,7 @@ configRouter.delete('/custom',
36 36
37async function getConfig (req: express.Request, res: express.Response, next: express.NextFunction) { 37async function getConfig (req: express.Request, res: express.Response, next: express.NextFunction) {
38 const allowed = await isSignupAllowed() 38 const allowed = await isSignupAllowed()
39 const allowedForCurrentIP = isSignupAllowedForCurrentIP(req.ip)
39 40
40 const enabledResolutions = Object.keys(CONFIG.TRANSCODING.RESOLUTIONS) 41 const enabledResolutions = Object.keys(CONFIG.TRANSCODING.RESOLUTIONS)
41 .filter(key => CONFIG.TRANSCODING.RESOLUTIONS[key] === true) 42 .filter(key => CONFIG.TRANSCODING.RESOLUTIONS[key] === true)
@@ -54,7 +55,8 @@ async function getConfig (req: express.Request, res: express.Response, next: exp
54 }, 55 },
55 serverVersion: packageJSON.version, 56 serverVersion: packageJSON.version,
56 signup: { 57 signup: {
57 allowed 58 allowed,
59 allowedForCurrentIP
58 }, 60 },
59 transcoding: { 61 transcoding: {
60 enabledResolutions 62 enabledResolutions
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts
index 0a591f11d..8dff4b87c 100644
--- a/server/controllers/api/users.ts
+++ b/server/controllers/api/users.ts
@@ -19,6 +19,7 @@ import {
19 authenticate, 19 authenticate,
20 ensureUserHasRight, 20 ensureUserHasRight,
21 ensureUserRegistrationAllowed, 21 ensureUserRegistrationAllowed,
22 ensureUserRegistrationAllowedForIP,
22 paginationValidator, 23 paginationValidator,
23 setDefaultPagination, 24 setDefaultPagination,
24 setDefaultSort, 25 setDefaultSort,
@@ -106,6 +107,7 @@ usersRouter.post('/',
106 107
107usersRouter.post('/register', 108usersRouter.post('/register',
108 asyncMiddleware(ensureUserRegistrationAllowed), 109 asyncMiddleware(ensureUserRegistrationAllowed),
110 ensureUserRegistrationAllowedForIP,
109 asyncMiddleware(usersRegisterValidator), 111 asyncMiddleware(usersRegisterValidator),
110 asyncMiddleware(registerUserRetryWrapper) 112 asyncMiddleware(registerUserRetryWrapper)
111) 113)