Repository navigation
Expand file tree
/
Copy pathserver.js
More file actions
324 lines (309 loc) · 8.19 KB
/
Copy pathserver.js
File metadata and controls
324 lines (309 loc) · 8.19 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/* http://extjs.github.io/Connect/errorHandler.html */
/* this is a simple example server without any decent error handling. it basically creates
a server at port 3000 that enables you to hit the server and get the data back in json format.
so you would hit it like this...
curl http://localhost:3000/?url=http://cnn.com
then the output would look like this...
{ 'Requested URL': 'http://www.cnn.com',
'Page URL': 'http://www.cnn.com/',
'Page Error': '',
'Page Error Detail': '',
'General Error Count': '0',
'Page Error Count': '0',
'Resource Error Count': '0',
'Domain Change': '',
'CName Change': '',
PageLoad: '4489',
'Copyright date': '2013',
Websphere: '',
'.NET': '',
PHP: '',
Janrain: '',
Flash: '',
Wordpress: '',
CQ: '',
'Operating System': '',
'Webtrends Tagging': '',
'Webtrends ID': '',
'Google Analytics': '',
'Pop-ups': '',
'Video on Homepage': '',
'Audio on Homepage': '',
Downloads: '',
Screensavers: '',
Emoticons: '',
Twitter: '',
'Google Search': '',
Facebook: '',
Youtube: '',
Netbiscuits: '',
'Detected Apps': 'Disqus|jQuery|Modernizr|Nginx|Optimizely|Prototype|script.aculo.us' }
*/
var connect = require("connect");
var _ = require("underscore");
var exec = require('child_process').exec;
var app = connect();
var regex = regexList();
connect()
.use(connect.logger('dev'))
.use(connect.bodyParser())
.use(connect.query())
.use(function(req, res, next) {
var form = _.extend(req.query, req.body);
if ( ! _.has(form, 'url') ) {
next("expected a url param containing the detination to hit");
}
var job = "phantomjs phantalyzer.js " + form.url;
/* setting the timeout here to 45 seconds */
var child = exec(job, { 'maxBuffer' : 2000*1024, 'timeout' : 45000 },
function (error, stdout, stderr) {
console.log(stderr);
var outputObj = {};
//console.log(stdout);
for (var key in regex) {
var def = regex[key];
var exp = new RegExp(def.pattern, def.modifiers);
var match = stdout.match(exp);
var result = "";
//console.log("checking " + def.pattern + ", match=", match);
if ( match ) {
result = match[0];
//console.log('KEY=' + key);
if ( def.hit != undefined ) {
result = def.hit;
for (var k = 0; k < match.length; k++ ) {
result = result.replace('\{\{' + k + '\}\}', match[k]);
}
}
result = result.replace('\{\{count\}\}', match.length);
//console.log('output=' + result);
} else {
if ( def.miss != undefined ) {
result = def.miss;
}
}
outputObj[key] = result;
}
console.log(outputObj);
var jsonOut = JSON.stringify(outputObj);
res.writeHead(200, {
'Content-Length': jsonOut.length,
// 'Content-Type': 'text/plain'
'Content-Type': 'application/json'
});
res.end(jsonOut);
}
);
})
.use(connect.errorHandler({ dumpExceptions: true }))
.listen(3000);
function regexList() {
var regexList = {
"Requested URL" : {
"pattern" : "^requestedUrl: ([^$]+?)$",
"modifiers" : "m",
"hit" : "{{1}}",
"miss" : "report missing"
},
"Page URL" : {
"pattern" : "^pageUrl: ([^$]+?)$",
"modifiers" : "m",
"hit" : "{{1}}",
"miss" : "miss"
},
"Page Error" : {
"pattern" : "^pageError: ([^$]+?)$",
"modifiers" : "m",
"hit" : "{{1}}",
"miss" : ""
},
"Page Error Detail" : {
"pattern" : "^pageErrorDetail: ([^$]+?)$",
"modifiers" : "m",
"hit" : "{{1}}",
"miss" : ""
},
"General Error Count": {
"pattern": "^error: ",
"modifiers": "im",
"hit" : "{{count}}",
"miss" : "0"
},
"Page Error Count": {
"pattern": "^pageError: ",
"modifiers": "im",
"hit" : "{{count}}",
"miss" : "0"
},
"Resource Error Count": {
"pattern": "^resourceError: ",
"modifiers": "im",
"hit" : "{{count}}",
"miss" : "0"
},
"Domain Change" : {
"pattern" : "^domainChange:",
"modifiers" : "m",
"hit" : "yes",
"miss" : ""
},
"CName Change" : {
"pattern" : "^cnameDomainChange:",
"modifiers" : "m",
"hit" : "yes",
"miss" : ""
},
"PageLoad" : {
"pattern" : "^pageLoadTimeMillis: (\\d+)",
"modifiers" : "m",
"hit" : "{{1}}",
"miss" : "not found"
},
"Copyright date" : {
"pattern": "©\\s*(\\d{4}(?:\\s*-\\s*\\d{4})?)",
"modifiers": "i",
"hit" : "{{1}}",
"miss" : ""
},
"Websphere": {
"pattern": "^wappalyzerDetected: Java",
"modifiers": "im",
"hit" : "yes",
"miss" : ""
},
".NET": {
"pattern": "^wappalyzerDetected: Microsoft ASP.NET",
"modifiers": "mi",
"hit" : "yes",
"miss" : ""
},
"PHP": {
"pattern": "^wappalyzerDetected: PHP",
"modifiers": "mi",
"hit" : "yes",
"miss" : ""
},
"Janrain": {
"pattern": "janrain",
"modifiers": "i",
"hit" : "yes",
"miss" : ""
},
"Flash": {
"pattern": "(<\\s*embed\\s+[^>]*\\.swf?|wappalyzerDetected: SWFObject)",
"modifiers": "i",
"hit" : "yes",
"miss" : ""
},
"Wordpress": {
"pattern": "^wappalyzerDetected: WordPress",
"modifiers": "mi",
"hit" : "yes",
"miss" : ""
},
"CQ": {
"pattern": "^wappalyzerDetected: Adobe CQ5",
"modifiers" : "m",
"hit" : "yes",
"miss" : ""
},
"Operating System": {
"pattern": "^wappalyzerDetected: (Unix|Centos|Redhat|Windows Server)",
"modifiers": "mi",
"hit" : "{{1}}",
"miss" : ""
},
"Webtrends Tagging": {
"pattern": "//statse.webtrendslive.com/([^/]+)",
"modifiers": "i",
"hit" : "yes",
"miss" : ""
},
"Webtrends ID": {
"pattern": "//statse.webtrendslive.com/([^/]+)",
"modifiers": "i",
"hit" : "{{1}}",
"miss" : ""
},
"Google Analytics": {
"patternx": "utmac=(UA-[-0-9]+)",
"pattern": "['\"](UA-\\d+-\\d+)['\"]",
"modifiers": "i",
"hit" : "{{1}}",
"miss" : ""
},
"Pop-ups": {
"pattern": "window.open",
"modifiers": "i",
"hit" : "yes",
"miss" : ""
},
"Video on Homepage": {
"pattern": "\\.(wmv|mov|flv|mp4|ogg|webm)",
"modifiers": "i",
"hit" : "yes",
"miss" : ""
},
"Audio on Homepage": {
"pattern": "\\.(aac|m4a|mpeg|mp1|mp2|mp3|mpg|mpeg|oga|ogg|wav)",
"modifiers": "i",
"hit" : "yes",
"miss" : ""
},
"Downloads": {
"pattern": "href\\s*=\\s*['\"][^>]*downloads",
"modifiers": "i",
"hit" : "yes",
"miss" : ""
},
"Screensavers": {
"pattern": "href\\s*=\\s*['\"][^>]*screensavers",
"modifiers": "i",
"hit" : "yes",
"miss" : ""
},
"Emoticons": {
"pattern": "href\\s*=\\s*['\"][^>]*emoticons",
"modifiers": "i",
"hit" : "yes",
"miss" : ""
},
"Twitter": {
"pattern": "^resourceReceived: .*twitter\\.com.*$",
"modifiers": "im",
"hit" : "yes",
"miss" : ""
},
"Google Search": {
"pattern": "(//www\\.google\\.com/cse/cse\\.js|<gcse:search>)",
"modifiers": "i",
"hit" : "yes",
"miss" : ""
},
"Facebook": {
"pattern": "^resourceReceived: .*facebook\\.com.*$",
"modifiers": "im",
"hit" : "yes",
"miss" : ""
},
"Youtube": {
"pattern": "^resourceReceived: .*youtube\\.com.*$",
"modifiers": "im",
"hit" : "yes",
"miss" : ""
},
"Netbiscuits" : {
"pattern":"Netbiscuits",
"modifiers" : "i",
"hit" : "yes",
"false" : ""
},
"Detected Apps" : {
"pattern" : "^detectedApps: ([^$]*?)$",
"modifiers" : "m",
"hit" : "{{1}}",
"false" : ""
}
};
return regexList;
}