Completed PhantomJS driver

main
Elbert Alias 10 years ago
parent 088294e7e2
commit 968a25052f

@ -1,10 +1,24 @@
(function() { (function() {
var url; var
url,
originalUrl,
args = [],
debug = false;
try { try {
if ( require('system').args.length > 1 ) { require('system').args.forEach(function(arg) {
url = require('system').args[1]; switch ( arg ) {
} else { case '-v':
case '--verbose':
debug = true;
break;
default:
url = originalUrl = arg;
}
});
if ( !url ) {
throw new Error('Usage: phantomjs ' + require('system').args[0] + ' <url>'); throw new Error('Usage: phantomjs ' + require('system').args[0] + ' <url>');
} }
@ -17,9 +31,9 @@
* Log messages to console * Log messages to console
*/ */
log: function(args) { log: function(args) {
//if ( args.type !== 'debug' ) { if ( debug || args.type !== 'debug' ) {
console.log(args.message); console.log(args.message);
//} }
}, },
/** /**
@ -32,6 +46,8 @@
cats = [], cats = [],
count = wappalyzer.detected[url] ? Object.keys(wappalyzer.detected[url]).length : 0; count = wappalyzer.detected[url] ? Object.keys(wappalyzer.detected[url]).length : 0;
wappalyzer.log('driver.displayApps');
if ( count ) { if ( count ) {
for ( app in wappalyzer.detected[url] ) { for ( app in wappalyzer.detected[url] ) {
@ -40,6 +56,8 @@
}); });
apps.push({ apps.push({
url: originalUrl,
finalUrl: url,
application: app, application: app,
confidence: wappalyzer.detected[url][app].confidenceTotal, confidence: wappalyzer.detected[url][app].confidenceTotal,
version: wappalyzer.detected[url][app].version, version: wappalyzer.detected[url][app].version,
@ -61,6 +79,8 @@
a = document.createElement('a'), a = document.createElement('a'),
json = JSON.parse(require('fs').read('apps.json')); json = JSON.parse(require('fs').read('apps.json'));
wappalyzer.log('driver.init');
a.href = url.replace(/#.*$/, ''); a.href = url.replace(/#.*$/, '');
hostname = a.hostname; hostname = a.hostname;
@ -82,7 +102,7 @@
return; return;
} }
if ( response.bodySize && response.stage === 'start' && response.contentType.indexOf('text/html') !== -1 ) { if ( response.stage === 'end' && response.contentType.indexOf('text/html') !== -1 ) {
response.headers.forEach(function(header) { response.headers.forEach(function(header) {
headers[header.name.toLowerCase()] = header.value; headers[header.name.toLowerCase()] = header.value;
}); });
@ -90,8 +110,39 @@
} }
}; };
page.open(url, function() { page.open(url, function(status) {
wappalyzer.analyze(hostname, url, { html: page.content, headers: headers }); var html, environmentVars;
if ( status === 'fail' ) {
return;
}
html = page.content;
if ( html.length > 50000 ) {
html = html.substring(0, 25000) + html.substring(html.length - 25000, html.length);
}
// Collect environment variables
environmentVars = page.evaluate(function() {
var i, environmentVars;
for ( i in window ) {
environmentVars += i + ' ';
}
return environmentVars;
});
wappalyzer.log({ message: 'environmentVars: ' + environmentVars });
environmentVars = environmentVars.split(' ').slice(0, 500);
wappalyzer.analyze(hostname, url, {
html: html,
headers: headers,
env: environmentVars
});
phantom.exit(); phantom.exit();
}); });

Loading…
Cancel
Save