topology.view.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php declare(strict_types = 0);
  2. /*
  3. ** L2 Topology page — display-only map (all settings live in the config center).
  4. ** @var CView $this
  5. ** @var array $data
  6. */
  7. use Modules\WecomCenter\Lib\I18n;
  8. $this->addCssFile('modules/WecomCenter/assets/l2topology/style.css?v=202611060205');
  9. $base = '/modules/WecomCenter/assets/l2topology/';
  10. $snapJson = (string) ($data['snap_json'] ?? 'null');
  11. $cfgJson = (string) ($data['cfg_json'] ?? '{}');
  12. $snapSafe = str_replace('</', '<\/', $snapJson);
  13. $cfgSafe = str_replace('</', '<\/', $cfgJson);
  14. $i18nKeys = [
  15. 'l2.title','l2.search_ph','l2.show_term','l2.only_off','l2.auto_refresh','l2.min',
  16. 'l2.refresh_now','l2.fit','l2.alarms','l2.offline','l2.time_live','l2.time_btn',
  17. 'l2.time_label','l2.time_pick','l2.no_data','l2.offline_empty','l2.alarm_empty','l2.updated',
  18. 'l2.pause','l2.resume','l2.legend_speed','l2.legend_tier','l2.legend_lat','l2.core','l2.main','l2.dist','l2.access',
  19. 'l2.lat_norm','l2.term_on','l2.term_off','l2.term_title','l2.term_mac','l2.term_rate','l2.term_switch','l2.term_port','l2.term_ip','l2.zoom_in','l2.zoom_out','l2.snapshot','l2.showing','l2.live_tag',
  20. 'l2.unit_sw','l2.tile_hint','l2.not_in_topo','l2.click_hint','l2.floor_na',
  21. 'l2.net_surve','l2.net_office','l2.net_other',
  22. 'l2.terminals','l2.offline_short','l2.last_online','l2.history','l2.history_live',
  23. 'l2.history_live_hint','l2.history_empty','l2.time_date','l2.time_time',
  24. 'l2.time_date_title','l2.time_time_title','l2.time_pick_title','l2.time_choose',
  25. 'l2.time_live_full','l2.time_live_hint','l2.firewall','l2.behavior','l2.total_core','l2.upstream'
  26. ];
  27. $i18n = [];
  28. foreach ($i18nKeys as $k) { $i18n[$k] = I18n::t($k); }
  29. $i18nJson = str_replace('</', '<\/', json_encode($i18n, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
  30. $hist = $data['history'] ?? [];
  31. $isLive = !empty($data['is_live']);
  32. $usedTs = (int) ($data['used_ts'] ?? 0);
  33. $pickerLabel = I18n::t('l2.time_live_full');
  34. if (!$isLive && $usedTs) {
  35. foreach ($hist as $h) {
  36. if ((int) $h['ts'] === $usedTs) {
  37. $pickerLabel = date('Y-m-d H:i:s', (int) $h['ts']);
  38. break;
  39. }
  40. }
  41. }
  42. $refreshSec = (int) ($data['cfg_refresh'] ?? 300);
  43. if (!function_exists('l2e')) { function l2e($v) { return htmlspecialchars((string) $v, ENT_QUOTES, 'UTF-8'); } }
  44. ?>
  45. <div class="l2-wrap" id="l2-wrap">
  46. <div class="l2-toolbar">
  47. <span class="tb-title"><?php echo l2e(I18n::t('l2.title')); ?></span>
  48. <div class="l2-search-wrap">
  49. <input id="l2-search" type="text" placeholder="<?php echo l2e(I18n::t('l2.search_ph')); ?>" autocomplete="off"/>
  50. <div id="l2-sug"></div>
  51. </div>
  52. <label class="l2-chk"><input type="checkbox" id="l2-showterm"/> <?php echo l2e(I18n::t('l2.show_term')); ?></label>
  53. <div class="l2-ts-label"><?php echo l2e(I18n::t('l2.time_pick_title')); ?>
  54. <span class="l2-ts-picker" id="l2-ts-picker">
  55. <button type="button" class="l2-ts-trigger" id="l2-ts-trigger" aria-haspopup="dialog" aria-expanded="false" title="<?php echo l2e(I18n::t('l2.time_pick_title')); ?>">
  56. <span class="l2-ts-clock" aria-hidden="true">&#9719;</span>
  57. <span class="l2-ts-current" id="l2-ts-current"><?php echo l2e($pickerLabel); ?></span>
  58. <span class="l2-ts-caret" aria-hidden="true">&#9662;</span>
  59. </button>
  60. <div class="l2-ts-pop" id="l2-ts-pop" role="dialog" aria-label="<?php echo l2e(I18n::t('l2.time_pick_title')); ?>">
  61. <div class="l2-ts-days" id="l2-ts-days"></div>
  62. <div class="l2-ts-times-wrap">
  63. <div class="l2-ts-times-title" id="l2-ts-times-title"></div>
  64. <div class="l2-ts-times" id="l2-ts-times"></div>
  65. </div>
  66. </div>
  67. </span>
  68. </div>
  69. <span class="l2-spacer"></span>
  70. <span id="l2-countdown" class="l2-muted"></span>
  71. <button class="l2-btn" id="l2-pause" title="pause">&#10074;&#10074;</button>
  72. <button class="l2-btn primary" id="l2-refresh-btn"><?php echo l2e(I18n::t('l2.refresh_now')); ?></button>
  73. <button class="l2-btn" id="l2-zin">&#43;</button>
  74. <button class="l2-btn" id="l2-zout">&#8722;</button>
  75. <button class="l2-btn" id="l2-fit"><?php echo l2e(I18n::t('l2.fit')); ?></button>
  76. <button class="l2-btn" id="l2-export"><?php echo l2e(I18n::t('l2.export_img')); ?></button>
  77. </div>
  78. <div class="l2-main">
  79. <div class="l2-canvas">
  80. <div id="l2-cy"></div>
  81. <div class="l2-stats" id="l2-stats"></div>
  82. </div>
  83. <div class="l2-side">
  84. <div class="side-tabs">
  85. <div class="side-tab active" data-sec="alarms"><?php echo l2e(I18n::t('l2.alarms')); ?> <span class="badge" id="l2-alarm-count">0</span></div>
  86. <div class="side-tab" data-sec="offline"><?php echo l2e(I18n::t('l2.offline')); ?> <span class="badge" id="l2-offline-count" style="background:#78909c">0</span></div>
  87. <div class="side-tab" data-sec="terms"><?php echo l2e(I18n::t('l2.show_term')); ?> <span class="badge" id="l2-term-count" style="background:#2E75B6">0</span></div>
  88. </div>
  89. <div class="side-body">
  90. <div class="panel-sec active" id="sec-alarms"><div id="l2-alarm-list"></div></div>
  91. <div class="panel-sec" id="sec-offline"><div id="l2-offline-list"></div></div>
  92. <div class="panel-sec" id="sec-terms"><div id="l2-term-list"></div></div>
  93. </div>
  94. <div class="l2-legend" id="l2-legend"></div>
  95. </div>
  96. </div>
  97. </div>
  98. <div class="l2-tip" id="l2-tip"></div>
  99. <script>
  100. window.L2SNAP = <?php echo $snapSafe; ?>;
  101. window.L2_CFG = <?php echo $cfgSafe; ?>;
  102. window.L2_I18N = <?php echo $i18nJson; ?>;
  103. window.L2_HISTORY = <?php echo str_replace('</', '<\/', json_encode($hist, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); ?>;
  104. window.L2_META = {
  105. base: '<?php echo $base; ?>',
  106. snapshotUrl: '<?php echo $base; ?>snapshot.json',
  107. isLive: <?php echo $isLive ? 'true' : 'false'; ?>,
  108. usedTs: <?php echo $usedTs; ?>,
  109. refreshSeconds: <?php echo $refreshSec; ?>,
  110. zabbixHostUrl: '/zabbix.php?action=problem.view&hostids%5B%5D=__HOSTID__'
  111. };
  112. </script>
  113. <script src="<?php echo $base; ?>cytoscape.min.js"></script>
  114. <script src="<?php echo $base; ?>app.js?v=202611060205"></script>
  115. <script>
  116. (function(){
  117. var tabs = document.querySelectorAll('.side-tab');
  118. tabs.forEach(function(t){
  119. t.addEventListener('click', function(){
  120. tabs.forEach(function(x){x.classList.remove('active');});
  121. t.classList.add('active');
  122. document.querySelectorAll('.panel-sec').forEach(function(s){s.classList.remove('active');});
  123. var sec = document.getElementById('sec-' + t.getAttribute('data-sec'));
  124. if (sec) sec.classList.add('active');
  125. if (t.getAttribute('data-sec') === 'terms') {
  126. var cb = document.getElementById('l2-showterm');
  127. if (cb && !cb.checked) { cb.checked = true; cb.dispatchEvent(new Event('change')); }
  128. }
  129. });
  130. });
  131. })();
  132. </script>