index.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. set_time_limit(0);
  3. if (cfr('SWITCHPOLL')) {
  4. $allDevices = sp_SnmpGetAllDevices();
  5. $allTemplates = sp_SnmpGetAllModelTemplates();
  6. $allTemplatesAssoc = sp_SnmpGetModelTemplatesAssoc();
  7. $allusermacs = zb_UserGetAllMACs();
  8. $alladdress = zb_AddressGetFullCityaddresslist();
  9. $alldeadswitches = zb_SwitchesGetAllDead();
  10. $deathTime = zb_SwitchesGetAllDeathTime();
  11. $allModels = zb_SwitchModelsGetAllTag();
  12. if ($ubillingConfig->getAlterParam('SWITCHES_EXTENDED')) {
  13. $allswitchmacs = array();
  14. $allSwitches = zb_SwitchesGetAll();
  15. if (!empty($allSwitches)) {
  16. foreach ($allSwitches as $io => $each) {
  17. if (!empty($each['swid'])) {
  18. $allswitchmacs[$each['swid']]['id'] = $each['id'];
  19. $allswitchmacs[$each['swid']]['ip'] = $each['ip'];
  20. $allswitchmacs[$each['swid']]['location'] = $each['location'];
  21. }
  22. }
  23. }
  24. } else {
  25. $allswitchmacs = array();
  26. }
  27. //poll single device
  28. if (ubRouting::checkGet('switchid')) {
  29. $switchId = ubRouting::get('switchid', 'int');
  30. if (!empty($allDevices)) {
  31. foreach ($allDevices as $ia => $eachDevice) {
  32. if ($eachDevice['id'] == $switchId) {
  33. //detecting device template
  34. if (!empty($allTemplatesAssoc)) {
  35. if (isset($allTemplatesAssoc[$eachDevice['modelid']])) {
  36. if (!isset($alldeadswitches[$eachDevice['ip']])) {
  37. //cache cleanup
  38. if (wf_CheckGet(array('forcecache'))) {
  39. $deviceRawSnmpCache = rcms_scandir('./exports/', $eachDevice['ip'] . '_*');
  40. if (!empty($deviceRawSnmpCache)) {
  41. foreach ($deviceRawSnmpCache as $ir => $fileToDelete) {
  42. unlink('./exports/' . $fileToDelete);
  43. }
  44. }
  45. rcms_redirect('?module=switchpoller&switchid=' . $eachDevice['id']);
  46. }
  47. $deviceTemplate = $allTemplatesAssoc[$eachDevice['modelid']];
  48. $modActions = wf_BackLink('?module=switches');
  49. $modActions .= wf_Link('?module=switches&edit=' . $switchId, web_edit_icon() . ' ' . __('Edit') . ' ' . __('Switch'), false, 'ubButton');
  50. if (cfr('SWITCHSONIC')) {
  51. if ($ubillingConfig->getAlterParam('SWITCHSONIC_ENABLED')) {
  52. if (!empty($eachDevice['snmp'])) {
  53. $ssonicUrl = '?module=switchsonic';
  54. $ssonicUrl .= '&swid=' . $eachDevice['id'];
  55. $ssonicUrl .= '&swip=' . $eachDevice['ip'];
  56. $ssonicUrl .= '&swcomm=' . $eachDevice['snmp'];
  57. $modActions .= wf_Link($ssonicUrl, wf_img('skins/sonic_icon.png') . ' ' . __('Realtime traffic'), false, 'ubButton');
  58. }
  59. }
  60. }
  61. $modActions .= wf_Link('?module=switchpoller&switchid=' . $eachDevice['id'] . '&forcecache=true', wf_img('skins/refresh.gif') . ' ' . __('Force query'), false, 'ubButton');
  62. $deviceModel = (isset($allModels[$eachDevice['modelid']])) ? $allModels[$eachDevice['modelid']] : __('Model') . ' ' . __('Unknown');
  63. show_window($deviceModel . ', ' . $eachDevice['ip'] . ' - ' . $eachDevice['location'], $modActions);
  64. sp_SnmpPollDevice($eachDevice['ip'], $eachDevice['snmp'], $allTemplates, $deviceTemplate, $allusermacs, $alladdress, $eachDevice['snmpwrite'], false, $allswitchmacs);
  65. } else {
  66. show_error(__('Switch dead since') . ' ' . @$deathTime[$eachDevice['ip']]);
  67. show_window('', wf_BackLink('?module=switches') . ' ' . wf_Link('?module=switches&edit=' . $switchId, web_edit_icon() . ' ' . __('Edit switch'), false, 'ubButton'));
  68. }
  69. } else {
  70. show_error(__('No') . ' ' . __('SNMP template'));
  71. }
  72. }
  73. }
  74. }
  75. }
  76. } else {
  77. //display all of available fdb tables
  78. $fdbData_raw = rcms_scandir('./exports/', '*_fdb');
  79. if (!empty($fdbData_raw)) {
  80. //// mac filters setup
  81. if (wf_CheckPost(array('setmacfilters'))) {
  82. //setting new MAC filters
  83. if (!empty($_POST['newmacfilters'])) {
  84. $newFilters = base64_encode($_POST['newmacfilters']);
  85. zb_StorageSet('FDBCACHEMACFILTERS', $newFilters);
  86. }
  87. //deleting old filters
  88. if (isset($_POST['deletemacfilters'])) {
  89. zb_StorageDelete('FDBCACHEMACFILTERS');
  90. }
  91. }
  92. //log download
  93. if (wf_CheckGet(array('dlswpolllog'))) {
  94. zb_FDBTableLogDownload();
  95. }
  96. //push ajax data
  97. if (wf_CheckGet(array('ajax'))) {
  98. if (wf_CheckGet(array('swfilter'))) {
  99. $fdbData_raw = array($_GET['swfilter'] . '_fdb');
  100. }
  101. if (wf_CheckGet(array('macfilter'))) {
  102. $macFilter = $_GET['macfilter'];
  103. } else {
  104. $macFilter = '';
  105. }
  106. sn_SnmpParseFdbCacheJson($fdbData_raw, $macFilter);
  107. } else {
  108. if (wf_CheckGet(array('fdbfor'))) {
  109. $fdbSwitchFilter = $_GET['fdbfor'];
  110. } else {
  111. $fdbSwitchFilter = '';
  112. }
  113. if (wf_CheckGet(array('macfilter'))) {
  114. $fdbMacFilter = $_GET['macfilter'];
  115. } else {
  116. $fdbMacFilter = '';
  117. }
  118. web_FDBTableShowDataTable($fdbSwitchFilter, $fdbMacFilter);
  119. }
  120. } else {
  121. show_warning(__('Nothing found'));
  122. }
  123. }
  124. } else {
  125. show_error(__('Access denied'));
  126. }