add by_ua.only_if_contains
This commit is contained in:
parent
802b618e7c
commit
cc4f8a2478
2 changed files with 12 additions and 5 deletions
|
|
@ -11,8 +11,11 @@ ranged.v4 = 16 # 16 => 255.255.0.0
|
|||
ranged.v6 = 48 # 48 => ffff:ffff:ffff::
|
||||
|
||||
# whether to also group by user agent
|
||||
by_ua = true
|
||||
timeout_by_ua = false
|
||||
by_ua.enable = true
|
||||
by_ua.only_if_contains = [
|
||||
"bot"
|
||||
]
|
||||
by_ua.timeout = true
|
||||
|
||||
|
||||
[handler]
|
||||
|
|
|
|||
10
src/main.rs
10
src/main.rs
|
|
@ -53,8 +53,12 @@ pub enum ClientID {
|
|||
|
||||
impl ClientID {
|
||||
pub fn is_not_allowed(&self) -> bool {
|
||||
let only_if = CONFIG["by_ua.only_if_contains"].simple_arr();
|
||||
match self {
|
||||
Self::TransformedUA(_) => !CONFIG["by_ua"].boolean(),
|
||||
Self::TransformedUA(s) => {
|
||||
!(CONFIG["by_ua.enable"].boolean()
|
||||
&& (only_if.is_empty() || only_if.iter().any(|x| s.contains(x.str()))))
|
||||
}
|
||||
Self::IpAddr(_) => false,
|
||||
}
|
||||
}
|
||||
|
|
@ -119,7 +123,7 @@ impl ConnectionState for Intercept {
|
|||
let mut addr_timeouts = self.addr_timeouts.lock().unwrap();
|
||||
let mut ua_timeouts = self.ua_timeouts.lock().unwrap();
|
||||
|
||||
if CONFIG["by_ua"].boolean() {
|
||||
if CONFIG["by_ua.enable"].boolean() {
|
||||
println!(
|
||||
"Handling request from {ip} ({discrim_ip} with {transformed_ua}) for {}.",
|
||||
connection.path
|
||||
|
|
@ -153,7 +157,7 @@ impl ConnectionState for Intercept {
|
|||
discrim_ip,
|
||||
Timer::new(TimerDuration::Real(Duration::from_secs(timeout))),
|
||||
);
|
||||
if CONFIG["timeout_by_ua"].boolean() {
|
||||
if CONFIG["by_ua.timeout"].boolean() {
|
||||
ua_timeouts.insert(
|
||||
transformed_ua.clone(),
|
||||
Timer::new(TimerDuration::Real(Duration::from_secs(timeout))),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue