Beispiel #1
0
 /**
  * @depends testBlocked
  */
 public function testBlock()
 {
     $this->mockGoodReferer();
     ob_start();
     \Nabble\SemaltBlocker\Blocker::protect();
     $output = ob_get_clean();
     $this->assertEmpty($output, 'Shouldn\'t output anything');
     $this->mockBadReferer();
     ob_start();
     \Nabble\SemaltBlocker\Blocker::protect();
     $output = ob_get_clean();
     $explodedExplanation = explode('%s', \Nabble\SemaltBlocker\Blocker::$explanation);
     $this->assertNotNull($output, 'Output shouldn\'t be null');
     $this->assertContains($explodedExplanation[0], $output, 'Should contain explanation');
     ob_start();
     \Nabble\SemaltBlocker\Blocker::protect('TEST_MESSAGE');
     $output = ob_get_clean();
     $this->assertNotNull($output, 'Output shouldn\'t be null');
     $this->assertContains('TEST_MESSAGE', $output, 'Should contain test message');
     ob_start();
     \Nabble\SemaltBlocker\Blocker::protect('http://www.google.com');
     $output = ob_get_clean();
     $this->assertNotNull($output, 'Output shouldn\'t be null');
     // @todo test headers
 }
Beispiel #2
0
 public function __bootstrap()
 {
     \Nabble\SemaltBlocker\Blocker::protect();
     Ajde_Event::register('TransactionModel', 'onPaid', [$this, 'onTransactionPaid']);
     Ajde_Event::register('TransactionModel', 'onCreate', [$this, 'onTransactionCreated']);
     if (UserModel::isTester() || UserModel::isAdmin()) {
         $providers = config('shop.transaction.providers');
         $providers[] = 'test';
         Config::set('shop.transaction.providers', $providers);
     }
     return true;
 }
Beispiel #3
0
<?php

/**
 * Export domains to various formats
 */
require_once './../vendor/autoload.php';
$domainsDir = __DIR__ . DIRECTORY_SEPARATOR . './../domains/';
$domains = \Nabble\SemaltBlocker\Blocker::getBlocklist();
file_put_contents($domainsDir . 'blocked.json', json_encode($domains, JSON_PRETTY_PRINT) . PHP_EOL);
echo "Written json file\n";
file_put_contents($domainsDir . 'blocked.csv', implode(PHP_EOL, array_map(function ($item) {
    return '"' . $item . '"';
}, $domains)) . PHP_EOL);
echo "Written csv file\n";
$xml = "<domains>" . PHP_EOL;
foreach ($domains as $domain) {
    $xml .= "\t<domain>" . $domain . "</domain>" . PHP_EOL;
}
$xml .= "</domains>" . PHP_EOL;
file_put_contents($domainsDir . 'blocked.xml', $xml);
echo "Written xml file\n";
$htaccess = "<IfModule mod_setenvif.c>" . PHP_EOL;
foreach ($domains as $domain) {
    $htaccess .= "\tSetEnvIfNoCase Referer " . $domain . " spambot=yes" . PHP_EOL;
}
$htaccess .= "</IfModule>";
file_put_contents($domainsDir . 'blocked.conf', $htaccess);
echo "Written apache conf file\n";
echo "Done\n";
exit;
Beispiel #4
0
$time_pre = microtime(true);
$i = $c;
while ($i--) {
    \Nabble\SemaltBlocker\Blocker::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\SemaltBlocker\Blocker::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\SemaltBlocker\Blocker::blocked();
}
echo number_format((microtime(true) - $time_pre) / $c * 1000, 8) . "ms\n";
echo "Testing bad referer     : ";
$domainlist = \Nabble\SemaltBlocker\Blocker::getBlocklist();
mockReferer($domainlist[array_rand($domainlist)]);
$time_pre = microtime(true);
$i = $c;
while ($i--) {
    \Nabble\SemaltBlocker\Blocker::blocked();
}
echo number_format((microtime(true) - $time_pre) / $c * 1000, 8) . "ms\n";
Beispiel #5
0
                $annotated['d' . crc32($cleaned . '-' . $source)] = (object) ['url' => $url, 'source' => $source, 'added' => date('c')];
            }
        }
    }
}
uasort($annotated, function ($a, $b) {
    if ($a->url . $a->source == $b->url . $b->source) {
        return 0;
    }
    return $a->url . $a->source < $b->url . $b->source ? -1 : 1;
});
file_put_contents('../domains/annotated.json', json_encode((object) $annotated, JSON_PRETTY_PRINT));
echo "Updated annotated.json\n";
// merge & cleanup spammers
if ($includeOldList) {
    $spammers = array_merge(Blocker::getBlocklist(), $spammers);
}
// cleanup
foreach ($spammers as &$spammer) {
    $spammer = clean($spammer, $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) . PHP_EOL);
}
echo "Updated blocklist\n";
Beispiel #6
0
<?php

