edituser.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <?php
  2. require_once ($_SERVER["DOCUMENT_ROOT"]."/inc/auth.php");
  3. require_once ($_SERVER["DOCUMENT_ROOT"]."/inc/languages/" . $language . ".php");
  4. require_once ($_SERVER["DOCUMENT_ROOT"]."/inc/idfilter.php");
  5. global $default_user_id;
  6. global $hotspot_user_id;
  7. $default_sort='ip_int';
  8. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/sortfilter.php");
  9. $msg_error = "";
  10. if (isset($_POST["edituser"])) {
  11. unset($new);
  12. unset($auth);
  13. $new["ou_id"] = $_POST["f_ou"] * 1;
  14. $new["filter_group_id"] = $_POST["f_filter"]*1;
  15. $new["queue_id"] = $_POST["f_queue"]*1;
  16. if ($default_user_id == $id or $hotspot_user_id == $id) {
  17. $new["enabled"] = 0;
  18. $new["blocked"] = 0;
  19. $new["day_quota"] = 0;
  20. $new["month_quota"] = 0;
  21. $auth["enabled"] = 0;
  22. $auth["blocked"] = 0;
  23. } else {
  24. $new["login"] = trim($_POST["f_login"]);
  25. $new["fio"] = trim($_POST["f_fio"]);
  26. $new["enabled"] = $_POST["f_enabled"] * 1;
  27. $new["blocked"] = $_POST["f_blocked"] * 1;
  28. $new["day_quota"] = trim($_POST["f_perday"]) * 1;
  29. $new["month_quota"] = trim($_POST["f_permonth"]) * 1;
  30. $auth["enabled"] = $new["enabled"];
  31. $auth["blocked"] = $new["blocked"];
  32. }
  33. $changes = get_diff_rec($db_link,"User_list","id='$id'", $new, 0);
  34. if (!empty($changes)) { LOG_WARNING($db_link,"Изменён пользователь id: $id. \r\nПрименено: $changes"); }
  35. update_record($db_link, "User_list", "id='$id'", $new);
  36. update_record($db_link, "User_auth", "user_id='" . $id . "'", $auth);
  37. header("Location: " . $_SERVER["REQUEST_URI"]);
  38. }
  39. if (isset($_POST["addauth"])) {
  40. $fip = substr(trim($_POST["newip"]), 0, 18);
  41. if (isset($_POST["newmac"])) { $fmac = mac_dotted(substr(trim($_POST["newmac"]), 0, 17)); }
  42. if ($fip) {
  43. if (checkValidIp($fip)) {
  44. $fid = new_auth($db_link, $fip, $fmac, $id);
  45. LOG_WARNING($db_link,"Создан новый адрес доступа: ip => $fip, mac => $fmac");
  46. if (isset($fid)) { header("location: /admin/users/editauth.php?id=$fid"); }
  47. header("Location: " . $_SERVER["REQUEST_URI"]);
  48. } else {
  49. $msg_error = "$msg_ip_error xxx.xxx.xxx.xxx/xx";
  50. }
  51. }
  52. header("Location: " . $_SERVER["REQUEST_URI"]);
  53. }
  54. if (isset($_POST["removeauth"])) {
  55. $auth_id = $_POST["f_auth_id"];
  56. foreach ($auth_id as $key => $val) {
  57. if ($val) {
  58. delete_record($db_link, 'connections', "auth_id=" . $val);
  59. delete_record($db_link, 'User_auth_alias', "auth_id=" . $val);
  60. $auth["deleted"] = 1;
  61. $changes = get_diff_rec($db_link,"User_auth","id='$val'", '', 0);
  62. if (!empty($changes)) { LOG_WARNING($db_link,"Удалён адрес доступа: \r\n $changes"); }
  63. update_record($db_link, "User_auth", "id=" . $val, $auth);
  64. delete_record($db_link, "connections", "auth_id=" . $val);
  65. }
  66. }
  67. header("Location: " . $_SERVER["REQUEST_URI"]);
  68. }
  69. if (isset($_POST["ApplyForAll"])) {
  70. $auth_id = $_POST["f_auth_id"];
  71. $a_enabled = $_POST["a_enabled"] * 1;
  72. $a_day = $_POST["a_day_q"] * 1;
  73. $a_month = $_POST["a_month_q"] * 1;
  74. $a_queue = $_POST["a_queue_id"] * 1;
  75. $a_group = $_POST["a_group_id"] * 1;
  76. foreach ($auth_id as $key => $val) {
  77. if ($val) {
  78. unset($new);
  79. if ($default_user_id == $id or $hotspot_user_id == $id) {
  80. $new["enabled"] = 0;
  81. $new["day_quota"] = 0;
  82. $new["month_quota"] = 0;
  83. $new["queue_id"] = 0;
  84. $new["filter_group_id"] = 0;
  85. } else {
  86. $new["enabled"] = $a_enabled;
  87. $new["day_quota"] = $a_day;
  88. $new["month_quota"] = $a_month;
  89. $new["queue_id"] = $a_queue;
  90. $new["filter_group_id"] = $a_group;
  91. }
  92. $changes = get_diff_rec($db_link,"User_auth","id='$val'", $new, 0);
  93. if (!empty($changes)) { LOG_WARNING($db_link,"Изменён адрес доступа id: $val. Применено: $changes"); }
  94. update_record($db_link, "User_auth", "id='" . $val . "'", $new);
  95. }
  96. }
  97. header("Location: " . $_SERVER["REQUEST_URI"]);
  98. }
  99. if (isset($_POST["moveauth"]) and isset($_POST["new_parent"])) {
  100. $new_user_id = $_POST["new_parent"]*1;
  101. $auth_id = $_POST["f_auth_id"];
  102. if ($new_user_id <> $id) {
  103. $user_rec = get_record($db_link, 'User_list', "id=".$new_user_id);
  104. foreach ($auth_id as $key => $val) {
  105. if ($val) {
  106. $new["filter_group_id"]=$user_rec["filter_group_id"];
  107. $new["queue_id"] = $user_rec["queue_id"];
  108. $new["enabled"] = $user_rec["enabled"];
  109. $new["user_id"] = $new_user_id;
  110. $changes = get_diff_rec($db_link,"User_auth","id='$val'", $new, 0);
  111. if (!empty($changes)) { LOG_WARNING($db_link,"Адрес доступа перемещён к другому пользователю id: $val (".$user_rec["login"]."). Применено: $changes"); }
  112. update_record($db_link, "User_auth", "id='" . $val . "'", $new);
  113. }
  114. }
  115. }
  116. header("Location: " . $_SERVER["REQUEST_URI"]);
  117. }
  118. if (isset($_POST["new_user"])) {
  119. $auth_id = $_POST["f_auth_id"];
  120. $save_traf = get_option($db_link, 23) * 1;
  121. foreach ($auth_id as $key => $val) {
  122. if ($val) {
  123. $flist = mysqli_query($db_link, "SELECT ip, comments, dns_name, dhcp_hostname from User_auth WHERE id=$val");
  124. list ($f_auth_ip, $f_auth_comments, $f_dns_name, $f_dhcp_name) = mysqli_fetch_array($flist);
  125. $ou_id = $_POST["f_new_ou"] * 1;
  126. if (!isset($ou_id)) { $ou_id = 0; }
  127. $login = $f_auth_ip;
  128. if (isset($f_auth_comments) and strlen($f_auth_comments) > 0) { $login = $f_auth_comments; }
  129. if (isset($f_dhcp_name) and strlen($f_dhcp_name) > 0) { $login = $f_dhcp_name; }
  130. if (isset($f_dns_name) and strlen($f_dns_name) > 0) { $login = $f_dns_name; }
  131. list ($l_id) = mysqli_fetch_array(mysqli_query($db_link, "Select id from User_list where LCase(login)=LCase('$login') and deleted=0"));
  132. if (isset($l_id) and $l_id > 0) {
  133. // move auth
  134. $auth["user_id"] = $l_id;
  135. $auth["save_traf"] = $save_traf;
  136. update_record($db_link, "User_auth", "id='" . $val . "'", $auth);
  137. apply_auth_rule($db_link,$val,$l_id);
  138. $changes = get_diff_rec($db_link,"User_auth","id='$val'", $new, 0);
  139. if (!empty($changes)) { LOG_WARNING($db_link,"Изменён адрес доступа id: $val. Применено: $changes"); }
  140. } else {
  141. $new["login"] = $login;
  142. $new["ou_id"] = $ou_id;
  143. $l_id=insert_record($db_link, "User_list", $new);
  144. $auth["user_id"] = $l_id;
  145. $auth["save_traf"] = $save_traf;
  146. update_record($db_link, "User_auth", "id='" . $val . "'", $auth);
  147. $changes = get_diff_rec($db_link,"User_auth","id='$val'", '', 0);
  148. LOG_WARNING($db_link,"Создан новый пользователь из адреса доступа: login => $login. Адрес доступа перемещён к созданному пользователю: $changes");
  149. }
  150. }
  151. }
  152. header("Location: " . $_SERVER["REQUEST_URI"]);
  153. }
  154. unset($_POST);
  155. $sSQL = "SELECT * FROM User_list WHERE id=$id";
  156. $user_info = get_record_sql($db_link, $sSQL);
  157. require_once ($_SERVER["DOCUMENT_ROOT"]."/inc/header.php");
  158. ?>
  159. <div id="cont">
  160. <?php
  161. if ($msg_error) {
  162. print "<div id='msg'><b>$msg_error</b></div><br>\n";
  163. }
  164. ?>
  165. <form name="def" action="edituser.php?id=<?php echo $id; ?>" method="post">
  166. <input type="hidden" name="id" value=<? echo $id; ?>>
  167. <table class="data">
  168. <tr>
  169. <td colspan=2><?php print $cell_login; ?></td>
  170. <td colspan=2><?php print $cell_fio; ?></td>
  171. <td colspan=2><?php print $cell_ou; ?></td>
  172. </tr>
  173. <tr>
  174. <td colspan=2><input type="text" name="f_login" value="<?php print $user_info["login"]; ?>" size=25></td>
  175. <td colspan=2><input type="text" name="f_fio" value="<?php print $user_info["fio"]; ?>" size=25></td>
  176. <td colspan=2><?php print_ou_select($db_link, 'f_ou', $user_info["ou_id"]); ?></td>
  177. </tr>
  178. <tr>
  179. <td>Фильтр</td>
  180. <td>Шейпер</td>
  181. <td><?php print $cell_enabled; ?></td>
  182. <td><?php print $cell_perday; ?></td>
  183. <td><?php print $cell_permonth; ?></td>
  184. <td><?php print $cell_blocked; ?></td>
  185. </tr>
  186. <tr>
  187. <td><?php print_group_select($db_link, 'f_filter', $user_info["filter_group_id"]); ?></td>
  188. <td><?php print_queue_select($db_link, 'f_queue', $user_info["queue_id"]); ?></td>
  189. <td><?php print_qa_select('f_enabled', $user_info["enabled"]); ?></td>
  190. <td><input type="text" name="f_perday" value="<? echo $user_info["day_quota"]; ?>" size=5></td>
  191. <td><input type="text" name="f_permonth" value="<? echo $user_info["month_quota"]; ?>" size=5></td>
  192. <td><?php print_qa_select('f_blocked', $user_info["blocked"]); ?></td>
  193. </tr>
  194. <tr>
  195. <?php
  196. print "<td>"; print_url("Список правил","/admin/users/edit_rules.php?id=$id"); print "</td>";
  197. $rule_count = get_count_records($db_link,"auth_rules","user_id=".$id);
  198. if ($rule_count>0) { print "<td colspan=3> Count: ".$rule_count."</td>"; } else { print "<td colspan=3></td>"; }
  199. ?>
  200. <td colspan=2>Created: <?php print $user_info["timestamp"]; ?></td><td></td>
  201. </tr>
  202. <tr>
  203. <?php
  204. print "<td colspan=2>"; print_url("Трафик за день","/admin/reports/userday.php?id=$id"); print "</td>";
  205. ?>
  206. <td colspan=3></td>
  207. <td><input type="submit" name="edituser" value=<?php print $btn_save; ?>></td>
  208. </tr>
  209. </table>
  210. <br>
  211. <?php
  212. if ($msg_error) { print "<div id='msg'><b>$msg_error</b></div><br>\n"; }
  213. ?>
  214. <table class="data">
  215. <tr>
  216. <td>Для выделенных установить: Включен&nbsp<?php print_qa_select('a_enabled', 0); ?></td>
  217. <td>Фильтр&nbsp<?php print_group_select($db_link, 'a_group_id', 0); ?></td>
  218. <td>Шейпер&nbsp<?php print_queue_select($db_link, 'a_queue_id', 0); ?></td>
  219. <td>В день&nbsp<input type="text" name="a_day_q" value="0" size=5></td>
  220. <td>В месяц&nbsp<input type="text" name="a_month_q" value="0" size=5></td>
  221. <td>&nbsp<input type="submit" name="ApplyForAll" value="Apply"></td>
  222. </tr>
  223. <tr>
  224. <?php
  225. print "<td colspan=6>Переместить выделенных к пользователю "; print_login_select($db_link, 'new_parent', $id); print "<input type=\"submit\" name=\"moveauth\" value=".$btn_move.">"; print "</td>";
  226. print "</tr><tr>";
  227. print "<td colspan=4>Создать пользователей по выделению в группе "; print_ou_select($db_link, 'f_new_ou', $user_info["ou_id"]); print "<button name='new_user'>Создать</button>\n"; print "</td>";
  228. print "<td colspan=2 align=\"right\">Удалить выделенных <input type=\"submit\" name=\"removeauth\" value=".$btn_remove.">";
  229. ?>
  230. </tr>
  231. </table>
  232. <?php
  233. $sort_table = 'User_auth';
  234. $sort_url = "<a href=edituser.php?id=" . $id;
  235. if ($id == $default_user_id or $id == $hotspot_user_id) { $default_sort = 'last_found DESC'; }
  236. ?>
  237. <br> <b>Список адресов доступа</b><br>
  238. <table class="data">
  239. <tr>
  240. <td class="data">Новый адрес доступа IP:&nbsp<input type=text name=newip value=""></td>
  241. <td class="data">Mac (необязательно):&nbsp<input type=text name=newmac value=""></td>
  242. <td class="data"><input type="submit" name="addauth" value="Добавить"></td>
  243. </tr>
  244. </table>
  245. <table class="data">
  246. <tr>
  247. <td class="data"><input type="checkbox" onClick="checkAll(this.checked);"></td>
  248. <td class="data"><?php print $sort_url . "&sort=ip_int&order=$new_order>" . $cell_ip . "</a>"; ?></td>
  249. <td class="data"><?php print $sort_url . "&sort=mac&order=$new_order>" . $cell_mac . "</a>"; ?></td>
  250. <td class="data"><?php print $cell_comment; ?></td>
  251. <td class="data"><?php print $sort_url . "&sort=dns_name&order=$new_order>" . $cell_dns_name . "</a>"; ?></td>
  252. <td class="data"><?php print $cell_enabled; ?></td>
  253. <td class="data"><?php print $cell_filter; ?></td>
  254. <td class="data"><?php print $cell_shaper; ?></td>
  255. <td class="data"><?php print $cell_perday."/<br>".$cell_permonth.", Mb"; ?></td>
  256. <td class="data"><?php print $cell_connection; ?></td>
  257. <td class="data"><?php print $sort_url . "&sort=timestamp&order=$new_order>Created</a>"; ?></td>
  258. <td class="data">Last DHCP/ARP Event</td>
  259. <td class="data"><?php print $sort_url . "&sort=last_found&order=$new_order>Last found</a>"; ?></td>
  260. </tr>
  261. <?php
  262. $flist=get_records($db_link,'User_auth',"user_id=".$id." and deleted=0 ORDER BY $sort_table.$sort_field $order");
  263. if (!empty($flist)) {
  264. foreach ( $flist as $row ) {
  265. if ($row["dhcp_time"] == '0000-00-00 00:00:00') {
  266. $dhcp_str = '';
  267. } else {
  268. $dhcp_str = FormatDateStr('Y.m.d H:m',$row["dhcp_time"]) . " (" . $row["dhcp_action"] . ")";
  269. }
  270. if ($row["last_found"] == '0000-00-00 00:00:00') { $row["last_found"] = ''; }
  271. print "<tr align=center>\n";
  272. print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_auth_id[] value=".$row["id"]." ></td>\n";
  273. print "<td class=\"data\" align=left><a href=editauth.php?id=".$row["id"].">" . $row["ip"] . "</a></td>\n";
  274. print "<td class=\"data\" >" . expand_mac($db_link,$row["mac"]) . "</td>\n";
  275. if (isset($row["dhcp_hostname"]) and strlen($row["dhcp_hostname"]) > 0) {
  276. print "<td class=\"data\" >".$row["comments"]." [" . $row["dhcp_hostname"] . "]</td>\n";
  277. } else {
  278. print "<td class=\"data\" >".$row["comments"]."</td>\n";
  279. }
  280. print "<td class=\"data\" >".$row["dns_name"]."</td>\n";
  281. $ip_status = 1;
  282. if ($row["blocked"] or !$row["enabled"]) { $ip_status = 0; }
  283. print "<td class=\"data\" >" . get_qa($ip_status). "</td>\n";
  284. print "<td class=\"data\" >" . get_group($db_link, $row["filter_group_id"]) . "</td>\n";
  285. print "<td class=\"data\" >" . get_queue($db_link, $row["queue_id"]) . "</td>\n";
  286. print "<td class=\"data\" >".$row["day_quota"]."/".$row["month_quota"]."</td>\n";
  287. print "<td class=\"data\" >" . get_connection($db_link, $row["id"]) . "</td>\n";
  288. print "<td class=\"data\" >" . FormatDateStr('Y.m.d',$row["timestamp"]) . "</td>\n";
  289. print "<td class=\"data\" >" . $dhcp_str . "</td>\n";
  290. print "<td class=\"data\" >" . FormatDateStr('Y.m.d H:i',$row["last_found"]) . "</td>\n";
  291. print "</tr>";
  292. }
  293. }
  294. ?>
  295. </table>
  296. </form>
  297. <?
  298. require_once ($_SERVER["DOCUMENT_ROOT"]."/inc/footer.php");
  299. ?>