ability to force anon and toggle ids + changed postform order and placeholders

merge-requests/208/head
fatchan 5 years ago
parent 06d4b26e65
commit 4b8fbf8e7f
  1. 41
      models/forms/make-post.js
  2. 15
      views/includes/postform.pug
  3. 13
      views/mixins/post.pug
  4. 9
      wipe.js

@ -147,18 +147,25 @@ module.exports = async (req, res, next, numFiles) => {
} }
} }
//post salt for IDs //poster ip
const ip = req.headers['x-real-ip'] || req.connection.remoteAddress;
let userId = null;
if (!salt) { if (!salt) {
//thread salt for IDs
salt = (await randomBytes(128)).toString('hex'); salt = (await randomBytes(128)).toString('hex');
} }
const ip = req.headers['x-real-ip'] || req.connection.remoteAddress; if (res.locals.board.settings.ids) {
const fullUserIdHash = crypto.createHash('sha256').update(salt + ip + req.params.board).digest('hex'); const fullUserIdHash = crypto.createHash('sha256').update(salt + ip + req.params.board).digest('hex');
const userId = fullUserIdHash.substring(fullUserIdHash.length-6); userId = fullUserIdHash.substring(fullUserIdHash.length-6);
}
let name = null; let name = 'Anonymous';
let tripcode = null; let tripcode = null;
let capcode = null; let capcode = null;
if (req.body.name && req.body.name.length > 0) { //if forceanon, only allow sage as email
const email = res.locals.board.settings.forceAnon && req.body.email !== 'sage' ? null : req.body.email;
if ((hasPerms || !res.locals.board.settings.forceAnon) && req.body.name && req.body.name.length > 0) {
// get matches with named groups for name, trip and capcode in 1 regex // get matches with named groups for name, trip and capcode in 1 regex
const matches = req.body.name.match(nameRegex); const matches = req.body.name.match(nameRegex);
if (matches && matches.groups) { if (matches && matches.groups) {
@ -190,7 +197,7 @@ module.exports = async (req, res, next, numFiles) => {
//build post data for db //build post data for db
const data = { const data = {
'date': new Date(), 'date': new Date(),
'name': name || 'Anonymous', 'name': name,
'board': req.params.board, 'board': req.params.board,
'tripcode': tripcode, 'tripcode': tripcode,
'capcode': capcode, 'capcode': capcode,
@ -198,7 +205,7 @@ module.exports = async (req, res, next, numFiles) => {
'message': message || null, 'message': message || null,
'thread': req.body.thread || null, 'thread': req.body.thread || null,
'password': req.body.password || null, 'password': req.body.password || null,
'email': req.body.email || null, 'email': email,
'salt': !req.body.thread ? salt : null, 'salt': !req.body.thread ? salt : null,
'spoiler': req.body.spoiler ? true : false, 'spoiler': req.body.spoiler ? true : false,
'banmessage': null, 'banmessage': null,
@ -207,12 +214,18 @@ module.exports = async (req, res, next, numFiles) => {
'files': files, 'files': files,
'reports': [], 'reports': [],
'globalreports': [], 'globalreports': [],
'replyposts': 0, }
'replyfiles': 0,
'sticky': false, if (!req.body.thread) {
'locked': false, //if this is a thread, add replies, sticky, sage, lock, etc
'saged': false, Object.assign(data, {
}; 'replyposts': 0,
'replyfiles': 0,
'sticky': false,
'locked': false,
'saged': false
});
}
let postId; let postId;
try { try {

@ -2,18 +2,16 @@ section.form-wrapper
form.form-post(action=`/forms/board/${board._id}/post`, enctype='multipart/form-data', method='POST') form.form-post(action=`/forms/board/${board._id}/post`, enctype='multipart/form-data', method='POST')
input(type='hidden' name='_csrf' value=csrf) input(type='hidden' name='_csrf' value=csrf)
input(type='hidden' name='thread' value=thread != null ? thread.postId : null) input(type='hidden' name='thread' value=thread != null ? thread.postId : null)
section.postform-row if !board.settings.forceAnon
.postform-label Name section.postform-row
input#name(type='text', name='name', placeholder='Anonymous' autocomplete='off' maxlength='50') .postform-label Name
input#name(type='text', name='name', placeholder='Anonymous' autocomplete='off' maxlength='50')
section.postform-row section.postform-row
.postform-label Subject .postform-label Subject
input#title(type='text', name='subject', autocomplete='off' maxlength='50') input#title(type='text', name='subject', autocomplete='off' maxlength='50')
section.postform-row section.postform-row
.postform-label Email .postform-label Email
input#name(type='text', name='email', autocomplete='off' maxlength='50') input#name(type='text', name='email', autocomplete='off' maxlength='50')
section.postform-row
.postform-label Password
input#password(type='password', name='password', autocomplete='off' maxlength='50')
section.postform-row section.postform-row
.postform-label Message .postform-label Message
textarea#message(name='message', rows='5', autocomplete='off' maxlength='2000') textarea#message(name='message', rows='5', autocomplete='off' maxlength='2000')
@ -23,6 +21,9 @@ section.form-wrapper
label.postform-style.ph-5.ml-1 label.postform-style.ph-5.ml-1
input#spoiler(type='checkbox', name='spoiler', value='true') input#spoiler(type='checkbox', name='spoiler', value='true')
| Spoiler | Spoiler
section.postform-row
.postform-label Password
input#password(type='password', name='password', autocomplete='off' placeholder='password for deleting post later' maxlength='50')
section.postform-row section.postform-row
.postform-label Captcha .postform-label Captcha
.postform-col .postform-col
@ -30,5 +31,3 @@ section.form-wrapper
input#captcha(type='text', name='captcha', autocomplete='off' placeholder='captcha text' maxlength='6') input#captcha(type='text', name='captcha', autocomplete='off' placeholder='captcha text' maxlength='6')
input(type='submit', value='submit') input(type='submit', value='submit')

@ -14,10 +14,10 @@ mixin post(post, truncate, manage=false, globalmanage=false)
img(src='/img/saged.svg' height='12') img(src='/img/saged.svg' height='12')
if post.locked if post.locked
img(src='/img/locked.svg' height='12') img(src='/img/locked.svg' height='12')
| |
if post.subject if post.subject
span.post-subject #{post.subject} span.post-subject #{post.subject}
| |
if post.email if post.email
a(href=`mailto:${post.email}`) a(href=`mailto:${post.email}`)
span.post-name #{post.name} span.post-name #{post.name}
@ -26,14 +26,15 @@ mixin post(post, truncate, manage=false, globalmanage=false)
| |
if post.tripcode if post.tripcode
span.post-tripcode #{post.tripcode} span.post-tripcode #{post.tripcode}
| |
if post.capcode if post.capcode
span.post-capcode #{post.capcode} span.post-capcode #{post.capcode}
| |
span #{post.date.toLocaleString()} span #{post.date.toLocaleString()}
| |
span.user-id(style=`background: #${post.userId}`) #{post.userId} if board.settings.ids && post.userId
| span.user-id(style=`background: #${post.userId}`) #{post.userId}
|
span: a(href=postURL) No.#{post.postId} span: a(href=postURL) No.#{post.postId}
.post-data .post-data
if post.files.length > 0 if post.files.length > 0

@ -1,3 +1,4 @@
'use strict'; 'use strict';
const Mongo = require(__dirname+'/db/db.js') const Mongo = require(__dirname+'/db/db.js')
@ -38,6 +39,10 @@ const Mongo = require(__dirname+'/db/db.js')
owner: '', owner: '',
moderators: [], moderators: [],
banners: [], banners: [],
settings: {
forceAnon: true,
ids: true,
}
}) })
await Boards.insertOne({ await Boards.insertOne({
_id: 'b', _id: 'b',
@ -46,6 +51,10 @@ const Mongo = require(__dirname+'/db/db.js')
owner: '', owner: '',
moderators: [], moderators: [],
banners: [], banners: [],
settings: {
forceAnon: false,
ids: false,
}
}) })
console.log('creating indexes') console.log('creating indexes')
await Bans.db.dropIndexes(); await Bans.db.dropIndexes();

Loading…
Cancel
Save