api.extnets.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. <?php
  2. /**
  3. * Extended network pools implementation
  4. */
  5. class ExtNets {
  6. protected $networks = array();
  7. protected $pools = array();
  8. protected $ips = array();
  9. protected $switches = array();
  10. protected $masklimits = array('upper' => 30, 'lower' => 24);
  11. protected $cidrs = array();
  12. protected $cidrToMask = array();
  13. protected $cidrOffsets = array();
  14. const EX_NOEXNET = 'NOT_EXISTING_NET_ID';
  15. const EX_NOEXPOOL = 'NOT_EXISTING_POOL_ID';
  16. const EX_NOEXIP = 'NOT_EXISTING_IP_ID';
  17. public function __construct() {
  18. $this->preprocessCidrMasks();
  19. $this->loadNetworks();
  20. $this->loadPools();
  21. $this->loadIps();
  22. }
  23. /**
  24. * transform net/CIDR notation to netmask
  25. *
  26. * @param $cidr string - network/CIDR
  27. *
  28. * @return array
  29. */
  30. protected function v4CIDRtoMask($cidr) {
  31. $cidr = explode('/', $cidr);
  32. return array($cidr[0], long2ip(-1 << (32 - (int) $cidr[1])));
  33. }
  34. /**
  35. * prepare private CIDR mask data for following usage
  36. *
  37. * @return void
  38. */
  39. protected function preprocessCidrMasks() {
  40. $startOffset = 2;
  41. if (!empty($this->masklimits)) {
  42. for ($i = $this->masklimits['upper']; $i >= $this->masklimits['lower']; $i--) {
  43. $this->cidrs[$i] = $i;
  44. }
  45. foreach ($this->cidrs as $each => $cidr) {
  46. $curMask = $this->v4CIDRtoMask('/' . $each);
  47. $this->cidrToMask[$each] = $curMask[1];
  48. $startOffset = $startOffset * 2;
  49. $this->cidrOffsets[$each] = $startOffset;
  50. }
  51. }
  52. }
  53. /**
  54. * loads actual `other` networks array from database
  55. *
  56. * @return void
  57. */
  58. protected function loadNetworks() {
  59. $query = "SELECT * from `networks` WHERE `nettype`='other';";
  60. $all = simple_queryall($query);
  61. if (!empty($all)) {
  62. foreach ($all as $io => $each) {
  63. $this->networks[$each['id']] = $each;
  64. }
  65. }
  66. }
  67. /**
  68. * loads existing extpools from database into private pools property
  69. *
  70. * @return void
  71. */
  72. protected function loadPools() {
  73. $query = "SELECT * from `netextpools` ORDER by `id` ASC";
  74. $all = simple_queryall($query);
  75. if (!empty($all)) {
  76. foreach ($all as $io => $each) {
  77. $this->pools[$each['id']] = $each;
  78. }
  79. }
  80. }
  81. /**
  82. * renders existing networks list accessible for pools assign
  83. *
  84. * @return string
  85. */
  86. public function renderNetworks() {
  87. //active row hlight
  88. if (wf_CheckGet(array('showpoolbynetid'))) {
  89. $hlightNetId = vf($_GET['showpoolbynetid'], 3);
  90. } else {
  91. $hlightNetId = 'NONE';
  92. }
  93. $cells = wf_TableCell(__('ID'));
  94. $cells.= wf_TableCell(__('First IP'));
  95. $cells.= wf_TableCell(__('Last IP'));
  96. $cells.= wf_TableCell(__('Network/CIDR'));
  97. $rows = wf_TableRow($cells, 'row1');
  98. if (!empty($this->networks)) {
  99. foreach ($this->networks as $io => $each) {
  100. $cells = wf_TableCell($each['id']);
  101. $cells.= wf_TableCell($each['startip']);
  102. $cells.= wf_TableCell($each['endip']);
  103. $actLink = wf_Link('?module=extnets&showpoolbynetid=' . $each['id'], $each['desc'], false, '');
  104. $cells.= wf_TableCell($actLink);
  105. if ($each['id'] != $hlightNetId) {
  106. $rowClass = 'row3';
  107. } else {
  108. $rowClass = 'row2';
  109. }
  110. $rows.= wf_TableRow($cells, $rowClass);
  111. }
  112. }
  113. $result = wf_TableBody($rows, '100%', '0', 'sortable');
  114. return ($result);
  115. }
  116. /**
  117. * returns network CIDR by id
  118. *
  119. * @param $netid
  120. *
  121. * @return string
  122. */
  123. public function getNetworkCidr($netid) {
  124. $netid = vf($netid, 3);
  125. if (isset($this->networks[$netid])) {
  126. $result = $this->networks[$netid]['desc'];
  127. } else {
  128. $result = '';
  129. throw new Exception(self::EX_NOEXNET);
  130. }
  131. return ($result);
  132. }
  133. /**
  134. * renders available pools assigned by some network
  135. *
  136. * @param $netid int existing network ID
  137. *
  138. * @return string
  139. */
  140. public function renderPools($netid) {
  141. $netid = vf($netid, 3);
  142. $result = __('Nothing found');
  143. $netpools = array();
  144. if (isset($this->networks[$netid])) {
  145. if (!empty($this->pools)) {
  146. foreach ($this->pools as $io => $each) {
  147. if ($each['netid'] == $netid) {
  148. $netpools[$each['id']] = $each;
  149. }
  150. }
  151. }
  152. }
  153. if (!empty($netpools)) {
  154. $cells = wf_TableCell(__('ID'));
  155. $cells.= wf_TableCell(__('Pool'));
  156. $cells.= wf_TableCell(__('Netmask'));
  157. $cells.= wf_TableCell(__('Gateway'));
  158. $cells.= wf_TableCell(__('IP'));
  159. $cells.= wf_TableCell(__('Broadcast'));
  160. $cells.= wf_TableCell(__('VLAN'));
  161. $cells.= wf_TableCell(__('Login'));
  162. $cells.= wf_TableCell(__('Actions'));
  163. $rows = wf_TableRow($cells, 'row1');
  164. foreach ($netpools as $io => $each) {
  165. $cells = wf_TableCell($each['id']);
  166. $cells.= wf_TableCell($each['pool']);
  167. $cells.= wf_TableCell($this->cidrToMask[$each['netmask']] . ' (/' . $each['netmask'] . ')');
  168. $cells.= wf_TableCell($each['gw']);
  169. $cells.= wf_TableCell(wf_Link('?module=extnets&showipsbypoolid=' . $each['id'], $this->ipsGetAssociated($each['id']), false), '40%');
  170. $cells.= wf_TableCell($each['broadcast']);
  171. $cells.= wf_TableCell($each['vlan']);
  172. if (!empty($each['login'])) {
  173. $loginlink = wf_Link('?module=userprofile&username=' . $each['login'], web_profile_icon() . ' ' . $each['login'], 'fasle');
  174. } else {
  175. $loginlink = '';
  176. }
  177. $cells.= wf_TableCell($loginlink);
  178. $actlinks = wf_JSAlert('?module=extnets&showpoolbynetid=' . $netid . '&deletepoolid=' . $each['id'], web_delete_icon(), __('Removing this may lead to irreparable results'));
  179. $actlinks.= wf_modal(web_edit_icon(), __('Edit') . ' ' . $each['pool'] . '/' . $each['netmask'], $this->poolEditForm($each['id']), '', '300', '200');
  180. $cells.= wf_TableCell($actlinks);
  181. $rows.= wf_TableRow($cells, 'row3');
  182. }
  183. $result = wf_TableBody($rows, '100%', '0', 'sortable');
  184. }
  185. return ($result);
  186. }
  187. /**
  188. * returns last unused network address for new pool for some netid
  189. *
  190. * @param $netid existing network ID
  191. *
  192. * @return int
  193. */
  194. protected function getFreePoolNet($netid) {
  195. $netid = vf($netid, 3);
  196. $curNetPools = array();
  197. $result = false;
  198. if (!empty($this->networks[$netid])) {
  199. if (!empty($this->pools)) {
  200. //select last broadcast +1
  201. foreach ($this->pools as $io => $each) {
  202. if ($each['netid'] == $netid) {
  203. $curNetPools[$each['id']] = ip2int($each['broadcast']) + 1;
  204. }
  205. }
  206. } else {
  207. //network start IP
  208. $curNetPools[0] = ip2int($this->networks[$netid]['startip']);
  209. }
  210. if (empty($curNetPools)) {
  211. //network start IP
  212. $curNetPools[0] = ip2int($this->networks[$netid]['startip']);
  213. }
  214. $result = max($curNetPools);
  215. $result = int2ip($result);
  216. }
  217. return ($result);
  218. }
  219. /**
  220. * returns new pool creation form
  221. *
  222. * @param $netid int existing network ID
  223. *
  224. * @return string
  225. */
  226. public function poolCreateForm($netid) {
  227. $netid = vf($netid, 3);
  228. $poolProposal = $this->getFreePoolNet($netid);
  229. $inputs = wf_TextInput('newpool', __('Network'), $poolProposal, false, '15');
  230. $inputs .= wf_HiddenInput('newpoolnetid', $netid);
  231. $inputs.= wf_Selector('newpoolnetmask', $this->cidrs, __('Netmask'));
  232. $inputs.= wf_tag('br');
  233. $inputs.= wf_TextInput('newpoolvlan', __('VLAN'), '', true, '6');
  234. $inputs.= wf_Submit(__('Create'));
  235. $result = wf_Form("", 'POST', $inputs, 'glamour');
  236. return ($result);
  237. }
  238. /**
  239. * Creates new address pool in database
  240. *
  241. * @param ...
  242. *
  243. *
  244. * @return void
  245. */
  246. public function poolCreate($netid, $pool, $netmask, $vlan) {
  247. $netid = vf($netid, 3);
  248. $pool = mysql_real_escape_string($pool);
  249. $netmask = vf($netmask);
  250. $vlan = vf($vlan, 3);
  251. $query = "INSERT INTO `netextpools` (`id`, `netid`, `pool`, `netmask`, `gw`, `clientip`, `broadcast`, `vlan`, `login`) "
  252. . "VALUES (NULL, '" . $netid . "', '" . $pool . "', '" . $netmask . "', NULL, NULL, NULL, '" . $vlan . "', NULL);";
  253. nr_query($query);
  254. $newPoolId = simple_get_lastid('netextpools');
  255. log_register("POOL CREATE [" . $newPoolId . "] `" . $pool . "/" . $netmask . "`");
  256. $newGw = int2ip(ip2int($pool) + 1);
  257. $newBroadcast = int2ip(ip2int($pool) + ($this->cidrOffsets[$netmask] - 1));
  258. simple_update_field('netextpools', 'gw', $newGw, "WHERE `id`='" . $newPoolId . "';");
  259. simple_update_field('netextpools', 'broadcast', $newBroadcast, "WHERE `id`='" . $newPoolId . "';");
  260. //creating ips list for pool
  261. $newIpsStart = int2ip(ip2int($newGw) + 1);
  262. $newIpsEnd = int2ip(ip2int($newBroadcast) - 1);
  263. $this->ipsCreate($newPoolId, $newIpsStart, $newIpsEnd);
  264. }
  265. /**
  266. * deletes existing pool by ID from database
  267. *
  268. * @param $poolid int existing pool ID
  269. *
  270. * @return void
  271. */
  272. public function poolDelete($poolid) {
  273. $poolid = vf($poolid, 3);
  274. if (isset($this->pools[$poolid])) {
  275. $query = "DELETE from `netextpools` WHERE `id`='" . $poolid . "'";
  276. nr_query($query);
  277. log_register("POOL DELETE [" . $poolid . "]");
  278. //delete associated ips
  279. $this->ipsDeleteByPool($poolid);
  280. } else {
  281. throw new Exception(self::EX_NOEXPOOL);
  282. }
  283. }
  284. /**
  285. * returns full list of associated IPs for all pools
  286. *
  287. * @return void
  288. */
  289. protected function loadIps() {
  290. $query = "SELECT * from `netextips` ORDER BY `id` ASC";
  291. $all = simple_queryall($query);
  292. if (!empty($all)) {
  293. foreach ($all as $io => $each) {
  294. $this->ips[$each['id']] = $each;
  295. }
  296. }
  297. }
  298. /**
  299. * returns full list of associated IPs for some pool
  300. *
  301. * @param $poolid int existing pool ID
  302. *
  303. * @return array
  304. */
  305. protected function ipsGetByPool($poolid) {
  306. $poolid = vf($poolid, 3);
  307. $result = array();
  308. $query = "SELECT * from `netextips` WHERE `poolid`='" . $poolid . "';";
  309. $all = simple_queryall($query);
  310. if (!empty($all)) {
  311. foreach ($all as $io => $each) {
  312. $result[$each['id']] = $each;
  313. }
  314. }
  315. return ($result);
  316. }
  317. /**
  318. * Deletes ips for some pool by ID
  319. *
  320. * @param $poolid int existing pool ID
  321. *
  322. * @return void
  323. */
  324. protected function ipsDeleteByPool($poolid) {
  325. $poolid = vf($poolid, 3);
  326. $query = "DELETE from `netextips` WHERE `poolid`='" . $poolid . "';";
  327. nr_query($query);
  328. log_register("POOL [" . $poolid . "] IPS DELETED");
  329. }
  330. /**
  331. * creates some ips range for newly created pool
  332. *
  333. * @return void
  334. */
  335. protected function ipsCreate($poolid, $begin, $end) {
  336. $poolid = vf($poolid, 3);
  337. $begin = ip2int($begin);
  338. $end = ip2int($end);
  339. //valid ips ugly check
  340. if ($begin <= $end) {
  341. for ($i = $begin; $i <= $end; $i++) {
  342. $newIp = int2ip($i);
  343. $query = "INSERT INTO `netextips` "
  344. . "(`id`, `poolid`, `ip`, `nas`, `iface`, `mac`, `switchid`, `port`, `vlan`) "
  345. . "VALUES (NULL, '" . $poolid . "', '" . $newIp . "', NULL, NULL, NULL, NULL, NULL, NULL); ";
  346. nr_query($query);
  347. }
  348. }
  349. log_register("POOL [" . $poolid . "] IPS CREATE RANGE `" . int2ip($begin) . "-" . int2ip($end) . "` ");
  350. }
  351. /**
  352. * returns raw list of ips associated with some pool
  353. *
  354. * @param int $poolid Existing pool ID
  355. *
  356. * @return string
  357. */
  358. protected function ipsGetAssociated($poolid) {
  359. $poolid = vf($poolid, 3);
  360. $tmpArr = array();
  361. $result = '';
  362. if (!empty($this->pools)) {
  363. if (isset($this->pools[$poolid])) {
  364. if (!empty($this->ips)) {
  365. foreach ($this->ips as $io => $each) {
  366. if ($each['poolid'] == $poolid) {
  367. $tmpArr[$each['ip']] = $each['ip'];
  368. }
  369. }
  370. }
  371. }
  372. }
  373. if (!empty($tmpArr)) {
  374. $result = implode(', ', $tmpArr);
  375. }
  376. return ($result);
  377. }
  378. /**
  379. * Returns pool editing form
  380. *
  381. * @param int $poolid
  382. *
  383. * @return string
  384. */
  385. protected function poolEditForm($poolid) {
  386. $poolid = vf($poolid, 3);
  387. $inputs = wf_HiddenInput('editpoolid', $poolid);
  388. $inputs.= wf_HiddenInput('editpoolnetid', $this->pools[$poolid]['netid']);
  389. $inputs.= wf_TextInput('editpoollogin', __('Login'), $this->pools[$poolid]['login'], true, 10);
  390. $inputs.= wf_TextInput('editpoolvlan', __('VLAN'), $this->pools[$poolid]['vlan'], true, 5);
  391. $inputs.= wf_Submit(__('Save'));
  392. $result = wf_Form("", 'POST', $inputs, 'glamour');
  393. return ($result);
  394. }
  395. /**
  396. * Updates pool data into database
  397. *
  398. * @param int $poolid $
  399. * @param int $vlan vlan id of the pool
  400. * @param string $login existing ubilling user login
  401. *
  402. * @return void
  403. */
  404. public function poolEdit($poolid, $vlan, $login) {
  405. $poolid = vf($poolid, 3);
  406. $vlan = vf($vlan, 3);
  407. $login = trim($login);
  408. if (isset($this->pools[$poolid])) {
  409. simple_update_field('netextpools', 'vlan', $vlan, "WHERE `id`='" . $poolid . "';");
  410. simple_update_field('netextpools', 'login', $login, "WHERE `id`='" . $poolid . "';");
  411. log_register("POOL EDIT [" . $poolid . "] VLAN `" . $vlan . "` LOGIN `" . $login . "`");
  412. } else {
  413. throw new Exception(self::EX_NOEXPOOL);
  414. }
  415. }
  416. /**
  417. * renders control links for pools associated with some login
  418. *
  419. * @param string $login Existing ubilling user login
  420. *
  421. * @return string
  422. */
  423. public function poolsExtractByLogin($login) {
  424. $login = mysql_real_escape_string($login);
  425. $result = '';
  426. $tmpArr = array();
  427. if (!empty($this->pools)) {
  428. foreach ($this->pools as $io => $each) {
  429. if ($each['login'] == $login) {
  430. $tmpArr[$each['id']] = $each['pool'] . '/' . $each['netmask'];
  431. }
  432. }
  433. if (!empty($tmpArr)) {
  434. $result.=' + ';
  435. foreach ($tmpArr as $poolid => $pool) {
  436. $result.=wf_Link('?module=extnets&showipsbypoolid=' . $poolid, $pool, false, '');
  437. }
  438. }
  439. }
  440. return ($result);
  441. }
  442. /**
  443. * loads available switches array into private switches property
  444. *
  445. * @return void
  446. */
  447. protected function loadSwitches() {
  448. $query = "SELECT * from `switches`";
  449. $all = simple_queryall($query);
  450. if (!empty($all)) {
  451. foreach ($all as $io => $each) {
  452. $this->switches[$each['id']] = $each['ip'] . ' - ' . $each['location'];
  453. }
  454. }
  455. }
  456. /**
  457. * returns IP editin control
  458. *
  459. * @param int $ipid Existing IP database ID
  460. *
  461. * @return string
  462. */
  463. protected function ipsEditForm($ipid) {
  464. $ipid = vf($ipid, 3);
  465. $switchesSelector = array();
  466. $result = '';
  467. if (isset($this->ips[$ipid])) {
  468. if (empty($this->switches)) {
  469. $this->loadSwitches();
  470. }
  471. $switchesSelector = $this->switches;
  472. $switchesSelector['NULL'] = '-';
  473. natsort($switchesSelector);
  474. $inputs = wf_HiddenInput('editipid', $ipid);
  475. $inputs.= wf_TextInput('editipnas', __('NAS'), $this->ips[$ipid]['nas'], true, 15);
  476. $inputs.= wf_TextInput('editipiface', __('Interface'), $this->ips[$ipid]['iface'], true, 15);
  477. $inputs.= wf_TextInput('editipmac', __('MAC'), $this->ips[$ipid]['mac'], true, 15);
  478. $inputs.= wf_Selector('editipswitchid', $switchesSelector, __('Switch'), $this->ips[$ipid]['switchid'], true);
  479. $inputs.= wf_TextInput('editipport', __('Port'), $this->ips[$ipid]['port'], true, 5);
  480. $inputs.= wf_Submit(__('Save'));
  481. $result = wf_Form("", 'POST', $inputs, 'glamour');
  482. } else {
  483. throw new Exception(self::EX_NOEXIP);
  484. }
  485. return ($result);
  486. }
  487. /**
  488. * edits some ip in database
  489. *
  490. * @param
  491. *
  492. * @return void
  493. */
  494. public function ipsEdit($ipid, $nas, $iface, $mac, $switchid, $port) {
  495. simple_update_field('netextips', 'nas', $nas, "WHERE `id`='" . $ipid . "'");
  496. simple_update_field('netextips', 'iface', $iface, "WHERE `id`='" . $ipid . "'");
  497. simple_update_field('netextips', 'mac', $mac, "WHERE `id`='" . $ipid . "'");
  498. simple_update_field('netextips', 'switchid', $switchid, "WHERE `id`='" . $ipid . "'");
  499. simple_update_field('netextips', 'port', $port, "WHERE `id`='" . $ipid . "'");
  500. log_register("POOL IP [" . $ipid . "] EDIT `" . $this->ips[$ipid]['ip'] . "`");
  501. }
  502. /**
  503. * Renders ips associated with some poolid
  504. *
  505. * @param int $poolid Existing pool ID
  506. *
  507. * @return string
  508. */
  509. public function renderIps($poolid) {
  510. $poolid = vf($poolid, 3);
  511. $result = '';
  512. if (empty($this->switches)) {
  513. $this->loadSwitches();
  514. }
  515. if (isset($this->pools[$poolid])) {
  516. if (!empty($this->ips)) {
  517. $cells = wf_TableCell(__('ID'));
  518. $cells.= wf_TableCell(__('IP'));
  519. $cells.= wf_TableCell(__('Gateway'));
  520. $cells.= wf_TableCell(__('Netmask'));
  521. $cells.= wf_TableCell(__('NAS'));
  522. $cells.= wf_TableCell(__('Interface'));
  523. $cells.= wf_TableCell(__('MAC'));
  524. $cells.= wf_TableCell(__('Switch'));
  525. $cells.= wf_TableCell(__('Port'));
  526. $cells.= wf_TableCell(__('VLAN'));
  527. $cells.= wf_TableCell(__('Actions'));
  528. $rows = wf_TableRow($cells, 'row1');
  529. foreach ($this->ips as $io => $eachip) {
  530. if ($eachip['poolid'] == $poolid) {
  531. $cells = wf_TableCell($eachip['id']);
  532. $cells.= wf_TableCell($eachip['ip']);
  533. $cells.= wf_TableCell($this->pools[$poolid]['gw']);
  534. $cells.= wf_TableCell($this->cidrToMask[$this->pools[$poolid]['netmask']]);
  535. $cells.= wf_TableCell($eachip['nas']);
  536. $cells.= wf_TableCell($eachip['iface']);
  537. $cells.= wf_TableCell($eachip['mac']);
  538. $cells.= wf_TableCell(@$this->switches[$eachip['switchid']]);
  539. $cells.= wf_TableCell($eachip['port']);
  540. $cells.= wf_TableCell($this->pools[$poolid]['vlan']);
  541. $actionsLink = wf_modal(web_edit_icon(), __('Edit') . ' ' . $eachip['ip'], $this->ipsEditForm($eachip['id']), '', '400', '300');
  542. $cells.= wf_TableCell($actionsLink);
  543. $rows.= wf_TableRow($cells, 'row3');
  544. }
  545. }
  546. $result = wf_TableBody($rows, '100%', '0', 'sortable');
  547. //back links controls
  548. if (!empty($this->pools[$poolid]['login'])) {
  549. $result.= wf_Link("?module=userprofile&username=" . $this->pools[$poolid]['login'], web_profile_icon() . ' ' . __('Back to user profile'), false, 'ubButton');
  550. }
  551. $result.= wf_BackLink('?module=extnets&showpoolbynetid=' . $this->pools[$poolid]['netid'], __('Back') . ' ' . $this->pools[$poolid]['pool'] . '/' . $this->pools[$poolid]['netmask'], true);
  552. }
  553. } else {
  554. throw new Exception(self::EX_NOEXPOOL);
  555. }
  556. return ($result);
  557. }
  558. /**
  559. * returns user attach pool control
  560. *
  561. * @param string $login existing ubilling user login
  562. *
  563. * @return string
  564. */
  565. public function poolLinkingForm($login) {
  566. $poolsArr = array();
  567. if (!empty($this->pools)) {
  568. foreach ($this->pools as $io => $each) {
  569. if (empty($each['login'])) {
  570. $poolsArr[$each['id']] = $each['pool'] . '/' . $each['netmask'];
  571. }
  572. }
  573. }
  574. $inputs = wf_Selector('extnetspoollinkid', $poolsArr, __('IP associated with pool'), '', false);
  575. $inputs.= wf_HiddenInput('extnetspoollinklogin', $login);
  576. $inputs.= wf_Submit(__('Save'));
  577. $result = wf_Form("", 'POST', $inputs, 'glamour');
  578. return ($result);
  579. }
  580. /**
  581. * changes pool login
  582. *
  583. * @param int $poolid Existing poolID
  584. * @param string $login Existin ubilling user login
  585. *
  586. * @return void
  587. */
  588. public function poolLinkLogin($poolid, $login) {
  589. $poolid = vf($poolid, 3);
  590. $login = trim($login);
  591. if (isset($this->pools[$poolid])) {
  592. simple_update_field('netextpools', 'login', $login, "WHERE `id`='" . $poolid . "'");
  593. log_register("POOL LINK USER `" . $login . "`");
  594. } else {
  595. throw new Exception(self::EX_NOEXPOOL);
  596. }
  597. }
  598. /**
  599. * returns data for docx templatizer for login and associated pools
  600. *
  601. * @param string $login Existing ubilling user login
  602. *
  603. * @return string
  604. */
  605. public function poolTemplateData($login) {
  606. $result = '';
  607. $poolArr = array();
  608. if (!empty($this->pools)) {
  609. foreach ($this->pools as $io => $each) {
  610. if ($each['login'] == $login) {
  611. $poolArr[$each['id']]['gw'] = $each['gw'];
  612. $poolArr[$each['id']]['netmask'] = $this->cidrToMask[$each['netmask']];
  613. $poolArr[$each['id']]['ips'] = $this->ipsGetAssociated($each['id']);
  614. }
  615. }
  616. if (!empty($poolArr)) {
  617. foreach ($poolArr as $ia => $eachpool) {
  618. $result.=__('Gateway') . ': ' . $eachpool['gw'] . ' ' . __('Netmask') . ': ' . $eachpool['netmask'] . ' ' . __('IP') . ': ' . $eachpool['ips'] . ' ';
  619. }
  620. }
  621. }
  622. return ($result);
  623. }
  624. }
  625. ?>