Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add checktor.js script to misc scripts useful for Tor2web integration
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
Copyright 2015 - Hermes Center - GlobaLeaks project | ||
Author <giovanni.pellerano@evilaliv3.org> | ||
Javascript CheckTor library | ||
*/ | ||
|
||
function redirectIfOnTor(url, test_url) { | ||
// Test if the user is using Tor and in that case | ||
// redirects the user to provided url | ||
try { | ||
if (typeof(test_url) === 'undefined') { | ||
var test_url = 'https://antani.tor2web.org/checktor'; | ||
} | ||
if (window.XMLHttpRequest) { | ||
var xmlhttp = new XMLHttpRequest(); | ||
|
||
xmlhttp.onreadystatechange=function() { | ||
if (xmlhttp.readyState==4 && xmlhttp.status==200) { | ||
if (xmlhttp.getResponseHeader("x-check-tor")) { | ||
window.location.href = url; | ||
} | ||
} | ||
} | ||
|
||
xmlhttp.open("GET", test_url, true); | ||
xmlhttp.send(); | ||
|
||
} | ||
} catch(err) { | ||
|
||
} | ||
} |