api.userreg.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035
  1. <?php
  2. /**
  3. * Returns random alpha-numeric string of some lenght
  4. *
  5. * @param int $size
  6. * @return string
  7. */
  8. function zb_rand_string($size = 4) {
  9. $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
  10. $string = "";
  11. for ($p = 0; $p < $size; $p++) {
  12. $string .= $characters[mt_rand(0, (strlen($characters) - 1))];
  13. }
  14. return ($string);
  15. }
  16. /**
  17. * Returns random numeric string of some lenght
  18. *
  19. * @param int $size
  20. * @return string
  21. */
  22. function zb_rand_digits($size = 4) {
  23. $characters = '0123456789';
  24. $string = "";
  25. for ($p = 0; $p < $size; $p++) {
  26. $string .= $characters[mt_rand(0, (strlen($characters) - 1))];
  27. }
  28. return ($string);
  29. }
  30. /**
  31. * Returns some easy-to-remember password proposal
  32. *
  33. * @param int $len
  34. *
  35. * @return string
  36. */
  37. function zb_PasswordGenerate($len = 8) {
  38. $result = '';
  39. if ($len >= 6 && ( $len % 2 ) !== 0) {
  40. $len = 8;
  41. }
  42. $length = $len - 2; // Makes room for a two-digit number on the end
  43. $conso = array('b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'm', 'n', 'p', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z');
  44. $vocal = array('a', 'e', 'i', 'u');
  45. srand((double) microtime() * 1000000);
  46. $max = $length / 2;
  47. for ($i = 1; $i <= $max; $i++) {
  48. $result .= $conso[rand(0, sizeof($conso) - 1)];
  49. $result .= $vocal[rand(0, sizeof($vocal) - 1)];
  50. }
  51. $result .= rand(10, 99);
  52. return ($result);
  53. }
  54. /**
  55. * Returns two-hands typing optimized password proposal
  56. *
  57. * @param int $len
  58. *
  59. * @return string
  60. */
  61. function zb_PasswordGenerateTH($len = 8) {
  62. $leftHand = array('q', 'w', 'e', 'r', 't', 'a', 's', 'd', 'f', 'g', 'z', 'x', 'c', 'v', 'b', '2', '3', '4', '5', '6');
  63. $rightHand = array('y', 'u', 'p', 'h', 'j', 'k', 'n', 'm', '7', '8', '9');
  64. $password = '';
  65. $left = true;
  66. for ($i = 0; $i < $len; $i++) {
  67. if ($left) {
  68. $password .= $leftHand[array_rand($leftHand)];
  69. $left = false;
  70. } else {
  71. $password .= $rightHand[array_rand($rightHand)];
  72. $left = true;
  73. }
  74. }
  75. return $password;
  76. }
  77. /**
  78. * Returns array of apartments located in some build
  79. *
  80. * @param int $buildid
  81. * @return array
  82. */
  83. function zb_AddressGetBuildApts($buildid) {
  84. $buildid = vf($buildid, 3);
  85. $query = "SELECT * from `apt` WHERE `buildid`='" . $buildid . "'";
  86. $allapts = simple_queryall($query);
  87. $result = array();
  88. if (!empty($allapts)) {
  89. foreach ($allapts as $io => $each) {
  90. $result[$each['apt']] = $each['id'];
  91. }
  92. }
  93. return ($result);
  94. }
  95. /**
  96. * Returns array of apartments located in some build
  97. *
  98. * @param int $buildid
  99. * @return array
  100. */
  101. function zb_AddressGetBuildAptIds($buildid) {
  102. $buildid = vf($buildid, 3);
  103. $query = "SELECT `id`,`apt` from `apt` WHERE `buildid`='" . $buildid . "'";
  104. $allapts = simple_queryall($query);
  105. $result = array();
  106. if (!empty($allapts)) {
  107. foreach ($allapts as $io => $each) {
  108. $result[$each['id']] = $each['apt'];
  109. }
  110. }
  111. return ($result);
  112. }
  113. /**
  114. * Returns apt ocupancy check javascript code
  115. *
  116. * @param int $buildid
  117. * @param string $apt
  118. * @param string $login
  119. *
  120. * @return void/string on error
  121. */
  122. function web_AddressBuildShowAptsCheck($buildid, $apt = '', $login = '') {
  123. $result = '';
  124. $buildid = vf($buildid, 3);
  125. $messages = new UbillingMessageHelper();
  126. $allapts = zb_AddressGetBuildAptIds($buildid);
  127. $someoneLiveHere = false;
  128. $busyApts = array(); //IDs of apts which is busy
  129. if (!empty($allapts)) {
  130. foreach ($allapts as $aptid => $aptnum) {
  131. if ($aptnum == $apt) {
  132. $someoneLiveHere = true;
  133. $busyApts[$aptid] = $aptnum;
  134. }
  135. }
  136. }
  137. //display of users which lives in this apt
  138. if ($someoneLiveHere) {
  139. $allAddress = zb_AddressGetAddressAllData();
  140. if (!empty($allAddress)) {
  141. $similarAddressUsers = array();
  142. foreach ($allAddress as $io => $each) {
  143. if (isset($busyApts[$each['aptid']])) {
  144. if ($each['login'] != $login) {
  145. $similarAddressUsers[$each['login']] = $each['login'];
  146. }
  147. }
  148. }
  149. if (!empty($similarAddressUsers)) {
  150. $result .= $messages->getStyledMessage(__('The apartment has one lives, we have nothing against, just be warned'), 'warning');
  151. }
  152. //additional cosmetic delimiter for binder module
  153. if (!empty($login)) {
  154. $result .= wf_delimiter(0);
  155. }
  156. if (!empty($similarAddressUsers)) {
  157. $result .= web_UserArrayShower($similarAddressUsers);
  158. }
  159. }
  160. }
  161. //modal window width control for cosmetic purposes
  162. if (!empty($result)) {
  163. $result .= wf_tag('div', false, '', 'style="width:900px;"') . wf_tag('div', true);
  164. }
  165. return ($result);
  166. }
  167. /**
  168. * Returns wizard-like new user location form
  169. *
  170. * @return string
  171. */
  172. function web_UserRegFormLocation() {
  173. global $registerSteps;
  174. global $ubillingConfig;
  175. $aptsel = '';
  176. $servicesel = '';
  177. $currentStep = 0;
  178. $addressExten = '';
  179. $addressExtendedOn = $ubillingConfig->getAlterParam('ADDRESS_EXTENDED_ENABLED');
  180. if (!isset($_POST['citysel'])) {
  181. $citysel = web_CitySelectorAc(); // onChange="this.form.submit();
  182. $streetsel = '';
  183. } else {
  184. $citydata = zb_AddressGetCityData($_POST['citysel']);
  185. $citysel = $citydata['cityname'] . wf_HiddenInput('citysel', $citydata['id']);
  186. $streetsel = web_StreetSelectorAc($citydata['id']);
  187. $currentStep = 1;
  188. }
  189. if (isset($_POST['streetsel'])) {
  190. $streetdata = zb_AddressGetStreetData($_POST['streetsel']);
  191. $streetsel = $streetdata['streetname'] . wf_HiddenInput('streetsel', $streetdata['id']);
  192. $buildsel = web_BuildSelectorAc($_POST['streetsel']);
  193. $currentStep = 2;
  194. } else {
  195. $buildsel = '';
  196. }
  197. if (isset($_POST['buildsel'])) {
  198. $submit_btn = '';
  199. $builddata = zb_AddressGetBuildData($_POST['buildsel']);
  200. $buildsel = $builddata['buildnum'] . wf_HiddenInput('buildsel', $builddata['id']);
  201. $aptsel = web_AptCreateForm();
  202. if ($addressExtendedOn) {
  203. $addressExten = web_AddressExtenCreateForm();
  204. }
  205. $servicesel = multinet_service_selector();
  206. $freeIpStatsFlag = $ubillingConfig->getAlterParam('USERREG_FREEIP_STATS');
  207. if ($freeIpStatsFlag == 1 OR $freeIpStatsFlag == 3) {
  208. $servicesel .= wf_modalAuto(wf_img('skins/icon_whois_small.png', __('IP usage stats')), __('IP usage stats'), web_FreeIpStats());
  209. }
  210. $currentStep = 3;
  211. //contrahens user diff
  212. $alter_conf = rcms_parse_ini_file(CONFIG_PATH . "alter.ini");
  213. if (isset($alter_conf['LOGIN_GENERATION'])) {
  214. if ($alter_conf['LOGIN_GENERATION'] == 'DEREBAN') {
  215. $agentCells = wf_TableCell(zb_RegContrAhentSelect('regagent', $alter_conf['DEFAULT_ASSIGN_AGENT']));
  216. $agentCells .= wf_TableCell(__('Contrahent name'));
  217. $submit_btn .= wf_TableRow($agentCells, 'row2');
  218. }
  219. }
  220. $submit_btn .= wf_tag('tr', false, 'row3');
  221. $submit_btn .= wf_tag('td', false);
  222. $submit_btn .= wf_Submit(__('Save'));
  223. $submit_btn .= wf_tag('td', true);
  224. $submit_btn .= wf_tag('td', false);
  225. $submit_btn .= wf_tag('td', true);
  226. $submit_btn .= wf_tag('tr', true);
  227. } else {
  228. $submit_btn = '';
  229. }
  230. $formInputs = wf_tag('tr', false, 'row3');
  231. $formInputs .= wf_tag('td', false, '', 'width="50%"') . $citysel . wf_tag('td', true);
  232. $formInputs .= wf_tag('td', false) . __('City') . wf_tag('td', true);
  233. $formInputs .= wf_tag('tr', true);
  234. $formInputs .= wf_tag('tr', false, 'row3');
  235. $formInputs .= wf_tag('td', false) . $streetsel . wf_tag('td', true);
  236. $formInputs .= wf_tag('td', false) . __('Street') . wf_tag('td', true);
  237. $formInputs .= wf_tag('tr', true);
  238. $formInputs .= wf_tag('tr', false, 'row3');
  239. $formInputs .= wf_tag('td', false) . $buildsel . wf_tag('td', true);
  240. $formInputs .= wf_tag('td', false) . __('Build') . wf_tag('td', true);
  241. $formInputs .= wf_tag('tr', true);
  242. $formInputs .= wf_tag('tr', false, 'row3');
  243. $formInputs .= wf_tag('td', false) . $aptsel . wf_tag('td', true);
  244. $formInputs .= wf_tag('td', false) . __('Apartment') . wf_tag('td', true);
  245. $formInputs .= wf_tag('tr', true);
  246. if ($addressExtendedOn) {
  247. $formInputs .= wf_tag('tr', false, 'row3');
  248. $formInputs .= wf_tag('td', false) . $addressExten . wf_tag('td', true);
  249. $formInputs .= wf_tag('td', false) . __('Extended address info') . wf_tag('td', true);
  250. $formInputs .= wf_tag('tr', true);
  251. }
  252. $formInputs .= wf_tag('tr', false, 'row3');
  253. $formInputs .= wf_tag('td', false) . $servicesel . wf_tag('td', true);
  254. $formInputs .= wf_tag('td', false) . __('Service') . wf_tag('td', true);
  255. $formInputs .= wf_tag('tr', true);
  256. $formInputs .= wf_tag('br');
  257. $formInputs .= $submit_btn;
  258. $formData = wf_Form('', 'POST', $formInputs);
  259. $form = wf_TableBody($formData, '100%', '0', 'glamour');
  260. $form .= wf_tag('div', false, '', 'style="clear:both;"') . wf_tag('div', true);
  261. $form .= wf_StepsMeter($registerSteps, $currentStep);
  262. return($form);
  263. }
  264. /**
  265. * Returns array of all already busy user logins
  266. *
  267. * @return array
  268. */
  269. function zb_AllBusyLogins() {
  270. $query = "SELECT `login` from `users`";
  271. $alluserlogins = simple_queryall($query);
  272. $result = array();
  273. if (!empty($alluserlogins)) {
  274. foreach ($alluserlogins as $io => $each) {
  275. $result[$each['login']] = $each['login'];
  276. }
  277. }
  278. return ($result);
  279. }
  280. /**
  281. * Returns new user password proposal
  282. *
  283. * @return string
  284. */
  285. function zb_RegPasswordProposal() {
  286. global $ubillingConfig;
  287. $alterconf = $ubillingConfig->getAlter();
  288. $password_proposal = '';
  289. if ((isset($alterconf['PASSWORD_GENERATION_LENGHT'])) AND ( isset($alterconf['PASSWORD_TYPE']))) {
  290. $passwordsType = (isset($alterconf['PASSWORD_TYPE'])) ? $alterconf['PASSWORD_TYPE'] : 1;
  291. $passwordsLenght = (isset($alterconf['PASSWORD_GENERATION_LENGHT'])) ? $alterconf['PASSWORD_GENERATION_LENGHT'] : 8;
  292. switch ($passwordsType) {
  293. case 0:
  294. $password_proposal = zb_rand_digits($passwordsLenght);
  295. break;
  296. case 1:
  297. $password_proposal = zb_rand_string($passwordsLenght);
  298. break;
  299. case 2:
  300. $password_proposal = zb_PasswordGenerate($passwordsLenght);
  301. break;
  302. case 3:
  303. $password_proposal = zb_PasswordGenerateTH($passwordsLenght);
  304. break;
  305. default :
  306. $password_proposal = zb_rand_string(8);
  307. break;
  308. }
  309. } else {
  310. die(strtoupper('you have missed a essential option. before update read release notes motherfucker!'));
  311. }
  312. return ($password_proposal);
  313. }
  314. /**
  315. * Filters user login for only allowed symbols
  316. *
  317. * @param string $login
  318. * @return string
  319. */
  320. function zb_RegLoginFilter($login) {
  321. $login = str_replace(' ', '_', $login);
  322. $result = preg_replace("#[^a-z0-9A-Z_]#Uis", '', $login);
  323. return ($result);
  324. }
  325. /**
  326. * Returns alert if generated user login have rscripd incompatible lenght
  327. *
  328. * @param string $login
  329. * @return string
  330. */
  331. function zb_CheckLoginRscriptdCompat($login) {
  332. $maxRsLen = 31;
  333. $maxStLen = 42;
  334. $loginLen = strlen($login);
  335. if (($loginLen >= $maxRsLen)) {
  336. //rscriptd notice
  337. if ($loginLen < $maxStLen) {
  338. $alert = __('Attention generated login longer than') . ' ' . $maxRsLen . ' ' . __('bytes') . '. (' . $loginLen . ') ' . __('This can lead to the inability to manage this user on remote NAS running rscriptd') . '. ';
  339. $alert .= __('Perhaps you need to shorten the alias, or use a different model for the generation of logins') . '.';
  340. $result = wf_modalOpened(__('Warning'), $alert, '500', '200');
  341. }
  342. //stargazer incompat notice
  343. if ($loginLen >= $maxStLen) {
  344. $alert = __('Attention generated login longer than') . ' ' . $maxStLen . ' ' . __('bytes') . '. (' . $loginLen . ') ' . __('And is not compatible with Stargazer') . '. ';
  345. $alert .= __('Perhaps you need to shorten the alias, or use a different model for the generation of logins') . '.';
  346. $result = wf_modalOpened(__('Error'), $alert, '500', '200');
  347. }
  348. } else {
  349. $result = '';
  350. }
  351. return ($result);
  352. }
  353. /**
  354. * Returns register last step form
  355. *
  356. * @param array $newuser_data
  357. * @return string
  358. */
  359. function web_UserRegFormNetData($newuser_data) {
  360. global $registerSteps;
  361. global $ubillingConfig;
  362. $currentStep = 4;
  363. $form = '';
  364. $alterconf = $ubillingConfig->getAlter();
  365. if ($alterconf['BRANCHES_ENABLED']) {
  366. global $branchControl;
  367. }
  368. $safe_mode = $alterconf['SAFE_REGMODE'];
  369. $citydata = zb_AddressGetCityData($newuser_data['city']);
  370. $cityalias = zb_TranslitString($citydata['cityalias']);
  371. $streetdata = zb_AddressGetStreetData($newuser_data['street']);
  372. $streetalias = zb_TranslitString($streetdata['streetalias']);
  373. $buildata = zb_AddressGetBuildData($newuser_data['build']);
  374. $buildnum = zb_TranslitString($buildata['buildnum']);
  375. if (empty($newuser_data['apt'])) {
  376. $newuser_data['apt'] = 0;
  377. }
  378. $apt = zb_TranslitString($newuser_data['apt']);
  379. //assign some agent from previously selected form
  380. if (isset($alterconf['LOGIN_GENERATION'])) {
  381. if ($alterconf['LOGIN_GENERATION'] == 'DEREBAN') {
  382. $agentPrefixID = $newuser_data['contrahent'];
  383. } else {
  384. $agentPrefixID = '';
  385. }
  386. } else {
  387. $agentPrefixID = '';
  388. }
  389. $ip_proposal = multinet_get_next_freeip('nethosts', 'ip', multinet_get_service_networkid($newuser_data['service']));
  390. $login_proposal = '';
  391. $loginGenerator = new SayMyName($cityalias, $streetalias, $buildnum, $apt, $ip_proposal, $agentPrefixID);
  392. try {
  393. $login_proposal = $loginGenerator->getLogin();
  394. } catch (Exception $exception) {
  395. show_error(__('Strange exception') . ': ' . $exception->getMessage());
  396. }
  397. $password_proposal = zb_RegPasswordProposal();
  398. if (empty($ip_proposal)) {
  399. $alert = wf_tag('script', false, '', 'type="text/javascript"');
  400. $alert .= 'alert("' . __('Error') . ': ' . __('No free IP available in selected pool') . '");';
  401. $alert .= wf_tag('script', true);
  402. print($alert);
  403. rcms_redirect("?module=multinet");
  404. die();
  405. }
  406. //protect important options
  407. if ($safe_mode) {
  408. $modifier = 'READONLY';
  409. } else {
  410. $modifier = '';
  411. }
  412. $addressCheck = web_AddressBuildShowAptsCheck($buildata['id'], $apt);
  413. if (!empty($addressCheck)) {
  414. $form .= wf_modalOpenedAuto(__('Warning'), $addressCheck, '800', '300');
  415. }
  416. $form .= wf_tag('table', false, 'glamour', 'width="100%" border="0"');
  417. $form .= wf_tag('form', false, '', ' action="" method="POST"');
  418. $form .= wf_tag('tr', false, 'row3');
  419. $form .= wf_tag('td', false, '', 'width="65%"');
  420. if ($safe_mode) {
  421. $form .= wf_tag('input', false, '', 'type="text" name="login" value="' . $login_proposal . '" READONLY');
  422. } else {
  423. $form .= wf_TextInput('login', '', $login_proposal, false, '', 'login');
  424. }
  425. $form .= wf_tag('td', true);
  426. $form .= wf_tag('td', false);
  427. $form .= __('Login') . ' ' . zb_CheckLoginRscriptdCompat($login_proposal);
  428. $form .= wf_tag('td', true);
  429. $form .= wf_tag('tr', true);
  430. $form .= wf_tag('tr', false, 'row3');
  431. $form .= wf_tag('td', false);
  432. $form .= wf_tag('input', false, '', 'type="text" name="password" value="' . $password_proposal . '" ' . $modifier);
  433. $form .= wf_tag('td', true);
  434. $form .= wf_tag('td', false);
  435. $form .= __('Password');
  436. $form .= wf_tag('td', true);
  437. $form .= wf_tag('tr', true);
  438. $form .= wf_tag('tr', false, 'row3');
  439. $form .= wf_tag('td', false);
  440. $ipPattern = 'pattern="^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$" placeholder="0.0.0.0" title="' . __('The IP address format can be') . ': 192.1.1.1"';
  441. $form .= wf_tag('input', false, '', 'type="text" name="IP" value="' . $ip_proposal . '" ' . $ipPattern . ' ' . $modifier);
  442. $form .= wf_tag('td', true);
  443. $form .= wf_tag('td', false);
  444. $form .= __('IP');
  445. $form .= wf_tag('td', true);
  446. $form .= wf_tag('tr', true);
  447. if (isset($alterconf['USERREG_MAC_INPUT_ENABLED']) and $alterconf['USERREG_MAC_INPUT_ENABLED']) {
  448. $form .= wf_tag('tr', false, 'row3');
  449. $form .= wf_tag('td', false);
  450. $form .= wf_TextInput('userMAC', '', '', false, 12, 'mac');
  451. $form .= wf_tag('td', true);
  452. $form .= wf_tag('td', false);
  453. $form .= __('MAC');
  454. $form .= wf_tag('td', true);
  455. $form .= wf_tag('tr', true);
  456. }
  457. if ($alterconf['BRANCHES_ENABLED']) {
  458. $form .= wf_tag('tr', false, 'row3');
  459. $form .= wf_tag('td', false);
  460. $form .= $branchControl->branchSelector('reguserbranchid') . ' ';
  461. if ((!cfr('BRANCHES')) OR ( cfr('ROOT'))) {
  462. $branchCheckboxFlag = ($ubillingConfig->getAlterParam('USERREG_NO_BRANCH_DEFAULT')) ? true : false;
  463. $form .= wf_CheckInput('reguserwithnobranch', __('Register user with no branch'), false, $branchCheckboxFlag);
  464. }
  465. $form .= wf_tag('td', true);
  466. $form .= wf_tag('td', false);
  467. $form .= __('Branch');
  468. $form .= wf_tag('td', true);
  469. $form .= wf_tag('tr', true);
  470. }
  471. if (@$alterconf['ONUAUTO_USERREG']) {
  472. $ponAPIObject = new PONizer();
  473. $allOLTs = $ponAPIObject->getAllOltDevices();
  474. $models = array();
  475. $modelsData = $ponAPIObject->getAllModelsData();
  476. if (!empty($modelsData)) {
  477. foreach ($modelsData as $io => $each) {
  478. if (@$alterconf['ONUMODELS_FILTER']) {
  479. if (ispos($each['modelname'], 'ONU')) {
  480. $models[$each['id']] = $each['modelname'];
  481. }
  482. } else {
  483. $models[$each['id']] = $each['modelname'];
  484. }
  485. }
  486. }
  487. $form .= wf_tag('tr', false, 'row3');
  488. $form .= wf_tag('tr', true, 'row3');
  489. $form .= wf_tag('tr', false, 'row3');
  490. $form .= wf_tag('tr', true, 'row3');
  491. $form .= wf_tag('tr', false, 'row3');
  492. $form .= wf_tag('td', false, '', 'style="padding-left: 15px"');
  493. $form .= wf_tag('h3', false, '', 'style="color: #000"');
  494. $form .= __('Associate ONU with subscriber');
  495. $form .= wf_tag('h3', true);
  496. $form .= wf_tag('td', true);
  497. $form .= wf_tag('td', false);
  498. $form .= wf_tag('td', true);
  499. $form .= wf_tag('tr', true);
  500. if (empty($allOLTs)) {
  501. $form .= wf_tag('tr', false, 'row3');
  502. $form .= wf_tag('td', false, '', 'style="text-align: center;" colspan="2"');
  503. $form .= wf_tag('h3', false, '', 'style="color: #000"');
  504. $form .= __('No OLT devices found - can not associate ONU');
  505. $form .= wf_tag('h3', true);
  506. $form .= wf_tag('td', true);
  507. $form .= wf_tag('tr', true);
  508. $form .= wf_HiddenInput('nooltsfound', 'true');
  509. } else {
  510. $form .= wf_tag('tr', false, 'row3');
  511. $form .= wf_tag('td', false);
  512. $form .= wf_Selector('oltid', $allOLTs, '', '', true, false, 'OLTSelector');
  513. $form .= wf_tag('script', false, '', 'type="text/javascript"');
  514. $form .= '
  515. $(document).ready(function() {
  516. getUnknownONUList($(\'#OLTSelector\').val());
  517. });
  518. $(\'#OLTSelector\').change(function(){
  519. getUnknownONUList($(this).val());
  520. });
  521. function getUnknownONUList(OLTID) {
  522. $.ajax({
  523. type: "GET",
  524. url: "?module=userreg",
  525. data: {
  526. getunknownlist:true,
  527. oltid:OLTID,
  528. selectorid:"UnknonwnsSelectorID",
  529. selectorname:"UnknonwnsSelector"
  530. },
  531. success: function(result) {
  532. $(\'#UnknonwnsSelBlock\').html(result);
  533. }
  534. });
  535. }
  536. ';
  537. $form .= wf_tag('script', true);
  538. $form .= wf_tag('td', true);
  539. $form .= wf_tag('td', false);
  540. $form .= __('OLT device') . wf_tag('sup') . '*' . wf_tag('sup', true);
  541. $form .= wf_tag('td', true);
  542. $form .= wf_tag('tr', true);
  543. $form .= wf_tag('tr', false, 'row3');
  544. $form .= wf_tag('td', false);
  545. $form .= wf_Selector('onumodelid', $models, '', '', true);
  546. $form .= wf_tag('td', true);
  547. $form .= wf_tag('td', false);
  548. $form .= __('ONU model') . wf_tag('sup') . '*' . wf_tag('sup', true);
  549. $form .= wf_tag('td', true);
  550. $form .= wf_tag('tr', true);
  551. $form .= wf_tag('tr', false, 'row3');
  552. $form .= wf_tag('td', false);
  553. $form .= wf_tag('input', false, '', 'type="text" name="onuip" value="" ');
  554. $form .= wf_CheckInput('onuipproposal', __('Make ONU IP same as subscriber IP'), false, false);
  555. $form .= wf_tag('script', false, '', 'type="text/javascript"');
  556. $form .= '$(\'[name = onuipproposal]\').change(function() {
  557. if ( $(this).is(\':checked\') ) {
  558. $(\'[name = onuip]\').attr("readonly", "readonly");
  559. $(\'[name = onuip]\').css(\'background-color\', \'#CECECE\')
  560. } else {
  561. $(\'[name = onuip]\').removeAttr("readonly");
  562. $(\'[name = onuip]\').css(\'background-color\', \'#FFFFFF\')
  563. }
  564. });';
  565. $form .= wf_tag('script', true);
  566. $form .= wf_tag('td', true);
  567. $form .= wf_tag('td', false);
  568. $form .= __('ONU IP');
  569. $form .= wf_tag('td', true);
  570. $form .= wf_tag('tr', true);
  571. $form .= wf_tag('tr', false, 'row3');
  572. $form .= wf_tag('td', false);
  573. $form .= wf_tag('input', false, '', 'type="text" name="onumac" id="onumacid" value="" ');
  574. //$form.= wf_delimiter();
  575. $form .= '&nbsp&nbsp' . __('or choose MAC from unknown ONU\'s list on chosen OLT') . '&nbsp&nbsp';
  576. $form .= wf_tag('div', false, '', 'id="UnknonwnsSelBlock" style="display:inline-block"');
  577. $form .= wf_tag('div', true);
  578. $form .= wf_tag('script', false, '', 'type="text/javascript"');
  579. $form .= '$(document).on("change", "#UnknonwnsSelectorID", function(){
  580. $(\'#onumacid\').val($(this).val());
  581. });';
  582. $form .= wf_tag('script', true);
  583. $form .= wf_tag('td', true);
  584. $form .= wf_tag('td', false);
  585. $form .= __('ONU MAC') . wf_tag('sup') . '*' . wf_tag('sup', true);
  586. $form .= wf_tag('td', true);
  587. $form .= wf_tag('tr', true);
  588. $form .= wf_tag('tr', false, 'row3');
  589. $form .= wf_tag('td', false);
  590. $form .= wf_tag('input', false, '', 'type="text" name="onuserial" value="" ');
  591. $form .= wf_tag('td', true);
  592. $form .= wf_tag('td', false);
  593. $form .= __('ONU serial');
  594. $form .= wf_tag('td', true);
  595. $form .= wf_tag('tr', true);
  596. $form .= wf_tag('tr', false, 'row3');
  597. $form .= wf_tag('td', false);
  598. $form .= wf_tag('a', false, 'ubButton', 'href="" class="ubButton" id="onuassignment1"');
  599. $form .= __('Check if ONU is assigned to any login already');
  600. $form .= wf_tag('a', true);
  601. $form .= wf_tag('script', false, '', 'type="text/javascript"');
  602. $form .= '$(\'#onuassignment1\').click(function(evt){
  603. evt.preventDefault();
  604. if ( typeof( $(\'input[name=onumac]\').val() ) === "string" && $(\'input[name=onumac]\').val().length > 0 ) {
  605. $.ajax({
  606. type: "GET",
  607. url: "?module=ponizer",
  608. data: {action:\'checkONUAssignment\', onumac:$(\'input[name=onumac]\').val()},
  609. success: function(result) {
  610. $(\'#onuassignment2\').text(result);
  611. }
  612. });
  613. } else {$(\'#onuassignment2\').text(\'\');}
  614. return false;
  615. });';
  616. $form .= wf_tag('script', true);
  617. $form .= wf_tag('td', true);
  618. $form .= wf_tag('td', false);
  619. $form .= wf_tag('p', false, '', 'id="onuassignment2" style="font-weight: 600; color: #000"');
  620. $form .= wf_tag('p', true);
  621. $form .= wf_tag('td', true);
  622. $form .= wf_tag('tr', true);
  623. }
  624. }
  625. $form .= wf_tag('table', true);
  626. $form .= wf_HiddenInput('repostdata', base64_encode(serialize($newuser_data)));
  627. $form .= wf_Submit(__('Let register that user'));
  628. $form .= wf_tag('form', true);
  629. $form .= wf_tag('div', false, '', 'style="clear:both;"') . wf_tag('div', true);
  630. $form .= wf_StepsMeter($registerSteps, $currentStep);
  631. return($form);
  632. }
  633. /**
  634. * Puts userreg log entry into database
  635. *
  636. * @param string $login
  637. *
  638. * @return void
  639. */
  640. function zb_UserRegisterLog($login) {
  641. $date = curdatetime();
  642. $admin = whoami();
  643. $login = vf($login);
  644. $address = zb_AddressGetFulladdresslist();
  645. $address = $address[$login];
  646. $address = mysql_real_escape_string($address);
  647. $query = "INSERT INTO `userreg` (`id` ,`date` ,`admin` ,`login` ,`address`) "
  648. . "VALUES (NULL , '" . $date . "', '" . $admin . "', '" . $login . "', '" . $address . "');";
  649. nr_query($query);
  650. }
  651. /**
  652. * Checks is some IP unique?
  653. *
  654. * @param string $ip
  655. * @return bool
  656. */
  657. function zb_ip_unique($ip) {
  658. $ip = mysql_real_escape_string($ip);
  659. $query = "SELECT `login` from `users` WHERE `ip`='" . $ip . "'";
  660. $usersbyip = simple_queryall($query);
  661. if (!empty($usersbyip)) {
  662. return (false);
  663. } else {
  664. return (true);
  665. }
  666. }
  667. /**
  668. * Checks is some MAC unique?
  669. *
  670. * @param string $mac
  671. * @return bool
  672. */
  673. function zb_mac_unique($mac) {
  674. $ip = mysql_real_escape_string($mac);
  675. $query = "SELECT `mac` from `nethosts` WHERE `mac`='" . $mac . "'";
  676. $usersbymac = simple_queryall($query);
  677. if (!empty($usersbymac)) {
  678. return (false);
  679. } else {
  680. return (true);
  681. }
  682. }
  683. /**
  684. * Assigns some user tags to the $login from the default tags list
  685. *
  686. * @param $login
  687. * @param $defaultTagsList
  688. *
  689. * @return void
  690. */
  691. function assignDefaultTags($login, $defaultTagsList) {
  692. if (!empty($login) and !empty($defaultTagsList)) {
  693. $defaultTagsList = explode(',', $defaultTagsList);
  694. foreach ($defaultTagsList as $io => $eachTagID) {
  695. $tmpTagID = trim($eachTagID);
  696. stg_add_user_tag($login, $tmpTagID);
  697. }
  698. }
  699. }
  700. /**
  701. * Performs an user registration
  702. *
  703. * @global object $billing
  704. * @param array $user_data
  705. * @param bool $goprofile
  706. */
  707. function zb_UserRegister($user_data, $goprofile = true) {
  708. global $billing, $ubillingConfig;
  709. $billingconf = $ubillingConfig->getBilling();
  710. $alterconf = $ubillingConfig->getAlter();
  711. $addressExtendedOn = $ubillingConfig->getAlterParam('ADDRESS_EXTENDED_ENABLED');
  712. $registerUserONU = $ubillingConfig->getAlterParam('ONUAUTO_USERREG');
  713. $contractTemplateStr = $ubillingConfig->getAlterParam('CONTRACT_GEN_TEMPLATE', '');
  714. $defaultTagsList = $ubillingConfig->getAlterParam('USERREG_DEFAULT_TAGS_LIST', '');
  715. $needONUAssignment = false;
  716. // Init all of needed user data
  717. $login = vf($user_data['login']);
  718. $login = zb_RegLoginFilter($login);
  719. $password = vf($user_data['password']);
  720. $ip = $user_data['IP'];
  721. $cityid = $user_data['city'];
  722. $streetid = $user_data['street'];
  723. $buildid = $user_data['build'];
  724. @$entrance = $user_data['entrance'];
  725. @$floor = $user_data['floor'];
  726. $apt = $user_data['apt'];
  727. $serviceid = $user_data['service'];
  728. if ($addressExtendedOn) {
  729. $postCode = $user_data['postalcode'];
  730. $extenTown = $user_data['towndistr'];
  731. $extenAddr = $user_data['addressexten'];
  732. }
  733. //ONU auto assign options
  734. if ($registerUserONU and !empty($user_data['oltid'])) {
  735. $OLTID = $user_data['oltid'];
  736. $ONUModelID = $user_data['onumodelid'];
  737. $ONUIP = $user_data['onuip'];
  738. $ONUMAC = $user_data['onumac'];
  739. $ONUSerial = $user_data['onuserial'];
  740. $needONUAssignment = !empty($ONUMAC);
  741. }
  742. if (isset($user_data['userMAC']) and !empty($user_data['userMAC'])) {
  743. $mac = strtolower($user_data['userMAC']);
  744. } elseif ($billingconf['REGRANDOM_MAC']) {
  745. // if random mac needed
  746. // funny random mac, yeah? :)
  747. $mac = zb_MacGetRandom();
  748. } else {
  749. $mac = null;
  750. }
  751. $netid = multinet_get_service_networkid($serviceid);
  752. $busylogins = zb_AllBusyLogins();
  753. //check login lenght
  754. $maxStLen = 42;
  755. $loginLen = strlen($login);
  756. if ($loginLen > $maxStLen) {
  757. log_register("HUGELOGIN REGISTER TRY (" . $login . ")");
  758. $alert = __('Attention generated login longer than') . ' ' . $maxStLen . ' ' . __('bytes') . '. (' . $login . ' > ' . $loginLen . ') ' . __('And is not compatible with Stargazer') . '.';
  759. die($alert);
  760. }
  761. // empty login validation
  762. if (empty($login)) {
  763. $alert = wf_tag('script', false, '', 'type="text/javascript"');
  764. $alert .= 'alert("' . __('Error') . ': ' . __('Empty login') . '");';
  765. $alert .= wf_tag('script', true);
  766. print($alert);
  767. rcms_redirect("?module=userreg");
  768. die();
  769. }
  770. //duplicate login validation
  771. if (isset($busylogins[$login])) {
  772. $alert = wf_tag('script', false, '', 'type="text/javascript"');
  773. $alert .= 'alert("' . __('Error') . ': ' . __('Duplicate login') . '");';
  774. $alert .= wf_tag('script', true);
  775. print($alert);
  776. rcms_redirect("?module=userreg");
  777. die();
  778. }
  779. //last checks
  780. if (!zb_ip_unique($ip)) {
  781. $alert = wf_tag('script', false, '', 'type="text/javascript"');
  782. $alert .= 'alert("' . __('Error') . ': ' . __('This IP is already used by another user') . '");';
  783. $alert .= wf_tag('script', true);
  784. print($alert);
  785. rcms_redirect("?module=userreg");
  786. die();
  787. }
  788. // registration subroutine
  789. $billing->createuser($login);
  790. log_register("StgUser REGISTER (" . $login . ")");
  791. $billing->setpassword($login, $password);
  792. log_register("StgUser (" . $login . ") PASSWORD `" . $password . "`");
  793. $billing->setip($login, $ip);
  794. log_register("StgUser (" . $login . ") IP `" . $ip . "`");
  795. zb_AddressCreateApartment($buildid, $entrance, $floor, $apt);
  796. zb_AddressCreateAddress($login, zb_AddressGetLastid());
  797. multinet_add_host($netid, $ip, $mac);
  798. zb_UserCreateRealName($login, '');
  799. zb_UserCreatePhone($login, '', '');
  800. zb_UserCreateContract($login, '');
  801. zb_UserCreateEmail($login, '');
  802. zb_UserCreateSpeedOverride($login, 0);
  803. zb_UserRegisterLog($login);
  804. // if AlwaysOnline to new user needed
  805. if ($billingconf['REGALWONLINE']) {
  806. $alwaysonline = 1;
  807. $billing->setao($login, $alwaysonline);
  808. log_register('CHANGE AlwaysOnline (' . $login . ') ON ' . $alwaysonline);
  809. }
  810. // if we want to disable detailed stats to new user by default
  811. if ($billingconf['REGDISABLEDSTAT']) {
  812. $dstat = 1;
  813. $billing->setdstat($login, $dstat);
  814. log_register('CHANGE dstat (' . $login . ') ON ' . $dstat);
  815. }
  816. // new users registers as frozen by default
  817. if (isset($billingconf['REGFROZEN'])) {
  818. if ($billingconf['REGFROZEN']) {
  819. $billing->setpassive($login, 1);
  820. log_register('CHANGE Passive (' . $login . ') ON 1');
  821. }
  822. }
  823. //set contract same as login for this user
  824. if (isset($alterconf['CONTRACT_SAME_AS_LOGIN'])) {
  825. if ($alterconf['CONTRACT_SAME_AS_LOGIN']) {
  826. $newUserContract = $login;
  827. $contractDate = date("Y-m-d");
  828. zb_UserChangeContract($login, $newUserContract);
  829. zb_UserContractDateCreate($newUserContract, $contractDate);
  830. }
  831. }
  832. //cemetery processing
  833. if (isset($alterconf['CEMETERY_ENABLED'])) {
  834. if ($alterconf['CEMETERY_ENABLED']) {
  835. if ($alterconf['CEMETERY_ENABLED'] == 2) {
  836. $cemetery = new Cemetery(false);
  837. $cemetery->setDead($login);
  838. }
  839. }
  840. }
  841. //contract autogeneration
  842. if (isset($alterconf['CONTRACT_AUTOGEN']) and empty($alterconf['CONTRACT_SAME_AS_LOGIN'])) {
  843. if ($alterconf['CONTRACT_AUTOGEN']) {
  844. $contract_proposal = '';
  845. $allcontracts = zb_UserGetAllContracts();
  846. $useContractTemplate = !empty($contractTemplateStr);
  847. $top_offset = 100000;
  848. //contract template is ON
  849. if ($useContractTemplate) {
  850. $contractTemplateSplitted = zb_GetBaseContractTemplateSplitted();
  851. $startContractTplPart = $contractTemplateSplitted[0];
  852. $endContractTplPart = $contractTemplateSplitted[1];
  853. $digitContractTplPart = $contractTemplateSplitted[2];
  854. $digitBlockLength = zb_GetContractDigitBlockTplParams($digitContractTplPart, true);
  855. }
  856. //contract generation mode default
  857. if ($alterconf['CONTRACT_GENERATION_DEFAULT']) {
  858. for ($i = 1; $i < $top_offset; $i++) {
  859. if ($useContractTemplate) {
  860. $contractDigitBlock = zb_GenContractDigitBlock($digitBlockLength, $i);
  861. $tmpContract = $startContractTplPart . $contractDigitBlock . $endContractTplPart;
  862. } else {
  863. $tmpContract = $i;
  864. }
  865. if (!isset($allcontracts[$tmpContract])) {
  866. $contract_proposal = $tmpContract;
  867. break;
  868. }
  869. }
  870. } else {
  871. //alternate generation method
  872. $max_contract = max(array_keys($allcontracts));
  873. if ($useContractTemplate) {
  874. $contractDigitBlock = zb_ExtractContractDigitPart($max_contract, $digitBlockLength, true);
  875. $contract_proposal = $startContractTplPart . $contractDigitBlock . $endContractTplPart;
  876. } else {
  877. if (!is_int($contract_proposal)) {
  878. $contract_proposal=0;
  879. }
  880. $contract_proposal = $max_contract + 1;
  881. }
  882. }
  883. if (empty($contract_proposal) and $useContractTemplate) {
  884. $contract_proposal = zb_GenBaseContractFromTemplate();
  885. }
  886. //setting generated contract to new user
  887. if (!isset($allcontracts[$contract_proposal])) {
  888. $contractDate = date("Y-m-d");
  889. zb_UserChangeContract($login, $contract_proposal);
  890. zb_UserContractDateCreate($contract_proposal, $contractDate);
  891. }
  892. }
  893. }
  894. //branches assign for newly created user
  895. if ($alterconf['BRANCHES_ENABLED']) {
  896. global $branchControl;
  897. if ((wf_CheckPost(array('reguserbranchid'))) AND (!wf_CheckPost(array('reguserwithnobranch')))) {
  898. $newUserBranchId = vf($_POST['reguserbranchid'], 3);
  899. $branchControl->userAssignBranch($newUserBranchId, $login);
  900. }
  901. }
  902. // ONU assign for newly created user
  903. if ($registerUserONU and $needONUAssignment) {
  904. $PONAPIObject = new PONizer();
  905. if ($PONAPIObject->checkOnuUnique($ONUMAC)) {
  906. $PONAPIObject->onuCreate($ONUModelID, $OLTID, $ONUIP, $ONUMAC, $ONUSerial, $login);
  907. } else {
  908. $ONUID = $PONAPIObject->getOnuIDbyIdent($ONUMAC);
  909. $PONAPIObject->onuAssign($ONUID, $login);
  910. }
  911. }
  912. if ($addressExtendedOn) {
  913. zb_AddAddressExtenSave($login, false, $postCode, $extenTown, $extenAddr);
  914. }
  915. //static OpenPayz payment IDs registration
  916. if ($alterconf['OPENPAYZ_SUPPORT']) {
  917. if ($alterconf['OPENPAYZ_STATIC_ID']) {
  918. $openPayz = new OpenPayz(false, true);
  919. $openPayz->registerStaticPaymentId($login);
  920. }
  921. }
  922. // default user tags list processing
  923. if (!empty($defaultTagsList)) {
  924. assignDefaultTags($login, $defaultTagsList);
  925. }
  926. ///////////////////////////////////
  927. if ($goprofile) {
  928. rcms_redirect("?module=userprofile&username=" . $login . '&justregistered=true');
  929. }
  930. }