Skip to content

Commit 0acd28c

Browse files
authored
Merge branch 'next' into dynamic-widgets
2 parents d4fbc5f + 77d3e83 commit 0acd28c

File tree

27 files changed

+472
-146
lines changed

27 files changed

+472
-146
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ api/node_modules/
22
.idea
33
frontend/express/node_modules/
44
api/config.js
5+
countly_marked_version.json
56
frontend/express/config.js
67
frontend/express/public/javascripts/countly/countly.config.js
78
frontend/express/certificates

Diff for: api/api.js

+39
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,58 @@ const http = require('http');
22
const cluster = require('cluster');
33
const formidable = require('formidable');
44
const os = require('os');
5+
const fs = require('fs');
56
const countlyConfig = require('./config', 'dont-enclose');
67
const plugins = require('../plugins/pluginManager.js');
78
const jobs = require('./parts/jobs');
89
const log = require('./utils/log.js')('core:api');
910
const common = require('./utils/common.js');
1011
const {processRequest} = require('./utils/requestProcessor');
12+
const versionInfo = require('../frontend/express/version.info');
1113

1214
var t = ["countly:", "api"];
1315

1416
if (cluster.isMaster) {
1517
t.push("master");
1618
t.push("node");
1719
t.push(process.argv[1]);
20+
//save current version in file
21+
if(versionInfo && versionInfo.version)
22+
{
23+
var olderVersions=[];
24+
var currentVersion =versionInfo.version;
25+
var lastVersion="";
26+
if (fs.existsSync(__dirname+"/../countly_marked_version.json"))//read form file(if exist);
27+
{
28+
try
29+
{
30+
var data = fs.readFileSync(__dirname+"/../countly_marked_version.json");
31+
try { olderVersions = JSON.parse(data);}
32+
catch (SyntaxError) {//unable to parse file
33+
log.e(SyntaxError);
34+
}
35+
if(Array.isArray(olderVersions))
36+
{
37+
lastVersion = olderVersions[olderVersions.length-1].version;
38+
}
39+
else
40+
olderVersions=[];
41+
42+
}catch(error)
43+
{
44+
log.e(error);
45+
}
46+
}
47+
if(lastVersion=="" || lastVersion!=currentVersion)
48+
{
49+
olderVersions.push({version:currentVersion,updated:Date.now()});
50+
try
51+
{
52+
fs.writeFileSync(__dirname+"/../countly_marked_version.json",JSON.stringify(olderVersions));
53+
}
54+
catch(error){log.e(error);}
55+
}
56+
}
1857
}
1958
else{
2059
t.push("worker");

Diff for: api/parts/data/events.js

+71-62
Original file line numberDiff line numberDiff line change
@@ -59,36 +59,40 @@ var countlyEvents = {},
5959

6060
for (var segKey in currEvent.segmentation) {
6161

62+
if(plugins.internalOmitSegments[currEvent.key] && Array.isArray(plugins.internalOmitSegments[currEvent.key]) && plugins.internalOmitSegments[currEvent.key].indexOf(segKey)!=-1)//check if segment should be ommited
63+
{
64+
continue;
65+
}
66+
6267
if(omitted_segments[currEvent.key] && Array.isArray(omitted_segments[currEvent.key]) && omitted_segments[currEvent.key].indexOf(segKey)!=-1)//check if segment should be ommited
6368
{
6469
continue;
6570
}
6671

72+
if (plugins.getConfig("api").event_segmentation_limit &&
73+
appSegments[currEvent.key] &&
74+
appSegments[currEvent.key].indexOf(segKey) === -1 &&
75+
appSegments[currEvent.key].length >= plugins.getConfig("api").event_segmentation_limit) {
76+
continue;
77+
}
6778

68-
if (plugins.getConfig("api").event_segmentation_limit &&
69-
appSegments[currEvent.key] &&
70-
appSegments[currEvent.key].indexOf(segKey) === -1 &&
71-
appSegments[currEvent.key].length >= plugins.getConfig("api").event_segmentation_limit) {
72-
continue;
73-
}
74-
75-
var tmpSegVal = currEvent.segmentation[segKey] + "";
79+
var tmpSegVal = currEvent.segmentation[segKey] + "";
7680

77-
if (tmpSegVal == "") {
78-
continue;
79-
}
81+
if (tmpSegVal == "") {
82+
continue;
83+
}
8084

81-
// Mongodb field names can't start with $ or contain .
82-
tmpSegVal = tmpSegVal.replace(/^\$/, "").replace(/\./g, ":");
85+
// Mongodb field names can't start with $ or contain .
86+
tmpSegVal = tmpSegVal.replace(/^\$/, "").replace(/\./g, ":");
8387

84-
if (forbiddenSegValues.indexOf(tmpSegVal) !== -1) {
85-
tmpSegVal = "[CLY]" + tmpSegVal;
86-
}
87-
var postfix = common.crypto.createHash("md5").update(tmpSegVal).digest('base64')[0];
88-
metaToFetch[eventCollectionName + "no-segment_" + common.getDateIds(params).zero + "_" + postfix] = {
89-
coll: eventCollectionName,
90-
id: "no-segment_" + common.getDateIds(params).zero + "_" + postfix
91-
};
88+
if (forbiddenSegValues.indexOf(tmpSegVal) !== -1) {
89+
tmpSegVal = "[CLY]" + tmpSegVal;
90+
}
91+
var postfix = common.crypto.createHash("md5").update(tmpSegVal).digest('base64')[0];
92+
metaToFetch[eventCollectionName + "no-segment_" + common.getDateIds(params).zero + "_" + postfix] = {
93+
coll: eventCollectionName,
94+
id: "no-segment_" + common.getDateIds(params).zero + "_" + postfix
95+
};
9296

9397
}
9498
}
@@ -207,59 +211,64 @@ var countlyEvents = {},
207211
}
208212

