1
0

index.php 11 KB

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