forked from acdha/phantomjs-mixed-content-scan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport-mixed-content.js
executable file
·82 lines (65 loc) · 2.15 KB
/
report-mixed-content.js
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
#!/usr/bin/env phantomjs --web-security=false --disk-cache=true --ignore-ssl-errors=false --load-images=true --output-encoding=utf-8
'use strict';
var system = require('system'),
webpage = require('webpage');
var args = system.args,
URLs = [];
args.slice(1).forEach(function(url) {
if (url.substr(0, 8) !== 'https://') {
//console.debug('Rewriting HTTP URL to use HTTPS:', url);
url = url.replace('http:', 'https:');
}
URLs.push(url);
});
if (URLs.length < 1) {
console.log('Usage:', args[0], 'URL [URL2]');
phantom.exit(1);
}
function initPage() {
var page = new WebPage();
page.onResourceRequested = function(requestData, networkRequest) {
var originalURL = currentURL = requestData.url;
var currentPageURL = page.url || page.originalURL;
if (currentURL.substr(0, 8) !== 'https://' && currentURL.substr(0, 5) !== 'data:' && currentURL.substr(0, 5) !== 'file:') {
console.log('❗️ ', currentPageURL, 'loaded an insecure resource:', originalURL);
}
};
page.onError = function (msg, trace) {
logError('🌋 Page error:', msg);
trace.forEach(function(item) {
logError(' ', item.file, ':', item.line);
});
};
page.onConsoleMessage = function(msg) {
if (msg == 'GOTO_NEXT_PAGE') {
page.close();
//crawlNextPage();
} else if (msg.indexOf('insecure content from') >= 0) {
// We can format WebKit's native error messages nicely:
console.log('❕ ', msg.trim().replace('The page at ', ''));
} else {
console.log('\t💻', msg);
}
};
return page;
}
function crawlNextPage() {
if (URLs.length < 1) {
console.log('… done!');
phantom.exit();
}
var url = URLs.shift();
console.log('Checking ' + url);
var page = initPage();
page.originalURL = url;
page.open(url, function (status) {
if (status === 'success') {
//console.log('✅ ', url);
} else {
console.log('❌ ', url);
}
page.close()
crawlNextPage();
});
}
crawlNextPage();