index.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <?php
  2. $default_displayed = 500;
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  4. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
  5. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  6. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/oufilter.php");
  7. $default_sort='login';
  8. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/sortfilter.php");
  9. $msg_error = "";
  10. if (getPOST("create") !== null) {
  11. $login = trim(getPOST("newlogin", null, ''));
  12. if ($login !== '') {
  13. // Проверка существования логина
  14. $lcount = get_count_records($db_link, "user_list", "LOWER(login) = LOWER(?)", [$login]);
  15. if ($lcount > 0) {
  16. $msg_error = WEB_cell_login . " " . $login . " " . $msg_exists . "!";
  17. } else {
  18. $new = ['login' => $login];
  19. // Определение OU
  20. if ($rou > 0) {
  21. $new['ou_id'] = $rou;
  22. } else {
  23. $rou = 3;
  24. $ou_exists = get_record_sql($db_link, "SELECT id FROM ou WHERE id = ?", [$rou]);
  25. if (empty($ou_exists)) {
  26. $new['ou_id'] = $default_user_ou_id; // по умолчанию
  27. } else {
  28. $new['ou_id'] = $rou;
  29. }
  30. }
  31. // Наследование настроек от OU
  32. $ou_info = get_record_sql($db_link, "SELECT * FROM ou WHERE id = ?", [$new['ou_id']]);
  33. if (!empty($ou_info)) {
  34. $new['enabled'] = isset($ou_info['enabled']) ? (int)$ou_info['enabled'] : 0;
  35. $new['queue_id'] = isset($ou_info['queue_id']) ? (int)$ou_info['queue_id'] : 0;
  36. $new['filter_group_id'] = isset($ou_info['filter_group_id']) ? (int)$ou_info['filter_group_id'] : 0;
  37. } else {
  38. // Если OU не найден — значения по умолчанию
  39. $new['enabled'] = 0;
  40. $new['queue_id'] = 0;
  41. $new['filter_group_id'] = 0;
  42. }
  43. $lid = insert_record($db_link, "user_list", $new);
  44. if (!empty($lid)) {
  45. header("Location: edituser.php?id=$lid");
  46. exit;
  47. }
  48. }
  49. }
  50. header("Location: " . $_SERVER["REQUEST_URI"]);
  51. exit;
  52. }
  53. ?>
  54. <div id="cont">
  55. <?php
  56. if ($msg_error) {
  57. print "<div id='msg'><b>$msg_error</b></div><br>\n";
  58. }
  59. ?>
  60. <script>
  61. function blockForm(formId) {
  62. const form = document.getElementById(formId);
  63. if (!form) return;
  64. // Меняем текст кнопки отправки
  65. const submitBtn = form.querySelector('input[type="submit"], button[type="submit"]');
  66. if (submitBtn) {
  67. submitBtn.disabled = true;
  68. submitBtn.value = '<?php print WEB_msg_processing; ?>';
  69. submitBtn.textContent = '<?php print WEB_msg_processing; ?>';
  70. }
  71. }
  72. </script>
  73. <form id="filter" name="filter" action="index.php" method="post">
  74. <div>
  75. <b><?php print WEB_cell_ou; ?> - </b>
  76. <?php print_ou_select($db_link, 'ou', $rou); print WEB_rows_at_page."&nbsp"; print_row_at_pages('rows',$displayed); ?>
  77. <input id="btn_filter" name="btn_filter" type="submit" value="<?php echo WEB_btn_show; ?>">
  78. </div>
  79. <br>
  80. <div>
  81. <?php echo WEB_new_user."&nbsp"; ?>
  82. <input type=text name=newlogin value="Unknown">
  83. <input type="submit" name="create" value="<?php echo WEB_btn_add; ?>">
  84. </div>
  85. </form>
  86. <br>
  87. <a class="mainButton" href="#modal"><?php print WEB_btn_apply_selected; ?></a>
  88. <div class="remodal" data-remodal-options="closeOnConfirm: true" data-remodal-id="modal" role="dialog" aria-labelledby="modal1Title" aria-describedby="modal1Desc">
  89. <div class="remodalBorder">
  90. <button data-remodal-action="close" class="remodal-close" aria-label="Close"></button>
  91. <form id="formUserApply" onsubmit="blockForm('formUserApply');">
  92. <h2 id="modal1Title"><?php print WEB_selection_title; ?></h2>
  93. <input type="hidden" name="ApplyForAll" value="MassChange">
  94. <table class="data" align=center>
  95. <tr><td><input type=checkbox class="putField" name="e_enabled" value='1'></td><td align=left><?php print WEB_cell_enabled."</td><td align=right>";print_qa_select('a_enabled', 0); ?></td></tr>
  96. <tr><td><input type=checkbox class="putField" name="e_group_id" value='1'></td><td align=left><?php print WEB_cell_filter."</td><td align=right>";print_filter_group_select($db_link, 'a_group_id', 0); ?></td></tr>
  97. <tr><td><input type=checkbox class="putField" name="e_queue_id" value='1'></td><td align=left><?php print WEB_cell_shaper."</td><td align=right>";print_queue_select($db_link, 'a_queue_id', 0); ?></td></tr>
  98. <tr><td><input type=checkbox class="putField" name="e_day_q" value='1'></td><td align=left><?php print WEB_cell_perday."</td><td align=right>"; ?><input type="text" name="a_day_q" value="0" size=5></td></tr>
  99. <tr><td><input type=checkbox class="putField" name="e_month_q" value='1'></td><td align=left><?php print WEB_cell_permonth."</td><td align=right>"; ?><input type="text" name="a_month_q" value="0" size=5></td></tr>
  100. <tr><td><input type=checkbox class="putField" name="e_new_ou" value='1'></td><td align=left><?php print WEB_cell_ou."</td><td align=right>";print_ou_set($db_link, 'a_new_ou', 0); ?></td></tr>
  101. <tr><td><input type=checkbox class="putField" name="e_bind_mac" value='1'></td><td align=left><?php print WEB_user_bind_mac."</td><td align=right>";print_qa_select('a_bind_mac', 1);?></td></tr>
  102. <tr><td><input type=checkbox class="putField" name="e_bind_ip" value='1'></td><td align=left><?php print WEB_user_bind_ip."</td><td align=right>";print_qa_select('a_bind_ip', 1);?></td></tr>
  103. <tr><td><input type=checkbox class="putField" name="e_create_netdev" value='1'></td><td align=left><?php print WEB_user_create_netdev."</td><td align=right>";print_qa_select('a_create_netdev', 1);?></td></tr>
  104. <tr><td><input type=checkbox class="putField" name="e_permanent" value='1'></td><td align=left><?php print WEB_user_permanent."</td><td align=right>";print_qa_select('a_permanent', 0);?></td></tr>
  105. </table>
  106. <input type="submit" name="submit" class="btn" value="<?php echo WEB_btn_apply; ?>">
  107. </form>
  108. </div>
  109. </div>
  110. <a class="delButton" href="#modalDel"><?php print WEB_btn_delete; ?></a>
  111. <div class="remodal" data-remodal-options="closeOnConfirm: true" data-remodal-id="modalDel" role="dialog" aria-labelledby="modal1Title" aria-describedby="modal1Desc">
  112. <div class="remodalBorder">
  113. <button data-remodal-action="close" class="remodal-close" aria-label="Close"></button>
  114. <form id="formUserDel" onsubmit="blockForm('formUserDel');">
  115. <h2 id="modal1Title"><?php print WEB_msg_delete_selected; ?></h2>
  116. <input type="hidden" name="RemoveUser" value="MassChange">
  117. <?php print_qa_select('f_deleted', 0);?><br><br>
  118. <input type="submit" name="submit" class="btn" value="<?php echo WEB_btn_apply; ?>">
  119. </form>
  120. </div>
  121. </div>
  122. <?php
  123. $sort_url = "<a href=/admin/users/index.php?";
  124. // === 1. Базовые условия ===
  125. $params = [];
  126. $conditions = ["U.deleted = 0", "U.ou_id = O.id"];
  127. if ($rou != 0) {
  128. $conditions[] = "U.ou_id = ?";
  129. $params[] = (int)$rou;
  130. }
  131. $whereClause = implode(' AND ', $conditions);
  132. // === 2. Безопасная сортировка (БЕЛЫЙ СПИСОК!) ===
  133. $allowed_sort_fields = ['id', 'login', 'description', 'ou_name', 'enabled', 'day_quota', 'month_quota', 'blocked', 'permanent'];
  134. $allowed_order = ['ASC', 'DESC'];
  135. $sort_field = in_array($sort_field, $allowed_sort_fields, true) ? $sort_field : 'id';
  136. $order = in_array(strtoupper($order), $allowed_order, true) ? strtoupper($order) : 'ASC';
  137. // === 3. Подсчёт записей ===
  138. $countSQL = "SELECT COUNT(*) FROM user_list U JOIN ou O ON U.ou_id = O.id WHERE $whereClause";
  139. $count_records = (int)get_single_field($db_link, $countSQL, $params);
  140. // === 4. Пагинация ===
  141. $total = ceil($count_records / $displayed);
  142. $page = max(1, min($page, $total));
  143. $start = ($page - 1) * $displayed;
  144. print_navigation($page_url, $page, $displayed, $count_records, $total);
  145. // === 5. Запрос данных ===
  146. $limit = (int)$displayed;
  147. $offset = (int)$start;
  148. $dataParams = array_merge($params, [$limit, $offset]);
  149. $sSQL = "
  150. SELECT
  151. U.id, U.login, U.description, O.ou_name, U.enabled,
  152. U.day_quota, U.month_quota, U.blocked, U.permanent
  153. FROM user_list U
  154. JOIN ou O ON U.ou_id = O.id
  155. WHERE $whereClause
  156. ORDER BY U.$sort_field $order
  157. LIMIT ? OFFSET ?
  158. ";
  159. $users = get_records_sql($db_link, $sSQL, $dataParams);
  160. ?>
  161. <form id="def" name="def" >
  162. <table class="data">
  163. <tr align="center">
  164. <td><input type="checkbox" onClick="checkAll(this.checked);"></td>
  165. <td><b><?php print $sort_url . "sort=id&order=$new_order>id</a>"; ?></b></td>
  166. <td><b><?php print $sort_url . "sort=login&order=$new_order>" . WEB_cell_login . "</a>"; ?></b></td>
  167. <td><b><?php print $sort_url . "sort=description&order=$new_order>" . WEB_cell_description . "</a>"; ?></b></td>
  168. <td><b><?php print WEB_cell_rule; ?></b></td>
  169. <td><b><?php print WEB_cell_ou; ?></b></td>
  170. <td><b><?php print WEB_cell_enabled; ?></b></td>
  171. <td><b><?php print WEB_cell_perday; ?></b></td>
  172. <td><b><?php print WEB_cell_permonth; ?></b></td>
  173. <td><b><?php print WEB_cell_report; ?></b></td>
  174. </tr>
  175. <?php
  176. foreach ($users as $row) {
  177. $auth_customs = get_count_records($db_link,"user_auth","user_id=? AND deleted=0 AND enabled <>?", [ $row['id'],$row['enabled'] ] );
  178. $cl = "data";
  179. if (! $row['enabled']) {
  180. $cl = "off";
  181. }
  182. if ($row['blocked']) {
  183. $cl = "error";
  184. }
  185. if ($auth_customs > 0) {
  186. $cl = "custom";
  187. }
  188. if (! get_auth_count($db_link, $row['id'])) {
  189. $cl = 'nb';
  190. }
  191. print "<tr align=center>\n";
  192. print "<td class=\"$cl\" style='padding:0'><input type=checkbox name=fid[] value=".$row['id']."></td>\n";
  193. $cl_id = $cl;
  194. if (!empty($row['permanent']) and $row['permanent'] == 1) { $cl_id = 'warn'; }
  195. print "<td class=\"$cl_id\">".$row['id']."</td>\n";
  196. if (empty($row['login'])) { $row['login']=$row['id']; }
  197. print "<td class=\"$cl\" align=left><a href=edituser.php?id=".$row['id'].">" . $row['login'] . "</a></td>\n";
  198. print "<td class=\"$cl\">".$row['description']."</td>\n";
  199. $rules_count = get_count_records($db_link,"auth_rules","user_id=?", [$row['id']]);
  200. print "<td class=\"$cl\">".$rules_count."</td>\n";
  201. print "<td class=\"$cl\">".$row['ou_name']."</td>\n";
  202. print "<td class=\"$cl\">".get_qa($row['enabled']) . "</td>\n";
  203. print "<td class=\"$cl\">".$row['day_quota']."</td>\n";
  204. print "<td class=\"$cl\">".$row['month_quota']."</td>\n";
  205. print "<td class=\"$cl\" align=center colspan=2><a href=../reports/userday.php?id=".$row['id'].">Просмотр</a></td>\n";
  206. }
  207. ?>
  208. </table>
  209. <?php
  210. print_navigation($page_url,$page,$displayed,$count_records,$total);
  211. ?>
  212. </form>
  213. <table class="data">
  214. <tr>
  215. <td colspan = 3><?php echo WEB_color_description; ?></td>
  216. </tr>
  217. <tr>
  218. <td class="nb"><?php echo WEB_color_user_empty; ?></td>
  219. <td class="off"><?php echo WEB_color_user_disabled; ?></td>
  220. <td class="error"><?php echo WEB_color_user_blocked; ?></td>
  221. <td class="custom"><?php echo WEB_color_user_custom; ?></td>
  222. <td class="warn"><?php echo WEB_color_user_permanent; ?></td>
  223. </table>
  224. <script src="/js/remodal/remodal.min.js"></script>
  225. <script src="/js/remodal-user.js"></script>
  226. <script>
  227. document.getElementById('ou').addEventListener('change', function(event) {
  228. const buttonApply = document.getElementById('btn_filter');
  229. buttonApply.click();
  230. });
  231. document.getElementById('rows').addEventListener('change', function(event) {
  232. const buttonApply = document.getElementById('btn_filter');
  233. buttonApply.click();
  234. });
  235. </script>
  236. <?php
  237. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  238. ?>