edituser.php 15 KB

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