Skip to content

Commit 95b74f0

Browse files
committed
Add checktor.js script to misc scripts useful for Tor2web integration
1 parent cd527e3 commit 95b74f0

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

misc/checktor.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
Copyright 2015 - Hermes Center - GlobaLeaks project
3+
Author <giovanni.pellerano@evilaliv3.org>
4+
5+
Javascript CheckTor library
6+
*/
7+
8+
function redirectIfOnTor(url, test_url) {
9+
// Test if the user is using Tor and in that case
10+
// redirects the user to provided url
11+
try {
12+
if (typeof(test_url) === 'undefined') {
13+
var test_url = 'https://antani.tor2web.org/checktor';
14+
}
15+
if (window.XMLHttpRequest) {
16+
var xmlhttp = new XMLHttpRequest();
17+
18+
xmlhttp.onreadystatechange=function() {
19+
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
20+
if (xmlhttp.getResponseHeader("x-check-tor")) {
21+
window.location.href = url;
22+
}
23+
}
24+
}
25+
26+
xmlhttp.open("GET", test_url, true);
27+
xmlhttp.send();
28+
29+
}
30+
} catch(err) {
31+
32+
}
33+
}

0 commit comments

Comments
 (0)