Unverified Commit 7d7ca56c authored by dmorley's avatar dmorley

Merge branch 'develop'

parents f7a1715f f909a892
bower_components
config.php
vendor
......@@ -13,6 +13,7 @@ dnsutils
bind9
npm
nodejs nodejs-legacy
composer
```
To Install:
......@@ -21,6 +22,7 @@ git clone https://github.com/diasporg/Poduptime.git
cd Poduptime
sudo npm install -g bower
bower install
composer install
cp config.php.example config.php
```
......@@ -50,6 +52,7 @@ To Upgrade:
cd Poduptime
git pull
bower install
composer install
psql -u podupuser podupdb < db/migrationx.sql (see db/version.md for proper migration version)
```
......
<?php
//Copyright (c) 2011, David Morley. This file is licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file.
use RedBeanPHP\R;
($_GET['key'] ?? null) === '4r45tg' || die;
// Other parameters.
......@@ -7,10 +10,14 @@ $_format = $_GET['format'] ?? '';
$_method = $_GET['method'] ?? '';
$_callback = $_GET['callback'] ?? '';
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/config.php';
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
$dbh || die('Error in connection: ' . pg_last_error());
define('PODUPTIME', microtime(true));
// Set up global DB connection.
R::setup("pgsql:host={$pghost};dbname={$pgdb}", $pguser, $pgpass, true);
R::testConnection() || die('Error in DB connection');
if ($_format === 'georss') {
echo <<<EOF
......@@ -21,50 +28,58 @@ if ($_format === 'georss') {
<link href="https://{$_SERVER['HTTP_HOST']}/"/>
EOF;
$sql = "SELECT name,monthsmonitored,responsetimelast7,uptimelast7,dateupdated,score,domain,country,lat,long FROM pods_apiv1";
$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)) {
$pod_name = htmlentities($row['name'], ENT_QUOTES);
$summary = sprintf(
try {
$pods = R::getAll('
SELECT name, monthsmonitored, responsetimelast7, uptimelast7, dateupdated, score, domain, country, lat, long
FROM pods_apiv1
');
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
}
foreach ($pods as $pod) {
$summary = sprintf(
'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['dateupdated'],
$row['score']
htmlentities($pod['name'], ENT_QUOTES),
$pod['monthsmonitored'],
$pod['responsetimelast7'],
$pod['uptimelast7'],
$pod['dateupdated'],
$pod['score']
);
echo <<<EOF
<entry>
<title>https://{$row['domain']}</title>
<link href="{$scheme}{$row['domain']}"/>
<id>urn:{$row['domain']}</id>
<summary>Pod Location is: {$row['country']}
<title>https://{$pod['domain']}</title>
<link href="https://{$pod['domain']}"/>
<id>urn:{$pod['domain']}</id>
<summary>Pod Location is: {$pod['country']}
&#xA;
{$summary}</summary>
<georss:point>{$row['lat']} {$row['long']}</georss:point>
<georss:featureName>{$row['domain']}</georss:featureName>
<georss:point>{$pod['lat']} {$pod['long']}</georss:point>
<georss:featureName>{$pod['domain']}</georss:featureName>
</entry>
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_apiv1';
$result = pg_query($dbh, $sql);
$result || die('Error in SQL query: ' . pg_last_error());
try {
$pods = R::getAll('
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_apiv1
');
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
}
//json output, thx Vipul A M for fixing this
header('Content-type: application/json');
$numrows = pg_num_rows($result);
$rows = array_values(pg_fetch_all($result));
$obj = [
'podcount' => $numrows,
'pods' => $rows,
$obj = [
'podcount' => count($pods),
'pods' => allToString($pods),
];
if ($_method === 'jsonp') {
print $_callback . '(' . json_encode($obj) . ')';
......@@ -72,20 +87,51 @@ EOF;
print json_encode($obj);
}
} else {
$i = 0;
$sql = "SELECT domain,uptimelast7,country FROM pods_apiv1";
$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)) {
try {
$pods = R::getAll('
SELECT domain, uptimelast7, country
FROM pods_apiv1
');
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
}
$i = 0;
foreach ($pods as $pod) {
$i++ > 0 && print ',';
printf(
'%1$s Up %2$s%% This Month - Located in: %3$s',
$row['domain'],
$row['uptimelast7'],
$row['country']
$pod['domain'],
$pod['uptimelast7'],
$pod['country']
);
}
}
/**
* Convert all passed items to strings.
*
* This method is for backwards compatibility of APIv1 only!
* After v2 is released and stable, this can safely be removed.
*
* @param array $arr List of all elements to stringify.
*
* @return array
*/
function allToString(array $arr)
{
$ret = $arr;
foreach ($ret as &$item) {
if (is_array($item)) {
/** @var array $item */
foreach ($item as &$field) {
$field !== null && $field = (string) $field;
}
} else {
$item !== null && $item = (string) $item;
}
unset($field, $item);
}
return $ret;
}
<?php
require_once __DIR__ . '/config.php';
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
$dbh || die('Error in connection: ' . pg_last_error());
use RedBeanPHP\R;
$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,latency,date_updated,ipv6,total_users,local_posts,comment_counts,stats_apikey,userrating,sslvalid FROM pods WHERE score < 50 ORDER BY weightedscore";
$result = pg_query($dbh, $sql);
$result || die('Error in SQL query: ' . pg_last_error());
$numrows = pg_num_rows($result);
defined('PODUPTIME') || die();
try {
$pods = R::getAll('
SELECT domain, masterversion, shortversion, monthsmonitored, score, signup, name, uptime_alltime, active_users_halfyear, active_users_monthly, latency, date_updated, total_users, local_posts, comment_counts, stats_apikey, sslvalid
FROM pods
WHERE score < 50
ORDER BY weightedscore ASC
');
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
}
?>
<meta property="og:title" content="<?php echo $numrows; ?> #Diaspora Pods listed, Come see the privacy aware social network."/><?php echo $numrows; ?> pods that are open for signup now.
<meta property="og:title" content="<?php echo count($pods); ?> #Diaspora Pods listed, Come see the privacy aware social network."/><?php echo count($pods); ?> pods that are open for signup now.
<meta charset="utf-8">
<!-- /* Copyright (c) 2011, David Morley. This file is licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file. */ -->
<div class="table-responsive">
<table class="table table-striped table-sm tablesorter table-hover tfont">
<table class="table table-striped table-sm tablesorter-bootstrap table-hover tfont">
<thead>
<tr>
<th>Pod<a class="tipsy" title="A pod is a site for you to set up your account.">?</a></th>
......@@ -36,59 +42,60 @@ $numrows = pg_num_rows($result);
<tbody>
<?php
$tt = 0;
while ($row = pg_fetch_array($result)) {
foreach ($pods as $pod) {
$tt++;
$verdiff = str_replace('.', '', $row['masterversion']) - str_replace('.', '', $row['shortversion']);
$verdiff = (int) str_replace('.', '', $pod['masterversion']) - (int) str_replace('.', '', $pod['shortversion']);
$pod_name = htmlentities($row['name'], ENT_QUOTES);
$pod_name = htmlentities($pod['name'], ENT_QUOTES);
$tip = sprintf(
'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['latency'],
$row['uptime_alltime'],
$row['date_updated'],
$row['score']
$pod['monthsmonitored'],
$pod['latency'],
$pod['uptime_alltime'],
$pod['date_updated'],
$pod['score']
);
echo '<tr><td><a class="text-success" target="_self" href="https://' . $row['domain'] . '">' . $row['domain'] . '<div title="' . $tip . '" class="tipsy" style="display: inline-block">?</div></a></td>';
echo '<tr><td><a class="text-success" target="_self" href="https://' . $pod['domain'] . '">' . $pod['domain'] . '<div title="' . $tip . '" class="tipsy" style="display: inline-block">?</div></a></td>';
if (stristr($row['shortversion'], 'head')) {
if (stristr($pod['shortversion'], 'head')) {
$version = '.dev';
$pre = 'This pod runs pre release development code';
} elseif (!$row['shortversion']) {
} elseif (!$pod['shortversion']) {
$version = '0';
$pre = 'This pod runs unknown code';
} else {
$version = $row['shortversion'];
$version = $pod['shortversion'];
$pre = 'This pod runs production code';
}
if ($row['shortversion'] === $row['masterversion'] && $row['shortversion'] !== '') {
if ($pod['shortversion'] === $pod['masterversion'] && $pod['shortversion'] !== '') {
$classver = 'text-success';
} elseif ($verdiff > 6) {
$classver = 'text-warning';
} else {
$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['uptime_alltime'] . '</td>';
echo '<td>' . $row['latency'] . '</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>';
$moreurl = 'https://api.uptimerobot.com/getMonitors?format=json&noJsonCallback=1&customUptimeRatio=7-30-60-90&apiKey=' . $row['stats_apikey'];
echo '<td><div title="Last Check ' . $row['date_updated'] . '" class="tipsy"><a target="_self" href="' . $moreurl . '">' . $row['monthsmonitored'] . '</a></div></td>';
echo '<td>' . $row['score'] . '</td>';
echo '<td><div class="tipsy" title="' . $row['sslvalid'] . '">con info</td>';
echo '<td class="' . $classver . '"><div title="' . $pre . ' codename: ' . $pod['shortversion'] . ' master version is: ' . $pod['masterversion'] . '" class="tipsy">' . $version . '</div></td>';
echo '<td>' . $pod['uptime_alltime'] . '</td>';
echo '<td>' . $pod['latency'] . '</td>';
echo '<td>' . ($pod['signup'] ? 'Open' : 'Closed') . '</td>';
echo '<td>' . $pod['total_users'] . '</td>';
echo '<td>' . $pod['active_users_halfyear'] . '</td>';
echo '<td>' . $pod['active_users_monthly'] . '</td>';
echo '<td>' . $pod['local_posts'] . '</td>';
echo '<td>' . $pod['comment_counts'] . '</td>';
$moreurl = 'https://api.uptimerobot.com/getMonitors?format=json&noJsonCallback=1&customUptimeRatio=7-30-60-90&apiKey=' . $pod['stats_apikey'];
echo '<td><div title="Last Check ' . $pod['date_updated'] . '" class="tipsy"><a target="_self" href="' . $moreurl . '">' . $pod['monthsmonitored'] . '</a></div></td>';
echo '<td>' . $pod['score'] . '</td>';
echo '<td><div class="tipsy" title="' . $pod['sslvalid'] . '">con info</td>';
?>
<td>
<form method="post" action="db/kill.php" target="_blank">
<input type="hidden" name="domain" value="<?php echo $row['domain']; ?>">
<input type="hidden" name="domain" value="<?php echo $pod['domain']; ?>">
<input type="hidden" name="adminkey" value="<?php echo $_COOKIE['adminkey']; ?>">
<label>Comments<input name="comments" value="<?php echo $row['sslvalid']; ?>" size="10"></label>
<label>Comments<input name="comments" value="<?php echo $pod['sslvalid']; ?>" size="10"></label>
<label><input type="radio" name="action" value="warn">warn</label>
<label><input type="radio" name="action" value="delete">delete</label>
<input type="submit" value="Process">
......
{
"require": {
"noplanman/xec": "0.1.0",
"gabordemooij/redbean": "^4.3"
}
}
This diff is collapsed.
......@@ -6,6 +6,8 @@ $backup_dir = '/backup';
$log_dir = '/log';
//location of pg dump
$pg_dump_dir = '/usr/bin';
//db host
$pghost = 'localhost';
//db username
$pguser = '';
//db password
......
/*
* Base structure
*/
/* Move down content because we have a fixed navbar that is 54px tall */
body {
padding-top: 54px;
}
/*
* Global add-ons
*/
.sub-header {
border-bottom: 1px solid #eee;
padding-bottom: 10px;
}
/*
* Sidebar
*/
.sidebar {
background-color: #f5f5f5;
border-right: 1px solid #eee;
bottom: 0;
display: block;
overflow-x: hidden;
overflow-y: auto; /* Scrollable contents if viewport is shorter than content. */
padding: 10px;
position: fixed;
top: 54px;
z-index: 1000;
}
.sidebar .nav {
margin-bottom: 20px;
}
.sidebar .nav .nav-link {
padding: .3em .7em;
}
/*
* Main content
*/
.main {
padding: 20px;
}
/*
* Placeholder dashboard ideas
*/
.placeholders {
margin-bottom: 30px;
text-align: center;
}
.placeholders h4 {
margin-bottom: 0;
}
.placeholder {
margin-bottom: 20px;
}
.placeholder img {
border-radius: 50%;
display: inline-block;
}
body {
padding-top: 54px;
}
.sub-header {
border-bottom: 1px solid #eee;
padding-bottom: 10px;
}
.sidebar {
background-color: #f5f5f5;
border-right: 1px solid #eee;
bottom: 0;
display: block;
overflow-x: hidden;
overflow-y: auto; /* Scrollable contents if viewport is shorter than content. */
padding: 10px;
position: fixed;
top: 54px;
z-index: 1000;
}
.sidebar .nav {
margin-bottom: 20px;
}
.sidebar .nav .nav-link {
padding: .3em .7em;
}
.main {
padding: 20px;
}
.placeholders {
margin-bottom: 30px;
text-align: center;
}
.placeholders h4 {
margin-bottom: 0;
}
.placeholder {
margin-bottom: 20px;
}
.placeholder img {
border-radius: 50%;
display: inline-block;
}
.rating {
font-size:9px;
}
......@@ -51,3 +94,7 @@ z-index: 1000 !important;
#facebox .content {
width: 800px !important;
}
.tablesorter-header {
background-size: 10px 15px !important;
}
<!-- /* Copyright (c) 2011, David Morley. This file is licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file. */ -->
<?php
use RedBeanPHP\R;
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../logging.php';
require_once __DIR__ . '/../config.php';
define('PODUPTIME', microtime(true));
$log = new Logging();
$log->lfile(__DIR__ . '/../' . $log_dir . '/add.log');
if (!($_domain = $_GET['domain'] ?? null)) {
......@@ -9,6 +16,7 @@ if (!($_domain = $_GET['domain'] ?? null)) {
die('no pod domain given');
}
// Other parameters.
$_email = $_GET['email'] ?? '';
$_podmin_statement = $_GET['podmin_statement'] ?? '';
$_podmin_notify = $_GET['podmin_notify'] ?? 0;
......@@ -18,29 +26,47 @@ if (!filter_var(gethostbyname($_domain), FILTER_VALIDATE_IP)) {
die('Could not validate the domain name, be sure to enter it as "domain.com" (no caps, no slashes, no extras)');
}
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
$dbh || die('Error in connection: ' . pg_last_error());
// Set up global DB connection.
R::setup("pgsql:host={$pghost};dbname={$pgdb}", $pguser, $pgpass, true);
R::testConnection() || die('Error in DB connection');
$sql = 'SELECT domain, stats_apikey, publickey, email FROM pods';
$result = pg_query($dbh, $sql);
$result || die('Error in SQL query: ' . pg_last_error());
try {
$pods = R::getAll('
SELECT id, domain, stats_apikey, publickey, email
FROM pods
');
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
}
while ($row = pg_fetch_array($result)) {
if ($row['domain'] === $_domain ) {
if ($row['email']) {
foreach ($pods as $pod) {
if ($pod['domain'] === $_domain) {
if ($pod['email']) {
$log->lwrite('domain already exists and is registered to an owner' . $_domain);
die('domain already exists and is registered to an owner, use the edit function to modify');
}
$digtxt = exec(escapeshellcmd('dig ' . $_domain . ' TXT +short'));
if (strpos($digtxt, $row['publickey']) !== false) {
echo 'domain validated, you can now add details ';
$uuid = md5(uniqid($_domain, true));
$expire = time() + 2700;
$sql = 'UPDATE pods SET token = $1, tokenexpire = $2 WHERE domain = $3';
$result = pg_query_params($dbh, $sql, [$uuid, date('Y-m-d H:i:s', $expire), $_domain]);
$result || die('Error in SQL query: ' . pg_last_error());
if (strpos($digtxt, $pod['publickey']) !== false) {
echo 'domain validated, you can now add details ';
$uuid = md5(uniqid($_domain, true));
$expire = time() + 2700;
try {
$p = R::findOne('pods', $pod['id']);
$p['token'] = $uuid;
$p['tokenexpire'] = date('Y-m-d H:i:s', $expire);
// @todo Temporary fix! https://github.com/gabordemooij/redbean/issues/547
foreach ($p->getProperties() as $key => $value) {
$pod[$key] = $value;
}
R::store($p);
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
}
echo <<<EOF
<form action="edit.php" method="get">
<input type="hidden" name="domain" value="{$_domain}">
......@@ -51,11 +77,11 @@ while ($row = pg_fetch_array($result)) {
<input type="submit" name="action" value="save">
</form>
EOF;
die;
} else {
$log->lwrite('domain already exists and can be registered' . $_domain);
die('domain already exists, you can claim the domain by adding a DNS TXT record that states<br><b> ' . $_domain . ' IN TXT "' . $row['publickey'] . '"</b>');
die('domain already exists, you can claim the domain by adding a DNS TXT record that states<br><b> ' . $_domain . ' IN TXT "' . $pod['publickey'] . '"</b>');
}
}
}
......@@ -74,10 +100,25 @@ if (stristr($outputssl, 'openRegistrations')) {
$log->lwrite('Your pod has ssl and is valid ' . $_domain);
echo 'Your pod has ssl and is valid<br>';
$publickey = md5(uniqid($domain, true));
$sql = 'INSERT INTO pods (domain, email, podmin_statement, podmin_notify, publickey) VALUES ($1, $2, $3, $4, $5)';
$result = pg_query_params($dbh, $sql, [$_domain, $_email, $_podmin_statement, $_podmin_notify, $publickey]);
$result || die('Error in SQL query: ' . pg_last_error());
$publickey = md5(uniqid($_domain, true));
try {
$p = R::dispense('pods');
$p['domain'] = $_domain;
$p['email'] = $_email;
$p['podmin_statement'] = $_podmin_statement;
$p['podmin_notify'] = $_podmin_notify;
$p['publickey'] = $publickey;
// @todo Temporary fix! https://github.com/gabordemooij/redbean/issues/547
foreach ($p->getProperties() as $key => $value) {
$pod[$key] = $value;
}
R::store($p);
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
}
if ($_email) {
$to = $adminemail;
......@@ -94,7 +135,7 @@ if (stristr($outputssl, 'openRegistrations')) {
@mail($to, $subject, implode("\r\n", $message_lines), implode("\r\n", $headers));
}
echo 'Data successfully inserted! Your pod will be reviewed and live on the list in a few hours!';
} else {
......
......@@ -2,33 +2,43 @@
//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
use RedBeanPHP\R;
// Required parameters.
($_domain = $_GET['domain'] ?? null) || die('no domain given');
// Other parameters.
$_format = $_GET['format'] ?? '';
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../config.php';
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
$dbh || die('Error in connection: ' . pg_last_error());
$sql = 'SELECT hgitdate,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_apiv1 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['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>';
}
define('PODUPTIME', microtime(true));
// Set up global DB connection.
R::setup("pgsql:host={$pghost};dbname={$pgdb}", $pguser, $pgpass, true);
R::testConnection() || die('Error in DB connection');
try {
$pod = R::getRow('
SELECT hgitdate, 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_apiv1
WHERE domain = ?
', [$_domain]);
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
}
if ($_format === 'json') {
echo json_encode($pod);
} else {
echo 'Status: ' . $pod['status'] . '<br>';
echo 'Last Git Pull: ' . $pod['hgitdate'] . '<br>';
echo 'Uptime This Month ' . $pod['uptimelast7'] . '<br>';
echo 'Months Monitored: ' . $pod['monthsmonitored'] . '<br>';
echo 'Response Time: ' . $pod['responsetimelast7'] . '<br>';
echo 'User Rating: ' . $pod['userrating'] . '<br>';
echo 'Server Location: ' . $pod['country'] . '<br>';
echo 'Latitude: ' . $pod['lat'] . '<br>';
echo 'Longitude: ' . $pod['long'] . '<br>';
}
<?php
use RedBeanPHP\R;
// Required parameters.
($_domain = $_GET['domain'] ?? null) || die('no pod domain given');
($_token = $_GET['token'] ?? null) || die('no token given');
......@@ -11,55 +14,70 @@ $_email = $_GET['email'] ?? '';
$_podmin_statement = $_GET['podmin_statement'] ?? '';
$_podmin_notify = $_GET['podmin_notify'] ?? 0;
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../config.php';
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
$dbh || die('Error in connection: ' . pg_last_error());
define('PODUPTIME', microtime(true));
$sql = 'SELECT domain,email,token,tokenexpire,weight,podmin_statement,podmin_notify FROM pods WHERE domain = $1';
$result = pg_query_params($dbh, $sql, [$_domain]);
$result || die('Error in SQL query: ' . pg_last_error());
// Set up global DB connection.
R::setup("pgsql:host={$pghost};dbname={$pgdb}", $pguser, $pgpass, true);
R::testConnection() || die('Error in DB connection');
while ($row = pg_fetch_array($result)) {
$row['token'] === $_token || die('token mismatch');
$row['tokenexpire'] >= date('Y-m-d H:i:s') || die('token expired');
try {
$pod = R::findOne('pods', 'domain = ?', [$_domain]);
$pod || die('domain not found');
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
}
// Delete and exit.
if ('delete' === $_action) {
$sql = 'DELETE FROM pods WHERE domain = $1';
$result = pg_query_params($dbh, $sql, [$_domain]);
$result || die('Error in SQL query: ' . pg_last_error());
$pod['token'] === $_token || die('token mismatch');
$pod['tokenexpire'] >= date('Y-m-d H:i:s') || die('token expired');
die('pod removed from DB');
}
// Delete and exit.
if ('delete' === $_action) {