Analyze headers in PhantomJS driver

main
Elbert Alias 10 years ago
parent 2b6886d351
commit 8d6d92dd1f

@ -1,5 +1,5 @@
(function() { (function() {
var url, json, app, categories, page; var url;
try { try {
if ( require('system').args.length > 1 ) { if ( require('system').args.length > 1 ) {
@ -17,24 +17,54 @@
* Log messages to console * Log messages to console
*/ */
log: function(args) { log: function(args) {
//if ( args.type !== 'debug' ) {
console.log(args.message); console.log(args.message);
//}
}, },
/** /**
* Display apps * Display apps
*/ */
displayApps: function() { displayApps: function() {
var count = wappalyzer.detected[url] ? Object.keys(wappalyzer.detected[url]).length.toString() : '0'; var
app,
apps = [],
cats = [],
count = wappalyzer.detected[url] ? Object.keys(wappalyzer.detected[url]).length : 0;
console.log(count); if ( count ) {
for ( app in wappalyzer.detected[url] ) {
wappalyzer.apps[app].cats.forEach(function(cat) {
cats.push(wappalyzer.categories[cat]);
});
apps.push({
application: app,
confidence: wappalyzer.detected[url][app].confidenceTotal,
version: wappalyzer.detected[url][app].version,
categories: cats
});
}
console.log(JSON.stringify(apps));
}
}, },
/** /**
* Initialize * Initialize
*/ */
init: function() { init: function() {
var
page, hostname,
headers = {};
a = document.createElement('a'),
json = JSON.parse(require('fs').read('apps.json')); json = JSON.parse(require('fs').read('apps.json'));
a.href = url.replace(/#.*$/, '');
hostname = a.hostname;
wappalyzer.apps = json.apps; wappalyzer.apps = json.apps;
wappalyzer.categories = json.categories; wappalyzer.categories = json.categories;
@ -44,16 +74,24 @@
console.log(message); console.log(message);
}; };
page.open(url, function(status) { page.onResourceReceived = function(response) {
var a, hostname; if ( response.url.replace(/\/$/, '') === url.replace(/\/$/, '') ) {
if ( response.redirectURL ) {
a = document.createElement('a'); url = response.redirectURL;
a.href = url.replace(/#.*$/, ''); return;
}
hostname = a.hostname; if ( response.bodySize && response.stage === 'start' && response.contentType.indexOf('text/html') !== -1 ) {
response.headers.forEach(function(header) {
headers[header.name.toLowerCase()] = header.value;
});
}
}
};
wappalyzer.analyze(hostname, url, { html: page.content }); page.open(url, function() {
wappalyzer.analyze(hostname, url, { html: page.content, headers: headers });
phantom.exit(); phantom.exit();
}); });