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

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

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

noplanman's avatar
noplanman committed
9
require_once __DIR__ . '/vendor/autoload.php';
10 11
require_once __DIR__ . '/config.php';

noplanman's avatar
noplanman committed
12 13 14 15 16
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');
dmorley's avatar
dmorley committed
17
R::usePartialBeans(true);
noplanman's avatar
noplanman committed
18 19 20 21 22 23 24 25 26 27 28 29

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
dmorley's avatar
dmorley committed
30 31
        AND uptime_alltime > 96
        AND monthsmonitored > 2
noplanman's avatar
noplanman committed
32 33 34 35 36 37 38 39 40 41
        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
42 43 44
  if (!(new CrawlerDetect())->isCrawler()) {
    R::store($c);
  }
noplanman's avatar
noplanman committed
45 46 47 48

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