Esempio n. 1
0
 /**
  * @depends testBlocked
  */
 public function testBlock()
 {
     $this->mockGoodReferer();
     ob_start();
     $goodReferer = \Nabble\Semalt::block();
     $output = ob_get_clean();
     $this->assertNull($goodReferer, 'Shouldn\'t return anything');
     $this->assertEmpty($output, 'Shouldn\'t output anything');
     $this->mockBadReferer();
     ob_start();
     $withoutAction = \Nabble\Semalt::block();
     $output = ob_get_clean();
     $explodedExplanation = explode('%s', \Nabble\Semalt::$explanation);
     $this->assertNull($withoutAction, 'Shouldn\'t return anything');
     $this->assertNotNull($output, 'Output shouldn\'t be null');
     $this->assertContains($explodedExplanation[0], $output, 'Should contain explanation');
     ob_start();
     $withMessage = \Nabble\Semalt::block('TEST_MESSAGE');
     $output = ob_get_clean();
     $this->assertNull($withMessage, 'Shouldn\'t return anything');
     $this->assertNotNull($output, 'Output shouldn\'t be null');
     $this->assertContains('TEST_MESSAGE', $output, 'Should contain test message');
     // @todo test headers
 }
Esempio n. 2
0
    if (isset($_GET['url']) && $_GET['url']) {
        function status($code, $redirect = false)
        {
            if (substr($code, 0, 1) == '2') {
                return '<span class="danger">Not blocked</span>';
            }
            if (substr($code, 0, 1) == '3') {
                return '<span class="warning">Redirect </span> &rarr; ' . $redirect;
            }
            return '<span class="success">Blocked</span>';
        }
        ob_implicit_flush(true);
        ob_end_flush();
        $list = [];
        if ($url) {
            $list = \Nabble\Semalt::getBlocklist();
            $client = new \Guzzle\Http\Client(null, array('redirect.disable' => true));
        }
        ?>

                    <div class="progress">
                        <div class="progress-bar progress-bar-success" style="width: 0%"></div>
                        <div class="progress-bar progress-bar-warning" style="width: 0%"></div>
                        <div class="progress-bar progress-bar-danger" style="width: 0%"></div>
                    </div>
                    <table class='table table-bordered table-condensed table-hover' data-total='<?php 
        echo count($list);
        ?>
'>

                    <?php 
Esempio n. 3
0
 public function testDeprecatedBlock()
 {
     $this->mockBadReferer();
     ob_start();
     \Nabble\Semalt::block('TEST_MESSAGE');
     $output = ob_get_clean();
     $this->assertNotNull($output, 'Output shouldn\'t be null');
     $this->assertContains('TEST_MESSAGE', $output, 'Should contain test message');
 }
Esempio n. 4
0
<?php

require '../vendor/autoload.php';
if (\Nabble\Semalt::blocked()) {
    $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
    header($protocol . ' 403 Forbidden');
}
?>
<html>
    <head>
        <title>semalt blocker test target</title>
    </head>
    <body>
        <?php 
echo \Nabble\Semalt::blocked(true);
?>

    </body>
</html>
Esempio n. 5
0
$time_pre = microtime(true);
$i = $c;
while ($i--) {
    \Nabble\Semalt::blocked();
}
echo number_format((microtime(true) - $time_pre) / $c * 1000, 8) . "ms\n";
echo "Testing invalid referer : ";
mockReferer('NotAnUrl');
$time_pre = microtime(true);
$i = $c;
while ($i--) {
    \Nabble\Semalt::blocked();
}
echo number_format((microtime(true) - $time_pre) / $c * 1000, 8) . "ms\n";
echo "Testing good referer    : ";
mockReferer('http://www.google.com/?q=query');
$time_pre = microtime(true);
$i = $c;
while ($i--) {
    \Nabble\Semalt::blocked();
}
echo number_format((microtime(true) - $time_pre) / $c * 1000, 8) . "ms\n";
echo "Testing bad referer     : ";
$domainlist = \Nabble\Semalt::getBlocklist();
mockReferer($domainlist[array_rand($domainlist)]);
$time_pre = microtime(true);
$i = $c;
while ($i--) {
    \Nabble\Semalt::blocked();
}
echo number_format((microtime(true) - $time_pre) / $c * 1000, 8) . "ms\n";
Esempio n. 6
0
<?php

/**
 * Merge a list with the blocked domains
 */
require_once './../vendor/autoload.php';
$semaltBlockerSources = \Nabble\Semalt::getBlocklist();
echo "Old list: " . count($semaltBlockerSources) . " sources\n";
echo "Paste domains (one on each line), then press ENTER twice:\n\n";
$handle = fopen("php://stdin", "r");
$newDomains = [];
while ($line = fgets($handle)) {
    if (trim($line) == '') {
        echo "Done, got " . count($newDomains) . " sources, new domains is ";
        $newList = array_merge($semaltBlockerSources, $newDomains);
        foreach ($newList as &$source) {
            $source = \Nabble\Domainparser::getToplevelDomain($source);
        }
        $newList = array_unique($newList);
        sort($newList);
        echo count($newList) . " sources:\n\n";
        echo implode("\n", $newList) . "\n\n";
        break;
    } else {
        $newDomains[] = trim($line);
    }
}
foreach ($sources as $source => $regex) {
    $raw = file_get_contents($source);
    if (!empty($regex)) {
        preg_match_all($regex, $raw, $list);
        $list = array_filter($list[1], function ($v) {
            return filter_var($v, FILTER_VALIDATE_URL) || filter_var('http://' . $v, FILTER_VALIDATE_URL);
        });
    } else {
        $list = explode("\n", $raw);
    }
    $spammers = array_merge($spammers, $list);
}
// only top-level domains
foreach ($spammers as &$spammer) {
    $spammer = \Nabble\Domainparser::getToplevelDomain($spammer);
}
// merge & cleanup spammers
$spammers = array_merge(\Nabble\Semalt::getBlocklist(), $spammers);
$spammers = array_map('strtolower', $spammers);
$spammers = array_map('trim', $spammers);
$spammers = array_unique($spammers);
$spammers = array_filter($spammers);
sort($spammers);
// echo some info
echo "New list: " . count($spammers) . " sources\n";
// write
if (count($spammers)) {
    file_put_contents('../domains/blocked', implode("\n", $spammers));
}
echo "Done\n";
exit;