Topic: Optional disable of posting and registering for Tor users

If any coders have some spare time big_smile
I'd love to be able to set in my admin panel

X   Disable users from Tor network to post  ( if user <3 posts)
X   Disable users from Tor network to register


[code=php]
<?php
/* NOTES on Irongeek's TorOrNot script:
To use this php script on some pages it will need it to have a png extension.
To do this, put a redirect from a png file to the php file in your apache config file (httpd.conf) or .htaccess.
Example line:
Redirect /torornot.png /torornot.php

Consider this code to be GPLed, but I'd love for you to email me at Irongeek (at) irongeek.com with any changes you make.
More information about using php and images can be found at http://us3.php.net/manual/en/ref.image.php
More information on detecting Tor exit nodes with TorDNSEL see https://www.torproject.org/tordnsel/

Adrian Crenshaw
http://www.irongeek.com
*/
header("Content-type: image/png");
//header("Content-type: text/html");
if (IsTorExitPoint()) {
$im = imagecreatefrompng("tor.png");
}else{
$im = imagecreatefrompng("nottor.png");
}
imageAlphaBlending($im, true);
imageSaveAlpha($im, true);
imagepng($im);
imagedestroy($im);

function IsTorExitPoint(){
if (gethostbyname(ReverseIPOctets($_SERVER['REMOTE_ADDR']).".".$_SERVER['SERVER_PORT'].".".ReverseIPOctets($_SERVER['SERVER_ADDR']).".ip-port.exitlist.torproject.org")=="127.0.0.2") {
return true;
} else {
return false;
}
}
function ReverseIPOctets($inputip){
$ipoc = explode(".",$inputip);
return $ipoc[3].".".$ipoc[2].".".$ipoc[1].".".$ipoc[0];
}
?>
[/code]

source: http://www.irongeek.com/i.php?page=secu … ode-in-php

Re: Optional disable of posting and registering for Tor users

or maybe with something like this:

###########################
#below is another code example I found#
###########################

RE: BANNING TOR NETWORK EXIT NODES

Not bad blacksuns' method, but i like doing things my way
Here we go:



[code=php]
#!/usr/local/bin/php
<?php
//there are several servers monitoring tor network status,
//uncomment the one you find more appealing smile
//$curl = curl_init('http://torstatus.kgprog.com/ip_list_exit.php/Tor_ip_list_EXIT.csv');
//$curl = curl_init('https://torstatus.all.de/ip_list_exit.php/Tor_ip_list_EXIT.csv');
//$curl = curl_init('http://torstatus.amorphis.eu/ip_list_exit.php/Tor_ip_list_EXIT.csv');
//$curl = curl_init('http://torstatus.cyberphunk.org/ip_list_exit.php/Tor_ip_list_EXIT.csv');
//$curl = curl_init('http://tns.hermetix.org/ip_list_exit.php/Tor_ip_list_EXIT.csv');
$curl = curl_init('http://torstatus.blutmagie.de/ip_list_exit.php/Tor_ip_list_EXIT.csv');
$fp = fopen('/tmp/tor_nodes', 'w');
curl_setopt($curl, CURLOPT_FILE, $fp);
curl_exec($curl);
curl_close($curl);
fclose($fp);

$db = mysql_connect('host', 'user', 'pass');//replace with your values
mysql_select_db('verlihub', $db);
mysql_query('TRUNCATE TABLE tor_nodes');//faster than DELETE FROM...
$row = 1;
$file = fopen('/tmp/tor_nodes', 'r');
while (($data = fgetcsv($file, 16, '\n')) !== FALSE)
{
    $num = count($data);
    $row++;
    for ($c=0; $c < $num; $c++)
   {
        //echo $data[$c] . "<br />";//if you need some testing
        mysql_query("INSERT INTO tor_nodes(node_ip) VALUES('$data[$c]')", $db);
    }
}
fclose($file);
mysql_close($db);
?>
[/code]

Next, we need a table, something like the folowing will do:

CREATE TABLE tor_nodes (node_ip varchar(16) NOT NULL);

No indexes, no fluff, only one column. If you find MyISAM too slow, convert to MEMORY (HEAP), the amount of data is very small, and the speed excellent. Now put the script into a cronjob(hence the shebang), running it hourly won't kill anyone.
So, we have everything up to date, a lua script is all we need, fortunately our friend Shagrath® shared one, to serve as starting point (thank you). Here we go:

foo = 1
function VH_OnUserLogin(nick)
      local res, OpChat = VH:GetConfig("config", "opchat_name")
      local res, userIP = VH:GetUserIP(nick)
      local res, host = VH:GetUserHost(nick)
      local query = "SELECT node_ip FROM tor_nodes WHERE node_ip = '"..userIP.."'"
      res, match = VH:SQLQuery(query)
      if match >= foo then
        VH:SendDataToUser("<BOFH> This hub doesn't accept connections from tor exit nodes. Bye.|",nick) --let him know what happened
         VH:SendPMToAll("Tor user detected, disconnecting... :)\nnick:\t"..nick.."\nIp:\t"..userIP.."\nHost:\t"..host.."\t Neeext!|", OpChat, 3, 10)
         VH:CloseConnection(nick)
      end
   return true
end

That's it, now run your benchmarks

**Edit: added VH:SendDataToUser, let the tor/proxy rider know what is going on.


source: http://forums.verlihub-project.org/view … amp;t=4691