api-more.php 1.61 KB
Newer Older
1
<?php
2
//Copyright (c) 2011, David Morley. This file is licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file.
3
//this is just a single api for a pod for the android app to get data
4 5 6 7 8 9 10

// Required parameters.
($_url = $_GET['url'] ?? null) || die('no url given');

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

11 12
require_once __DIR__ . '/../config.php';

dmorley's avatar
cleanup  
dmorley committed
13
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
14 15
$dbh || die('Error in connection: ' . pg_last_error());

16 17
$sql    = 'SELECT 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 WHERE domain = $1';
$result = pg_query_params($dbh, $sql, [$_url]);
18 19
$result || die('Error in SQL query: ' . pg_last_error());

dmorley's avatar
cleanup  
dmorley committed
20
while ($row = pg_fetch_array($result)) {
21
  if ($_format === 'json') {
David Morley's avatar
David Morley committed
22 23
    echo json_encode($row);
  } else {
24 25 26 27 28 29
    echo 'Status: ' . $row['status'] . '<br>';
    echo 'Last Git Pull: ' . $row['hgitdate'] . '<br>';
    echo 'Uptime This Month ' . $row['uptimelast7'] . '<br>';
    echo 'Months Monitored: ' . $row['monthsmonitored'] . '<br>';
    echo 'Response Time: ' . $row['responsetimelast7'] . '<br>';
    echo 'User Rating: ' . $row['userrating'] . '<br>';
30 31 32
    echo 'Server Country: ' . $row['country'] . '<br>';
    echo 'Server State: ' . $row['state'] . '<br>';
    echo 'Server City: ' . $row['city'] . '<br>';
33 34
    echo 'Latitude: ' . $row['lat'] . '<br>';
    echo 'Longitude: ' . $row['long'] . '<br>';
David Morley's avatar
David Morley committed
35
  }
dmorley's avatar
cleanup  
dmorley committed
36
}
37
pg_free_result($result);
dmorley's avatar
cleanup  
dmorley committed
38
pg_close($dbh);