singleview.php 3.73 KB
Newer Older
dmorley's avatar
dmorley committed
1 2 3 4 5 6 7 8 9
<?php

/**
 * This is just a single pod data pull for /domain.tld page
 */

declare(strict_types=1);

use RedBeanPHP\R;
dmorley's avatar
dmorley committed
10
use Carbon\Carbon;
dmorley's avatar
dmorley committed
11 12 13 14 15 16 17 18 19 20

// Required parameters.
($_domain = $input ?? null) || die('no domain given');

require_once __DIR__ . '/boot.php';

$iso = new Matriphe\ISO639\ISO639;

try {
    $pod = R::getRow('
dmorley's avatar
dmorley committed
21
        SELECT domain, podmin_statement, shortversion, softwarename, monthsmonitored, daysmonitored, score, name, countryname, city, state, detectedlanguage, uptime_alltime, active_users_halfyear, services, service_xmpp, latency, total_users, local_posts, comment_counts, userrating, status, lat, long
dmorley's avatar
dmorley committed
22 23 24 25 26 27 28
        FROM pods
        WHERE domain = ?
    ', [$_domain]);
} catch (\RedBeanPHP\RedException $e) {
    die('Error in SQL query: ' . $e->getMessage());
}

dmorley's avatar
dmorley committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
try {
    $domain_clicks = R::getAll("
        SELECT
            to_char(date_clicked, 'yyyy-mm') AS yymm,
            SUM(manualclick) AS manualclick, 
            SUM(autoclick) AS autoclick
        FROM clicks
        WHERE domain = ?
        GROUP BY yymm
    ", [$_domain]);
} catch (\RedBeanPHP\RedException $e) {
    die('Error in SQL query: ' . $e->getMessage());
}
$humanmonitored = Carbon::now()->subDays($pod['daysmonitored'])->diffForHumans(null, true);

echo '<h4>' . c('title') . ' report for <a href="/go.php?domain=' . $pod['domain'] . '">' . idn_to_utf8($pod['domain']) . '</a></h4><br>';
echo 'This  ' . $pod['softwarename'] . ' pod/node runs software version ' . $pod['shortversion'] . ' <br>';
echo 'This pod/node has been monitored for ' . $humanmonitored . '<br>';
dmorley's avatar
dmorley committed
47
echo 'Score for this pod is  ' . $pod['score'] . ' out of 100<br>';
dmorley's avatar
dmorley committed
48 49
echo 'Detected language of this pod is ' . ($pod['detectedlanguage'] ? $iso->languageByCode1($pod['detectedlanguage']) : '') . '<br>';
echo '<br>';
dmorley's avatar
dmorley committed
50

dmorley's avatar
dmorley committed
51 52 53 54
$services = json_decode($pod['services'], true);
($pod['service_xmpp'] ?? false) && $services[] = 'xmpp';

if (!empty($services)) {
dmorley's avatar
dmorley committed
55 56 57 58 59 60 61 62
    echo 'Services this pod/node offers are: ';
    echo implode(', ', $services);
    echo '<br><br>';
}

echo 'Servers IP address shows: ' . $pod['countryname'];
echo ' ' . $pod['state'];
echo ' ' . $pod['city'] . '<br>';
dmorley's avatar
dmorley committed
63 64
echo '<br>';
if ($pod['podmin_statement']) {
dmorley's avatar
dmorley committed
65
    echo 'The host of the pod would like you to know<br><b><i> ' . $pod['podmin_statement'] . ' </i></b><br><br>';
dmorley's avatar
dmorley committed
66
}
dmorley's avatar
dmorley committed
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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
$_GET['domain'] = $pod['domain'];
echo "<h4>Uptime & Latency</h4><br>";
include 'podstat-uptime.php';
echo "<h4>User Stats</h4><br>";
include 'podstat-counts.php';
?>
<h4>Clicks Out</h4><br>
<div class="chart-container p-1 table-responsive" style="height:400px; width:700px">
    <canvas id="clicks"></canvas>
</div>
<script>

    new Chart(document.getElementById('clicks'), {
        type: "bar",
        data: {
            labels: <?php echo json_encode(array_column($domain_clicks, 'yymm')); ?>,
            datasets: [{
                data: <?php echo json_encode(array_column($domain_clicks, 'manualclick')); ?>,
                label: 'Manual',
                fill: false,
                yAxisID: "l2",
                borderColor: "#A07614",
                backgroundColor: "#A07614",
                borderWidth: 4,
                pointHoverRadius: 6
            }, {
                data: <?php echo json_encode(array_column($domain_clicks, 'autoclick')); ?>,
                label: 'Auto',
                fill: false,
                yAxisID: "l2",
                borderColor: "#4b6588",
                backgroundColor: "#4b6588",
                borderWidth: 4,
                pointHoverRadius: 6
            }]
        },
        options: {
            responsive: true,
            maintainAspectRatio: true,
            scales: {
                yAxes: [{
                    position: "left",
                    "id": "l2"
                }]
            }
        }
    });
    </script>