index.php 11 KB

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