Unverified Commit 97358212 authored by dmorley's avatar dmorley

Merge branch 'develop'

parents 39b28467 4fe717ba
# 2.2.0
## Podmins
* Can now pause/unpause or delete from podmin area
## End Users
* go.php auto select picks a more stable pod than before
* Graph on user growth on the network
* Make map prettier
* Use lines on tables to make them more readable
## Cleanup
* Don't delete dead pods, keep them and data for history hide them for users
* Put daily tasks in the pull.sh and run each day
* Fix ipv6
## DB
* Add monthly stats table
* Update status to 1-5 rather than text
* Two migrations for this version update see db/version.md
......@@ -4,16 +4,7 @@ Poduptime is software to get live stats and data on listed Diaspora Pods.
Dependencies:
```
php7.0 php7.0-curl php7.0-pgsql php-geoip php7.0-cli php7.0-common php7.0-json php7.0-readline php-cgi
git
curl
postgresql postgresql-contrib
wget
dnsutils
bind9
npm
nodejs nodejs-legacy
composer
php7.2 php7.2-curl php7.2-pgsql php-geoip php7.2-cli php7.2-common php7.2-json php7.2-readline php-cgi git curl postgresql postgresql-contrib wget dnsutils bind9 npm nodejs nodejs-legacy composer
```
To Install:
......@@ -39,13 +30,16 @@ sudo nano /etc/postgresql/vx.x/main/pg_hba.conf
# restart postgresql
# import database structure
psql -u podupuser podupdb < db/tables.sql
psql -U podupuser podupdb < db/tables.sql
```
Edit `config.php` to add your DB and file settings.
touch add.log in location you configured in config.php
run db/pull.sh manually or with cron to update your data
run `db/pull.sh` manually or with cron to update your data
run `db/pull.sh debug` to debug output
run `db/pull.sh develop` to run without email alerts to end users
run `db/pull.sh Check_System_Deleted` to re-check system deleted pods as needed
To Upgrade:
```
......@@ -53,7 +47,7 @@ cd Poduptime
git pull
bower install
composer install
psql -u podupuser podupdb < db/migrationx.sql (see db/version.md for proper migration version)
psql -U podupuser podupdb < db/migrationXXX.sql (see db/version.md for proper migration versions)
```
============================
......
......@@ -18,6 +18,7 @@ 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');
R::usePartialBeans(true);
if ($_format === 'georss') {
echo <<<EOF
......
<?php
use RedBeanPHP\R;
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 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-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>
<th>Version<a class="tipsy" title="Version of Diaspora this pod runs">?</a></th>
<th>Uptime<a class="tipsy" title="Percent of the time the pod is online for <?php echo date('F') ?>.">?</a></th>
<th>ms</th>
<th>Signups</th>
<th>Total<a class="tipsy" title="Number of total users on this pod.">?</a></th>
<th>Active 6<a class="tipsy" title="Number of users active last 6 months on this pod.">?</a></th>
<th>Active 1<a class="tipsy" title="Number of users active last 1 month on this pod.">?</a></th>
<th>Posts<a class="tipsy" title="Number of total posts on this pod.">?</a></th>
<th>Comm<a class="tipsy" title="Number of total comments on this pod.">?</a></th>
<th>Month<a class="tipsy" title="How many months has this pod been online? Click number for more history.">?</a></th>
<th>Sc<a class="tipsy" title="System Score on a 100 scale.">?</a></th>
<th>conn<a class="tipsy" title="">?</a></th>
<th>Delete?<a class="tipsy" title="Delete this pod from DB?">?</a></th>
</tr>
</thead>
<tbody>
<?php
$tt = 0;
foreach ($pods as $pod) {
$tt++;
$verdiff = (int) str_replace('.', '', $pod['masterversion']) - (int) str_replace('.', '', $pod['shortversion']);
$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,
$pod['monthsmonitored'],
$pod['latency'],
$pod['uptime_alltime'],
$pod['date_updated'],
$pod['score']
);
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($pod['shortversion'], 'head')) {
$version = '.dev';
$pre = 'This pod runs pre release development code';
} elseif (!$pod['shortversion']) {
$version = '0';
$pre = 'This pod runs unknown code';
} else {
$version = $pod['shortversion'];
$pre = 'This pod runs production code';
}
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: ' . $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 $pod['domain']; ?>">
<input type="hidden" name="adminkey" value="<?php echo $_COOKIE['adminkey']; ?>">
<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">
</form>
</td>
<?php
echo '</tr>';
}
?>
</tbody>
</table>
</div>
{
"require": {
"noplanman/xec": "0.1.0",
"gabordemooij/redbean": "^4.3"
"gabordemooij/redbean": "^5.0",
"jaybizzle/crawler-detect" :"1.*",
"commerceguys/enum": "^1.0"
},
"autoload": {
"classmap": ["lib"]
}
}
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "8e8b0627248a269ae9d624bef32e61d6",
"content-hash": "b753491dc03e2084e9587d0bbafad98c",
"packages": [
{
"name": "commerceguys/enum",
"version": "v1.0",
"source": {
"type": "git",
"url": "https://github.com/commerceguys/enum.git",
"reference": "1d9db2dbeb1a02500e7a14589ae2f9cb402c5c95"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/commerceguys/enum/zipball/1d9db2dbeb1a02500e7a14589ae2f9cb402c5c95",
"reference": "1d9db2dbeb1a02500e7a14589ae2f9cb402c5c95",
"shasum": ""
},
"require": {
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"autoload": {
"psr-4": {
"CommerceGuys\\Enum\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Bojan Zivanovic"
}
],
"description": "A PHP 5.4+ enumeration library.",
"time": "2015-02-27T21:36:56+00:00"
},
{
"name": "gabordemooij/redbean",
"version": "v4.3.3",
"version": "v5.1",
"source": {
"type": "git",
"url": "https://github.com/gabordemooij/redbean.git",
"reference": "1c7ec69850e9f7966ff7feb87b01d8f43a9753d3"
"reference": "a02e58ad5519149f572559a8293b5dffea385956"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/gabordemooij/redbean/zipball/1c7ec69850e9f7966ff7feb87b01d8f43a9753d3",
"reference": "1c7ec69850e9f7966ff7feb87b01d8f43a9753d3",
"url": "https://api.github.com/repos/gabordemooij/redbean/zipball/a02e58ad5519149f572559a8293b5dffea385956",
"reference": "a02e58ad5519149f572559a8293b5dffea385956",
"shasum": ""
},
"require": {
......@@ -37,15 +75,64 @@
{
"name": "Gabor de Mooij",
"email": "gabor@redbeanphp.com",
"homepage": "http://redbeanphp.com"
"homepage": "https://redbeanphp.com"
}
],
"description": "RedBeanPHP ORM",
"homepage": "http://redbeanphp.com/",
"homepage": "https://redbeanphp.com/",
"keywords": [
"orm"
],
"time": "2016-10-03T21:25:17+00:00"
"time": "2018-04-01T11:51:37+00:00"
},
{
"name": "jaybizzle/crawler-detect",
"version": "v1.2.62",
"source": {
"type": "git",
"url": "https://github.com/JayBizzle/Crawler-Detect.git",
"reference": "f9767578e00f87a081835b49adc7c71074a5b46c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/JayBizzle/Crawler-Detect/zipball/f9767578e00f87a081835b49adc7c71074a5b46c",
"reference": "f9767578e00f87a081835b49adc7c71074a5b46c",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "4.8.*",
"satooshi/php-coveralls": "1.*"
},
"type": "library",
"autoload": {
"psr-4": {
"Jaybizzle\\CrawlerDetect\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Mark Beech",
"email": "m@rkbee.ch",
"role": "Developer"
}
],
"description": "CrawlerDetect is a PHP class for detecting bots/crawlers/spiders via the user agent",
"homepage": "https://github.com/JayBizzle/Crawler-Detect/",
"keywords": [
"crawler",
"crawler detect",
"crawler detector",
"crawlerdetect",
"php crawler detect"
],
"time": "2018-03-27T18:25:43+00:00"
},
{
"name": "noplanman/xec",
......
......@@ -16,9 +16,9 @@ $pgpass = '';
$pgdb = '';
//admin email for forms
$adminemail = '';
//admin key for deleting pods, set this as a cookie on your own
$adminkey = '';
//DNS server for dnssec testing
//DNS server for dnssec testing. 1.1.1.1 tests the best
$dnsserver = '';
//CA for curl to use - suggest wget http://curl.haxx.se/ca/cacert.pem as they pull from mozilla if you use a system CA then certs like wosign and startssl will be valid but users will be unable to connect to them
$cafullpath = '';
//Mapbox.com API key. https://www.mapbox.com/help/how-access-tokens-work/
$mapboxkey = '';
......@@ -29,10 +29,11 @@ if (!filter_var(gethostbyname($_domain), FILTER_VALIDATE_IP)) {
// Set up global DB connection.
R::setup("pgsql:host={$pghost};dbname={$pgdb}", $pguser, $pgpass, true);
R::testConnection() || die('Error in DB connection');
R::usePartialBeans(true);
try {
$pods = R::getAll('
SELECT id, domain, stats_apikey, publickey, email
SELECT id, domain, publickey, email
FROM pods
');
} catch (\RedBeanPHP\RedException $e) {
......@@ -57,11 +58,6 @@ foreach ($pods as $pod) {
$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) {
$p[$key] = $value;
}
R::store($p);
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
......@@ -110,11 +106,6 @@ if (stristr($outputssl, 'openRegistrations')) {
$p['podmin_notify'] = $_podmin_notify;
$p['publickey'] = $publickey;
// @todo Temporary fix! https://github.com/gabordemooij/redbean/issues/547
foreach ($p->getProperties() as $key => $value) {
$p[$key] = $value;
}
R::store($p);
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
......
......@@ -18,6 +18,7 @@ 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');
R::usePartialBeans(true);
try {
$pod = R::getRow('
......@@ -32,7 +33,12 @@ try {
if ($_format === 'json') {
echo json_encode($pod);
} else {
echo 'Status: ' . $pod['status'] . '<br>';
if ($pod['status'] === PodStatus::Up) {
echo 'Status: Up<br>';
}
if ($pod['status'] === PodStatus::Down) {
echo 'Status: Down<br>';
}
echo 'Last Git Pull: ' . $pod['hgitdate'] . '<br>';
echo 'Uptime This Month ' . $pod['uptimelast7'] . '<br>';
echo 'Months Monitored: ' . $pod['monthsmonitored'] . '<br>';
......
<?php
use RedBeanPHP\R;
use CommerceGuys\Enum\AbstractEnum;
// Required parameters.
($_domain = $_GET['domain'] ?? null) || die('no pod domain given');
......@@ -17,12 +18,6 @@ $_podmin_notify = $_GET['podmin_notify'] ?? 0;
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../config.php';
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::findOne('pods', 'domain = ?', [$_domain]);
$pod || die('domain not found');
......@@ -35,8 +30,35 @@ $pod['tokenexpire'] >= date('Y-m-d H:i:s') || die('token expired');
// Delete and exit.
if ('delete' === $_action) {
R::trash($pod);
die('pod removed from DB');
try {
$pod['status'] = PodStatus::User_Deleted;
R::store($pod);
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
}
die('pod deleted');
}
// Pause and exit.
if ('pause' === $_action) {
try {
$pod['status'] = PodStatus::Paused;
R::store($pod);
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
}
die('pod paused');
}
// Un-Pause and exit.
if ('unpause' === $_action) {
try {
$pod['status'] = PodStatus::Recheck;
R::store($pod);
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
}
die('pod unpaused');
}
// Save and exit.
......@@ -49,11 +71,6 @@ if ('save' === $_action) {
$pod['podmin_statement'] = $_podmin_statement;
$pod['podmin_notify'] = $_podmin_notify;
// @todo Temporary fix for RedBean property handling, hope this gets fixed soon!
foreach ($pod->getProperties() as $key => $value) {
$pod[$key] = $value;
}
R::store($pod);
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
......@@ -69,23 +86,38 @@ if ('save' === $_action) {
}
// Forms.
?>
Authorized to edit <b><?php echo $_domain; ?></b> until <?php echo $pod['tokenexpire']; ?><br>
<form action="edit.php" method="get">
<form>
<input type="hidden" name="edit">
<input type="hidden" name="domain" value="<?php echo $_domain; ?>">
<input type="hidden" name="token" value="<?php echo $_token; ?>">
<label>Email <input type="text" size="20" name="email" value="<?php echo $pod['email']; ?>"></label><br>
<label>Podmin Statement (You can use HTML to include links to your terms and policies and information about your pod you wish to share with users.) <br><textarea cols="100" rows="7" name="podmin_statement"><?php echo $pod['podmin_statement']; ?></textarea></label><br>
<label>Email <input type="text" size="40" name="email" value="<?php echo $pod['email']; ?>"></label><br>
<label>Podmin Statement (You can use HTML to include links to your terms and policies and information about your pod you wish to share with users.) <br><textarea cols="150" rows="10" name="podmin_statement"><?php echo $pod['podmin_statement']; ?></textarea></label><br>
<label>Weight <input type="text" size="2" name="weight" value="<?php echo $pod['weight']; ?>"> This lets you weight your pod lower on the list if you have too much traffic coming in, 10 is the norm use lower to move down the list.</label><br>
<label>Notify if pod falls to hidden status? <input type="checkbox" name="podmin_notify" <?php echo $pod['podmin_notify'] ? 'checked' : ''; ?> ></label><br>
<input type="submit" name="action" value="save">
</form>
<br>
<br>Your pod status is currently: <?php echo PodStatus::getKey((int)$pod['status']); ?>
<br>
<br>
<form action="edit.php" method="get">
<form>
<input type="hidden" name="edit">
<input type="hidden" name="domain" value="<?php echo $_domain; ?>">
<input type="hidden" name="token" value="<?php echo $_token; ?>">
<input type="submit" name="action" value="delete">
</form>
<form>
<input type="hidden" name="edit">
<input type="hidden" name="domain" value="<?php echo $_domain; ?>">
<input type="hidden" name="token" value="<?php echo $_token; ?>">
<input type="submit" name="action" value="pause">
</form>
<form>
<input type="hidden" name="edit">
<input type="hidden" name="domain" value="<?php echo $_domain; ?>">
<input type="hidden" name="token" value="<?php echo $_token; ?>">
WARNING: This can not be undone, you will need to add your pod again if you want back on list: <input type="submit" name="action" value="delete">
<input type="submit" name="action" value="unpause">
</form>
<?php
......@@ -16,6 +16,7 @@ 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');
R::usePartialBeans(true);
try {
$pod = R::findOne('pods', 'domain = ?', [$_domain]);
......@@ -26,7 +27,7 @@ try {
// Set up common variables.
$uuid = md5(uniqid($_domain, true));
$link = sprintf('https://%1$s/db/edit.php?domain=%2$s&token=%3$s', $_SERVER['HTTP_HOST'], $_domain, $uuid);
$link = sprintf('https://%1$s/?edit&domain=%2$s&token=%3$s', $_SERVER['HTTP_HOST'], $_domain, $uuid);
$headers = ['From: ' . $adminemail];
$message_lines = [];
......@@ -53,11 +54,6 @@ try {
$pod['token'] = $uuid;
$pod['tokenexpire'] = date('Y-m-d H:i:s', $expire);
// @todo Temporary fix! https://github.com/gabordemooij/redbean/issues/547
foreach ($pod->getProperties() as $key => $value) {
$pod[$key] = $value;
}
R::store($pod);
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
......
<?php
use RedBeanPHP\R;
// Required parameters.
($_domain = $_POST['domain'] ?? null) || die('no pod domain given');
($_adminkey = $_POST['adminkey'] ?? null) || die('no admin key given');
($_action = $_POST['action'] ?? null) || die('no action selected');
// Other parameters.
$_comments = $_POST['comments'] ?? '';
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../config.php';
$adminkey === $_adminkey || die('admin key mismatch');
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 id, email FROM pods WHERE domain = ?', [$_domain]);
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
}
if ($pod) {
$email = $pod['email'];
if ($_action === 'delete') {
R::trash('pods', $pod['id']);
if ($email) {
$to = $email;
$headers = ['From: ' . $adminemail, 'Cc: ' . $adminemail];
$subject = 'Pod deleted from ' . $_SERVER['HTTP_HOST'];
$message = 'Pod ' . $_domain . ' was deleted from ' . $_SERVER['HTTP_HOST'] . ' as it was dead on the list. ' . $_comments . ' Feel free to add back at any time.';
@mail($to, $subject, $message, implode("\r\n", $headers));
}
} elseif ($_action === 'warn') {
if ($email) {
$to = $email;
$headers = ['From: ' . $adminemail, 'Cc: ' . $adminemail];
$subject = 'Pod removal warning from ' . $_SERVER['HTTP_HOST'];
$message = 'Pod ' . $_domain . ' is on the list to be deleted now because: ' . $_comments . ".\r\nPlease let me know if you need help fixing before it is removed.";
@mail($to, $subject, $message, implode("\r\n", $headers));
}
}
}
CREATE INDEX idx_clicks ON clicks (domain);
UPDATE pods SET status=0 WHERE status = 'Down';
UPDATE pods SET status=1 WHERE status = 'Up';
/*
0 = Down
1 = Up
2 = Recheck
3 = Paused
4 = System Deleted
5 = User Deleted
*/
ALTER TABLE pods ALTER COLUMN status TYPE smallint USING status::smallint;
CREATE TABLE monthlystats (
id serial8 UNIQUE PRIMARY KEY,
total_users int,
total_posts int,
total_comments int,
total_pods int,
total_uptime int,
date_checked timestamp DEFAULT current_timestamp
);
<?php
use RedBeanPHP\R;
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../config.php';
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');
R::usePartialBeans(true);
try {
$monthly_totals = R::getAll("
SELECT
to_char(date_checked, 'yyyy-mm') AS yymm,
sum(total_users) / count(DISTINCT to_char(date_checked, 'HH24 dd')) as users,
sum(local_posts) / count(DISTINCT to_char(date_checked, 'HH24 dd')) as posts,
sum(comment_counts) / count(DISTINCT to_char(date_checked, 'HH24 dd')) as comments,
count(domain) / count(DISTINCT to_char(date_checked, 'HH24 dd')) as pods,
count(nullif(online, false)) as uptime,
count(nullif(online, true)) as downtime
FROM checks
GROUP BY yymm
");
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
}
foreach ($monthly_totals as $monthly) {
// Format date to timestamp.
$timestamp = $monthly['yymm'].'-01 01:01:01-01';
try {
$p = R::findOrCreate('monthlystats', ['date_checked' => $timestamp]);
$p['total_users'] = $monthly['users'];
$p['total_posts'] = $monthly['posts'];
$p['total_comments'] = $monthly['comments'];
$p['total_pods'] = $monthly['pods'];
if ($monthly['downtime']) {
$p['total_uptime'] = round($monthly['downtime'] / $monthly['uptime'] * 100);
} else {
$p['total_uptime'] = 100;
}
R::store($p);
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
}
}
<?php
if (php_sapi_name() == "cli") {
$json = json_decode(file_get_contents('https://the-federation.info/pods.json'));
if ($json) {
foreach ($json->pods ?? [] as $poddata) {
echo exec("php-cgi add.php domain={$poddata->host}") . "\r\n";
}
}
} else {
header('HTTP/1.0 403 Forbidden');
}
......@@ -11,6 +11,7 @@ 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');
R::usePartialBeans(true);
$softwares = [
'diaspora' => ['url' => 'https://raw.githubusercontent.com/diaspora/diaspora/master/config/defaults.yml', 'regex' => '/number:.*"(.*)"/'],
......
......@@ -19,10 +19,11 @@ 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');
R::usePartialBeans(true);
try {
$sql = '
SELECT domain, score, date_created, adminrating, weight, hidden, podmin_notify, email
SELECT domain, score, date_created, adminrating, weight, hidden, podmin_notify, email, masterversion, shortversion, status
FROM pods
';
......@@ -30,8 +31,12 @@ try {
if ($_domain) {
$sql .= ' WHERE domain = ?';
$pods = R::getAll($sql, [$_domain]);
} elseif (PHP_SAPI === 'cli' && (isset($argv) && in_array('Check_System_Deleted', $argv, true))) {
$sql .= ' WHERE status = ?';
$pods = R::getAll($sql, [PodStatus::System_Deleted]);
} elseif (PHP_SAPI === 'cli') {
$pods = R::getAll($sql);
$sql .= ' WHERE status < ?';
$pods = R::getAll($sql, [PodStatus::Paused]);
}
} catch (\RedBeanPHP\RedException $e) {