api-more.php 1.41 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
require_once __DIR__ . '/../config.php';

dmorley's avatar
cleanup  
dmorley committed
6 7
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
if (!$dbh) {
8
  die('Error in connection: ' . pg_last_error());
dmorley's avatar
cleanup  
dmorley committed
9
}  
David Morley's avatar
David Morley committed
10
$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";
dmorley's avatar
cleanup  
dmorley committed
11 12
$result = pg_query_params($dbh, $sql, array($_GET['url']));
if (!$result) {
13
  die('Error in SQL query: ' . pg_last_error());
dmorley's avatar
cleanup  
dmorley committed
14 15
}   
while ($row = pg_fetch_array($result)) {
16
  if ($_GET['format'] == 'json') {
David Morley's avatar
David Morley committed
17 18
    echo json_encode($row);
  } else {
19 20 21 22 23 24 25 26 27
  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>';
  echo 'Server Location: ' . $row['country'] . '<br>';
  echo 'Latitude: ' . $row['lat'] . '<br>';
  echo 'Longitude: ' . $row['long'] . '<br>';
David Morley's avatar
David Morley committed
28
  }
dmorley's avatar
cleanup  
dmorley committed
29 30 31
}
pg_free_result($result);       
pg_close($dbh);