Refactoring

main
Elbert Alias 8 years ago
parent 3282680af5
commit f445a79c50

@ -234,7 +234,7 @@ var wappalyzer = (function() {
*/ */
analyze: function(hostname, url, data) { analyze: function(hostname, url, data) {
var var
app, confirmMatch, type, app,
apps = {}; apps = {};
w.log('w.analyze'); w.log('w.analyze');
@ -259,50 +259,22 @@ var wappalyzer = (function() {
for ( app in w.apps ) { for ( app in w.apps ) {
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] ) {
confirmMatch = function(pattern, value, key) {
apps[app].setDetected(pattern, type, value, key);
}
switch ( type ) {
case 'url':
if ( url ) { if ( url ) {
w.analyzeUrl(parsePatterns(w.apps[app][type]), url, confirmMatch); w.analyzeUrl(apps[app], url);
}
break;
case 'html':
if ( data.html ) {
w.analyzeHtml(parsePatterns(w.apps[app][type]), data.html, confirmMatch);
} }
break;
case 'script':
if ( data.html ) { if ( data.html ) {
w.analyzeScript(parsePatterns(w.apps[app][type]), data.html, confirmMatch); w.analyzeHtml(apps[app], data.html);
w.analyzeScript(apps[app], data.html);
w.analyzeMeta(apps[app], data.html);
} }
break; if ( data.headers ) {
case 'meta': w.analyzeHeaders(apps[app], data.headers);
if ( data.html ) {
w.analyzeMeta(parsePatterns(w.apps[app][type]), data.html, confirmMatch);
} }
break; if ( data.env ) {
case 'headers': w.analyzeEnv(apps[app], data.env);
if ( data.hasOwnProperty('headers') && data.headers ) {
w.analyzeHeaders(parsePatterns(w.apps[app][type]), data.headers, confirmMatch);
}
break;
case 'env':
if ( data.hasOwnProperty('env') && data.env ) {
w.analyzeEnv(parsePatterns(w.apps[app][type]), data.env, confirmMatch);
}
break;
default:
}
} }
} }
@ -462,50 +434,64 @@ var wappalyzer = (function() {
/** /**
* Analyze URL * Analyze URL
*/ */
analyzeUrl: function(patterns, url, confirmMatch) { analyzeUrl: function(app, url) {
var patterns = parsePatterns(w.apps[app.app].url);
if ( patterns.length ) {
patterns.forEach(function(pattern) { patterns.forEach(function(pattern) {
if ( pattern.regex.test(url) ) { if ( pattern.regex.test(url) ) {
confirmMatch(pattern, url); app.setDetected(pattern, 'url', url);
} }
}); });
}
}, },
/** /**
* Analyze HTML * Analyze HTML
*/ */
analyzeHtml: function(patterns, html, confirmMatch) { analyzeHtml: function(app, html) {
var patterns = parsePatterns(w.apps[app.app].html);
if ( patterns.length ) {
patterns.forEach(function(pattern) { patterns.forEach(function(pattern) {
if ( pattern.regex.test(html) ) { if ( pattern.regex.test(html) ) {
confirmMatch(pattern, html); app.setDetected(pattern, 'html', html);
} }
}); });
}
}, },
/** /**
* Analyze script tag * Analyze script tag
*/ */
analyzeScript: function(patterns, html, confirmMatch) { analyzeScript: function(app, html) {
var regex = new RegExp('<script[^>]+src=("|\')([^"\']+)', 'ig'); var
regex = new RegExp('<script[^>]+src=("|\')([^"\']+)', 'ig'),
patterns = parsePatterns(w.apps[app.app].script);
if ( patterns.length ) {
patterns.forEach(function(pattern) { patterns.forEach(function(pattern) {
var match; var match;
while ( match = regex.exec(html) ) { while ( match = regex.exec(html) ) {
if ( pattern.regex.test(match[2]) ) { if ( pattern.regex.test(match[2]) ) {
confirmMatch(pattern, match[2]); app.setDetected(pattern, 'script', match[2]);
} }
} }
}); });
}
}, },
/** /**
* Analyze meta tag * Analyze meta tag
*/ */
analyzeMeta: function(patterns, html, confirmMatch) { analyzeMeta: function(app, html) {
var var
content, match, meta, content, match, meta,
regex = /<meta[^>]+>/ig; regex = /<meta[^>]+>/ig,
patterns = parsePatterns(w.apps[app.app].meta);
if ( patterns.length ) {
while ( match = regex.exec(html) ) { while ( match = regex.exec(html) ) {
for ( meta in patterns ) { for ( meta in patterns ) {
if ( new RegExp('(name|property)=["\']' + meta + '["\']', 'i').test(match) ) { if ( new RegExp('(name|property)=["\']' + meta + '["\']', 'i').test(match) ) {
@ -513,45 +499,54 @@ var wappalyzer = (function() {
patterns[meta].forEach(function(pattern) { patterns[meta].forEach(function(pattern) {
if ( content && content.length === 4 && pattern.regex.test(content[2]) ) { if ( content && content.length === 4 && pattern.regex.test(content[2]) ) {
confirmMatch(pattern, content[2], meta); app.setDetected(pattern, 'meta', content[2], meta);
} }
}); });
} }
} }
} }
}
}, },
/** /**
* analyze response headers * analyze response headers
*/ */
analyzeHeaders: function(patterns, headers, confirmMatch) { analyzeHeaders: function(app, headers) {
var header; var
header,
patterns = parsePatterns(w.apps[app.app].headers);
if ( patterns.length && headers ) {
for ( header in patterns ) { for ( header in patterns ) {
patterns[header].forEach(function(pattern) { patterns[header].forEach(function(pattern) {
header = header.toLowerCase(); header = header.toLowerCase();
if ( headers.hasOwnProperty(header) && pattern.regex.test(headers[header]) ) { if ( headers.hasOwnProperty(header) && pattern.regex.test(headers[header]) ) {
confirmMatch(pattern, headers[header], header); app.setDetected(pattern, 'headers', headers[header], header);
} }
}); });
} }
}
}, },
/** /**
* Analyze environment variables * Analyze environment variables
*/ */
analyzeEnv: function(patterns, envs, confirmMatch) { analyzeEnv: function(app, envs) {
var env; var patterns = parsePatterns(w.apps[app.app].env);
if ( patterns.length ) {
patterns.forEach(function(pattern) { patterns.forEach(function(pattern) {
var env;
for ( env in envs ) { for ( env in envs ) {
if ( pattern.regex.test(envs[env]) ) { if ( pattern.regex.test(envs[env]) ) {
confirmMatch(pattern, envs[env]); app.setDetected(pattern, 'env', envs[env]);
} }
} }
}); });
} }
}
}; };
return w; return w;

Loading…
Cancel
Save