L2TopologyView.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php declare(strict_types = 0);
  2. /*
  3. ** L2 Topology - GET controller.
  4. ** Renders either the live snapshot or any stored snapshot chosen by ?ts=<epoch>.
  5. */
  6. namespace Modules\WecomCenter\Actions;
  7. use CController;
  8. use CControllerResponseData;
  9. use CWebUser;
  10. use Modules\WecomCenter\Lib\L2Store;
  11. class L2TopologyView extends CController {
  12. protected function init() {
  13. $this->disableCsrfValidation();
  14. }
  15. protected function checkInput() {
  16. return true;
  17. }
  18. protected function checkPermissions() {
  19. return CWebUser::getType() >= USER_TYPE_ZABBIX_USER;
  20. }
  21. protected function doAction() {
  22. L2Store::ensureSchema();
  23. $cfg = L2Store::getConfig();
  24. $ts_raw = $_REQUEST['ts'] ?? '';
  25. $ts = ($ts_raw === '' || $ts_raw === null) ? null : (int) $ts_raw;
  26. $snap = L2Store::snapshotAt($ts);
  27. $json = $snap['json'] ?? null;
  28. $used_ts = $snap['ts'];
  29. $this->setResponse(new CControllerResponseData([
  30. 'title' => _('L2 Topology'),
  31. 'snap_json' => ($json !== null && $json !== '') ? $json : 'null',
  32. 'cfg_json' => json_encode($cfg, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
  33. 'history' => L2Store::listHistory(500),
  34. 'used_ts' => $used_ts,
  35. 'is_live' => ($ts === null),
  36. 'cfg_refresh'=> (int) $cfg['refresh_seconds'],
  37. 'cfg_dark' => !empty($cfg['dark_default'])
  38. ]));
  39. }
  40. }