Commit 26ea33f5 authored by noplanman's avatar noplanman Committed by GitHub
Browse files

Merge pull request #66 from diasporg/fixsql

Fixsql
parents ba0fb1dd 6557bd37
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,responsetime,local_posts,comment_counts,date_created,date_updated,date_laststats,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['responsetime'] . '<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') {
<link href="https://{$_SERVER['HTTP_HOST']}/"/>
EOF;
$sql = "SELECT * FROM pods WHERE hidden <> 'yes'";
$sql = "SELECT name,monthsmonitored,responsetime,uptime_alltime,dateupdated,score,secure,domain,country,lat,long FROM pods";
$result = pg_query($dbh, $sql);
$result || die('Error in SQL query: ' . pg_last_error());
......@@ -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',
$pod_name,
$row['monthsmonitored'],
$row['responsetimelast7'],
$row['uptimelast7'],
$row['responsetime'],
$row['uptime_alltime'],
$row['dateupdated'],
$row['score']
);
$scheme = $row['secure'] === 'true' ? 'https://' : 'http://';
$scheme = $row['secure'] === 't' ? 'https://' : 'http://';
echo <<<EOF
<entry>
<title>{$scheme}{$row['domain']}</title>
......@@ -54,7 +54,7 @@ EOF;
}
echo '</feed>';
} 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,responsetime,local_posts,comment_counts,date_created,date_updated,date_laststats,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 || die('Error in SQL query: ' . pg_last_error());
......@@ -74,21 +74,19 @@ EOF;
}
} else {
$i = 0;
$sql = "SELECT * FROM pods WHERE hidden <> 'yes' ORDER BY uptimelast7 DESC";
$sql = "SELECT domain,uptime_alltime,country,status FROM pods";
$result = pg_query($dbh, $sql);
$result || die('Error in SQL query: ' . pg_last_error());
$numrows = pg_num_rows($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 ',';
printf(
'%1$s Up %2$s%% This Month - Located in: %3$s',
'%1$s is %2$s now - online %3$s%% This Month - Located in: %4$s',
$row['domain'],
$row['uptimelast7'],
$row['status'],
$row['uptime_alltime'],
$row['country']
);
}
......
......@@ -4,7 +4,7 @@ require_once __DIR__ . '/config.php';
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
$dbh || die('Error in connection: ' . pg_last_error());
$sql = "SELECT * FROM pods WHERE hidden <> 'no' AND score < 50 ORDER BY weightedscore";
$sql = "SELECT domain,masterversion,shortversion,softwarename,monthsmonitored,score,signup,secure,name,country,city,state,lat,long,uptime_alltime,active_users_halfyear,active_users_monthly,service_facebook,service_twitter,service_tumblr,service_wordpress,service_xmpp,responsetime,dateupdated,ipv6,total_users,local_posts,comment_counts,statsurl,userrating,sslvalid FROM pods WHERE score < 50 ORDER BY weightedscore";
$result = pg_query($dbh, $sql);
$result || die('Error in SQL query: ' . pg_last_error());
......@@ -39,7 +39,7 @@ $numrows = pg_num_rows($result);
$tt = 0;
while ($row = pg_fetch_array($result)) {
$tt++;
if ($row['secure'] === 'true') {
if ($row['secure'] === 't') {
$scheme = 'https://';
$class = 'green';
$tip = 'This pod uses SSL encryption for traffic.';
......@@ -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',
$pod_name,
$row['monthsmonitored'],
$row['responsetimelast7'],
$row['uptimelast7'],
$row['responsetime'],
$row['uptime_alltime'],
$row['dateupdated'],
$row['score']
);
......@@ -81,18 +81,18 @@ $numrows = pg_num_rows($result);
$classver = 'black';
}
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['responsetimelast7'] . '</td>';
echo '<td>' . ($row['signup'] === '1' ? 'Open' : 'Closed') . '</td>';
echo '<td>' . $row['uptime_alltime'] . '</td>';
echo '<td>' . $row['responsetime'] . '</td>';
echo '<td>' . ($row['signup'] === 't' ? 'Open' : 'Closed') . '</td>';
echo '<td>' . $row['total_users'] . '</td>';
echo '<td>' . $row['active_users_halfyear'] . '</td>';
echo '<td>' . $row['active_users_monthly'] . '</td>';
echo '<td>' . $row['local_posts'] . '</td>';
echo '<td>' . $row['comment_counts'] . '</td>';
if (strpos($row['pingdomurl'], 'pingdom.com')) {
$moreurl = $row['pingdomurl'];
if (strpos($row['statsurl'], 'pingdom.com')) {
$moreurl = $row['statsurl'];
} 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>' . $row['score'] . '</td>';
......
......@@ -16,6 +16,10 @@ if (!($_email = $_POST['email'] ?? null)) {
$log->lwrite('no email given ' . $_domain);
die('no email given');
}
if (!($_terms = $_POST['terms'] ?? null)) {
$log->lwrite('terms link required ' . $_domain);
die('no terms link');
}
if (!$_url) {
$log->lwrite('no api given ' . $_domain);
die('no API key for your stats');
......@@ -29,7 +33,7 @@ if (strlen($_url) < 14) {
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
$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 || die('Error in SQL query: ' . pg_last_error());
......@@ -38,7 +42,7 @@ while ($row = pg_fetch_array($result)) {
$log->lwrite('domain already exists ' . $_domain);
die('domain already exists');
}
if ($row['pingdomurl'] === $_url) {
if ($row['statsurl'] === $_url) {
$log->lwrite('API key already exists ' . $_domain);
die('API key already exists');
}
......@@ -77,8 +81,8 @@ if (stristr($output, 'nodeName')) {
$valid = true;
}
if ($valid) {
$sql = 'INSERT INTO pods (domain, pingdomurl, email) VALUES ($1, $2, $3)';
$result = pg_query_params($dbh, $sql, [$_domain, $_url, $_email]);
$sql = 'INSERT INTO pods (domain, statsurl, email, terms) VALUES ($1, $2, $3, $4)';
$result = pg_query_params($dbh, $sql, [$_domain, $_url, $_email, $_terms]);
$result || die('Error in SQL query: ' . pg_last_error());
$to = $adminemail;
......
<?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,15 @@ $_delete = $_GET['delete'] ?? '';
$_weight = $_GET['weight'] ?? '';
$_email = $_GET['email'] ?? '';
$_oldemail = $_GET['oldemail'] ?? '';
$_pingdomurl = $_GET['pingdomurl'] ?? '';
$_statsurl = $_GET['statsurl'] ?? '';
$_terms = $_GET['terms'] ?? '';
require_once __DIR__ . '/../config.php';
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
$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,terms FROM pods WHERE domain = $1';
$result = pg_query_params($dbh, $sql, [$_domain]);
$result || die('Error in SQL query: ' . pg_last_error());
......@@ -38,8 +39,8 @@ while ($row = pg_fetch_array($result)) {
if ($_save === $row['token']) {
$_weight <= 10 || die('10 is max weight');
$sql = 'UPDATE pods SET email = $1, pingdomurl = $2, weight = $3 WHERE domain = $4';
$result = pg_query_params($dbh, $sql, [$_email, $_pingdomurl, $_weight, $_domain]);
$sql = 'UPDATE pods SET email = $1, statsurl = $2, weight = $3, terms = $4 WHERE domain = $5';
$result = pg_query_params($dbh, $sql, [$_email, $_statsurl, $_weight, $_terms, $_domain]);
if (!$result) {
die('Error in SQL query: ' . pg_last_error());
}
......@@ -60,8 +61,9 @@ while ($row = pg_fetch_array($result)) {
echo '<input type="hidden" name="save" value="' . $_token . '">';
echo '<input type="hidden" name="token" value="' . $_token . '">';
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 'Terms Link <input type="text" size="20" name="terms" value="' . $row['terms'] . '"><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 '</form><br><br><br>';
......
<?php
$systemTimeZone = system('date +%Z');
$systemTimeZone = exec('date +%Z');
// Required parameters.
($_domain = $_POST['domain'] ?? null) || die('no pod domain given');
......
ALTER TABLE pods ADD terms text, ADD sslexpire timestamp, ADD uptime_custom text, ADD dnssec boolean, ADD masterversion text, ADD shortversion text;
ALTER TABLE pods DROP Hgitdate, DROP Hgitref, DROP Hruntime, DROP Hencoding, DROP longversion, DROP ptr, DROP whois, DROP postalcode, DROP connection, DROP pingdomlast;
ALTER TABLE pods RENAME COLUMN pingdomurl TO statsurl;
ALTER TABLE pods RENAME COLUMN xmpp TO service_xmpp;
ALTER TABLE pods RENAME COLUMN uptimelast7 TO uptime_alltime;
ALTER TABLE pods RENAME COLUMN responsetimelast7 TO responsetime;
ALTER TABLE pods RENAME COLUMN dateUpdated TO date_updated;
ALTER TABLE pods RENAME COLUMN dateLaststats TO date_laststats;
ALTER TABLE pods RENAME COLUMN dateCreated TO date_created;
ALTER TABLE pods ALTER COLUMN ipv6 TYPE boolean USING ipv6::boolean;
ALTER TABLE pods ALTER hidden DROP DEFAULT;
ALTER TABLE pods ALTER COLUMN hidden TYPE boolean USING hidden::boolean;
ALTER TABLE pods ALTER COLUMN secure TYPE boolean USING secure::boolean;
ALTER TABLE pods ALTER COLUMN signup TYPE boolean USING signup::boolean;
DROP TABLE users;
CREATE TABLE apikeys (
key text,
email text,
usage int,
date_created timestamp DEFAULT current_timestamp
);
CREATE TABLE clicks (
domain text,
manualclick int,
autoclick int,
date_clicked timestamp DEFAULT current_timestamp
);
CREATE TABLE checks (
domain text,
online boolean,
error text,
date_checked timestamp DEFAULT current_timestamp
);
......@@ -46,11 +46,11 @@ $dbh || die('Error in connection: ' . pg_last_error());
//foreach pod check it and update db
if ($_domain) {
$sql = 'SELECT domain,pingdomurl,score,datecreated,weight FROM pods WHERE domain = $1';
$sql = 'SELECT domain,statsurl,score,date_created,weight FROM pods WHERE domain = $1';
$sleep = '0';
$result = pg_query_params($dbh, $sql, [$_domain]);
} elseif (PHP_SAPI === 'cli') {
$sql = 'SELECT domain,pingdomurl,score,datecreated,adminrating,weight FROM pods';
$sql = 'SELECT domain,statsurl,score,date_created,adminrating,weight FROM pods';
$sleep = '1';
$result = pg_query($dbh, $sql);
} else {
......@@ -63,7 +63,7 @@ while ($row = pg_fetch_all($result)) {
for ($i = 0; $i < $numrows; $i++) {
$domain = $row[$i]['domain'];
$score = (int) $row[$i]['score'];
$dateadded = $row[$i]['datecreated'];
$dateadded = $row[$i]['date_created'];
$admindb = (int) $row[$i]['adminrating'];
$weight = $row[$i]['weight'];
//get ratings
......@@ -73,7 +73,7 @@ while ($row = pg_fetch_all($result)) {
$adminratingavg = [];
$userrating = [];
$adminrating = [];
$sqlforr = 'SELECT * FROM rating_comments WHERE domain = $1';
$sqlforr = 'SELECT admin,rating FROM rating_comments WHERE domain = $1';
$ratings = pg_query_params($dbh, $sqlforr, [$domain]);
$ratings || die('Error in SQL query2: ' . pg_last_error());
......@@ -129,7 +129,7 @@ while ($row = pg_fetch_all($result)) {
unset($service_tumblr);
unset($service_wordpess);
unset($service_xmpp);
unset($dver);
unset($shortversion);
unset($dverr);
unset($xdver);
unset($softwarename);
......@@ -168,10 +168,20 @@ while ($row = pg_fetch_all($result)) {
if (!$output && !$outpulssl && !$domain) {
continue;
echo 'no connection to pod';
$sql = 'INSERT INTO checks (domain, online, error) VALUES ($1, $2, $3)';
$result = pg_query_params($dbh, $sql, [$domain, false, $outputsslerror]);
$result || die('Error in SQL query: ' . pg_last_error());
}
if ($outputssl) {
$secure = 'true';
$outputresults = $outputssl;
$sql = 'INSERT INTO checks (domain, online) VALUES ($1, $2)';
$result = pg_query_params($dbh, $sql, [$domain, true]);
$result || die('Error in SQL query: ' . pg_last_error());
} elseif ($output) {
$secure = 'false';
$outputresults = $output;
......@@ -189,11 +199,11 @@ while ($row = pg_fetch_all($result)) {
}
$xdver = $jsonssl->software->version ?? 0;
$dverr = explode('-', trim($xdver));
$dver = $dverr[0];
$shortversion = $dverr[0];
if ($debug) {
echo ' <br> Version code: ' . $dver . '<br>';
echo ' <br> Version code: ' . $shortversion . '<br>';
}
if (!$dver) {
if (!$shortversion) {
$score = $score - 2;
}
$softwarename = $jsonssl->software->name ?? 'null';
......@@ -212,7 +222,7 @@ while ($row = pg_fetch_all($result)) {
$secure = 'false';
$score = $score - 1;
$dver = '.connect error';
$dverr = 0;
$shortversion = 0;
//no diaspora cookie on either, lets set this one as hidden and notify someone its not really a pod
//could also be a ssl pod with a bad cert, I think its ok to call that a dead pod now
}
......@@ -220,20 +230,20 @@ while ($row = pg_fetch_all($result)) {
if ($debug) {
echo '<br>Signup Open: ' . $signup . '<br>';
}
$ip6 = escapeshellcmd('dig +nocmd ' . $domain . ' aaaa +noall +short');
$ip = escapeshellcmd('dig +nocmd ' . $domain . ' a +noall +short');
$ip6num = exec($ip6);
$ipnum = exec($ip);
$test = strpos($ip6num, ':');
$ip6cmd = escapeshellcmd('dig +nocmd ' . $domain . ' aaaa +noall +short');
$ipcmd = escapeshellcmd('dig +nocmd ' . $domain . ' a +noall +short');
$ip6 = exec($ip6cmd);
$ip = exec($ipcmd);
$test = strpos($ip6, ':');
if ($test === false) {
$ipv6 = 'no';
} else {
$ipv6 = 'yes';
}
if ($debug) {
echo 'IP: ' . $ipnum . '<br>';
echo 'IP: ' . $ip . '<br>';
}
$location = geoip_record_by_name($ipnum);
$location = geoip_record_by_name($ip);
if ($debug) {
echo ' Location: ';
var_dump($location);
......@@ -254,15 +264,14 @@ while ($row = pg_fetch_all($result)) {
}
}
echo '<br>';
$connection = '';
$pingdomdate = date('Y-m-d H:i:s');
if (strpos($row[$i]['pingdomurl'], 'pingdom.com')) {
$statslastdate = date('Y-m-d H:i:s');
if (strpos($row[$i]['statsurl'], 'pingdom.com')) {
//curl the pingdom page
$ping = curl_init();
$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) {
echo $row[$i]['pingdomurl'] . $thismonth;
echo $row[$i]['statsurl'] . $thismonth;
}
curl_setopt($ping, CURLOPT_POST, 0);
curl_setopt($ping, CURLOPT_HEADER, 1);
......@@ -290,15 +299,15 @@ while ($row = pg_fetch_all($result)) {
//uptime %
preg_match_all('/<h3>Uptime this month<\/h3>\s*<p class="large">(.*?)%</', $pingdom, $matchper);
$uptime = isset($matchper[1][0]) ? preg_replace('/,/', '.', $matchper[1][0]) : 0;
$pingdomdate = date('Y-m-d H:i:s');
$statslastdate = date('Y-m-d H:i:s');
if (strpos($pingdom, "class=\"up\"")) {
$live = 'up';
$status = 'up';
} elseif (strpos($pingdom, "class=\"down\"")) {
$live = 'down';
$status = 'down';
} elseif (strpos($pingdom, "class=\"paused\"")) {
$live = 'paused';
$status = 'paused';
} else {
$live = 'error';
$status = 'error';
$score = $score - 2;
}
} else {
......@@ -308,7 +317,7 @@ while ($row = pg_fetch_all($result)) {
} else {
//do uptimerobot API instead
$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_HEADER, 0);
curl_setopt($ping, CURLOPT_RETURNTRANSFER, 1);
......@@ -331,25 +340,26 @@ while ($row = pg_fetch_all($result)) {
$responsetime = $uptr->monitors->monitor{'0'}->responsetime{'0'}->value;
$uptimerobotstat = $uptr->stat;
$uptime = $uptr->monitors->monitor{'0'}->alltimeuptimeratio;
$uptime_custom = $uptr->monitors->monitor{'0'}->customuptimeratio;
$diff = abs(strtotime(date('Y-m-d H:i:s')) - strtotime($dateadded));
$months = floor(($diff - $years * 365 * 60 * 60 * 24) / (30 * 60 * 60 * 24));
if ($uptr->monitors->monitor{'0'}->status == 2) {
$live = 'Up';
$status = 'Up';
}
if ($uptr->monitors->monitor{'0'}->status == 0) {
$live = 'Paused';
$status = 'Paused';
}
if ($uptr->monitors->monitor{'0'}->status == 1) {
$live = 'Not Checked Yet';
$status = 'Not Checked Yet';
}
if ($uptr->monitors->monitor{'0'}->status == 8) {
$live = 'Seems Down';
$status = 'Seems Down';
}
if ($uptr->monitors->monitor{'0'}->status == 9) {
$live = 'Down';
$status = 'Down';
}
$pingdomdate = date('Y-m-d H:i:s');
if ($uptimerobotstat == 'fail' || $live <> 'Up') {
if ($uptimerobotstat == 'fail' || $status <> 'Up') {
$score = $score - 2;
}
}
......@@ -376,13 +386,9 @@ while ($row = pg_fetch_all($result)) {
//sql it
$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,
uptimelast7 = $10, status = $11, dateLaststats = $12, dateUpdated = $13, responsetimelast7 = $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,
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
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]);
$sql = 'UPDATE pods SET secure = $2, hidden = $3, ip = $4, ipv6 = $5, monthsmonitored = $6, uptime_alltime = $7, status = $8, date_laststats = $9, date_updated = $10, responsetime = $11, score = $12, adminrating = $13, country = $14, city = $15, state = $16, lat = $17, long = $18, userrating = $19, shortversion = $20, masterversion = $21, signup = $22, total_users = $23, active_users_halfyear = $24, active_users_monthly = $25, local_posts = $26, name = $27, comment_counts = $28, service_facebook = $29, service_tumblr = $30, service_twitter = $31, service_wordpress = $32, weightedscore = $33, service_xmpp = $34, softwarename = $35, sslvalid = $36, uptime_custom = $37
WHERE domain = $1';
$result = pg_query_params($dbh, $sql, [$domain, $secure, $hidden, $ip, $ipv6, $months, $uptime, $status, $statslastdate, $timenow, $responsetime, $score, $adminrating, $country, $city, $state, $lat, $long, $userrating, $shortversion, $masterversion, $signup, $total_users, $active_users_halfyear, $active_users_monthly, $local_posts, $name, $comment_counts, $service_facebook, $service_tumblr, $service_twitter, $service_wordpress, $weightedscore, $service_xmpp, $softwarename, $outputsslerror, $uptime_custom]);
$result || die('Error in SQL query3: ' . pg_last_error());
if ($debug) {
......
......@@ -3,52 +3,49 @@ CREATE TABLE pods (
domain text UNIQUE NOT NULL,
name text,
softwarename text,
masterversion text,
shortversion text,
score int DEFAULT 10,
weightedscore numeric(5,2) DEFAULT 10,
adminrating decimal DEFAULT 10,
userrating decimal DEFAULT 10,
whois text,
hidden text DEFAULT 'yes',
hidden boolean DEFAULT true,
ip text,
ptr text,
country text,
city text,
state text,
lat text,
long text,
connection text,
postalcode text,
email text,
ipv6 text,
secure text,
ipv6 boolean,
secure boolean,
sslvalid text,
Hgitdate text,
Hgitref text,
Hruntime text,
Hencoding text,
pingdomurl text,
pingdomlast text,
statsurl text,
monthsmonitored int,
signup int,
signup boolean,
total_users int,
active_users_halfyear int,
active_users_monthly int,
local_posts int,
uptimelast7 numeric(5,2),
uptime_alltime numeric(5,2),
uptime_custom text,
status text,
responsetimelast7 text,
responsetime text,
service_facebook boolean,
service_twitter boolean,
service_tumblr boolean,
service_wordpress boolean,
service_xmpp boolean,
token text,
tokenexpire timestamp,
terms text,
sslexpire timestamp,
dnssec boolean,
comment_counts int,
weight int DEFAULT 10,
xmpp boolean,
dateUpdated timestamp DEFAULT current_timestamp,
dateLaststats timestamp DEFAULT current_timestamp,
dateCreated timestamp DEFAULT current_timestamp
weight int DEFAULT 50,
date_updated timestamp DEFAULT current_timestamp,
date_laststats timestamp DEFAULT current_timestamp,
date_created timestamp DEFAULT current_timestamp
);
CREATE TABLE rating_comments (
id serial8 UNIQUE PRIMARY KEY,
......@@ -61,12 +58,24 @@ CREATE TABLE rating_comments (
userurl text,
date timestamp DEFAULT current_timestamp
);
CREATE TABLE users (
id serial8 UNIQUE PRIMARY KEY,
admin int