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

noplanman's avatar
noplanman committed
3 4
use RedBeanPHP\R;

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

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

noplanman's avatar
noplanman committed
11 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 40 41 42 43
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;
  R::store($c);

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