$BLOCKLIST = __DIR__ . DIRECTORY_SEPARATOR . 'blocked';
copy(__DIR__ . DIRECTORY_SEPARATOR . './../domains/blocked', $BLOCKLIST);
chmod($BLOCKLIST, 0777);
include 'semaltblocker.php';
$_SERVER["HTTP_REFERER"] = 'http://semalt.com';
try {
    // Test blocking
    $expected = 'Blocking because referral domain (semalt.com) is found on blocklist';
    $actual = \Nabble\SemaltBlocker\Blocker::blocked(true);
    if (!@assert($expected === $actual)) {
        throw new Exception('Blocking domains failed');
    }
    // Test updating
    file_put_contents($BLOCKLIST, '');
    \Nabble\SemaltBlocker\Updater::update(true);
    $expected = \Nabble\SemaltBlocker\Updater::getNewDomainList();
    $actual = file_get_contents($BLOCKLIST);
    if (!@assert($expected === $actual)) {
        throw new Exception('Updating domains failed');
    }
} catch (Exception $e) {
    echo $e->getMessage() . '<br/>' . PHP_EOL;
}
echo 'All tests finished' . PHP_EOL;
unlink($BLOCKLIST);
Beispiel #7
0
        }
        function statusHtml($status, $redirect = null)
        {
            if ($status == STATUS_RED) {
                return '<span class="danger">Not blocked</span>';
            }
            if ($status == STATUS_ORANGE) {
                return '<span class="warning">Redirect </span> &rarr; <a href="?url=' . urlencode($redirect) . '">' . $redirect . '</a>';
            }
            return '<span class="success">Blocked</span>';
        }
        ob_implicit_flush(true);
        ob_end_flush();
        $list = [];
        if ($url) {
            $list = \Nabble\SemaltBlocker\Blocker::getBlocklist();
            $client = new \Guzzle\Http\Client(null, array('redirect.disable' => true));
        }
        ?>

        <p><a href=".">recent scores</a></p>
        <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);
        ?>
'>
Beispiel #8
0
<?php

require '../vendor/autoload.php';
if (\Nabble\SemaltBlocker\Blocker::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\SemaltBlocker\Blocker::blocked(true);
?>

    </body>
</html>
                return filter_var($v, FILTER_VALIDATE_URL) || filter_var('http://' . $v, FILTER_VALIDATE_URL);
            });
        } else {
            $list = explode("\n", $raw);
        }
    }
    echo $source . " contains " . count($list) . " source(s)\n";
    $spammers = array_merge($spammers, $list);
}
// only top-level domains
foreach ($spammers as &$spammer) {
    $spammer = \Nabble\SemaltBlocker\Domainparser::getRootDomain($spammer);
}
// merge & cleanup spammers
if ($includeOldList) {
    $spammers = array_merge(\Nabble\SemaltBlocker\Blocker::getBlocklist(), $spammers);
}
$spammers = array_map('strtolower', $spammers);
$spammers = array_map('trim', $spammers);
$punicode = new \TrueBV\Punycode();
foreach ($spammers as &$spammer) {
    $spammer = iconv("UTF-8", "ISO-8859-1", $punicode->encode($spammer));
}
$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) . PHP_EOL);