$user_id, 'rule_type' => 2, 'rule' => $b_mac ]); LOG_INFO($db_link, "Created auto rule for user_id: $user_id and mac $b_mac"); } else { LOG_INFO($db_link, "Auto rule for user_id: $user_id and mac $b_mac already exists"); } } else { run_sql($db_link, "DELETE FROM auth_rules WHERE user_id = ? AND rule_type = 2", [$user_id]); LOG_INFO($db_link, "Remove auto rule for user_id: $user_id and mac $b_mac"); } } // === Правило привязки IP === if (getPOST("e_bind_ip", $page_url) !== null) { if ($a_bind_ip && $b_ip) { $user_rule = get_record_sql($db_link, "SELECT * FROM auth_rules WHERE user_id = ? AND rule_type = 1", [$user_id] ); $ip_rule = get_record_sql($db_link, "SELECT * FROM auth_rules WHERE rule = ? AND rule_type = 1", [$b_ip] ); if (!$user_rule && !$ip_rule) { insert_record($db_link, "auth_rules", [ 'user_id' => $user_id, 'rule_type' => 1, 'rule' => $b_ip ]); LOG_INFO($db_link, "Created auto rule for user_id: $user_id and ip $b_ip"); } else { LOG_INFO($db_link, "Auto rule for user_id: $user_id and ip $b_ip already exists"); } } else { run_sql($db_link, "DELETE FROM auth_rules WHERE user_id = ? AND rule_type = 1", [$user_id]); LOG_INFO($db_link, "Remove auto rule for user_id: $user_id and ip $b_ip"); } } // === Создание сетевого устройства === if (getPOST("e_create_netdev", $page_url) !== null && $a_create_netdev && $b_ip) { $existing_device = get_record_sql($db_link, "SELECT * FROM devices WHERE user_id = ?", [$user_id] ); if (!$existing_device) { $latest_auth = get_record_sql($db_link, "SELECT * FROM user_auth WHERE user_id = ? ORDER BY last_found DESC", [$user_id] ); if ($latest_auth) { $new_device = [ 'user_id' => $user_id, 'device_name' => $login_record['login'] ?? 'user_' . $user_id, 'device_type' => 5, 'ip' => $latest_auth['ip'], 'community' => get_const('snmp_default_community'), 'snmp_version' => get_const('snmp_default_version'), 'login' => get_option($db_link, 28), 'password' => get_option($db_link, 29), 'protocol' => 0, 'control_port' => get_option($db_link, 30) ]; $new_id = insert_record($db_link, "devices", $new_device); } } } } if ($all_ok) { print "Success!"; } else { print "Fail!"; } } ?>