. */ namespace Modules\WecomCenter\Actions; use CController; use CControllerResponseData; use CWebUser; use Modules\WecomCenter\Lib\L2Store; class L2TopologyView extends CController { protected function init() { $this->disableCsrfValidation(); } protected function checkInput() { return true; } protected function checkPermissions() { return CWebUser::getType() >= USER_TYPE_ZABBIX_USER; } protected function doAction() { L2Store::ensureSchema(); $cfg = L2Store::getConfig(); $ts_raw = $_REQUEST['ts'] ?? ''; $ts = ($ts_raw === '' || $ts_raw === null) ? null : (int) $ts_raw; $requested_ts = $ts; $snap = L2Store::snapshotAt($ts); $json = $snap['json'] ?? null; $used_ts = $snap['ts']; // A stale bookmark / hand-edited ?ts= must not leave an empty page. // If that exact snapshot is gone, fall back to the live latest view. if ($ts !== null && ($json === null || $json === '')) { $ts = null; $snap = L2Store::snapshotAt(null); $json = $snap['json'] ?? null; $used_ts = $snap['ts']; } // The selector must cover the full retention window, not only the // latest 500 rows. At 5 minutes / 7 days this is ~2,016 points. $history_days = max(1, min(30, (int) ($cfg['history_days'] ?? 7))); $history_interval = max(5, (int) ($cfg['history_interval_min'] ?? 5)); $history_limit = (int) ceil($history_days * 1440 / $history_interval) + 30; $history_limit = max(500, min(10000, $history_limit)); $this->setResponse(new CControllerResponseData([ 'title' => _('L2 Topology'), 'snap_json' => ($json !== null && $json !== '') ? $json : 'null', 'cfg_json' => json_encode($cfg, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), 'history' => L2Store::listHistory($history_limit), 'used_ts' => $used_ts, 'requested_ts' => $ts, 'is_live' => ($ts === null), 'cfg_refresh'=> (int) $cfg['refresh_seconds'] ])); } }