country blocking per board

merge-requests/208/head
fatchan 4 years ago
parent 5c7fc003ad
commit 9f44f8aabc
  1. 2
      helpers/paramconverter.js
  2. 1
      migrations/index.js
  3. 12
      migrations/migration-0.0.6.js
  4. 8
      models/forms/changeboardsettings.js
  5. 12
      models/forms/makepost.js
  6. 2
      package.json
  7. 16
      views/includes/2charisocountries.pug
  8. 3
      views/pages/managesettings.pug

@ -2,7 +2,7 @@
const { ObjectId } = require(__dirname+'/../db/db.js')
, allowedArrays = new Set(['checkednews', 'checkedposts', 'globalcheckedposts',
'checkedreports', 'checkedbans', 'checkedbanners', 'checkedaccounts']) //only these should be arrays, since express bodyparser can output arrays
'checkedreports', 'checkedbans', 'checkedbanners', 'checkedaccounts', 'countries']) //only these should be arrays, since express bodyparser can output arrays
, trimFields = ['tags', 'uri', 'moderators', 'filters', 'announcement', 'description', 'message',
'name', 'subject', 'email', 'postpassword', 'password', 'default_name', 'report_reason', 'ban_reason', 'log_message', 'custom_css'] //trim if we dont want filed with whitespace
, numberFields = ['filter_mode', 'lock_mode', 'captcha_mode', 'tph_trigger', 'pph_trigger', 'trigger_action', 'bump_limit', 'reply_limit', 'move_to_thread',, 'postId',

@ -6,4 +6,5 @@ module.exports = {
'0.0.3': require(__dirname+'/migration-0.0.3.js'), //move files from /img to /file/
'0.0.4': require(__dirname+'/migration-0.0.4.js'), //rename some fields for board lock mode and unlisting
'0.0.5': require(__dirname+'/migration-0.0.5.js'), //add bumplimit to board settings
'0.0.6': require(__dirname+'/migration-0.0.6.js'), //add blocked countries to board settings
}

@ -0,0 +1,12 @@
'use strict';
module.exports = async(db, redis) => {
console.log('Adding blockedCountries field to boards');
await db.collection('boards').updateMany({}, {
'$set': {
'settings.blockedCountries': [],
}
});
console.log('Cleared boards cache');
await redis.deletePattern('board:*');
};

@ -9,6 +9,7 @@ const { Boards, Posts, Accounts } = require(__dirname+'/../../db/')
, { remove } = require('fs-extra')
, deletePosts = require(__dirname+'/deletepost.js')
, messageHandler = require(__dirname+'/../../helpers/posting/message.js')
, countryCodes = new Set(['??', 'AD','AE','AF','AG','AI','AL','AM','AO','AQ','AR','AS','AT','AU','AW','AX','AZ','BA','BB','BD','BE','BF','BG','BH','BI','BJ','BL','BM','BN','BO','BQ','BR','BS','BT','BV','BW','BY','BZ','CA','CC','CD','CF','CG','CH','CI','CK','CL','CM','CN','CO','CR','CU','CV','CW','CX','CY','CZ','DE','DJ','DK','DM','DO','DZ','EC','EE','EG','EH','ER','ES','ET','FI','FJ','FK','FM','FO','FR','GA','GB','GD','GE','GF','GG','GH','GI','GL','GM','GN','GP','GQ','GR','GS','GT','GU','GW','GY','HK','HM','HN','HR','HT','HU','ID','IE','IL','IM','IN','IO','IQ','IR','IS','IT','JE','JM','JO','JP','KE','KG','KH','KI','KM','KN','KP','KR','KW','KY','KZ','LA','LB','LC','LI','LK','LR','LS','LT','LU','LV','LY','MA','MC','MD','ME','MF','MG','MH','MK','ML','MM','MN','MO','MP','MQ','MR','MS','MT','MU','MV','MW','MX','MY','MZ','NA','NC','NE','NF','NG','NI','NL','NO','NP','NR','NU','NZ','OM','PA','PE','PF','PG','PH','PK','PL','PM','PN','PR','PS','PT','PW','PY','QA','RE','RO','RS','RU','RW','SA','SB','SC','SD','SE','SG','SH','SI','SJ','SK','SL','SM','SN','SO','SR','SS','ST','SV','SX','SY','SZ','TC','TD','TF','TG','TH','TJ','TK','TL','TM','TN','TO','TR','TT','TV','TW','TZ','UA','UG','UM','US','UY','UZ','VA','VC','VE','VG','VI','VN','VU','WF','WS','XK','YE','YT','ZA','ZM','ZW'])
, trimSetting = (setting, oldSetting) => {
return setting && setting.trim().length > 0 ? setting : oldSetting;
}
@ -61,6 +62,12 @@ module.exports = async (req, res, next) => {
}
}
if (req.body.countries) {
req.body.countries = [...new Set(req.body.countries)] //prevents submitting multiple of same code, not like it matters, but meh
.filter(code => countryCodes.has(code))
.slice(0,250);
}
const newSettings = {
moderators,
'name': trimSetting(req.body.name, oldSettings.name),
@ -101,6 +108,7 @@ module.exports = async (req, res, next) => {
'filterBanDuration': numberSetting(req.body.ban_duration, oldSettings.filterBanDuration),
'tags': arraySetting(req.body.tags, oldSettings.tags, 10),
'filters': arraySetting(req.body.filters, oldSettings.filters, 50),
'blockedCountries': req.body.countries || [],
'strictFiltering': booleanSetting(req.body.strict_filtering),
'customCss': globalLimits.customCss.enabled ? (req.body.custom_css !== null ? req.body.custom_css : oldSettings.customCss) : null,
'announcement': {

@ -44,10 +44,20 @@ module.exports = async (req, res, next) => {
let redirect = `/${req.params.board}/`
let salt = null;
let thread = null;
const { filterBanDuration, filterMode, filters,
const { filterBanDuration, filterMode, filters, blockedCountries,
maxFiles, forceAnon, replyLimit, disableReplySubject,
threadLimit, ids, userPostSpoiler, pphTrigger, tphTrigger, triggerAction,
captchaMode, lockMode, allowedFileTypes, flags } = res.locals.board.settings;
if (flags === true
&& res.locals.permLevel >= 4
&& req.headers['x-country-code']
&& blockedCountries.includes(req.headers['x-country-code'])) {
return dynamicResponse(req, res, 403, 'message', {
'title': 'Forbidden',
'message': `Your country code ${req.headers['x-country-code']} is not allowed to post on this board`,
'redirect': redirect
});
}
if ((lockMode === 2 || (lockMode === 1 && !req.body.thread)) //if board lock, or thread lock and its a new thread
&& res.locals.permLevel >= 4) { //and not staff
await deleteTempFiles(req).catch(e => console.error);

@ -1,7 +1,7 @@
{
"name": "jschan",
"version": "0.0.1",
"migrateVersion": "0.0.5",
"migrateVersion": "0.0.6",
"description": "",
"main": "server.js",
"dependencies": {

@ -1,6 +1,7 @@
-
const codeKeys = ['AD','AE','AF','AG','AI','AL','AM','AO','AQ','AR','AS','AT','AU','AW','AX','AZ','BA','BB','BD','BE','BF','BG','BH','BI','BJ','BL','BM','BN','BO','BQ','BR','BS','BT','BV','BW','BY','BZ','CA','CC','CD','CF','CG','CH','CI','CK','CL','CM','CN','CO','CR','CU','CV','CW','CX','CY','CZ','DE','DJ','DK','DM','DO','DZ','EC','EE','EG','EH','ER','ES','ET','FI','FJ','FK','FM','FO','FR','GA','GB','GD','GE','GF','GG','GH','GI','GL','GM','GN','GP','GQ','GR','GS','GT','GU','GW','GY','HK','HM','HN','HR','HT','HU','ID','IE','IL','IM','IN','IO','IQ','IR','IS','IT','JE','JM','JO','JP','KE','KG','KH','KI','KM','KN','KP','KR','KW','KY','KZ','LA','LB','LC','LI','LK','LR','LS','LT','LU','LV','LY','MA','MC','MD','ME','MF','MG','MH','MK','ML','MM','MN','MO','MP','MQ','MR','MS','MT','MU','MV','MW','MX','MY','MZ','NA','NC','NE','NF','NG','NI','NL','NO','NP','NR','NU','NZ','OM','PA','PE','PF','PG','PH','PK','PL','PM','PN','PR','PS','PT','PW','PY','QA','RE','RO','RS','RU','RW','SA','SB','SC','SD','SE','SG','SH','SI','SJ','SK','SL','SM','SN','SO','SR','SS','ST','SV','SX','SY','SZ','TC','TD','TF','TG','TH','TJ','TK','TL','TM','TN','TO','TR','TT','TV','TW','TZ','UA','UG','UM','US','UY','UZ','VA','VC','VE','VG','VI','VN','VU','WF','WS','XK','YE','YT','ZA','ZM','ZW'];
const codeKeys = ['??', 'AD','AE','AF','AG','AI','AL','AM','AO','AQ','AR','AS','AT','AU','AW','AX','AZ','BA','BB','BD','BE','BF','BG','BH','BI','BJ','BL','BM','BN','BO','BQ','BR','BS','BT','BV','BW','BY','BZ','CA','CC','CD','CF','CG','CH','CI','CK','CL','CM','CN','CO','CR','CU','CV','CW','CX','CY','CZ','DE','DJ','DK','DM','DO','DZ','EC','EE','EG','EH','ER','ES','ET','FI','FJ','FK','FM','FO','FR','GA','GB','GD','GE','GF','GG','GH','GI','GL','GM','GN','GP','GQ','GR','GS','GT','GU','GW','GY','HK','HM','HN','HR','HT','HU','ID','IE','IL','IM','IN','IO','IQ','IR','IS','IT','JE','JM','JO','JP','KE','KG','KH','KI','KM','KN','KP','KR','KW','KY','KZ','LA','LB','LC','LI','LK','LR','LS','LT','LU','LV','LY','MA','MC','MD','ME','MF','MG','MH','MK','ML','MM','MN','MO','MP','MQ','MR','MS','MT','MU','MV','MW','MX','MY','MZ','NA','NC','NE','NF','NG','NI','NL','NO','NP','NR','NU','NZ','OM','PA','PE','PF','PG','PH','PK','PL','PM','PN','PR','PS','PT','PW','PY','QA','RE','RO','RS','RU','RW','SA','SB','SC','SD','SE','SG','SH','SI','SJ','SK','SL','SM','SN','SO','SR','SS','ST','SV','SX','SY','SZ','TC','TD','TF','TG','TH','TJ','TK','TL','TM','TN','TO','TR','TT','TV','TW','TZ','UA','UG','UM','US','UY','UZ','VA','VC','VE','VG','VI','VN','VU','WF','WS','XK','YE','YT','ZA','ZM','ZW'];
const codeMap = {
'??': 'TOR (not implemented yet)',
'AD': 'Andorra',
'AE': 'United Arab Emirates',
'AF': 'Afghanistan',
@ -253,8 +254,11 @@
'ZW': 'Zimbabwe'
}
select(name='countries' multiple)
each code in blockedCountries
option(value=code) #{codeMap[code]}
each code in codeKeys.filter(c => !blockedCountries.has(c))
option(value=code) #{codeMap[code]}
- const blockedCountries = new Set(board.settings.blockedCountries);
select(name='countries' size='10' multiple)
optgroup(label='Currently blocked')
each code in board.settings.blockedCountries
option(value=code) #{codeMap[code]}
optgroup(label='Not blocked')
each code in codeKeys.filter(c => !blockedCountries.has(c))
option(value=code) #{codeMap[code]}

@ -151,7 +151,6 @@ block content
.label Geo Flags
label.postform-style.ph-5
input(type='checkbox', name='flags', value='true' checked=board.settings.flags)
.col
.row
.label Lock Mode
select(name='lock_mode')
@ -170,6 +169,7 @@ block content
.label SFW
label.postform-style.ph-5
input(type='checkbox', name='sfw', value='true' checked=board.settings.sfw)
.col
.row
.label Theme
select(name='theme')
@ -210,7 +210,6 @@ block content
input(type='checkbox', name='early404', value='true' checked=board.settings.early404)
.row
.label Blocked Countries
- const blockedCountries = new Set(board.settings.blockedCountries);
include ../includes/2charisocountries.pug
.row
.label Filters

Loading…
Cancel
Save