api.wificpe.php 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716
  1. <?php
  2. /**
  3. * Client side wireless equipment management subsystem
  4. */
  5. class WifiCPE {
  6. /**
  7. * Contains system alter config as key=>value
  8. *
  9. * @var array
  10. */
  11. protected $altCfg = array();
  12. /**
  13. * Contains all available APs as id=>APdata
  14. *
  15. * @var array
  16. */
  17. public $allAP = array();
  18. /**
  19. * Contains available AP SSIDs if exists as id=>ssid
  20. *
  21. * @var array
  22. */
  23. protected $allSSids = array();
  24. /**
  25. * Contains all available devices models as modelid=>name
  26. *
  27. * @var array
  28. */
  29. protected $deviceModels = array();
  30. /**
  31. * Contains all available CPEs as id=>CPEdata
  32. *
  33. * @var array
  34. */
  35. public $allCPE = array();
  36. /**
  37. * Contains all available user to CPE assigns as id=>assignData
  38. *
  39. * @var array
  40. */
  41. protected $allAssigns = array();
  42. /**
  43. * Contains array of all existing users data as login=>userData
  44. *
  45. * @var array
  46. */
  47. protected $allUsersData = array();
  48. /**
  49. * Messages helper object placeholder
  50. *
  51. * @var object
  52. */
  53. protected $messages = '';
  54. /**
  55. * Is MTSIGMON enbaled?
  56. *
  57. * @var bool
  58. */
  59. protected $SigmonEnabled = false;
  60. /**
  61. * Placeholder for UbillingConfig object instance
  62. *
  63. * @var object
  64. */
  65. protected $ubConfig = null;
  66. /**
  67. * Sorting order of APs in lists and dropdowns
  68. * Possible values: id, ip, location
  69. *
  70. * @var string
  71. */
  72. protected $apSortOrder = "id";
  73. /**
  74. * Base module URL
  75. */
  76. const URL_ME = '?module=wcpe';
  77. /**
  78. * MTSIGMON module URL
  79. */
  80. const URL_SIGMON = '?module=mtsigmon';
  81. public function __construct() {
  82. global $ubillingConfig;
  83. $this->ubConfig = $ubillingConfig;
  84. $this->loadConfigs();
  85. $this->initMessages();
  86. $this->loadDeviceModels();
  87. $this->loadAps();
  88. $this->loadCPEs();
  89. $this->loadAssigns();
  90. $this->SigmonEnabled = $this->ubConfig->getAlterParam('MTSIGMON_ENABLED');
  91. $this->apSortOrder = ($this->ubConfig->getAlterParam('SIGMON_WCPE_AP_LIST_SORT')) ? $this->ubConfig->getAlterParam('SIGMON_WCPE_AP_LIST_SORT') : 'id';
  92. }
  93. /**
  94. * Loads system alter config to protected property for further usage
  95. *
  96. * @global object $ubillingConfig
  97. *
  98. * @return void
  99. */
  100. protected function loadConfigs() {
  101. $this->altCfg = $this->ubConfig->getAlter();
  102. }
  103. /**
  104. * Initalizes system message helper instance
  105. *
  106. * @return void
  107. */
  108. protected function initMessages() {
  109. $this->messages = new UbillingMessageHelper();
  110. }
  111. /**
  112. * Loads all available AP devices from switches directory
  113. *
  114. * @return void
  115. */
  116. protected function loadAps() {
  117. $query = "SELECT * from `switches` WHERE `desc` LIKE '%AP%' ORDER BY `location` ASC;";
  118. $all = simple_queryall($query);
  119. if (!empty($all)) {
  120. foreach ($all as $io => $each) {
  121. $this->allAP[$each['id']] = $each;
  122. $apSsid = $this->extractSsid($each['desc']);
  123. if (!empty($apSsid)) {
  124. $this->allSSids[$each['id']] = $apSsid;
  125. }
  126. }
  127. }
  128. }
  129. /**
  130. * Ectracts SSID if exists from AP description
  131. *
  132. * @param string $desc
  133. *
  134. * @return string
  135. */
  136. protected function extractSsid($desc) {
  137. $result = '';
  138. if (!empty($desc)) {
  139. $rawDesc = explode(' ', $desc);
  140. if (!empty($rawDesc)) {
  141. foreach ($rawDesc as $io => $each) {
  142. if (ispos($each, 'ssid:')) {
  143. $result = $each;
  144. }
  145. }
  146. }
  147. }
  148. return ($result);
  149. }
  150. /**
  151. * Loads all available CPE to protected property
  152. *
  153. * @return void
  154. */
  155. protected function loadCPEs() {
  156. $query = "SELECT * from `wcpedevices`;";
  157. $all = simple_queryall($query);
  158. if (!empty($all)) {
  159. foreach ($all as $io => $each) {
  160. $this->allCPE[$each['id']] = $each;
  161. }
  162. }
  163. }
  164. /**
  165. * Loads existing CPE assigns from database
  166. *
  167. * @return void
  168. */
  169. protected function loadAssigns() {
  170. $query = "SELECT * from `wcpeusers`";
  171. $all = simple_queryall($query);
  172. if (!empty($all)) {
  173. foreach ($all as $io => $each) {
  174. $this->allAssigns[$each['id']] = $each;
  175. }
  176. }
  177. }
  178. /**
  179. * Loads all existing users data into protected property
  180. *
  181. * @return void
  182. */
  183. protected function loadUserData() {
  184. $this->allUsersData = zb_UserGetAllDataCache();
  185. }
  186. /**
  187. * Loads available device models from database
  188. *
  189. * @return void
  190. */
  191. protected function loadDeviceModels() {
  192. $this->deviceModels = zb_SwitchModelsGetAllTag();
  193. }
  194. public function getAllCPE() {
  195. if (empty($this->allCPE)) {
  196. $this->loadCPEs();
  197. }
  198. return $this->allCPE;
  199. }
  200. /**
  201. * Returns CPE ID from database if record with CPEMAC found or false if not
  202. *
  203. * @param string $CPEMAC
  204. *
  205. * @return bool/int
  206. */
  207. public function getCPEIDByMAC($CPEMAC) {
  208. if (empty($this->allCPE) or empty($CPEMAC)) {
  209. return false;
  210. }
  211. $query = "SELECT * from `wcpedevices` WHERE `mac` = '" . strtolower($CPEMAC) . "';";
  212. $all = simple_queryall($query);
  213. if (!empty($all)) {
  214. return $all[0]['id'];
  215. } else {
  216. return false;
  217. }
  218. }
  219. /**
  220. * Returns array with all CPE data from database if record with CPEID found or false if not
  221. *
  222. * @param $CPEID
  223. *
  224. * @return array|bool
  225. */
  226. public function getCPEData($CPEID) {
  227. if (empty($this->allCPE) or empty($CPEID)) {
  228. return false;
  229. }
  230. $query = "SELECT * from `wcpedevices` WHERE `id` = " . $CPEID . ";";
  231. $all = simple_queryall($query);
  232. if (!empty($all)) {
  233. return $all[0];
  234. } else {
  235. return false;
  236. }
  237. }
  238. /**
  239. * Creates new CPE in database
  240. *
  241. * @param int $modelId
  242. * @param string $ip
  243. * @param string $mac
  244. * @param string $location
  245. * @param bool $bridgeMode
  246. * @param int $uplinkApId
  247. * @param string $geo
  248. *
  249. * @return void/string on error
  250. */
  251. public function createCPE($modelId, $ip, $mac, $snmp, $location, $bridgeMode = false, $uplinkApId, $geo) {
  252. $result = '';
  253. $modelId = vf($modelId, 3);
  254. $ipF = mysql_real_escape_string($ip);
  255. $mac = strtolower_utf8($mac);
  256. $macF = mysql_real_escape_string($mac);
  257. $snmpF = mysql_real_escape_string($snmp);
  258. $loactionF = mysql_real_escape_string($location);
  259. $bridgeMode = ($bridgeMode) ? 1 : 0;
  260. $uplinkApId = vf($uplinkApId, 3);
  261. $geoF = mysql_real_escape_string($geo);
  262. if (isset($this->deviceModels[$modelId])) {
  263. if (empty($macF)) {
  264. $macCheckFlag = true;
  265. } else {
  266. $macCheckFlag = check_mac_format($macF);
  267. }
  268. if ($macCheckFlag) {
  269. $query = "INSERT INTO `wcpedevices` (`id`, `modelid`, `ip`, `mac`, `snmp`, `location`, `bridge`, `uplinkapid`, `uplinkcpeid`, `geo`) "
  270. . "VALUES (NULL, '" . $modelId . "', '" . $ipF . "', '" . $macF . "', '" . $snmpF . "', '" . $loactionF . "', '" . $bridgeMode . "', '" . $uplinkApId . "', NULL, '" . $geoF . "');";
  271. nr_query($query);
  272. $newId = simple_get_lastid('wcpedevices');
  273. log_register('WCPE CREATE [' . $newId . ']');
  274. $this->loadCPEs();
  275. } else {
  276. $result .= $this->messages->getStyledMessage(__('This MAC have wrong format'), 'error');
  277. }
  278. } else {
  279. $result .= $this->messages->getStyledMessage(__('Strange exeption') . ': MODELID_NOT_EXISTS', 'error');
  280. }
  281. return ($result);
  282. }
  283. /**
  284. * Deletes existing CPE from database
  285. *
  286. * @param int $cpeId
  287. *
  288. * @return void/string
  289. */
  290. public function deleteCPE($cpeId) {
  291. $result = '';
  292. $cpeId = vf($cpeId, 3);
  293. if (isset($this->allCPE[$cpeId])) {
  294. if (!$this->isCPEProtected($cpeId)) {
  295. $query = "DELETE from `wcpedevices` WHERE `id`='" . $cpeId . "';";
  296. nr_query($query);
  297. log_register('WCPE DELETE [' . $cpeId . ']');
  298. } else {
  299. $result .= $this->messages->getStyledMessage(__('Some users is assigned to this CPE'), 'warning');
  300. }
  301. } else {
  302. $result .= $this->messages->getStyledMessage(__('Strange exeption') . ': CPEID_NOT_EXISTS', 'error');
  303. }
  304. return ($result);
  305. }
  306. /**
  307. * Checks is CPE assigned with some users or not?
  308. *
  309. * @param int $cpeId
  310. *
  311. * @return string
  312. */
  313. protected function isCPEProtected($cpeId) {
  314. $result = false;
  315. if (!empty($this->allAssigns)) {
  316. foreach ($this->allAssigns as $io => $each) {
  317. if ($each['cpeid'] == $cpeId) {
  318. $result = true;
  319. break;
  320. }
  321. }
  322. }
  323. return ($result);
  324. }
  325. /**
  326. * Returns user CPE assign ID or 0 if assign not exists
  327. *
  328. * @param string $userLogin
  329. *
  330. * @return int
  331. */
  332. protected function userHaveCPE($userLogin) {
  333. $result = 0;
  334. if (!empty($this->allAssigns)) {
  335. foreach ($this->allAssigns as $io => $each) {
  336. if ($each['login'] == $userLogin) {
  337. $result = $each['id'];
  338. break;
  339. }
  340. }
  341. }
  342. return ($result);
  343. }
  344. /**
  345. * Returns user CPE assign ID or 0 if assign not exists
  346. *
  347. * @param int $cpeId
  348. *
  349. * @return int
  350. */
  351. protected function cpeHaveUser($cpeId) {
  352. $result = 0;
  353. if (!empty($this->allAssigns)) {
  354. foreach ($this->allAssigns as $io => $each) {
  355. if ($each['cpeid'] == $cpeId) {
  356. $result = $each['id'];
  357. break;
  358. }
  359. }
  360. }
  361. return ($result);
  362. }
  363. /**
  364. * Renders CPE creation form
  365. *
  366. * @param string $userLogin
  367. * @param string $CPEMAC
  368. * @param string $CPEIP
  369. * @param string $APID
  370. * @param bool $RenderedOutside
  371. * @param bool $PageReloadAfterDone
  372. * @param string $CtrlIDToReplaceAfterDone
  373. * @param string $ModalWindowID
  374. *
  375. * @return string
  376. */
  377. public function renderCPECreateForm($userLogin = '', $CPEMAC = '', $CPEIP = '', $APID = '', $RenderedOutside = false, $PageReloadAfterDone = false, $CtrlIDToReplaceAfterDone = '', $ModalWindowID = ''
  378. ) {
  379. $result = '';
  380. if (!empty($this->deviceModels)) {
  381. $apTmp = array('' => __('No'));
  382. if (!empty($this->allAP)) {
  383. foreach ($this->allAP as $io => $each) {
  384. switch ($this->apSortOrder) {
  385. case "id":
  386. case "location":
  387. $apTmp[$each['id']] = $each['location'] . ' - ' . $each['ip'] . ' ' . @$this->allSSids[$each['id']];
  388. break;
  389. case "ip":
  390. $apTmp[$each['id']] = $each['ip'] . ' - ' . $each['location'] . ' ' . @$this->allSSids[$each['id']];
  391. }
  392. }
  393. }
  394. $inputs = wf_HiddenInput('createnewcpe', 'true');
  395. $inputs .= wf_Selector('newcpemodelid', $this->deviceModels, __('Model'), '', true);
  396. $inputs .= wf_CheckInput('newcpebridge', __('Bridge mode'), true, false);
  397. $inputs .= wf_TextInput('newcpeip', __('IP'), $CPEIP, true, 15);
  398. $inputs .= wf_TextInput('newcpemac', __('MAC'), $CPEMAC, true, 15);
  399. $inputs .= wf_TextInput('newcpesnmp', __('SNMP community'), '', true, 15);
  400. $inputs .= wf_TextInput('newcpelocation', __('Location'), '', true, 25);
  401. $inputs .= wf_TextInput('newcpegeo', __('Geo location'), '', true, 25);
  402. $inputs .= wf_Selector('newcpeuplinkapid', $apTmp, __('Connected to AP'), $APID, true);
  403. if (!empty($userLogin)) {
  404. $TmpBlockID = 'UsrLogin_' . wf_InputId();
  405. $inputs .= wf_HiddenInput('assignoncreate', $userLogin);
  406. $inputs .= wf_tag('br', true);
  407. $inputs .= wf_tag('span', false, '__UsrAssignBlock', 'id="' . $TmpBlockID . '"');
  408. $inputs .= __('Assign WiFi equipment to user') . ': ';
  409. $inputs .= wf_tag('b', false);
  410. $inputs .= $userLogin . '&nbsp&nbsp';
  411. $inputs .= wf_tag('b', true);
  412. $TmpLnkID = 'DelUsrLogin_' . wf_InputId();
  413. $inputs .= wf_tag('script', false, '', 'type="text/javascript"');
  414. $inputs .= '$(function() {
  415. $(\'#' . $TmpLnkID . '\').click(function(evt) {
  416. $("[name=assignoncreate]").val("");
  417. $(\'#' . $TmpBlockID . '\').html("' . __('Do not assign WiFi equipment to any user') . '");
  418. evt.preventDefault();
  419. return false;
  420. });
  421. });
  422. ';
  423. $inputs .= wf_tag('script', true);
  424. $inputs .= wf_tag('a', false, '__UsrDelAssignButton', 'id="' . $TmpLnkID . '" href="#" style="vertical-align: sub;"');
  425. $inputs .= web_delete_icon();
  426. $inputs .= wf_tag('a', true);
  427. $inputs .= wf_tag('span', true);
  428. $inputs .= wf_tag('br', true);
  429. }
  430. $NoRedirChkID = 'NoRedirChk_' . wf_InputId();
  431. $ReloadChkID = 'ReloadChk_' . wf_InputId();
  432. $SubmitID = 'Submit_' . wf_InputId();
  433. $FormID = 'Form_' . wf_InputId();
  434. $HiddenReplID = 'ReplaceCtrlID_' . wf_InputId();
  435. $HiddenModalID = 'ModalWindowID_' . wf_InputId();
  436. $inputs .= wf_tag('br');
  437. $inputs .= ( ($RenderedOutside) ? wf_CheckInput('NoRedirect', __('Do not redirect anywhere: just add & close'), true, true, $NoRedirChkID, '__CPEAACFormNoRedirChck') : '' );
  438. $inputs .= ( ($PageReloadAfterDone) ? wf_CheckInput('', __('Reload page after action'), true, true, $ReloadChkID, '__CPEAACFormPageReloadChck') : '' );
  439. $inputs .= wf_tag('br');
  440. $inputs .= wf_Submit(__('Create'), $SubmitID);
  441. $result = wf_Form(self::URL_ME, 'POST', $inputs, 'glamour __CPEAssignAndCreateForm', '', $FormID);
  442. $result .= wf_HiddenInput('', $CtrlIDToReplaceAfterDone, $HiddenReplID, '__CPEAACFormReplaceCtrlID');
  443. $result .= wf_HiddenInput('', $ModalWindowID, $HiddenModalID, '__CPEAACFormModalWindowID');
  444. $result .= wf_tag('script', false, '', 'type="text/javascript"');
  445. $result .= '
  446. $(\'#' . $FormID . '\').submit(function(evt) {
  447. if ( $(\'#' . $NoRedirChkID . '\').is(\':checked\') ) {
  448. var FrmData = $(\'#' . $FormID . '\').serialize();
  449. evt.preventDefault();
  450. $.ajax({
  451. type: "POST",
  452. url: "' . self::URL_ME . '",
  453. data: FrmData,
  454. success: function() {
  455. if ( $(\'#' . $ReloadChkID . '\').is(\':checked\') ) { location.reload(); }
  456. $( \'#\'+$(\'#' . $HiddenReplID . '\').val() ).replaceWith(\'' . web_ok_icon() . '\');
  457. $( \'#\'+$(\'#' . $HiddenModalID . '\').val() ).dialog("close");
  458. }
  459. });
  460. }
  461. });
  462. ';
  463. $result .= wf_tag('script', true);
  464. } else {
  465. $result = $this->messages->getStyledMessage(__('No') . ' ' . __('Equipment models'), 'error');
  466. }
  467. return ($result);
  468. }
  469. /**
  470. * Renders available CPE list container
  471. *
  472. * @return string
  473. */
  474. public function renderCPEList($userLogin = '') {
  475. $result = '';
  476. if (!empty($userLogin)) {
  477. $assignPostfix = '&assignpf=' . $userLogin;
  478. } else {
  479. $assignPostfix = '';
  480. }
  481. if (!empty($this->allCPE)) {
  482. $columns = array('ID', 'Model', 'IP', 'MAC', 'SNMP community', 'Location', 'Geo location', 'Connected to AP', 'Bridge mode', 'Actions');
  483. $opts = '"order": [[ 0, "desc" ]]';
  484. $result = wf_JqDtLoader($columns, self::URL_ME . '&ajcpelist=true' . $assignPostfix, false, __('CPE'), 100, $opts);
  485. } else {
  486. $result = $this->messages->getStyledMessage(__('Nothing to show'), 'info');
  487. }
  488. return ($result);
  489. }
  490. /**
  491. * Renders JSON data of available CPE devices
  492. *
  493. * @return void
  494. */
  495. public function getCPEListJson($userLogin = '') {
  496. $json = new wf_JqDtHelper();
  497. if (!empty($this->allCPE)) {
  498. foreach ($this->allCPE as $io => $each) {
  499. $data[] = $each['id'];
  500. $data[] = @$this->deviceModels[$each['modelid']];
  501. $data[] = $each['ip'];
  502. $data[] = $each['mac'];
  503. $data[] = $each['snmp'];
  504. $data[] = $each['location'];
  505. $data[] = $each['geo'];
  506. if (isset($this->allSSids[$each['uplinkapid']])) {
  507. $apLabel = @$this->allAP[$each['uplinkapid']]['ip'] . ' - ' . @$this->allSSids[$each['uplinkapid']];
  508. } else {
  509. $apLabel = @$this->allAP[$each['uplinkapid']]['ip'] . ' - ' . @$this->allAP[$each['uplinkapid']]['location'];
  510. }
  511. $data[] = $apLabel;
  512. $data[] = web_bool_led($each['bridge']);
  513. $actLinks = '';
  514. if (!empty($each['ip'])) {
  515. $cpeWebIfaceLink = wf_tag('a', false, '', 'href="http://' . $each['ip'] . '" target="_blank" title="' . __('Go to the web interface') . '"');
  516. $cpeWebIfaceLink .= wf_img('skins/ymaps/network.png');
  517. $cpeWebIfaceLink .= wf_tag('a', true);
  518. $actLinks .= $cpeWebIfaceLink . '&nbsp';
  519. }
  520. if (empty($userLogin)) {
  521. $actLinks .= wf_JSAlert(self::URL_ME . '&deletecpeid=' . $each['id'], web_delete_icon(), $this->messages->getDeleteAlert()) . ' ';
  522. $actLinks .= wf_link(self::URL_ME . '&editcpeid=' . $each['id'], web_edit_icon('Edit'));
  523. } else {
  524. $actLinks = wf_link(self::URL_ME . '&newcpeassign=' . $each['id'] . '&assignuslo=' . $userLogin, web_icon_create('Assign'));
  525. }
  526. $data[] = $actLinks;
  527. $json->addRow($data);
  528. unset($data);
  529. }
  530. }
  531. $json->getJson();
  532. }
  533. /**
  534. * Checks is user available for CPE assign?
  535. *
  536. * @param string $userLogin
  537. *
  538. * @return bool
  539. */
  540. protected function isUserUnassigned($userLogin) {
  541. $result = true;
  542. if (!empty($this->allAssigns)) {
  543. foreach ($this->allAssigns as $io => $each) {
  544. if ($each['login'] == $userLogin) {
  545. $result = false;
  546. break;
  547. }
  548. }
  549. }
  550. return ($result);
  551. }
  552. /**
  553. * Assigns existing CPE to some user login
  554. *
  555. * @param int $cpeId
  556. * @param string $userLogin
  557. *
  558. * @return void/string
  559. */
  560. public function assignCPEUser($cpeId, $userLogin) {
  561. $result = '';
  562. $cpeId = vf($cpeId, 3);
  563. $userLoginF = mysql_real_escape_string($userLogin);
  564. if (isset($this->allCPE[$cpeId])) {
  565. if ($this->isUserUnassigned($userLogin)) {
  566. $query = "INSERT INTO `wcpeusers` (`id`,`cpeid`,`login`) VALUES (NULL,'" . $cpeId . "','" . $userLoginF . "');";
  567. nr_query($query);
  568. $newId = simple_get_lastid('wcpeusers');
  569. log_register('WCPE [' . $cpeId . '] ASSIGN (' . $userLogin . ') ID [' . $newId . ']');
  570. } else {
  571. $result .= $this->messages->getStyledMessage(__('Strange exeption') . ': USERLOGIN_ALREADY_ASSIGNED', 'error');
  572. }
  573. } else {
  574. $result .= $this->messages->getStyledMessage(__('Strange exeption') . ': CPEID_NOT_EXISTS', 'error');
  575. }
  576. return ($result);
  577. }
  578. /**
  579. * Deletes CPE to user assign from database
  580. *
  581. * @param int $assignId
  582. *
  583. * @return void/string
  584. */
  585. public function deassignCPEUser($assignId) {
  586. $result = '';
  587. $assignId = vf($assignId, 3);
  588. if (isset($this->allAssigns[$assignId])) {
  589. $assignData = $this->allAssigns[$assignId];
  590. $query = "DELETE from `wcpeusers` WHERE `id`='" . $assignId . "';";
  591. nr_query($query);
  592. log_register('WCPE [' . $assignData['cpeid'] . '] DEASSIGN (' . $assignData['login'] . ') ID [' . $assignId . ']');
  593. } else {
  594. $result .= $this->messages->getStyledMessage(__('Strange exeption') . ': ASSIGNID_NOT_EXISTS', 'error');
  595. }
  596. return ($result);
  597. }
  598. /**
  599. * Renders CPE edit form
  600. *
  601. * @param int $cpeId
  602. *
  603. * @return string
  604. */
  605. public function renderCPEEditForm($cpeId) {
  606. $result = '';
  607. $cpeId = vf($cpeId, 3);
  608. if (isset($this->allCPE[$cpeId])) {
  609. if (!empty($this->deviceModels)) {
  610. $cpeData = $this->allCPE[$cpeId];
  611. $apTmp = array('' => __('No'));
  612. if (!empty($this->allAP)) {
  613. foreach ($this->allAP as $io => $each) {
  614. switch ($this->apSortOrder) {
  615. case "id":
  616. case "location":
  617. $apTmp[$each['id']] = $each['location'] . ' - ' . $each['ip'] . ' ' . @$this->allSSids[$each['id']];
  618. break;
  619. case "ip":
  620. $apTmp[$each['id']] = $each['ip'] . ' - ' . $each['location'] . ' ' . @$this->allSSids[$each['id']];
  621. }
  622. }
  623. $inputs = wf_HiddenInput('editcpe', $cpeId);
  624. $inputs .= wf_Selector('editcpemodelid', $this->deviceModels, __('Model'), $cpeData['modelid'], true);
  625. $inputs .= wf_CheckInput('editcpebridge', __('Bridge mode'), true, $cpeData['bridge']);
  626. $inputs .= wf_TextInput('editcpeip', __('IP'), $cpeData['ip'], true, 15);
  627. $inputs .= wf_TextInput('editcpemac', __('MAC'), $cpeData['mac'], true, 15);
  628. $inputs .= wf_TextInput('editcpesnmp', __('SNMP community'), $cpeData['snmp'], true, 15);
  629. $inputs .= wf_TextInput('editcpelocation', __('Location'), $cpeData['location'], true, 25);
  630. $inputs .= wf_TextInput('editcpegeo', __('Geo location'), $cpeData['geo'], true, 25);
  631. $inputs .= wf_Selector('editcpeuplinkapid', $apTmp, __('Connected to AP'), $cpeData['uplinkapid'], true);
  632. $inputs .= wf_tag('br');
  633. $inputs .= wf_Submit(__('Save'));
  634. $result = wf_Form('', 'POST', $inputs, 'glamour');
  635. $result .= wf_tag('br');
  636. if ($this->SigmonEnabled) {
  637. $SigMon = new MTsigmon();
  638. $CtrlID = wf_InputId();
  639. $APSignalContainerID = 'APSignal_' . $CtrlID;
  640. $APPollDTContainerID = 'APSignalPollDT_' . $CtrlID;
  641. $APSignalControls = $this->getAPCPESignalControls($cpeData['mac'], '#' . $APSignalContainerID, '#' . $APPollDTContainerID, $cpeData['uplinkapid']);
  642. if (empty($APSignalControls)) {
  643. $LastPollDateAP = '';
  644. $SignalLevelLabelAP = '';
  645. $RefreshButtonAP = '';
  646. } else {
  647. $LastPollDateAP = $APSignalControls['LastPollDate'];
  648. $SignalLevelLabelAP = $APSignalControls['SignalLevelLabel'];
  649. $RefreshButtonAP = $APSignalControls['RefreshButton'];
  650. }
  651. $CPESignalContainerID = 'CPESignal_' . $CtrlID;
  652. $CPEPollDTContainerID = 'CPESignalPollDT_' . $CtrlID;
  653. $CPESignalControls = $this->getAPCPESignalControls($cpeData['mac'], '#' . $CPESignalContainerID, '#' . $CPEPollDTContainerID, 0, $cpeData['ip'], $cpeData['snmp']);
  654. if (empty($CPESignalControls)) {
  655. $LastPollDateCPE = '';
  656. $SignalLevelLabelCPE = '';
  657. $RefreshButtonCPE = '';
  658. } else {
  659. $LastPollDateCPE = $CPESignalControls['LastPollDate'];
  660. $SignalLevelLabelCPE = $CPESignalControls['SignalLevelLabel'];
  661. $RefreshButtonCPE = $CPESignalControls['RefreshButton'];
  662. }
  663. $cells = wf_TableCell(__('Signal level on AP'), '20%', 'row2');
  664. $cells .= wf_TableCell($SignalLevelLabelAP, '55%', '', 'id="' . $APSignalContainerID . '"');
  665. $cells .= wf_TableCell($RefreshButtonAP);
  666. $cells .= wf_TableCell($LastPollDateAP, '25%', '', 'id="' . $APPollDTContainerID . '"');
  667. $rows = wf_TableRow($cells, 'row3');
  668. $cells = wf_TableCell(__('Signal level on CPE'), '20%', 'row2');
  669. $cells .= wf_TableCell($SignalLevelLabelCPE, '55%', '', 'id="' . $CPESignalContainerID . '"');
  670. $cells .= wf_TableCell($RefreshButtonCPE);
  671. $cells .= wf_TableCell($LastPollDateCPE, '25%', '', 'id="' . $CPEPollDTContainerID . '"');
  672. $rows .= wf_TableRow($cells, 'row3');
  673. $result .= wf_TableBody($rows, '100%', 0, '');
  674. $SignalGraphAP = $SigMon->renderSignalGraphs($cpeData['mac'], true, true, false, true, true);
  675. $SignalGraphCPE = $SigMon->renderSignalGraphs($cpeData['mac'], false, true, false, true, true);
  676. $SignalGraphs = '';
  677. $Hyphen = ' - ';
  678. if (empty($SignalGraphAP)) {
  679. $GraphContainerSelector = 'NoAPDataBlck_' . $CtrlID;
  680. $GraphRefreshButton = $this->getAPCPEGraphRefreshButton($cpeData['mac'], '#' . $GraphContainerSelector, true, true, true);
  681. $SignalGraphs .= wf_tag('div', false, '', 'id="' . $GraphContainerSelector . '" style="margin: 10px auto; display: table; font-size: 14px; font-weight: 600;"');
  682. $SignalGraphs .= __('No data from AP yet') . (( empty($GraphRefreshButton) ) ? '' : $Hyphen);
  683. $SignalGraphs .= $GraphRefreshButton;
  684. $SignalGraphs .= wf_tag('div', true);
  685. } else {
  686. $GraphContainerID = 'SpoilerAP_' . $CtrlID;
  687. $GraphContainerSelector = '#' . $GraphContainerID . ' .spoiler_body';
  688. $GraphRefreshButton = $this->getAPCPEGraphRefreshButton($cpeData['mac'], $GraphContainerSelector, true, false);
  689. $SignalGraphs .= wf_Spoiler($SignalGraphAP, $GraphRefreshButton . '&nbsp&nbsp' . __('Signal data from AP'), true, $GraphContainerID, '', '', '', 'style="margin: 10px auto; display: table;"');
  690. }
  691. if (empty($SignalGraphCPE)) {
  692. $GraphContainerSelector = 'NoCPEDataBlck_' . $CtrlID;
  693. $GraphRefreshButton = $this->getAPCPEGraphRefreshButton($cpeData['mac'], '#' . $GraphContainerSelector, false, true, true);
  694. $SignalGraphs .= wf_tag('div', false, '', 'id="' . $GraphContainerSelector . '" style="margin: 10px auto; display: table; font-size: 14px; font-weight: 600;"');
  695. $SignalGraphs .= __('No data from CPE yet') . (( empty($GraphRefreshButton) ) ? '' : $Hyphen);
  696. $SignalGraphs .= $GraphRefreshButton;
  697. $SignalGraphs .= wf_tag('div', true);
  698. } else {
  699. $GraphContainerID = 'SpoilerCPE_' . $CtrlID;
  700. $GraphContainerSelector = '#' . $GraphContainerID . ' .spoiler_body';
  701. $GraphRefreshButton = $this->getAPCPEGraphRefreshButton($cpeData['mac'], $GraphContainerSelector, false, false);
  702. $SignalGraphs .= wf_Spoiler($SignalGraphCPE, $GraphRefreshButton . '&nbsp&nbsp' . __('Signal data from CPE'), true, $GraphContainerID, '', '', '', 'style="margin: 10px auto; display: table;"');
  703. }
  704. $result .= wf_Spoiler($SignalGraphs, __('Signal levels history graphs'), true);
  705. $result .= wf_tag('script', false, '', 'type="text/javascript"');
  706. $result .= $this->getSignalRefreshJS();
  707. $result .= $this->getGraphRefreshJS();
  708. $result .= wf_tag('script', true);
  709. if (!empty($cpeData['uplinkapid'])) {
  710. $result .= $this->renderAPEssentialData($cpeData['uplinkapid'], $SigMon);
  711. }
  712. }
  713. if (!empty($cpeData['ip'])) {
  714. $cpeWebIfaceLink = wf_tag('a', false, 'ubButton', 'href="http://' . $cpeData['ip'] . '" target="_blank" title="' . __('Go to the web interface') . '"');
  715. $cpeWebIfaceLink .= wf_img('skins/ymaps/network.png') . ' CPE - ' . __('Go to the web interface');
  716. $cpeWebIfaceLink .= wf_tag('a', true);
  717. $result .= $cpeWebIfaceLink . '&nbsp&nbsp&nbsp';
  718. }
  719. if (!empty($cpeData['uplinkapid']) and ! empty($this->allAP[$cpeData['uplinkapid']])) {
  720. $apWebIfaceLink = wf_tag('a', false, 'ubButton', 'href="http://' . $this->allAP[$cpeData['uplinkapid']]['ip'] . '" target="_blank" title="' . __('Go to the web interface') . '"');
  721. $apWebIfaceLink .= wf_img('skins/ymaps/network.png') . ' AP - ' . __('Go to the web interface');
  722. $apWebIfaceLink .= wf_tag('a', true);
  723. $result .= $apWebIfaceLink . '&nbsp&nbsp&nbsp';
  724. $result .= wf_Link('?module=switches&edit=' . $cpeData['uplinkapid'], web_edit_icon('Navigate to AP') . ' ' . __('Navigate to AP'), false, 'ubButton');
  725. $result .= '&nbsp&nbsp&nbsp';
  726. }
  727. if (!empty($cpeData['geo'])) {
  728. $result .= wf_Link('?module=switchmap&finddevice=' . $cpeData['geo'], web_icon_search('Find on map') . ' ' . __('Find on map'), false, 'ubButton');
  729. $result .= '&nbsp&nbsp&nbsp';
  730. }
  731. if ($this->isCPEProtected($cpeId)) {
  732. $result .= wf_JSAlert('', web_delete_icon() . ' ' . __('Delete'), __('Some users is assigned to this CPE'), '', 'ubButton');
  733. } else {
  734. $result .= wf_Link(self::URL_ME . '&deletecpeid=' . $cpeId, web_delete_icon('Delete') . ' ' . __('Delete'), false, 'ubButton');
  735. }
  736. }
  737. } else {
  738. $result = $this->messages->getStyledMessage(__('No') . ' ' . __('Equipment models'), 'error');
  739. }
  740. } else {
  741. $result .= $this->messages->getStyledMessage(__('Strange exeption') . ': CPEID_NOT_EXISTS', 'error');
  742. }
  743. return ($result);
  744. }
  745. /**
  746. * Performs CPE changes, return string on error
  747. *
  748. * @return void/string
  749. */
  750. public function saveCPE() {
  751. $result = '';
  752. if (wf_CheckPost(array('editcpe', 'editcpemodelid'))) {
  753. $cpeId = vf($_POST['editcpe']);
  754. if (isset($this->allCPE[$cpeId])) {
  755. $cpeData = $this->allCPE[$cpeId];
  756. $where = "WHERE `id`='" . $cpeId . "'";
  757. //model changing
  758. if ($_POST['editcpemodelid'] != $cpeData['modelid']) {
  759. if (isset($this->deviceModels[$_POST['editcpemodelid']])) {
  760. simple_update_field('wcpedevices', 'modelid', $_POST['editcpemodelid'], $where);
  761. log_register('WCPE [' . $cpeId . '] CHANGE MODEL [' . $_POST['editcpemodelid'] . ']');
  762. } else {
  763. $result .= $this->messages->getStyledMessage(__('Strange exeption') . ': MODELID_NOT_EXISTS [' . $_POST['editcpemodelid'] . ']', 'error');
  764. }
  765. }
  766. //bridge mode flag
  767. $bridgeFlag = (wf_CheckPost(array('editcpebridge'))) ? 1 : 0;
  768. if ($bridgeFlag != $cpeData['bridge']) {
  769. simple_update_field('wcpedevices', 'bridge', $bridgeFlag, $where);
  770. log_register('WCPE [' . $cpeId . '] CHANGE BRIDGE `' . $bridgeFlag . '`');
  771. }
  772. //ip change
  773. if ($_POST['editcpeip'] != $cpeData['ip']) {
  774. simple_update_field('wcpedevices', 'ip', $_POST['editcpeip'], $where);
  775. log_register('WCPE [' . $cpeId . '] CHANGE IP `' . $_POST['editcpeip'] . '`');
  776. }
  777. //mac editing
  778. if ($_POST['editcpemac'] != $cpeData['mac']) {
  779. $clearMac = trim($_POST['editcpemac']);
  780. $clearMac = strtolower_utf8($clearMac);
  781. if (empty($clearMac)) {
  782. $macCheckFlag = true;
  783. } else {
  784. $macCheckFlag = check_mac_format($clearMac);
  785. }
  786. if ($macCheckFlag) {
  787. simple_update_field('wcpedevices', 'mac', $clearMac, $where);
  788. log_register('WCPE [' . $cpeId . '] CHANGE MAC `' . $clearMac . '`');
  789. } else {
  790. $result .= $this->messages->getStyledMessage(__('This MAC have wrong format') . ' ' . $clearMac, 'error');
  791. }
  792. }
  793. //SNMP community change
  794. if ($_POST['editcpesnmp'] != $cpeData['snmp']) {
  795. simple_update_field('wcpedevices', 'snmp', $_POST['editcpesnmp'], $where);
  796. log_register('WCPE [' . $cpeId . '] CHANGE SNMP COMMUNITY `' . $_POST['editcpesnmp'] . '`');
  797. }
  798. //location changing
  799. if ($_POST['editcpelocation'] != $cpeData['location']) {
  800. simple_update_field('wcpedevices', 'location', $_POST['editcpelocation'], $where);
  801. log_register('WCPE [' . $cpeId . '] CHANGE LOC `' . $_POST['editcpelocation'] . '`');
  802. }
  803. //location changing
  804. if ($_POST['editcpegeo'] != $cpeData['geo']) {
  805. simple_update_field('wcpedevices', 'geo', $_POST['editcpegeo'], $where);
  806. log_register('WCPE [' . $cpeId . '] CHANGE GEO `' . $_POST['editcpegeo'] . '`');
  807. }
  808. //changing uplink AP
  809. if ($_POST['editcpeuplinkapid'] != $cpeData['uplinkapid']) {
  810. simple_update_field('wcpedevices', 'uplinkapid', $_POST['editcpeuplinkapid'], $where);
  811. log_register('WCPE [' . $cpeId . '] CHANGE UPLINKAP [' . $_POST['editcpeuplinkapid'] . ']');
  812. }
  813. } else {
  814. $result .= $this->messages->getStyledMessage(__('Strange exeption') . ': CPEID_NOT_EXISTS [' . $cpeId . ']', 'error');
  815. }
  816. }
  817. return ($result);
  818. }
  819. /**
  820. * Returns user array in table view
  821. *
  822. * @global object $ubillingConfig
  823. * @param array $usersarr
  824. * @return string
  825. */
  826. function renderAssignedUsersArray($usersarr) {
  827. if (!empty($usersarr)) {
  828. $alladdress = zb_AddressGetFulladdresslistCached();
  829. $allrealnames = zb_UserGetAllRealnames();
  830. $alltariffs = zb_TariffsGetAllUsers();
  831. $allusercash = zb_CashGetAllUsers();
  832. $allusercredits = zb_CreditGetAllUsers();
  833. $alluserips = zb_UserGetAllIPs();
  834. if ($this->altCfg['ONLINE_LAT']) {
  835. $alluserlat = zb_LatGetAllUsers();
  836. }
  837. //additional finance links
  838. if ($this->altCfg['FAST_CASH_LINK']) {
  839. $fastcash = true;
  840. } else {
  841. $fastcash = false;
  842. }
  843. $tablecells = wf_TableCell(__('Login'));
  844. $tablecells .= wf_TableCell(__('Address'));
  845. $tablecells .= wf_TableCell(__('Real Name'));
  846. $tablecells .= wf_TableCell(__('IP'));
  847. $tablecells .= wf_TableCell(__('Tariff'));
  848. // last activity time
  849. if ($this->altCfg['ONLINE_LAT']) {
  850. $tablecells .= wf_TableCell(__('LAT'));
  851. }
  852. $tablecells .= wf_TableCell(__('Active'));
  853. //online detect
  854. if ($this->altCfg['DN_ONLINE_DETECT']) {
  855. $tablecells .= wf_TableCell(__('Users online'));
  856. }
  857. $tablecells .= wf_TableCell(__('Balance'));
  858. $tablecells .= wf_TableCell(__('Credit'));
  859. $tablecells .= wf_TableCell(__('Actions'));
  860. $tablerows = wf_TableRow($tablecells, 'row1');
  861. foreach ($usersarr as $assignId => $eachlogin) {
  862. @$usercash = $allusercash[$eachlogin];
  863. @$usercredit = $allusercredits[$eachlogin];
  864. //finance check
  865. $activity = web_green_led();
  866. $activity_flag = 1;
  867. if ($usercash < '-' . $usercredit) {
  868. $activity = web_red_led();
  869. $activity_flag = 0;
  870. }
  871. //fast cash link
  872. if ($fastcash) {
  873. $financelink = wf_Link('?module=addcash&username=' . $eachlogin, wf_img('skins/icon_dollar.gif', __('Finance operations')), false, '');
  874. } else {
  875. $financelink = '';
  876. }
  877. $profilelink = $financelink . wf_Link('?module=userprofile&username=' . $eachlogin, web_profile_icon() . ' ' . $eachlogin);
  878. $tablecells = wf_TableCell($profilelink);
  879. $tablecells .= wf_TableCell(@$alladdress[$eachlogin]);
  880. $tablecells .= wf_TableCell(@$allrealnames[$eachlogin]);
  881. $tablecells .= wf_TableCell(@$alluserips[$eachlogin], '', '', 'sorttable_customkey="' . ip2int(@$alluserips[$eachlogin]) . '"');
  882. $tablecells .= wf_TableCell(@$alltariffs[$eachlogin]);
  883. if ($this->altCfg['ONLINE_LAT']) {
  884. if (isset($alluserlat[$eachlogin])) {
  885. $cUserLat = date("Y-m-d H:i:s", $alluserlat[$eachlogin]);
  886. } else {
  887. $cUserLat = __('No');
  888. }
  889. $tablecells .= wf_TableCell($cUserLat);
  890. }
  891. $tablecells .= wf_TableCell($activity, '', '', 'sorttable_customkey="' . $activity_flag . '"');
  892. if ($this->altCfg['DN_ONLINE_DETECT']) {
  893. if (file_exists(DATA_PATH . 'dn/' . $eachlogin)) {
  894. $online_flag = 1;
  895. } else {
  896. $online_flag = 0;
  897. }
  898. $tablecells .= wf_TableCell(web_bool_star($online_flag), '', '', 'sorttable_customkey="' . $online_flag . '"');
  899. }
  900. $tablecells .= wf_TableCell($usercash);
  901. $tablecells .= wf_TableCell($usercredit);
  902. $actLinks = wf_JSAlert(self::URL_ME . '&deleteassignid=' . $assignId . '&tocpe=' . $this->allAssigns[$assignId]['cpeid'], web_delete_icon(), $this->messages->getDeleteAlert());
  903. $tablecells .= wf_TableCell($actLinks);
  904. $tablerows .= wf_TableRow($tablecells, 'row5');
  905. }
  906. $result = wf_TableBody($tablerows, '100%', '0', 'sortable');
  907. $result .= wf_tag('b') . __('Total') . ': ' . wf_tag('b', true) . sizeof($usersarr);
  908. } else {
  909. $result = $this->messages->getStyledMessage(__('Any users found'), 'info');
  910. }
  911. return ($result);
  912. }
  913. /**
  914. * Renders list of users assigned with some CPE
  915. *
  916. * @param int $cpeId
  917. *
  918. * @return string
  919. */
  920. public function renderCPEAssignedUsers($cpeId) {
  921. $result = '';
  922. if (!empty($this->allAssigns)) {
  923. $assignedUsers = array();
  924. foreach ($this->allAssigns as $io => $each) {
  925. if (!empty($each)) {
  926. if ($each['cpeid'] == $cpeId) {
  927. $assignedUsers[$each['id']] = $each['login'];
  928. }
  929. }
  930. }
  931. if (!empty($assignedUsers)) {
  932. $result = $this->renderAssignedUsersArray($assignedUsers);
  933. } else {
  934. $result .= $this->messages->getStyledMessage(__('Nothing to show'), 'info');
  935. }
  936. } else {
  937. $result .= $this->messages->getStyledMessage(__('Nothing to show'), 'info');
  938. }
  939. return ($result);
  940. }
  941. /**
  942. * Returns CPE assign controls to user profile, if no CPE is attached to user yet
  943. *
  944. * @param $userLogin
  945. * @param string $userIP
  946. * @param string $userMAC
  947. *
  948. * @return string
  949. */
  950. protected function renderCPEAssignControl($userLogin, $userIP = '', $userMAC = '') {
  951. $result = '';
  952. $result .= wf_tag('br') . wf_tag('b') . __('Users WiFi equipment') . wf_tag('b', true) . wf_tag('br');
  953. $result .= wf_Link(self::URL_ME . '&userassign=' . $userLogin, wf_img('skins/icon_link.gif') . ' ' . __('Assign WiFi equipment to user'), false, 'ubButton') . '&nbsp';
  954. //$createForm = $this->renderCPECreateForm($userLogin);
  955. //$result.= wf_modalAuto(web_icon_create() . ' ' . __('Create new CPE'), __('Create new CPE'), $createForm, 'ubButton');
  956. $LnkID = wf_InputId();
  957. // the line below HAS to be commented to create "CPE create&assign form" dynamically
  958. $result .= wf_modalAutoForm(__('Create new CPE'), '', 'dialog-modal_' . $LnkID, 'body_dialog-modal_' . $LnkID);
  959. $result .= wf_tag('a', false, 'ubButton', 'id="' . $LnkID . '" href="#"');
  960. $result .= web_icon_create() . ' ' . __('Create new CPE');
  961. $result .= wf_tag('a', true);
  962. $result .= wf_tag('script', false, '', 'type="text/javascript"');
  963. // just an example for creating delegated JS event bindings for dynamically created objects that aren't exist on the page yet
  964. // this particular example is for "DelUserAssignment" button("red cross" near user's login) on "CPE create&assign form"
  965. // it's needed when the "CPE create&assign form" is created DYNAMICALLY
  966. // it's located here, 'cause this part of page already exists on the moment of "CPE create&assign form" creation
  967. // we're binding event to class name ".UsrDelAssignButton" here, 'cause it's ID we will never know from here - it simply does not exists yet
  968. // so, be sure to add that class to your control when you create it
  969. //
  970. /* $result.= '
  971. $(document).on("click", ".__UsrDelAssignButton", function() {
  972. alert(\'lalala\');
  973. return false;
  974. });
  975. '; */
  976. // below is an example of how to create "CPE create&assign form" dynamically
  977. /* $result.= '
  978. $(\'#' . $LnkID . '\').click(function(evt) {
  979. $.ajax({
  980. type: "GET",
  981. url: "' . self::URL_ME . '",
  982. data: {renderCreateForm:true, renderDynamically:true, userLogin:"' . $userLogin . '", ModalWID:"dialog-modal_' . $LnkID . '", ModalWBID:"body_dialog-modal_' . $LnkID .'"},
  983. success: function(result) {
  984. $(document.body).append(result);
  985. $(\'#dialog-modal_' . $LnkID . '\').dialog("open");
  986. }
  987. });
  988. evt.preventDefault();
  989. return false;
  990. });
  991. '; */
  992. $result .= '
  993. $(\'#' . $LnkID . '\').click(function(evt) {
  994. $.ajax({
  995. type: "GET",
  996. url: "' . self::URL_ME . '",
  997. data: {
  998. renderCreateForm:true,
  999. renderedOutside:true,
  1000. reloadPageAfterDone:true,
  1001. userLogin:"' . $userLogin . '",
  1002. wcpeMAC:"' . $userMAC . '",
  1003. wcpeIP:"' . $userIP . '",
  1004. wcpeAPID:"",
  1005. ActionCtrlID:"' . $LnkID . '",
  1006. ModalWID:"dialog-modal_' . $LnkID . '"
  1007. },
  1008. success: function(result) {
  1009. $(\'#body_dialog-modal_' . $LnkID . '\').html(result);
  1010. $(\'#dialog-modal_' . $LnkID . '\').dialog("open");
  1011. }
  1012. });
  1013. evt.preventDefault();
  1014. return false;
  1015. });
  1016. ';
  1017. $result .= wf_tag('script', true);
  1018. $result .= wf_delimiter();
  1019. //$result.=wf_tag('br');
  1020. return ($result);
  1021. }
  1022. /**
  1023. * Renders user profile CPE controls
  1024. *
  1025. * @param string $userLogin
  1026. * @param array $allUserData
  1027. *
  1028. * @return string
  1029. */
  1030. public function renderCpeUserControls($userLogin, $allUserData) {
  1031. $result = '';
  1032. $assignId = $this->userHaveCPE($userLogin);
  1033. //debarr($allUserData);
  1034. if ($assignId) {
  1035. //user have some CPE assigned
  1036. $assignedCpeId = $this->allAssigns[$assignId]['cpeid'];
  1037. if (isset($this->allCPE[$assignedCpeId])) {
  1038. $assignedCpeData = $this->allCPE[$assignedCpeId];
  1039. if (!empty($assignedCpeData)) {
  1040. $CPESNMPCommunity = ( empty($assignedCpeData['snmp']) ) ? 'public' : $assignedCpeData['snmp'];
  1041. $actLinks = '';
  1042. $telepathySup = wf_tag('abbr', false, '', 'title="' . __('Taken from the user, because the router mode is used') . '"') . '(?)' . wf_tag('abbr', true);
  1043. $telepathySup = ' ' . wf_tag('sup') . $telepathySup . wf_tag('sup', true);
  1044. $result .= wf_tag('br', true) . wf_tag('b') . __('Users WiFi equipment') . wf_tag('b', true);
  1045. $cpeModel = $this->deviceModels[$assignedCpeData['modelid']];
  1046. $cpeBridge = $assignedCpeData['bridge'];
  1047. $cpeIp = $assignedCpeData['ip'];
  1048. $cpeIpLabel = $cpeIp;
  1049. if ((empty($cpeIp)) AND ( !$cpeBridge)) {
  1050. $cpeIp = $allUserData[$userLogin]['ip'];
  1051. $cpeIpLabel = $cpeIp . $telepathySup;
  1052. }
  1053. $cpeMac = $assignedCpeData['mac'];
  1054. $cpeMacLabel = $cpeMac;
  1055. if ((empty($cpeMac)) AND ( !$cpeBridge)) {
  1056. $cpeMac = $allUserData[$userLogin]['mac'];
  1057. $cpeMacLabel = $cpeMac . $telepathySup;
  1058. }
  1059. $cpeLocation = $assignedCpeData['location'];
  1060. if ((empty($cpeLocation)) AND ( !$cpeBridge)) {
  1061. $cpeLocation = $allUserData[$userLogin]['fulladress'] . $telepathySup;
  1062. }
  1063. $cpeGeo = $assignedCpeData['geo'];
  1064. if ((empty($cpeGeo)) AND ( !$cpeBridge)) {
  1065. $cpeGeoCoords = $allUserData[$userLogin]['geo'];
  1066. if (!empty($cpeGeoCoords)) {
  1067. $cpeGeo = $cpeGeoCoords . $telepathySup;
  1068. }
  1069. }
  1070. $APSysInfo = '';
  1071. $APSigLvlCells = '';
  1072. $CPESigLvlCells = '';
  1073. $SignalGraphsBlock = '';
  1074. if ($this->SigmonEnabled) {
  1075. $SigMon = new MTsigmon();
  1076. $CtrlID = wf_InputId();
  1077. if (!empty($this->allAP) and ! empty($assignedCpeData['uplinkapid']) and ! empty($this->allAP[$assignedCpeData['uplinkapid']])) {
  1078. $APID = $this->allAP[$assignedCpeData['uplinkapid']]['id'];
  1079. } else {
  1080. $APID = 0;
  1081. }
  1082. $APSignalContainerID = 'APSignal_' . $CtrlID;
  1083. $APPollDTContainerID = 'APSignalPollDT_' . $CtrlID;
  1084. $APSignalControls = $this->getAPCPESignalControls($cpeMac, '#' . $APSignalContainerID, '#' . $APPollDTContainerID, $APID);
  1085. $LastPollDateAP = $APSignalControls['LastPollDate'];
  1086. $SignalLevelLabelAP = $APSignalControls['SignalLevelLabel'];
  1087. $RefreshButtonAP = $APSignalControls['RefreshButton'];
  1088. $CPESignalContainerID = 'CPESignal_' . $CtrlID;
  1089. $CPEPollDTContainerID = 'CPESignalPollDT_' . $CtrlID;
  1090. $CPESignalControls = $this->getAPCPESignalControls($cpeMac, '#' . $CPESignalContainerID, '#' . $CPEPollDTContainerID, 0, $cpeIp, $CPESNMPCommunity);
  1091. $LastPollDateCPE = $CPESignalControls['LastPollDate'];
  1092. $SignalLevelLabelCPE = $CPESignalControls['SignalLevelLabel'];
  1093. $RefreshButtonCPE = $CPESignalControls['RefreshButton'];
  1094. $APSigLvlCells = wf_TableCell(__('Signal level on AP'), '20%', 'row2');
  1095. $APSigLvlCells .= wf_TableCell($SignalLevelLabelAP, '55%', '', 'id="' . $APSignalContainerID . '"');
  1096. $APSigLvlCells .= wf_TableCell($RefreshButtonAP);
  1097. $APSigLvlCells .= wf_TableCell($LastPollDateAP, '25%', '', 'id="' . $APPollDTContainerID . '"');
  1098. $CPESigLvlCells = wf_TableCell(__('Signal level on CPE'), '20%', 'row2');
  1099. $CPESigLvlCells .= wf_TableCell($SignalLevelLabelCPE, '55%', '', 'id="' . $CPESignalContainerID . '"');
  1100. $CPESigLvlCells .= wf_TableCell($RefreshButtonCPE);
  1101. $CPESigLvlCells .= wf_TableCell($LastPollDateCPE, '25%', '', 'id="' . $CPEPollDTContainerID . '"');
  1102. $SignalGraphAP = $SigMon->renderSignalGraphs($cpeMac, true, true, false, true, true);
  1103. $SignalGraphCPE = $SigMon->renderSignalGraphs($cpeMac, false, true, false, true, true);
  1104. $SignalGraphs = '';
  1105. $Hyphen = ' - ';
  1106. if (empty($SignalGraphAP)) {
  1107. $GraphContainerSelector = 'NoAPDataBlck_' . $CtrlID;
  1108. $GraphRefreshButton = $this->getAPCPEGraphRefreshButton($cpeMac, '#' . $GraphContainerSelector, true, true, true);
  1109. $SignalGraphs .= wf_tag('div', false, '', 'id="' . $GraphContainerSelector . '" style="margin: 10px auto; display: table; font-size: 14px; font-weight: 600;"');
  1110. $SignalGraphs .= __('No data from AP yet') . (( empty($GraphRefreshButton) ) ? '' : $Hyphen);
  1111. $SignalGraphs .= $GraphRefreshButton;
  1112. $SignalGraphs .= wf_tag('div', true);
  1113. } else {
  1114. $GraphContainerID = 'SpoilerAP_' . $CtrlID;
  1115. $GraphContainerSelector = '#' . $GraphContainerID . ' .spoiler_body';
  1116. $GraphRefreshButton = $this->getAPCPEGraphRefreshButton($cpeMac, $GraphContainerSelector, true, false);
  1117. $SignalGraphs .= wf_Spoiler($SignalGraphAP, $GraphRefreshButton . '&nbsp&nbsp' . __('Signal data from AP'), true, $GraphContainerID, '', '', '', 'style="margin: 10px auto; display: table;"');
  1118. }
  1119. if (empty($SignalGraphCPE)) {
  1120. $GraphContainerSelector = 'NoCPEDataBlck_' . $CtrlID;
  1121. $GraphRefreshButton = $this->getAPCPEGraphRefreshButton($cpeMac, '#' . $GraphContainerSelector, false, true, true);
  1122. $SignalGraphs .= wf_tag('div', false, '', 'id="' . $GraphContainerSelector . '" style="margin: 10px auto; display: table; font-size: 14px; font-weight: 600;"');
  1123. $SignalGraphs .= __('No data from CPE yet') . (( empty($GraphRefreshButton) ) ? '' : $Hyphen);
  1124. $SignalGraphs .= $GraphRefreshButton;
  1125. $SignalGraphs .= wf_tag('div', true);
  1126. } else {
  1127. $GraphContainerID = 'SpoilerCPE_' . $CtrlID;
  1128. $GraphContainerSelector = '#' . $GraphContainerID . ' .spoiler_body';
  1129. $GraphRefreshButton = $this->getAPCPEGraphRefreshButton($cpeMac, $GraphContainerSelector, false, false);
  1130. $SignalGraphs .= wf_Spoiler($SignalGraphCPE, $GraphRefreshButton . '&nbsp&nbsp' . __('Signal data from CPE'), true, $GraphContainerID, '', '', '', 'style="margin: 10px auto; display: table;"');
  1131. }
  1132. $SignalGraphsBlock .= wf_Spoiler($SignalGraphs, __('Signal levels history graphs'), true);
  1133. $SignalGraphsBlock .= wf_tag('script', false, '', 'type="text/javascript"');
  1134. $SignalGraphsBlock .= $this->getSignalRefreshJS();
  1135. $SignalGraphsBlock .= $this->getGraphRefreshJS();
  1136. $SignalGraphsBlock .= wf_tag('script', true);
  1137. $APSysInfo = $this->renderAPEssentialData($APID, $SigMon);
  1138. }
  1139. $bridgeLabel = ($cpeBridge) ? web_bool_led(true) . ' ' . __('Yes') : web_bool_led(false) . ' ' . __('No');
  1140. $cpeLink = wf_Link(self::URL_ME . '&editcpeid=' . $assignedCpeId, web_edit_icon(__('Show') . ' ' . __('CPE')), false, '');
  1141. $cpeWebIfaceLink = wf_tag('a', false, '', 'href="http://' . $cpeIp . '" target="_blank" title="' . __('Go to the web interface') . '"');
  1142. $cpeWebIfaceLink .= wf_img('skins/ymaps/network.png');
  1143. $cpeWebIfaceLink .= wf_tag('a', true);
  1144. $cells = wf_TableCell(__('Model'), '20%', 'row2');
  1145. $cells .= wf_TableCell($cpeModel . '&nbsp&nbsp&nbsp' . $cpeLink);
  1146. $rows = wf_TableRow($cells, 'row3');
  1147. $cells = wf_TableCell(__('IP'), '20%', 'row2');
  1148. $cells .= wf_TableCell($cpeIpLabel . '&nbsp&nbsp&nbsp' . $cpeWebIfaceLink);
  1149. $rows .= wf_TableRow($cells, 'row3');
  1150. $cells = wf_TableCell(__('MAC'), '20%', 'row2');
  1151. $cells .= wf_TableCell($cpeMacLabel);
  1152. $rows .= wf_TableRow($cells, 'row3');
  1153. $cells = wf_TableCell(__('Location'), '20%', 'row2');
  1154. $cells .= wf_TableCell($cpeLocation);
  1155. $rows .= wf_TableRow($cells, 'row3');
  1156. $cells = wf_TableCell(__('Geo location'), '20%', 'row2');
  1157. $cells .= wf_TableCell($cpeGeo);
  1158. $rows .= wf_TableRow($cells, 'row3');
  1159. $cells = wf_TableCell(__('Bridge mode'), '20%', 'row2');
  1160. $cells .= wf_TableCell($bridgeLabel);
  1161. $rows .= wf_TableRow($cells, 'row3');
  1162. if (!empty($assignedCpeData['uplinkapid'])) {
  1163. if (isset($this->allAP[$assignedCpeData['uplinkapid']])) {
  1164. $apLabel = $this->allAP[$assignedCpeData['uplinkapid']]['ip'];
  1165. $apWebIfaceLink = wf_tag('a', false, '', 'href="http://' . $this->allAP[$assignedCpeData['uplinkapid']]['ip'] . '" target="_blank" title="' . __('Go to the web interface') . '"');
  1166. $apWebIfaceLink .= wf_img('skins/ymaps/network.png');
  1167. $apWebIfaceLink .= wf_tag('a', true);
  1168. if (isset($this->allSSids[$assignedCpeData['uplinkapid']])) {
  1169. $apLabel .= ' - ' . $this->allSSids[$assignedCpeData['uplinkapid']];
  1170. } else {
  1171. $apLabel .= ' - ' . $this->allAP[$assignedCpeData['uplinkapid']]['location'];
  1172. }
  1173. $apLink = wf_Link('?module=switches&edit=' . $assignedCpeData['uplinkapid'], web_edit_icon(__('Navigate to AP')), false, '');
  1174. $cells = wf_TableCell(__('Connected to AP'), '20%', 'row2');
  1175. $cells .= wf_TableCell($apLabel . '&nbsp&nbsp&nbsp' . $apLink . '&nbsp&nbsp&nbsp' . $apWebIfaceLink);
  1176. $rows .= wf_TableRow($cells, 'row3');
  1177. }
  1178. } else {
  1179. $cells = wf_TableCell(__('Connected to AP'), '20%', 'row2');
  1180. $cells .= wf_TableCell(__('No'));
  1181. $rows .= wf_TableRow($cells, 'row3');
  1182. }
  1183. $rows .= wf_TableRow($APSigLvlCells, 'row3');
  1184. $rows .= wf_TableRow($CPESigLvlCells, 'row3');
  1185. $result .= wf_TableBody($rows, '100%', 0, '');
  1186. $result .= $APSysInfo;
  1187. $result .= $SignalGraphsBlock;
  1188. }
  1189. } else {
  1190. $result .= $this->messages->getStyledMessage(__('Strange exeption') . ': CPEID_NOT_EXISTS [' . $assignedCpeId . ']', 'error');
  1191. }
  1192. } else {
  1193. $result .= $this->renderCPEAssignControl($userLogin, $allUserData[$userLogin]['ip'], $allUserData[$userLogin]['mac']);
  1194. }
  1195. return ($result);
  1196. }
  1197. /**
  1198. * Renders main module control panel
  1199. *
  1200. * @return string
  1201. */
  1202. public function panel() {
  1203. $result = '';
  1204. $result .= wf_modalAuto(web_add_icon() . ' ' . __('Create new CPE'), __('Create new CPE'), $this->renderCPECreateForm(), 'ubButton') . ' ';
  1205. $result .= wf_Link(self::URL_ME, wf_img('skins/ymaps/switchdir.png') . ' ' . __('Available CPE list'), false, 'ubButton');
  1206. $result .= wf_Link(self::URL_ME . '&rendermap=true', wf_img('skins/ymaps/network.png') . ' ' . __('Map') . ' ' . __('CPE') . '/' . __('AP'), false, 'ubButton');
  1207. return ($result);
  1208. }
  1209. /**
  1210. * Renders wireless devices map
  1211. *
  1212. * @return string
  1213. */
  1214. public function renderDevicesMap() {
  1215. global $ubillingConfig;
  1216. $ymconf = $ubillingConfig->getYmaps();
  1217. $this->loadUserData();
  1218. $deadSwitches = zb_SwitchesGetAllDead();
  1219. $result = '';
  1220. $placemarks = '';
  1221. $result = wf_tag('div', false, '', 'id="ubmap" style="width: 100%; height:800px;"');
  1222. $result .= wf_tag('div', true);
  1223. if (!empty($this->allAP)) {
  1224. foreach ($this->allAP as $io => $each) {
  1225. if (!empty($each['geo'])) {
  1226. $apName = $each['location'] . ' - ' . $each['ip'] . ' ' . @$this->allSSids[$each['id']];
  1227. $apLink = trim(wf_Link('?module=switches&edit=' . $each['id'], web_edit_icon() . ' ' . __('Navigate to AP')));
  1228. $apLink = str_replace('"', '', $apLink);
  1229. $apIcon = sm_MapGoodIcon();
  1230. if (isset($deadSwitches[$each['ip']])) {
  1231. $apIcon = sm_MapBadIcon();
  1232. }
  1233. $placemarks .= sm_MapAddMark($each['geo'], $apName, $apLink, '', $apIcon);
  1234. }
  1235. }
  1236. }
  1237. if (!empty($this->allCPE)) {
  1238. foreach ($this->allCPE as $io => $each) {
  1239. $cpeCoords = '';
  1240. if (!empty($each['geo'])) {
  1241. $cpeCoords = $each['geo'];
  1242. } else {
  1243. //try extract from user geo
  1244. $assignId = $this->cpeHaveUser($each['id']);
  1245. if ($assignId) {
  1246. if (isset($this->allAssigns[$assignId])) {
  1247. if (isset($this->allUsersData[$this->allAssigns[$assignId]['login']])) {
  1248. if (!empty($this->allUsersData[$this->allAssigns[$assignId]['login']]['geo'])) {
  1249. $cpeCoords = $this->allUsersData[$this->allAssigns[$assignId]['login']]['geo'];
  1250. }
  1251. }
  1252. }
  1253. }
  1254. }
  1255. //drawing CPE on map
  1256. if (!empty($cpeCoords)) {
  1257. $cpeName = $each['id'] . ': ' . @$this->deviceModels[$each['modelid']];
  1258. $cpeLink = trim(wf_Link(self::URL_ME . '&editcpeid=' . $each['id'], web_edit_icon() . ' ' . __('Show') . ' ' . __('CPE')));
  1259. $cpeLink = str_replace('"', '', $cpeLink);
  1260. $placemarks .= sm_MapAddMark($cpeCoords, $cpeName, $cpeLink, '', um_MapBuildIcon(1));
  1261. //drawing CPE uplinks
  1262. if (!empty($each['uplinkapid'])) {
  1263. if (isset($this->allAP[$each['uplinkapid']])) {
  1264. if (!empty($this->allAP[$each['uplinkapid']]['geo'])) {
  1265. $lineColor = '#00FF00';
  1266. $lineWidth = 2;
  1267. if (isset($deadSwitches[$this->allAP[$each['uplinkapid']]['ip']])) {
  1268. $lineColor = '#FF0000';
  1269. $lineWidth = 3;
  1270. }
  1271. $placemarks .= sm_MapAddLine($cpeCoords, $this->allAP[$each['uplinkapid']]['geo'], $lineColor, '', $lineWidth);
  1272. }
  1273. }
  1274. }
  1275. }
  1276. }
  1277. }
  1278. $result .= generic_MapInit($ymconf['CENTER'], $ymconf['ZOOM'], $ymconf['TYPE'], $placemarks, '', $ymconf['LANG']);
  1279. return ($result);
  1280. }
  1281. /**
  1282. * Returns signal show&repoll controls
  1283. * $SignalContainerSelector and $PollDateContainerSelector must be a valid JQuery selectors where returned data will be stored in
  1284. *
  1285. * @param string $CPEMAC
  1286. * @param string $SignalContainerSelector
  1287. * @param string $PollDateContainerSelector
  1288. * @param int $UplinkAPID
  1289. * @param string $CPEIP
  1290. * @param string $CPESNMPCommunity
  1291. *
  1292. * @return array
  1293. */
  1294. public function getAPCPESignalControls($CPEMAC, $SignalContainerSelector, $PollDateContainerSelector, $UplinkAPID = 0, $CPEIP = '', $CPESNMPCommunity = '') {
  1295. $ReturnedControlsArray = array();
  1296. if (empty($CPEMAC) || empty($SignalContainerSelector) || empty($PollDateContainerSelector)) {
  1297. $ReturnedControlsArray = array('LastPollDate' => '',
  1298. 'SignalLevelLabel' => '',
  1299. 'RefreshButton' => ''
  1300. );
  1301. return $ReturnedControlsArray;
  1302. }
  1303. $SigMon = new MTsigmon();
  1304. $CtrlID = wf_InputId();
  1305. if (empty($UplinkAPID)) {
  1306. // return CPE signal&poll controls
  1307. $SignalDataArray = $SigMon->getCPESignalData($CPEMAC, 0, $CPEIP, $CPESNMPCommunity, false, false);
  1308. $LnkID = 'CPESigUpd_' . $CtrlID;
  1309. $LnkTitle = __('Refresh data for this CPE');
  1310. } else {
  1311. // return AP signal&poll controls
  1312. $SignalDataArray = $SigMon->getCPESignalData($CPEMAC, $UplinkAPID, '', '', true, false);
  1313. $LnkID = 'APSigUpd_' . $CtrlID;
  1314. $LnkTitle = __('Refresh data for this AP');
  1315. }
  1316. $LastPollDate = (empty($SignalDataArray[0])) ? __('Device is not polled yet') : __('Cache state at time') . ': ' . $SignalDataArray[0];
  1317. $SignalLevelLabel = (empty($SignalDataArray[1])) ? '' : $SignalDataArray[1];
  1318. $RefreshButton = wf_tag('a', false, '', 'href="#" id="' . $LnkID . '" title="' . $LnkTitle . '"');
  1319. $RefreshButton .= wf_img('skins/refresh.gif');
  1320. $RefreshButton .= wf_tag('a', true);
  1321. $RefreshButton .= wf_tag('script', false, '', 'type="text/javascript"');
  1322. $RefreshButton .= '$(\'#' . $LnkID . '\').click(function(evt) {
  1323. $(this).find(\'img\').toggleClass("image_rotate");
  1324. APCPESignalRefresh("' . $CPEMAC . '", "' . $SignalContainerSelector . '", "' . $PollDateContainerSelector . '", "'
  1325. . $UplinkAPID . '", "' . $CPEIP . '", "' . $CPESNMPCommunity . '", "#' . $LnkID . '");
  1326. evt.preventDefault();
  1327. return false;
  1328. });';
  1329. $RefreshButton .= wf_tag('script', true);
  1330. $ReturnedControlsArray = array('LastPollDate' => $LastPollDate,
  1331. 'SignalLevelLabel' => $SignalLevelLabel,
  1332. 'RefreshButton' => $RefreshButton
  1333. );
  1334. return $ReturnedControlsArray;
  1335. }
  1336. /**
  1337. * Returns signal history graph for given CPE.
  1338. * $GraphContainerSelector must be a valid JQuery selector where returned data will be stored in
  1339. * $ReplaceContainerWithGraph:
  1340. * if true - returned data will replace $GraphContainerSelector with JQuery's "replaceWith()" method
  1341. * otherwise - $GraphContainerSelector's inner HTML will be replaced with returned data (JQuery's "html()" method will be used)
  1342. *
  1343. * @param string $CPEMAC
  1344. * @param string $GraphContainerSelector
  1345. * @param bool $GraphFromAP
  1346. * @param bool $ReturnGraphInSpoiler
  1347. * @param bool $ReplaceContainerWithGraph
  1348. *
  1349. * @return string
  1350. */
  1351. public function getAPCPEGraphRefreshButton($CPEMAC, $GraphContainerSelector, $GraphFromAP = false, $ReturnGraphInSpoiler = false, $ReplaceContainerWithGraph = false) {
  1352. if (empty($GraphContainerSelector) || empty($CPEMAC)) {
  1353. return '';
  1354. }
  1355. $CtrlID = wf_InputId();
  1356. $LnkTitle = __('Refresh') . ' ' . __('data');
  1357. $LnkID = ( ($GraphFromAP) ? 'APGraphUpd_' : 'CPEGraphUpd_') . $CtrlID;
  1358. $GraphRefreshButton = wf_tag('a', false, '', 'href="#" id="' . $LnkID . '" style="vertical-align: sub;" title="' . $LnkTitle . '"');
  1359. $GraphRefreshButton .= wf_img('skins/refresh.gif');
  1360. $GraphRefreshButton .= wf_tag('a', true);
  1361. $GraphRefreshButton .= wf_tag('script', false, '', 'type="text/javascript"');
  1362. $GraphRefreshButton .= '$(\'#' . $LnkID . '\').click(function(evt) {
  1363. evt.stopImmediatePropagation();
  1364. $(this).find(\'img\').toggleClass("image_rotate");
  1365. SignalGraphRefresh("' . $CPEMAC . '", "' . $GraphContainerSelector . '", ' . var_export($GraphFromAP, true) . ', true, false, true, true, '
  1366. . var_export($ReturnGraphInSpoiler, true) . ', ' . var_export($ReplaceContainerWithGraph, true) . ', "#' . $LnkID . '");
  1367. evt.preventDefault();
  1368. return false;
  1369. });';
  1370. $GraphRefreshButton .= wf_tag('script', true);
  1371. return $GraphRefreshButton;
  1372. }
  1373. /**
  1374. * Returns JS code for controls returned by "getAPCPESignalControls()" function
  1375. * Without this code controls returned by "getAPCPESignalControls()" function will not work properly
  1376. *
  1377. * @param bool $PutInsideScriptTag
  1378. *
  1379. * @return string
  1380. */
  1381. public function getSignalRefreshJS($PutInsideScriptTag = false) {
  1382. $SignalRefreshJS = ($PutInsideScriptTag) ? wf_tag('script', false, '', 'type="text/javascript"') : '';
  1383. $SignalRefreshJS .= '
  1384. function APCPESignalRefresh(MACCPE, SignalContainerSelector, PollDateContainerSelector, APID = \'\', IPCPE = \'\', SNMPCCPE = \'public\', RefreshButtonID = \'\') {
  1385. var SignalContainerObj = $(SignalContainerSelector);
  1386. if ( !SignalContainerObj.length || !(SignalContainerObj instanceof jQuery)) {return false;}
  1387. var PollDateContainerObj = $(PollDateContainerSelector);
  1388. if ( !PollDateContainerObj.length || !(PollDateContainerObj instanceof jQuery)) {return false;}
  1389. $.ajax({
  1390. type: "GET",
  1391. url: "' . self::URL_SIGMON . '",
  1392. data: {IndividualRefresh:true, cpeMAC:MACCPE, apid:APID, cpeIP:IPCPE, cpeCommunity:SNMPCCPE},
  1393. success: function(result) {
  1394. var RefreshButtonObj = $(RefreshButtonID);
  1395. if ( RefreshButtonObj.length && (RefreshButtonObj instanceof jQuery)) {
  1396. RefreshButtonObj.find(\'img\').toggleClass("image_rotate");
  1397. }
  1398. try {
  1399. var jsonObj = $.parseJSON(result);
  1400. SignalContainerObj.html(jsonObj.SignalLevel);
  1401. PollDateContainerObj.html("' . __('Cache state at time') . ': " + ' . 'jsonObj.LastPollDate);
  1402. } catch (e) {
  1403. return false;
  1404. }
  1405. }
  1406. });
  1407. }
  1408. ';
  1409. $SignalRefreshJS .= ($PutInsideScriptTag) ? wf_tag('script', true) : '';
  1410. return $SignalRefreshJS;
  1411. }
  1412. /**
  1413. * Returns JS code for controls returned by "getAPCPEGraphRefreshButton()" function
  1414. * Without this code controls returned by "getAPCPEGraphRefreshButton()" function will not work properly
  1415. *
  1416. * @param bool $PutInsideScriptTag
  1417. *
  1418. * @return string
  1419. */
  1420. public function getGraphRefreshJS($PutInsideScriptTag = false) {
  1421. $GraphRefreshJS = ($PutInsideScriptTag) ? wf_tag('script', false, '', 'type="text/javascript"') : '';
  1422. $GraphRefreshJS .= '
  1423. function SignalGraphRefresh(CPEMAC, GraphContainerSelector, FromAP = false, ShowTitle = false, ShowXLabel = false, ShowYLabel = false, ShowRangeSelector = false, ReturnInSpoiler = false, ReplaceContainerWithGraph = false, RefreshButtonID = \'\') {
  1424. var GraphContainerObj = $(GraphContainerSelector);
  1425. if ( !GraphContainerObj.length || !(GraphContainerObj instanceof jQuery)) {return false;}
  1426. $.ajax({
  1427. type: "GET",
  1428. url: "' . self::URL_SIGMON . '",
  1429. data: { IndividualRefresh:true,
  1430. getGraphs:true,
  1431. cpeMAC:CPEMAC,
  1432. fromAP:FromAP,
  1433. showTitle:ShowTitle,
  1434. showXLabel:ShowXLabel,
  1435. showYLabel:ShowYLabel,
  1436. showRangeSelector:ShowRangeSelector,
  1437. returnInSpoiler:ReturnInSpoiler
  1438. },
  1439. success: function(result) {
  1440. var RefreshButtonObj = $(RefreshButtonID);
  1441. if ( RefreshButtonObj.length && (RefreshButtonObj instanceof jQuery)) {
  1442. RefreshButtonObj.find(\'img\').toggleClass("image_rotate");
  1443. }
  1444. if (empty(result)) {return false;}
  1445. if (ReplaceContainerWithGraph) {
  1446. GraphContainerObj.replaceWith(result);
  1447. } else {
  1448. GraphContainerObj.html(result);
  1449. }
  1450. }
  1451. });
  1452. };
  1453. function empty (mixed_var) {
  1454. // version: 909.322
  1455. // discuss at: http://phpjs.org/functions/empty
  1456. var key;
  1457. if (mixed_var === "" || mixed_var === 0 || mixed_var === "0" || mixed_var === null || mixed_var === false || mixed_var === undefined ) {
  1458. return true;
  1459. }
  1460. if (typeof mixed_var == \'object\') {
  1461. for (key in mixed_var) {
  1462. return false;
  1463. }
  1464. return true;
  1465. }
  1466. return false;
  1467. }
  1468. ';
  1469. $GraphRefreshJS .= ($PutInsideScriptTag) ? wf_tag('script', true) : '';
  1470. return $GraphRefreshJS;
  1471. }
  1472. private function renderAPEssentialData($APID, $SigMonObj) {
  1473. $InfoButtonID = 'InfID_' . $APID;
  1474. $InfoBlockID = 'InfBlck_' . $APID;
  1475. $APInfoBlock = wf_tag('div', false, '', 'id="' . $InfoBlockID . '"');
  1476. $APInfoBlock .= ( isset($this->altCfg['USERPROFILE_APINFO_AUTOLOAD']) and $this->altCfg['USERPROFILE_APINFO_AUTOLOAD'] ) ? $SigMonObj->getAPEssentialData($APID, true, false, false) : '';
  1477. $APInfoBlock .= wf_tag('div', true);
  1478. $APInfoButton = wf_tag('a', false, '', 'href="#" id="' . $InfoButtonID . '" title="' . __('Get system info for this AP') . '"');
  1479. $APInfoButton .= wf_tag('img', false, '', 'src="skins/icn_alert_info.png" border="0" style="vertical-align: bottom;"');
  1480. $APInfoButton .= wf_tag('a', true);
  1481. $APInfoButton .= wf_tag('script', false, '', 'type="text/javascript"');
  1482. $APInfoButton .= '$(\'#' . $InfoButtonID . '\').click(function(evt) {
  1483. $(\'img\', this).toggleClass("image_rotate");
  1484. getAPInfo(' . $APID . ', "#' . $InfoBlockID . '", true, false, ' . $InfoButtonID . ');
  1485. evt.preventDefault();
  1486. return false;
  1487. });';
  1488. $APInfoButton .= wf_tag('script', true);
  1489. $Result = wf_Spoiler($APInfoBlock, $APInfoButton . '&nbsp&nbsp' . __('System AP info'), true, '', '', '', '', 'style="margin: 10px auto;"');
  1490. $Result .= wf_tag('script', false, '', 'type="text/javascript"');
  1491. $Result .= 'function getAPInfo(APID, InfoBlckSelector, ReturnHTML = false, InSpoiler = false, RefreshButtonSelector) {
  1492. $.ajax({
  1493. type: "GET",
  1494. url: "' . self::URL_SIGMON . '",
  1495. data: { IndividualRefresh:true,
  1496. GetAPInfo:true,
  1497. apid:APID,
  1498. returnAsHTML:ReturnHTML,
  1499. returnInSpoiler:InSpoiler
  1500. },
  1501. success: function(result) {
  1502. if ($.type(RefreshButtonSelector) === \'string\') {
  1503. $("#"+RefreshButtonSelector).find(\'img\').toggleClass("image_rotate");
  1504. } else {
  1505. $(RefreshButtonSelector).find(\'img\').toggleClass("image_rotate");
  1506. }
  1507. var InfoBlck = $(InfoBlckSelector);
  1508. if ( !InfoBlck.length || !(InfoBlck instanceof jQuery)) {return false;}
  1509. $(InfoBlck).html(result);
  1510. }
  1511. });
  1512. }
  1513. ';
  1514. $Result .= wf_tag('script', true);
  1515. return $Result;
  1516. }
  1517. }
  1518. ?>