api-more.php 1.4 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
dmorley committed
6 7 8 9
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
if (!$dbh) {
  die("Error in connection: " . pg_last_error());
}  
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
dmorley committed
11 12 13 14 15
$result = pg_query_params($dbh, $sql, array($_GET['url']));
if (!$result) {
  die("Error in SQL query: " . pg_last_error());
}   
while ($row = pg_fetch_array($result)) {
David Morley's avatar
David Morley committed
16 17 18
  if ($_GET['format'] == "json") {
    echo json_encode($row);
  } else {
dmorley's avatar
dmorley committed
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
dmorley committed
29 30 31
}
pg_free_result($result);       
pg_close($dbh);