Skip to content

Node.js based forum software built for the modern web

closes #2498

barisusaklief3b6a245074
diff --git a/src/posts/create.js b/src/posts/create.js
index 99c50ea813..d9040e443e 100644
--- a/src/posts/create.js
+++ b/src/posts/create.js
@@ -2,6 +2,7 @@
var async = require('async'),
+ meta = require('../meta'),
db = require('../database'),
plugins = require('../plugins'),
user = require('../user'),
@@ -46,6 +47,10 @@ module.exports = function(Posts) {
postData.toPid = data.toPid;
}
+ if (data.ip && parseInt(meta.config.trackIpPerPost, 10) === 1) {
+ postData.ip = data.ip;
+ }
+
plugins.fireHook('filter:post.save', postData, next);
},
function(postData, next) {
diff --git a/src/socket.io/index.js b/src/socket.io/index.js
index a0e0c1a150..0a49982d3f 100644
--- a/src/socket.io/index.js
+++ b/src/socket.io/index.js
@@ -250,7 +250,7 @@ Sockets.reqFromSocket = function(socket) {
referer = headers.referer || '';
return {
- ip: socket.ip,
+ ip: headers['x-forwarded-for'] || socket.ip,
host: host,
protocol: socket.request.connection.encrypted ? 'https' : 'http',
secure: !!socket.request.connection.encrypted,
diff --git a/src/topics/create.js b/src/topics/create.js
index d1b2428e0c..76d905a1f0 100644
--- a/src/topics/create.js
+++ b/src/topics/create.js
@@ -226,7 +226,7 @@ module.exports = function(Topics) {
checkContentLength(content, next);
},
function(next) {
- posts.create({uid: uid, tid: tid, content: content, toPid: toPid}, next);
+ posts.create({uid: uid, tid: tid, content: content, toPid: toPid, ip: data.req.ip}, next);
},
function(data, next) {
postData = data;
diff --git a/src/views/admin/settings/post.tpl b/src/views/admin/settings/post.tpl
index 2af1117c10..122b2cdf0c 100644
--- a/src/views/admin/settings/post.tpl
+++ b/src/views/admin/settings/post.tpl
@@ -41,6 +41,11 @@
<label>Minimum Post Length</label>
<input type="number" class="form-control" value="8" data-field="minimumPostLength">
</div>
+ <div class="checkbox">
+ <label>
+ <input type="checkbox" data-field="trackIpPerPost"> <strong>Track IP Address for each post</strong>
+ </label>
+ </div>
</form>
</div>
</div>