113 lines
2.8 KiB
PHP
113 lines
2.8 KiB
PHP
<?php
|
|
|
|
const DOMORE_SIM_URL = 'http://192.168.4.253/data/json?test=WX0';
|
|
|
|
$fetchedAt = new DateTimeImmutable('now', new DateTimeZone('America/Chicago'));
|
|
$rawResponse = null;
|
|
$displayPayload = null;
|
|
$errorMessage = null;
|
|
$httpStatus = null;
|
|
|
|
$curl = curl_init(DOMORE_SIM_URL);
|
|
curl_setopt_array(
|
|
$curl,
|
|
[
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_FOLLOWLOCATION => true,
|
|
CURLOPT_CONNECTTIMEOUT => 3,
|
|
CURLOPT_TIMEOUT => 5,
|
|
]
|
|
);
|
|
|
|
$rawResponse = curl_exec($curl);
|
|
|
|
if ($rawResponse === false) {
|
|
$errorMessage = curl_error($curl) ?: 'Unknown cURL error';
|
|
} else {
|
|
$httpStatus = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
|
|
$decoded = json_decode($rawResponse, true);
|
|
if (json_last_error() === JSON_ERROR_NONE) {
|
|
$displayPayload = json_encode(
|
|
$decoded,
|
|
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
|
|
);
|
|
} else {
|
|
$displayPayload = $rawResponse;
|
|
}
|
|
}
|
|
|
|
curl_close($curl);
|
|
|
|
$escapedUrl = htmlspecialchars(DOMORE_SIM_URL, ENT_QUOTES, 'UTF-8');
|
|
$escapedFetched = htmlspecialchars(
|
|
$fetchedAt->format('Y-m-d H:i:s T'),
|
|
ENT_QUOTES,
|
|
'UTF-8'
|
|
);
|
|
$escapedStatus = $httpStatus !== null ? (int) $httpStatus : null;
|
|
$escapedError = $errorMessage !== null
|
|
? htmlspecialchars($errorMessage, ENT_QUOTES, 'UTF-8')
|
|
: null;
|
|
$escapedPayload = htmlspecialchars(
|
|
$displayPayload ?? 'No payload received.',
|
|
ENT_NOQUOTES,
|
|
'UTF-8'
|
|
);
|
|
|
|
?><!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="refresh" content="1">
|
|
<title>DCS DoMore SIM Feed</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
padding: 1.5rem;
|
|
font-family: Consolas, "Courier New", monospace;
|
|
background-color: #111;
|
|
color: #f0f0f0;
|
|
}
|
|
pre {
|
|
margin: 0;
|
|
white-space: pre-wrap;
|
|
word-break: break-word;
|
|
}
|
|
.status {
|
|
margin-bottom: 1rem;
|
|
font-size: 0.9rem;
|
|
color: #aaa;
|
|
}
|
|
.status strong {
|
|
color: #fff;
|
|
}
|
|
.error {
|
|
color: #ff6b6b;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="status">
|
|
<strong>Source:</strong>
|
|
<?php echo $escapedUrl; ?><br>
|
|
<strong>Fetched:</strong>
|
|
<?php echo $escapedFetched; ?><br>
|
|
<?php if ($escapedStatus !== null) : ?>
|
|
<strong>HTTP Status:</strong> <?php echo $escapedStatus; ?><br>
|
|
<?php endif; ?>
|
|
<strong>Auto-refresh:</strong> 1 seconds
|
|
</div>
|
|
|
|
<?php if ($errorMessage !== null) : ?>
|
|
<p class="error">
|
|
Failed to retrieve feed:
|
|
<?php echo $escapedError; ?>
|
|
</p>
|
|
<?php else : ?>
|
|
<pre>
|
|
<?php echo $escapedPayload; ?>
|
|
</pre>
|
|
<?php endif; ?>
|
|
</body>
|
|
</html>
|