topology.view.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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=202611052255');
  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.firewall','l2.behavior','l2.total_core','l2.upstream'
  25. ];
  26. $i18n = [];
  27. foreach ($i18nKeys as $k) { $i18n[$k] = I18n::t($k); }
  28. $i18nJson = str_replace('</', '<\/', json_encode($i18n, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
  29. $hist = $data['history'] ?? [];
  30. $isLive = !empty($data['is_live']);
  31. $usedTs = (int) ($data['used_ts'] ?? 0);
  32. $byDay = [];
  33. foreach ($hist as $h) {
  34. $byDay[date('Y-m-d', (int) $h['ts'])][] = $h;
  35. }
  36. $usedDay = (!$isLive && $usedTs) ? date('Y-m-d', $usedTs) : '';
  37. $dateOpts = '<option value=""'.($isLive ? ' selected' : '').'>'.htmlspecialchars(I18n::t('l2.time_live')).'</option>';
  38. $timeOpts = '<option value="">--:--</option>';
  39. foreach ($byDay as $day => $items) {
  40. $dateOpts .= '<option value="'.htmlspecialchars($day).'"'.($day === $usedDay ? ' selected' : '').'>'
  41. .htmlspecialchars($day).' ('.count($items).')</option>';
  42. if ($day === $usedDay) {
  43. $timeOpts = '';
  44. foreach ($items as $h) {
  45. $sel = ($usedTs === (int) $h['ts']) ? ' selected' : '';
  46. $timeOpts .= '<option value="'.(int) $h['ts'].'"'.$sel.'>'.date('H:i:s', (int) $h['ts']).'</option>';
  47. }
  48. }
  49. }
  50. $refreshSec = (int) ($data['cfg_refresh'] ?? 300);
  51. if (!function_exists('l2e')) { function l2e($v) { return htmlspecialchars((string) $v, ENT_QUOTES, 'UTF-8'); } }
  52. ?>
  53. <div class="l2-wrap" id="l2-wrap">
  54. <div class="l2-toolbar">
  55. <span class="tb-title"><?php echo l2e(I18n::t('l2.title')); ?></span>
  56. <div class="l2-search-wrap">
  57. <input id="l2-search" type="text" placeholder="<?php echo l2e(I18n::t('l2.search_ph')); ?>" autocomplete="off"/>
  58. <div id="l2-sug"></div>
  59. </div>
  60. <label class="l2-chk"><input type="checkbox" id="l2-showterm"/> <?php echo l2e(I18n::t('l2.show_term')); ?></label>
  61. <label class="l2-ts-label"><?php echo l2e(I18n::t('l2.time_date')); ?>
  62. <select id="l2-ts-date" class="l2-btn l2-ts-select l2-ts-date" title="<?php echo l2e(I18n::t('l2.time_date_title')); ?>"><?php echo $dateOpts; ?></select>
  63. </label>
  64. <label class="l2-ts-label"><?php echo l2e(I18n::t('l2.time_time')); ?>
  65. <select id="l2-ts-time" class="l2-btn l2-ts-select l2-ts-time" title="<?php echo l2e(I18n::t('l2.time_time_title')); ?>"<?php echo $isLive ? ' disabled' : ''; ?>><?php echo $timeOpts; ?></select>
  66. </label>
  67. <button class="l2-btn" id="l2-ts-go"><?php echo l2e(I18n::t('l2.time_btn')); ?></button>
  68. <span class="l2-spacer"></span>
  69. <span id="l2-countdown" class="l2-muted"></span>
  70. <button class="l2-btn" id="l2-pause" title="pause">❚❚</button>
  71. <button class="l2-btn primary" id="l2-refresh-btn"><?php echo l2e(I18n::t('l2.refresh_now')); ?></button>
  72. <button class="l2-btn" id="l2-zin">+</button>
  73. <button class="l2-btn" id="l2-zout">-</button>
  74. <button class="l2-btn" id="l2-fit"><?php echo l2e(I18n::t('l2.fit')); ?></button>
  75. <button class="l2-btn" id="l2-export"><?php echo l2e(I18n::t('l2.export_img')); ?></button>
  76. </div>
  77. <div class="l2-main">
  78. <div class="l2-canvas">
  79. <div id="l2-cy"></div>
  80. <div class="l2-stats" id="l2-stats"></div>
  81. </div>
  82. <div class="l2-side">
  83. <div class="side-tabs">
  84. <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>
  85. <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>
  86. <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>
  87. </div>
  88. <div class="side-body">
  89. <div class="panel-sec active" id="sec-alarms"><div id="l2-alarm-list"></div></div>
  90. <div class="panel-sec" id="sec-offline"><div id="l2-offline-list"></div></div>
  91. <div class="panel-sec" id="sec-terms"><div id="l2-term-list"></div></div>
  92. </div>
  93. <div class="l2-legend" id="l2-legend"></div>
  94. </div>
  95. </div>
  96. </div>
  97. <div class="l2-tip" id="l2-tip"></div>
  98. <script>
  99. window.L2SNAP = <?php echo $snapSafe; ?>;
  100. window.L2_CFG = <?php echo $cfgSafe; ?>;
  101. window.L2_I18N = <?php echo $i18nJson; ?>;
  102. window.L2_HISTORY = <?php echo str_replace('</', '<\/', json_encode($hist, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); ?>;
  103. window.L2_META = {
  104. base: '<?php echo $base; ?>',
  105. snapshotUrl: '<?php echo $base; ?>snapshot.json',
  106. isLive: <?php echo $isLive ? 'true' : 'false'; ?>,
  107. usedTs: <?php echo $usedTs; ?>,
  108. refreshSeconds: <?php echo $refreshSec; ?>,
  109. zabbixHostUrl: '/zabbix.php?action=problem.view&hostids%5B%5D=__HOSTID__'
  110. };
  111. </script>
  112. <script src="<?php echo $base; ?>cytoscape.min.js"></script>
  113. <script src="<?php echo $base; ?>app.js?v=202611052255"></script>
  114. <script>
  115. (function(){
  116. var tabs = document.querySelectorAll('.side-tab');
  117. tabs.forEach(function(t){
  118. t.addEventListener('click', function(){
  119. tabs.forEach(function(x){x.classList.remove('active');});
  120. t.classList.add('active');
  121. document.querySelectorAll('.panel-sec').forEach(function(s){s.classList.remove('active');});
  122. var sec = document.getElementById('sec-' + t.getAttribute('data-sec'));
  123. if (sec) sec.classList.add('active');
  124. if (t.getAttribute('data-sec') === 'terms') {
  125. var cb = document.getElementById('l2-showterm');
  126. if (cb && !cb.checked) { cb.checked = true; cb.dispatchEvent(new Event('change')); }
  127. }
  128. });
  129. });
  130. })();
  131. </script>