Files
Torn-Vault-Tracker/index.php
T
Keith Solomon a133a5a49d index.php: catch bootstrap exceptions and render a non-fatal warning
Per the spec's error-handling section, all exceptions must be caught at
the top of index.php's bootstrap path so a single bad page (CurlError,
JsonData, ApiValidation, ApiKeyMissing, LogEntryIncomplete) does not take
down the whole UI. The page now renders whatever data is in the DB plus
a warning banner with the exception message (htmlspecialchars-escaped to
avoid XSS). On the first-run backfill path, the redirect is still
emitted inside the try block so the success path is unchanged.
2026-08-03 14:18:48 -05:00

115 lines
3.2 KiB
PHP

<?php
/**
* Main entry point for the Torn Vault Tracker application.
*
* PHP version 8.1+
*
* @category Main
* @package TornVaultTracker
* @author Keith Solomon <ksolmon@gmail.com>
* @license Unlicense https://unlicense.org/
* @link https://github.com/ksolmon/torn-vault-tracker
*/
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/functions.php';
$bootstrapWarning = null;
try {
if (dbNew()) {
foreach (USER_KEYS as $key => $value) {
backfillUserLogs($key);
}
header('Location: /');
exit;
} else {
foreach (USER_KEYS as $key => $value) {
syncUserLogs($key);
}
}
} catch (Exception $e) {
$bootstrapWarning = $e->getMessage();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Torn Vault Tracker</title>
<link rel="icon" type="image/png" href="favicon.png">
<link rel="stylesheet" href="style.css?v=<?php echo filemtime('style.css'); ?>">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital@0;1&display=swap" rel="stylesheet">
</head>
<body>
<h1>Torn Vault Tracker</h1>
<?php if ($bootstrapWarning !== null): ?>
<div class="warning" style="background:#f77e82;color:#000;padding:.5em 1em;margin:1em 0;border:1px solid #333;">Warning: failed to fetch latest logs from Torn — showing cached data. (<?php echo htmlspecialchars($bootstrapWarning, ENT_QUOTES, 'UTF-8'); ?>)</div>
<?php endif; ?>
<div class="grid">
<div class="gridLeft">
<h1>Transactions</h1>
<table id="data">
<thead>
<tr>
<th><h4>User</h4></th>
<th><h4>Date / Time (TCT)</h4></th>
<th><h4>Operation</h4></th>
<th><h4>Amount</h4></th>
</tr>
</thead>
<tbody>
<?php buildTable(); ?>
</tbody>
</table>
<div id="pagination-controls">
<button onclick="changePage(-999)">&laquo;</button>
<button onclick="changePage(-1)">&lsaquo;</button>
<div id="page-info">Page x of y</div>
<button onclick="changePage(1)">&rsaquo;</button>
<button onclick="changePage(999)">&raquo;</button>
</div>
</div>
<div class="gridRight">
<h1>Balances</h1>
<section class="vault">
<h2>Vault Balance: $<?php echo generateBalance(); ?></h2>
<h3>Space left: $<?php echo getSpace(); ?></h3>
</section>
<h2>Shares</h2>
<div class="grid">
<?php foreach (USER_KEYS as $key => $value) { ?>
<section class="user">
<h3><?php echo ucfirst($key); ?> balance: $<?php echo generateBalance($key); ?></h3>
<h4>Share left: $<?php echo getSpace($key); ?></h4>
</section>
<?php } ?>
</div>
</div>
</div>
<script src="script.js"></script>
<script>
let rowsPerPage = <?php echo ROWS_PER_PAGE; ?>; // Set in config.php
paginate();
</script>
</body>
</html>