-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidatehttps.js
More file actions
209 lines (134 loc) · 7.02 KB
/
validatehttps.js
File metadata and controls
209 lines (134 loc) · 7.02 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
example for configuration:
<?php
$httpsUrl = 'https://www.metodika.com/valid.php';
$validateHttps = 1; //0 = false, 1 = true
?>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var validateHttpsUrl = "<?=$httpsUrl?>";
var validateHttps = "<?=$validateHttps?>";
var allowOnlyHttps = '<?=$account_settings->ONLY_HTTPS_CONNECTION?>';
</script>
<script type="text/javascript" src="validatehttps.js"></script>
Just adding is enough:
<script type="text/javascript" src="validatehttps.js"></script>
*/
var dynamicUrl = (typeof validateHttpsUrl == 'undefined' || validateHttpsUrl === "") ? 'https://www.metodika.com/valid.php' : validateHttpsUrl;
var runValidation = (typeof validateHttps == 'undefined' || validateHttps === "") ? '1' : validateHttps;
var allowOnlyHttps = (typeof allowOnlyHttps == 'undefined' || allowOnlyHttps === "") ? '0' : allowOnlyHttps;
var warningText = (typeof warningText == 'undefined' || warningText === "") ? "Unsecure SSL connection. Please update your browser. " : warningText + " ";
var moreInfo = (typeof moreInfo == 'undefined' || moreInfo === "") ? "More info" : moreInfo;
function loadJSON(callback) {
var xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
//set dynamicUrl via index php site
xobj.open('GET', dynamicUrl, true);
xobj.onreadystatechange = function () {
if (xobj.status == "0") {
//error
callback(xobj.responseText);
}else if(xobj.status == "200" && xobj.readyState == 4){
callback(xobj.responseText);
}else{
//Nothing
}
}
xobj.send(null);
}
var validateWarning = '<div id="validateWrapper">';
validateWarning += '<p>'+warningText+'<a href="http://www.macworld.com/article/2099987/what-you-need-to-know-about-apples-ssl-bug.html" target="_blank">'+moreInfo+'</a></p>';
validateWarning += '</div>'; //validateWrapper
document.body.innerHTML += validateWarning;
document.getElementById('validateWrapper').style.display = "none";
document.getElementById('validateWrapper').style.width = "100%";
document.getElementById('validateWrapper').style.position = "absolute";
document.getElementById('validateWrapper').style.top = "0";
document.getElementById('validateWrapper').style.paddingTop = "10px";
document.getElementById('validateWrapper').style.textAlign = "center";
document.getElementById('validateWrapper').style.backgroundColor = "rgb(236,236,236)";
document.getElementById('validateWrapper').getElementsByTagName('p')[0].style.fontSize = "13px";
var httpWarning = '<div id="httpBlock">';
httpWarning += '<div>';
httpWarning += '<p>'+warningText+'<a href="http://www.macworld.com/article/2099987/what-you-need-to-know-about-apples-ssl-bug.html" target="_blank">'+moreInfo+'</a></p>';
httpWarning += '</div>';
httpWarning += '</div>';
document.body.innerHTML += httpWarning;
document.getElementById('httpBlock').style.visibility = 'hidden';
document.getElementById('httpBlock').style.position = 'fixed';
document.getElementById('httpBlock').style.left = '0px';
document.getElementById('httpBlock').style.top = '0';
document.getElementById('httpBlock').style.width = '100%';
document.getElementById('httpBlock').style.height = '100%';
document.getElementById('httpBlock').style.textAlign = 'center';
document.getElementById('httpBlock').style.zIndex = '99999';
document.getElementById('httpBlock').style.backgroundColor = 'rgba(0, 0, 0, 0.75)';
document.getElementById('httpBlock').childNodes[0].style.border = '1px solid #999';
document.getElementById('httpBlock').childNodes[0].style.border = '1px solid rgba(0,0,0,0.3)';
document.getElementById('httpBlock').childNodes[0].style.webkitBorderRadius = '6px';
document.getElementById('httpBlock').childNodes[0].style.mozBorderRadius = '6px';
document.getElementById('httpBlock').childNodes[0].style.borderRadius = '6px';
document.getElementById('httpBlock').childNodes[0].style.outline = 0;
document.getElementById('httpBlock').childNodes[0].style.webkitBoxShadow = '0 3px 7px rgba(0,0,0,0.3)';
document.getElementById('httpBlock').childNodes[0].style.mozBoxShadow = '0 3px 7px rgba(0,0,0,0.3)';
document.getElementById('httpBlock').childNodes[0].style.boxShadow = '0 3px 7px rgba(0,0,0,0.3)';
document.getElementById('httpBlock').childNodes[0].style.webkitBackgroundClip = 'padding-box';
document.getElementById('httpBlock').childNodes[0].style.mozBackgroundClip = 'padding-box';
document.getElementById('httpBlock').childNodes[0].style.backgroundClip = 'padding-box';
document.getElementById('httpBlock').childNodes[0].style.position = 'fixed';
document.getElementById('httpBlock').childNodes[0].style.backgroundColor = '#fff';
document.getElementById('httpBlock').childNodes[0].style.border = '1px solid #000';
document.getElementById('httpBlock').childNodes[0].style.padding = '15px';
document.getElementById('httpBlock').childNodes[0].style.textAlign = 'center';
document.getElementById('httpBlock').childNodes[0].style.top = '10%';
//Small screen
var w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
if(w>767){
document.getElementById('httpBlock').childNodes[0].style.width = '560px';
document.getElementById('httpBlock').childNodes[0].style.left = '50%';
document.getElementById('httpBlock').childNodes[0].style.marginLeft = '-280px';
}else{
document.getElementById('httpBlock').childNodes[0].style.width = 'auto';
}
var fullUrl = window.location.href;
var http = fullUrl.split('://');
if(http[0] === "http" && runValidation == 1){
document.body.style.marginTop = "50px";
// Call to function with anonymous callback
loadJSON(function(response) {
var fullUrl = window.location.href;
var http = fullUrl.split('//');
if(response === ""){
//Error
//Warning box at the top
if(allowOnlyHttps == 1){
document.getElementById('httpBlock').style.visibility = 'visible';
//Prevent DOM manipulation
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
var target = document.querySelector('#httpBlock');
var targetChild = document.querySelector('#httpBlock').childNodes[0];
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
location.reload();
});
});
var config = { attributes: true, childList: true, characterData: true, attributeOldValue: true }
observer.observe(target, config);
observer.observe(targetChild, config);
}else{
document.getElementById('validateWrapper').style.display = "block";
}
//console.log("Not safe");
}else{
//Success
jsonResponse = JSON.parse(response);
if(jsonResponse.safe === "true"){
window.location.href = 'https://' + http[1];
}else{
console.log("safe !== true");
}
}
})
}