-
Notifications
You must be signed in to change notification settings - Fork 44
/
_randomEvent.js
157 lines (128 loc) · 4.81 KB
/
_randomEvent.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
'use strict';
var samples = require('./samples');
var argv = require('./argv');
var stringGenerator = require('./samples/string_generator');
var eventCounter = -1;
var count = argv.total;
var countOfDays = (function () {
var cursor = argv.start.clone();
var count = 0;
var end = argv.end.valueOf();
if (cursor.valueOf() <= end) {
do {
cursor.add(1, 'day');
count += 1;
} while (cursor.valueOf() <= end);
}
return count;
}());
var countPerDay = Math.ceil(count / countOfDays);
var indexInterval = argv.indexInterval;
var dayMoment = argv.start.clone();
var day;
module.exports = function RandomEvent(indexPrefix) {
var event = {};
var i = ++eventCounter;
var iInDay = i % countPerDay;
if (day && iInDay === 0) {
dayMoment.add(1, 'day');
day = null;
}
if (day == null) {
day = {
year: dayMoment.year(),
month: dayMoment.month(),
date: dayMoment.date(),
};
}
var ms = samples.lessRandomMsInDay();
// extract number of hours from the milliseconds
var hours = Math.floor(ms / 3600000);
ms = ms - hours * 3600000;
// extract number of minutes from the milliseconds
var minutes = Math.floor(ms / 60000);
ms = ms - minutes * 60000;
// extract number of seconds from the milliseconds
var seconds = Math.floor(ms / 1000);
ms = ms - seconds * 1000;
// apply the values found to the date
var date = new Date(day.year, day.month, day.date, hours, minutes, seconds, ms);
var dateAsIso = date.toISOString();
switch (indexInterval) {
case 'yearly':
event.index = indexPrefix + dateAsIso.substr(0, 4);
break;
case 'monthly':
event.index = indexPrefix + dateAsIso.substr(0, 4) + '.' + dateAsIso.substr(5, 2);
break;
case 'daily':
event.index = indexPrefix + dateAsIso.substr(0, 4) + '.' + dateAsIso.substr(5, 2) + '.' + dateAsIso.substr(8, 2);
break;
default:
event.index = indexPrefix + Math.floor(i / indexInterval);
break;
}
event['@timestamp'] = dateAsIso;
event.ip = samples.ips();
event.extension = samples.extensions();
event.response = samples.responseCodes();
event.geo = {
coordinates: samples.airports(),
src: samples.countries(),
dest: samples.countries()
};
event.geo.srcdest = event.geo.src + ':' + event.geo.dest;
event['@tags'] = [
samples.tags(),
samples.tags2()
];
event.utc_time = dateAsIso;
event.referer = 'http://' + samples.referrers() + '/' + samples.tags() + '/' + samples.astronauts();
event.agent = samples.userAgents();
event.clientip = event.ip;
event.bytes = event.response < 500 ? samples.lessRandomRespSize(event.extension) : 0;
switch (event.extension) {
case 'php':
event.host = 'theacademyofperformingartsandscience.org';
event.request = '/people/type:astronauts/name:' + samples.astronauts() + '/profile';
event.phpmemory = event.memory = event.bytes * 40;
break;
case 'gif':
event.host = 'motion-media.theacademyofperformingartsandscience.org';
event.request = '/canhaz/' + samples.astronauts() + '.' + event.extension;
break;
case 'css':
event.host = 'cdn.theacademyofperformingartsandscience.org';
event.request = '/styles/' + samples.stylesheets();
break;
default:
event.host = 'media-for-the-masses.theacademyofperformingartsandscience.org';
event.request = '/uploads/' + samples.astronauts() + '.' + event.extension;
break;
}
event.url = 'https://' + event.host + event.request;
event['@message'] = event.ip + ' - - [' + dateAsIso + '] "GET ' + event.request + ' HTTP/1.1" ' +
event.response + ' ' + event.bytes + ' "-" "' + event.agent + '"';
event.spaces = 'this is a thing with lots of spaces wwwwoooooo';
event.xss = '<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==" onload="alert(\'XSS found via img-onload!\')"><script>alert("XSS found via script-tag!")</script>';
event.headings = [
'<h3>' + samples.astronauts() + '</h5>',
'http://' + samples.referrers() + '/' + samples.tags() + '/' + samples.astronauts()
];
event.links = [
samples.astronauts() + '@' + samples.referrers(),
'http://' + samples.referrers() + '/' + samples.tags2() + '/' + samples.astronauts(),
'www.' + samples.referrers()
];
event.relatedContent = samples.relatedContent();
event.machine = {
os: samples.randomOs(),
ram: samples.randomRam()
};
event.longValues = stringGenerator(Math.floor(Math.random() * 200 + 100));
event.longValuesWithSpaces = stringGenerator(Math.floor(Math.random() * 200 + 100), true);
var longFieldName = 'thisisaverylongfieldnamethatevendoesnotcontainanyspaces'
+ 'whyitcouldpotentiallybreakouruiinseveralplaces';
event[longFieldName] = stringGenerator(Math.floor(Math.random() * 200 + 50));
return event;
};