index.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. if (cfr('PLCHECKER')) {
  3. /**
  4. * Checks is field available in database?
  5. *
  6. * @param string $table
  7. * @param string $login
  8. *
  9. * @return bool
  10. */
  11. function zb_plcheckfield($table, $login) {
  12. $login = mysql_real_escape_string($login);
  13. $table = mysql_real_escape_string($table);
  14. $query = "SELECT `id` from `" . $table . "` where `login`='" . $login . "'";
  15. $result = simple_queryall($query);
  16. $result = (!empty($result)) ? 1 : 0;
  17. return ($result);
  18. }
  19. /**
  20. * Checks user nethost availablity
  21. *
  22. * @param string $login
  23. *
  24. * @return int 1 - ok, 0 - not exists, false - duplicate
  25. */
  26. function zb_plchecknethost($login) {
  27. $login = mysql_real_escape_string($login);
  28. $ip = zb_UserGetIP($login);
  29. $query = "SELECT `id` from `nethosts` where `ip`='" . $ip . "'";
  30. $all = simple_queryall($query);
  31. if (!empty($all)) {
  32. $result = 1;
  33. }
  34. if (empty($all)) {
  35. $result = 0;
  36. }
  37. if (sizeof($all) > 1) {
  38. $result = -1;
  39. }
  40. return ($result);
  41. }
  42. /**
  43. * Returns default field fixing form
  44. *
  45. * @param string $login
  46. * @param string $field
  47. * @param bool $flag
  48. *
  49. * @return string
  50. */
  51. function web_plfixerform($login, $field, $flag) {
  52. $result = '';
  53. if (($flag != 1)) {
  54. $inputs = wf_HiddenInput('fixme', $field);
  55. $inputs .= wf_Submit(__('Fix'));
  56. $result .= wf_Form('', 'POST', $inputs, '');
  57. }
  58. return($result);
  59. }
  60. /**
  61. * Performs fixing of some user database fields
  62. *
  63. * @param string $login
  64. * @param string $field
  65. *
  66. * @return void
  67. */
  68. function zb_plfixer($login, $field) {
  69. if ($field == 'emails') {
  70. zb_UserCreateEmail($login, '');
  71. rcms_redirect("?module=pl_checker&username=" . $login);
  72. }
  73. if ($field == 'contracts') {
  74. zb_UserCreateContract($login, '');
  75. rcms_redirect("?module=pl_checker&username=" . $login);
  76. }
  77. if ($field == 'phones') {
  78. zb_UserCreatePhone($login, '', '');
  79. rcms_redirect("?module=pl_checker&username=" . $login);
  80. }
  81. if ($field == 'realname') {
  82. zb_UserCreateRealName($login, '');
  83. rcms_redirect("?module=pl_checker&username=" . $login);
  84. }
  85. if ($field == 'userspeeds') {
  86. zb_UserCreateSpeedOverride($login, '0');
  87. rcms_redirect("?module=pl_checker&username=" . $login);
  88. }
  89. if ($field == 'nethosts') {
  90. $problemType = zb_plchecknethost($login);
  91. $userIp = zb_UserGetIP($login);
  92. if (!empty($userIp)) {
  93. $userNetwork = zb_NetworkGetByIp($userIp);
  94. $randommac = zb_MacGetRandom();
  95. if (zb_mac_unique($randommac)) {
  96. $newMacvalue = $randommac;
  97. } else {
  98. show_error('Oops');
  99. $newMacvalue = '';
  100. }
  101. if ($userNetwork != false) {
  102. switch ($problemType) {
  103. case 0:
  104. multinet_add_host($userNetwork, $userIp, $newMacvalue);
  105. multinet_rebuild_all_handlers();
  106. break;
  107. case -1:
  108. $currentUserMac = zb_MultinetGetMAC($userIp);
  109. multinet_delete_host($userIp);
  110. multinet_add_host($userNetwork, $userIp, $currentUserMac);
  111. multinet_rebuild_all_handlers();
  112. break;
  113. }
  114. rcms_redirect("?module=pl_checker&username=" . $login);
  115. } else {
  116. show_error(__('No network detected'));
  117. }
  118. }
  119. }
  120. }
  121. /**
  122. * Renders module interface
  123. *
  124. * @param string $login
  125. *
  126. * @return string
  127. */
  128. function web_plchecker($login) {
  129. $login = mysql_real_escape_string($login);
  130. $result = '';
  131. $emails = zb_plcheckfield('emails', $login);
  132. $contracts = zb_plcheckfield('contracts', $login);
  133. $phones = zb_plcheckfield('phones', $login);
  134. $realname = zb_plcheckfield('realname', $login);
  135. $userspeeds = zb_plcheckfield('userspeeds', $login);
  136. $nethosts = zb_plchecknethost($login);
  137. $cells = wf_TableCell(__('Status'));
  138. $cells .= wf_TableCell(__('Parameter'));
  139. $cells .= wf_TableCell(__('Actions'));
  140. $rows = wf_TableRow($cells, 'row1');
  141. $cells = wf_TableCell(web_bool_led($emails));
  142. $cells .= wf_TableCell(__('Email'));
  143. $cells .= wf_TableCell(web_plfixerform($login, 'emails', $emails));
  144. $rows .= wf_TableRow($cells, 'row3');
  145. $cells = wf_TableCell(web_bool_led($contracts));
  146. $cells .= wf_TableCell(__('Contract'));
  147. $cells .= wf_TableCell(web_plfixerform($login, 'contracts', $contracts));
  148. $rows .= wf_TableRow($cells, 'row3');
  149. $cells = wf_TableCell(web_bool_led($phones));
  150. $cells .= wf_TableCell(__('Phone') . '/' . __('Mobile'));
  151. $cells .= wf_TableCell(web_plfixerform($login, 'phones', $phones));
  152. $rows .= wf_TableRow($cells, 'row3');
  153. $cells = wf_TableCell(web_bool_led($realname));
  154. $cells .= wf_TableCell(__('Real Name'));
  155. $cells .= wf_TableCell(web_plfixerform($login, 'realname', $realname));
  156. $rows .= wf_TableRow($cells, 'row3');
  157. $cells = wf_TableCell(web_bool_led($userspeeds));
  158. $cells .= wf_TableCell(__('Speed override'));
  159. $cells .= wf_TableCell(web_plfixerform($login, 'userspeeds', $userspeeds));
  160. $rows .= wf_TableRow($cells, 'row3');
  161. switch ($nethosts) {
  162. case 0:
  163. $nhProblemType = web_bool_led(0) . __('Not exists');
  164. break;
  165. case -1:
  166. $nhProblemType = web_bool_led(0) . __('Duplicate');
  167. break;
  168. case 1:
  169. $nhProblemType = web_bool_led(1);
  170. break;
  171. }
  172. $cells = wf_TableCell($nhProblemType);
  173. $cells .= wf_TableCell(__('Network'));
  174. $cells .= wf_TableCell(web_plfixerform($login, 'nethosts', $nethosts));
  175. $rows .= wf_TableRow($cells, 'row3');
  176. $result .= wf_TableBody($rows, '100%', 0);
  177. $result .= web_UserControls($login);
  178. return($result);
  179. }
  180. if (isset($_GET['username'])) {
  181. $login = $_GET['username'];
  182. if (isset($_POST['fixme'])) {
  183. zb_plfixer($login, $_POST['fixme']);
  184. }
  185. show_window(__('User integrity checker'), web_plchecker($login));
  186. }
  187. } else {
  188. show_error(__('You cant control this module'));
  189. }
  190. ?>