api-more.php 1.75 KB
Newer Older
dmorley's avatar
dmorley committed
1 2 3 4
<?php
//Copyright (c) 2011, David Morley. This file is licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file.
//this is just a single api for a pod for the android app to get data

noplanman's avatar
noplanman committed
5 6
use RedBeanPHP\R;

dmorley's avatar
dmorley committed
7 8 9 10 11 12
// Required parameters.
($_domain = $_GET['domain'] ?? null) || die('no domain given');

// Other parameters.
$_format = $_GET['format'] ?? '';

noplanman's avatar
noplanman committed
13
require_once __DIR__ . '/../vendor/autoload.php';
David Morley's avatar
David Morley committed
14
require_once __DIR__ . '/../config.php';
dmorley's avatar
dmorley committed
15

noplanman's avatar
noplanman committed
16 17 18 19 20
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
21
R::usePartialBeans(true);
noplanman's avatar
noplanman committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35

try {
  $pod = R::getRow('
    SELECT hgitdate, id, domain, status, secure, score, userrating, adminrating, city, state, country, lat, long, ip, ipv6, pingdomurl, monthsmonitored, uptimelast7, responsetimelast7, local_posts, comment_counts, dateCreated, dateUpdated, dateLaststats, hidden
    FROM pods_apiv1
    WHERE domain = ?
  ', [$_domain]);
} catch (\RedBeanPHP\RedException $e) {
  die('Error in SQL query: ' . $e->getMessage());
}

if ($_format === 'json') {
  echo json_encode($pod);
} else {
dmorley's avatar
dmorley committed
36 37 38 39 40 41
  if ($pod['status'] === PodStatus::Up) {
    echo 'Status: Up<br>';
  }
  if ($pod['status'] === PodStatus::Down) {
    echo 'Status: Down<br>';
  }
noplanman's avatar
noplanman committed
42 43 44 45 46 47 48 49
  echo 'Last Git Pull: ' . $pod['hgitdate'] . '<br>';
  echo 'Uptime This Month ' . $pod['uptimelast7'] . '<br>';
  echo 'Months Monitored: ' . $pod['monthsmonitored'] . '<br>';
  echo 'Response Time: ' . $pod['responsetimelast7'] . '<br>';
  echo 'User Rating: ' . $pod['userrating'] . '<br>';
  echo 'Server Location: ' . $pod['country'] . '<br>';
  echo 'Latitude: ' . $pod['lat'] . '<br>';
  echo 'Longitude: ' . $pod['long'] . '<br>';
dmorley's avatar
dmorley committed
50
}