Commit 04f9aeaf authored by David Morley's avatar David Morley

fix api more

parent 56677aca
<?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
include('config.php');
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
if (!$dbh) {
die("Error in connection: " . pg_last_error());
}
$sql = "SELECT * FROM pods WHERE domain = $1";
$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)) {
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>";
}
pg_free_result($result);
pg_close($dbh);
?>
db/api-more.php
\ No newline at end of file
...@@ -45,7 +45,7 @@ EOF; ...@@ -45,7 +45,7 @@ EOF;
echo "</feed>"; echo "</feed>";
} }
elseif ($_GET['format'] == "json") { elseif ($_GET['format'] == "json") {
$sql = "SELECT id,domain,status,secure,score,userrating,adminrating,city,state,country,lat,long,ip,ipv6,hgitdate,hgitref,pingdomurl,pingdomlast,monthsmonitored,uptimelast7,responsetimelast7,hruntime,hencoding,local_posts,comment_counts,dateCreated,dateUpdated,dateLaststats,hidden FROM pods"; $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";
$result = pg_query($dbh, $sql); $result = pg_query($dbh, $sql);
if (!$result) { if (!$result) {
die("Error in SQL query: " . pg_last_error()); die("Error in SQL query: " . pg_last_error());
......
...@@ -6,12 +6,15 @@ $dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass"); ...@@ -6,12 +6,15 @@ $dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
if (!$dbh) { if (!$dbh) {
die("Error in connection: " . pg_last_error()); die("Error in connection: " . pg_last_error());
} }
$sql = "SELECT * FROM pods WHERE domain = $1"; $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, array($_GET['url'])); $result = pg_query_params($dbh, $sql, array($_GET['url']));
if (!$result) { if (!$result) {
die("Error in SQL query: " . pg_last_error()); die("Error in SQL query: " . pg_last_error());
} }
while ($row = pg_fetch_array($result)) { while ($row = pg_fetch_array($result)) {
if ($_GET['format'] == "json") {
echo json_encode($row);
} else {
echo "Status: " . $row["status"] . "<br>"; echo "Status: " . $row["status"] . "<br>";
echo "Last Git Pull: " . $row["hgitdate"] . "<br>"; echo "Last Git Pull: " . $row["hgitdate"] . "<br>";
echo "Uptime This Month " . $row["uptimelast7"] . "<br>"; echo "Uptime This Month " . $row["uptimelast7"] . "<br>";
...@@ -21,6 +24,7 @@ while ($row = pg_fetch_array($result)) { ...@@ -21,6 +24,7 @@ while ($row = pg_fetch_array($result)) {
echo "Server Location: ". $row["country"] . "<br>"; echo "Server Location: ". $row["country"] . "<br>";
echo "Latitude: ". $row["lat"] . "<br>"; echo "Latitude: ". $row["lat"] . "<br>";
echo "Longitude: ". $row["long"] . "<br>"; echo "Longitude: ". $row["long"] . "<br>";
}
} }
pg_free_result($result); pg_free_result($result);
pg_close($dbh); pg_close($dbh);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment