editauth.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. <?php
  2. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/auth.php");
  3. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/languages/" . HTML_LANG . ".php");
  4. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/idfilter.php");
  5. $msg_error = "";
  6. $old_auth_info = get_record_sql($db_link, "SELECT * FROM user_auth WHERE id = ?", [$id]);
  7. if (empty($old_auth_info)) {
  8. header("Location: /admin/");
  9. exit;
  10. }
  11. $parent_id = $old_auth_info['user_id'];
  12. $user_info = get_record_sql($db_link, "SELECT * FROM user_list WHERE id = ?", [$parent_id]);
  13. $parent_ou_id = $user_info['ou_id'];
  14. $user_enabled = $user_info['enabled'];
  15. // === РЕДАКТИРОВАНИЕ ЗАПИСИ АВТОРИЗАЦИИ ==========================================
  16. if (getPOST("editauth") !== null && !$old_auth_info['deleted']) {
  17. $ip = normalizeIpAddress(substr(trim(getPOST("f_ip", null, '')), 0, 18));
  18. if (!empty($ip)) {
  19. $ip_aton = ip2long($ip);
  20. $mac = mac_dotted(getPOST("f_mac", null, ''));
  21. // Проверка MAC
  22. $mac_exists = find_mac_in_subnet($db_link, $ip, $mac);
  23. if (!empty($mac_exists) && ($mac_exists['count'] ?? 0) >= 1 && !in_array($parent_id, $mac_exists['users_id'] ?? [])) {
  24. $dup_info = get_record_sql($db_link, "SELECT * FROM user_list WHERE id = ?", [$mac_exists['users_id'][0] ?? 0]);
  25. $msg_error = "Mac already exists at another user in this subnet! Skip creating $ip [$mac].<br>Old user id: " . ($dup_info['id'] ?? '') . " login: " . ($dup_info['login'] ?? '');
  26. $_SESSION[$page_url]['msg'] = $msg_error;
  27. LOG_ERROR($db_link, $msg_error);
  28. header("Location: " . $_SERVER["REQUEST_URI"]);
  29. exit;
  30. }
  31. // DHCP для вторичного IP
  32. $f_dhcp = (int)getPOST("f_dhcp", null, 0);
  33. if (!empty($mac_exists) && in_array($parent_id, $mac_exists['users_id'] ?? [])) {
  34. if ($parent_id != ($mac_exists['users_id'][0] ?? null)) {
  35. $f_dhcp = 0;
  36. }
  37. }
  38. // Проверка дубликата IP
  39. $dup_ip_record = get_record_sql($db_link, "SELECT * FROM user_auth WHERE ip_int = ? AND id <> ? AND deleted = 0", [$ip_aton, $id]);
  40. if (!empty($dup_ip_record)) {
  41. $dup_info = get_record_sql($db_link, "SELECT * FROM user_list WHERE id = ?", [$dup_ip_record['user_id']]);
  42. $msg_error = "$ip already exists. Skip creating $ip [$mac].<br>Old user id: " . $dup_info['id'] . " login: " . $dup_info['login'];
  43. $_SESSION[$page_url]['msg'] = $msg_error;
  44. LOG_ERROR($db_link, $msg_error);
  45. header("Location: " . $_SERVER["REQUEST_URI"]);
  46. exit;
  47. }
  48. $new = [
  49. 'ip' => $ip,
  50. 'ou_id' => $parent_ou_id,
  51. 'ip_int' => $ip_aton,
  52. 'mac' => $mac,
  53. 'description' => trim(getPOST("f_description", null, '')),
  54. 'wikiname' => trim(getPOST("f_wiki", null, ''))
  55. ];
  56. $f_dnsname = trim(getPOST("f_dns_name", null, ''));
  57. $f_dns_ptr_present = (getPOST("f_dns_ptr", null, null) !== null);
  58. if (empty($f_dnsname)) {
  59. $new['dns_ptr_only'] = 0;
  60. $new['dns_name'] = '';
  61. } else {
  62. $new['dns_ptr_only'] = $f_dns_ptr_present ? 1 : 0;
  63. }
  64. // Обновление IP в devices
  65. $device = get_record_sql($db_link, "SELECT * FROM devices WHERE ip_int = ?", [$old_auth_info['ip_int']]);
  66. if (!empty($device)) {
  67. update_record($db_link, "devices", "id = ?", [
  68. 'ip' => $ip,
  69. 'ip_int' => $ip_aton
  70. ], [$device['id']]);
  71. }
  72. // Обработка DNS-имени и алиасов
  73. $dns_alias_count = get_count_records($db_link, 'user_auth_alias', 'auth_id = ?', [$id]);
  74. if (!empty($f_dnsname) && !$new['dns_ptr_only']) {
  75. $domain_zone = ltrim(get_option($db_link, 33), '.');
  76. $escaped_zone = preg_quote($domain_zone, '/');
  77. $f_dnsname = preg_replace('/\.' . $escaped_zone . '$/i', '', $f_dnsname);
  78. $f_dnsname = preg_replace('/\s+/', '-', $f_dnsname);
  79. if ($dns_alias_count > 0 && $f_dnsname !== $old_auth_info['dns_name']) {
  80. $f_dnsname = $old_auth_info['dns_name'];
  81. } else {
  82. $valid_dns = checkValidHostname($f_dnsname);
  83. $uniq_dns = checkUniqHostname($db_link, $id, $f_dnsname);
  84. if ($valid_dns && $uniq_dns) {
  85. $new['dns_name'] = $f_dnsname;
  86. } else {
  87. $msg_error = !$uniq_dns
  88. ? "DNS $f_dnsname already exists at: " . searchHostname($db_link, $id, $f_dnsname) . " Discard changes!"
  89. : "DNS $f_dnsname not valid! Discard changes!";
  90. $_SESSION[$page_url]['msg'] = $msg_error;
  91. LOG_ERROR($db_link, $msg_error);
  92. header("Location: " . $_SERVER["REQUEST_URI"]);
  93. exit;
  94. }
  95. }
  96. }
  97. // Удаление алиасов при отключении DNS
  98. if (empty($f_dnsname) || $new['dns_ptr_only']) {
  99. $new['dns_name'] = '';
  100. $t_user_auth_alias = get_records($db_link, 'user_auth_alias', "auth_id = ? ORDER BY alias", [$id]);
  101. if (!empty($t_user_auth_alias)) {
  102. foreach ($t_user_auth_alias as $row) {
  103. LOG_INFO($db_link, "Remove alias id: " . $row['id'] . " for auth_id: $id :: " . dump_record($db_link, 'user_auth_alias', 'id = ?', [$row['id']]));
  104. delete_record($db_link, 'user_auth_alias', 'id = ?', [$row['id']]);
  105. }
  106. }
  107. }
  108. // PTR-only режим
  109. if ($old_auth_info['dns_ptr_only'] && !$new['dns_ptr_only']) {
  110. $new['dns_name'] = '';
  111. }
  112. if (!empty($f_dnsname) && $new['dns_ptr_only']) {
  113. $domain_zone = ltrim(get_option($db_link, 33), '.');
  114. $escaped_zone = preg_quote($domain_zone, '/');
  115. $f_dnsname = preg_replace('/\.' . $escaped_zone . '$/i', '', $f_dnsname);
  116. $f_dnsname = preg_replace('/\s+/', '-', $f_dnsname);
  117. $new['dns_name'] = $f_dnsname;
  118. }
  119. // Остальные поля
  120. $new['save_traf'] = (int)getPOST("f_save_traf", null, 0);
  121. $new['dhcp_acl'] = trim(getPOST("f_acl", null, ''));
  122. $new['dhcp_option_set'] = trim(getPOST("f_dhcp_option_set", null, ''));
  123. $new['dynamic'] = (int)(getPOST("f_dynamic", null, 0));
  124. if ($new['dynamic']) {
  125. $new['end_life'] = trim(getPOST("f_end_life"));
  126. }
  127. // Настройки по OU
  128. if (is_system_ou($db_link, $parent_ou_id)) {
  129. $new += [
  130. 'nagios_handler' => '',
  131. 'enabled' => 0,
  132. 'link_check' => 0,
  133. 'nagios' => 0,
  134. 'blocked' => 0,
  135. 'day_quota' => 0,
  136. 'month_quota' => 0,
  137. 'queue_id' => 0,
  138. 'filter_group_id' => 0
  139. ];
  140. } else {
  141. $new += [
  142. 'nagios_handler' => trim(getPOST("f_handler", null, '')),
  143. 'enabled' => (int)getPOST("f_enabled", null, 0),
  144. 'link_check' => (int)getPOST("f_link", null, 0),
  145. 'nagios' => (int)getPOST("f_nagios", null, 0),
  146. 'dhcp' => $f_dhcp,
  147. 'blocked' => (int)getPOST("f_blocked", null, 0),
  148. 'day_quota' => (int)getPOST("f_day_q", null, 0),
  149. 'month_quota' => (int)getPOST("f_month_q", null, 0),
  150. 'queue_id' => (int)getPOST("f_queue_id", null, 0),
  151. 'filter_group_id' => (int)getPOST("f_group_id", null, 0)
  152. ];
  153. }
  154. if ($new['day_quota']>0) {
  155. if ($new['month_quota'] <= $new['day_quota']) { $new['month_quota'] = $new['day_quota'] * 31; }
  156. }
  157. if ($new['nagios'] == 0) {
  158. $new['nagios_status'] = 'UP';
  159. }
  160. if (!$user_enabled) {
  161. $new['enabled'] = 0;
  162. }
  163. if (is_auth_bind_changed($db_link, $id, $ip, $mac)) {
  164. $new_id = copy_auth($db_link, $id, $new);
  165. if (!empty($new_id)) {
  166. header("Location: /admin/users/editauth.php?id=" . $new_id, true, 302);
  167. } else {
  168. header("Location: " . $_SERVER["REQUEST_URI"]);
  169. }
  170. exit;
  171. } else {
  172. update_record($db_link, "user_auth", "id = ?", $new, [$id]);
  173. }
  174. } else {
  175. $msg_error = "$msg_ip_error xxx.xxx.xxx.xxx";
  176. $_SESSION[$page_url]['msg'] = $msg_error;
  177. }
  178. header("Location: " . $_SERVER["REQUEST_URI"]);
  179. exit;
  180. }
  181. // === ПЕРЕМЕЩЕНИЕ ЗАПИСИ =========================================================
  182. if (getPOST("moveauth") !== null && !$old_auth_info['deleted']) {
  183. $new_parent_id = (int)getPOST("f_new_parent", null, 0);
  184. $moved_auth = get_record_sql($db_link, "SELECT description FROM user_auth WHERE id = ?", [$id]);
  185. $changes = apply_auth_rule($db_link, $moved_auth, $new_parent_id);
  186. update_record($db_link, "user_auth", "id = ?", $changes, [$id]);
  187. // Удаляем старые правила
  188. delete_records($db_link, "auth_rules", "user_id = ? AND rule = ? AND rule_type = 2", [$old_auth_info["user_id"], $old_auth_info["mac"]]);
  189. delete_records($db_link, "auth_rules", "user_id = ? AND rule = ? AND rule_type = 1", [$old_auth_info["user_id"], $old_auth_info["ip"]]);
  190. header("Location: " . $_SERVER["REQUEST_URI"]);
  191. exit;
  192. }
  193. // === ВОССТАНОВЛЕНИЕ УДАЛЁННОЙ ЗАПИСИ ===========================================
  194. if (getPOST("recovery") !== null && $old_auth_info['deleted']) {
  195. $ip = trim(getPOST("f_ip", null, ''));
  196. if (checkValidIp($ip)) {
  197. $ip_aton = ip2long($ip);
  198. $mac = mac_dotted(getPOST("f_mac", null, ''));
  199. // Проверка MAC
  200. $mac_exists = find_mac_in_subnet($db_link, $ip, $mac);
  201. if (!empty($mac_exists) && ($mac_exists['count'] ?? 0) >= 1 && !in_array($parent_id, $mac_exists['users_id'] ?? [])) {
  202. $dup_info = get_record_sql($db_link, "SELECT * FROM user_list WHERE id = ?", [$mac_exists['users_id'][0] ?? 0]);
  203. $msg_error = "Mac already exists at another user in this subnet! Skip creating $ip [$mac].<br>Old user id: " . ($dup_info['id'] ?? '') . " login: " . ($dup_info['login'] ?? '');
  204. $_SESSION[$page_url]['msg'] = $msg_error;
  205. LOG_ERROR($db_link, $msg_error);
  206. header("Location: " . $_SERVER["REQUEST_URI"]);
  207. exit;
  208. }
  209. // DHCP для вторичного IP
  210. $f_dhcp = (int)getPOST("f_dhcp", null, 0);
  211. if (!empty($mac_exists) && in_array($parent_id, $mac_exists['users_id'] ?? [])) {
  212. if ($parent_id != ($mac_exists['users_id'][0] ?? null)) {
  213. $f_dhcp = 0;
  214. }
  215. }
  216. // Проверка дубликата IP
  217. $dup_ip_record = get_record_sql($db_link, "SELECT * FROM user_auth WHERE ip_int = ? AND id <> ? AND deleted = 0", [$ip_aton, $id]);
  218. if (!empty($dup_ip_record)) {
  219. $dup_info = get_record_sql($db_link, "SELECT * FROM user_list WHERE id = ?", [$dup_ip_record['user_id']]);
  220. $msg_error = "$ip already exists. Skip creating $ip [$mac].<br>Old user id: " . $dup_info['id'] . " login: " . $dup_info['login'];
  221. $_SESSION[$page_url]['msg'] = $msg_error;
  222. LOG_ERROR($db_link, $msg_error);
  223. header("Location: " . $_SERVER["REQUEST_URI"]);
  224. exit;
  225. }
  226. $new = ['deleted' => 0, 'dynamic' => 0, 'dns_name' => ''];
  227. $old_parent = get_record_sql($db_link, "SELECT * FROM user_list WHERE id = ?", [$parent_id]);
  228. if (empty($old_parent)) {
  229. $new_user_info = get_new_user_id($db_link, $ip, $mac, null);
  230. $new_user_id = $new_user_info['user_id'] ?? null;
  231. if (empty($new_user_id)) {
  232. $new_user_id = new_user($db_link, $new_user_info);
  233. }
  234. $new['user_id'] = $new_user_id;
  235. }
  236. $new['description'] = $old_parent['description'] ?? '';
  237. // Настройки по OU
  238. if (get_const('default_user_ou_id') == $parent_ou_id || get_const('default_hotspot_ou_id') == $parent_ou_id) {
  239. $new += [
  240. 'nagios_handler' => '',
  241. 'enabled' => 0,
  242. 'link_check' => 0,
  243. 'nagios' => 0,
  244. 'blocked' => 0,
  245. 'day_quota' => 0,
  246. 'month_quota' => 0,
  247. 'queue_id' => 0,
  248. 'filter_group_id' => 0
  249. ];
  250. } else {
  251. $new += [
  252. 'nagios_handler' => trim(getPOST("f_handler", null, '')),
  253. 'enabled' => (int)getPOST("f_enabled", null, 0),
  254. 'link_check' => (int)getPOST("f_link", null, 0),
  255. 'nagios' => (int)getPOST("f_nagios", null, 0),
  256. 'dhcp' => (int)getPOST("f_dhcp", null, 0),
  257. 'blocked' => (int)getPOST("f_blocked", null, 0),
  258. 'day_quota' => (int)getPOST("f_day_q", null, 0),
  259. 'month_quota' => (int)getPOST("f_month_q", null, 0),
  260. 'queue_id' => (int)getPOST("f_queue_id", null, 0),
  261. 'filter_group_id' => (int)getPOST("f_group_id", null, 0)
  262. ];
  263. }
  264. $new = apply_auth_rule($db_link, $new, $new['user_id']);
  265. update_record($db_link, "user_auth", "id = ?", $new, [$id]);
  266. } else {
  267. $msg_error = "$msg_ip_error xxx.xxx.xxx.xxx/xx";
  268. $_SESSION[$page_url]['msg'] = $msg_error;
  269. }
  270. header("Location: " . $_SERVER["REQUEST_URI"]);
  271. exit;
  272. }
  273. unset($_POST);
  274. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/header.php");
  275. $sSQL = "SELECT * FROM user_auth WHERE id=?";
  276. $auth_info = get_record_sql($db_link, $sSQL, [ $id ]);
  277. $device = get_record_sql($db_link, "SELECT * FROM devices WHERE user_id=?", [ $auth_info['user_id'] ]);
  278. $parent_name = get_login($db_link, $auth_info['user_id']);
  279. if (empty($parent_name)) { $parent_name=$auth_info['user_id']; }
  280. if (is_empty_datetime($auth_info['dhcp_time'])) {
  281. $dhcp_str = '';
  282. } else {
  283. $dhcp_str = $auth_info['dhcp_time'] . " (" . $auth_info['dhcp_action'] . ")";
  284. }
  285. if (is_empty_datetime($auth_info['last_found'])) { $auth_info['last_found'] = ''; }
  286. if (is_empty_datetime($auth_info['mac_found'])) { $auth_info['mac_found'] = ''; }
  287. if (is_empty_datetime($auth_info['arp_found'])) { $auth_info['arp_found'] = ''; }
  288. $now = DateTime::createFromFormat("Y-m-d H:i:s",date('Y-m-d H:i:s'));
  289. $created = new DateTime($auth_info['ts']);
  290. if (empty($auth_info['end_life']) || is_empty_datetime($auth_info['end_life'])) {
  291. $now->modify('+1 day');
  292. $auth_info['end_life'] = $now->format('Y-m-d H:i:s');
  293. }
  294. $is_system_ou = is_system_ou($db_link, $parent_ou_id);
  295. $disabled_attr = $is_system_ou ? 'disabled' : '';
  296. ?>
  297. <div id="cont">
  298. <?php if (!empty($_SESSION[$page_url]['msg'])): ?>
  299. <div id="msg"><?php echo $_SESSION[$page_url]['msg']; unset($_SESSION[$page_url]['msg']); ?></div>
  300. <?php endif; ?>
  301. <b><?php echo WEB_user_title; ?>&nbsp;
  302. <a href="/admin/users/edituser.php?id=<?php echo $auth_info['user_id']; ?>">
  303. <?php echo $parent_name; ?>
  304. </a>
  305. </b>
  306. <?php
  307. $alias_link = '';
  308. if (!empty($auth_info['dns_name']) && !$auth_info['dns_ptr_only']) {
  309. $alias_link = "/admin/users/edit_alias.php?id=" . $id;
  310. }
  311. if (empty($auth_info['created_by'])) {
  312. $auth_info['created_by'] = '-';
  313. }
  314. $f_dns_ptr = $auth_info['dns_ptr_only'] ? 'checked' : '';
  315. ?>
  316. <form name="def" action="editauth.php?id=<?php echo $id; ?>" method="post">
  317. <input type="hidden" name="id" value="<?php echo $id; ?>">
  318. <table class="data">
  319. <!-- 1. СЕТЕВЫЕ ДАННЫЕ -->
  320. <tr>
  321. <td><?php echo WEB_cell_ip; ?></td>
  322. <td><?php echo WEB_cell_mac; ?></td>
  323. <td><?php echo WEB_cell_description; ?></td>
  324. <td></td>
  325. <td><?php echo WEB_cell_traf; ?></td>
  326. </tr>
  327. <tr>
  328. <td><input type="text" name="f_ip" value="<?php echo htmlspecialchars($auth_info['ip']); ?>" pattern="^(\d{1,3}\.){3}\d{1,3}$" class='full-width'></td>
  329. <td><input type="text" name="f_mac" value="<?php echo htmlspecialchars($auth_info['mac']); ?>" pattern="^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$" class='full-width'></td>
  330. <td colspan=2><input type="text" name="f_description" value="<?php echo htmlspecialchars($auth_info['description']); ?>" class='full-width'></td>
  331. <td><?php print_qa_select('f_save_traf', $auth_info['save_traf'],$is_system_ou); ?></td>
  332. </tr>
  333. <!-- 2. ДОСТУП И ОГРАНИЧЕНИЯ -->
  334. <tr style="height: 10px; background: #f5f5f5;"><td colspan="5"></td></tr>
  335. <tr>
  336. <td><?php echo WEB_cell_enabled; ?></td>
  337. <td><?php echo WEB_cell_blocked; ?></td>
  338. <td><?php echo WEB_cell_filter; ?></td>
  339. <td><?php echo WEB_cell_shaper; ?></td>
  340. <td><?php echo WEB_cell_perday; ?> / <?php echo WEB_cell_permonth; ?></td>
  341. </tr>
  342. <tr>
  343. <td><?php print_qa_select('f_enabled', $auth_info['enabled'], $is_system_ou); ?></td>
  344. <td><?php print_qa_select('f_blocked', $auth_info['blocked'], $is_system_ou); ?></td>
  345. <td><?php print_filter_group_select($db_link, 'f_group_id', $auth_info['filter_group_id'], $is_system_ou); ?></td>
  346. <td><?php print_queue_select($db_link, 'f_queue_id', $auth_info['queue_id'],$is_system_ou); ?></td>
  347. <td>
  348. <input type="text" name="f_day_q" value="<?php echo $auth_info['day_quota']; ?>" size="5" <?php print $disabled_attr; ?> > /
  349. <input type="text" name="f_month_q" value="<?php echo $auth_info['month_quota']; ?>" size="5" <?php print $disabled_attr; ?> >
  350. </td>
  351. </tr>
  352. <!-- 3. DHCP -->
  353. <tr style="height: 10px; background: #f5f5f5;"><td colspan="5"></td></tr>
  354. <tr>
  355. <td><?php echo WEB_cell_dns_name; ?> &nbsp;|&nbsp; <?php print_url(WEB_cell_aliases, $alias_link); ?></td>
  356. <td><?php echo WEB_cell_dhcp; ?></td>
  357. <td><?php echo WEB_cell_acl; ?></td>
  358. <td><?php echo WEB_cell_option_set; ?></td>
  359. <td></td>
  360. </tr>
  361. <tr>
  362. <td style="white-space: nowrap;">
  363. <input type="text" name="f_dns_name" size="14" value="<?php echo htmlspecialchars($auth_info['dns_name']); ?>" pattern="^([a-zA-Z0-9-]{1,63})(\.[a-zA-Z0-9-]{1,63})*\.?$" <?php echo $disabled_attr; ?> class='full-width'>
  364. <br>
  365. <label>
  366. <input type="checkbox" id="f_dns_ptr" name="f_dns_ptr" value="1" <?php echo $f_dns_ptr; echo " {$disabled_attr}"; ?>>
  367. <?php echo WEB_cell_ptr_only; ?>
  368. </label>
  369. </td>
  370. <td><?php print_qa_select('f_dhcp', $auth_info['dhcp'], $is_system_ou); ?></td>
  371. <td><?php print_dhcp_acl_list($db_link, "f_acl", $auth_info['dhcp_acl'], $is_system_ou); ?></td>
  372. <td><?php print_dhcp_option_set_list($db_link, "f_dhcp_option_set", $auth_info['dhcp_option_set'],$is_system_ou); ?></td>
  373. <td></td>
  374. </tr>
  375. <!-- 4. МОНИТОРИНГ -->
  376. <tr style="height: 10px; background: #f5f5f5;"><td colspan="5"></td></tr>
  377. <tr>
  378. <td width="200"><?php echo WEB_cell_wikiname; ?></td>
  379. <td><?php if (empty($device) || (!empty($device) && $device['device_type'] > 2)) echo WEB_cell_nagios; ?></td>
  380. <td><?php if (empty($device) || (!empty($device) && $device['device_type'] > 2)) echo WEB_cell_link; ?></td>
  381. <td><?php echo WEB_cell_nagios_handler; ?></td>
  382. <td></td>
  383. </tr>
  384. <tr>
  385. <td><input type="text" name="f_wiki" value="<?php echo htmlspecialchars($auth_info['wikiname']); ?>" <?php print $disabled_attr; ?> class='full-width'></td>
  386. <td><?php if (empty($device) || (!empty($device) && $device['device_type'] > 2)) print_qa_select('f_nagios', $auth_info['nagios'],$is_system_ou); ?></td>
  387. <td><?php if (empty($device) || (!empty($device) && $device['device_type'] > 2)) print_qa_select('f_link', $auth_info['link_check'],$is_system_ou); ?></td>
  388. <td colspan=2><input type="text" name="f_handler" value="<?php echo htmlspecialchars($auth_info['nagios_handler']); ?>" <?php print $disabled_attr; ?> class='full-width'></td>
  389. </tr>
  390. <!-- 5. ТИП ЗАПИСИ -->
  391. <tr style="height: 10px; background: #f5f5f5;"><td colspan="5"></td></tr>
  392. <tr>
  393. <td><?php echo WEB_cell_temporary; ?></td>
  394. <td colspan="4">
  395. <?php print_qa_select('f_dynamic', $auth_info['dynamic']); ?>
  396. <span id="end-life-container" style="<?php echo !$auth_info['dynamic'] ? 'display:none;' : ''; ?>">
  397. &nbsp;—&nbsp;
  398. <input type="datetime-local"
  399. id="f_end_life"
  400. name="f_end_life"
  401. min="<?php echo $created->format('Y-m-d\TH:i:s'); ?>"
  402. value="<?php echo htmlspecialchars($auth_info['end_life'] ?? ''); ?>"
  403. step="1">
  404. </span>
  405. </td>
  406. </tr>
  407. <!-- КНОПКИ -->
  408. <tr style="height: 10px; background: #f5f5f5;"><td colspan="5"></td></tr>
  409. <tr>
  410. <td colspan="3">
  411. <input type="submit" name="moveauth" value="<?php echo WEB_btn_move; ?>">
  412. <?php print_login_select($db_link, 'f_new_parent', $auth_info['user_id']); ?>
  413. </td>
  414. <?php if ($auth_info['deleted']): ?>
  415. <td><font color="red"><?php echo WEB_deleted . ": " . $auth_info['changed_time']; ?></font></td>
  416. <td align="right"><input type="submit" name="recovery" value="<?php echo WEB_btn_recover; ?>"></td>
  417. <?php else: ?>
  418. <td></td>
  419. <td align="right"><input type="submit" name="editauth" value="<?php echo WEB_btn_save; ?>"></td>
  420. <?php endif; ?>
  421. </tr>
  422. </table>
  423. <!-- ИНФОРМАЦИЯ О ЗАПИСИ -->
  424. <table class="data" style="margin-top: 20px;">
  425. <caption style="caption-side: top; font-weight: bold; margin-bottom: 5px;"><?php echo WEB_status; ?></caption>
  426. <tr>
  427. <td width="150"><?php echo WEB_cell_created_by; ?>:</td>
  428. <td width="200"><?php echo $auth_info['created_by']; ?></td>
  429. <td align="right"><a href="/admin/logs/authlog.php?auth_id=<?php echo $id; ?>"><?php echo WEB_log; ?></a></td>
  430. <td align="right"><?php print_url(WEB_report_by_day, "/admin/reports/authday.php?id=$id"); ?></td>
  431. </tr>
  432. <tr>
  433. <td><?php echo WEB_cell_created; ?>:</td>
  434. <td><?php echo $auth_info['ts']; ?></td>
  435. <td><?php echo WEB_cell_connection; ?>:</td>
  436. <td><?php echo get_connection($db_link, $id); ?></td>
  437. </tr>
  438. <tr>
  439. <td><?php echo WEB_cell_dhcp_hostname; ?>:</td>
  440. <td><?php echo $auth_info['dhcp_hostname']; ?></td>
  441. <td>Dhcp event:</td>
  442. <td><?php echo $dhcp_str; ?></td>
  443. </tr>
  444. <tr>
  445. <td><?php echo WEB_cell_arp_found; ?>:</td>
  446. <td><?php echo $auth_info['arp_found']; ?></td>
  447. <td><?php echo WEB_cell_mac_found; ?>:</td>
  448. <td><?php echo $auth_info['mac_found']; ?></td>
  449. </tr>
  450. <tr>
  451. <td><?php echo WEB_changed_time; ?>:</td>
  452. <td><?php echo $auth_info['changed_time']; ?></td>
  453. <td></td>
  454. <td></td>
  455. </tr>
  456. </table>
  457. <?php if ($msg_error): ?>
  458. <div id="msg"><b><?php echo $msg_error; ?></b></div>
  459. <?php endif; ?>
  460. </form>
  461. <script>
  462. document.addEventListener('DOMContentLoaded', function() {
  463. const dynamicField = document.querySelector('[name="f_dynamic"]');
  464. const endLifeContainer = document.getElementById('end-life-container');
  465. if (dynamicField && endLifeContainer) {
  466. function toggleEndLife() {
  467. const isActive = dynamicField.type === 'checkbox'
  468. ? dynamicField.checked
  469. : dynamicField.value == '1';
  470. endLifeContainer.style.display = isActive ? '' : 'none';
  471. }
  472. dynamicField.addEventListener('change', toggleEndLife);
  473. }
  474. });
  475. </script>
  476. <?php require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/footer.php"); ?>