tabledata.php 6.14 KB
Newer Older
dmorley's avatar
dmorley committed
1 2 3 4 5 6 7 8 9 10 11 12
<?php

/**
 * get data for showfull.php calls.
 */

declare(strict_types=1);

use Carbon\Carbon;
use Poduptime\PodStatus;
use RedBeanPHP\R;

13
require_once __DIR__ . '/boot.php';
dmorley's avatar
dmorley committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96

try {
    $pods = R::getAll('
        SELECT domain, dnssec, podmin_statement, sslexpire, masterversion, shortversion, softwarename, daysmonitored, monthsmonitored, score, signup, name, country, countryname, city, state, detectedlanguage, 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, userrating, status
        FROM pods
        WHERE status < ?
        ORDER BY weightedscore DESC
    ', [PodStatus::SYSTEM_DELETED]);
} catch (\RedBeanPHP\RedException $e) {
    die('Error in SQL query: ' . $e->getMessage());
}

// CloudFlare country code pull.
$country_code = $_SERVER['HTTP_CF_IPCOUNTRY'] ?? '';

foreach ($pods as $pod) {
    $humanmonitored = Carbon::now()->subDays($pod['daysmonitored'])->diffForHumans(null, true);
    $tip            = "Over the last {$humanmonitored} uptime was {$pod['uptime_alltime']}% and response time from Los Angeles was {$pod['latency']}ms.";

    if (($_COOKIE['domain'] ?? null) === $pod['domain']) {
        echo '<tr><td title="This is the last pod you visited from this site. ' . $tip . '" data-placement="right" data-toggle="tooltip" class="bg-secondary"><a class="text-warning url" target="_self" href="/go.php?domain=' . $pod['domain'] . '">' . $pod['domain'] . '</a></td>';
    } else {
        echo '<tr><td data-placement="right" title="' . $tip . '" data-toggle="tooltip"><a class="text-success url" target="_self" href="/go.php?domain=' . $pod['domain'] . '">' . $pod['domain'] . '</a></td>';
    }

    if ($pod['shortversion'] > $pod['masterversion']) {
        $version = $pod['shortversion'];
        $pre     = 'This pod runs pre release development code';
    } elseif (!$pod['shortversion']) {
        $version = '';
        $pre     = 'This pod runs unknown code';
    } else {
        $version = $pod['shortversion'];
        $pre     = 'This pod runs production code';
    }

    $classver = 'black';
    if (version_compare($pod['shortversion'] ?? '', $pod['masterversion'] ?? '', '=')) {
        $classver = 'text-success';
    } elseif (version_compare($pod['shortversion'] ?? '', $pod['masterversion'] ?? '', '<')) {
        $classver = 'text-warning';
    }
    echo '<td>' . $pod['name'] . '</td>';
    echo '<td class="' . $classver . '"><div title="' . $pre . ' version: ' . $pod['shortversion'] . ' master version is: ' . ($pod['masterversion'] ?: 'unknown') . '" data-toggle="tooltip">' . $version . '</div></td>';
    echo '<td>' . $pod['softwarename'] . '</td>';
    echo '<td><a href="#" data-featherlight-variant="table-responsive" data-featherlight="podstat-uptime.php?domain=' . $pod['domain'] . '">' . ($pod['uptime_alltime'] > 0 ? $pod['uptime_alltime'] . '%' : '') . '</a></td>';
    echo '<td>' . ($pod['ipv6'] ? 'Y' : 'N') . '</td>';
    echo '<td>' . ($pod['latency'] > 0 ? $pod['latency'] : '') . '</td>';
    echo '<td>' . ($pod['signup'] ? 'Y' : 'N') . '</td>';
    echo '<td><a href="#" data-featherlight-variant="table-responsive" data-featherlight="podstat-counts.php?domain=' . $pod['domain'] . '">' . ($pod['total_users'] > 0 ? $pod['total_users'] : '') . '</a></td>';
    echo '<td>' . ($pod['active_users_halfyear'] > 0 ? $pod['active_users_halfyear'] : '') . '</td>';
    echo '<td>' . ($pod['active_users_monthly'] > 0 ? $pod['active_users_monthly'] : '') . '</td>';
    echo '<td>' . ($pod['local_posts'] > 0 ? $pod['local_posts'] : '') . '</td>';
    echo '<td>' . ($pod['comment_counts'] > 0 ? $pod['comment_counts'] : '') . '</td>';
    echo '<td><div title="This pod has been monitored ' . $humanmonitored . '" data-toggle="tooltip">' . $pod['monthsmonitored'] . '</div></td>';
    echo '<td><a href="#" data-featherlight-variant="table-responsive" data-featherlight="rate.php?domain=' . $pod['domain'] . '">' . $pod['userrating'] . '</a></td>';
    echo '<td><div>' . $pod['score'] . '</div></td>';
    echo '<td><div>' . PodStatus::getKey((int) $pod['status']) . '</div></td>';
    echo '<td>' . ($pod['dnssec'] ? 'Y' : 'N') . '</td>';
    if ($country_code === $pod['country']) {
        echo '<td class="text-success" data-toggle="tooltip" title="Country: ' . ($pod['countryname'] ?? 'n/a') . ' City: ' . ($pod['city'] ?? 'n/a') . ' State: ' . ($pod['state'] ?? 'n/a') . '"><b>' . $pod['country'] . '</b></td>';
    } else {
        echo '<td data-toggle="tooltip" title="Country: ' . ($pod['countryname'] ?? 'n/a') . ' City: ' . ($pod['city'] ?? 'n/a') . ' State: ' . ($pod['state'] ?? 'n/a') . '">' . $pod['country'] . '</td>';
    }
    echo '<td>' . $pod['city'] . '</td>';
    echo '<td>' . $pod['state'] . '</td>';
    echo '<td>' . ($pod['detectedlanguage'] ?: '') . '</td>';
    echo '<td class="text-truncate">';
    $pod['service_facebook'] && print '<div class="smlogo smlogo-facebook" data-toggle="tooltip" title="Publish to Facebook"></div>';
    $pod['service_twitter'] && print '<div class="smlogo smlogo-twitter" data-toggle="tooltip" title="Publish to Twitter"></div>';
    $pod['service_tumblr'] && print '<div class="smlogo smlogo-tumblr" data-toggle="tooltip" title="Publish to Tumblr"></div>';
    $pod['service_wordpress'] && print '<div class="smlogo smlogo-wordpress" data-toggle="tooltip" title="Publish to WordPress"></div>';
    $pod['service_xmpp'] && print '<div class="smlogo smlogo-xmpp"><img src="/images/icon-xmpp.png" width="16" height="16" data-toggle="tooltip" title="XMPP chat server" alt="XMPP chat server"></div>';
    echo '</td>';
    echo '<td>' . ($pod['service_facebook'] ? 'Y' : 'N') . '</td>';
    echo '<td>' . ($pod['service_twitter'] ? 'Y' : 'N') . '</td>';
    echo '<td>' . ($pod['service_tumblr'] ? 'Y' : 'N') . '</td>';
    echo '<td>' . ($pod['service_wordpress'] ? 'Y' : 'N') . '</td>';
    echo '<td>' . ($pod['service_xmpp'] ? 'Y' : 'N') . '</td>';

    $podmin_statement = htmlentities($pod['podmin_statement'] ?? '', ENT_QUOTES);
    echo '<td>' . ($podmin_statement ? '<a href="#" data-featherlight="<p>' . $podmin_statement . '</p>">&#128172;</a>' : '&nbsp;') . '</td></tr>';
}