api.mtsigmon.php 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553
  1. <?php
  2. /**
  3. * MikroTik/UBNT signal monitoring class
  4. */
  5. class MTsigmon {
  6. /**
  7. * User login
  8. *
  9. * @var string
  10. */
  11. protected $userLogin = '';
  12. /**
  13. * User assigned switch ID
  14. *
  15. * @var array
  16. */
  17. protected $userSwitch = '';
  18. /**
  19. * Data DEVICE id and his array mac data
  20. *
  21. * @var array
  22. */
  23. protected $deviceIdUsersMac = array();
  24. /**
  25. * All users MAC
  26. *
  27. * @var array
  28. */
  29. protected $allUsermacs = array();
  30. /**
  31. * All users CPE MAC
  32. *
  33. * @var array
  34. */
  35. protected $allUserCpeMacs = array();
  36. /**
  37. * All users Data
  38. *
  39. * @var array
  40. */
  41. protected $allUserData = array();
  42. /**
  43. * All available MT devices
  44. *
  45. * @var array
  46. */
  47. protected $allMTDevices = array();
  48. /**
  49. * OLT devices snmp data as id=>snmp data array
  50. *
  51. * @var array
  52. */
  53. protected $allMTSnmp = array();
  54. /**
  55. * UbillingCache object placeholder
  56. *
  57. * @var object
  58. */
  59. protected $cache = '';
  60. /**
  61. * Comments caching time
  62. *
  63. * @var int
  64. */
  65. protected $cacheTime = 2592000; //month by default
  66. /**
  67. * Contains system mussages object placeholder
  68. *
  69. * @var object
  70. */
  71. protected $messages = '';
  72. /**
  73. * Contains value of MTSIGMON_QUICK_AP_LINKS from alter.ini
  74. *
  75. * @var bool
  76. */
  77. protected $EnableQuickAPLinks = false;
  78. /**
  79. * Contains value of MTSIGMON_CPE_AUTOPOLL from alter.ini
  80. *
  81. * @var bool
  82. */
  83. protected $EnableCPEAutoPoll = false;
  84. /**
  85. * Is WCPE module enabled? Contains value of WIFICPE_ENABLED from alter.ini
  86. *
  87. * @var bool
  88. */
  89. protected $WCPEEnabled = false;
  90. /**
  91. * Placeholder for UbillingConfig object instance
  92. *
  93. * @var object
  94. */
  95. protected $ubConfig = null;
  96. /**
  97. * Sorting order of APs in lists and dropdowns
  98. * Possible values: id, ip, location
  99. *
  100. * @var string
  101. */
  102. protected $apSortOrder = "id";
  103. /**
  104. * Placeholder for SWITCH_GROUPS_ENABLED alter.ini option
  105. *
  106. * @var bool
  107. */
  108. protected $switchGroupsEnabled = false;
  109. /**
  110. * Placeholder for SIGMON_GROUP_AP_BY_SWITCHGROUP_WITH_TABS alter.ini option
  111. *
  112. * @var bool
  113. */
  114. protected $groupAPsBySwitchGroupWithTabs = false;
  115. /**
  116. * Contains array which represents sigmon devices and their groups, like: mtId => switchGroup
  117. *
  118. * @var array
  119. */
  120. protected $allMTSwitchGroups = array();
  121. /**
  122. * Contains groups in which only sigmon devices are present
  123. *
  124. * @var array
  125. */
  126. protected $existingMTSwitchGroups = array();
  127. const URL_ME = '?module=mtsigmon';
  128. const CACHE_PREFIX = 'MTSIGMON_';
  129. const CPE_SIG_PATH = 'content/documents/wifi_cpe_sig_hist/';
  130. public function __construct() {
  131. global $ubillingConfig;
  132. $this->ubConfig = $ubillingConfig;
  133. $this->EnableQuickAPLinks = $this->ubConfig->getAlterParam('MTSIGMON_QUICK_AP_LINKS');
  134. $this->EnableCPEAutoPoll = $this->ubConfig->getAlterParam('MTSIGMON_CPE_AUTOPOLL');
  135. $this->WCPEEnabled = $this->ubConfig->getAlterParam('WIFICPE_ENABLED');
  136. $this->apSortOrder = ($this->ubConfig->getAlterParam('SIGMON_WCPE_AP_LIST_SORT')) ? $this->ubConfig->getAlterParam('SIGMON_WCPE_AP_LIST_SORT') : 'id';
  137. $this->switchGroupsEnabled = $this->ubConfig->getAlterParam('SWITCH_GROUPS_ENABLED');
  138. $this->groupAPsBySwitchGroupWithTabs = $this->ubConfig->getAlterParam('SIGMON_GROUP_AP_BY_SWITCHGROUP_WITH_TABS');
  139. $this->LoadUsersData();
  140. $this->initCache();
  141. if (wf_CheckGet(array('username'))) {
  142. $this->initLogin(vf($_GET['username']));
  143. }
  144. $this->getMTDevices();
  145. $this->initSNMP();
  146. }
  147. /**
  148. * Creates single instance of SNMPHelper object
  149. *
  150. * @return void
  151. */
  152. protected function initSNMP() {
  153. $this->snmp = new SNMPHelper();
  154. }
  155. /**
  156. * If get login set $userLogin
  157. *
  158. * @return void
  159. */
  160. protected function initLogin($login) {
  161. $this->userLogin = $login;
  162. $this->getMTidByUserMac();
  163. }
  164. /**
  165. * Initalizes system cache object for further usage
  166. *
  167. * @return void
  168. */
  169. protected function initCache() {
  170. $this->cache = new UbillingCache();
  171. }
  172. /**
  173. * If get login set $userSwitch
  174. *
  175. * @return void
  176. */
  177. protected function getMTidByUserMac() {
  178. $usermac = strtolower($this->allUsermacs[$this->userLogin]);
  179. $userCpeMac = (isset($this->allUserCpeMacs[$this->userLogin])) ? strtolower($this->allUserCpeMacs[$this->userLogin]) : 'F0:14:78:87:41:0F';
  180. $MT_fdb_arr = $this->cache->get(self::CACHE_PREFIX . 'MTID_UMAC', $this->cacheTime);
  181. if (!empty($MT_fdb_arr) and isset($usermac)) {
  182. foreach ($MT_fdb_arr as $mtid => $fdb_arr) {
  183. if (in_array($usermac, $fdb_arr) or in_array($userCpeMac, $fdb_arr)) {
  184. $this->userSwitch = $mtid;
  185. break;
  186. }
  187. }
  188. }
  189. }
  190. /**
  191. * Returns array of monitored MikroTik devices with MTSIGMON label and enabled SNMP
  192. *
  193. * @return array
  194. */
  195. protected function getMTDevices() {
  196. $query_where = ($this->userLogin and ! empty($this->userSwitch)) ? " AND `id` = '" . $this->userSwitch . "' " : '';
  197. if ($this->switchGroupsEnabled and $this->groupAPsBySwitchGroupWithTabs) {
  198. $query = "SELECT `switches`.`id`, `switches`.`ip`, `switches`.`location`, `switches`.`snmp`, COALESCE(`swgrp`.`groupname`, '') AS groupname, `swgrp`.`groupdescr`
  199. FROM `switches`
  200. LEFT JOIN (SELECT `switch_groups_relations`.`switch_id`, `switch_groups`.`groupname`, `switch_groups`.`groupdescr`
  201. FROM `switch_groups_relations`
  202. LEFT JOIN `switch_groups`
  203. ON `switch_groups_relations`.`sw_group_id` = `switch_groups`.`id`) AS swgrp
  204. ON `switches`.`id` = `swgrp`.`switch_id`
  205. WHERE `desc` LIKE '%MTSIGMON%'" . $query_where;
  206. } else {
  207. $query = "SELECT `id`, `ip`, `location`, `snmp` FROM `switches` WHERE `desc` LIKE '%MTSIGMON%'" . $query_where;
  208. }
  209. if ($this->switchGroupsEnabled and $this->groupAPsBySwitchGroupWithTabs) {
  210. switch ($this->apSortOrder) {
  211. case "ip":
  212. $query .= ' GROUP BY `groupname`, `ip`';
  213. break;
  214. case "location":
  215. $query .= ' GROUP BY `groupname`, `location`';
  216. }
  217. } else {
  218. switch ($this->apSortOrder) {
  219. case "ip":
  220. $query .= ' ORDER BY `ip`';
  221. break;
  222. case "location":
  223. $query .= ' ORDER BY `location`';
  224. }
  225. }
  226. $alldevices = simple_queryall($query);
  227. if (!empty($alldevices)) {
  228. foreach ($alldevices as $io => $each) {
  229. $this->allMTDevices[$each['id']] = $each['ip'] . ' - ' . $each['location'];
  230. if (!empty($each['snmp'])) {
  231. $this->allMTSnmp[$each['id']]['ip'] = $each['ip'];
  232. $this->allMTSnmp[$each['id']]['community'] = $each['snmp'];
  233. }
  234. if ($this->switchGroupsEnabled and $this->groupAPsBySwitchGroupWithTabs) {
  235. $this->allMTSwitchGroups[$each['id']]['groupname'] = $each['groupname'];
  236. $this->allMTSwitchGroups[$each['id']]['groupdescr'] = $each['groupdescr'];
  237. if (!in_array($each['groupname'], $this->existingMTSwitchGroups)) {
  238. $this->existingMTSwitchGroups[] = $each['groupname'];
  239. }
  240. }
  241. }
  242. }
  243. }
  244. /**
  245. * Load user data, mac, adress
  246. *
  247. * @return array
  248. */
  249. protected function LoadUsersData() {
  250. $this->allUsermacs = zb_UserGetAllMACs();
  251. $this->allUserData = zb_UserGetAllDataCache();
  252. if ($this->WCPEEnabled) {
  253. $this->LoadUsersCpeMACs();
  254. }
  255. }
  256. /**
  257. * Load user data, mac, adress
  258. *
  259. * @return array
  260. */
  261. protected function LoadUsersCpeMACs() {
  262. $query = "SELECT `login`,`mac` FROM `wcpeusers` INNER JOIN (SELECT `id`,`mac`,`bridge` FROM `wcpedevices`) AS wcd ON (`wcpeusers`.`cpeid`=`wcd`.`id`) WHERE `bridge` = '1'";
  263. $usersCpeMacs = simple_queryall($query);
  264. if (!empty($usersCpeMacs)) {
  265. foreach ($usersCpeMacs as $io => $each) {
  266. $this->allUserCpeMacs[$each['login']] = $each['mac'];
  267. }
  268. }
  269. }
  270. /**
  271. * Performs available MT devices polling. Use only in remote API.
  272. *
  273. * @param bool $quiet
  274. * @param string $apid
  275. *
  276. * @return void
  277. */
  278. public function MTDevicesPolling($quiet = false, $apid = '') {
  279. if (!empty($this->allMTDevices)) {
  280. if (empty($apid)) {
  281. foreach ($this->allMTDevices as $mtid => $each) {
  282. if (!$quiet) {
  283. print('POLLING:' . $mtid . ' ' . $each . "\n");
  284. }
  285. $this->deviceQuery($mtid);
  286. }
  287. } else {
  288. $this->deviceQuery($apid);
  289. }
  290. // Set cache for Device fdb table
  291. if (empty($this->userLogin) or ( !empty($this->userLogin) and empty($this->userSwitch))) {
  292. $this->cache->set(self::CACHE_PREFIX . 'MTID_UMAC', $this->deviceIdUsersMac, $this->cacheTime);
  293. $this->cache->set(self::CACHE_PREFIX . 'DATE', date("Y-m-d H:i:s"), $this->cacheTime);
  294. }
  295. }
  296. if ($this->EnableCPEAutoPoll && $this->WCPEEnabled) {
  297. $WCPE = new WifiCPE();
  298. $AllCPEs = $WCPE->getAllCPE();
  299. if (!empty($AllCPEs)) {
  300. foreach ($AllCPEs as $io => $each) {
  301. $this->deviceQuery(0, $each['ip'], $each['mac'], $each['snmp']);
  302. }
  303. }
  304. }
  305. }
  306. /**
  307. * Performs getting string representation of AP/CPE devices signal levels from cache.
  308. * Can re-poll the devices, before taking data from cache, to get the most fresh values.
  309. * IP and SNMP community for AP is taken from APs dictionary.
  310. * For an individual CPE - IP and SNMP community must be given as a parameter
  311. *
  312. * @param string $WiFiCPEMAC
  313. * @param string $WiFiAPID
  314. * @param string $WiFiCPEIP
  315. * @param string $WiFiCPECommunity
  316. * @param bool $GetFromAP
  317. * @param bool $Repoll
  318. *
  319. * @return array
  320. */
  321. public function getCPESignalData($WiFiCPEMAC, $WiFiAPID = '', $WiFiCPEIP = '', $WiFiCPECommunity = 'public', $GetFromAP = false, $Repoll = false) {
  322. if (empty($WiFiCPEMAC) or ( empty($WiFiAPID) and empty($WiFiCPEIP))) {
  323. return array();
  324. }
  325. $BillCfg = $this->ubConfig->getBilling();
  326. if ($GetFromAP) {
  327. $HistoryFile = self::CPE_SIG_PATH . md5($WiFiCPEMAC) . '_AP';
  328. if ($Repoll and ! empty($WiFiAPID)) {
  329. $this->MTDevicesPolling(false, $WiFiAPID);
  330. }
  331. } else {
  332. $HistoryFile = self::CPE_SIG_PATH . md5($WiFiCPEMAC) . '_CPE';
  333. if ($Repoll and ! empty($WiFiCPEIP)) {
  334. $this->deviceQuery(0, $WiFiCPEIP, $WiFiCPEMAC, $WiFiCPECommunity);
  335. }
  336. }
  337. if (file_exists($HistoryFile)) {
  338. //$GREPString = ( empty($GREPBy) ) ? '' : ' | ' . $BillCfg['GREP'] . ' ' . $GREPBy;
  339. //$RawDataLastLine = strstr(shell_exec($GetDataCmd), "\n", true);
  340. $GetDataCmd = $BillCfg['TAIL'] . ' -n 1 ' . $HistoryFile;
  341. $RawDataLastLine = shell_exec($GetDataCmd);
  342. $LastLineArray = explode(',', trim($RawDataLastLine));
  343. $LastPollDate = $LastLineArray[0];
  344. $SignalRX = $LastLineArray[1];
  345. if (isset($LastLineArray[2]) and ! empty($LastLineArray[2])) {
  346. $SignalCheck = (($SignalRX > $LastLineArray[2]) ? $LastLineArray[2] : $SignalRX);
  347. $SignalTX = ' / ' . $LastLineArray[2];
  348. } else {
  349. $SignalCheck = $SignalRX;
  350. $SignalTX = '';
  351. }
  352. $SignalLevel = $SignalRX . $SignalTX;
  353. if ($SignalCheck < -79) {
  354. $SignalLevel = wf_tag('font', false, '', 'color="ab0000" style="font-weight: 700"') . $SignalLevel . wf_tag('font', true);
  355. } elseif ($SignalCheck > -80 and $SignalCheck < -74) {
  356. $SignalLevel = wf_tag('font', false, '', 'color="#FF5500" style="font-weight: 700"') . $SignalLevel . wf_tag('font', true);
  357. } else {
  358. $SignalLevel = wf_tag('font', false, '', 'color="#005502" style="font-weight: 700"') . $SignalLevel . wf_tag('font', true);
  359. }
  360. //return ( wf_CheckGet(array('cpeMAC')) ) ? array("LastPollDate" => $LastPollDate, "SignalLevel" => $SignalLevel) : array($LastPollDate, $SignalLevel);
  361. return ( $Repoll ) ? array("LastPollDate" => $LastPollDate, "SignalLevel" => $SignalLevel) : array($LastPollDate, $SignalLevel);
  362. }
  363. }
  364. /**
  365. * Renders signal graphs for specified CPE if there are some history data already
  366. * Returns ready-to-use piece of HTML
  367. *
  368. * @param string $WiFiCPEMAC
  369. * @param bool $FromAP
  370. * @param bool $ShowTitle
  371. * @param bool $ShowXLabel
  372. * @param bool $ShowYLabel
  373. * @param bool $ShowRangeSelector
  374. * @return string
  375. */
  376. public function renderSignalGraphs($WiFiCPEMAC, $FromAP = false, $ShowTitle = false, $ShowXLabel = false, $ShowYLabel = false, $ShowRangeSelector = false) {
  377. $result = '';
  378. $BillCfg = $this->ubConfig->getBilling();
  379. if ($FromAP) {
  380. // get signal data on AP for this CPE
  381. $HistoryFile = self::CPE_SIG_PATH . md5($WiFiCPEMAC) . '_AP';
  382. $HistoryFileMonth = self::CPE_SIG_PATH . md5($WiFiCPEMAC) . '_AP_month';
  383. } else {
  384. // get signal data for this CPE itself
  385. $HistoryFile = self::CPE_SIG_PATH . md5($WiFiCPEMAC) . '_CPE';
  386. }
  387. if (file_exists($HistoryFile)) {
  388. $curdate = curdate();
  389. $curmonth = curmonth() . '-';
  390. $getMonthDataCmd = $BillCfg['CAT'] . ' ' . $HistoryFile . ' | ' . $BillCfg['GREP'] . ' ' . $curmonth;
  391. $rawData = shell_exec($getMonthDataCmd);
  392. $result .= wf_delimiter();
  393. $todaySignal = '';
  394. if (!empty($rawData)) {
  395. $todayTmp = explodeRows($rawData);
  396. if (!empty($todayTmp)) {
  397. foreach ($todayTmp as $io => $each) {
  398. if (ispos($each, $curdate)) {
  399. $todaySignal .= $each . "\n";
  400. }
  401. }
  402. }
  403. }
  404. $GraphTitle = ($ShowTitle) ? __('Today') : '';
  405. $GraphXLabel = ($ShowXLabel) ? __('Time') : '';
  406. $GraphYLabel = ($ShowYLabel) ? __('Signal') : '';
  407. $result .= wf_Graph($todaySignal, '800', '300', false, $GraphTitle, $GraphXLabel, $GraphYLabel, $ShowRangeSelector);
  408. $result .= wf_delimiter(2);
  409. //current month signal levels
  410. $monthSignal = '';
  411. $curmonth = curmonth();
  412. if (!empty($rawData)) {
  413. $monthTmp = explodeRows($rawData);
  414. if (!empty($monthTmp)) {
  415. foreach ($monthTmp as $io => $each) {
  416. if (ispos($each, $curmonth)) {
  417. $monthSignal .= $each . "\n";
  418. }
  419. }
  420. }
  421. }
  422. $GraphTitle = ($ShowTitle) ? __('Monthly graph') : '';
  423. $GraphXLabel = ($ShowXLabel) ? __('Date') : '';
  424. if ($FromAP) {
  425. file_put_contents($HistoryFileMonth, $monthSignal);
  426. $result .= wf_GraphCSV($HistoryFileMonth, '800', '300', false, $GraphTitle, $GraphXLabel, $GraphYLabel, $ShowRangeSelector);
  427. } else {
  428. $result .= wf_Graph($monthSignal, '800', '300', false, $GraphTitle, $GraphXLabel, $GraphYLabel, $ShowRangeSelector);
  429. }
  430. $result .= wf_delimiter(2);
  431. //all time signal history
  432. $GraphTitle = ($ShowTitle) ? __('All time graph') : '';
  433. $result .= wf_GraphCSV($HistoryFile, '800', '300', false, $GraphTitle, $GraphXLabel, $GraphYLabel, $ShowRangeSelector);
  434. $result .= wf_delimiter();
  435. }
  436. return $result;
  437. }
  438. /*
  439. * Common for all
  440. * .1.3.6.1.2.1.1.1.0 - AP sys description
  441. * .1.3.6.1.2.1.1.3.0 - AP uptime
  442. * .1.3.6.1.2.1.1.5.0 - AP sys name
  443. *
  444. * .1.3.6.1.2.1.2.2.1.6 - AP interaces MACs list - too many afforts needed to get correct wireless MAC
  445. * cause we first need to determine the wireless interface correctly,
  446. * then get it's index and only then we can get APs MAC for sure.
  447. * But on different devices there are different approaches to get the wireless interface correctly:
  448. * on Mikrotiks we can not rely on iface description, but can rely on iface type;
  449. * on other devices we can supposedly rely on iface description, but not 100%
  450. *
  451. *
  452. * Mikrotik *
  453. * .1.3.6.1.2.1.25.3.3.1.2.1 - CPU load average
  454. * .1.3.6.1.4.1.14988.1.1.1.3.1.4 - AP ssid
  455. * .1.3.6.1.4.1.14988.1.1.1.3.1.7 - AP freq
  456. * .1.3.6.1.4.1.14988.1.1.1.3.1.8 - AP band
  457. * .1.3.6.1.2.1.2.2.1.6.1 - AP wireless MAC
  458. *
  459. *
  460. * Ubiquity b/g/n AirOS version >= 5.6
  461. * .1.3.6.1.4.1.41112.1.4.1.1.4 - AP freq
  462. * .1.3.6.1.4.1.41112.1.4.5.1.2 - AP ssid
  463. * .1.3.6.1.4.1.41112.1.4.5.1.14 - AP channel width
  464. * .1.2.840.10036.1.1.1.1.5 - AP wireless MAC
  465. *
  466. *
  467. * Ubiquity b/g
  468. * only common data can be got
  469. *
  470. *
  471. * Ligowave DLB
  472. * .1.3.6.1.4.1.32750.3.10.1.2.1.1.1 - AP wireless MAC
  473. * .1.3.6.1.4.1.32750.3.10.1.2.1.1.4 - AP ssid
  474. * .1.3.6.1.4.1.32750.3.10.1.2.1.1.6 - AP freq
  475. * .1.3.6.1.4.1.32750.3.10.1.2.1.1.8 - AP channel width
  476. *
  477. * Deliberant APC Series
  478. * .1.3.6.1.4.1.32761.3.5.1.2.1.1.4 - AP ssid
  479. * .1.3.6.1.4.1.32761.3.5.1.2.1.1.7 - AP freq
  480. * .1.3.6.1.4.1.32761.3.5.1.2.1.1.9 - AP channel width
  481. *
  482. * .1.3.6.1.4.1.32761.3.5.1.2.1.1.14 - CPE signal level, but need wireless iface index...
  483. */
  484. /**
  485. * Gets essential system info about AP via SNMP and returns it as HTML table or array
  486. *
  487. * @param $APID
  488. * @param bool $ReturnHTML
  489. * @param bool $ReturnInSpoiler
  490. * @param bool $SpoilerClosed
  491. *
  492. * @return array|string
  493. */
  494. public function getAPEssentialData($APID, $ReturnHTML = false, $ReturnInSpoiler = false, $SpoilerClosed = false) {
  495. if (isset($this->allMTSnmp[$APID]['community'])) {
  496. $this->snmp->setMode('native');
  497. $APIP = $this->allMTSnmp[$APID]['ip'];
  498. $APCommunity = $this->allMTSnmp[$APID]['community'];
  499. $APSysDescr = '';
  500. $APUptime = '';
  501. $APSysName = '';
  502. $APSSID = '';
  503. $APFreq = '';
  504. $APBandChWidth = '';
  505. $MTikCPULoad = '';
  506. $APMAC = '';
  507. $SNMPDataArray = array();
  508. //getting common data for all devices
  509. // sys description
  510. $tmpOID = '.1.3.6.1.2.1.1.1.0';
  511. $tmpSNMP = $this->snmp->walk($APIP, $APCommunity, $tmpOID, false);
  512. $APSysDescr = ( empty($tmpSNMP) && $tmpSNMP === "$tmpOID = " ) ? '' : trim(substr($tmpSNMP, stripos($tmpSNMP, ':') + 1));
  513. // uptime
  514. $tmpOID = '.1.3.6.1.2.1.1.3.0';
  515. $tmpSNMP = $this->snmp->walk($APIP, $APCommunity, $tmpOID, false);
  516. $APUptime = ( empty($tmpSNMP) && $tmpSNMP === "$tmpOID = " ) ? '' : trim(substr($tmpSNMP, stripos($tmpSNMP, ')') + 1));
  517. // sys name
  518. $tmpOID = '.1.3.6.1.2.1.1.5.0';
  519. $tmpSNMP = $this->snmp->walk($APIP, $APCommunity, $tmpOID, false);
  520. $APSysName = ( empty($tmpSNMP) && $tmpSNMP === "$tmpOID = " ) ? '' : trim(substr($tmpSNMP, stripos($tmpSNMP, ':') + 1));
  521. // suppose it's Mikrotik
  522. $tmpOID = '.1.3.6.1.4.1.14988.1.1.1.3.1.4';
  523. $tmpSNMP = $this->snmp->walk($APIP, $APCommunity, $tmpOID, false);
  524. if (!empty($tmpSNMP) && $tmpSNMP !== "$tmpOID = ") {
  525. $APSSID = ( empty($tmpSNMP) && $tmpSNMP === "$tmpOID = " ) ? '' : trim(substr($tmpSNMP, stripos($tmpSNMP, ':') + 1));
  526. $tmpOID = '.1.3.6.1.4.1.14988.1.1.1.3.1.7';
  527. $tmpSNMP = $this->snmp->walk($APIP, $APCommunity, $tmpOID, false);
  528. $APFreq = ( empty($tmpSNMP) && $tmpSNMP === "$tmpOID = " ) ? '' : trim(substr($tmpSNMP, stripos($tmpSNMP, ':') + 1));
  529. $tmpOID = '.1.3.6.1.4.1.14988.1.1.1.3.1.8';
  530. $tmpSNMP = $this->snmp->walk($APIP, $APCommunity, $tmpOID, false);
  531. $APBandChWidth = ( empty($tmpSNMP) && $tmpSNMP === "$tmpOID = " ) ? '' : trim(substr($tmpSNMP, stripos($tmpSNMP, ':') + 1));
  532. $tmpOID = '.1.3.6.1.2.1.25.3.3.1.2.1';
  533. $tmpSNMP = $this->snmp->walk($APIP, $APCommunity, $tmpOID, false);
  534. $MTikCPULoad = ( empty($tmpSNMP) && $tmpSNMP === "$tmpOID = " ) ? '' : trim(substr($tmpSNMP, stripos($tmpSNMP, ':') + 1));
  535. // Device MAC for Mikrotik
  536. $tmpOID = '.1.3.6.1.2.1.2.2.1.6.1';
  537. $tmpSNMP = $this->snmp->walk($APIP, $APCommunity, $tmpOID, false);
  538. $APMAC = (empty($tmpSNMP) && $tmpSNMP === "$tmpOID = ") ? '' : $this->getMACFromSNMPStr($tmpSNMP);
  539. } else {
  540. // now suppose it's Ubnt AirOS version >= 5.6
  541. $tmpOID = '.1.3.6.1.4.1.41112.1.4.1.1.4';
  542. $tmpSNMP = $this->snmp->walk($APIP, $APCommunity, $tmpOID, false);
  543. if (!empty($tmpSNMP) && $tmpSNMP !== "$tmpOID = ") {
  544. $APFreq = (empty($tmpSNMP) && $tmpSNMP === "$tmpOID = ") ? '' : trim(substr($tmpSNMP, stripos($tmpSNMP, ':') + 1));
  545. $tmpOID = '.1.3.6.1.4.1.41112.1.4.5.1.2';
  546. $tmpSNMP = $this->snmp->walk($APIP, $APCommunity, $tmpOID, false);
  547. $APSSID = (empty($tmpSNMP) && $tmpSNMP === "$tmpOID = ") ? '' : trim(substr($tmpSNMP, stripos($tmpSNMP, ':') + 1));
  548. $tmpOID = '.1.3.6.1.4.1.41112.1.4.5.1.14';
  549. $tmpSNMP = $this->snmp->walk($APIP, $APCommunity, $tmpOID, false);
  550. $APBandChWidth = (empty($tmpSNMP) && $tmpSNMP === "$tmpOID = ") ? '' : trim(substr($tmpSNMP, stripos($tmpSNMP, ':') + 1));
  551. // Device MAC for Loco M2
  552. $tmpOID = '.1.2.840.10036.1.1.1.1.5';
  553. $tmpSNMP = $this->snmp->walk($APIP, $APCommunity, $tmpOID, false);
  554. $APMAC = (empty($tmpSNMP) && $tmpSNMP === "$tmpOID = ") ? '' : $this->getMACFromSNMPStr($tmpSNMP);
  555. } else {
  556. // now suppose it's Ligowave DLB
  557. $tmpOID = '.1.3.6.1.4.1.32750.3.10.1.2.1.1.1';
  558. $tmpSNMP = $this->snmp->walk($APIP, $APCommunity, $tmpOID, false);
  559. if (!empty($tmpSNMP) && $tmpSNMP !== "$tmpOID = ") {
  560. $APMAC = $this->getMACFromSNMPStr($tmpSNMP);
  561. $tmpOID = '.1.3.6.1.4.1.32750.3.10.1.2.1.1.4';
  562. $tmpSNMP = $this->snmp->walk($APIP, $APCommunity, $tmpOID, false);
  563. $APSSID = ( empty($tmpSNMP) && $tmpSNMP === "$tmpOID = " ) ? '' : trim(substr($tmpSNMP, stripos($tmpSNMP, ':') + 1));
  564. $tmpOID = '.1.3.6.1.4.1.32750.3.10.1.2.1.1.6';
  565. $tmpSNMP = $this->snmp->walk($APIP, $APCommunity, $tmpOID, false);
  566. $APFreq = ( empty($tmpSNMP) && $tmpSNMP === "$tmpOID = " ) ? '' : trim(substr($tmpSNMP, stripos($tmpSNMP, ':') + 1));
  567. $tmpOID = '.1.3.6.1.4.1.32750.3.10.1.2.1.1.8';
  568. $tmpSNMP = $this->snmp->walk($APIP, $APCommunity, $tmpOID, false);
  569. $APBandChWidth = ( empty($tmpSNMP) && $tmpSNMP === "$tmpOID = " ) ? '' : trim(substr($tmpSNMP, stripos($tmpSNMP, ':') + 1));
  570. } else {
  571. // now suppose it's Deliberant APC Series
  572. $tmpOID = '.1.3.6.1.4.1.32761.3.5.1.2.1.1.4';
  573. $tmpSNMP = $this->snmp->walk($APIP, $APCommunity, $tmpOID, false);
  574. if (!empty($tmpSNMP) && $tmpSNMP !== "$tmpOID = ") {
  575. $APSSID = ( empty($tmpSNMP) && $tmpSNMP === "$tmpOID = " ) ? '' : trim(substr($tmpSNMP, stripos($tmpSNMP, ':') + 1));
  576. $tmpOID = '.1.3.6.1.4.1.32761.3.5.1.2.1.1.7';
  577. $tmpSNMP = $this->snmp->walk($APIP, $APCommunity, $tmpOID, false);
  578. $APFreq = ( empty($tmpSNMP) && $tmpSNMP === "$tmpOID = " ) ? '' : trim(substr($tmpSNMP, stripos($tmpSNMP, ':') + 1));
  579. $tmpOID = '.1.3.6.1.4.1.32761.3.5.1.2.1.1.9';
  580. $tmpSNMP = $this->snmp->walk($APIP, $APCommunity, $tmpOID, false);
  581. $APBandChWidth = ( empty($tmpSNMP) && $tmpSNMP === "$tmpOID = " ) ? '' : trim(substr($tmpSNMP, stripos($tmpSNMP, ':') + 1));
  582. } else {
  583. // Device MAC for UBNT
  584. $tmpOID = '.1.2.840.10036.1.1.1.1.5';
  585. $tmpSNMP = $this->snmp->walk($APIP, $APCommunity, $tmpOID, false);
  586. if (!empty($tmpSNMP) && $tmpSNMP !== "$tmpOID = ") {
  587. $APMAC = $this->getMACFromSNMPStr($tmpSNMP);
  588. } else {
  589. // WHAT A HELL ARE YOU?!
  590. }
  591. }
  592. }
  593. }
  594. }
  595. if ($ReturnHTML) {
  596. $APInfoRows = '';
  597. $APInfoHTML = '';
  598. if (!empty($APSysDescr)) {
  599. $cells = wf_TableCell(__('System description'), '20%', 'row2');
  600. $cells .= wf_TableCell($APSysDescr);
  601. $APInfoRows .= wf_TableRow($cells, 'row3');
  602. }
  603. if (!empty($APSysName)) {
  604. $cells = wf_TableCell(__('System name'), '20%', 'row2');
  605. $cells .= wf_TableCell($APSysName);
  606. $APInfoRows .= wf_TableRow($cells, 'row3');
  607. }
  608. if (!empty($APUptime)) {
  609. $cells = wf_TableCell(__('Uptime'), '20%', 'row2');
  610. $cells .= wf_TableCell($APUptime);
  611. $APInfoRows .= wf_TableRow($cells, 'row3');
  612. }
  613. if (!empty($APSSID)) {
  614. $cells = wf_TableCell(__('SSID'), '20%', 'row2');
  615. $cells .= wf_TableCell($APSSID);
  616. $APInfoRows .= wf_TableRow($cells, 'row3');
  617. }
  618. if (!empty($APFreq)) {
  619. $cells = wf_TableCell(__('Frequency'), '20%', 'row2');
  620. $cells .= wf_TableCell($APFreq . ' MHz');
  621. $APInfoRows .= wf_TableRow($cells, 'row3');
  622. }
  623. if (!empty($APBandChWidth)) {
  624. $cells = wf_TableCell(__('Band/channel width'), '20%', 'row2');
  625. $cells .= wf_TableCell($APBandChWidth . ' MHz');
  626. $APInfoRows .= wf_TableRow($cells, 'row3');
  627. }
  628. if (!empty($MTikCPULoad)) {
  629. $cells = wf_TableCell(__('CPU load'), '20%', 'row2');
  630. $cells .= wf_TableCell($MTikCPULoad . '%');
  631. $APInfoRows .= wf_TableRow($cells, 'row3');
  632. }
  633. if (!empty($APMAC)) {
  634. $cells = wf_TableCell(__('MAC address'), '20%', 'row2');
  635. $cells .= wf_TableCell($APMAC);
  636. $APInfoRows .= wf_TableRow($cells, 'row3');
  637. }
  638. $APInfoHTML = ( empty($APInfoRows) ) ? '' : wf_TableBody($APInfoRows, '88%', 0, '', 'style="margin: 0 auto;"');
  639. if ($ReturnInSpoiler) {
  640. $APInfoHTML = wf_Spoiler($APInfoHTML, __('System AP info'), $SpoilerClosed, '', '', '', '', 'style="margin: 10px auto;"');
  641. }
  642. return $APInfoHTML;
  643. } else {
  644. $SNMPDataArray = array('APSysDescr' => $APSysDescr,
  645. 'APUptime' => $APUptime,
  646. 'APSysName' => $ReturnHTML,
  647. 'APSSID' => $APSSID,
  648. 'APFreq' => $APFreq,
  649. 'APBandChWidth' => $APBandChWidth,
  650. 'MTikCPULoad' => $MTikCPULoad,
  651. 'APMAC' => $APMAC
  652. );
  653. return $SNMPDataArray;
  654. }
  655. }
  656. }
  657. /**
  658. * Returns MAC in 'XX:XX:XX:XX:XX:XX' format from something like this: '.1.3.6.1.2.1.2.2.1.6.1 = Hex-STRING: E4 8D 8C 27 2F 7B'
  659. * or
  660. * Returns MAC in 'XX:XX:XX:XX:XX:XX' format from something like this: '.1.2.840.10036.1.1.1.1.5 = STRING: "00:27:22:90:11:AE"'
  661. * or
  662. * Returns MAC in 'XX:XX:XX:XX:XX:XX' format from something like this: '.1.3.6.1.2.1.2.2.1.6.1 = STRING: 0:c:42:da:af:4'
  663. *
  664. * @param $SNMPString
  665. *
  666. * @return string
  667. */
  668. protected function getMACFromSNMPStr($SNMPString, $MACDelimiter = '') {
  669. $APMAC = '';
  670. $MACDelimiter = ( empty($MACDelimiter)) ? ':' : $MACDelimiter;
  671. $tmpOidDataArray = explode(': ', $SNMPString);
  672. if (isset($tmpOidDataArray[1])) {
  673. $tmpData = trim($tmpOidDataArray[1]);
  674. $tmpData = preg_replace('/"/', '', $tmpData);
  675. $tmpDataArray = preg_split('/[\s:]+/', $tmpData); // alternative for function explode for two and more parametrs
  676. if (count($tmpDataArray) == 6) {
  677. $APMAC = vsprintf('%02s' . $MACDelimiter . '%02s' . $MACDelimiter . '%02s' . $MACDelimiter . '%02s' . $MACDelimiter . '%02s' . $MACDelimiter . '%02s', $tmpDataArray);
  678. }
  679. }
  680. return $APMAC;
  681. }
  682. /**
  683. * Polls wireless APs/CPEs and stores data to cache
  684. *
  685. * @param int $mtid
  686. * @param string $WiFiCPEIP
  687. * @param string $WiFiCPEMAC
  688. * @param string $WiFiCPECommunity
  689. *
  690. * @return void
  691. */
  692. protected function deviceQuery($mtid, $WiFiCPEIP = '', $WiFiCPEMAC = '', $WiFiCPECommunity = 'public') {
  693. if (isset($this->allMTSnmp[$mtid]['community']) or ( !empty($WiFiCPEIP) and ! empty($WiFiCPEMAC))) {
  694. $ip = ( empty($WiFiCPEIP) ) ? $this->allMTSnmp[$mtid]['ip'] : $WiFiCPEIP;
  695. $community = ( empty($WiFiCPEIP) ) ? $this->allMTSnmp[$mtid]['community'] : $WiFiCPECommunity;
  696. global $ubillingConfig;
  697. $alterCfg = $ubillingConfig->getAlter();
  698. $oid = '.1.3.6.1.4.1.14988.1.1.1.2.1.3'; // - RX Signal Strength
  699. $oid2 = '.1.3.6.1.4.1.14988.1.1.1.2.1.19'; // - TX Signal Strength
  700. $oid3 = '.1.2.840.10036.1.1.1.1.5'; // - MAC adress of Device WLAN interface
  701. $mask_mac = false;
  702. $ubnt_shift = 0;
  703. $result = array();
  704. $rawsnmp = array();
  705. $rawsnmp2 = array();
  706. $result_fdb = array();
  707. $DeliberantClient = false;
  708. $this->snmp->setBackground(false);
  709. $this->snmp->setMode('native');
  710. $tmpSnmp = $this->snmp->walk($ip, $community, $oid, false);
  711. $tmpSnmp2 = $this->snmp->walk($ip, $community, $oid2, false);
  712. $tmpSnmp3 = $this->snmp->walk($ip, $community, $oid3, false);
  713. // If returned string '.1.3.6.1.4.1.14988.1.1.1.2.1.3 = ' - then:
  714. // For AirOS 5.6 and newer
  715. if ($tmpSnmp === "$oid = ") {
  716. $oid = '.1.3.6.1.4.1.41112.1.4.7.1.3.1';
  717. $tmpSnmp = $this->snmp->walk($ip, $community, $oid, false);
  718. $ubnt_shift = 1;
  719. }
  720. // For Ligowave DLB 2-90
  721. if ($tmpSnmp === "$oid = ") {
  722. $oid = '.1.3.6.1.4.1.32750.3.10.1.3.2.1.5.5';
  723. $tmpSnmp = $this->snmp->walk($ip, $community, $oid, false);
  724. }
  725. // For Ligowave DLB 2-90 after 7.59 firmware version
  726. if ($tmpSnmp === "$oid = ") {
  727. $oid = '.1.3.6.1.4.1.32750.3.10.1.3.2.1.5.7';
  728. $tmpSnmp = $this->snmp->walk($ip, $community, $oid, false);
  729. }
  730. /*
  731. // For Deliberant APC Series clients. Won't work for APs, cause there is no ability to monitor
  732. // Deliberant APC Series APs clients signal level via SNMP. Only on clients itself
  733. if ($tmpSnmp === "$oid = ") {
  734. $DeliberantClient = true;
  735. $oid = '.1.3.6.1.4.1.32761.3.5.1.2.1.1.14.6';
  736. $oid2 = '.1.3.6.1.2.1.2.2.1.6.6';
  737. $tmpSnmp = $this->snmp->walk($ip, $community, $oid, false);
  738. $tmpSnmp2 = $this->snmp->walk($ip, $community, $oid2, false);
  739. } */
  740. if ($alterCfg['SWITCHES_SNMP_MAC_EXORCISM']) {
  741. $APMAC = '';
  742. // Check and write MAC adress of Device WLAN interface
  743. // For AirOS 5.6 and newer
  744. if (!empty($tmpSnmp3) && $tmpSnmp3 !== "$oid3 = ") {
  745. $APMAC = $this->getMACFromSNMPStr($tmpSnmp3);
  746. } else {
  747. // For Ligowave DLB
  748. $oid3 = '.1.3.6.1.4.1.32750.3.10.1.2.1.1.1';
  749. $tmpSnmp3 = $this->snmp->walk($ip, $community, $oid3, false);
  750. if (!empty($tmpSnmp3) && $tmpSnmp3 !== "$oid3 = ") {
  751. $APMAC = $this->getMACFromSNMPStr($tmpSnmp3);
  752. } else {
  753. // For Mikrotik
  754. $oid3 = '.1.3.6.1.2.1.2.2.1.6.1';
  755. $tmpSnmp3 = $this->snmp->walk($ip, $community, $oid3, false);
  756. if (!empty($tmpSnmp3) && $tmpSnmp3 !== "$oid3 = ") {
  757. $APMAC = $this->getMACFromSNMPStr($tmpSnmp3);
  758. }
  759. }
  760. }
  761. // Write Device MAC address to file
  762. if (!empty($APMAC)) {
  763. file_put_contents('exports/' . $ip . '_MAC', strtolower($APMAC));
  764. }
  765. }
  766. if (!empty($tmpSnmp) and ( $tmpSnmp !== "$oid = ")) {
  767. $explodeData = explodeRows($tmpSnmp);
  768. if (!empty($explodeData)) {
  769. foreach ($explodeData as $io => $each) {
  770. $explodeRow = explode(' = ', $each);
  771. if (isset($explodeRow[1])) {
  772. $rawsnmp[$explodeRow[0]] = $explodeRow[1];
  773. }
  774. }
  775. }
  776. }
  777. if (!empty($tmpSnmp2) and ( $tmpSnmp2 !== "$oid2 = ") and ! $DeliberantClient) {
  778. $explodeData = explodeRows($tmpSnmp2);
  779. if (!empty($explodeData)) {
  780. foreach ($explodeData as $io => $each) {
  781. $explodeRow = explode(' = ', $each);
  782. if (isset($explodeRow[1])) {
  783. $rawsnmp2[$explodeRow[0]] = $explodeRow[1];
  784. }
  785. }
  786. }
  787. }
  788. $rssi = '';
  789. $rssi2 = '';
  790. $TXoid = '';
  791. if (!empty($rawsnmp)) {
  792. if (is_array($rawsnmp)) {
  793. foreach ($rawsnmp as $indexOID => $rssi) {
  794. $mac = '';
  795. if ($DeliberantClient) {
  796. $mac = $this->getMACFromSNMPStr($tmpSnmp2);
  797. } else {
  798. $TXoid = (!empty($rawsnmp2)) ? str_replace($oid, $oid2, $indexOID) : '';
  799. $oidarray = explode(".", $indexOID);
  800. $end_num = sizeof($oidarray) + $ubnt_shift;
  801. for ($counter = 2; $counter < 8; $counter++) {
  802. $temp = sprintf('%02x', $oidarray[$end_num - $counter]);
  803. if (($counter < 5) && $mask_mac)
  804. $mac = ":xx$mac";
  805. else if ($counter == 7)
  806. $mac = "$temp$mac";
  807. else
  808. $mac = ":$temp.$mac";
  809. }
  810. $mac = str_replace('.', '', $mac);
  811. $mac = trim($mac);
  812. }
  813. $rssi = str_replace('INTEGER:', '', $rssi);
  814. $rssi = trim($rssi);
  815. if (!empty($TXoid)) {
  816. $rssi2 = $rawsnmp2[$TXoid];
  817. $rssi2 = str_replace('INTEGER:', '', $rssi2);
  818. $rssi2 = trim($rssi2);
  819. $rssi2 = ' / ' . $rssi2;
  820. }
  821. if (empty($WiFiCPEIP)) {
  822. $result[$mac] = $rssi . $rssi2;
  823. $result_fdb[] = $mac;
  824. $HistoryFile = self::CPE_SIG_PATH . md5($mac) . '_AP';
  825. } else {
  826. $HistoryFile = self::CPE_SIG_PATH . md5($WiFiCPEMAC) . '_CPE';
  827. }
  828. file_put_contents($HistoryFile, curdatetime() . ',' . $rssi . ',' . mb_substr($rssi2, 3) . "\n", FILE_APPEND);
  829. }
  830. }
  831. }
  832. if (empty($WiFiCPEIP)) {
  833. if ($this->userLogin and $this->userSwitch) {
  834. $this->cache->set(self::CACHE_PREFIX . $mtid, $result, $this->cacheTime);
  835. } else {
  836. $this->cache->set(self::CACHE_PREFIX . $mtid, $result, $this->cacheTime);
  837. $this->deviceIdUsersMac[$mtid] = $result_fdb;
  838. }
  839. }
  840. }
  841. }
  842. /**
  843. * Returns default list controls
  844. *
  845. * @return string
  846. */
  847. public function controls() {
  848. // Load only when using web module
  849. $this->messages = new UbillingMessageHelper();
  850. $result = '';
  851. $cache_date = $this->cache->get(self::CACHE_PREFIX . 'DATE', $this->cacheTime);
  852. if ($this->userLogin) {
  853. $result .= wf_BackLink('?module=userprofile&username=' . $this->userLogin);
  854. $result .= wf_Link(self::URL_ME . '&forcepoll=true' . '&username=' . $this->userLogin, wf_img('skins/refresh.gif') . ' ' . __('Force query'), false, 'ubButton');
  855. } else {
  856. $result .= wf_Link(self::URL_ME . '&forcepoll=true', wf_img('skins/refresh.gif') . ' ' . __('Force query'), false, 'ubButton');
  857. }
  858. if (!empty($cache_date)) {
  859. $result .= $this->messages->getStyledMessage(__('Cache state at time') . ': ' . wf_tag('b', false) . @$cache_date . wf_tag('b', true), 'info');
  860. } else {
  861. $result .= $this->messages->getStyledMessage(__('Devices are not polled yet'), 'warning');
  862. }
  863. $result .= wf_tag('script', false, '', 'type="text/javascript"');
  864. $result .= 'function APIndividualRefresh(APID, JQAjaxTab, RefreshButtonSelector) {
  865. $.ajax({
  866. type: "GET",
  867. url: "' . self::URL_ME . '",
  868. data: {IndividualRefresh:true, apid:APID},
  869. success: function(result) {
  870. if ($.type(JQAjaxTab) === \'string\') {
  871. $("#"+JQAjaxTab).DataTable().ajax.reload();
  872. } else {
  873. $(JQAjaxTab).DataTable().ajax.reload();
  874. }
  875. if ($.type(RefreshButtonSelector) === \'string\') {
  876. $("#"+RefreshButtonSelector).find(\'img\').toggleClass("image_rotate");
  877. } else {
  878. $(RefreshButtonSelector).find(\'img\').toggleClass("image_rotate");
  879. }
  880. }
  881. });
  882. };
  883. function getAPInfo(APID, InfoBlckSelector, ReturnHTML = false, InSpoiler = false, RefreshButtonSelector) {
  884. $.ajax({
  885. type: "GET",
  886. url: "' . self::URL_ME . '",
  887. data: { IndividualRefresh:true,
  888. GetAPInfo:true,
  889. apid:APID,
  890. returnAsHTML:ReturnHTML,
  891. returnInSpoiler:InSpoiler
  892. },
  893. success: function(result) {
  894. if ($.type(RefreshButtonSelector) === \'string\') {
  895. $("#"+RefreshButtonSelector).find(\'img\').toggleClass("image_rotate");
  896. } else {
  897. $(RefreshButtonSelector).find(\'img\').toggleClass("image_rotate");
  898. }
  899. var InfoBlck = $(InfoBlckSelector);
  900. if ( !InfoBlck.length || !(InfoBlck instanceof jQuery)) {return false;}
  901. $(InfoBlck).html(result);
  902. }
  903. });
  904. }
  905. ';
  906. // making an event binding for "DelUserAssignment" button("red cross" near user's login) on "CPE create&assign form"
  907. // to be able to create "CPE create&assign form" dynamically and not to put it's content to every "Create CPE" button in JqDt tables
  908. // creating of "CPE create&assign form" dynamically reduces the amount of text and page weight dramatically
  909. $result .= '$(document).on("click", ".__UsrDelAssignButton", function(evt) {
  910. $("[name=assignoncreate]").val("");
  911. $(\'.__UsrAssignBlock\').html("' . __('Do not assign WiFi equipment to any user') . '");
  912. evt.preventDefault();
  913. return false;
  914. });
  915. ';
  916. // making an event binding for "CPE create&assign form" 'Submit' action to be able to create "CPE create&assign form" dynamically
  917. $result .= '$(document).on("submit", ".__CPEAssignAndCreateForm", function(evt) {
  918. //var FrmAction = \'"\' + $(".__CPEAssignAndCreateForm").attr("action") + \'"\';
  919. var FrmAction = $(".__CPEAssignAndCreateForm").attr("action");
  920. if ( $(".__CPEAACFormNoRedirChck").is(\':checked\') ) {
  921. var FrmData = $(".__CPEAssignAndCreateForm").serialize();
  922. evt.preventDefault();
  923. $.ajax({
  924. type: "POST",
  925. url: FrmAction,
  926. data: FrmData,
  927. success: function() {
  928. if ( $(".__CPEAACFormPageReloadChck").is(\':checked\') ) { location.reload(); }
  929. $( \'#\'+$(".__CPEAACFormReplaceCtrlID").val() ).replaceWith(\'' . web_ok_icon() . '\');
  930. $( \'#\'+$(".__CPEAACFormModalWindowID").val() ).dialog("close");
  931. }
  932. });
  933. }
  934. });
  935. ';
  936. $result .= wf_tag('script', true);
  937. $result .= wf_delimiter();
  938. return ($result);
  939. }
  940. /**
  941. * Renders available CPE JQDT list container
  942. *
  943. * @return string
  944. */
  945. public function renderMTList() {
  946. $result = '';
  947. $columns = array();
  948. $opts = '"order": [[ 0, "desc" ]]';
  949. $columns[] = ('Login');
  950. $columns[] = ('Address');
  951. $columns[] = ('Real Name');
  952. $columns[] = ('Tariff');
  953. $columns[] = ('IP');
  954. $columns[] = ('MAC');
  955. $columns[] = __('Signal') . ' (' . __('dBm') . ')';
  956. if ($this->WCPEEnabled) {
  957. $columns[] = __('Actions');
  958. }
  959. if (empty($this->allMTDevices) and ! empty($this->userLogin) and empty($this->userSwitch)) {
  960. $result .= show_window('', $this->messages->getStyledMessage(__('User MAC not found on devises'), 'warning'));
  961. } elseif (!empty($this->allMTDevices) and ! empty($this->userLogin) and ! empty($this->userSwitch)) {
  962. $result .= show_window(wf_img('skins/wifi.png') . ' ' . __(@$this->allMTDevices[$this->userSwitch]), wf_JqDtLoader($columns, '' . self::URL_ME . '&ajaxmt=true&mtid=' . $this->userSwitch . '&username=' . $this->userLogin, false, __('results'), 100, $opts));
  963. } elseif (!empty($this->allMTDevices) and empty($this->userLogin)) {
  964. // to prevent changing the keys order of $this->allMTDevices we are using "+" opreator and not all those "array_merge" and so on
  965. $QickAPsArray = array(-9999 => '') + $this->allMTDevices;
  966. foreach ($this->allMTDevices as $MTId => $eachMT) {
  967. $MTsigmonData = $this->cache->get(self::CACHE_PREFIX . $MTId, $this->cacheTime);
  968. if (!empty($MTsigmonData)) {
  969. foreach ($MTsigmonData as $eachmac => $eachsig) {
  970. if (strpos($eachsig, '/') !== false) {
  971. $columns[6] = __('Signal') . ' RX / TX (' . __('dBm') . ')';
  972. } else {
  973. $columns[6] = __('Signal') . ' (' . __('dBm') . ')';
  974. }
  975. break;
  976. }
  977. }
  978. $AjaxURLStr = '' . self::URL_ME . '&ajaxmt=true&mtid=' . $MTId . '';
  979. $JQDTId = 'jqdt_' . md5($AjaxURLStr);
  980. $APIDStr = 'APID_' . $MTId;
  981. $InfoButtonID = 'InfID_' . $MTId;
  982. $InfoBlockID = 'InfBlck_' . $MTId;
  983. $QuickAPLinkID = 'QuickAPLinkID_' . $MTId;
  984. $QuickAPDDLName = 'QuickAPDDL_' . wf_InputId();
  985. $QuickAPLink = wf_tag('span', false, '', 'id="' . $QuickAPLinkID . '"') .
  986. wf_img('skins/wifi.png') . wf_tag('span', true);
  987. if (isset($this->allMTSnmp[$MTId]['ip'])) {
  988. $apWebIfaceLink = wf_tag('a', false, '', 'href="http://' . $this->allMTSnmp[$MTId]['ip'] . '" target="_blank" title="' . __('Go to the web interface') . '"');
  989. $apWebIfaceLink .= wf_img('skins/ymaps/network.png');
  990. $apWebIfaceLink .= wf_tag('a', true);
  991. } else {
  992. $apWebIfaceLink = '';
  993. }
  994. $APInfoBlock = wf_tag('div', false, '', 'id="' . $InfoBlockID . '"');
  995. $APInfoBlock .= wf_tag('div', true);
  996. $APInfoButton = wf_tag('a', false, '', 'href="#" id="' . $InfoButtonID . '" title="' . __('Get system info for this AP') . '"');
  997. $APInfoButton .= wf_img('skins/icn_alert_info.png');
  998. $APInfoButton .= wf_tag('a', true);
  999. $APInfoButton .= wf_tag('script', false, '', 'type="text/javascript"');
  1000. $APInfoButton .= '$(\'#' . $InfoButtonID . '\').click(function(evt) {
  1001. $(\'img\', this).toggleClass("image_rotate");
  1002. getAPInfo(' . $MTId . ', "#' . $InfoBlockID . '", true, true, ' . $InfoButtonID . ');
  1003. evt.preventDefault();
  1004. return false;
  1005. });';
  1006. $APInfoButton .= wf_tag('script', true);
  1007. $refresh_button = wf_tag('a', false, '', 'href="#" id="' . $APIDStr . '" title="' . __('Refresh data for this AP') . '"');
  1008. $refresh_button .= wf_img('skins/refresh.gif');
  1009. $refresh_button .= wf_tag('a', true);
  1010. $refresh_button .= wf_tag('script', false, '', 'type="text/javascript"');
  1011. $refresh_button .= '$(\'#' . $APIDStr . '\').click(function(evt) {
  1012. $(\'img\', this).toggleClass("image_rotate");
  1013. APIndividualRefresh(' . $MTId . ', ' . $JQDTId . ', ' . $APIDStr . ');
  1014. evt.preventDefault();
  1015. return false;
  1016. });';
  1017. $refresh_button .= wf_tag('script', true);
  1018. if ($this->EnableQuickAPLinks) {
  1019. $QuickAPLinkInput = wf_tag('div', false, '', 'style="width: 100%; text-align: right; margin-top: 15px; margin-bottom: 20px"') .
  1020. wf_tag('font', false, '', 'style="font-weight: 600"') . __('Go to AP') . wf_tag('font', true) .
  1021. '&nbsp&nbsp' . wf_Selector($QuickAPDDLName, $QickAPsArray, '', '', true) .
  1022. wf_tag('script', false, '', 'type="text/javascript"') .
  1023. '$(\'[name="' . $QuickAPDDLName . '"]\').change(function(evt) {
  1024. //var LinkIDObjFromVal = $(\'a[href="#\'+$(this).val()+\'"]\');
  1025. //$(\'body,html\').animate( { scrollTop: $(LinkIDObjFromVal).offset().top - 30 }, 4500 );
  1026. var LinkIDObjFromVal = $(\'#QuickAPLinkID_\'+$(this).val());
  1027. $(\'body,html\').scrollTop( $(LinkIDObjFromVal).offset().top - 25 );
  1028. });' .
  1029. wf_tag('script', true) .
  1030. wf_tag('div', true);
  1031. } else {
  1032. $QuickAPLinkInput = '';
  1033. }
  1034. $result .= show_window($refresh_button . '&nbsp&nbsp&nbsp&nbsp' . $APInfoButton . '&nbsp&nbsp&nbsp&nbsp' . $apWebIfaceLink . '&nbsp&nbsp&nbsp&nbsp' . $QuickAPLink . '&nbsp&nbsp' .
  1035. __(@$eachMT), $APInfoBlock . wf_JqDtLoader($columns, $AjaxURLStr, false, __('results'), 100, $opts) .
  1036. $QuickAPLinkInput
  1037. );
  1038. }
  1039. } else {
  1040. $result .= show_window('', $this->messages->getStyledMessage(__('No devices for signal monitoring found'), 'warning'));
  1041. }
  1042. $result .= wf_delimiter();
  1043. return ($result);
  1044. }
  1045. public function renderMTListTabbed() {
  1046. $result = '';
  1047. $loopIndex = 0; // for dirty-dirty hack
  1048. if (!empty($this->existingMTSwitchGroups)) {
  1049. $result = '';
  1050. $columns = array();
  1051. $opts = '"order": [[ 0, "desc" ]]';
  1052. $columns[] = ('Login');
  1053. $columns[] = ('Address');
  1054. $columns[] = ('Real Name');
  1055. $columns[] = ('Tariff');
  1056. $columns[] = ('IP');
  1057. $columns[] = ('MAC');
  1058. $columns[] = __('Signal') . ' (' . __('dBm') . ')';
  1059. if ($this->WCPEEnabled) {
  1060. $columns[] = __('Actions');
  1061. }
  1062. foreach ($this->existingMTSwitchGroups as $io => $eachGroup) {
  1063. $groupName = (empty($eachGroup)) ? __('Ungrouped') : $eachGroup;
  1064. $groupWindowCaption = wf_tag('span', false, '', 'id="GroupLnk_' . $io . '"') .
  1065. $groupName .
  1066. wf_tag('span', true);
  1067. $displayGroup = array_filter($this->allMTSwitchGroups, function ($var) use ($eachGroup) {
  1068. return ($var['groupname'] == $eachGroup);
  1069. });
  1070. $curGroupMTDevices = array_intersect_key($this->allMTDevices, $displayGroup);
  1071. $tabClickScript = '';
  1072. $tabsList = array();
  1073. $tabsData = array();
  1074. $QuickAPDDLName = 'QuickAPDDL_' . wf_InputId();
  1075. $quickGrpDDLName = 'quickGrpDDLName_' . wf_InputId();
  1076. if ($this->EnableQuickAPLinks) {
  1077. $QuickGrpLinkInput = wf_tag('span', false, '', 'style="float: right; clear: right;') .
  1078. wf_tag('font', false, '', 'style="font-weight: 600;"') . __('Go to group') . wf_tag('font', true) .
  1079. wf_nbsp(2) . wf_Selector($quickGrpDDLName, $this->existingMTSwitchGroups, '', '', true) .
  1080. wf_tag('script', false, '', 'type="text/javascript"') .
  1081. '$(\'[name="' . $quickGrpDDLName . '"]\').change(function(evt) {
  1082. var LinkIDObjFromVal = $(\'#GroupLnk_\'+$(this).val());
  1083. $(\'body,html\').scrollTop( $(LinkIDObjFromVal).offset().top - 25 );
  1084. });' .
  1085. wf_tag('script', true) .
  1086. wf_tag('span', true);
  1087. } else {
  1088. $QuickGrpLinkInput = '';
  1089. }
  1090. foreach ($displayGroup as $MTId => $eachMT) {
  1091. $deviceInfo = $curGroupMTDevices[$MTId];
  1092. $MTsigmonData = $this->cache->get(self::CACHE_PREFIX . $MTId, $this->cacheTime);
  1093. if (!empty($MTsigmonData)) {
  1094. foreach ($MTsigmonData as $eachmac => $eachsig) {
  1095. if (strpos($eachsig, '/') !== false) {
  1096. $columns[6] = __('Signal') . ' RX / TX (' . __('dBm') . ')';
  1097. } else {
  1098. $columns[6] = __('Signal') . ' (' . __('dBm') . ')';
  1099. }
  1100. break;
  1101. }
  1102. }
  1103. $AjaxURLStr = '' . self::URL_ME . '&ajaxmt=true&mtid=' . $MTId . '';
  1104. $JQDTId = 'jqdt_' . md5($AjaxURLStr);
  1105. $APIDStr = 'APID_' . $MTId;
  1106. $InfoButtonID = 'InfID_' . $MTId;
  1107. $InfoBlockID = 'InfBlck_' . $MTId;
  1108. $QuickAPLinkID = 'QuickAPLinkID_' . $MTId;
  1109. $webIfaceLnkId = 'webIfaceLnk_' . $MTId;
  1110. if (isset($this->allMTSnmp[$MTId]['ip'])) {
  1111. $apWebIfaceLink = wf_tag('span', false, '', 'id="' . $webIfaceLnkId . '" href="http://' . $this->allMTSnmp[$MTId]['ip'] . '" target="_blank" title="' . __('Go to the web interface') . '" style="cursor: pointer;"');
  1112. $apWebIfaceLink .= wf_img('skins/ymaps/network.png');
  1113. $apWebIfaceLink .= wf_tag('span', true);
  1114. $apWebIfaceLink .= wf_tag('script', false, '', 'type="text/javascript"');
  1115. $apWebIfaceLink .= '$(\'#' . $webIfaceLnkId . '\').click(function(evt) {
  1116. window.open(\'http://' . $this->allMTSnmp[$MTId]['ip'] . '\', \'_blank\');
  1117. });
  1118. ';
  1119. $apWebIfaceLink .= wf_tag('script', true);
  1120. } else {
  1121. $apWebIfaceLink = '';
  1122. }
  1123. $APInfoBlock = wf_tag('div', false, '', 'id="' . $InfoBlockID . '"');
  1124. $APInfoBlock .= wf_tag('div', true);
  1125. $APInfoButton = wf_tag('span', false, '', 'href="#" id="' . $InfoButtonID . '" title="' . __('Get system info for this AP') . '" style="cursor: pointer;"');
  1126. $APInfoButton .= wf_img('skins/icn_alert_info.png');
  1127. $APInfoButton .= wf_tag('span', true);
  1128. $APInfoButton .= wf_tag('script', false, '', 'type="text/javascript"');
  1129. $APInfoButton .= '$(\'#' . $InfoButtonID . '\').click(function(evt) {
  1130. $(\'img\', this).toggleClass("image_rotate");
  1131. getAPInfo(' . $MTId . ', "#' . $InfoBlockID . '", true, true, ' . $InfoButtonID . ');
  1132. evt.preventDefault();
  1133. return false;
  1134. });';
  1135. $APInfoButton .= wf_tag('script', true);
  1136. if ($this->EnableQuickAPLinks) {
  1137. $tabClickScript = wf_tag('script', false, '', 'type="text/javascript"');
  1138. $tabClickScript .= '$(\'a[href="#' . $QuickAPLinkID . '"]\').click(function(evt) {
  1139. var tmpID = $(this).attr("href").replace("#QuickAPLinkID_", "");
  1140. if ($(\'[name="' . $QuickAPDDLName . '"]\').val() != tmpID) {
  1141. $(\'[name="' . $QuickAPDDLName . '"]\').val(tmpID);
  1142. }
  1143. });
  1144. ';
  1145. $tabClickScript .= wf_tag('script', true);
  1146. }
  1147. $refresh_button = wf_tag('span', false, '', 'href="#" id="' . $APIDStr . '" title="' . __('Refresh data for this AP') . '" style="cursor: pointer;"');
  1148. $refresh_button .= wf_img('skins/refresh.gif');
  1149. $refresh_button .= wf_tag('span', true);
  1150. $refresh_button .= wf_tag('script', false, '', 'type="text/javascript"');
  1151. $refresh_button .= '$(\'#' . $APIDStr . '\').click(function(evt) {
  1152. $(\'img\', this).toggleClass("image_rotate");
  1153. APIndividualRefresh(' . $MTId . ', ' . $JQDTId . ', ' . $APIDStr . ');
  1154. evt.preventDefault();
  1155. return false;
  1156. });';
  1157. $refresh_button .= wf_tag('script', true);
  1158. $tabsList[$QuickAPLinkID] = array('options' => '',
  1159. 'caption' => $refresh_button . wf_nbsp(2) . $APInfoButton . wf_nbsp(2) . $apWebIfaceLink .
  1160. wf_nbsp(2) . wf_img('skins/wifi.png') . wf_nbsp(2) . @$deviceInfo,
  1161. 'additional_data' => $tabClickScript
  1162. );
  1163. $tabsData[$QuickAPLinkID] = array('options' => 'style="padding: 0 0 0 2px;"',
  1164. 'body' => $APInfoBlock . wf_JqDtLoader($columns, $AjaxURLStr, false, 'CPE', 100, $opts),
  1165. 'additional_data' => ''
  1166. );
  1167. }
  1168. $tabsDivOpts = 'style="border: none; padding: 0; width: 100%;"';
  1169. $tabsLstOpts = 'style="border: none; background: #fff;"';
  1170. if ($this->EnableQuickAPLinks) {
  1171. $QuickAPLinkInput = wf_tag('div', false, '', 'style="margin-top: 15px; text-align: right;"') .
  1172. wf_tag('font', false, '', 'style="font-weight: 600"') . __('Go to AP') . wf_tag('font', true) .
  1173. wf_nbsp(2) . wf_Selector($QuickAPDDLName, $curGroupMTDevices, '', '', true) .
  1174. wf_tag('script', false, '', 'type="text/javascript"') .
  1175. '$(\'[name="' . $QuickAPDDLName . '"]\').change(function(evt) {
  1176. $(\'a[href="#QuickAPLinkID_\'+$(this).val()+\'"]\').click();
  1177. });' .
  1178. wf_tag('script', true) .
  1179. wf_tag('div', true);
  1180. } else {
  1181. $QuickAPLinkInput = '';
  1182. }
  1183. // ditry-dirty hack...khe-khe
  1184. if ($loopIndex < 1) {
  1185. $TabsCarouselInitLinking = wf_TabsCarouselInitLinking();
  1186. } else {
  1187. $TabsCarouselInitLinking = '';
  1188. }
  1189. $loopIndex++;
  1190. $tmpTabsDivId = 'ui-tabs_' . wf_InputId();
  1191. $result .= show_window($groupWindowCaption . $QuickGrpLinkInput, $QuickAPLinkInput . wf_delimiter(0) .
  1192. $TabsCarouselInitLinking . wf_TabsGen($tmpTabsDivId, $tabsList, $tabsData, $tabsDivOpts, $tabsLstOpts, true) .
  1193. $QuickAPLinkInput . wf_delimiter());
  1194. }
  1195. }
  1196. return ($result);
  1197. }
  1198. /**
  1199. * Renders MTSIGMON list container
  1200. *
  1201. * @return string
  1202. */
  1203. public function renderMTsigmonList($MTid) {
  1204. // Get MTSigmon cache gtom stroage by MT id
  1205. $MTsigmonData = $this->cache->get(self::CACHE_PREFIX . $MTid, $this->cacheTime);
  1206. $json = new wf_JqDtHelper();
  1207. if (!empty($MTsigmonData)) {
  1208. $data = array();
  1209. foreach ($MTsigmonData as $eachmac => $eachsig) {
  1210. $signalArr = explode(' / ', $eachsig);
  1211. // if RX/TX signal presents - lets take the lowest value
  1212. if (isset($signalArr[1])) {
  1213. $signal = ($signalArr[0] > $signalArr[1]) ? $signalArr[1] : $signalArr[0];
  1214. } else {
  1215. $signal = $signalArr[0];
  1216. }
  1217. //signal coloring
  1218. if ($signal < -79) {
  1219. $displaysig = wf_tag('font', false, '', 'color="#ab0000"') . $eachsig . wf_tag('font', true);
  1220. } elseif ($signal > -80 and $signal < -74) {
  1221. $displaysig = wf_tag('font', false, '', 'color="#FF5500"') . $eachsig . wf_tag('font', true);
  1222. } else {
  1223. $displaysig = wf_tag('font', false, '', 'color="#005502"') . $eachsig . wf_tag('font', true);
  1224. }
  1225. $allMacs = $this->allUserCpeMacs + $this->allUsermacs;
  1226. $allMacs = array_flip($allMacs);
  1227. //$login = in_array($eachmac, array_map('strtolower', $allMacs)) ? array_search($eachmac, array_map('strtolower', $allMacs)) : '';
  1228. $login = (isset($allMacs[$eachmac])) ? $allMacs[$eachmac] : '';
  1229. //user search highlight
  1230. if ((!empty($this->userLogin)) AND ( $this->userLogin == $login)) {
  1231. $hlStart = wf_tag('font', false, '', 'color="#0045ac"');
  1232. $hlEnd = wf_tag('font', true);
  1233. } else {
  1234. $hlStart = '';
  1235. $hlEnd = '';
  1236. }
  1237. $userLink = $login ? wf_Link('?module=userprofile&username=' . $login, web_profile_icon() . ' ' . @$this->allUserData[$login]['login'] . '', false) : '';
  1238. $userLogin = $login ? @$this->allUserData[$login]['login'] : '';
  1239. $userRealnames = $login ? @$this->allUserData[$login]['realname'] : '';
  1240. $userTariff = $login ? @$this->allUserData[$login]['Tariff'] : '';
  1241. $userIP = $login ? @$this->allUserData[$login]['ip'] : '';
  1242. if ($this->WCPEEnabled) {
  1243. $WCPE = new WifiCPE();
  1244. $ActionLnk = '';
  1245. // check if CPE with such MAC exists and create appropriate control
  1246. $WCPEID = $WCPE->getCPEIDByMAC($eachmac);
  1247. if (!empty($WCPEID)) {
  1248. $WCPEDATA = $WCPE->getCPEData($WCPEID);
  1249. if (!empty($WCPEDATA) && !empty($WCPEDATA['ip'])) {
  1250. $cpeWebIfaceLink = wf_tag('a', false, '', 'href="http://' . $WCPEDATA['ip'] . '" target="_blank" title="' . __('Go to the web interface') . '"');
  1251. $cpeWebIfaceLink .= wf_img('skins/ymaps/network.png');
  1252. $cpeWebIfaceLink .= wf_tag('a', true);
  1253. $ActionLnk .= $cpeWebIfaceLink . '&nbsp';
  1254. }
  1255. $ActionLnk .= wf_link($WCPE::URL_ME . '&editcpeid=' . $WCPEID, web_edit_icon());
  1256. } else {
  1257. $LnkID = wf_InputId();
  1258. $ActionLnk .= wf_tag('a', false, '', 'id="' . $LnkID . '" href="#" title="' . __('Create new CPE') . '"');
  1259. $ActionLnk .= web_icon_create();
  1260. $ActionLnk .= wf_tag('a', true);
  1261. $ActionLnk .= wf_tag('script', false, '', 'type="text/javascript"');
  1262. $ActionLnk .= '
  1263. $(\'#' . $LnkID . '\').click(function(evt) {
  1264. $.ajax({
  1265. type: "GET",
  1266. url: "' . $WCPE::URL_ME . '",
  1267. data: {
  1268. renderCreateForm:true,
  1269. renderDynamically:true,
  1270. renderedOutside:true,
  1271. reloadPageAfterDone:false,
  1272. userLogin:"' . $userLogin . '",
  1273. wcpeMAC:"' . $eachmac . '",
  1274. wcpeIP:"' . $userIP . '",
  1275. wcpeAPID:"' . $MTid . '",
  1276. ModalWID:"dialog-modal_' . $LnkID . '",
  1277. ModalWBID:"body_dialog-modal_' . $LnkID . '",
  1278. ActionCtrlID:"' . $LnkID . '"
  1279. },
  1280. success: function(result) {
  1281. $(document.body).append(result);
  1282. $(\'#dialog-modal_' . $LnkID . '\').dialog("open");
  1283. }
  1284. });
  1285. evt.preventDefault();
  1286. return false;
  1287. });
  1288. ';
  1289. $ActionLnk .= wf_tag('script', true);
  1290. }
  1291. }
  1292. $data[] = $userLink;
  1293. $data[] = $hlStart . @$this->allUserData[$login]['fulladress'] . $hlEnd;
  1294. $data[] = $hlStart . $userRealnames . $hlEnd;
  1295. $data[] = $hlStart . $userTariff . $hlEnd;
  1296. $data[] = $hlStart . $userIP . $hlEnd;
  1297. $data[] = $hlStart . $eachmac . $hlEnd;
  1298. $data[] = $displaysig;
  1299. if ($this->WCPEEnabled) {
  1300. $data[] = $ActionLnk;
  1301. }
  1302. $json->addRow($data);
  1303. unset($data);
  1304. }
  1305. }
  1306. $json->getJson();
  1307. }
  1308. public function useSwtichGroupsAndTabs() {
  1309. return ($this->switchGroupsEnabled and $this->groupAPsBySwitchGroupWithTabs);
  1310. }
  1311. /**
  1312. * Returns array like: $userLogin => $wifiSignal
  1313. *
  1314. * @return array
  1315. */
  1316. public function getAllWiFiSignals() {
  1317. $allSignals = array();
  1318. if (!empty($this->allMTDevices)) {
  1319. foreach ($this->allMTDevices as $MTId => $eachMT) {
  1320. $MTsigmonData[] = $this->cache->get(self::CACHE_PREFIX . $MTId, $this->cacheTime);
  1321. }
  1322. }
  1323. if (!empty($MTsigmonData)) {
  1324. $allMacs = $this->allUserCpeMacs + $this->allUsermacs;
  1325. $allMacs = array_flip($allMacs);
  1326. foreach ($MTsigmonData as $eachMTid) {
  1327. if (is_array($eachMTid) and ! empty($eachMTid)) {
  1328. foreach ($eachMTid as $eachmac => $eachsig) {
  1329. //$login = in_array($eachmac, array_map('strtolower', $allMacs)) ? array_search($eachmac, array_map('strtolower', $allMacs)) : '';
  1330. $login = (isset($allMacs[$eachmac])) ? $allMacs[$eachmac] : '';
  1331. if (!empty($login)) {
  1332. //$signal = explode('/', $eachsig);
  1333. $allSignals[$login] = $eachsig;
  1334. }
  1335. }
  1336. }
  1337. }
  1338. }
  1339. return ($allSignals);
  1340. }
  1341. }
  1342. ?>