File: //proc/thread-self/cwd/graph-loader.php
<?php
$router_ip = $_SERVER['REMOTE_ADDR'];
$port = '5678';
$graph_url = "http://$router_ip:$port/graphs/iface/Wan1/daily.gif";
// 抓圖
$ch = curl_init($graph_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$content = curl_exec($ch);
$ctype = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// 檢查是否為圖片、是否可能是跳轉 HTML
$is_image = ($code === 200 && strpos($ctype, 'image/') === 0);
$looks_like_html = stripos($content, '<html') !== false || stripos($content, '<script') !== false;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body { margin: 0; padding: 10px; text-align: center; font-family: Arial; }
img { max-width: 100%; border: 1px solid #ccc; }
.error { color: red; font-weight: bold; padding: 20px; }
</style>
</head>
<body>
<h4>流量圖表</h4>
<?php if ($is_image && !$looks_like_html): ?>
<img src="data:<?= htmlspecialchars($ctype) ?>;base64,<?= base64_encode($content) ?>" alt="RouterOS 圖表">
<?php else: ?>
<div class="error">⚠ 圖片載入失敗或回傳內容含跳轉</div>
<?php endif; ?>
</body>
</html>