209213
for (var segKey in currEvent.segmentation) {
214+
if(plugins.internalOmitSegments[currEvent.key] && Array.isArray(plugins.internalOmitSegments[currEvent.key]) && plugins.internalOmitSegments[currEvent.key].indexOf(segKey)!=-1)//check if segment should be ommited
215+
{
216+
continue;
217+
}
218+
210219
if(omitted_segments[currEvent.key] && Array.isArray(omitted_segments[currEvent.key]) && omitted_segments[currEvent.key].indexOf(segKey)!=-1)//check if segment should be ommited
211220
{
212221
continue;
213222
}
214223

215-
if (plugins.getConfig("api").event_segmentation_limit &&
216-
appSegments[currEvent.key] &&
217-
appSegments[currEvent.key].indexOf(segKey) === -1 &&
218-
appSegments[currEvent.key].length >= plugins.getConfig("api").event_segmentation_limit) {
219-
continue;
220-
}
224+
if (plugins.getConfig("api").event_segmentation_limit &&
225+
appSegments[currEvent.key] &&
226+
appSegments[currEvent.key].indexOf(segKey) === -1 &&
227+
appSegments[currEvent.key].length >= plugins.getConfig("api").event_segmentation_limit) {
228+
continue;
229+
}
221230

222-
tmpEventObj = {};
223-
var tmpSegVal = currEvent.segmentation[segKey] + "";
231+
tmpEventObj = {};
232+
var tmpSegVal = currEvent.segmentation[segKey] + "";
224233

225-
if (tmpSegVal == "") {
226-
continue;
227-
}
234+
if (tmpSegVal == "") {
235+
continue;
236+
}
228237

229-
// Mongodb field names can't start with $ or contain .
230-
tmpSegVal = tmpSegVal.replace(/^\$/, "").replace(/\./g, ":");
238+
// Mongodb field names can't start with $ or contain .
239+
tmpSegVal = tmpSegVal.replace(/^\$/, "").replace(/\./g, ":");
231240

232-
if (forbiddenSegValues.indexOf(tmpSegVal) !== -1) {
233-
tmpSegVal = "[CLY]" + tmpSegVal;
234-
}
235-
236-
var postfix = common.crypto.createHash("md5").update(tmpSegVal).digest('base64')[0];
237-
238-
if (plugins.getConfig("api").event_segmentation_value_limit &&
239-
appSgValues[eventCollectionName] &&
240-
appSgValues[eventCollectionName]["no-segment" + "_" + dateIds.zero + "_" + postfix] &&
241-
appSgValues[eventCollectionName]["no-segment" + "_" + dateIds.zero + "_" + postfix][segKey] &&
242-
appSgValues[eventCollectionName]["no-segment" + "_" + dateIds.zero + "_" + postfix][segKey].indexOf(tmpSegVal) === -1 &&
243-
appSgValues[eventCollectionName]["no-segment" + "_" + dateIds.zero + "_" + postfix][segKey].length >= plugins.getConfig("api").event_segmentation_value_limit) {
244-
continue;
245-
}
241+
if (forbiddenSegValues.indexOf(tmpSegVal) !== -1) {
242+
tmpSegVal = "[CLY]" + tmpSegVal;
243+
}
244+
245+
var postfix = common.crypto.createHash("md5").update(tmpSegVal).digest('base64')[0];
246+
247+
if (plugins.getConfig("api").event_segmentation_value_limit &&
248+
appSgValues[eventCollectionName] &&
249+
appSgValues[eventCollectionName]["no-segment" + "_" + dateIds.zero + "_" + postfix] &&
250+
appSgValues[eventCollectionName]["no-segment" + "_" + dateIds.zero + "_" + postfix][segKey] &&
251+
appSgValues[eventCollectionName]["no-segment" + "_" + dateIds.zero + "_" + postfix][segKey].indexOf(tmpSegVal) === -1 &&
252+
appSgValues[eventCollectionName]["no-segment" + "_" + dateIds.zero + "_" + postfix][segKey].length >= plugins.getConfig("api").event_segmentation_value_limit) {
253+
continue;
254+
}
246255

247-
if (currEvent.sum && common.isNumber(currEvent.sum)) {
248-
common.fillTimeObjectMonth(params, tmpEventObj, tmpSegVal + '.' + common.dbMap['sum'], currEvent.sum);
249-
}
250-
251-
if (currEvent.dur && common.isNumber(currEvent.dur)) {
252-
common.fillTimeObjectMonth(params, tmpEventObj, tmpSegVal + '.' + common.dbMap['dur'], currEvent.dur);
253-
}
256+
if (currEvent.sum && common.isNumber(currEvent.sum)) {
257+
common.fillTimeObjectMonth(params, tmpEventObj, tmpSegVal + '.' + common.dbMap['sum'], currEvent.sum);
258+
}
259+
260+
if (currEvent.dur && common.isNumber(currEvent.dur)) {
261+
common.fillTimeObjectMonth(params, tmpEventObj, tmpSegVal + '.' + common.dbMap['dur'], currEvent.dur);
262+
}
254263

255-
common.fillTimeObjectMonth(params, tmpEventObj, tmpSegVal + '.' + common.dbMap['count'], currEvent.count);
264+
common.fillTimeObjectMonth(params, tmpEventObj, tmpSegVal + '.' + common.dbMap['count'], currEvent.count);
256265

257-
if (!eventSegmentsZeroes[eventCollectionName]) {
258-
eventSegmentsZeroes[eventCollectionName] = [];
259-
common.arrayAddUniq(eventSegmentsZeroes[eventCollectionName], dateIds.zero + "." + postfix);
260-
} else {
261-
common.arrayAddUniq(eventSegmentsZeroes[eventCollectionName], dateIds.zero + "." + postfix);
262-
}
266+
if (!eventSegmentsZeroes[eventCollectionName]) {
267+
eventSegmentsZeroes[eventCollectionName] = [];
268+
common.arrayAddUniq(eventSegmentsZeroes[eventCollectionName], dateIds.zero + "." + postfix);
269+
} else {
270+
common.arrayAddUniq(eventSegmentsZeroes[eventCollectionName], dateIds.zero + "." + postfix);
271+
}
263272

264273
if (!eventSegments[eventCollectionName + "." + dateIds.zero + "." + postfix]) {
265274
eventSegments[eventCollectionName + "." + dateIds.zero + "." + postfix] = {};

Diff for: api/utils/requestProcessor.js

-1
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,6 @@ const processRequest = (params) => {
13231323
path: params.qstring.path,
13241324
data: params.qstring.data,
13251325
method: params.qstring.method,
1326-
post: params.qstring.post,
13271326
prop: params.qstring.prop,
13281327
type: params.qstring.type,
13291328
filename: params.qstring.filename

Diff for: bin/scripts/checking_versions.js

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
const fs = require('fs');
2+
const versionInfo = require('../../frontend/express/version.info');
3+
var versions=[];
4+
var marked_version="";
5+
var current_version="";
6+
7+
//get current version
8+
if(versions && versionInfo.version)
9+
current_version = versionInfo.version;
10+
11+
//load marked version
12+
if (fs.existsSync(__dirname+"/../../countly_marked_version.json"))//read form file(if exist);
13+
{
14+
var olderVersions=[];
15+
try
16+
{
17+
var data = fs.readFileSync(__dirname+"/../../countly_marked_version.json");
18+
try { olderVersions = JSON.parse(data);}
19+
catch (SyntaxError) {//unable to parse file
20+
console.error(SyntaxError);
21+
}
22+
if(Array.isArray(olderVersions))
23+
marked_version = olderVersions[olderVersions.length-1].version;
24+
}catch(error){console.error(error);}
25+
}
26+
//reading version numbers from upgrade folder
27+
var pattern = new RegExp(/^(([0-9])*\.)*[0-9]*$/);
28+
try
29+
{
30+
var dir_items = fs.readdirSync("../upgrade");
31+
for (var i=0; i<dir_items.length; i++)
32+
{
33+
if(dir_items[i] != '.')
34+
{
35+
try
36+
{
37+
stat = fs.statSync("../upgrade/"+dir_items[i]);
38+
if(stat.isDirectory() && pattern.test(dir_items[i]))
39+
{
40+
var my_name = dir_items[i]
41+
versions.push(dir_items[i]);
42+
}
43+
}catch(error)
44+
{
45+
console.error(error);
46+
}
47+
}
48+
}
49+
50+
}catch(error)
51+
{
52+
console.error(error);
53+
}
54+
versions = versions.sort();
55+
56+
var from=0;
57+
var til=versions.length-1;
58+
59+
if(current_version=="")
60+
{
61+
console.error("could not load current version.");
62+
return;
63+
}
64+
65+
if(marked_version=="")
66+
{
67+
console.error("Could not load marked version.");
68+
return;
69+
}
70+
if(current_version==marked_version)
71+
{
72+
console.error("up to date");
73+
return;
74+
}
75+
else
76+
{
77+
while(versions[from]<=marked_version && from<versions.length){ from++;}
78+
while(versions[til]>current_version && til>=0){ til--;}
79+
80+
if(til==-1 || from ==versions.length)
81+
{
82+
console.error("version range not found");
83+
return;
84+
}
85+
else{
86+
versions = versions.slice(from,til+1);
87+
console.log(versions.join(";"));
88+
}
89+
}

Diff for: frontend/express/app.js

+33-14
Original file line numberDiff line numberDiff line change
@@ -816,22 +816,41 @@ app.get(countlyConfig.path+'/reset/:prid', function (req, res, next) {
816816
});
817817

818818
app.post(countlyConfig.path+'/reset', function (req, res, next) {
819-
if (req.body.password && req.body.again && req.body.prid) {
820-
req.body.prid += "";
821-
var password = sha512Hash(req.body.password);
822-
823-
countlyDb.collection('password_reset').findOne({prid:req.body.prid}, function (err, passwordReset) {
824-
countlyDb.collection('members').findAndModify({_id:passwordReset.user_id}, {}, {'$set':{ "password":password }}, function (err, member) {
825-
member = member && member.ok ? member.value : null;
826-
plugins.callMethod("passwordReset", {req:req, res:res, next:next, data:member});
827-
req.flash('info', 'reset.result');
828-
res.redirect(countlyConfig.path+'/login');
829-
});
819+
var result = validatePassword(req.body.password);
820+
821+
if (result === false) {
822+
if (req.body.password && req.body.again && req.body.prid) {
823+
req.body.prid += "";
824+
var password = sha512Hash(req.body.password);
825+
826+
countlyDb.collection('password_reset').findOne({ prid: req.body.prid }, function (err, passwordReset) {
827+
countlyDb.collection('members').findAndModify({ _id: passwordReset.user_id }, {}, { '$set': { "password": password } }, function (err, member) {
828+
member = member && member.ok ? member.value : null;
829+
plugins.callMethod("passwordReset", { req: req, res: res, next: next, data: member });
830+
req.flash('info', 'reset.result');
831+
res.redirect(countlyConfig.path + '/login');
832+
});
830833

831-
countlyDb.collection('password_reset').remove({prid:req.body.prid}, function () {});
832-
});
834+
countlyDb.collection('password_reset').remove({ prid: req.body.prid }, function () { });
835+
});
836+
} else {
837+
res.render('reset', { countlyFavicon: req.countly.favicon, countlyTitle: req.countly.title, countlyPage: req.countly.page, "csrf": req.csrfToken(), "prid": req.body.prid, "message": "", path: countlyConfig.path || "", cdn: countlyConfig.cdn || "", themeFiles: req.themeFiles, inject_template: req.template });
838+
}
833839
} else {
834-
res.render('reset', { countlyFavicon:req.countly.favicon, countlyTitle:req.countly.title, countlyPage:req.countly.page, "csrf":req.csrfToken(), "prid":req.body.prid, "message":"", path:countlyConfig.path || "", cdn:countlyConfig.cdn || "", themeFiles:req.themeFiles, inject_template:req.template});
840+
res.render('reset',
841+
{
842+
countlyFavicon: req.countly.favicon,
843+
countlyTitle: req.countly.title,
844+
countlyPage: req.countly.page,
845+
"csrf": req.csrfToken(),
846+
"prid": req.body.prid,
847+
path: countlyConfig.path || "",
848+
cdn: countlyConfig.cdn || "",
849+
themeFiles: req.themeFiles,
850+
inject_template: req.template,
851+
message: result,
852+
password_min: plugins.getConfig("security").password_min
853+
});
835854
}
836855
});
837856

0 commit comments

Comments
 (0)