]>
jfr.im git - irc/SurrealServices/srsv.git/blob - branches/0.4.3/SrSv/TOR.pm
3 # This file is part of SurrealServices.
5 # SurrealServices is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # SurrealServices is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with SurrealServices; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 Parses the TOR router list for exit-nodes, and optionally
21 for exit-nodes that can connect to our services.
23 Interface still in progress.
29 use Exporter
'import';
30 BEGIN { our @EXPORT = qw( getTorRouters ); }
35 if($URI =~ s/^file:\/\///i) {
37 $fh = IO
::File-
>new($URI, 'r') or die;
41 $fh = IO
::Pipe-
>new();
42 $fh->reader(qq(wget -q -O - $URI)) or die;
52 'router' => \
&TOR_router
,
53 'reject' => \
&TOR_reject
,
54 'accept' => \
&TOR_accept
,
58 sub parseTorRouterList
($) {
60 our (%currentRouter, @routerList);
61 foreach my $l (<$fh>) {
62 my ($tok, undef) = split(' ', $l, 2);
65 if(my $code = $TOR_cmdhash{$tok}) {
71 #r atari i2i65Qm8DXfRpHVk6N0tcT0fxvs djULF2FbASFyIzuSpH1Zit9cYFc 2007-10-07 00:19:17 85.31.187.200 9001 9030
72 my (undef, $name, undef, undef, undef, $ip, $in_port, $dir_port) = split(' ', $l);
73 %currentRouter = ( NAME
=> $name, IP
=> $ip, IN_PORT
=> $in_port, DIR_PORT
=> $dir_port );
79 #s Exit Fast Guard Stable Running V2Dir Valid
81 # uncomment the conditional if you trust the router status flags
82 #if($tokens =~ /Exit/) {
83 push @routerList, $currentRouter{IP
};
89 my (undef, $name, $ip, $in_port, undef, $dir_port) = split(' ', $l);
90 push @routerList, processTorRouter
(%currentRouter) if scalar(%currentRouter);
91 %currentRouter = ( NAME
=> $name, IP
=> $ip, IN_PORT
=> $in_port, DIR_PORT
=> $dir_port );
96 my ($tok, $tuple) = split(' ', $l);
97 my ($ip, $ports) = split(':', $tuple);
98 push @{$currentRouter{REJECT
}}, "$ip:$ports";
102 my ($tok, $tuple) = split(' ', $l);
103 my ($ip, $ports) = split(':', $tuple);
104 push @{$currentRouter{ACCEPT
}}, "$ip:$ports";
110 sub processTorRouter
(%) {
111 # only used for v1, and possibly v3
112 my (%routerData) = @_;
113 my @rejectList = ( $routerData{REJECT
} and scalar(@{$routerData{REJECT
}}) ? @{$routerData{REJECT
}} : () );
114 my @acceptList = ( $routerData{ACCEPT
} and scalar(@{$routerData{ACCEPT
}}) ? @{$routerData{ACCEPT
}} : () );
115 return () if $routerData{IP
} =~ /^(127|10|192\.168)\./;
116 if ( (scalar(@rejectList) == 1) and ($rejectList[0] eq '*:*') ) {
117 #print STDERR "$routerData{IP} is not an exit node.\n";
120 #print STDERR "$routerData{IP} is an exit node.\n";
121 return ($routerData{IP
});
125 sub getTorRouters
($) {
127 return parseTorRouterList
(openURI
($URI));