Refactoring

main
Elbert Alias 8 years ago
parent 7e3e6652d2
commit 97b9285f8b

@ -1673,7 +1673,7 @@
"X-Powered-By": "CppCMS/([\\d.]+)\\;version:\\1" "X-Powered-By": "CppCMS/([\\d.]+)\\;version:\\1"
}, },
"icon": "CppCMS.png", "icon": "CppCMS.png",
"implies": "C++", "implies": "C\\+\\+",
"website": "http://cppcms.com" "website": "http://cppcms.com"
}, },
"Craft CMS": { "Craft CMS": {

@ -234,10 +234,8 @@ var wappalyzer = (function() {
*/ */
analyze: function(hostname, url, data) { analyze: function(hostname, url, data) {
var var
confirmMatch, confidence, id, match, patterns, type, version, app, confirmMatch, type,
apps = {}, apps = {};
excludes = [],
checkImplies = true;
w.log('w.analyze'); w.log('w.analyze');
@ -262,12 +260,6 @@ var wappalyzer = (function() {
apps[app] = w.detected[url] && w.detected[url][app] ? w.detected[url][app] : new Application(app); apps[app] = w.detected[url] && w.detected[url][app] ? w.detected[url][app] : new Application(app);
for ( type in w.apps[app] ) { for ( type in w.apps[app] ) {
patterns = parsePatterns(w.apps[app][type]);
if ( !patterns ) {
continue;
}
confirmMatch = function(pattern, value, key) { confirmMatch = function(pattern, value, key) {
apps[app].setDetected(pattern, type, value, key); apps[app].setDetected(pattern, type, value, key);
} }
@ -275,37 +267,37 @@ var wappalyzer = (function() {
switch ( type ) { switch ( type ) {
case 'url': case 'url':
if ( url ) { if ( url ) {
w.analyzeUrl(patterns, url, confirmMatch); w.analyzeUrl(parsePatterns(w.apps[app][type]), url, confirmMatch);
} }
break; break;
case 'html': case 'html':
if ( data.html ) { if ( data.html ) {
w.analyzeHtml(patterns, data.html, confirmMatch); w.analyzeHtml(parsePatterns(w.apps[app][type]), data.html, confirmMatch);
} }
break; break;
case 'script': case 'script':
if ( data.html ) { if ( data.html ) {
w.analyzeScript(patterns, data.html, confirmMatch); w.analyzeScript(parsePatterns(w.apps[app][type]), data.html, confirmMatch);
} }
break; break;
case 'meta': case 'meta':
if ( data.html ) { if ( data.html ) {
w.analyzeMeta(patterns, data.html, confirmMatch); w.analyzeMeta(parsePatterns(w.apps[app][type]), data.html, confirmMatch);
} }
break; break;
case 'headers': case 'headers':
if ( data.hasOwnProperty('headers') && data.headers ) { if ( data.hasOwnProperty('headers') && data.headers ) {
w.analyzeHeaders(patterns, data.headers, confirmMatch); w.analyzeHeaders(parsePatterns(w.apps[app][type]), data.headers, confirmMatch);
} }
break; break;
case 'env': case 'env':
if ( data.hasOwnProperty('env') && data.env ) { if ( data.hasOwnProperty('env') && data.env ) {
w.analyzeEnv(patterns, data.env, confirmMatch); w.analyzeEnv(parsePatterns(w.apps[app][type]), data.env, confirmMatch);
} }
break; break;
@ -320,6 +312,22 @@ var wappalyzer = (function() {
} }
} }
w.resolveExcludes(apps);
w.resolveImplies(apps, url);
w.cacheDetectedApps(apps, url);
w.trackDetectedApps(apps, url, hostname, data.html);
w.log(Object.keys(apps).length + ' apps detected: ' + Object.keys(apps).join(', ') + ' on ' + url);
driver('displayApps');
},
resolveExcludes: function(apps) {
var
app,
excludes = [];
// Exclude app in detected apps only // Exclude app in detected apps only
for ( app in apps ) { for ( app in apps ) {
if ( w.apps[app].excludes ) { if ( w.apps[app].excludes ) {
@ -339,6 +347,10 @@ var wappalyzer = (function() {
delete apps[app]; delete apps[app];
} }
} }
},
resolveImplies: function(apps, url) {
var checkImplies = true;
// Implied applications // Implied applications
// Run several passes as implied apps may imply other apps // Run several passes as implied apps may imply other apps
@ -377,23 +389,34 @@ var wappalyzer = (function() {
} }
} }
} }
},
w.log(Object.keys(apps).length + ' apps detected: ' + Object.keys(apps).join(', ') + ' on ' + url); /**
* Cache detected applications
*/
cacheDetectedApps: function(apps, url) {
var app, key, confidence;
// Keep history of detected apps
for ( app in apps ) { for ( app in apps ) {
confidence = apps[app].confidence; confidence = apps[app].confidence;
version = apps[app].version;
// Per URL // Per URL
w.detected[url][app] = apps[app]; w.detected[url][app] = apps[app];
for ( id in confidence ) { for ( key in confidence ) {
w.detected[url][app].confidence[id] = confidence[id]; w.detected[url][app].confidence[key] = confidence[key];
}
} }
},
/**
* Track detected applications
*/
trackDetectedApps: function(apps, url, hostname, html) {
var app, match;
for ( app in apps ) {
if ( w.detected[url][app].getConfidence() >= 100 ) { if ( w.detected[url][app].getConfidence() >= 100 ) {
// Per hostname
if ( /(www.)?((.+?)\.(([a-z]{2,3}\.)?[a-z]{2,6}))$/.test(hostname) && !/((local|dev(elopment)?|stag(e|ing)?|test(ing)?|demo(shop)?|admin|google|cache)\.|\/admin|\.local)/.test(url) ) { if ( /(www.)?((.+?)\.(([a-z]{2,3}\.)?[a-z]{2,6}))$/.test(hostname) && !/((local|dev(elopment)?|stag(e|ing)?|test(ing)?|demo(shop)?|admin|google|cache)\.|\/admin|\.local)/.test(url) ) {
if ( !w.ping.hostnames.hasOwnProperty(hostname) ) { if ( !w.ping.hostnames.hasOwnProperty(hostname) ) {
w.ping.hostnames[hostname] = { w.ping.hostnames[hostname] = {
@ -410,8 +433,8 @@ var wappalyzer = (function() {
w.ping.hostnames[hostname].applications[app].hits ++; w.ping.hostnames[hostname].applications[app].hits ++;
if ( version ) { if ( apps[app].version ) {
w.ping.hostnames[hostname].applications[app].version = version; w.ping.hostnames[hostname].applications[app].version = apps[app].version;
} }
} else { } else {
w.log('Ignoring hostname "' + hostname + '"'); w.log('Ignoring hostname "' + hostname + '"');
@ -421,20 +444,16 @@ var wappalyzer = (function() {
// Additional information // Additional information
if ( w.ping.hostnames.hasOwnProperty(hostname) ) { if ( w.ping.hostnames.hasOwnProperty(hostname) ) {
if ( typeof data.html === 'string' && data.html ) { match = html.match(/<html[^>]*[: ]lang="([a-z]{2}((-|_)[A-Z]{2})?)"/i);
match = data.html.match(/<html[^>]*[: ]lang="([a-z]{2}((-|_)[A-Z]{2})?)"/i);
if ( match && match.length ) { if ( match && match.length ) {
w.ping.hostnames[hostname].meta['language'] = match[1]; w.ping.hostnames[hostname].meta['language'] = match[1];
} }
} }
}
if ( Object.keys(w.ping.hostnames).length >= 50 || w.adCache.length >= 50 ) { if ( Object.keys(w.ping.hostnames).length >= 50 || w.adCache.length >= 50 ) {
driver('ping'); driver('ping');
} }
driver('displayApps');
}, },
/** /**
@ -481,7 +500,7 @@ var wappalyzer = (function() {
*/ */
analyzeMeta: function(patterns, html, confirmMatch) { analyzeMeta: function(patterns, html, confirmMatch) {
var var
content, meta, content, match, meta,
regex = /<meta[^>]+>/ig; regex = /<meta[^>]+>/ig;
while ( match = regex.exec(html) ) { while ( match = regex.exec(html) ) {