Commit 0095c9f0 authored by David Morley's avatar David Morley Committed by GitHub

Ownstats (#88)

* rebase

* features and work

* Make software version pull easier to understand and extend. (#91)

* Combine related conditions. (#90)

* Add helper function for chart display. (#89)

Simplify chart data generation.

* PR updates

* WIP - Nicer domain checks (#92)

* Explicitly check passed domain name.

* Make domain lowercase.

* Use native PHP instead of system exec calls to get IPs.

* remove key
parent 53d8c2fb
......@@ -24,6 +24,7 @@
"tablesorter": "jquery.tablesorter#^2.28.3",
"leaflet": "^1.0.2",
"leaflet.markercluster": "^1.0.0",
"facebox": "*"
"facebox": "*",
"chart.js": "^2.4.0"
}
}
......@@ -16,5 +16,5 @@ $pgdb = '';
$adminemail = '';
//admin key for deleting pods, set this as a cookie on your own
$adminkey = '';
//apikey for public api calls
$apikey = '';
//DNS server for dnssec testing
$dnsserver = '';
......@@ -4,42 +4,55 @@ require_once __DIR__ . '/../logging.php';
require_once __DIR__ . '/../config.php';
$log = new Logging();
$log->lfile(__DIR__ . '/../' . $log_dir . '/add.log');
if (!($_domain = $_POST['domain'] ?? null)) {
if (!($_domain = $_GET['domain'] ?? null)) {
$log->lwrite('no domain given');
die('no pod domain given');
}
if (!($_stats_apikey = $_POST['stats_apikey'] ?? null)) {
$log->lwrite('no api given ' . $_domain);
die('no API key for your stats');
}
if (strlen($_stats_apikey) < 14) {
$log->lwrite('api key too short ' . $_domain);
die('API key bad needs to be like m58978-80abdb799f6ccf15e3e3787ee');
}
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');
$_domain = strtolower($_domain);
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());
$sql = 'SELECT domain, stats_apikey FROM pods';
$sql = 'SELECT domain, stats_apikey, publickey, email FROM pods';
$result = pg_query($dbh, $sql);
$result || die('Error in SQL query: ' . pg_last_error());
while ($row = pg_fetch_array($result)) {
if ($row['domain'] === $_domain) {
$log->lwrite('domain already exists ' . $_domain);
die('domain already exists');
}
if ($row['stats_apikey'] === $_stats_apikey) {
$log->lwrite('API key already exists ' . $_domain);
die('API key already exists');
if ($row['domain'] === $_domain ) {
if ($row['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());
echo <<<EOF
<form action="edit.php" method="get">
<input type="hidden" name="domain" value="{$_domain}">
<input type="hidden" name="token" value="{$uuid}">
<label>Email <input type="text" size="20" name="email"></label><br>
<label>Terms Link <input type="text" size="20" name="terms"></label><br>
<label>Weight <input type="text" size="2" name="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>
<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>');
}
}
}
......@@ -57,8 +70,9 @@ if (stristr($outputssl, 'openRegistrations')) {
$log->lwrite('Your pod has ssl and is valid ' . $_domain);
echo 'Your pod has ssl and is valid<br>';
$sql = 'INSERT INTO pods (domain, stats_apikey, email, terms) VALUES ($1, $2, $3, $4)';
$result = pg_query_params($dbh, $sql, [$_domain, $_stats_apikey, $_email, $_terms]);
$publickey = md5(uniqid($domain, true));
$sql = 'INSERT INTO pods (domain, email, terms, publickey) VALUES ($1, $2, $3, $4, $5)';
$result = pg_query_params($dbh, $sql, [$_domain, $_email, $_terms, $publickey]);
$result || die('Error in SQL query: ' . pg_last_error());
$to = $adminemail;
......
......@@ -16,7 +16,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 domain,email,token,tokenexpire,stats_apikey,weight,terms FROM pods WHERE domain = $1';
$sql = 'SELECT domain,email,token,tokenexpire,weight,terms FROM pods WHERE domain = $1';
$result = pg_query_params($dbh, $sql, [$_domain]);
$result || die('Error in SQL query: ' . pg_last_error());
......@@ -37,8 +37,8 @@ while ($row = pg_fetch_array($result)) {
if ('save' === $_action) {
$_weight <= 10 || die('10 is max weight');
$sql = 'UPDATE pods SET email = $1, stats_apikey = $2, weight = $3, terms = $4 WHERE domain = $5';
$result = pg_query_params($dbh, $sql, [$_email, $_stats_apikey, $_weight, $_terms, $_domain]);
$sql = 'UPDATE pods SET email = $1, weight = $2, terms = $3 WHERE domain = $4';
$result = pg_query_params($dbh, $sql, [$_email, $_weight, $_terms, $_domain]);
$result || die('Error in SQL query: ' . pg_last_error());
$to = $_email;
......@@ -56,7 +56,6 @@ while ($row = pg_fetch_array($result)) {
<form action="edit.php" method="get">
<input type="hidden" name="domain" value="<?php echo $_domain; ?>">
<input type="hidden" name="token" value="<?php echo $_token; ?>">
<label>Stats Key <input type="text" size="50" name="stats_apikey" value="<?php echo $row['stats_apikey']; ?>">Uptimerobot API key for this monitor</label><br>
<label>Email <input type="text" size="20" name="email" value="<?php echo $row['email']; ?>"></label><br>
<label>Terms Link <input type="text" size="20" name="terms" value="<?php echo $row['terms']; ?>"></label><br>
<label>Weight <input type="text" size="2" name="weight" value="<?php echo $row['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>
......
......@@ -33,7 +33,9 @@ while ($row = pg_fetch_array($result)) {
$headers[] = 'Bcc: ' . $adminemail;
$expire = time() + 2700;
$output = 'Link sent to your email';
} else {
} elseif (!$row['email']) {
echo "domain is registered but no email associated, to add an email use the add a pod feature";die;
} else {
$to = $adminemail;
$subject = 'FORWARD REQUEST: Temporary edit key for ' . $_SERVER['HTTP_HOST'];
$message_lines[] = 'User trying to edit pod without email address.';
......@@ -43,7 +45,7 @@ while ($row = pg_fetch_array($result)) {
}
$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 = pg_query_params($dbh, $sql, [$uuid, date('Y-m-d H:i:s', $expire), $_domain]);
$result || die('Error in SQL query: ' . pg_last_error());
$message_lines[] = 'Link: ' . $link;
......
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 ADD terms text, ADD sslexpire timestamp, ADD dnssec boolean, ADD masterversion text, ADD shortversion text, ADD publickey 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 stats_apikey;
......@@ -41,5 +41,15 @@ CREATE TABLE checks (
online boolean,
error text,
ttl numeric(8,6),
total_users int,
local_posts int,
comment_counts int,
shortversion text,
date_checked timestamp DEFAULT current_timestamp
);
CREATE TABLE masterversions (
software text,
version text,
date_checked timestamp DEFAULT current_timestamp
);
<?php
//* Copyright (c) 2017, David Morley. This file is licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file. */
require __DIR__ . '/../config.php';
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
$dbh || die('Error in connection: ' . pg_last_error());
$softwares = [
'diaspora' => ['url' => 'https://raw.githubusercontent.com/diaspora/diaspora/master/config/defaults.yml', 'regex' => '/number:.*"(.*)"/'],
'friendica' => ['url' => 'https://raw.githubusercontent.com/friendica/friendica/master/boot.php', 'regex' => '/define.*\'FRIENDICA_VERSION\'.*\'(.*)\'/'],
'hubzilla' => ['url' => 'https://raw.githubusercontent.com/redmatrix/hubzilla/master/boot.php', 'regex' => '/define.*\'STD_VERSION\'.*\'(.*)\'/'],
];
foreach ($softwares as $software => $details) {
$mv = curl_init();
curl_setopt($mv, CURLOPT_URL, $details['url']);
curl_setopt($mv, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($mv, CURLOPT_RETURNTRANSFER, 1);
$outputmv = curl_exec($mv);
curl_close($mv);
if ($masterversion = preg_match($details['regex'], $outputmv, $version) ? $version[1] : '') {
$sql = 'INSERT INTO masterversions (software,version) VALUES ($1,$2)';
$result = pg_query_params($dbh, $sql, [$software, $masterversion]);
$result || die('Error in SQL query: ' . pg_last_error());
}
printf('%s:%s ', $software, $masterversion ?: 'n/a');
}
......@@ -9,36 +9,6 @@ $_domain = $_GET['domain'] ?? '';
require_once __DIR__ . '/../config.php';
//get master code version for diaspora pods
$mv = curl_init();
curl_setopt($mv, CURLOPT_URL, 'https://raw.githubusercontent.com/diaspora/diaspora/master/config/defaults.yml');
curl_setopt($mv, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($mv, CURLOPT_RETURNTRANSFER, 1);
$outputmv = curl_exec($mv);
curl_close($mv);
$dmasterversion = preg_match('/number:.*"(.*)"/', $outputmv, $version) ? $version[1] : '';
_debug('Diaspora Masterversion', $dmasterversion);
//get master code version for friendica pods
$mv = curl_init();
curl_setopt($mv, CURLOPT_URL, 'https://raw.githubusercontent.com/friendica/friendica/master/boot.php');
curl_setopt($mv, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($mv, CURLOPT_RETURNTRANSFER, 1);
$outputmv = curl_exec($mv);
curl_close($mv);
$fmasterversion = preg_match('/define.*\'FRIENDICA_VERSION\'.*\'(.*)\'/', $outputmv, $version) ? $version[1] : '';
_debug('Friendica Masterversion', $fmasterversion);
//get master code version for hubzilla pods
$mv = curl_init();
curl_setopt($mv, CURLOPT_URL, 'https://raw.githubusercontent.com/redmatrix/hubzilla/master/boot.php');
curl_setopt($mv, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($mv, CURLOPT_RETURNTRANSFER, 1);
$outputmv = curl_exec($mv);
curl_close($mv);
$hmasterversion = preg_match('/define.*\'STD_VERSION\'.*\'(.*)\'/', $outputmv, $version) ? $version[1] : '' ;
_debug('Hubzilla Masterversion', $hmasterversion);
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
$dbh || die('Error in connection: ' . pg_last_error());
......@@ -112,10 +82,6 @@ while ($row = pg_fetch_assoc($result)) {
}
if ($jsonssl !== null) {
$sql_checks = 'INSERT INTO checks (domain, online, ttl) VALUES ($1, $2, $3)';
$result_checks = pg_query_params($dbh, $sql_checks, [$domain, 1, $ttl]);
$result_checks || die('Error in SQL query: ' . pg_last_error());
(!$jsonssl->software->version) || $score += 1;
$xdver = $jsonssl->software->version ?? 0;
$dverr = explode('-', trim($xdver));
......@@ -134,6 +100,12 @@ while ($row = pg_fetch_assoc($result)) {
$service_tumblr = in_array('tumblr', $jsonssl->services->outbound, true);
$service_wordpress = in_array('wordpress', $jsonssl->services->outbound, true);
$service_xmpp = $jsonssl->metadata->xmppChat === true ?? false;
$status = 'Up';
$sql_checks = 'INSERT INTO checks (domain, online, ttl, total_users, local_posts, comment_counts, shortversion) VALUES ($1, $2, $3, $4, $5, $6, $7)';
$result_checks = pg_query_params($dbh, $sql_checks, [$domain, 1, $ttl, $total_users, $local_posts, $comment_counts, $shortversion]);
$result_checks || die('Error in SQL query: ' . pg_last_error());
} else {
$score -= 1;
$dver = '.connect error';
......@@ -141,20 +113,20 @@ while ($row = pg_fetch_assoc($result)) {
}
_debug('Signup Open', $signup);
$ip6 = exec(escapeshellcmd('dig @74.82.42.42 +nocmd ' . $domain . ' aaaa +noall +short'));
$ip = dns_get_record($_domain, DNS_A)[0]['ip'] ?? null;
$ipv6 = dns_get_record($_domain, DNS_AAAA)[0]['ipv6'] ?? null;
$iplookup = [];
exec(escapeshellcmd('delv @74.82.42.42 ' . $domain), $iplookup);
exec(escapeshellcmd('delv @' . $dnsserver . ' ' . $domain), $iplookup);
if ($iplookup) {
_debug('Iplookup', $iplookup, true);
$dnssec = in_array('; fully validated', $iplookup, true) ?? false ;
$getaonly = array_values(preg_grep('/\s+IN\s+A\s+.*/', $iplookup));
preg_match('/A\s(.*)/', $getaonly[0], $version);
$ip = trim($version[1]);
$dnssec = in_array('; fully validated', $iplookup, true) ?? false;
}
$ip || $score -= 2;
$ipv6 = strpos($ip6, ':') !== false;
_debug('IP', $ip);
_debug('IPv6', $ip6);
_debug('IPv4', $ip);
_debug('IPv6', $ipv6);
$location = geoip_record_by_name($ip);
_debug('Location', $location, true);
......@@ -166,46 +138,30 @@ while ($row = pg_fetch_assoc($result)) {
echo $newline;
$statslastdate = date('Y-m-d H:i:s');
$ping = curl_init();
curl_setopt($ping, CURLOPT_URL, 'https://api.uptimerobot.com/getMonitors?format=json&noJsonCallback=1&customUptimeRatio=7-30-60-90&responseTimes=1&responseTimesAverage=86400&apiKey=' . $row['stats_apikey']);
curl_setopt($ping, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ping, CURLOPT_CONNECTTIMEOUT, 8);
$uptr = json_decode(curl_exec($ping));
curl_close($ping);
_debug('Uptime Robot', $uptr, true);
if ($uptr->stat === 'ok') {
$responsetime = $uptr->monitors->monitor{'0'}->responsetime{'0'}->value ?? 'n/a';
$uptimerobotstat = $uptr->stat;
$uptime = $uptr->monitors->monitor{'0'}->alltimeuptimeratio;
$uptime_custom = $uptr->monitors->monitor{'0'}->customuptimeratio;
$diff = (new DateTime())->diff(new DateTime($dateadded));
$months = $diff->m + ($diff->y * 12);
if ($uptr->monitors->monitor{'0'}->status == 2) {
$status = 'Up';
}
if ($uptr->monitors->monitor{'0'}->status == 0) {
$status = 'Paused';
}
if ($uptr->monitors->monitor{'0'}->status == 1) {
$status = 'Not Checked Yet';
}
if ($uptr->monitors->monitor{'0'}->status == 8) {
$status = 'Seems Down';
}
if ($uptr->monitors->monitor{'0'}->status == 9) {
$status = 'Down';
}
$statslastdate = date('Y-m-d H:i:s');
}
if ($softwarename === 'diaspora') {
$masterversion = $dmasterversion;
} elseif ($softwarename === 'friendica') {
$masterversion = $fmasterversion;
} elseif ($softwarename === 'redmatrix') {
$masterversion = $hmasterversion;
}
$responsetime = 0;
$sqlttl = 'SELECT round(avg(ttl) * 1000) AS ttl FROM checks WHERE domain = $1';
$resultttl = pg_query_params($dbh, $sqlttl, [$domain]);
$resultttl || die('Error in SQL query resultchecks: ' . pg_last_error());
$responsetime = pg_fetch_result($resultttl, 0);
$uptime = 0;
$sqlonline = 'SELECT round(avg(online::int),2) * 100 AS online FROM checks WHERE domain = $1';
$resultonline = pg_query_params($dbh, $sqlonline, [$domain]);
$resultonline || die('Error in SQL query resultchecks: ' . pg_last_error());
$uptime = pg_fetch_result($resultonline, 0);
$sqlmasters = 'SELECT version FROM masterversions WHERE software = $1 ORDER BY date_checked LIMIT 1';
$resultmasters = pg_query_params($dbh, $sqlmasters, [$softwarename]);
$resultmasters || die('Error in SQL query: ' . pg_last_error());
$masterversion = pg_fetch_result($resultmasters, 0);
_debug('Masterversion', $masterversion);
$hidden = $score <= 70;
_debug('Hidden', $hidden ? 'yes' : 'no');
// lets cap the scores or you can go too high or too low to never be effected by them
......@@ -217,9 +173,9 @@ while ($row = pg_fetch_assoc($result)) {
$weightedscore = ($uptime + $score + ($active_users_monthly / 19999) - ((10 - $weight) * .12));
//sql it
$timenow = date('Y-m-d H:i:s');
$sql_set = '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, dnssec = $38, sslexpire = $39 WHERE domain = $1';
$result_set = pg_query_params($dbh, $sql_set, [$domain, 1, (int) $hidden, $ip, (int) $ipv6, $months, $uptime, $status, $statslastdate, $timenow, $responsetime, $score, $admin_rating, $country, $city, $state, $lat, $long, $user_rating, $shortversion, $masterversion, (int) $signup, $total_users, $active_users_halfyear, $active_users_monthly, $local_posts, $name, $comment_counts, (int) $service_facebook, (int) $service_tumblr, (int) $service_twitter, (int) $service_wordpress, $weightedscore, (int) $service_xmpp, $softwarename, $outputsslerror, $uptime_custom, (int) $dnssec, $sslexpire]);
$timenow = date('Y-m-d H:i:s');
$sql_set = '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, dnssec = $37, sslexpire = $38 WHERE domain = $1';
$result_set = pg_query_params($dbh, $sql_set, [$domain, 1, (int) $hidden, $ip, (int) ($ipv6 !== null), $months, $uptime, $status, $statslastdate, $timenow, $responsetime, $score, $admin_rating, $country, $city, $state, $lat, $long, $user_rating, $shortversion, $masterversion, (int) $signup, $total_users, $active_users_halfyear, $active_users_monthly, $local_posts, $name, $comment_counts, (int) $service_facebook, (int) $service_tumblr, (int) $service_twitter, (int) $service_wordpress, $weightedscore, (int) $service_xmpp, $softwarename, $outputsslerror, (int) $dnssec, $sslexpire]);
$result_set || die('Error in SQL query3: ' . pg_last_error());
_debug('Score out of 100', $score);
......
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
SCRIPT_DIR = "$( cd "$( dirname "$0" )" && pwd )"
TIME = `date +%k`
if [ -s /tmp/index.google ];then
echo "already running die"
echo "already running die"
exit;
else
echo "Checking for internet";
echo "Checking for internet";
fi
wget -q --tries=2 --timeout=15 http://www.google.com -O /tmp/index.google
sleep 2
if [ ! -s /tmp/index.google ];then
echo "could not update pods as no internet"
rm /tmp/index.google
echo "could not update pods as no internet"
rm /tmp/index.google
exit;
else
echo "Pulling in new pod data";
cd "$SCRIPT_DIR"
php pull.php
touch last.data
php backup.php
rm /tmp/index.google
cd "$SCRIPT_DIR"
if [ $TIME = 6 ];then
echo "Pulling in master versions";
php pull-masterversions.php
fi
echo "Pulling in new pod data";
php pull.php
touch last.data
php backup.php
rm /tmp/index.google
fi
......@@ -20,7 +20,6 @@ CREATE TABLE pods (
ipv6 boolean,
secure boolean,
sslvalid text,
stats_apikey text,
monthsmonitored int,
signup boolean,
total_users int,
......@@ -28,7 +27,6 @@ CREATE TABLE pods (
active_users_monthly int,
local_posts int,
uptime_alltime numeric(5,2),
uptime_custom text,
status text,
responsetime text,
service_facebook boolean,
......@@ -37,6 +35,7 @@ CREATE TABLE pods (
service_wordpress boolean,
service_xmpp boolean,
token text,
publickey text,
tokenexpire timestamp,
terms text,
sslexpire timestamp,
......@@ -77,6 +76,16 @@ CREATE TABLE checks (
online boolean,
error text,
ttl numeric(8,6),
total_users int,
local_posts int,
comment_counts int,
shortversion text,
date_checked timestamp DEFAULT current_timestamp
);
CREATE TABLE masterversions (
software text,
version text,
date_checked timestamp DEFAULT current_timestamp
);
......@@ -3,9 +3,10 @@ $lastfile = 'db/last.data';
$advancedview = isset($_GET['advancedview']);
$mapview = isset($_GET['mapview']);
$cleanup = isset($_GET['cleanup']);
$statsview = isset($_GET['statsview']);
$podmin = isset($_GET['podmin']);
$podminedit = isset($_GET['podminedit']);
$simpleview = !($advancedview || $mapview || $cleanup || $podmin || $podminedit);
$simpleview = !($advancedview || $mapview || $cleanup || $podmin || $podminedit || $statsview);
?>
<!doctype html>
<html>
......@@ -35,6 +36,7 @@ $simpleview = !($advancedview || $mapview || $cleanup || $podmin || $podminedi
<a class="nav-item nav-link<?php $simpleview && print ' active'; ?>" href="/">Simple View</a>
<a class="nav-item nav-link<?php $advancedview && print ' active'; ?>" href="/?advancedview">Advanced View</a>
<a class="nav-item nav-link<?php $mapview && print ' active'; ?>" href="/?mapview">Map View</a>
<a class="nav-item nav-link<?php $statsview && print ' active'; ?>" href="/?statsview">Network Stats</a>
</nav>
</div>
</nav>
......@@ -45,6 +47,7 @@ $simpleview = !($advancedview || $mapview || $cleanup || $podmin || $podminedi
<li<?php $simpleview && print ' class="active"'; ?>><a href="/">Simple View<?php $simpleview && print ' <span class="sr-only bg-dark">(current)</span>'; ?></a></li>
<li<?php $advancedview && print ' class="active"'; ?>><a href="/?advancedview">Advanced View<?php $advancedview && print ' <span class="sr-only bg-dark">(current)</span>'; ?></a></li>
<li<?php $mapview && print ' class="active"'; ?>><a href="/?mapview">Map View<?php $mapview && print ' <span class="sr-only bg-dark">(current)</span>'; ?></a></li>
<li<?php $statsview && print ' class="active"'; ?>><a href="/?statsview">Network Stats<?php $statsview && print ' <span class="sr-only bg-dark">(current)</span>'; ?></a></li>
</ul>
<ul class="nav nav-sidebar">
<li<?php $podmin && print ' class="active"'; ?>><a href="/?podmin">Add a pod<?php $podmin && print ' <span class="sr-only bg-dark">(current)</span>'; ?></a></li>
......@@ -75,6 +78,8 @@ $simpleview = !($advancedview || $mapview || $cleanup || $podmin || $podminedi
include_once __DIR__ . '/showfull.php';
} elseif ($mapview) {
include_once __DIR__ . '/showmap.php';
} elseif ($statsview) {
include_once __DIR__ . '/statsview.php';
} elseif ($podmin) {
include_once __DIR__ . '/podmin.php';
} elseif ($podminedit) {
......@@ -96,5 +101,7 @@ $simpleview = !($advancedview || $mapview || $cleanup || $podmin || $podminedi
<script src="bower_components/facebox/src/facebox.js"></script>
<script src="bower_components/tablesorter/dist/js/jquery.tablesorter.min.js"></script>
<script src="bower_components/jquery-ui/jquery-ui.min.js"></script>
<script src="bower_components/chart.js/dist/Chart.min.js"></script>
<?php $statsview && include_once __DIR__ . '/statsviewjs.php'; ?>
</body>
</html>
<?php
require_once __DIR__ . '/config.php';
//grab pods from the-federation
$chss = curl_init();
curl_setopt($chss, CURLOPT_URL, 'https://the-federation.info/pods.json');
curl_setopt($chss, CURLOPT_CONNECTTIMEOUT, 19);
curl_setopt($chss, CURLOPT_TIMEOUT, 19);
curl_setopt($chss, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($chss);
curl_close($chss);
$json = json_decode($output);
foreach($json->pods as $mydata) {
$addjson = exec('php-cgi db/add.php domain='.$mydata->host);
echo $addjson;
}
//local json from a diaspora pod json dump /admin_panel/pod/export
$string = file_get_contents("pods.json");
$json_a = json_decode($string, true);
foreach ($json_a as $pod => $host) {
$addlocal = exec('php-cgi db/add.php domain='.$host['pod']['host']);
echo $addlocal;
}
<br>
Want your pod listed?<br>
Its easy start monitoring on your pod with a free <a href="https://uptimerobot.com" target="_blank">Uptime Robot</a> account.<br>
Create a monitor for your pod, then in "My Settings" create a monitor-specific API key and paste below.<br>
Want your pod listed? Or to claim a listed pod?<br>
<br>
<form action="db/add.php" method="post">
<label>Monitor API Key: <input type="text" name="stats_apikey" class="xlarge span8" placeholder="m58978-80abdb799f6ccf15e3e4ttwe"> (don't copy the period on the end)</label><br>
<label>Pod Domain Name: <input type="text" name="domain" class="xlarge span4" placeholder="domain.com"></label><br>
<label>Pod Terms Link: <input type="text" name="terms" class="xlarge span4" value="/terms" placeholder="/terms"></label><br>
<form action="db/add.php" method="get">
<label>Pod Domain Name: <input type="text" name="domain" class="xlarge span4 required" placeholder="domain.com"></label><br>
<label>Pod Terms Link: <input type="text" name="terms" class="xlarge span4" placeholder="/terms"></label><br>
<label>Your Email: <input type="text" name="email" class="xlarge span4" placeholder="user@domain.com"></label><br>
<input type="submit" value="submit">
</form>
......@@ -80,7 +80,7 @@ $numrows = pg_num_rows($result);
echo '<td>' . $row['local_posts'] . '</td>';
echo '<td>' . $row['comment_counts'] . '</td>';
$moreurl = '/showstats.php?domain=' . $row['domain'];
echo '<td><div title="Last Check ' . $row['date_updated'] . '" data-toggle="tooltip" data-placement="bottom"><a rel="facebox" href="' . $moreurl . '">' . $row['monthsmonitored'] . '</a></div></td>';
echo '<td><div title="Last Check ' . $row['date_updated'] . '" data-toggle="tooltip" data-placement="bottom">' . $row['monthsmonitored'] . '</div></td>';
echo '<td><a rel="facebox" href="rate.php?domain=' . $row['domain'] . '">' . $row['userrating'];
echo '</a></td>';
echo '<td>' . $row['score'] . '</td>';
......
<div class="container">
<div class="row">
<div class="col-6 col-md-4">Users by network<br>
<canvas id="total_network_users" width="100" height="100"></canvas>
</div>
<div class="col-6 col-md-4">Pods by network<br>
<canvas id="total_network_pods" width="100" height="100"></canvas>
</div>
<div class="col-6 col-md-4">Uptime by network<br>
<canvas id="total_network_uptime" width="100" height="100"></canvas>
</div>
</div>
</div>
<?php
require_once __DIR__ . '/config.php';
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
$dbh || die('Error in connection: ' . pg_last_error());
$sql_totals = 'SELECT softwarename, count(*) AS pods, sum(total_users) AS users, round(avg(uptime_alltime),2) AS uptime FROM pods GROUP BY softwarename';
$result_totals = pg_query($dbh, $sql_totals);
$result_totals || die('Error in SQL query: ' . pg_last_error());
$totals = pg_fetch_all($result_totals);
?>
<script>
/**
* Add a new chart for the passed data.
*
* @param id HTML element ID to place the chart.
* @param data Data to display on the chart.
*/
function addPieChart(id, data) {
new Chart(document.getElementById(id), {
type: "pie",
data: {
labels: <?php echo json_encode(array_column($totals, 'softwarename')); ?>,
datasets: [{
data: data,
backgroundColor: ["#FF6384", "#36A2EB", "#FFCE56", "#419641", "#A569BD", "#EB984E"],
hoverBackgroundColor: ["#FF6360", "#36A2AD", "#FFCE10", "#419615", "#A569AA", "#EB980A"]
}]
},
options: {
responsive: true,
maintainAspectRatio: true
}
});
}
addPieChart('total_network_users', <?php echo json_encode(array_column($totals, 'users')); ?>);
addPieChart('total_network_pods', <?php echo json_encode(array_column($totals, 'pods')); ?>);
addPieChart('total_network_uptime', <?php echo json_encode(array_column($totals, 'uptime')); ?>);
</script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment