Commit 296c66d7 authored by dmorley's avatar dmorley

sql cleanup

parent af3fa032
db/api-more.php
\ No newline at end of file
<?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
// Required parameters.
($_domain = $_GET['domain'] ?? null) || die('no domain given');
// Other parameters.
$_format = $_GET['format'] ?? '';
require_once __DIR__ . '/config.php';
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
$dbh || die('Error in connection: ' . pg_last_error());
$sql = 'SELECT id,domain,status,secure,score,userrating,adminrating,city,state,country,lat,long,ip,ipv6,statsurl,monthsmonitored,uptime_alltime,responsetimems,local_posts,comment_counts,dateCreated,dateUpdated,dateLaststats,hidden FROM pods WHERE domain = $1';
$result = pg_query_params($dbh, $sql, [$_domain]);
$result || die('Error in SQL query: ' . pg_last_error());
while ($row = pg_fetch_array($result)) {
if ($_format === 'json') {
echo json_encode($row);
} else {
echo 'Status: ' . $row['status'] . '<br>';
echo 'Last Git Pull: ' . $row['hgitdate'] . '<br>';
echo 'Uptime This Month ' . $row['uptime_alltime'] . '<br>';
echo 'Months Monitored: ' . $row['monthsmonitored'] . '<br>';
echo 'Response Time: ' . $row['responsetimems'] . '<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);
...@@ -21,7 +21,7 @@ if ($_format === 'georss') { ...@@ -21,7 +21,7 @@ if ($_format === 'georss') {
<link href="https://podupti.me/"/> <link href="https://podupti.me/"/>
EOF; EOF;
$sql = "SELECT * FROM pods WHERE hidden <> 'yes'"; $sql = "SELECT * FROM pods WHERE NOT hidden";
$result = pg_query($dbh, $sql); $result = pg_query($dbh, $sql);
$result || die('Error in SQL query: ' . pg_last_error()); $result || die('Error in SQL query: ' . pg_last_error());
...@@ -32,12 +32,12 @@ EOF; ...@@ -32,12 +32,12 @@ EOF;
'This pod %1$s has been watched for %2$s months and its average ping time is %3$s with uptime of %4$s%% this month and was last checked on %5$s. On a score of 100 this pod is a %6$s right now', 'This pod %1$s has been watched for %2$s months and its average ping time is %3$s with uptime of %4$s%% this month and was last checked on %5$s. On a score of 100 this pod is a %6$s right now',
$pod_name, $pod_name,
$row['monthsmonitored'], $row['monthsmonitored'],
$row['responsetimelast7'], $row['responsetimems'],
$row['uptimelast7'], $row['uptime_alltime'],
$row['dateupdated'], $row['dateupdated'],
$row['score'] $row['score']
); );
$scheme = $row['secure'] === 'true' ? 'https://' : 'http://'; $scheme = $row['secure'] ? 'https://' : 'http://';
echo <<<EOF echo <<<EOF
<entry> <entry>
<title>{$scheme}{$row['domain']}</title> <title>{$scheme}{$row['domain']}</title>
...@@ -54,7 +54,7 @@ EOF; ...@@ -54,7 +54,7 @@ EOF;
} }
echo '</feed>'; echo '</feed>';
} elseif ($_format === 'json') { } elseif ($_format === 'json') {
$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'; $sql = 'SELECT id,domain,status,secure,score,userrating,adminrating,city,state,country,lat,long,ip,ipv6,statsurl,monthsmonitored,uptime_alltime,responsetimems,local_posts,comment_counts,dateCreated,dateUpdated,dateLaststats,hidden,terms,sslexpire,uptime_custom,dnssec,softwarename,total_users,local_posts,comment_counts,service_facebook,service_twitter,service_tumblr,service_wordpress,service_xmpp FROM pods';
$result = pg_query($dbh, $sql); $result = pg_query($dbh, $sql);
$result || die('Error in SQL query: ' . pg_last_error()); $result || die('Error in SQL query: ' . pg_last_error());
...@@ -74,21 +74,18 @@ EOF; ...@@ -74,21 +74,18 @@ EOF;
} }
} else { } else {
$i = 0; $i = 0;
$sql = "SELECT * FROM pods WHERE hidden <> 'yes' ORDER BY uptimelast7 DESC"; $sql = "SELECT domain,uptime_alltime,country FROM pods WHERE NOT hidden ORDER BY uptime_alltime DESC";
$result = pg_query($dbh, $sql); $result = pg_query($dbh, $sql);
$result || die('Error in SQL query: ' . pg_last_error()); $result || die('Error in SQL query: ' . pg_last_error());
$numrows = pg_num_rows($result); $numrows = pg_num_rows($result);
while ($row = pg_fetch_array($result)) { while ($row = pg_fetch_array($result)) {
// $status = $row['status'] === 'up' ? 'Online' : 'Offline';
// $scheme = $row['secure'] === 'true' ? 'https://' : 'http://';
// $class = $row['secure'] === 'true' ? 'green' : 'red';
$i++ > 0 && print ','; $i++ > 0 && print ',';
printf( printf(
'%1$s Up %2$s%% This Month - Located in: %3$s', '%1$s Up %2$s%% This Month - Located in: %3$s',
$row['domain'], $row['domain'],
$row['uptimelast7'], $row['uptime_alltime'],
$row['country'] $row['country']
); );
} }
......
...@@ -4,7 +4,7 @@ require_once __DIR__ . '/config.php'; ...@@ -4,7 +4,7 @@ require_once __DIR__ . '/config.php';
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass"); $dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
$dbh || die('Error in connection: ' . pg_last_error()); $dbh || die('Error in connection: ' . pg_last_error());
$sql = "SELECT * FROM pods WHERE hidden <> 'no' AND score < 50 ORDER BY weightedscore"; $sql = "SELECT * FROM pods WHERE score < 50 ORDER BY weightedscore";
$result = pg_query($dbh, $sql); $result = pg_query($dbh, $sql);
$result || die('Error in SQL query: ' . pg_last_error()); $result || die('Error in SQL query: ' . pg_last_error());
...@@ -39,7 +39,7 @@ $numrows = pg_num_rows($result); ...@@ -39,7 +39,7 @@ $numrows = pg_num_rows($result);
$tt = 0; $tt = 0;
while ($row = pg_fetch_array($result)) { while ($row = pg_fetch_array($result)) {
$tt++; $tt++;
if ($row['secure'] === 'true') { if ($row['secure']) {
$scheme = 'https://'; $scheme = 'https://';
$class = 'green'; $class = 'green';
$tip = 'This pod uses SSL encryption for traffic.'; $tip = 'This pod uses SSL encryption for traffic.';
...@@ -55,8 +55,8 @@ $numrows = pg_num_rows($result); ...@@ -55,8 +55,8 @@ $numrows = pg_num_rows($result);
"\n" . 'This pod %1$s has been watched for %2$s months and its average ping time is %3$s with uptime of %4$s%% this month and was last checked on %5$s. On a score of -20 to +20 this pod is a %6$s right now', "\n" . 'This pod %1$s has been watched for %2$s months and its average ping time is %3$s with uptime of %4$s%% this month and was last checked on %5$s. On a score of -20 to +20 this pod is a %6$s right now',
$pod_name, $pod_name,
$row['monthsmonitored'], $row['monthsmonitored'],
$row['responsetimelast7'], $row['responsetimems'],
$row['uptimelast7'], $row['uptime_alltime'],
$row['dateupdated'], $row['dateupdated'],
$row['score'] $row['score']
); );
...@@ -81,18 +81,18 @@ $numrows = pg_num_rows($result); ...@@ -81,18 +81,18 @@ $numrows = pg_num_rows($result);
$classver = 'black'; $classver = 'black';
} }
echo '<td class="' . $classver . '"><div title="' . $pre . ' codename: ' . $row['shortversion'] . ' master version is: ' . $row['masterversion'] . '" class="tipsy">' . $version . '</div></td>'; echo '<td class="' . $classver . '"><div title="' . $pre . ' codename: ' . $row['shortversion'] . ' master version is: ' . $row['masterversion'] . '" class="tipsy">' . $version . '</div></td>';
echo '<td>' . $row['uptimelast7'] . '</td>'; echo '<td>' . $row['uptime_alltime'] . '</td>';
echo '<td>' . $row['responsetimelast7'] . '</td>'; echo '<td>' . $row['responsetimems'] . '</td>';
echo '<td>' . ($row['signup'] === '1' ? 'Open' : 'Closed') . '</td>'; echo '<td>'; echo $row['signup'] ? 'Open' : 'Closed'; echo '</td>';
echo '<td>' . $row['total_users'] . '</td>'; echo '<td>' . $row['total_users'] . '</td>';
echo '<td>' . $row['active_users_halfyear'] . '</td>'; echo '<td>' . $row['active_users_halfyear'] . '</td>';
echo '<td>' . $row['active_users_monthly'] . '</td>'; echo '<td>' . $row['active_users_monthly'] . '</td>';
echo '<td>' . $row['local_posts'] . '</td>'; echo '<td>' . $row['local_posts'] . '</td>';
echo '<td>' . $row['comment_counts'] . '</td>'; echo '<td>' . $row['comment_counts'] . '</td>';
if (strpos($row['pingdomurl'], 'pingdom.com')) { if (strpos($row['statsurl'], 'pingdom.com')) {
$moreurl = $row['pingdomurl']; $moreurl = $row['statsurl'];
} else { } else {
$moreurl = 'https://api.uptimerobot.com/getMonitors?format=json&customUptimeRatio=7-30-60-90&apiKey=' . $row['pingdomurl']; $moreurl = 'https://api.uptimerobot.com/getMonitors?format=json&customUptimeRatio=7-30-60-90&apiKey=' . $row['statsurl'];
} }
echo '<td><div title="Last Check ' . $row['dateupdated'] . '" class="tipsy"><a target="_self" href="' . $moreurl . '">' . $row['monthsmonitored'] . '</a></div></td>'; echo '<td><div title="Last Check ' . $row['dateupdated'] . '" class="tipsy"><a target="_self" href="' . $moreurl . '">' . $row['monthsmonitored'] . '</a></div></td>';
echo '<td>' . $row['score'] . '</td>'; echo '<td>' . $row['score'] . '</td>';
......
...@@ -30,7 +30,7 @@ require_once __DIR__ . '/../config.php'; ...@@ -30,7 +30,7 @@ require_once __DIR__ . '/../config.php';
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass"); $dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
$dbh || die('Error in connection: ' . pg_last_error()); $dbh || die('Error in connection: ' . pg_last_error());
$sql = 'SELECT domain, pingdomurl FROM pods'; $sql = 'SELECT domain, statsurl FROM pods';
$result = pg_query($dbh, $sql); $result = pg_query($dbh, $sql);
$result || die('Error in SQL query: ' . pg_last_error()); $result || die('Error in SQL query: ' . pg_last_error());
...@@ -39,7 +39,7 @@ while ($row = pg_fetch_array($result)) { ...@@ -39,7 +39,7 @@ while ($row = pg_fetch_array($result)) {
$log->lwrite('domain already exists ' . $_domain); $log->lwrite('domain already exists ' . $_domain);
die('domain already exists'); die('domain already exists');
} }
if ($row['pingdomurl'] === $_url) { if ($row['statsurl'] === $_url) {
$log->lwrite('API key already exists ' . $_domain); $log->lwrite('API key already exists ' . $_domain);
die('API key already exists'); die('API key already exists');
} }
...@@ -78,7 +78,7 @@ if (stristr($output, 'nodeName')) { ...@@ -78,7 +78,7 @@ if (stristr($output, 'nodeName')) {
$valid = true; $valid = true;
} }
if ($valid) { if ($valid) {
$sql = 'INSERT INTO pods (domain, pingdomurl, email) VALUES ($1, $2, $3)'; $sql = 'INSERT INTO pods (domain, statsurl, email) VALUES ($1, $2, $3)';
$result = pg_query_params($dbh, $sql, [$_domain, $_url, $_email]); $result = pg_query_params($dbh, $sql, [$_domain, $_url, $_email]);
$result || die('Error in SQL query: ' . pg_last_error()); $result || die('Error in SQL query: ' . pg_last_error());
......
<?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
// Required parameters.
($_url = $_GET['url'] ?? null) || die('no url given');
// Other parameters.
$_format = $_GET['format'] ?? '';
require_once __DIR__ . '/../config.php';
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
$dbh || die('Error in connection: ' . pg_last_error());
$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]);
$result || die('Error in SQL query: ' . pg_last_error());
while ($row = pg_fetch_array($result)) {
if ($_format === 'json') {
echo json_encode($row);
} else {
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 Country: ' . $row['country'] . '<br>';
echo 'Server State: ' . $row['state'] . '<br>';
echo 'Server City: ' . $row['city'] . '<br>';
echo 'Latitude: ' . $row['lat'] . '<br>';
echo 'Longitude: ' . $row['long'] . '<br>';
}
}
pg_free_result($result);
pg_close($dbh);
...@@ -10,14 +10,14 @@ $_delete = $_GET['delete'] ?? ''; ...@@ -10,14 +10,14 @@ $_delete = $_GET['delete'] ?? '';
$_weight = $_GET['weight'] ?? ''; $_weight = $_GET['weight'] ?? '';
$_email = $_GET['email'] ?? ''; $_email = $_GET['email'] ?? '';
$_oldemail = $_GET['oldemail'] ?? ''; $_oldemail = $_GET['oldemail'] ?? '';
$_pingdomurl = $_GET['pingdomurl'] ?? ''; $_statsurl = $_GET['statsurl'] ?? '';
require_once __DIR__ . '/../config.php'; require_once __DIR__ . '/../config.php';
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass"); $dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
$dbh || die('Error in connection: ' . pg_last_error()); $dbh || die('Error in connection: ' . pg_last_error());
$sql = 'SELECT domain,email,token,tokenexpire,pingdomurl,weight FROM pods WHERE domain = $1'; $sql = 'SELECT domain,email,token,tokenexpire,statsurl,weight FROM pods WHERE domain = $1';
$result = pg_query_params($dbh, $sql, [$_domain]); $result = pg_query_params($dbh, $sql, [$_domain]);
$result || die('Error in SQL query: ' . pg_last_error()); $result || die('Error in SQL query: ' . pg_last_error());
...@@ -38,8 +38,8 @@ while ($row = pg_fetch_array($result)) { ...@@ -38,8 +38,8 @@ while ($row = pg_fetch_array($result)) {
if ($_save === $row['token']) { if ($_save === $row['token']) {
$_weight <= 10 || die('10 is max weight'); $_weight <= 10 || die('10 is max weight');
$sql = 'UPDATE pods SET email = $1, pingdomurl = $2, weight = $3 WHERE domain = $4'; $sql = 'UPDATE pods SET email = $1, statsurl = $2, weight = $3 WHERE domain = $4';
$result = pg_query_params($dbh, $sql, [$_email, $_pingdomurl, $_weight, $_domain]); $result = pg_query_params($dbh, $sql, [$_email, $_statsurl, $_weight, $_domain]);
if (!$result) { if (!$result) {
die('Error in SQL query: ' . pg_last_error()); die('Error in SQL query: ' . pg_last_error());
} }
...@@ -60,7 +60,7 @@ while ($row = pg_fetch_array($result)) { ...@@ -60,7 +60,7 @@ while ($row = pg_fetch_array($result)) {
echo '<input type="hidden" name="save" value="' . $_token . '">'; echo '<input type="hidden" name="save" value="' . $_token . '">';
echo '<input type="hidden" name="token" value="' . $_token . '">'; echo '<input type="hidden" name="token" value="' . $_token . '">';
echo '<input type="hidden" name="domain" value="' . $_domain . '">'; echo '<input type="hidden" name="domain" value="' . $_domain . '">';
echo 'Stats Key <input type="text" size="50" name="pingdomurl" value="' . $row['pingdomurl'] . '"">Uptimerobot API key for this monitor<br>'; echo 'Stats Key <input type="text" size="50" name="statsurl" value="' . $row['statsurl'] . '"">Uptimerobot API key for this monitor<br>';
echo 'Email <input type="text" size="20" name="email" value="' . $row['email'] . '"><br>'; echo 'Email <input type="text" size="20" name="email" value="' . $row['email'] . '"><br>';
echo 'Weight <input type="text" size="2" name="weight" value="' . $row['weight'] . '"> This lets you weight your pod lower on the list if you have too much trafic coming in, 10 is the norm use lower to move down the list.<br>'; echo 'Weight <input type="text" size="2" name="weight" value="' . $row['weight'] . '"> This lets you weight your pod lower on the list if you have too much trafic coming in, 10 is the norm use lower to move down the list.<br>';
echo '<input type="submit" name="submit">'; echo '<input type="submit" name="submit">';
......
...@@ -46,11 +46,11 @@ $dbh || die('Error in connection: ' . pg_last_error()); ...@@ -46,11 +46,11 @@ $dbh || die('Error in connection: ' . pg_last_error());
//foreach pod check it and update db //foreach pod check it and update db
if ($_domain) { if ($_domain) {
$sql = 'SELECT domain,pingdomurl,score,datecreated,weight FROM pods WHERE domain = $1'; $sql = 'SELECT domain,statsurl,score,datecreated,weight FROM pods WHERE domain = $1';
$sleep = '0'; $sleep = '0';
$result = pg_query_params($dbh, $sql, [$_domain]); $result = pg_query_params($dbh, $sql, [$_domain]);
} elseif (PHP_SAPI === 'cli') { } elseif (PHP_SAPI === 'cli') {
$sql = 'SELECT domain,pingdomurl,score,datecreated,adminrating,weight FROM pods'; $sql = 'SELECT domain,statsurl,score,datecreated,adminrating,weight FROM pods';
$sleep = '1'; $sleep = '1';
$result = pg_query($dbh, $sql); $result = pg_query($dbh, $sql);
} else { } else {
...@@ -254,15 +254,14 @@ while ($row = pg_fetch_all($result)) { ...@@ -254,15 +254,14 @@ while ($row = pg_fetch_all($result)) {
} }
} }
echo '<br>'; echo '<br>';
$connection = '';
$pingdomdate = date('Y-m-d H:i:s'); $pingdomdate = date('Y-m-d H:i:s');
if (strpos($row[$i]['pingdomurl'], 'pingdom.com')) { if (strpos($row[$i]['statsurl'], 'pingdom.com')) {
//curl the pingdom page //curl the pingdom page
$ping = curl_init(); $ping = curl_init();
$thismonth = '/' . date('Y') . '/' . date('m'); $thismonth = '/' . date('Y') . '/' . date('m');
curl_setopt($ping, CURLOPT_URL, $row[$i]['pingdomurl'] . $thismonth); curl_setopt($ping, CURLOPT_URL, $row[$i]['statsurl'] . $thismonth);
if ($debug) { if ($debug) {
echo $row[$i]['pingdomurl'] . $thismonth; echo $row[$i]['statsurl'] . $thismonth;
} }
curl_setopt($ping, CURLOPT_POST, 0); curl_setopt($ping, CURLOPT_POST, 0);
curl_setopt($ping, CURLOPT_HEADER, 1); curl_setopt($ping, CURLOPT_HEADER, 1);
...@@ -308,7 +307,7 @@ while ($row = pg_fetch_all($result)) { ...@@ -308,7 +307,7 @@ while ($row = pg_fetch_all($result)) {
} else { } else {
//do uptimerobot API instead //do uptimerobot API instead
$ping = curl_init(); $ping = curl_init();
curl_setopt($ping, CURLOPT_URL, 'https://api.uptimerobot.com/getMonitors?format=json&customUptimeRatio=7-30-60-90&responseTimes=1&responseTimesAverage=86400&apiKey=' . $row[$i]['pingdomurl']); curl_setopt($ping, CURLOPT_URL, 'https://api.uptimerobot.com/getMonitors?format=json&customUptimeRatio=7-30-60-90&responseTimes=1&responseTimesAverage=86400&apiKey=' . $row[$i]['statsurl']);
curl_setopt($ping, CURLOPT_POST, 0); curl_setopt($ping, CURLOPT_POST, 0);
curl_setopt($ping, CURLOPT_HEADER, 0); curl_setopt($ping, CURLOPT_HEADER, 0);
curl_setopt($ping, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ping, CURLOPT_RETURNTRANSFER, 1);
...@@ -377,10 +376,10 @@ while ($row = pg_fetch_all($result)) { ...@@ -377,10 +376,10 @@ while ($row = pg_fetch_all($result)) {
$timenow = date('Y-m-d H:i:s'); $timenow = date('Y-m-d H:i:s');
$sql = 'UPDATE pods SET Hgitdate = $1, Hencoding = $2, secure = $3, hidden = $4, Hruntime = $5, Hgitref = $6, ip = $7, ipv6 = $8, monthsmonitored = $9, $sql = 'UPDATE pods SET Hgitdate = $1, Hencoding = $2, secure = $3, hidden = $4, Hruntime = $5, Hgitref = $6, ip = $7, ipv6 = $8, monthsmonitored = $9,
uptimelast7 = $10, status = $11, dateLaststats = $12, dateUpdated = $13, responsetimelast7 = $14, score = $15, adminrating = $16, country = $17, city = $18, uptime_alltime = $10, status = $11, dateLaststats = $12, dateUpdated = $13, responsetimems = $14, score = $15, adminrating = $16, country = $17, city = $18,
state = $19, lat = $20, long = $21, postalcode=\'\', connection = $22, whois = $23, userrating = $24, longversion = $25, shortversion = $26, state = $19, lat = $20, long = $21, connection = $22, whois = $23, userrating = $24, longversion = $25, shortversion = $26,
masterversion = $27, signup = $28, total_users = $29, active_users_halfyear = $30, active_users_monthly = $31, local_posts = $32, name = $33, masterversion = $27, signup = $28, total_users = $29, active_users_halfyear = $30, active_users_monthly = $31, local_posts = $32, name = $33,
comment_counts = $35, service_facebook = $36, service_tumblr = $37, service_twitter = $38, service_wordpress = $39, weightedscore = $40, xmpp = $41, softwarename = $42, sslvalid = $43 comment_counts = $35, service_facebook = $36, service_tumblr = $37, service_twitter = $38, service_wordpress = $39, weightedscore = $40, service_xmpp = $41, softwarename = $42, sslvalid = $43
WHERE domain = $34'; WHERE domain = $34';
$result = pg_query_params($dbh, $sql, [$gitdate, $encoding, $secure, $hidden, $runtime, $gitrev, $ipnum, $ipv6, $months, $uptime, $live, $pingdomdate, $timenow, $responsetime, $score, $adminrating, $country, $city, $state, $lat, $long, $dver, $whois, $userrating, $xdver, $dver, $masterversion, $signup, $total_users, $active_users_halfyear, $active_users_monthly, $local_posts, $name, $domain, $comment_counts, $service_facebook, $service_tumblr, $service_twitter, $service_wordpress, $weightedscore, $service_xmpp, $softwarename, $outputsslerror]); $result = pg_query_params($dbh, $sql, [$gitdate, $encoding, $secure, $hidden, $runtime, $gitrev, $ipnum, $ipv6, $months, $uptime, $live, $pingdomdate, $timenow, $responsetime, $score, $adminrating, $country, $city, $state, $lat, $long, $dver, $whois, $userrating, $xdver, $dver, $masterversion, $signup, $total_users, $active_users_halfyear, $active_users_monthly, $local_posts, $name, $domain, $comment_counts, $service_facebook, $service_tumblr, $service_twitter, $service_wordpress, $weightedscore, $service_xmpp, $softwarename, $outputsslerror]);
$result || die('Error in SQL query3: ' . pg_last_error()); $result || die('Error in SQL query3: ' . pg_last_error());
......
...@@ -3,49 +3,51 @@ CREATE TABLE pods ( ...@@ -3,49 +3,51 @@ CREATE TABLE pods (
domain text UNIQUE NOT NULL, domain text UNIQUE NOT NULL,
name text, name text,
softwarename text, softwarename text,
masterversion text,
shortversion text,
score int DEFAULT 10, score int DEFAULT 10,
weightedscore numeric(5,2) DEFAULT 10, weightedscore numeric(5,2) DEFAULT 10,
adminrating decimal DEFAULT 10, adminrating decimal DEFAULT 10,
userrating decimal DEFAULT 10, userrating decimal DEFAULT 10,
whois text, whois text,
hidden text DEFAULT 'yes', hidden boolean DEFAULT 'yes',
ip text, ip text,
ptr text,
country text, country text,
city text, city text,
state text, state text,
lat text, lat text,
long text, long text,
connection text,
postalcode text,
email text, email text,
ipv6 text, ipv6 boolean,
secure text, secure boolean,
sslvalid text, sslvalid text,
Hgitdate text, Hgitdate text,
Hgitref text, Hgitref text,
Hruntime text, Hruntime text,
Hencoding text, Hencoding text,
pingdomurl text, statsurl text,
pingdomlast text,
monthsmonitored int, monthsmonitored int,
signup int, signup boolean,
total_users int, total_users int,
active_users_halfyear int, active_users_halfyear int,
active_users_monthly int, active_users_monthly int,
local_posts int, local_posts int,
uptimelast7 numeric(5,2), uptime_alltime numeric(5,2),
uptime_custom text,
status text, status text,
responsetimelast7 text, responsetimems text,
service_facebook boolean, service_facebook boolean,
service_twitter boolean, service_twitter boolean,
service_tumblr boolean, service_tumblr boolean,
service_wordpress boolean, service_wordpress boolean,
service_xmpp boolean,
token text, token text,
tokenexpire timestamp, tokenexpire timestamp,
terms text,
sslexpire timestamp,
dnssec boolean,
comment_counts int, comment_counts int,
weight int DEFAULT 10, weight int DEFAULT 50,
xmpp boolean,
dateUpdated timestamp DEFAULT current_timestamp, dateUpdated timestamp DEFAULT current_timestamp,
dateLaststats timestamp DEFAULT current_timestamp, dateLaststats timestamp DEFAULT current_timestamp,
dateCreated timestamp DEFAULT current_timestamp dateCreated timestamp DEFAULT current_timestamp
...@@ -61,12 +63,4 @@ CREATE TABLE rating_comments ( ...@@ -61,12 +63,4 @@ CREATE TABLE rating_comments (
userurl text, userurl text,
date timestamp DEFAULT current_timestamp date timestamp DEFAULT current_timestamp
); );
CREATE TABLE users (
id serial8 UNIQUE PRIMARY KEY,
admin int NOT NULL,
username text UNIQUE NOT NULL,
password text NOT NULL,
userurl text,
userpod text,
dateCreated timestamp DEFAULT current_timestamp
);
...@@ -20,11 +20,11 @@ if ($_url) { ...@@ -20,11 +20,11 @@ if ($_url) {
//Add click counter +1 for $row[0]['domain'] clicks in future, separate click table //Add click counter +1 for $row[0]['domain'] clicks in future, separate click table
header('Location:' . $_url); header('Location:' . $_url);
} else { } else {
$sql = 'SELECT secure,domain FROM pods WHERE score > 90 AND masterversion = shortversion AND signup = 1 ORDER BY RANDOM() LIMIT 1'; $sql = 'SELECT secure,domain FROM pods WHERE score > 90 AND masterversion = shortversion AND signup ORDER BY RANDOM() LIMIT 1';
$result = pg_query($dbh, $sql); $result = pg_query($dbh, $sql);
$result || die('Error in SQL query: ' . pg_last_error()); $result || die('Error in SQL query: ' . pg_last_error());
$row = pg_fetch_all($result); $row = pg_fetch_all($result);
$scheme = $row[0]['secure'] === 'true' ? 'https://' : 'http://'; $scheme = $row[0]['secure'] ? 'https://' : 'http://';
header('Location:' . $scheme . $row[0]['domain'] . '/users/sign_up'); header('Location:' . $scheme . $row[0]['domain'] . '/users/sign_up');
} }
...@@ -2,10 +2,7 @@ $(document).ready(function(){ ...@@ -2,10 +2,7 @@ $(document).ready(function(){
$.facebox.settings.closeImage = 'bower_components/facebox/src/closelabel.png' $.facebox.settings.closeImage = 'bower_components/facebox/src/closelabel.png'
$.facebox.settings.loadingImage = 'bower_components/facebox/src/loading.gif' $.facebox.settings.loadingImage = 'bower_components/facebox/src/loading.gif'
$('a[rel*=facebox]').facebox() $('a[rel*=facebox]').facebox()
$('#myTable').tablesorter(); $('#myTable').tablesorter()
});
$(function () {
$('[data-toggle="tooltip"]').tooltip() $('[data-toggle="tooltip"]').tooltip()
}) });
...@@ -8,7 +8,7 @@ $country_code = $_SERVER['HTTP_CF_IPCOUNTRY'] ?? ''; ...@@ -8,7 +8,7 @@ $country_code = $_SERVER['HTTP_CF_IPCOUNTRY'] ?? '';
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass"); $dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
$dbh || die('Error in connection: ' . pg_last_error()); $dbh || die('Error in connection: ' . pg_last_error());
$sql = "SELECT * FROM pods WHERE adminrating <> -1 AND hidden <> 'yes' AND signup = 1 ORDER BY uptimelast7 DESC"; $sql = "SELECT * FROM pods WHERE adminrating <> -1 AND NOT hidden AND signup ORDER BY uptime_alltime DESC";
$result = pg_query($dbh, $sql); $result = pg_query($dbh, $sql);
$result || die('Error in SQL query: ' . pg_last_error()); $result || die('Error in SQL query: ' . pg_last_error());
...@@ -32,14 +32,12 @@ $numrows = pg_num_rows($result); ...@@ -32,14 +32,12 @@ $numrows = pg_num_rows($result);
<?php <?php
while ($row = pg_fetch_array($result)) { while ($row = pg_fetch_array($result)) {
if ($row['secure'] === 'true') { if ($row['secure']) {
$scheme = 'https://'; $scheme = 'https://';
$class = 'text-success'; $class = 'text-success';
//$tip="This pod uses SSL encryption for traffic.";
} else { } else {
$scheme = 'http://'; $scheme = 'http://';
$class = 'red'; $class = 'red';
//$tip="This pod does not offer SSL";
} }
$verdiff = str_replace('.', '', $row['masterversion']) - str_replace('.', '', $row['shortversion']); $verdiff = str_replace('.', '', $row['masterversion']) - str_replace('.', '', $row['shortversion']);
$pod_name = htmlentities($row['name'], ENT_QUOTES); $pod_name = htmlentities($row['name'], ENT_QUOTES);
...@@ -48,12 +46,12 @@ $numrows = pg_num_rows($result); ...@@ -48,12 +46,12 @@ $numrows = pg_num_rows($result);
$row['softwarename'], $row['softwarename'],
$pod_name, $pod_name,
$row['monthsmonitored'], $row['monthsmonitored'],
$row['uptimelast7'], $row['uptime_alltime'],
$row['score'] $row['score']
); );
echo '<tr><td><div title="' . $tip . '" data-toggle="tooltip" data-placement="bottom"><a class="' . $class . ' url" target="_self" href="/go.php?url=' . $scheme . $row['domain'] . '">' . $row['domain'] . '</a></div></td>'; echo '<tr><td><div title="' . $tip . '" data-toggle="tooltip" data-placement="bottom"><a class="' . $class . ' url" target="_self" href="/go.php?url=' . $scheme . $row['domain'] . '">' . $row['domain'] . '</a></div></td>';
echo '<td>' . $row['uptimelast7'] . '%</td>'; echo '<td>' . $row['uptime_alltime'] . '%</td>';
echo '<td data-toggle="tooltip" data-placement="bottom" title="active six months: ' . $row['active_users_halfyear'] . ', active one month: ' . $row['active_users_monthly'] . '">' . $row['active_users_halfyear'] . '</td>'; echo '<td data-toggle="tooltip" data-placement="bottom" title="active six months: ' . $row['active_users_halfyear'] . ', active one month: ' . $row['active_users_monthly'] . '">' . $row['active_users_halfyear'] . '</td>';
if ($country_code === $row['country']) { if ($country_code === $row['country']) {
echo '<td class="text-success" data-toggle="tooltip" data-placement="bottom" title="City: '. ($row['city'] ?? 'n/a') . ' State: ' . ($row['state'] ?? 'n/a') . '"><b>' . $row['country'] . '</b></td>'; echo '<td class="text-success" data-toggle="tooltip" data-placement="bottom" title="City: '. ($row['city'] ?? 'n/a') . ' State: ' . ($row['state'] ?? 'n/a') . '"><b>' . $row['country'] . '</b></td>';
...@@ -65,7 +63,7 @@ $numrows = pg_num_rows($result); ...@@ -65,7 +63,7 @@ $numrows = pg_num_rows($result);
$row['service_twitter'] === 't' && print '<div class="smlogo smlogo-twitter" title="Publish to Twitter" alt="Publish to Twitter"></div>'; $row['service_twitter'] === 't' && print '<div class="smlogo smlogo-twitter" title="Publish to Twitter" alt="Publish to Twitter"></div>';
$row['service_tumblr'] === 't' && print '<div class="smlogo smlogo-tumblr" title="Publish to Tumblr" alt="Publish to Tumblr"></div>'; $row['service_tumblr'] === 't' && print '<div class="smlogo smlogo-tumblr" title="Publish to Tumblr" alt="Publish to Tumblr"></div>';
$row['service_wordpress'] === 't' && print '<div class="smlogo smlogo-wordpress" title="Publish to Wordpress" alt="Publish to Wordpress"></div>'; $row['service_wordpress'] === 't' && print '<div class="smlogo smlogo-wordpress" title="Publish to Wordpress" alt="Publish to Wordpress"></div>';
$row['xmpp'] === 't' && print '<div class="smlogo smlogo-xmpp"><img src="/images/icon-xmpp.png" width="16" height="16" title="XMPP chat server" alt="XMPP chat server"></div>'; $row['service_xmpp'] === 't' && print '<div class="smlogo smlogo-xmpp"><img src="/images/icon-xmpp.png" width="16" height="16" title="XMPP chat server" alt="XMPP chat server"></div>';
echo '</td></tr>'; echo '</td></tr>';
} }
pg_free_result($result); pg_free_result($result);
......
...@@ -8,7 +8,7 @@ $country_code = $_SERVER['HTTP_CF_IPCOUNTRY'] ?? ''; ...@@ -8,7 +8,7 @@ $country_code = $_SERVER['HTTP_CF_IPCOUNTRY'] ?? '';
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass"); $dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
$dbh || die('Error in connection: ' . pg_last_error()); $dbh || die('Error in connection: ' . pg_last_error());
$sql = 'SELECT * FROM pods ORDER BY uptimelast7 DESC'; $sql = 'SELECT * FROM pods ORDER BY uptime_alltime DESC';
$result = pg_query($dbh, $sql); $result = pg_query($dbh, $sql);
$result || die('Error in SQL query: ' . pg_last_error()); $result || die('Error in SQL query: ' . pg_last_error());
...@@ -42,7 +42,7 @@ $numrows = pg_num_rows($result); ...@@ -42,7 +42,7 @@ $numrows = pg_num_rows($result);
<tbody> <tbody>
<?php <?php
while ($row = pg_fetch_array($result)) { while ($row = pg_fetch_array($result)) {
if ($row['secure'] === 'true') { if ($row['secure']) {
$scheme = 'https://'; $scheme = 'https://';
$class = 'green'; $class = 'green';
$tip = 'This pod uses SSL encryption for traffic.'; $tip = 'This pod uses SSL encryption for traffic.';
...@@ -52,7 +52,7 @@ $numrows = pg_num_rows($result); ...@@ -52,7 +52,7 @@ $numrows = pg_num_rows($result);
$tip = 'This pod does not offer SSL'; $tip = 'This pod does not offer SSL';
} }
$pod_name = htmlentities($row['name'], ENT_QUOTES); $pod_name = htmlentities($row['name'], ENT_QUOTES);
$tip .= "\n This {$row['softwarename']} pod {$pod_name} has been watched for {$row['monthsmonitored']} months with an overall uptime of {$row['uptimelast7']}% and a response time average today of {$row['responsetimelast7']}ms was last checked on {$row['dateupdated']}. "; $tip .= "\n This {$row['softwarename']} pod {$pod_name} has been watched for {$row['monthsmonitored']} months with an overall uptime of {$row['uptime_alltime']}% and a response time average today of {$row['responsetimems']}ms was last checked on {$row['dateupdated']}. ";
$tip .= "On a scale of 100 this pod is a {$row['score']} right now"; $tip .= "On a scale of 100 this pod is a {$row['score']} right now";
echo '<tr><td><a title="' . $tip . '" data-toggle="tooltip" data-placement="bottom" class="' . $class . '" target="_self" href="/go.php?url=' . $scheme . $row['domain'] . '">' . $row['domain'] . '</a></td>'; echo '<tr><td><a title="' . $tip . '" data-toggle="tooltip" data-placement="bottom" class="' . $class . '" target="_self" href="/go.php?url=' . $scheme . $row['domain'] . '">' . $row['domain'] . '</a></td>';
...@@ -75,17 +75,17 @@ $numrows = pg_num_rows($result); ...@@ -75,17 +75,17 @@ $numrows = pg_num_rows($result);
$classver = 'black'; $classver = 'black';
} }
echo '<td class="' . $classver . '"><div title="' . $pre . ' version: ' . $row['shortversion'] . ' master version is: ' . $row['masterversion'] . '" data-toggle="tooltip" data-placement="bottom">' . $version . '</div></td>'; echo '<td class="' . $classver . '"><div title="' . $pre . ' version: ' . $row['shortversion'] . ' master version is: ' . $row['masterversion'] . '" data-toggle="tooltip" data-placement="bottom">' . $version . '</div></td>';
echo '<td>' . $row['uptimelast7'] . '%</td>'; echo '<td>' . $row['uptime_alltime'] . '%</td>';
echo '<td>' . $row['ipv6'] . '</td>'; echo '<td>'; echo $row['ipv6'] ? 'Yes' : 'No'; echo '</td>';
echo '<td>' . $row['responsetimelast7'] . '</td>'; echo '<td>' . $row['responsetimems'] . '</td>';
echo '<td>' . ($row['signup'] === '1' ? 'Open' : 'Closed') . '</td>'; echo '<td>'; echo $row['signup'] ? 'Open' : 'Closed'; echo '</td>';
echo '<td>' . $row['total_users'] . '</td>'; echo '<td>' . $row['total_users'] . '</td>';
echo '<td>' . $row['active_users_halfyear'] . '</td>'; echo '<td>' . $row['active_users_halfyear'] . '</td>';
echo '<td>' . $row['active_users_monthly'] . '</td>'; echo '<td>' . $row['active_users_monthly'] . '</td>';
echo '<td>' . $row['local_posts'] . '</td>'; echo '<td>' . $row['local_posts'] . '</td>';
echo '<td>' . $row['comment_counts'] . '</td>'; echo '<td>' . $row['comment_counts'] . '</td>';
if (strpos($row['pingdomurl'], 'pingdom.com')) { if (strpos($row['statsurl'], 'pingdom.com')) {
$moreurl = $row['pingdomurl']; $moreurl = $row['statsurl'];
} else { } else {
$moreurl = '/showstats.php?domain=' . $row['domain']; $moreurl = '/showstats.php?domain=' . $row['domain'];
} }
...@@ -106,7 +106,7 @@ $numrows = pg_num_rows($result); ...@@ -106,7 +106,7 @@ $numrows = pg_num_rows($result);
$row['service_twitter'] === 't' && print '<div class="smlogo smlogo-twitter"></div>'; $row['service_twitter'] === 't' && print '<div class="smlogo smlogo-twitter"></div>';
$row['service_tumblr'] === 't' && print '<div class="smlogo smlogo-tumblr"></div>'; $row['service_tumblr'] === 't' && print '<div class="smlogo smlogo-tumblr"></div>';
$row['service_wordpress'] === 't' && print '<div class="smlogo smlogo-wordpress"></div>'; $row['service_wordpress'] === 't' && print '<div class="smlogo smlogo-wordpress"></div>';
$row['xmpp'] === 't' && print '<div class="smlogo smlogo-xmpp"><img src="/images/icon-xmpp.png" width="16" height="16" title="XMPP chat server" alt="XMPP chat server"></div>'; $row['service_xmpp'] === 't' && print '<div class="smlogo smlogo-xmpp"><img src="/images/icon-xmpp.png" width="16" height="16" title="XMPP chat server" alt="XMPP chat server"></div>';
echo '</td></tr>'; echo '</td></tr>';
}