This repository has been archived by the owner on Oct 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
torcheck.php
78 lines (63 loc) · 1.86 KB
/
torcheck.php
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
<?php
error_reporting(E_ALL);
class TorCheck
{
public $ip_list_exit_file = "/tmp/Tor_ip_list_EXIT.csv";
public $ip_list_exit_local = "/var/lib/tor/cached-consensus";
public $ip_list_exit_url = "http://torstatus.blutmagie.de/ip_list_exit.php/Tor_ip_list_EXIT.csv";
public $expiry = 3600;
public $fetchmethod = "local";
public $exit_list = array();
function __construct($method) {
if ( $method) {
$this->fetchmethod = $method;
}
if ( $this->fetchmethod == "localsh" ) {
system("cat ".$this->ip_list_exit_local."| grep \"^s Exit\" -B1 | grep \"^r \" | cut -d ' ' -f7 > ".$this->ip_list_exit_file, $ret);
} else {
if (
!(file_exists($this->ip_list_exit_file)) ||
(filemtime($this->ip_list_exit_file) - time()) > $this->expiry
) {
file_put_contents($this->ip_list_exit_file, file_get_contents($this->ip_list_exit_url));
}
}
$exit_list = file($this->ip_list_exit_file);
foreach ($exit_list as $ip) {
array_push($this->exit_list, trim($ip));
}
}
function check($ip) {
if(in_array($ip, $this->exit_list)) {
return true;
}
else {
return false;
}
}
}
# $ip = "10.10.1.1";
# Instantiate with local for local file retrieval
# Default method
$tor = new TorCheck("local");
$ip = $_SERVER['REMOTE_ADDR'];
$callback = $_GET['callback'];
if(!preg_match("/^[a-z0-9&_=]+$/i", $callback)) {
echo ":P...";
exit;
} else {
$result = array("Tor" => $tor->check($ip));
echo $_GET['callback'] . '(' . json_encode($result) . ');';
}
/*
if($tor->check($ip)) {
echo "You are using Tor\n";
} else {
if($ip == "127.0.0.1") {
echo "You are conneting through localhost\n";
} else {
echo "You are not using Tor\n";
}
}
*/
?>