132 lines
5.0 KiB
PHP
132 lines
5.0 KiB
PHP
<?php
|
|
session_start();
|
|
date_default_timezone_set('Europe/Berlin');
|
|
|
|
// =========================================================================
|
|
// API PROXY & AUTOMATISCHER HISTORY-LOGGER
|
|
// =========================================================================
|
|
if (isset($_GET['api_action'])) {
|
|
header('Content-Type: application/json');
|
|
$api_base = "http://public-pool:3334/api/";
|
|
$action = $_GET['api_action'];
|
|
$endpoint = '';
|
|
|
|
if ($action === 'history') {
|
|
$file = __DIR__ . '/posts/hashrate_history.json';
|
|
echo file_exists($file) ? file_get_contents($file) : '[]';
|
|
exit;
|
|
}
|
|
|
|
if (in_array($action, ['pool', 'network', 'info'])) {
|
|
$endpoint = $action;
|
|
} elseif (preg_match('/^client\/[a-zA-Z0-9]+$/', $action)) {
|
|
$endpoint = $action;
|
|
} else {
|
|
echo '{}';
|
|
exit;
|
|
}
|
|
|
|
$ctx = stream_context_create(['http' => ['timeout' => 3]]);
|
|
$data = @file_get_contents($api_base . $endpoint, false, $ctx);
|
|
|
|
if ($action === 'pool' && $data) {
|
|
$json = json_decode($data, true);
|
|
$hr = $json['totalHashRate'] ?? 0;
|
|
$file = __DIR__ . '/posts/hashrate_history.json';
|
|
$history = file_exists($file) ? json_decode(file_get_contents($file), true) : [];
|
|
|
|
$last_time = end($history)['timestamp'] ?? 0;
|
|
$now = time();
|
|
|
|
if ($now - $last_time >= 300) {
|
|
$history[] = [
|
|
'timestamp' => $now,
|
|
'label' => date('d.m. H:i'),
|
|
'hashrate' => $hr
|
|
];
|
|
if (count($history) > 432) array_shift($history);
|
|
file_put_contents($file, json_encode($history), LOCK_EX);
|
|
}
|
|
}
|
|
|
|
echo $data ?: '{}';
|
|
exit;
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Bitcoin Solo Pool Dashboard</title>
|
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
|
<style>
|
|
body { background: #141210; color: #f3ede7; font-family: sans-serif; padding: 20px; }
|
|
.card { background: #1c1815; border: 1px solid #382e27; padding: 20px; border-radius: 8px; margin-bottom: 20px; }
|
|
input { background: #141210; border: 1px solid #382e27; color: #fff; padding: 10px; border-radius: 4px; }
|
|
button { background: #e05a2b; color: #fff; border: none; padding: 10px 18px; border-radius: 4px; cursor: pointer; }
|
|
table { width: 100%; border-collapse: collapse; margin-top: 15px; }
|
|
th, td { padding: 10px; border-bottom: 1px solid #382e27; text-align: left; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>⛏️ Bitcoin Solo Mining Dashboard</h1>
|
|
|
|
<div class="card">
|
|
<h2>📊 Live Pool Hashrate (36 Stunden Verlauf)</h2>
|
|
<div style="height: 250px;"><canvas id="hashChart"></canvas></div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<h2>🔍 Eigene Worker prüfen</h2>
|
|
<input type="text" id="wallet-in" placeholder="Bitcoin-Wallet (bc1q...) eingeben" style="width: 320px;">
|
|
<button onclick="fetchWorkers()">Suchen</button>
|
|
|
|
<table>
|
|
<thead>
|
|
<tr><th>Worker</th><th>Sessions</th><th>Hashrate</th><th>Best Difficulty</th></tr>
|
|
</thead>
|
|
<tbody id="worker-rows">
|
|
<tr><td colspan="4" style="color: #a89f91;">Bitte Wallet-Adresse suchen.</td></tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<script>
|
|
const ctx = document.getElementById('hashChart').getContext('2d');
|
|
const chart = new Chart(ctx, {
|
|
type: 'line',
|
|
data: { labels: [], datasets: [{ label: 'Hashrate (H/s)', data: [], borderColor: '#e05a2b', fill: true, backgroundColor: 'rgba(224,90,43,0.1)' }] },
|
|
options: { responsive: true, maintainAspectRatio: false }
|
|
});
|
|
|
|
async function loadHistory() {
|
|
const res = await fetch('index.php?api_action=history').then(r => r.json());
|
|
if (Array.isArray(res) && res.length > 0) {
|
|
chart.data.labels = res.map(p => p.label);
|
|
chart.data.datasets[0].data = res.map(p => p.hashrate);
|
|
chart.update();
|
|
}
|
|
}
|
|
|
|
async function fetchWorkers() {
|
|
const wallet = document.getElementById('wallet-in').value.trim();
|
|
if (!wallet) return;
|
|
const res = await fetch('index.php?api_action=client/' + encodeURIComponent(wallet)).then(r => r.json());
|
|
const list = res.workers || [];
|
|
let html = '';
|
|
|
|
if (list.length === 0) {
|
|
html = '<tr><td colspan="4">Keine aktiven Worker gefunden.</td></tr>';
|
|
} else {
|
|
list.forEach(w => {
|
|
html += `<tr><td><b>${w.name}</b></td><td>${(w.sessions||[]).length}</td><td>${(w.hashrate||0).toLocaleString()} H/s</td><td>${w.bestDifficulty||0}</td></tr>`;
|
|
});
|
|
}
|
|
document.getElementById('worker-rows').innerHTML = html;
|
|
}
|
|
|
|
loadHistory();
|
|
setInterval(loadHistory, 300000);
|
|
</script>
|
|
</body>
|
|
</html>
|