go.php 1.13 KB
Newer Older
dmorley's avatar
dmorley committed
1
<?php
2

3
use RedBeanPHP\R;
David Morley's avatar
David Morley committed
4
use Jaybizzle\CrawlerDetect\CrawlerDetect;
5

6
// Other parameters.
7
$_domain = $_GET['domain'] ?? '';
8

9
require_once __DIR__ . '/vendor/autoload.php';
10 11
require_once __DIR__ . '/config.php';

12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
define('PODUPTIME', microtime(true));

// Set up global DB connection.
R::setup("pgsql:host={$pghost};dbname={$pgdb}", $pguser, $pgpass, true);
R::testConnection() || die('Error in DB connection');

try {
  if ($_domain) {
    $click  = 'manualclick';
    $domain = R::getCell('SELECT domain FROM pods WHERE domain LIKE ?', [$_domain]);
    $domain || die('unknown domain');
  } else {
    $click  = 'autoclick';
    $domain = R::getCell('
      SELECT domain
      FROM pods
      WHERE signup
        AND score > 90
        AND pods.masterversion = shortversion
      ORDER BY random()
      LIMIT 1
    ');
    $domain || die('no domains exist');
  }

  $c           = R::dispense('clicks');
  $c['domain'] = $domain;
  $c[$click]   = 1;
David Morley's avatar
David Morley committed
40 41 42
  if (!(new CrawlerDetect())->isCrawler()) {
    R::store($c);
  }
43 44 45 46

  header('Location: https://' . $domain);
} catch (\RedBeanPHP\RedException $e) {
  die('Error in SQL query: ' . $e->getMessage());
47
}