User:SQLBot/ctor2.php

From Wikipedia, the free encyclopedia

<?php
include("SxWiki.php");
include("config.php");
 
function checktorbl ($addr) {
        $flags = array();
        $flags['tor'] = "no";
        $p = explode(".", $addr);
        $ahbladdr = $p[3] . "." . $p[2] . "." . $p[1] . "." . $p[0] . "." . "tor.ahbl.org";;
        $ahbl = gethostbyname($ahbladdr);
        if ($ahbl == "127.0.0.2") { $flags['transit'] = "yes"; "yes"; $flags['tor'] = "yes";}
        if ($ahbl == "127.0.0.3") { $flags['exit'] = "yes"; "yes"; $flags['tor'] = "yes";}
        $kewladdr = $p[3] . "." . $p[2] . "." . $p[1] . "." . $p[0] . "." . "torexit.kewlio.net.uk";;
        $kewlbl = gethostbyname($kewladdr);
        if ($kewlbl == "127.0.0.100") { $flags['exit'] = "yes"; $flags['tor'] = "yes"; }
        return($flags);
}
 
echo "Getting category ";
$supp_tor_blocked = sxGetCat("Tor proxies blocked on Wikipedia", "3");
echo "\nChecking for blocked IP's ";
$blocked_tor = array();
$unblocked_tor = array();
$blockedby = array();
foreach($supp_tor_blocked as $stor_u) {
        $totaltor++;
        $stor_u = ltrim($stor_u);
        $stor_u = rtrim($stor_u);
        preg_match("/User talk:(.*)/", $stor_u, $matches);
        $isblocked = sxIsBlocked($matches[1], 1);
        $stor_u = $matches[1];
        if($isblocked === FALSE) {
                array_push($unblocked_tor, $stor_u);       
                echo "!";
                $numublocked++;
        } else {
                if(!is_array($blockedby[$stor_u])) {$blockedby[$stor_u] = array();}
                array_push($blocked_tor, $stor_u);
                array_push($blockedby[$stor_u], $isblocked[5]);
                echo ".";
                $numblocked++;
        }
}
 
$legit_block = array();
$nolegit  = array();
$goodblocks = array();
$badblocks = array();
echo "\nChecking blocked addresses against DNSBL's\n";
foreach ($blocked_tor as $ator) {
        $legit = "no";
        $ator = ltrim($ator);
        $ator = rtrim($ator);
        $tor_status = checktorbl($ator);
        if($tor_status['tor'] == "no") {
                        array_push($nolegit, $ator);
                        $bb_admin = $blockedby[$ator][0];
                        $badblocks[$bb_admin]++;
                        $nntor++;
                        echo "N";
        }
        if($tor_status['tor'] == "yes") {
                $gb_admin = $blockedby[$ator][0];
                $goodblocks[$gb_admin]++;
                if($tor_status['exit'] == "yes" && $tor_status['transit'] == "yes") {
                        $ator1 = $ator . " '''TRANSIT'''/'''EXIT'''";
                        array_push($legit_block, $ator1);
                        $ntor++;
                        echo "B";
                } else {
                        if($tor_status['transit'] == "yes") {
                                $ator1 = $ator . " '''TRANSIT'''";
                                array_push($legit_block, $ator1);
                                $ntor++;
                                echo "T";
                        }
                        if($tor_status['exit'] == "yes") {
                                $ator1 = $ator . " '''EXIT'''";
                                array_push($legit_block, $ator1);
                                $ntor++;
                                echo "E";
                        }
                }
        }
}
echo "\nPreparing output...\n";
$out = "This is a list, based on [[:Category:Tor proxies blocked on Wikipedia]], which, in turn is based on User talk pages, that transclude {{t1|tor}}. Listed below, are addresses in this cat that aren't blocked, addresses that are confirmed as tor nodes, and, addresses that are probably no longer TOR nodes (or, that no longer allow wikipedia exit) Changes to this page will be wiped out with each bot run. If you need to add something to the page, please use the talkpage.\n\n__TOC__\n\n";
$pblocked = $numblocked / $totaltor;
$pblocked = $pblocked * 100;
$pblocked = round($pblocked, 2);
$btor = $ntor + $nntor;
$bptor = $nntor / $btor;
$bptor = $bptor * 100;
$bptor = round($bptor, 2);
$out = $out . "==Stats==\n\n* Total in this category: $totaltor\n* Number not blocked: $numublocked\n* Number blocked: $numblocked\n* Percent blocked: $pblocked%\n* Number probably not TOR: $nntor\n* Number confirmed TOR: $ntor\n* Percent blocked, but probably not tor: $bptor%\n\n==See also==\n\n* [[User:SQL/Funky_TOR/Admin_Stats]]\n* [[User:SQL/Unblocked_TOR]]\n* [[Wikipedia:Blocking Policy]]\n* [[Wikipedia:No Open Proxies]]\n\n";
 
$out = $out . "==Not Blocked==\n\n";
foreach ($unblocked_tor as $unblocked) {
        $out = $out . "# {{User:SQL/TORUser|" . $unblocked . "}}\n";
}
$out = $out . "==Blocked==\n";
$out = $out . "===Blocked, Not TOR===\n\n";
foreach ($nolegit as $a_no) {
        $out = $out . "# {{User:SQL/TORUser2|" . $a_no . "}}\n";
}
$out = $out . "===Blocked, Confirmed TOR===\n\n";
foreach ($legit_block as $a_yea) {
        $l_blinfo = explode(" ", $a_yea);
        $out = $out . "# {{User:SQL/TORUser3|" . $l_blinfo[0] . "}} " . $l_blinfo[1] . "\n";
}
echo "Posting List...\n";
sxPutPage("User:SQL/Funky_TOR", "Testing for TOR blocks that may no longer be valid", $out, NULL, "1");
echo "Preparing Admin_Stats...\n";
arsort($goodblocks);
arsort($badblocks);
$s_out = "This is a simple statistics page. It lists, statistics for admins whom presently have active blocks on users who's talkpages are presently tagged with {{t1|tor}}. An admin having a lot of blocks in one category or another, is by no means an indication that they are a good or bad admin, as {{t1|tor}} templates may be added or removed, before or after the block, and, may or may no even be relevant to the block.\n==TOR==\n\n";
 
foreach ($goodblocks as $gbad => $gbnumber) {
        $s_out = $s_out . "* [[$gbad]], $gbnumber\n";
}
 
$s_out = $s_out . "\n==Not TOR==\n\n";
foreach ($badblocks as $bbad => $bbnumber) {
        $s_out = $s_out . "* [[$bbad]], $bbnumber\n";
}
echo "Posting Admin_Stats...\n";
sxPutPage("User:SQL/Funky_TOR/Admin_Stats", "Posting Admin stats on TOR blocks", $s_out, NULL, "1");
echo "Done.\n\n";
?>