1
0

index.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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 (isset($_POST['search_str'])) { $f_search_str = trim($_POST['search_str']); }
  57. if (!isset($f_search_str) and isset($_SESSION[$page_url]['search_str'])) { $f_search_str=$_SESSION[$page_url]['search_str']; }
  58. if (!isset($f_search_str)) { $f_search_str=''; }
  59. $_SESSION[$page_url]['search_str']=$f_search_str;
  60. $f_search=replaceSpecialChars($f_search_str);
  61. if ($msg_error) {
  62. print "<div id='msg'><b>$msg_error</b></div><br>\n";
  63. }
  64. ?>
  65. <script>
  66. function blockForm(formId) {
  67. const form = document.getElementById(formId);
  68. if (!form) return;
  69. // Меняем текст кнопки отправки
  70. const submitBtn = form.querySelector('input[type="submit"], button[type="submit"]');
  71. if (submitBtn) {
  72. submitBtn.disabled = true;
  73. submitBtn.value = '<?php print WEB_msg_processing; ?>';
  74. submitBtn.textContent = '<?php print WEB_msg_processing; ?>';
  75. }
  76. }
  77. </script>
  78. <form id="filter" name="filter" action="index.php" method="post">
  79. <fieldset style="display: flex; align-items: center; gap: 10px; padding: 10px;">
  80. <legend><b><?php echo WEB_cell_ou; ?> —</b></legend>
  81. <?php print_ou_select($db_link, 'ou', $rou); ?>
  82. <span><?php echo WEB_rows_at_page; ?></span>
  83. <?php print_row_at_pages('rows', $displayed); ?>
  84. <label for="search_str" style="margin: 0;"><?php echo WEB_ips_search; ?>:</label>
  85. <input type="text" id="search_str" name="search_str" value="<?php echo $f_search_str; ?>" style="margin: 0;">
  86. <input id="btn_filter" name="btn_filter" type="submit" value="<?php echo WEB_btn_show; ?>" style="margin: 0;">
  87. </fieldset>
  88. <fieldset>
  89. <legend><?php echo WEB_new_user; ?></legend>
  90. <div>
  91. <input type="text" id="newlogin" name="newlogin" value="Unknown">
  92. <input type="submit" name="create" value="<?php echo WEB_btn_add; ?>">
  93. </div>
  94. </fieldset>
  95. </form>
  96. <br>
  97. <a class="mainButton" href="#modal"><?php print WEB_btn_apply_selected; ?></a>
  98. <div class="remodal" data-remodal-options="closeOnConfirm: true" data-remodal-id="modal" role="dialog" aria-labelledby="modal1Title" aria-describedby="modal1Desc">
  99. <div class="remodalBorder">
  100. <button data-remodal-action="close" class="remodal-close" aria-label="Close"></button>
  101. <form id="formUserApply" onsubmit="blockForm('formUserApply');">
  102. <h2 id="modal1Title"><?php print WEB_selection_title; ?></h2>
  103. <input type="hidden" name="ApplyForAll" value="MassChange">
  104. <table class="data" align=center>
  105. <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>
  106. <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>
  107. <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>
  108. <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>
  109. <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>
  110. <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>
  111. <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>
  112. <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>
  113. <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>
  114. <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>
  115. </table>
  116. <input type="submit" name="submit" class="btn" value="<?php echo WEB_btn_apply; ?>">
  117. </form>
  118. </div>
  119. </div>
  120. <a class="delButton" href="#modalDel"><?php print WEB_btn_delete; ?></a>
  121. <div class="remodal" data-remodal-options="closeOnConfirm: true" data-remodal-id="modalDel" role="dialog" aria-labelledby="modal1Title" aria-describedby="modal1Desc">
  122. <div class="remodalBorder">
  123. <button data-remodal-action="close" class="remodal-close" aria-label="Close"></button>
  124. <form id="formUserDel" onsubmit="blockForm('formUserDel');">
  125. <h2 id="modal1Title"><?php print WEB_msg_delete_selected; ?></h2>
  126. <input type="hidden" name="RemoveUser" value="MassChange">
  127. <?php print_qa_select('f_deleted', 0);?><br><br>
  128. <input type="submit" name="submit" class="btn" value="<?php echo WEB_btn_apply; ?>">
  129. </form>
  130. </div>
  131. </div>
  132. <?php
  133. $sort_url = "<a href=/admin/users/index.php?";
  134. $params = [];
  135. $conditions = ["deleted = 0"];
  136. if ($rou != 0) {
  137. $conditions[] = "ou_id = ?";
  138. $params[] = (int)$rou;
  139. }
  140. if (isset($f_search_str) && strlen($f_search_str) > 0) {
  141. $search_pattern = '%' . $f_search . '%';
  142. $conditions[] = "(login LIKE ? OR description LIKE ?)";
  143. $params[] = $search_pattern;
  144. $params[] = $search_pattern;
  145. }
  146. // Защита от пустого WHERE
  147. if (!empty($conditions)) {
  148. $whereClause = ' WHERE ' . implode(' AND ', $conditions);
  149. } else {
  150. $whereClause = '';
  151. }
  152. // === 2. Безопасная сортировка (БЕЛЫЙ СПИСОК!) ===
  153. $allowed_sort_fields = ['id', 'login', 'description' ];
  154. $allowed_order = ['ASC', 'DESC'];
  155. $sort_field = in_array($sort_field, $allowed_sort_fields, true) ? $sort_field : 'id';
  156. $order = in_array(strtoupper($order), $allowed_order, true) ? strtoupper($order) : 'ASC';
  157. // === 3. Подсчёт записей ===
  158. $countSQL = "SELECT COUNT(*) FROM user_list $whereClause";
  159. $count_records = (int)get_single_field($db_link, $countSQL, $params);
  160. // === 4. Пагинация ===
  161. $total = ceil($count_records / $displayed);
  162. $page = max(1, min($page, $total));
  163. $start = ($page - 1) * $displayed;
  164. print_navigation($page_url, $page, $displayed, $count_records, $total);
  165. // === 5. Запрос данных ===
  166. $limit = (int)$displayed;
  167. $offset = (int)$start;
  168. $dataParams = array_merge($params, [$limit, $offset]);
  169. $sSQL = "
  170. SELECT *
  171. FROM user_list U
  172. $whereClause
  173. ORDER BY $sort_field $order
  174. LIMIT ? OFFSET ?
  175. ";
  176. $users = get_records_sql($db_link, $sSQL, $dataParams);
  177. ?>
  178. <form id="def" name="def" >
  179. <table class="data">
  180. <tr align="center">
  181. <td><input type="checkbox" onClick="checkAll(this.checked);"></td>
  182. <td><b><?php print $sort_url . "sort=id&order=$new_order>id</a>"; ?></b></td>
  183. <td><b><?php print $sort_url . "sort=login&order=$new_order>" . WEB_cell_login . "</a>"; ?></b></td>
  184. <td><b><?php print $sort_url . "sort=description&order=$new_order>" . WEB_cell_description . "</a>"; ?></b></td>
  185. <td><b><?php print WEB_cell_rule; ?></b></td>
  186. <td><b><?php print WEB_cell_ou; ?></b></td>
  187. <td><b><?php print WEB_cell_enabled; ?></b></td>
  188. <td><b><?php print WEB_cell_perday; ?></b></td>
  189. <td><b><?php print WEB_cell_permonth; ?></b></td>
  190. <td><b><?php print WEB_cell_report; ?></b></td>
  191. </tr>
  192. <?php
  193. foreach ($users as $row) {
  194. $auth_customs = get_count_records($db_link,"user_auth","user_id=? AND deleted=0 AND enabled <>?", [ $row['id'],$row['enabled'] ] );
  195. $cl = "data";
  196. if (! $row['enabled']) {
  197. $cl = "off";
  198. }
  199. if ($row['blocked']) {
  200. $cl = "error";
  201. }
  202. if ($auth_customs > 0) {
  203. $cl = "custom";
  204. }
  205. if (! get_auth_count($db_link, $row['id'])) {
  206. $cl = 'nb';
  207. }
  208. print "<tr align=center>\n";
  209. print "<td class=\"$cl\" style='padding:0'><input type=checkbox name=fid[] value=".$row['id']."></td>\n";
  210. $cl_id = $cl;
  211. if (!empty($row['permanent']) and $row['permanent'] == 1) { $cl_id = 'warn'; }
  212. print "<td class=\"$cl_id\">".$row['id']."</td>\n";
  213. if (empty($row['login'])) { $row['login']=$row['id']; }
  214. print "<td class=\"$cl\" align=left><a href=edituser.php?id=".$row['id'].">" . $row['login'] . "</a></td>\n";
  215. print "<td class=\"$cl\">".$row['description']."</td>\n";
  216. $rules_count = get_count_records($db_link,"auth_rules","user_id=?", [$row['id']]);
  217. print "<td class=\"$cl\">".$rules_count."</td>\n";
  218. print "<td class=\"$cl\">".get_ou($db_link,$row['ou_id'])."</td>\n";
  219. print "<td class=\"$cl\">".get_qa($row['enabled']) . "</td>\n";
  220. print "<td class=\"$cl\">".$row['day_quota']."</td>\n";
  221. print "<td class=\"$cl\">".$row['month_quota']."</td>\n";
  222. print "<td class=\"$cl\" align=center colspan=2><a href=../reports/userday.php?id=".$row['id'].">Просмотр</a></td>\n";
  223. }
  224. ?>
  225. </table>
  226. <?php
  227. print_navigation($page_url,$page,$displayed,$count_records,$total);
  228. ?>
  229. </form>
  230. <table class="data">
  231. <tr>
  232. <td colspan = 3><?php echo WEB_color_description; ?></td>
  233. </tr>
  234. <tr>
  235. <td class="nb"><?php echo WEB_color_user_empty; ?></td>
  236. <td class="off"><?php echo WEB_color_user_disabled; ?></td>
  237. <td class="error"><?php echo WEB_color_user_blocked; ?></td>
  238. <td class="custom"><?php echo WEB_color_user_custom; ?></td>
  239. <td class="warn"><?php echo WEB_color_user_permanent; ?></td>
  240. </table>
  241. <script src="/js/remodal/remodal.min.js"></script>
  242. <script src="/js/remodal-user.js"></script>
  243. <script>
  244. document.getElementById('ou').addEventListener('change', function(event) {
  245. const buttonApply = document.getElementById('btn_filter');
  246. buttonApply.click();
  247. });
  248. document.getElementById('rows').addEventListener('change', function(event) {
  249. const buttonApply = document.getElementById('btn_filter');
  250. buttonApply.click();
  251. });
  252. </script>
  253. <?php
  254. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  255. ?>