Unverified Commit 7d7ca56c authored by dmorley's avatar dmorley

Merge branch 'develop'

parents f7a1715f f909a892
bower_components bower_components
config.php config.php
vendor
...@@ -13,6 +13,7 @@ dnsutils ...@@ -13,6 +13,7 @@ dnsutils
bind9 bind9
npm npm
nodejs nodejs-legacy nodejs nodejs-legacy
composer
``` ```
To Install: To Install:
...@@ -21,6 +22,7 @@ git clone https://github.com/diasporg/Poduptime.git ...@@ -21,6 +22,7 @@ git clone https://github.com/diasporg/Poduptime.git
cd Poduptime cd Poduptime
sudo npm install -g bower sudo npm install -g bower
bower install bower install
composer install
cp config.php.example config.php cp config.php.example config.php
``` ```
...@@ -50,6 +52,7 @@ To Upgrade: ...@@ -50,6 +52,7 @@ To Upgrade:
cd Poduptime cd Poduptime
git pull git pull
bower install bower install
composer install
psql -u podupuser podupdb < db/migrationx.sql (see db/version.md for proper migration version) psql -u podupuser podupdb < db/migrationx.sql (see db/version.md for proper migration version)
``` ```
......
<?php <?php
//Copyright (c) 2011, David Morley. This file is licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file. //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; ($_GET['key'] ?? null) === '4r45tg' || die;
// Other parameters. // Other parameters.
...@@ -7,10 +10,14 @@ $_format = $_GET['format'] ?? ''; ...@@ -7,10 +10,14 @@ $_format = $_GET['format'] ?? '';
$_method = $_GET['method'] ?? ''; $_method = $_GET['method'] ?? '';
$_callback = $_GET['callback'] ?? ''; $_callback = $_GET['callback'] ?? '';
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/config.php'; require_once __DIR__ . '/config.php';
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass"); define('PODUPTIME', microtime(true));
$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');
if ($_format === 'georss') { if ($_format === 'georss') {
echo <<<EOF echo <<<EOF
...@@ -21,50 +28,58 @@ if ($_format === 'georss') { ...@@ -21,50 +28,58 @@ if ($_format === 'georss') {
<link href="https://{$_SERVER['HTTP_HOST']}/"/> <link href="https://{$_SERVER['HTTP_HOST']}/"/>
EOF; EOF;
$sql = "SELECT name,monthsmonitored,responsetimelast7,uptimelast7,dateupdated,score,domain,country,lat,long FROM pods_apiv1";
$result = pg_query($dbh, $sql); try {
$result || die('Error in SQL query: ' . pg_last_error()); $pods = R::getAll('
SELECT name, monthsmonitored, responsetimelast7, uptimelast7, dateupdated, score, domain, country, lat, long
$numrows = pg_num_rows($result); FROM pods_apiv1
while ($row = pg_fetch_array($result)) { ');
$pod_name = htmlentities($row['name'], ENT_QUOTES); } catch (\RedBeanPHP\RedException $e) {
$summary = sprintf( 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', '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, htmlentities($pod['name'], ENT_QUOTES),
$row['monthsmonitored'], $pod['monthsmonitored'],
$row['responsetimelast7'], $pod['responsetimelast7'],
$row['uptimelast7'], $pod['uptimelast7'],
$row['dateupdated'], $pod['dateupdated'],
$row['score'] $pod['score']
); );
echo <<<EOF echo <<<EOF
<entry> <entry>
<title>https://{$row['domain']}</title> <title>https://{$pod['domain']}</title>
<link href="{$scheme}{$row['domain']}"/> <link href="https://{$pod['domain']}"/>
<id>urn:{$row['domain']}</id> <id>urn:{$pod['domain']}</id>
<summary>Pod Location is: {$row['country']} <summary>Pod Location is: {$pod['country']}
&#xA; &#xA;
{$summary}</summary> {$summary}</summary>
<georss:point>{$row['lat']} {$row['long']}</georss:point> <georss:point>{$pod['lat']} {$pod['long']}</georss:point>
<georss:featureName>{$row['domain']}</georss:featureName> <georss:featureName>{$pod['domain']}</georss:featureName>
</entry> </entry>
EOF; 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_apiv1';
$result = pg_query($dbh, $sql); try {
$result || die('Error in SQL query: ' . pg_last_error()); $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 //json output, thx Vipul A M for fixing this
header('Content-type: application/json'); header('Content-type: application/json');
$numrows = pg_num_rows($result); $obj = [
$rows = array_values(pg_fetch_all($result)); 'podcount' => count($pods),
$obj = [ 'pods' => allToString($pods),
'podcount' => $numrows,
'pods' => $rows,
]; ];
if ($_method === 'jsonp') { if ($_method === 'jsonp') {
print $_callback . '(' . json_encode($obj) . ')'; print $_callback . '(' . json_encode($obj) . ')';
...@@ -72,20 +87,51 @@ EOF; ...@@ -72,20 +87,51 @@ EOF;
print json_encode($obj); print json_encode($obj);
} }
} else { } else {
$i = 0; try {
$sql = "SELECT domain,uptimelast7,country FROM pods_apiv1"; $pods = R::getAll('
$result = pg_query($dbh, $sql); SELECT domain, uptimelast7, country
$result || die('Error in SQL query: ' . pg_last_error()); FROM pods_apiv1
');
$numrows = pg_num_rows($result); } catch (\RedBeanPHP\RedException $e) {
while ($row = pg_fetch_array($result)) { die('Error in SQL query: ' . $e->getMessage());
}
$i = 0;
foreach ($pods as $pod) {
$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'], $pod['domain'],
$row['uptimelast7'], $pod['uptimelast7'],
$row['country'] $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 <?php
require_once __DIR__ . '/config.php';
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass"); use RedBeanPHP\R;
$dbh || die('Error in connection: ' . pg_last_error());
$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"; defined('PODUPTIME') || die();
$result = pg_query($dbh, $sql);
$result || die('Error in SQL query: ' . pg_last_error()); try {
$numrows = pg_num_rows($result); $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"> <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. */ --> <!-- /* 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"> <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> <thead>
<tr> <tr>
<th>Pod<a class="tipsy" title="A pod is a site for you to set up your account.">?</a></th> <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); ...@@ -36,59 +42,60 @@ $numrows = pg_num_rows($result);
<tbody> <tbody>
<?php <?php
$tt = 0; $tt = 0;
while ($row = pg_fetch_array($result)) {
foreach ($pods as $pod) {
$tt++; $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( $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', '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'], $pod['monthsmonitored'],
$row['latency'], $pod['latency'],
$row['uptime_alltime'], $pod['uptime_alltime'],
$row['date_updated'], $pod['date_updated'],
$row['score'] $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'; $version = '.dev';
$pre = 'This pod runs pre release development code'; $pre = 'This pod runs pre release development code';
} elseif (!$row['shortversion']) { } elseif (!$pod['shortversion']) {
$version = '0'; $version = '0';
$pre = 'This pod runs unknown code'; $pre = 'This pod runs unknown code';
} else { } else {
$version = $row['shortversion']; $version = $pod['shortversion'];
$pre = 'This pod runs production code'; $pre = 'This pod runs production code';
} }
if ($row['shortversion'] === $row['masterversion'] && $row['shortversion'] !== '') { if ($pod['shortversion'] === $pod['masterversion'] && $pod['shortversion'] !== '') {
$classver = 'text-success'; $classver = 'text-success';
} elseif ($verdiff > 6) { } elseif ($verdiff > 6) {
$classver = 'text-warning'; $classver = 'text-warning';
} else { } else {
$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: ' . $pod['shortversion'] . ' master version is: ' . $pod['masterversion'] . '" class="tipsy">' . $version . '</div></td>';
echo '<td>' . $row['uptime_alltime'] . '</td>'; echo '<td>' . $pod['uptime_alltime'] . '</td>';
echo '<td>' . $row['latency'] . '</td>'; echo '<td>' . $pod['latency'] . '</td>';
echo '<td>' . ($row['signup'] === 't' ? 'Open' : 'Closed') . '</td>'; echo '<td>' . ($pod['signup'] ? 'Open' : 'Closed') . '</td>';
echo '<td>' . $row['total_users'] . '</td>'; echo '<td>' . $pod['total_users'] . '</td>';
echo '<td>' . $row['active_users_halfyear'] . '</td>'; echo '<td>' . $pod['active_users_halfyear'] . '</td>';
echo '<td>' . $row['active_users_monthly'] . '</td>'; echo '<td>' . $pod['active_users_monthly'] . '</td>';
echo '<td>' . $row['local_posts'] . '</td>'; echo '<td>' . $pod['local_posts'] . '</td>';
echo '<td>' . $row['comment_counts'] . '</td>'; echo '<td>' . $pod['comment_counts'] . '</td>';
$moreurl = 'https://api.uptimerobot.com/getMonitors?format=json&noJsonCallback=1&customUptimeRatio=7-30-60-90&apiKey=' . $row['stats_apikey']; $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 ' . $row['date_updated'] . '" class="tipsy"><a target="_self" href="' . $moreurl . '">' . $row['monthsmonitored'] . '</a></div></td>'; echo '<td><div title="Last Check ' . $pod['date_updated'] . '" class="tipsy"><a target="_self" href="' . $moreurl . '">' . $pod['monthsmonitored'] . '</a></div></td>';
echo '<td>' . $row['score'] . '</td>'; echo '<td>' . $pod['score'] . '</td>';
echo '<td><div class="tipsy" title="' . $row['sslvalid'] . '">con info</td>'; echo '<td><div class="tipsy" title="' . $pod['sslvalid'] . '">con info</td>';
?> ?>
<td> <td>
<form method="post" action="db/kill.php" target="_blank"> <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']; ?>"> <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="warn">warn</label>
<label><input type="radio" name="action" value="delete">delete</label> <label><input type="radio" name="action" value="delete">delete</label>
<input type="submit" value="Process"> <input type="submit" value="Process">
......
This diff is collapsed.
...@@ -6,6 +6,8 @@ $backup_dir = '/backup'; ...@@ -6,6 +6,8 @@ $backup_dir = '/backup';
$log_dir = '/log'; $log_dir = '/log';
//location of pg dump //location of pg dump
$pg_dump_dir = '/usr/bin'; $pg_dump_dir = '/usr/bin';
//db host
$pghost = 'localhost';
//db username //db username
$pguser = ''; $pguser = '';
//db password //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 { .rating {
font-size:9px; font-size:9px;
} }
...@@ -51,3 +94,7 @@ z-index: 1000 !important; ...@@ -51,3 +94,7 @@ z-index: 1000 !important;
#facebox .content { #facebox .content {
width: 800px !important; 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. */ --> <!-- /* Copyright (c) 2011, David Morley. This file is licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file. */ -->
<?php <?php
use RedBeanPHP\R;
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../logging.php'; require_once __DIR__ . '/../logging.php';
require_once __DIR__ . '/../config.php'; require_once __DIR__ . '/../config.php';
define('PODUPTIME', microtime(true));
$log = new Logging(); $log = new Logging();
$log->lfile(__DIR__ . '/../' . $log_dir . '/add.log'); $log->lfile(__DIR__ . '/../' . $log_dir . '/add.log');
if (!($_domain = $_GET['domain'] ?? null)) { if (!($_domain = $_GET['domain'] ?? null)) {
...@@ -9,6 +16,7 @@ if (!($_domain = $_GET['domain'] ?? null)) { ...@@ -9,6 +16,7 @@ if (!($_domain = $_GET['domain'] ?? null)) {
die('no pod domain given'); die('no pod domain given');
} }
// Other parameters.
$_email = $_GET['email'] ?? ''; $_email = $_GET['email'] ?? '';
$_podmin_statement = $_GET['podmin_statement'] ?? ''; $_podmin_statement = $_GET['podmin_statement'] ?? '';
$_podmin_notify = $_GET['podmin_notify'] ?? 0; $_podmin_notify = $_GET['podmin_notify'] ?? 0;
...@@ -18,29 +26,47 @@ if (!filter_var(gethostbyname($_domain), FILTER_VALIDATE_IP)) { ...@@ -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)'); 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"); // Set up global DB connection.
$dbh || die('Error in connection: ' . pg_last_error()); 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'; try {
$result = pg_query($dbh, $sql); $pods = R::getAll('
$result || die('Error in SQL query: ' . pg_last_error()); 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)) { foreach ($pods as $pod) {
if ($row['domain'] === $_domain ) { if ($pod['domain'] === $_domain) {
if ($row['email']) { if ($pod['email']) {
$log->lwrite('domain already exists and is registered to an owner' . $_domain); $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'); die('domain already exists and is registered to an owner, use the edit function to modify');
} }
$digtxt = exec(escapeshellcmd('dig ' . $_domain . ' TXT +short')); $digtxt = exec(escapeshellcmd('dig ' . $_domain . ' TXT +short'));
if (strpos($digtxt, $row['publickey']) !== false) { if (strpos($digtxt, $pod['publickey']) !== false) {
echo 'domain validated, you can now add details '; echo 'domain validated, you can now add details ';
$uuid = md5(uniqid($_domain, true)); $uuid = md5(uniqid($_domain, true));
$expire = time() + 2700; $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]); try {
$result || die('Error in SQL query: ' . pg_last_error()); $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;