api.swpoll.php 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348
  1. <?php
  2. /*
  3. * SNMP switch polling API
  4. */
  5. /**
  6. * Raw SNMP data parser
  7. *
  8. * @return string
  9. */
  10. function sp_parse_raw($data) {
  11. if (!empty($data)) {
  12. $data = explode('=', $data);
  13. $result = $data[1] . wf_tag('br');
  14. return ($result);
  15. } else {
  16. return (__('Empty reply received'));
  17. }
  18. }
  19. /**
  20. * Raw SNMP data parser with value types cleanup
  21. *
  22. * @param string $data
  23. *
  24. * @return string
  25. */
  26. function sp_parse_raw_sanitized($data) {
  27. $result = '';
  28. if (!empty($data)) {
  29. $result = zb_SanitizeSNMPValue($data) . wf_tag('br');
  30. } else {
  31. $result = __('Empty reply received');
  32. }
  33. return($result);
  34. }
  35. /**
  36. * Returns human readable uptime converted from seconds value
  37. *
  38. * @param string $data
  39. *
  40. * @return string
  41. */
  42. function sp_parse_time_seconds($data) {
  43. $result = '';
  44. if (!empty($data)) {
  45. $rawTime = zb_SanitizeSNMPValue($data);
  46. if (!empty($rawTime)) {
  47. $result = zb_formatTime($rawTime) . wf_tag('br');
  48. }
  49. } else {
  50. $result = __('Empty reply received');
  51. }
  52. return($result);
  53. }
  54. /**
  55. * Returns LED of electrical power state.
  56. *
  57. * @param string $data
  58. *
  59. * @return string
  60. */
  61. function sp_parse_power($data) {
  62. $result = '';
  63. if (!empty($data)) {
  64. $rawValue = zb_SanitizeSNMPValue($data);
  65. if ($rawValue) {
  66. $result = wf_img('skins/lighton.png') . wf_tag('br');
  67. } else {
  68. $result = wf_img('skins/lightoff.png') . wf_tag('br');
  69. }
  70. } else {
  71. $result = __('Empty reply received');
  72. }
  73. return($result);
  74. }
  75. /**
  76. * Returns temperature value from equicom ping3 as text
  77. *
  78. * @param string $data
  79. *
  80. * @return string
  81. */
  82. function sp_parse_eping_temp($data) {
  83. $result = '';
  84. if (!empty($data)) {
  85. $rawValue = zb_SanitizeSNMPValue($data);
  86. if (!empty($rawValue)) {
  87. $result = ($rawValue / 10) . ' °C' . wf_tag('br');
  88. }
  89. } else {
  90. $result = __('Empty reply received');
  91. }
  92. return($result);
  93. }
  94. /**
  95. * Returns temperature value from equicom ping3 as gauge
  96. *
  97. * @param string $data
  98. *
  99. * @return string
  100. */
  101. function sp_parse_eping_temp_gauge($data) {
  102. $result = '';
  103. if (!empty($data)) {
  104. $rawValue = zb_SanitizeSNMPValue($data);
  105. if (!empty($rawValue)) {
  106. $degrees = $rawValue / 10;
  107. $options = 'max: 40,
  108. min: 10,
  109. width: 280, height: 280,
  110. greenFrom: 15, greenTo: 20,
  111. yellowFrom:20, yellowTo: 25,
  112. redFrom: 25, redTo: 40,
  113. minorTicks: 5';
  114. $result = wf_renderTemperature($degrees, '', $options);
  115. }
  116. } else {
  117. $result = __('Empty reply received');
  118. }
  119. return($result);
  120. }
  121. /**
  122. * Returns battery voltage value from equicom ping3 as text
  123. *
  124. * @param string $data
  125. *
  126. * @return string
  127. */
  128. function sp_parse_eping_bat($data) {
  129. $result = '';
  130. if (!empty($data)) {
  131. $rawValue = zb_SanitizeSNMPValue($data);
  132. if (!empty($rawValue)) {
  133. $result = ($rawValue / 10) . ' V' . wf_tag('br');
  134. }
  135. } else {
  136. $result = __('Empty reply received');
  137. }
  138. return($result);
  139. }
  140. /**
  141. * Raw SNMP data parser with trimming
  142. *
  143. * @return string
  144. */
  145. function sp_parse_raw_trim_tab($data) {
  146. $result = __('Empty reply received');
  147. if (!empty($data)) {
  148. $data = trimSNMPOutput($data, '');
  149. $cells = wf_TableCell($data[1]);
  150. $rows = wf_TableRow($cells, 'row3');
  151. $result = wf_TableBody($rows, '100%', 0, '');
  152. }
  153. return ($result);
  154. }
  155. /**
  156. * Raisecom Port state data parser
  157. *
  158. * @return string
  159. */
  160. function sp_parse_raportstates($data) {
  161. if (!empty($data)) {
  162. $data = explode('=', $data);
  163. $data[0] = trim($data[0]);
  164. $portnum = substr($data[0], -2);
  165. $portnum = str_replace('.', '', $portnum);
  166. $portnum = $portnum - 32;
  167. if (ispos($data[1], '1')) {
  168. $cells = wf_TableCell($portnum, '24', '', 'style="height:20px;"');
  169. $cells .= wf_TableCell(web_bool_led(true));
  170. $rows = wf_TableRow($cells, 'row3');
  171. $result = wf_TableBody($rows, '100%', 0, '');
  172. } else {
  173. $cells = wf_TableCell($portnum, '24', '', 'style="height:20px;"');
  174. $cells .= wf_TableCell(web_bool_led(false));
  175. $rows = wf_TableRow($cells, 'row3');
  176. $result = wf_TableBody($rows, '100%', 0, '');
  177. }
  178. return ($result);
  179. } else {
  180. return (__('Empty reply received'));
  181. }
  182. }
  183. /**
  184. * Zyxel Port state data parser
  185. *
  186. * @return string
  187. */
  188. function sp_parse_zyportstates($data) {
  189. if (!empty($data)) {
  190. $data = explode('=', $data);
  191. $data[0] = trim($data[0]);
  192. $portnum = substr($data[0], -2);
  193. $portnum = str_replace('.', '', $portnum);
  194. if (ispos($data[1], '1')) {
  195. $cells = wf_TableCell($portnum, '24', '', 'style="height:20px;"');
  196. $cells .= wf_TableCell(web_bool_led(true));
  197. $rows = wf_TableRow($cells, 'row3');
  198. $result = wf_TableBody($rows, '100%', 0, '');
  199. } else {
  200. $cells = wf_TableCell($portnum, '24', '', 'style="height:20px;"');
  201. $cells .= wf_TableCell(web_bool_led(false));
  202. $rows = wf_TableRow($cells, 'row3');
  203. $result = wf_TableBody($rows, '100%', 0, '');
  204. }
  205. return ($result);
  206. } else {
  207. return (__('Empty reply received'));
  208. }
  209. }
  210. /**
  211. * Some Foxgate 60xx port state data parser
  212. *
  213. * @return string
  214. */
  215. function sp_parse_fxportstates($data) {
  216. $result = '';
  217. if (!empty($data)) {
  218. $data = explode('=', $data);
  219. $data[0] = trim($data[0]);
  220. $portnum = substr($data[0], -2);
  221. $portnum = str_replace('.', '', $portnum);
  222. $portnum = $portnum - 1;
  223. if ($portnum != 0) {
  224. if (ispos($data[1], '1')) {
  225. $cells = wf_TableCell($portnum, '24', '', 'style="height:20px;"');
  226. $cells .= wf_TableCell(web_bool_led(true));
  227. $rows = wf_TableRow($cells, 'row3');
  228. $result = wf_TableBody($rows, '100%', 0, '');
  229. } else {
  230. $cells = wf_TableCell($portnum, '24', '', 'style="height:20px;"');
  231. $cells .= wf_TableCell(web_bool_led(false));
  232. $rows = wf_TableRow($cells, 'row3');
  233. $result = wf_TableBody($rows, '100%', 0, '');
  234. }
  235. }
  236. return ($result);
  237. } else {
  238. return (__('Empty reply received'));
  239. }
  240. }
  241. /**
  242. * D-Link Cable diagnostic data parser
  243. *
  244. * @return string
  245. */
  246. function sp_parse_cable_tester($ip, $community, $currentTemplate) {
  247. if (!empty($currentTemplate)) {
  248. $snmp = new SNMPHelper();
  249. $result = '';
  250. @$sectionOids = explode(',', $currentTemplate['OIDS']);
  251. $sectionResult = array();
  252. $rawData_arr = array();
  253. //now parse each oid
  254. if (!empty($sectionOids)) {
  255. foreach ($sectionOids as $eachOid) {
  256. $eachOid = trim($eachOid);
  257. $rawData = $snmp->walk($ip, $community, $eachOid, true);
  258. $rawData_arr[] = str_replace('"', '`', $rawData);
  259. // Create new array [$portnum][$each]=>$data
  260. foreach ($rawData_arr as $each => $data_arr) {
  261. $data = explode(PHP_EOL, $data_arr);
  262. foreach ($data as $data_info) {
  263. $data = explode('=', $data_info);
  264. if (isset($data[0]) and isset($data[1])) {
  265. $data[0] = trim($data[0]);
  266. $portnum = substr($data[0], -2);
  267. $portnum = str_replace('.', '', $portnum);
  268. $interger = trim($data[1]);
  269. $interger = str_replace('INTEGER: ', '', $interger);
  270. $sectionResult[$portnum][$each] = $interger;
  271. }
  272. }
  273. }
  274. }
  275. }
  276. // Parsing result after snmwalk and create data array
  277. foreach ($sectionResult as $port => $data) {
  278. if (!empty($data)) {
  279. $cells = wf_TableCell($port, '24', '', 'style="height:20px;"');
  280. $cells_data = '';
  281. foreach ($data as $test_id => $info) {
  282. if ($test_id == 0 and $info != 2) {
  283. if (@$data[1] == 0 OR @ $data[2] == 0 OR @ $data[3] == 0 OR @ $data[4] == 0) {
  284. $cells_data .= __("OK");
  285. // Return Length for Pair2, becase some modele have accrose rawdata
  286. @$cells_data .= ($data[2] == 0 AND $data[6] > 0 ) ? "," . __("Cable Length:") . $data[6] : '';
  287. } elseif ($data[1] == 1 OR $data[2] == 1 OR $data[3] == 1 OR $data[4] == 1) {
  288. $cells_data .= ($data[1] == 1) ? __("Pair1 Open:") . $data[5] . " " : '';
  289. $cells_data .= ($data[2] == 1) ? __("Pair2 Open:") . $data[6] . " " : '';
  290. $cells_data .= ($data[3] == 1) ? __("Pair3 Open:") . $data[7] . " " : '';
  291. $cells_data .= ($data[4] == 1) ? __("Pair4 Open:") . $data[8] . " " : '';
  292. } elseif ($data[1] == 2 OR $data[2] == 2 OR $data[3] == 2 OR $data[4] == 2) {
  293. $cells_data .= ($data[1] == 2) ? __("Pair1 Short:") . $data[5] . " " : '';
  294. $cells_data .= ($data[2] == 2) ? __("Pair2 Short:") . $data[6] . " " : '';
  295. $cells_data .= ($data[3] == 2) ? __("Pair3 Short:") . $data[7] . " " : '';
  296. $cells_data .= ($data[4] == 2) ? __("Pair4 Short:") . $data[8] . " " : '';
  297. } elseif ($data[1] == 3 OR $data[2] == 3 OR $data[3] == 3 OR $data[4] == 3) {
  298. $cells_data .= ($data[1] == 3) ? __("Pair1 Open-Short:") . $data[5] . " " : '';
  299. $cells_data .= ($data[2] == 3) ? __("Pair2 Open-Short:") . $data[6] . " " : '';
  300. $cells_data .= ($data[3] == 3) ? __("Pair3 Open-Short:") . $data[7] . " " : '';
  301. $cells_data .= ($data[4] == 3) ? __("Pair4 Open-Short:") . $data[8] . " " : '';
  302. } elseif ($data[1] == 4 OR $data[2] == 4 OR $data[3] == 4 OR $data[4] == 4) {
  303. $cells_data .= ($data[1] == 4) ? __("Pair1 crosstalk") . " " : '';
  304. $cells_data .= ($data[2] == 4) ? __("Pair2 crosstalk") . " " : '';
  305. $cells_data .= ($data[3] == 4) ? __("Pair3 crosstalk") . " " : '';
  306. $cells_data .= ($data[4] == 4) ? __("Pair4 crosstalk") . " " : '';
  307. } elseif ($data[1] == 5 OR $data[2] == 5 OR $data[5] == 5 OR $data[4] == 5) {
  308. $cells_data .= ($data[1] == 5) ? __("Pair1 unknown") . " " : '';
  309. $cells_data .= ($data[2] == 5) ? __("Pair2 unknown") . " " : '';
  310. $cells_data .= ($data[3] == 5) ? __("Pair3 unknown") . " " : '';
  311. $cells_data .= ($data[4] == 5) ? __("Pair4 unknown") . " " : '';
  312. } elseif ($data[1] == 6 OR $data[2] == 6 OR $data[5] == 6 OR $data[4] == 6) {
  313. $cells_data .= ($data[1] == 6) ? __("Pair1 count") . " " : '';
  314. $cells_data .= ($data[2] == 6) ? __("Pair2 count") . " " : '';
  315. $cells_data .= ($data[3] == 6) ? __("Pair3 count") . " " : '';
  316. $cells_data .= ($data[4] == 6) ? __("Pair4 count") . " " : '';
  317. } elseif ($data[1] == 7 OR $data[2] == 7 OR $data[5] == 7 OR $data[4] == 7) {
  318. $cells_data .= __("No Cable");
  319. } elseif ($data[1] == 8 OR $data[2] == 8 OR $data[5] == 8 OR $data[4] == 8) {
  320. $cells_data .= __("The PHY can't support Cable Diagnostic");
  321. }
  322. } elseif ($test_id == 0 and $info == 2) {
  323. $cells_data .= __("Cable Diagnostic processing");
  324. }
  325. }
  326. $cells .= wf_TableCell($cells_data);
  327. $rows = wf_TableRow($cells, 'row3');
  328. $result .= wf_TableBody($rows, '100%', 0, '');
  329. }
  330. }
  331. return ($result);
  332. } else {
  333. return (__('Empty reply received'));
  334. }
  335. }
  336. /**
  337. * Zyxel Port byte counters data parser
  338. *
  339. * @return string
  340. */
  341. function sp_parse_zyportbytes($data) {
  342. if (!empty($data)) {
  343. $data = explode('=', $data);
  344. $data[0] = trim($data[0]);
  345. $portnum = substr($data[0], -2);
  346. $portnum = str_replace('.', '', $portnum);
  347. $bytes = str_replace(array('Counter32:', 'Counter64:'), '', $data[1]);
  348. $bytes = trim($bytes);
  349. if (ispos($data[1], 'up')) {
  350. $cells = wf_TableCell($portnum, '24', '', 'style="height:20px;"');
  351. $cells .= wf_TableCell($bytes);
  352. $rows = wf_TableRow($cells, 'row3');
  353. $result = wf_TableBody($rows, '100%', 0, '');
  354. } else {
  355. $cells = wf_TableCell($portnum, '24', '', 'style="height:20px;"');
  356. $cells .= wf_TableCell($bytes);
  357. $rows = wf_TableRow($cells, 'row3');
  358. $result = wf_TableBody($rows, '100%', 0, '');
  359. }
  360. return ($result);
  361. } else {
  362. return (__('Empty reply received'));
  363. }
  364. }
  365. /**
  366. * Raisecom-ISCOM2624G-4GE-AC Port byte counters data parser
  367. *
  368. * @return string
  369. */
  370. function sp_parse_raportbytes($data) {
  371. if (!empty($data)) {
  372. $data = explode('=', $data);
  373. $data[0] = trim($data[0]);
  374. $portnum = substr($data[0], -2);
  375. $portnum = $portnum - 32;
  376. $portnum = str_replace('.', '', $portnum);
  377. $bytes = str_replace(array('Counter32:', 'Counter64:'), '', $data[1]);
  378. $bytes = trim($bytes);
  379. if (ispos($data[1], 'up')) {
  380. $cells = wf_TableCell($portnum, '24', '', 'style="height:20px;"');
  381. $cells .= wf_TableCell($bytes);
  382. $rows = wf_TableRow($cells, 'row3');
  383. $result = wf_TableBody($rows, '100%', 0, '');
  384. } else {
  385. $cells = wf_TableCell($portnum, '24', '', 'style="height:20px;"');
  386. $cells .= wf_TableCell($bytes);
  387. $rows = wf_TableRow($cells, 'row3');
  388. $result = wf_TableBody($rows, '100%', 0, '');
  389. }
  390. return ($result);
  391. } else {
  392. return (__('Empty reply received'));
  393. }
  394. }
  395. /**
  396. * Foxgate 60xx port byte counters data parser
  397. *
  398. * @return string
  399. */
  400. function sp_parse_fxportbytes($data) {
  401. $result = '';
  402. if (!empty($data)) {
  403. $data = explode('=', $data);
  404. $data[0] = trim($data[0]);
  405. $portnum = substr($data[0], -2);
  406. $portnum = str_replace('.', '', $portnum);
  407. $portnum = $portnum - 1; //shitty offset
  408. $bytes = str_replace(array('Counter32:', 'Counter64:'), '', $data[1]);
  409. $bytes = trim($bytes);
  410. if ($portnum != 0) {
  411. if (ispos($data[1], 'up')) {
  412. $cells = wf_TableCell($portnum, '24', '', 'style="height:20px;"');
  413. $cells .= wf_TableCell($bytes);
  414. $rows = wf_TableRow($cells, 'row3');
  415. $result = wf_TableBody($rows, '100%', 0, '');
  416. } else {
  417. $cells = wf_TableCell($portnum, '24', '', 'style="height:20px;"');
  418. $cells .= wf_TableCell($bytes);
  419. $rows = wf_TableRow($cells, 'row3');
  420. $result = wf_TableBody($rows, '100%', 0, '');
  421. }
  422. }
  423. return ($result);
  424. } else {
  425. return (__('Empty reply received'));
  426. }
  427. }
  428. /**
  429. * Zyxel Port description data parser
  430. *
  431. * @return string
  432. */
  433. function sp_parse_zyportdesc($data) {
  434. if (!empty($data)) {
  435. $data = explode('=', $data);
  436. $data[0] = trim($data[0]);
  437. $portnum = substr($data[0], -2);
  438. $portnum = str_replace('.', '', $portnum);
  439. if (ispos($data[1], 'NULL')) {
  440. $desc = __('No');
  441. } else {
  442. $desc = str_replace('STRING:', '', $data[1]);
  443. $desc = trim($desc);
  444. }
  445. if (ispos($data[1], 'up')) {
  446. $cells = wf_TableCell($portnum, '24', '', 'style="height:20px;"');
  447. $cells .= wf_TableCell($desc);
  448. $rows = wf_TableRow($cells, 'row3');
  449. $result = wf_TableBody($rows, '100%', 0, '');
  450. } else {
  451. $cells = wf_TableCell($portnum, '24', '', 'style="height:20px;"');
  452. $cells .= wf_TableCell($desc);
  453. $rows = wf_TableRow($cells, 'row3');
  454. $result = wf_TableBody($rows, '100%', 0, '');
  455. }
  456. return ($result);
  457. } else {
  458. return (__('Empty reply received'));
  459. }
  460. }
  461. /**
  462. * Cisco memory usage data parser
  463. *
  464. * @return string
  465. */
  466. function sp_parse_ciscomemory($data) {
  467. if (!empty($data)) {
  468. $data = explode('=', $data);
  469. $result = vf($data[1], 3);
  470. $result = trim($result);
  471. $result = stg_convert_size($result);
  472. return ($result);
  473. } else {
  474. return (__('Empty reply received'));
  475. }
  476. }
  477. /**
  478. * Cisco memory usage data parser
  479. *
  480. * @return string
  481. */
  482. function sp_parse_ciscocpu($data) {
  483. if (!empty($data)) {
  484. $data = explode('=', $data);
  485. $result = vf($data[1], 3);
  486. $result = trim($result);
  487. $result = $result . '%';
  488. return ($result);
  489. } else {
  490. return (__('Empty reply received'));
  491. }
  492. }
  493. /**
  494. * Eltex AC Power States
  495. *
  496. * @param string $data
  497. *
  498. * @return string
  499. */
  500. function sp_parse_eltex_acpower($data) {
  501. if (!empty($data)) {
  502. $data = explode(':', $data);
  503. $out = trim($data[1]);
  504. $state = ":Normal:Warning:Critical:Shutdown:notPresent:notFunctioning:Restore";
  505. $power = explode(':', $state);
  506. $result = $power[$out];
  507. return ($result);
  508. } else {
  509. return (__('Empty reply received'));
  510. }
  511. }
  512. /**
  513. * Eltex DC Power States
  514. *
  515. * @param string $data
  516. *
  517. * @return string
  518. */
  519. function sp_parse_eltex_dcpower($data) {
  520. if (!empty($data)) {
  521. $data = explode(':', $data);
  522. $out = trim($data[1]);
  523. $state = ":Battery recharge:Battery discharge:Battery low:Shutdown:notPresent:notFunctioning:Restore";
  524. $power = explode(':', $state);
  525. $result = $power[$out];
  526. return ($result);
  527. } else {
  528. return (__('Empty reply received'));
  529. }
  530. }
  531. /**
  532. * Eltex Battery charge state
  533. *
  534. * @param string $data
  535. *
  536. * @return string
  537. */
  538. function sp_parse_eltex_battery($data) {
  539. if (!empty($data)) {
  540. $data = explode(':', $data);
  541. $result = vf($data[1]);
  542. $result = trim($result);
  543. $result = $result . '%';
  544. if ($data[1] == 255) {
  545. $result = __('No');
  546. }
  547. return ($result);
  548. } else {
  549. return (__('Empty reply received'));
  550. }
  551. }
  552. /**
  553. * Standard parser for values with units and possible division necessity
  554. *
  555. * @param string $data
  556. * @param string $divBy
  557. * @param string $units
  558. *
  559. * @return mixed|string
  560. */
  561. function sp_parse_division_units($data, $divBy = '', $units = '') {
  562. $result = '';
  563. if (!empty($data)
  564. and ! ispos($data, 'No Such Object available')
  565. and ! ispos($data, 'No more variables left')
  566. ) {
  567. $data = trimSNMPOutput($data, '');
  568. $portnum = substr($data[0], -2);
  569. $portnum = str_replace('.', '', $portnum);
  570. $value = $data[1];
  571. // 10 G
  572. if ($value == 1410065408) {
  573. $value = 10000000;
  574. $units = __('Gbit/s');
  575. }
  576. if (!empty($divBy) and is_numeric($divBy)) {
  577. $value = $value / $divBy;
  578. }
  579. if (!empty($units)) {
  580. $value = $value . ' ' . __($units);
  581. }
  582. $cells = wf_TableCell($portnum, '24', '', 'style="height:20px;"');
  583. $cells .= wf_TableCell($value);
  584. $rows = wf_TableRow($cells, 'row3');
  585. $result = wf_TableBody($rows, '100%', 0, '');
  586. } else {
  587. $cells = wf_TableCell('', '24', '', 'style="height:20px;"');
  588. $cells .= wf_TableCell(__('Empty reply received'));
  589. $rows = wf_TableRow($cells, 'row3');
  590. $result = wf_TableBody($rows, '100%', 0, '');
  591. }
  592. return ($result);
  593. }
  594. /**
  595. * Raisecom-ISCOM2624G-4GE-AC parser for values with units and possible division necessity
  596. *
  597. * @param string $data
  598. * @param string $divBy
  599. * @param string $units
  600. *
  601. * @return mixed|string
  602. */
  603. function sp_parse_division_units_ra($data, $divBy = '', $units = '') {
  604. $result = '';
  605. if (!empty($data)
  606. and ! ispos($data, 'No Such Object available')
  607. and ! ispos($data, 'No more variables left')
  608. ) {
  609. $data = trimSNMPOutput($data, '');
  610. $portnum = substr($data[0], -2);
  611. $portnum = str_replace('.', '', $portnum);
  612. $portnum = $portnum - 32;
  613. $value = $data[1];
  614. if (!empty($divBy) and is_numeric($divBy)) {
  615. $value = $value / $divBy;
  616. }
  617. if (!empty($units)) {
  618. $value = $value . ' ' . __($units);
  619. }
  620. $cells = wf_TableCell($portnum, '24', '', 'style="height:20px;"');
  621. $cells .= wf_TableCell($value);
  622. $rows = wf_TableRow($cells, 'row3');
  623. $result = wf_TableBody($rows, '100%', 0, '');
  624. } else {
  625. $cells = wf_TableCell('', '24', '', 'style="height:20px;"');
  626. $cells .= wf_TableCell(__('Empty reply received'));
  627. $rows = wf_TableRow($cells, 'row3');
  628. $result = wf_TableBody($rows, '100%', 0, '');
  629. }
  630. return ($result);
  631. }
  632. /**
  633. * Standard parser for values with units and possible division necessity
  634. * for data without ports info
  635. *
  636. * @param string $data
  637. * @param string $divBy
  638. * @param string $units
  639. *
  640. * @return mixed|string
  641. */
  642. function sp_parse_division_units_noport($data, $divBy = '', $units = '') {
  643. $result = '';
  644. if (!empty($data)
  645. and ! ispos($data, 'No Such Object available')
  646. and ! ispos($data, 'No more variables left')
  647. ) {
  648. $data = trimSNMPOutput($data, '');
  649. $value = $data[1];
  650. if (!empty($divBy) and is_numeric($divBy)) {
  651. $value = $value / $divBy;
  652. }
  653. if (!empty($units)) {
  654. $value = $value . ' ' . $units;
  655. }
  656. $cells = wf_TableCell($value);
  657. $rows = wf_TableRow($cells, 'row3');
  658. $result = wf_TableBody($rows, '100%', 0, '');
  659. } else {
  660. $cells = wf_TableCell('', '24', '', 'style="height:20px;"');
  661. $cells .= wf_TableCell(__('Empty reply received'));
  662. $rows = wf_TableRow($cells, 'row3');
  663. $result = wf_TableBody($rows, '100%', 0, '');
  664. }
  665. return ($result);
  666. }
  667. /**
  668. * Mikrotik POE statuses parser
  669. *
  670. * @param $data
  671. *
  672. * @return mixed|string
  673. */
  674. function sp_parse_mikrotik_poe($data) {
  675. $result = __('Empty reply received');
  676. if (!empty($data)
  677. and ! ispos($data, 'No Such Object available')
  678. and ! ispos($data, 'No more variables left')
  679. ) {
  680. $data = trimSNMPOutput($data, '');
  681. $portnum = substr($data[0], -2);
  682. $portnum = str_replace('.', '', $portnum);
  683. $value = $data[1];
  684. switch ($value) {
  685. case 1:
  686. $value = 'Disabled';
  687. break;
  688. case 2:
  689. $value = 'Waiting for load';
  690. break;
  691. case 3:
  692. $value = 'Powered ON';
  693. break;
  694. case 4:
  695. $value = 'Overload';
  696. break;
  697. default:
  698. $value = 'Short circuit';
  699. }
  700. $cells = wf_TableCell($portnum, '24', '', 'style="height:20px;"');
  701. $cells .= wf_TableCell($value);
  702. $rows = wf_TableRow($cells, 'row3');
  703. $result = wf_TableBody($rows, '100%', 0, '');
  704. }
  705. return ($result);
  706. }
  707. /**
  708. * Returns switch ports index array
  709. *
  710. * @param $portIdxTab
  711. * @param $oid
  712. *
  713. * @return array
  714. */
  715. function sp_parse_sw_port_idx($portIdxTab, $oid) {
  716. $result = array();
  717. if (!empty($portIdxTab)) {
  718. $portIdxTab = explodeRows($portIdxTab);
  719. foreach ($portIdxTab as $eachRow) {
  720. $tmpArr = trimSNMPOutput($eachRow, $oid);
  721. if (!empty($tmpArr)) {
  722. $result[] = (empty($tmpArr[1])) ? 0 : $tmpArr[1];
  723. }
  724. }
  725. }
  726. return ($result);
  727. }
  728. /**
  729. * Returns switch ports descriptions as pre-formatted HTML table cell
  730. *
  731. * @param $data
  732. *
  733. * @return mixed|string
  734. */
  735. function sp_parse_sw_port_descr($data) {
  736. $result = '';
  737. if (!empty($data)) {
  738. foreach ($data as $eachPort => $eachDescr) {
  739. $portnum = $eachPort;
  740. $descr = $eachDescr;
  741. $cells = wf_TableCell($portnum, '24', '', 'style="height:20px;"');
  742. $cells .= wf_TableCell($descr);
  743. $rows = wf_TableRow($cells, 'row3');
  744. $result .= wf_TableBody($rows, '100%', 0, '');
  745. }
  746. return ($result);
  747. } else {
  748. return (__('Empty reply received'));
  749. }
  750. }
  751. /**
  752. * Gets associated list of SNMP templates and switch models
  753. *
  754. * @return array
  755. */
  756. function sp_SnmpGetModelTemplatesAssoc() {
  757. $query = "SELECT `id`,`snmptemplate` from `switchmodels` WHERE `snmptemplate`!=''";
  758. $all = simple_queryall($query);
  759. $result = array();
  760. if (!empty($all)) {
  761. foreach ($all as $io => $each) {
  762. $result[$each['id']] = $each['snmptemplate'];
  763. }
  764. }
  765. return ($result);
  766. }
  767. /**
  768. * Returns raw SNMP data from device with caching
  769. * @param $ip device IP
  770. * @param $community SNMP community
  771. * @param $oid OID which will be polled
  772. * @param $cache cache results
  773. *
  774. * @return string
  775. */
  776. function sp_SnmpPollData($ip, $community, $oid, $cache = true) {
  777. // migrated to SNMPHelper class in 0.6.5
  778. // left this for backward compatibility
  779. $snmp = new SNMPHelper();
  780. $snmp->setBackground(false);
  781. $result = $snmp->walk($ip, $community, $oid, $cache);
  782. return ($result);
  783. }
  784. /**
  785. * Returns list of all monitored devices
  786. *
  787. * @return array
  788. */
  789. function sp_SnmpGetAllDevices() {
  790. $query = "SELECT * from `switches` WHERE `snmp`!='' AND `desc` LIKE '%SWPOLL%'";
  791. $result = simple_queryall($query);
  792. return ($result);
  793. }
  794. /**
  795. * Returns list of all available SNMP device templates
  796. *
  797. * @return array
  798. */
  799. function sp_SnmpGetAllModelTemplates() {
  800. $path = CONFIG_PATH . 'snmptemplates/';
  801. $privatePath = DATA_PATH . 'documents/mysnmptemplates/';
  802. $alltemplates = rcms_scandir($path);
  803. $result = array();
  804. if (!empty($alltemplates)) {
  805. foreach ($alltemplates as $each) {
  806. $result[$each] = rcms_parse_ini_file($path . $each, true);
  807. }
  808. }
  809. $myTemplates = rcms_scandir($privatePath);
  810. if (!empty($myTemplates)) {
  811. foreach ($myTemplates as $each) {
  812. $privateTemplateBody = rcms_parse_ini_file($privatePath . $each, true);
  813. //checking custom template integrity and marking it as custom
  814. if (isset($privateTemplateBody['define'])) {
  815. if (isset($privateTemplateBody['define']['DEVICE'])) {
  816. $originaDeviceModel = $privateTemplateBody['define']['DEVICE'];
  817. $privateTemplateBody['define']['DEVICE'] = $originaDeviceModel . ' 🚲 ';
  818. $result[$each] = $privateTemplateBody;
  819. }
  820. }
  821. }
  822. }
  823. return ($result);
  824. }
  825. /**
  826. * Convert splitted decimal MAC to normal view
  827. *
  828. * @param array $parts
  829. *
  830. * @return string
  831. */
  832. function sp_PartsToMac($parts) {
  833. $result = '';
  834. //format + mac is present?
  835. if (count($parts) == 6) {
  836. foreach ($parts as $io => $eachPart) {
  837. $result .= sprintf('%02X', $eachPart) . ':';
  838. }
  839. $result = rtrim($result, ':');
  840. $result = strtolower($result);
  841. }
  842. return($result);
  843. }
  844. /**
  845. * Parsing of FDB port table SNMP raw data
  846. *
  847. * @param $portTable raw SNMP data
  848. *
  849. * @return array
  850. */
  851. function sp_SnmpParseFdb($portTable) {
  852. $portData = array();
  853. $arr_PortTable = explodeRows($portTable);
  854. if (!empty($arr_PortTable)) {
  855. foreach ($arr_PortTable as $eachEntry) {
  856. if (!empty($eachEntry)) {
  857. $eachEntry = str_replace('.1.3.6.1.2.1.17.4.3.1.2', '', $eachEntry);
  858. $cleanMac = '';
  859. $rawMac = explode('=', $eachEntry);
  860. $parts = explode('.', trim($rawMac[0], '.'));
  861. if (count($parts) == 6) {
  862. $cleanMac = sp_PartsToMac($parts);
  863. $portData[$cleanMac] = vf($rawMac[1], 3);
  864. }
  865. }
  866. }
  867. }
  868. return ($portData);
  869. }
  870. // Parsing of FDB port table SNMP raw data for Raisecom
  871. // Due crazy portindex
  872. function sp_SnmpParseFdbRa($portTable) {
  873. $portData = array();
  874. $arr_PortTable = explodeRows($portTable);
  875. if (!empty($arr_PortTable)) {
  876. foreach ($arr_PortTable as $eachEntry) {
  877. if (!empty($eachEntry)) {
  878. $eachEntry = str_replace('.1.3.6.1.2.1.17.7.1.2.2.1.2', '', $eachEntry);
  879. $cleanMac = '';
  880. $rawMac = explode('=', $eachEntry);
  881. $parts = explode('.', trim($rawMac[0], '.'));
  882. $port = vf($rawMac[1], 3);
  883. $port = $port - 2082476032;
  884. unset($parts[0]);
  885. // Some devices show CPU interface as port 0
  886. if (count($parts) == 6 and intval($port) != 0) {
  887. $cleanMac = sp_PartsToMac($parts);
  888. $portData[strtolower($cleanMac)] = $port;
  889. }
  890. }
  891. }
  892. }
  893. return ($portData);
  894. }
  895. /**
  896. * Parsing of FDB port table SNMP raw data from Cisco 3xx
  897. *
  898. * @param $portTable raw SNMP data
  899. *
  900. * @return array
  901. */
  902. function sp_SnmpParseFdbCisEb($portTable) {
  903. $portData = array();
  904. $arr_PortTable = explodeRows($portTable);
  905. if (!empty($arr_PortTable)) {
  906. foreach ($arr_PortTable as $eachEntry) {
  907. if (!empty($eachEntry)) {
  908. $eachEntry = str_replace('.1.3.6.1.2.1.17.4.3.1.2', '', $eachEntry);
  909. $cleanMac = '';
  910. $rawMac = explode('=', $eachEntry);
  911. $parts = explode('.', trim($rawMac[0], '.'));
  912. if (count($parts) == 6) {
  913. $cleanMac = sp_PartsToMac($parts);
  914. $port = ubRouting::filters($rawMac[1], 'int');
  915. //A-A-A!!!!111
  916. $portReplaceTable = array(
  917. 1 => 49,
  918. 2 => 50,
  919. 27 => 51,
  920. 28 => 52,
  921. );
  922. //combo ports offset
  923. if (isset($portReplaceTable[$port])) {
  924. $port = $portReplaceTable[$port];
  925. } else {
  926. if ($port < 27) {
  927. $port = $port - 2;
  928. }
  929. if ($port > 28) {
  930. $port = $port - 4;
  931. }
  932. }
  933. $portData[$cleanMac] = $port;
  934. }
  935. }
  936. }
  937. }
  938. return ($portData);
  939. }
  940. /**
  941. * Parsing of FDB port table SNMP raw data for some exotic Dlink switches
  942. *
  943. * @param $portTable raw SNMP data
  944. *
  945. * @return array
  946. */
  947. function sp_SnmpParseFdbDl($portTable) {
  948. $portData = array();
  949. $arr_PortTable = explodeRows($portTable);
  950. if (!empty($arr_PortTable)) {
  951. foreach ($arr_PortTable as $eachEntry) {
  952. if (!empty($eachEntry)) {
  953. $eachEntry = str_replace('.1.3.6.1.2.1.17.7.1.2.2.1.2', '', $eachEntry);
  954. $cleanMac = '';
  955. $rawMac = explode('=', $eachEntry);
  956. $parts = explode('.', trim($rawMac[0], '.'));
  957. $port = vf($rawMac[1], 3);
  958. unset($parts[0]);
  959. // Some devices show CPU interface as port 0
  960. if (count($parts) == 6 and intval($port) != 0) {
  961. $cleanMac = sp_PartsToMac($parts);
  962. $portData[$cleanMac] = $port;
  963. }
  964. }
  965. }
  966. }
  967. return ($portData);
  968. }
  969. /**
  970. * Parsing of FDB port table SNMP raw data for some exotic Tplink switches
  971. *
  972. * @param $portTable raw SNMP data
  973. *
  974. * @return array
  975. */
  976. function sp_SnmpParseFdbTlp($portTable, $oid) {
  977. $portData = array();
  978. $arr_PortTable = explodeRows($portTable);
  979. if (!empty($arr_PortTable)) {
  980. foreach ($arr_PortTable as $eachEntry) {
  981. if (!empty($eachEntry)) {
  982. $eachEntry = str_replace($oid, '', $eachEntry);
  983. $cleanMac = '';
  984. $rawMac = explode('=', $eachEntry);
  985. $rawMac[0] = substr($rawMac[0], 0, -2); //drop last 01 octet
  986. $rawMac[0] = '.1' . $rawMac[0]; // add .1 part. fuck this shit
  987. $parts = explode('.', trim($rawMac[0], '.'));
  988. unset($parts[0]);
  989. if (count($parts) == 6) {
  990. $cleanMac = sp_PartsToMac($parts);
  991. $portData[$cleanMac] = vf($rawMac[1], 3);
  992. }
  993. }
  994. }
  995. }
  996. return ($portData);
  997. }
  998. /**
  999. * Parsing of FDB port table SNMP raw data for some strange foxgate switches
  1000. *
  1001. * @param $portTable raw SNMP data
  1002. *
  1003. * @return array
  1004. */
  1005. function sp_SnmpParseFdbFlp($portTable, $oid) {
  1006. $portData = array();
  1007. $arr_PortTable = explodeRows($portTable);
  1008. if (!empty($arr_PortTable)) {
  1009. foreach ($arr_PortTable as $eachEntry) {
  1010. if (!empty($eachEntry)) {
  1011. $eachEntry = str_replace($oid, '', $eachEntry);
  1012. $cleanMac = '';
  1013. $rawMac = explode('=', $eachEntry);
  1014. $parts = explode('.', trim($rawMac[0], '.'));
  1015. unset($parts[0]);
  1016. if (count($parts) == 6) {
  1017. $cleanMac = call_user_func_array('sprintf', $parts);
  1018. $portData[$cleanMac] = vf($rawMac[1], 3);
  1019. }
  1020. }
  1021. }
  1022. }
  1023. return ($portData);
  1024. }
  1025. /**
  1026. * Parsing of FDB port and VLAN tables from SNMP raw data for cumulative FDB mode
  1027. *
  1028. * @param string $portTable
  1029. * @param string $statusTable
  1030. * @param string $portOID
  1031. * @param string $statusOID
  1032. * @param bool $dot1Q
  1033. *
  1034. * @return array
  1035. */
  1036. function sp_SnmpParseFdbCumulative($portTable, $statusTable, $portOID, $statusOID, $dot1Q = false) {
  1037. $portData = array();
  1038. $statusData = array();
  1039. $arr_PortTable = explodeRows($portTable);
  1040. $arr_StatusTale = explodeRows($statusTable);
  1041. if (!empty($arr_StatusTale)) {
  1042. foreach ($arr_StatusTale as $eachEntry) {
  1043. $tmpStatusArr = trimSNMPOutput($eachEntry, $statusOID);
  1044. // $tmpStatusArr[0] - DEC raw MAC or VLAN.DEC raw MAC in dot1Q mode
  1045. // $tmpStatusArr[1] - MAC status: 1 - other, 2 - invalid, 3 - learned, 4 - self, 5 - mgmt
  1046. if (!empty($tmpStatusArr[0])) {
  1047. $statusData[$tmpStatusArr[0]] = $tmpStatusArr[1];
  1048. }
  1049. }
  1050. }
  1051. if (!empty($arr_PortTable)) {
  1052. foreach ($arr_PortTable as $eachEntry) {
  1053. if (!empty($eachEntry)) {
  1054. $tmpArr = trimSNMPOutput($eachEntry, $portOID);
  1055. // $tmpArr[0] - DEC raw MAC or VLAN.DEC raw MAC in dot1Q mode
  1056. // $tmpArr[1] - src port idx
  1057. if (!empty($tmpArr[0])) {
  1058. // trying to exclude and skip MAC addresses with "self" status, as they are native for the device
  1059. if (!empty($statusData[$tmpArr[0]]) and $statusData[$tmpArr[0]] == 4) {
  1060. continue;
  1061. }
  1062. if ($dot1Q) {
  1063. // extracting VLAN portion from OID
  1064. $vlanNum = substr($tmpArr[0], 0, stripos($tmpArr[0], '.'));
  1065. $rawMAC = substr($tmpArr[0], strlen($vlanNum) + 1);
  1066. } else {
  1067. $rawMAC = $tmpArr[0];
  1068. }
  1069. $cleanMAC = convertMACDec2Hex($rawMAC);
  1070. if (!empty($cleanMAC)) {
  1071. if ($dot1Q) {
  1072. $portData[strtolower($cleanMAC)][] = array('port' => vf($tmpArr[1], 3), 'vlan' => vf($vlanNum, 3));
  1073. } else {
  1074. $portData[strtolower($cleanMAC)] = vf($tmpArr[1], 3);
  1075. }
  1076. }
  1077. }
  1078. }
  1079. }
  1080. }
  1081. return ($portData);
  1082. }
  1083. /**
  1084. * Poll/Show data for some device
  1085. *
  1086. * @global object $ubillingConfig
  1087. * @param string $ip
  1088. * @param string $community
  1089. * @param array $alltemplates
  1090. * @param string $deviceTemplate
  1091. * @param array $allusermacs
  1092. * @param array $alladdress
  1093. * @param string $communitywrite
  1094. * @param bool $quiet
  1095. * @param array $allswitchmacs
  1096. *
  1097. * @return void
  1098. */
  1099. function sp_SnmpPollDevice($ip, $community, $alltemplates, $deviceTemplate, $allusermacs, $alladdress, $communitywrite = '', $quiet = false, $allswitchmacs = array()) {
  1100. global $ubillingConfig;
  1101. $devPollProcess = new StarDust('SWPOLL_' . $ip);
  1102. $pollingStart = time();
  1103. if ($devPollProcess->notRunning()) {
  1104. $devPollProcess->start();
  1105. if (isset($alltemplates[$deviceTemplate])) {
  1106. $currentTemplate = $alltemplates[$deviceTemplate];
  1107. if (!empty($currentTemplate)) {
  1108. $deviceDescription = $currentTemplate['define']['DEVICE'];
  1109. $deviceFdb = (isset($currentTemplate['define']['FDB'])) ? $currentTemplate['define']['FDB'] : 'false';
  1110. $deviceMAC = (isset($currentTemplate['define']['MAC'])) ? $currentTemplate['define']['MAC'] : 'false';
  1111. $pollMode = (isset($currentTemplate['define']['POLLMODE'])) ? $currentTemplate['define']['POLLMODE'] : '';
  1112. $sfpStartPort = (empty($currentTemplate['define']['SFPSTARTPORT'])) ? 1 : $currentTemplate['define']['SFPSTARTPORT'];
  1113. $sfpEndPort = (empty($currentTemplate['define']['SFPENDPORT'])) ? '' : $currentTemplate['define']['SFPENDPORT'];
  1114. $poeStartPort = (empty($currentTemplate['define']['POESTARTPORT'])) ? 1 : $currentTemplate['define']['POESTARTPORT'];
  1115. $poeEndPort = (empty($currentTemplate['define']['POEENDPORT'])) ? '' : $currentTemplate['define']['POEENDPORT'];
  1116. $sectionResult = '';
  1117. $sectionName = '';
  1118. $finalResult = '';
  1119. $tempArray = array();
  1120. $portIdxArr = array();
  1121. $portDescrArr = array();
  1122. $alterCfg = $ubillingConfig->getAlter();
  1123. $snmp = new SNMPHelper();
  1124. //selecting FDB processing mode
  1125. if (isset($currentTemplate['define']['FDB_MODE'])) {
  1126. $deviceFdbMode = $currentTemplate['define']['FDB_MODE'];
  1127. } else {
  1128. $deviceFdbMode = 'default';
  1129. }
  1130. //selecting Device MAC processing mode
  1131. if (isset($currentTemplate['define']['MAC_MODE'])) {
  1132. $deviceMACMode = $currentTemplate['define']['MAC_MODE'];
  1133. } else {
  1134. $deviceMACMode = 'default';
  1135. }
  1136. // selecting FDB allowed only port to process MAC-s only on them
  1137. // "ignored port" list is ignored if "allowed only" list used
  1138. if (!empty($currentTemplate['define']['FDB_ALLOW_ONLY_PORTS'])) {
  1139. $deviceFdbAllowedPorts = $currentTemplate['define']['FDB_ALLOW_ONLY_PORTS'];
  1140. $deviceFdbAllowedPorts = explode(',', $deviceFdbAllowedPorts);
  1141. $deviceFdbAllowedPorts = array_flip($deviceFdbAllowedPorts);
  1142. } else {
  1143. $deviceFdbAllowedPorts = array();
  1144. }
  1145. //selecting FDB ignored port for skipping MAC-s on it
  1146. if (isset($currentTemplate['define']['FDB_IGNORE_PORTS'])) {
  1147. $deviceFdbIgnore = $currentTemplate['define']['FDB_IGNORE_PORTS'];
  1148. $deviceFdbIgnore = explode(',', $deviceFdbIgnore);
  1149. $deviceFdbIgnore = array_flip($deviceFdbIgnore);
  1150. } else {
  1151. $deviceFdbIgnore = array();
  1152. }
  1153. // cumulative mode iface processing
  1154. if ($pollMode == 'cumulative' and ! empty($currentTemplate['portiface'])) {
  1155. $portIdxOID = trim($currentTemplate['portiface']['PORTINDEX']);
  1156. $portDescrOID = trim($currentTemplate['portiface']['PORTDESCR']);
  1157. $portAliasOID = trim($currentTemplate['portiface']['PORTALIAS']);
  1158. // get ports indexes
  1159. $rawDataPrtIdx = $snmp->walk($ip, $community, $portIdxOID, true);
  1160. $portIdxArr = sp_parse_sw_port_idx($rawDataPrtIdx, $portIdxOID);
  1161. // get ports aliases and ports descrs: if empty alias - we will use descr
  1162. $rawDataPrtDescr = $snmp->walk($ip, $community, $portDescrOID, true);
  1163. $rawDataPrtAlias = $snmp->walk($ip, $community, $portAliasOID, true);
  1164. // storing iface indexes with descriptions
  1165. if (!empty($rawDataPrtDescr)) {
  1166. $rawDataPrtDescr = explodeRows($rawDataPrtDescr);
  1167. foreach ($rawDataPrtDescr as $eachRow) {
  1168. $tmpArr = trimSNMPOutput($eachRow, $portDescrOID . '.');
  1169. // $tmpArr[0] - iface/port index
  1170. // $tmpArr[1] - iface/port descr
  1171. if (!empty($tmpArr[1])) {
  1172. $portDescrArr[$tmpArr[0]] = $tmpArr[1];
  1173. }
  1174. }
  1175. }
  1176. // storing iface indexes with aliases
  1177. // and trying to populate $portDescrArr
  1178. // but only if we didn't populate it in the descr section above
  1179. if (!empty($rawDataPrtAlias)) {
  1180. $rawDataPrtAlias = explodeRows($rawDataPrtAlias);
  1181. foreach ($rawDataPrtAlias as $eachRow) {
  1182. $tmpAliasArr = trimSNMPOutput($eachRow, $portAliasOID . '.');
  1183. // $tmpAliasArr[0] - iface/port index
  1184. // $tmpAliasArr[1] - iface/port alias
  1185. if (!empty($tmpAliasArr[0]) and ( !isset($portDescrArr[$tmpAliasArr[0]]) or empty($portDescrArr[$tmpAliasArr[0]]))) {
  1186. // if nothing was found in port description section for current port index
  1187. if (!empty($tmpAliasArr[1])) {
  1188. $portDescrArr[$tmpAliasArr[0]] = $tmpAliasArr[1];
  1189. } elseif (!empty($tmpAliasArr[0])) {
  1190. // just populate descr index with empty value
  1191. $portDescrArr[$tmpAliasArr[0]] = '';
  1192. }
  1193. }
  1194. }
  1195. }
  1196. if (!empty($portDescrArr)) {
  1197. $fdbPortDescrCache = serialize($portDescrArr);
  1198. file_put_contents('exports/' . $ip . '_fdb_portdescr', $fdbPortDescrCache);
  1199. }
  1200. }
  1201. //parse each section of template
  1202. foreach ($alltemplates[$deviceTemplate] as $section => $eachpoll) {
  1203. if ($section != 'define' and $section != 'portiface') {
  1204. if (!$quiet) {
  1205. $finalResult .= wf_tag('div', false, 'dashboard', '');
  1206. }
  1207. @$sectionName = $eachpoll['NAME'];
  1208. $sectionPollMode = (empty($eachpoll['SECTPOLLMODE'])) ? '' : $eachpoll['SECTPOLLMODE'];
  1209. if ($pollMode == 'cumulative') {
  1210. @$sectionOids = array($eachpoll['OIDS']);
  1211. } else {
  1212. @$sectionOids = explode(',', $eachpoll['OIDS']);
  1213. }
  1214. if (isset($eachpoll['SETOIDS'])) {
  1215. $sectionSetOids = explode(',', $eachpoll['SETOIDS']);
  1216. } else {
  1217. $sectionSetOids = array();
  1218. }
  1219. $sectionDivBy = (empty($eachpoll['DIV'])) ? ', ""' : ', "' . $eachpoll['DIV'] . '"';
  1220. $sectionUnits = (empty($eachpoll['UNITS'])) ? ', ""' : ', "' . $eachpoll['UNITS'] . '"';
  1221. @$sectionParser = $eachpoll['PARSER'];
  1222. $sectionResult = '';
  1223. //yeah, lets set some oids to this shit
  1224. if (!empty($sectionSetOids)) {
  1225. foreach ($sectionSetOids as $eachSetOid) {
  1226. $eachSetOidRaw = trim($eachSetOid);
  1227. $eachSetOidRaw = explode('|', $eachSetOidRaw);
  1228. //all three parts of set squense present
  1229. if ((isset($eachSetOidRaw[0])) and ( isset($eachSetOidRaw[1])) and ( isset($eachSetOidRaw[2]))) {
  1230. $setDataTmp[0] = array('oid' => $eachSetOidRaw[0], 'type' => $eachSetOidRaw[1], 'value' => $eachSetOidRaw[2]);
  1231. if (!empty($communitywrite)) {
  1232. $runSet = $snmp->set($ip, $communitywrite, $setDataTmp);
  1233. }
  1234. }
  1235. }
  1236. }
  1237. if ($section == 'portdesc' and $pollMode == 'cumulative' and ! empty($portDescrArr)) {
  1238. $sectionResult = sp_parse_sw_port_descr($portDescrArr);
  1239. } else {
  1240. //now parse each oid
  1241. if (!empty($sectionOids)) {
  1242. // in cumulative mode we are not aware of ports amount
  1243. // so, need to fulfill each section OID with port number
  1244. // and populate $sectionOids array with OID for each port, like in conservative mode
  1245. if ($pollMode == 'cumulative' and $sectionPollMode != 'noncumulative' and ! empty($portIdxArr)) {
  1246. $tmpOID = $sectionOids[0];
  1247. $sectionOids = array();
  1248. $isSFPSection = ispos($section, 'sfp');
  1249. $sfpEndPort = ($isSFPSection and empty($sfpEndPort)) ? $portIdxArr[count($portIdxArr)] : $sfpEndPort;
  1250. $isPOESection = ispos($section, 'poe');
  1251. $poeEndPort = ($isPOESection and empty($poeEndPort)) ? $portIdxArr[count($portIdxArr)] : $poeEndPort;
  1252. foreach ($portIdxArr as $eachPort) {
  1253. if (empty($eachPort)) {
  1254. continue;
  1255. }
  1256. if ($isSFPSection and ( $eachPort < $sfpStartPort or $eachPort > $sfpEndPort)) {
  1257. continue;
  1258. }
  1259. if ($isPOESection and ( $eachPort < $poeStartPort or $eachPort > $poeEndPort)) {
  1260. continue;
  1261. }
  1262. $sectionOids[] = $tmpOID . '.' . $eachPort;
  1263. }
  1264. }
  1265. if ($section == 'cablediag') {
  1266. if (!empty($sectionParser)) {
  1267. $sectionResult .= $sectionParser($ip, $community, $currentTemplate['cablediag']);
  1268. } else {
  1269. $sectionResult = '';
  1270. }
  1271. } else {
  1272. foreach ($sectionOids as $eachOid) {
  1273. $eachOid = trim($eachOid);
  1274. $rawData = $snmp->walk($ip, $community, $eachOid, true);
  1275. $rawData = str_replace('"', '`', $rawData);
  1276. if (!empty($sectionParser)) {
  1277. if (function_exists($sectionParser)) {
  1278. if (empty($sectionDivBy) and empty($sectionUnits)) {
  1279. $parseCode = '$sectionResult.=' . $sectionParser . '("' . $rawData . '");';
  1280. } else {
  1281. $parseCode = '$sectionResult.=' . $sectionParser . '("' . $rawData . '"' . $sectionDivBy . $sectionUnits . ');';
  1282. }
  1283. // actual parser processing
  1284. eval($parseCode);
  1285. } else {
  1286. $sectionResult = __('Parser') . ' "' . $sectionParser . '" ' . __('Not exists');
  1287. }
  1288. } else {
  1289. $sectionResult = '';
  1290. }
  1291. }
  1292. }
  1293. }
  1294. }
  1295. if (!$quiet) {
  1296. if (!empty($sectionResult)) {
  1297. $finalResult .= wf_tag('div', false, 'dashtask', '') . wf_tag('strong') . __($sectionName) . wf_tag('strong', true) . '<br>';
  1298. $finalResult .= $sectionResult . wf_tag('div', true);
  1299. }
  1300. }
  1301. }
  1302. }
  1303. $finalResult .= wf_tag('div', true);
  1304. $finalResult .= wf_tag('div', false, '', 'style="clear:both;"');
  1305. $finalResult .= wf_tag('div', true);
  1306. if (!$quiet) {
  1307. show_window('', $finalResult);
  1308. }
  1309. //
  1310. //parsing data from FDB table
  1311. //
  1312. if ($deviceFdb == 'true') {
  1313. $portData = array();
  1314. $vlanData = array();
  1315. $portTable = '';
  1316. $statusTable = '';
  1317. $portTabOID = '';
  1318. $portTabOIDVal = '';
  1319. $statusOID = '';
  1320. $statusOIDVal = '';
  1321. $dot1Q = false;
  1322. $snmp->setBackground(false); // need to process data with system + background
  1323. if ($deviceFdbMode == 'default') {
  1324. //default zyxel & cisco port table
  1325. $portTable = $snmp->walk($ip, $community, '.1.3.6.1.2.1.17.4.3.1.2', true);
  1326. } elseif ($deviceFdbMode == 'sw_cumulative') {
  1327. if (!empty($currentTemplate['port.1d_fdb'])) {
  1328. $portTabOID = trim($currentTemplate['port.1d_fdb']['PORTTABLE']);
  1329. $statusOID = trim($currentTemplate['port.1d_fdb']['PORTSTATUS']);
  1330. $portTable = $snmp->walk($ip, $community, $portTabOID, true);
  1331. $statusTable = $snmp->walk($ip, $community, $statusOID, true);
  1332. }
  1333. if (!empty($currentTemplate['port.1q_fdb'])) {
  1334. $portQTabOID = trim($currentTemplate['port.1q_fdb']['PORTTABLE']);
  1335. $statusQOID = trim($currentTemplate['port.1q_fdb']['PORTSTATUS']);
  1336. $portQTable = $snmp->walk($ip, $community, $portQTabOID, true);
  1337. $statusQTable = $snmp->walk($ip, $community, $statusQOID, true);
  1338. }
  1339. // if dot1Q table is not empty - we prefer it's data
  1340. // as it's usually more detailed and contains VLAN data
  1341. if (!empty($portQTable) and ! empty($statusQTable)
  1342. and ! ispos($portQTable, 'No Such Object available')
  1343. and ! ispos($statusQTable, 'No Such Object available')
  1344. and ! ispos($portQTable, 'No more variables left')
  1345. and ! ispos($statusQTable, 'No more variables left')) {
  1346. $dot1Q = true;
  1347. $portTabOID = $portQTabOID;
  1348. $statusOID = $statusQOID;
  1349. $portTable = $portQTable;
  1350. $statusTable = $statusQTable;
  1351. }
  1352. } else {
  1353. if (($deviceFdbMode == 'dlp') OR ( $deviceFdbMode == 'ra')) {
  1354. //custom dlink port table with VLANS
  1355. $portTable = $snmp->walk($ip, $community, '.1.3.6.1.2.1.17.7.1.2.2.1.2', true);
  1356. }
  1357. if ($deviceFdbMode == 'tlp5428ev2') {
  1358. $tlpOid = '.1.3.6.1.4.1.11863.1.1.1.2.3.2.2.1.3';
  1359. $portTable = $snmp->walk($ip, $community, $tlpOid, true);
  1360. }
  1361. if ($deviceFdbMode == 'tlp2428') {
  1362. $tlpOid = '.1.3.6.1.4.1.11863.1.1.11.2.3.2.2.1.3';
  1363. $portTable = $snmp->walk($ip, $community, $tlpOid, true);
  1364. }
  1365. if ($deviceFdbMode == 'tlp2210') {
  1366. $tlpOid = '.1.3.6.1.4.1.11863.1.1.19.2.3.2.2.1.3';
  1367. $portTable = $snmp->walk($ip, $community, $tlpOid, true);
  1368. }
  1369. //foxgate lazy parsing
  1370. if ($deviceFdbMode == 'flp') {
  1371. $flpOid = '.1.3.6.1.2.1.17.7.1.2.3.1.2';
  1372. $portTable = $snmp->walk($ip, $community, $flpOid, true);
  1373. }
  1374. //cisco ebobo parser
  1375. if ($deviceFdbMode == 'ciscoebobo') {
  1376. $portTable = $snmp->walk($ip, $community, '.1.3.6.1.2.1.17.4.3.1.2', true);
  1377. }
  1378. }
  1379. if (!empty($portTable)) {
  1380. if ($deviceFdbMode == 'default') {
  1381. //default FDB parser
  1382. $portData = sp_SnmpParseFDB($portTable);
  1383. } elseif ($deviceFdbMode == 'sw_cumulative') {
  1384. $portData = sp_SnmpParseFdbCumulative($portTable, $statusTable, $portTabOID, $statusOID, $dot1Q);
  1385. if ($dot1Q and ! empty($portData)) {
  1386. // saving array to temp var for further processing
  1387. $tmpPortData = $portData;
  1388. $portData = array();
  1389. // separating port and vlan data to different arrays
  1390. foreach ($tmpPortData as $eachMAC => $eachData) {
  1391. if (!empty($eachData)) {
  1392. foreach ($eachData as $each) {
  1393. // making array keys like "MAC_VLAN" to provide their uniqueness
  1394. $portData[$eachMAC . '_' . $each['vlan']] = $each['port'];
  1395. $vlanData[$eachMAC . '_' . $each['vlan']] = $each['vlan'];
  1396. }
  1397. }
  1398. }
  1399. }
  1400. } else {
  1401. if ($deviceFdbMode == 'dlp') {
  1402. //exotic dlink parser
  1403. $portData = sp_SnmpParseFdbDl($portTable);
  1404. }
  1405. if ($deviceFdbMode == 'ra') {
  1406. //exotic Raisecom parser
  1407. $portData = sp_SnmpParseFdbRa($portTable);
  1408. }
  1409. if (($deviceFdbMode == 'tlp5428ev2') OR ( $deviceFdbMode == 'tlp2428') OR ( $deviceFdbMode == 'tlp2210')) {
  1410. //more exotic tplink parser
  1411. $portData = sp_SnmpParseFdbTlp($portTable, $tlpOid);
  1412. }
  1413. //foxgate - its you again? Oo
  1414. if ($deviceFdbMode == 'flp') {
  1415. $portData = sp_SnmpParseFdbFlp($portTable, $flpOid);
  1416. }
  1417. //cisco 3xx series giga-port fucking issue
  1418. if ($deviceFdbMode == 'ciscoebobo') {
  1419. $portData = sp_SnmpParseFdbCisEb($portTable, '.1.3.6.1.2.1.17.4.3.1.2');
  1420. }
  1421. }
  1422. // processing FDB allowed only ports for cumulative mode
  1423. // and make an exclusion of allowed ports and ignored ports
  1424. // to leave only ports which are allowed
  1425. // thus, if port is in allowed list and in ignored list at the same time - it will not be ignored
  1426. if (!empty($deviceFdbAllowedPorts)) {
  1427. if (!empty($portData)) {
  1428. foreach ($portData as $some_mac => $some_port) {
  1429. if (isset($deviceFdbAllowedPorts[$some_port])) {
  1430. $tempArray[$some_mac] = $some_port;
  1431. }
  1432. }
  1433. $portData = $tempArray;
  1434. }
  1435. } elseif (!empty($deviceFdbIgnore)) {
  1436. //skipping some port data if FDB_IGNORE_PORTS option is set
  1437. if (!empty($portData)) {
  1438. foreach ($portData as $some_mac => $some_port) {
  1439. if (!isset($deviceFdbIgnore[$some_port])) {
  1440. $tempArray[$some_mac] = $some_port;
  1441. }
  1442. }
  1443. $portData = $tempArray;
  1444. }
  1445. }
  1446. $fdbCache = serialize($portData);
  1447. @file_put_contents('exports/' . $ip . '_fdb', $fdbCache);
  1448. if (!empty($vlanData)) {
  1449. $fdbVLANCache = serialize($vlanData);
  1450. file_put_contents('exports/' . $ip . '_fdb_vlan', $fdbVLANCache);
  1451. }
  1452. }
  1453. //show port data User friendly :)
  1454. if (!empty($portData)) {
  1455. $fdbExtenInfo = $ubillingConfig->getAlterParam('SW_FDB_EXTEN_INFO');
  1456. //extracting all needed data for switchport control
  1457. if ($alterCfg['SWITCHPORT_IN_PROFILE']) {
  1458. $allswitchesArray = zb_SwitchesGetAll();
  1459. $allportassigndata = array();
  1460. $allportassigndata_q = "SELECT * from `switchportassign`;";
  1461. $allportassigndata_raw = simple_queryall($allportassigndata_q);
  1462. if (!empty($allportassigndata_raw)) {
  1463. foreach ($allportassigndata_raw as $iopd => $eachpad) {
  1464. $allportassigndata[$eachpad['login']] = $eachpad;
  1465. }
  1466. }
  1467. }
  1468. $allusermacs = array_flip($allusermacs);
  1469. $recordsCounter = 0;
  1470. $cells = wf_TableCell(__('User') . ' / ' . __('Device'), '30%');
  1471. $cells .= wf_TableCell(__('MAC'));
  1472. $cells .= wf_TableCell(__('Ports'));
  1473. if ($fdbExtenInfo) {
  1474. $cells .= wf_TableCell(__('Port description'));
  1475. $cells .= wf_TableCell(__('VLAN'));
  1476. }
  1477. $rows = wf_TableRow($cells, 'row1');
  1478. foreach ($portData as $eachMac => $eachPort) {
  1479. // if we have MACs stored along with VLANs - we need to extract MAC portion
  1480. $eachMAC_VLAN = '';
  1481. if (ispos($eachMac, '_')) {
  1482. $eachMAC_VLAN = $eachMac;
  1483. $eachMac = substr($eachMac, 0, stripos($eachMac, '_'));
  1484. }
  1485. //user detection
  1486. if (isset($allusermacs[$eachMac])) {
  1487. $userLogin = $allusermacs[$eachMac];
  1488. @$useraddress = $alladdress[$userLogin];
  1489. $userlink = wf_Link('?module=userprofile&username=' . $userLogin, web_profile_icon() . ' ' . $useraddress, false);
  1490. //switch port assing form
  1491. if ($alterCfg['SWITCHPORT_IN_PROFILE']) {
  1492. $assignForm = wf_modal(web_edit_icon(__('Switch port assign')), __('Switch port assign'), web_SnmpSwitchControlForm($userLogin, $allswitchesArray, $allportassigndata, @$_GET['switchid'], $eachPort), '', '500', '250');
  1493. if (isset($allportassigndata[$userLogin])) {
  1494. $assignForm .= wf_img('skins/arrow_right_green.png') . @$allportassigndata[$userLogin]['port'];
  1495. }
  1496. } else {
  1497. $assignForm = '';
  1498. }
  1499. } else {
  1500. if (isset($allswitchmacs[$eachMac])) {
  1501. @$switchAddress = $allswitchmacs[$eachMac]['location'];
  1502. @$switchId = $allswitchmacs[$eachMac]['id'];
  1503. @$switchIp = $allswitchmacs[$eachMac]['ip'];
  1504. $switchLabel = (!empty($switchAddress)) ? $switchAddress : $switchIp;
  1505. $userlink = wf_Link('?module=switches&edit=' . $switchId, wf_img_sized('skins/menuicons/switches.png', __('Switch'), 11, 13) . ' ' . $switchLabel);
  1506. $assignForm = '';
  1507. } else {
  1508. $userlink = '';
  1509. $assignForm = '';
  1510. }
  1511. }
  1512. $cells = wf_TableCell($userlink . $assignForm, '', '', 'sorttable_customkey="' . $eachPort . '"');
  1513. $cells .= wf_TableCell($eachMac);
  1514. $cells .= wf_TableCell($eachPort);
  1515. if ($fdbExtenInfo) {
  1516. $eachPortDescr = '';
  1517. $eachVLAN = '';
  1518. if (!empty($portDescrArr[$eachPort])) {
  1519. $eachPortDescr = $portDescrArr[$eachPort];
  1520. }
  1521. if (!empty($vlanData[$eachMAC_VLAN])) {
  1522. $eachVLAN = $vlanData[$eachMAC_VLAN];
  1523. }
  1524. $cells .= wf_TableCell($eachPortDescr);
  1525. $cells .= wf_TableCell($eachVLAN);
  1526. }
  1527. $rows .= wf_TableRow($cells, 'row5');
  1528. $recordsCounter++;
  1529. }
  1530. if (!$quiet) {
  1531. $fdbTableResult = wf_TableBody($rows, '100%', '0', 'sortable');
  1532. $fdbTableResult .= wf_tag('b') . __('Total') . ': ' . $recordsCounter . wf_tag('b', true);
  1533. show_window(__('FDB'), $fdbTableResult);
  1534. }
  1535. }
  1536. }
  1537. //
  1538. //parsing data of DEVICE MAC
  1539. //
  1540. if ($alterCfg['SWITCHES_SNMP_MAC_EXORCISM'] and $deviceMAC == 'true') {
  1541. $MacOfDevice = '';
  1542. $snmp->setBackground(false); // need to process data with system + background
  1543. if ($deviceMACMode == 'default') {
  1544. //default for many D-link HP JunOS
  1545. $MacOfDevice = $snmp->walk($ip, $community, '.1.0.8802.1.1.2.1.3.2.0', true);
  1546. } else {
  1547. /* Need Tests
  1548. if ($deviceMACMode == 'dlp') {
  1549. //custom dlink mac
  1550. $tmpOid = '';
  1551. $MacOfDevice = $snmp->walk($ip, $community, $tmpOid, true);
  1552. }
  1553. if ($deviceMACMode == 'tlp5428ev2') {
  1554. $tmpOid = '';
  1555. $MacOfDevice = $snmp->walk($ip, $community, $tmpOid, true);
  1556. }
  1557. if ($deviceMACMode == 'tlp2428') {
  1558. $tmpOid = '';
  1559. $MacOfDevice = $snmp->walk($ip, $community, $tmpOid, true);
  1560. }
  1561. if ($deviceMACMode == 'tlp2210') {
  1562. $tmpOid = '';
  1563. $MacOfDevice = $snmp->walk($ip, $community, $tmpOid, true);
  1564. }
  1565. //foxgate lazy parsing
  1566. if ($deviceMACMode == 'flp') {
  1567. $tmpOid = '';
  1568. $MacOfDevice = $snmp->walk($ip, $community, $tmpOid, true);
  1569. }
  1570. */
  1571. }
  1572. if (!empty($MacOfDevice)) {
  1573. if ($deviceMACMode == 'default') {
  1574. //default M parser
  1575. $MACData = sn_SnmpParseDeviceMAC($MacOfDevice);
  1576. } else {
  1577. /* Need test
  1578. if ($deviceMACMode == 'dlp') {
  1579. //exotic dlink parser
  1580. $MACData = sn_SnmpParseDeviceMAC($MacOfDevice);
  1581. }
  1582. if (($deviceMACMode == 'tlp5428ev2') OR ( $deviceMACMode == 'tlp2428') OR ( $deviceMACMode == 'tlp2210')) {
  1583. //more exotic tplink parser
  1584. $MACData = sn_SnmpParseDeviceMAC($MacOfDevice, $tmpOid);
  1585. }
  1586. // foxgate - its you again? Oo
  1587. if ($deviceMACMode == 'flp') {
  1588. $MACData = sn_SnmpParseDeviceMAC($MacOfDevice, $tmpOid);
  1589. }
  1590. */
  1591. }
  1592. // Write Device MAC address to file
  1593. if (!empty($MACData)) {
  1594. file_put_contents('exports/' . $ip . '_MAC', $MACData);
  1595. }
  1596. }
  1597. }
  1598. }
  1599. }
  1600. }
  1601. //filling device polling stats
  1602. $devPollProcess->stop();
  1603. $pollingEnd = time();
  1604. $statsPath = 'exports/HORDE_' . $ip;
  1605. $cachedStats = array();
  1606. $cachedStats['start'] = $pollingStart;
  1607. $cachedStats['end'] = $pollingEnd;
  1608. $cachedStats = serialize($cachedStats);
  1609. @file_put_contents($statsPath, $cachedStats);
  1610. }
  1611. /**
  1612. * Check MAC address for filter
  1613. *
  1614. * @param string $mac
  1615. * @param array $allfilters
  1616. * @return bool
  1617. */
  1618. function sn_FDBFilterCheckMac($mac, $allfilters) {
  1619. $result = true;
  1620. if (!empty($allfilters)) {
  1621. if (isset($allfilters[$mac])) {
  1622. $result = true;
  1623. } else {
  1624. $result = false;
  1625. }
  1626. }
  1627. return ($result);
  1628. }
  1629. /**
  1630. * Renders JSON data for display FDB cache
  1631. *
  1632. * @global object $ubillingConfig
  1633. * @param array $fdbData_raw
  1634. * @param string $macFilter
  1635. *
  1636. * @return void
  1637. */
  1638. function sn_SnmpParseFdbCacheJson($fdbData_raw, $macFilter, $fdbVLANData_raw = array()) {
  1639. global $ubillingConfig;
  1640. $allusermacs = zb_UserGetAllMACs();
  1641. $allusermacs = array_flip($allusermacs);
  1642. $alladdress = zb_AddressGetFulladdresslist();
  1643. $allswitches = zb_SwitchesGetAll();
  1644. $rawFilters = zb_StorageGet('FDBCACHEMACFILTERS');
  1645. $filteredCounter = 0;
  1646. $switchdata = array();
  1647. $switchIds = array();
  1648. $allfilters = array();
  1649. $allswitchmacs = array();
  1650. $switchesExtFlag = $ubillingConfig->getAlterParam('SWITCHES_EXTENDED');
  1651. $fdbExtenInfo = $ubillingConfig->getAlterParam('SW_FDB_EXTEN_INFO');
  1652. $json = new wf_JqDtHelper();
  1653. //switch data preprocessing
  1654. if (!empty($allswitches)) {
  1655. foreach ($allswitches as $io => $eachswitch) {
  1656. $switchdata[$eachswitch['ip']] = $eachswitch['location'];
  1657. $switchIds[$eachswitch['ip']] = $eachswitch['id'];
  1658. if ($switchesExtFlag) {
  1659. $allswitchmacs[$eachswitch['swid']]['id'] = $eachswitch['id'];
  1660. $allswitchmacs[$eachswitch['swid']]['ip'] = $eachswitch['ip'];
  1661. $allswitchmacs[$eachswitch['swid']]['location'] = $eachswitch['location'];
  1662. }
  1663. }
  1664. }
  1665. //mac filters preprocessing
  1666. if (!empty($rawFilters)) {
  1667. $rawFilters = base64_decode($rawFilters);
  1668. $rawFilters = explodeRows($rawFilters);
  1669. if (!empty($rawFilters)) {
  1670. foreach ($rawFilters as $rawfindex => $rawfmac) {
  1671. $eachMacFilter = strtolower($rawfmac);
  1672. $allfilters[trim($eachMacFilter)] = $rawfindex;
  1673. }
  1674. }
  1675. }
  1676. //single mac filter processing
  1677. if (!empty($macFilter)) {
  1678. $allfilters[trim($macFilter)] = '42'; // The Ultimate Question of Life, the Universe, and Everything
  1679. }
  1680. foreach ($fdbData_raw as $each_raw) {
  1681. $nameExplode = explode('_', $each_raw);
  1682. if (sizeof($nameExplode) == 2) {
  1683. $switchIp = $nameExplode[0];
  1684. $switchId = (isset($switchIds[$switchIp])) ? $switchIds[$switchIp] : '';
  1685. $switchControls = '';
  1686. if (!empty($switchId)) {
  1687. if (cfr('SWITCHES')) {
  1688. $switchControls .= wf_Link('?module=switches&edit=' . $switchId, web_edit_icon());
  1689. }
  1690. }
  1691. if (file_exists('exports/' . $each_raw)) {
  1692. $eachfdb_raw = file_get_contents('exports/' . $each_raw);
  1693. $eachfdb = unserialize($eachfdb_raw);
  1694. if (!empty($eachfdb_raw)) {
  1695. $eachfdb_vlan = array();
  1696. $eachfdb_portdescr = array();
  1697. if ($fdbExtenInfo) {
  1698. if (file_exists('exports/' . $each_raw . '_vlan')) {
  1699. $eachfdb_vlan_raw = file_get_contents('exports/' . $each_raw . '_vlan');
  1700. $eachfdb_vlan = unserialize($eachfdb_vlan_raw);
  1701. }
  1702. if (file_exists('exports/' . $each_raw . '_portdescr')) {
  1703. $eachfdb_portdescr_raw = file_get_contents('exports/' . $each_raw . '_portdescr');
  1704. $eachfdb_portdescr = unserialize($eachfdb_portdescr_raw);
  1705. }
  1706. }
  1707. foreach ($eachfdb as $mac => $port) {
  1708. // if we have MACs stored along with VLANs (separated with underscore '_')
  1709. // - we need to extract MAC portion
  1710. $eachMAC_VLAN = '';
  1711. if (ispos($mac, '_')) {
  1712. // storing original value in "MAC_VLAN" representation
  1713. $eachMAC_VLAN = $mac;
  1714. // storing only extracted MAC portion
  1715. $mac = substr($mac, 0, stripos($mac, '_'));
  1716. }
  1717. //detecting user login by his mac
  1718. if (isset($allusermacs[$mac])) {
  1719. $userlogin = $allusermacs[$mac];
  1720. } else {
  1721. $userlogin = false;
  1722. }
  1723. if ($userlogin) {
  1724. $userlink = wf_Link('?module=userprofile&username=' . $userlogin, web_profile_icon() . ' ' . @$alladdress[$userlogin], $allfilters, false, '');
  1725. } else {
  1726. if (isset($allswitchmacs[$mac])) {
  1727. @$switchAddress = $allswitchmacs[$mac]['location'];
  1728. @$switchIdL = $allswitchmacs[$mac]['id'];
  1729. @$switchIpL = $allswitchmacs[$mac]['ip'];
  1730. $switchLabel = (!empty($switchAddress)) ? $switchAddress : $switchIpL;
  1731. $userlink = wf_Link('?module=switches&edit=' . $switchIdL, wf_img_sized('skins/menuicons/switches.png', __('Switch'), 11, 13) . ' ' . $switchLabel);
  1732. } else {
  1733. $userlink = '';
  1734. }
  1735. }
  1736. if (sn_FDBFilterCheckMac($mac, $allfilters)) {
  1737. $data[] = $switchIp;
  1738. $data[] = $port;
  1739. if ($fdbExtenInfo) {
  1740. $eachPortDescr = '';
  1741. $eachVLAN = '';
  1742. if (!empty($eachfdb_portdescr[$port])) {
  1743. $eachPortDescr = $eachfdb_portdescr[$port];
  1744. }
  1745. if (!empty($eachfdb_vlan[$eachMAC_VLAN])) {
  1746. $eachVLAN = $eachfdb_vlan[$eachMAC_VLAN];
  1747. }
  1748. $data[] = $eachPortDescr;
  1749. $data[] = $eachVLAN;
  1750. }
  1751. $data[] = @$switchdata[$switchIp] . ' ' . $switchControls;
  1752. $data[] = $mac;
  1753. $data[] = $userlink;
  1754. $json->addRow($data);
  1755. unset($data);
  1756. $filteredCounter++;
  1757. }
  1758. }
  1759. }
  1760. }
  1761. }
  1762. }
  1763. $json->getJson();
  1764. }
  1765. /**
  1766. * function that returns array data for existing FDB cache
  1767. *
  1768. * @param $fdbData_raw - array of existing cache _fdb files
  1769. *
  1770. * @return array
  1771. */
  1772. function sn_SnmpParseFdbCacheArray($fdbData_raw) {
  1773. $allswitches = zb_SwitchesGetAll();
  1774. $switchdata = array();
  1775. $result = array();
  1776. //switch data preprocessing
  1777. if (!empty($allswitches)) {
  1778. foreach ($allswitches as $io => $eachswitch) {
  1779. $switchdata[$eachswitch['ip']] = $eachswitch['location'];
  1780. }
  1781. }
  1782. foreach ($fdbData_raw as $each_raw) {
  1783. $nameExplode = explode('_', $each_raw);
  1784. if (sizeof($nameExplode) == 2) {
  1785. $switchIp = $nameExplode[0];
  1786. $eachfdb_raw = file_get_contents('exports/' . $each_raw);
  1787. $eachfdb = unserialize($eachfdb_raw);
  1788. if (!empty($eachfdb_raw)) {
  1789. foreach ($eachfdb as $mac => $port) {
  1790. if (@!empty($switchdata[$switchIp])) {
  1791. $switchDesc = $switchIp . ' - ' . @$switchdata[$switchIp];
  1792. } else {
  1793. $switchDesc = $switchIp;
  1794. }
  1795. $result[$mac][] = $switchDesc . ' ' . __('Port') . ': ' . $port;
  1796. }
  1797. }
  1798. }
  1799. }
  1800. return($result);
  1801. }
  1802. /**
  1803. * Extracts array data for some mac from sn_SnmpParseFdbCacheArray results
  1804. *
  1805. * @param array $data
  1806. *
  1807. * @return string
  1808. */
  1809. function sn_SnmpParseFdbExtract($data) {
  1810. $result = '';
  1811. $modalContent = '';
  1812. if (!empty($data)) {
  1813. if (sizeof($data) == 1) {
  1814. foreach ($data as $io => $each) {
  1815. $result .= $each;
  1816. }
  1817. } else {
  1818. foreach ($data as $io => $each) {
  1819. $modalContent .= $each . wf_tag('br');
  1820. }
  1821. $result .= $each . ' ' . wf_modal(wf_img_sized('skins/menuicons/switches.png', __('Switches'), '12', '12'), __('Switches'), $modalContent, '', '600', '400');
  1822. }
  1823. }
  1824. return ($result);
  1825. }
  1826. /**
  1827. * Extracts MAC of device
  1828. *
  1829. * @param raw data $data
  1830. *
  1831. * @return string
  1832. */
  1833. function sn_SnmpParseDeviceMAC($data) {
  1834. $result = '';
  1835. if (!empty($data)) {
  1836. $data = explode('=', $data);
  1837. $device_mac_raw = str_replace('Hex-STRING:', '', @$data[1]);
  1838. $device_mac_t = trim($device_mac_raw);
  1839. if (!empty($device_mac_t)) {
  1840. $device_mac = str_replace(" ", ":", $device_mac_t);
  1841. $result_temp = strtolower($device_mac);
  1842. if (check_mac_format($result_temp)) {
  1843. $result = $result_temp;
  1844. }
  1845. }
  1846. }
  1847. return ($result);
  1848. }
  1849. /**
  1850. * Cleans data types from raw SNMP request data. Returns only filtered value.
  1851. *
  1852. * @param string $data
  1853. *
  1854. * @return string
  1855. */
  1856. function zb_SanitizeSNMPValue($data) {
  1857. $result = '';
  1858. $dataTypes = array(
  1859. 'Counter32:',
  1860. 'Counter64:',
  1861. 'Gauge32:',
  1862. 'Gauge64:',
  1863. 'INTEGER:',
  1864. 'STRING:',
  1865. 'OID:',
  1866. 'Timeticks:',
  1867. 'Hex-STRING:',
  1868. 'Network Address:'
  1869. );
  1870. if (!empty($data)) {
  1871. $data = explode('=', $data);
  1872. if (isset($data[1])) {
  1873. $result = str_ireplace($dataTypes, '', $data[1]);
  1874. $result = trim($result);
  1875. }
  1876. }
  1877. return($result);
  1878. }
  1879. /**
  1880. * Standard parser for values with units and possible division necessity
  1881. * for data without ports info
  1882. *
  1883. * @param string $data
  1884. * @param int $divBy
  1885. * @param string $units min|max|yellow|red
  1886. *
  1887. * @return mixed|string
  1888. */
  1889. function sp_parse_division_temperature($data, $divBy = '', $units = '') {
  1890. $result = '';
  1891. if (!empty($data)
  1892. and ! ispos($data, 'No Such Object available')
  1893. and ! ispos($data, 'No more variables left')
  1894. ) {
  1895. $data = trimSNMPOutput($data, '');
  1896. $value = $data[1];
  1897. $value = ubRouting::filters($value, 'float');
  1898. if (!empty($divBy) and is_numeric($divBy)) {
  1899. $value = $value / $divBy;
  1900. }
  1901. $min = 5;
  1902. $max = 100;
  1903. $yellow = 30;
  1904. $red = 50;
  1905. if (!empty($units)) {
  1906. //mapped from units format: min|max|yellow|red
  1907. $chartOpts = explode('|', $units);
  1908. $min = $chartOpts[0];
  1909. $max = $chartOpts[1];
  1910. $yellow = $chartOpts[2];
  1911. $red = $chartOpts[3];
  1912. }
  1913. $options = 'max: ' . $max . ',
  1914. min: ' . $min . ',
  1915. width: 280, height: 280,
  1916. greenFrom: ' . ($min + 1) . ', greenTo: ' . $yellow . ',
  1917. yellowFrom:' . $yellow . ', yellowTo: ' . $red . ',
  1918. redFrom: ' . $red . ', redTo: ' . ($max - 1) . ',
  1919. minorTicks: 5';
  1920. $result = wf_renderTemperature($value, '', $options);
  1921. } else {
  1922. $cells = wf_TableCell(__('Empty reply received'));
  1923. $rows = wf_TableRow($cells, 'row3');
  1924. $result = wf_TableBody($rows, '100%', 0, '');
  1925. }
  1926. return ($result);
  1927. }
  1928. /**
  1929. * Returns FDB cache lister MAC filters setup form
  1930. *
  1931. * @param string $currentFilters
  1932. *
  1933. * @return string
  1934. */
  1935. function web_FDBTableFiltersForm($currentFilters) {
  1936. if (!empty($currentFilters)) {
  1937. $currentFilters = base64_decode($currentFilters);
  1938. }
  1939. $inputs = __('One MAC address per line') . wf_tag('br');
  1940. $inputs .= wf_TextArea('newmacfilters', '', $currentFilters, true, '40x10');
  1941. $inputs .= wf_HiddenInput('setmacfilters', 'true');
  1942. $inputs .= wf_CheckInput('deletemacfilters', __('Cleanup'), true, false);
  1943. $inputs .= wf_Submit(__('Save'));
  1944. $result = wf_Form('', 'POST', $inputs, 'glamour');
  1945. return ($result);
  1946. }
  1947. /**
  1948. * Renders swpoll logs control
  1949. *
  1950. * @global object $ubillingConfig
  1951. *
  1952. * @return string
  1953. */
  1954. function web_FDBTableLogControl() {
  1955. global $ubillingConfig;
  1956. $messages = new UbillingMessageHelper();
  1957. $result = '';
  1958. $logPath = 'exports/swpolldata.log';
  1959. $logData = array();
  1960. $renderData = '';
  1961. $rows = '';
  1962. $recordsLimit = 200;
  1963. $prevTime = '';
  1964. $curTimeTime = '';
  1965. $diffTime = '';
  1966. if (file_exists($logPath)) {
  1967. $billCfg = $ubillingConfig->getBilling();
  1968. $tailCmd = $billCfg['TAIL'];
  1969. $runCmd = $tailCmd . ' -n ' . $recordsLimit . ' ' . $logPath;
  1970. $rawResult = shell_exec($runCmd);
  1971. $renderData .= __('Showing') . ' ' . $recordsLimit . ' ' . __('last events') . wf_tag('br');
  1972. $renderData .= wf_Link('?module=switchpoller&dlswpolllog=true', wf_img('skins/icon_download.png', __('Download')) . ' ' . __('Download full log'), true);
  1973. if (!empty($rawResult)) {
  1974. $logData = explodeRows($rawResult);
  1975. if (!empty($logData)) {
  1976. $cells = wf_TableCell(__('Time') . ' (' . __('seconds') . ')');
  1977. $cells .= wf_TableCell(__('Date'));
  1978. $cells .= wf_TableCell(__('IP'));
  1979. $cells .= wf_TableCell(__('Event'));
  1980. $rows .= wf_TableRow($cells, 'row1');
  1981. // $logData = array_reverse($logData);
  1982. foreach ($logData as $io => $each) {
  1983. if (!empty($each)) {
  1984. if (!ispos($each, 'SWPOLLSTART')) {
  1985. $eachEntry = explode(' ', $each);
  1986. $curTime = $eachEntry[0] . ' ' . $eachEntry[1];
  1987. $curTime = strtotime($curTime);
  1988. if (!empty($prevTime)) {
  1989. $diffTime = $curTime - $prevTime;
  1990. } else {
  1991. $diffTime = 0;
  1992. }
  1993. $prevTime = $eachEntry[0] . ' ' . $eachEntry[1];
  1994. $prevTime = strtotime($prevTime);
  1995. $cells = wf_TableCell($diffTime);
  1996. $cells .= wf_TableCell($eachEntry[0] . ' ' . $eachEntry[1]);
  1997. $cells .= wf_TableCell($eachEntry[2]);
  1998. $cells .= wf_TableCell($eachEntry[3] . ' ' . @$eachEntry[4] . ' ' . @$eachEntry[5]);
  1999. $rows .= wf_TableRow($cells, 'row3');
  2000. } else {
  2001. $eachEntry = explode(' ', $each);
  2002. $prevTime = strtotime($eachEntry[0] . ' ' . $eachEntry[1]);
  2003. }
  2004. }
  2005. }
  2006. $renderData .= wf_TableBody($rows, '100%', 0, 'sortable');
  2007. }
  2008. } else {
  2009. $renderData .= $messages->getStyledMessage(__('Nothing found'), 'warning');
  2010. }
  2011. $result = wf_modal(wf_img('skins/log_icon_small.png', __('Swpoll log')), __('Swpoll log'), $renderData, '', '800', '600');
  2012. }
  2013. return ($result);
  2014. }
  2015. /**
  2016. * Performs downloading of switches polling logs
  2017. *
  2018. * @return void
  2019. */
  2020. function zb_FDBTableLogDownload() {
  2021. $logPath = 'exports/swpolldata.log';
  2022. if (file_exists($logPath)) {
  2023. zb_DownloadFile($logPath);
  2024. } else {
  2025. show_error(__('Something went wrong') . ': EX_FILE_NOT_FOUND ' . $logPath);
  2026. }
  2027. }
  2028. /**
  2029. * Renders horde stats control if horde enabled
  2030. *
  2031. * @return string
  2032. */
  2033. function web_HordeStatsControl() {
  2034. global $ubillingConfig;
  2035. $result = '';
  2036. if ($ubillingConfig->getAlterParam('HORDE_OF_SWITCHES')) {
  2037. $stats = '';
  2038. $hordePath = 'exports/';
  2039. $allHordeStats = rcms_scandir($hordePath, '*HORDE_*');
  2040. $totalCount = 0;
  2041. $totalTime = 0;
  2042. if (!empty($allHordeStats)) {
  2043. $cells = wf_TableCell(__('IP'));
  2044. $cells .= wf_TableCell(__('from'));
  2045. $cells .= wf_TableCell(__('to'));
  2046. $cells .= wf_TableCell(__('time'));
  2047. $rows = wf_TableRow($cells, 'row1');
  2048. foreach ($allHordeStats as $io => $eachStat) {
  2049. $devIp = zb_ExtractIpAddress($eachStat);
  2050. $statData = file_get_contents($hordePath . $eachStat);
  2051. if (!empty($statData)) {
  2052. $statData = unserialize($statData);
  2053. $pollTime = $statData['end'] - $statData['start'];
  2054. $cells = wf_TableCell($devIp);
  2055. $cells .= wf_TableCell(date("Y-m-d H:i:s", $statData['start']));
  2056. $cells .= wf_TableCell(date("Y-m-d H:i:s", $statData['end']));
  2057. $cells .= wf_TableCell(zb_formatTime($pollTime));
  2058. $rows .= wf_TableRow($cells, 'row5');
  2059. $totalCount++;
  2060. $totalTime += $pollTime;
  2061. }
  2062. }
  2063. $stats .= wf_TableBody($rows, '100%', 0, '');
  2064. $stats .= wf_tag('b') . __('Total') . ' ' . __('time') . ': ' . wf_tag('b', true) . zb_formatTime($totalTime) . wf_delimiter(0);
  2065. $stats .= wf_tag('b') . __('Devices') . ': ' . wf_tag('b', true) . $totalCount . wf_delimiter(0);
  2066. } else {
  2067. $messages = new UbillingMessageHelper();
  2068. $stats .= $messages->getStyledMessage(__('Nothing to show'), 'warning');
  2069. }
  2070. $result .= ' ' . wf_modal(wf_img('skins/orc_small.png', __('Devices polling stats')), __('Devices polling stats'), $stats, '', '800', '600');
  2071. }
  2072. return($result);
  2073. }
  2074. /**
  2075. * Shows current FDB cache list container
  2076. *
  2077. * @param string $fdbSwitchFilter
  2078. */
  2079. function web_FDBTableShowDataTable($fdbSwitchFilter = '', $fdbMacFilter = '') {
  2080. global $ubillingConfig;
  2081. $fdbExtenInfo = $ubillingConfig->getAlterParam('SW_FDB_EXTEN_INFO');
  2082. $filter = '';
  2083. $macfilter = '';
  2084. $result = '';
  2085. $filter = (!empty($fdbSwitchFilter)) ? '&swfilter=' . $fdbSwitchFilter : '';
  2086. $macfilter = (!empty($fdbMacFilter)) ? '&macfilter=' . $fdbMacFilter : '';
  2087. $currentFilters = zb_StorageGet('FDBCACHEMACFILTERS');
  2088. $filtersForm = wf_modalAuto(web_icon_search('MAC filters setup'), __('MAC filters setup'), web_FDBTableFiltersForm($currentFilters), '');
  2089. if (!empty($currentFilters)) {
  2090. $filtersForm .= ' ' . wf_img('skins/filter_icon.png', __('Filters'));
  2091. }
  2092. $logControls = web_FDBTableLogControl();
  2093. $logControls .= web_HordeStatsControl();
  2094. $mainControls = FDBArchive::renderNavigationPanel();
  2095. show_window('', $mainControls);
  2096. if ($fdbExtenInfo) {
  2097. $columns = array('Switch IP', 'Port', __('Port description'), 'VLAN', 'Location', 'MAC', __('User') . ' / ' . __('Device'));
  2098. } else {
  2099. $columns = array('Switch IP', 'Port', 'Location', 'MAC', __('User') . ' / ' . __('Device'));
  2100. }
  2101. $result .= wf_JqDtLoader($columns, '?module=switchpoller&ajax=true' . $filter . $macfilter, true, 'Objects', 100);
  2102. show_window(__('Current FDB cache') . ' ' . $filtersForm . ' ' . $logControls, $result);
  2103. }