updated webservice.rs
This commit is contained in:
parent
36f892cf42
commit
09ca2ada91
@ -2,12 +2,19 @@ use crate::config::Context;
|
|||||||
use crate::ip::{IpData, IpEvent};
|
use crate::ip::{IpData, IpEvent};
|
||||||
use crate::utils::sleep_s;
|
use crate::utils::sleep_s;
|
||||||
|
|
||||||
|
use reqwest::Client;
|
||||||
use reqwest::Error as ReqError;
|
use reqwest::Error as ReqError;
|
||||||
|
|
||||||
pub async fn send_to_ipbl_api(ctx: &Context, ip: &IpEvent, ret: &mut Vec<String>) {
|
pub async fn send_to_ipbl_ws(
|
||||||
ret.push(format!("host: {hostname}", hostname = ctx.hostname));
|
client: &Client,
|
||||||
|
hostname: &str,
|
||||||
|
server: &str,
|
||||||
|
ip: &IpEvent,
|
||||||
|
ret: &mut Vec<String>,
|
||||||
|
) {
|
||||||
|
ret.push(format!("host: {hostname}", hostname = hostname));
|
||||||
loop {
|
loop {
|
||||||
match push_ip(&ctx, &ip.ipdata, ret).await {
|
match push_ip(&client, &server, &ip.ipdata, ret).await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -19,7 +26,12 @@ pub async fn send_to_ipbl_api(ctx: &Context, ip: &IpEvent, ret: &mut Vec<String>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn push_ip(ctx: &Context, ip: &IpData, ret: &mut Vec<String>) -> Result<(), ReqError> {
|
async fn push_ip(
|
||||||
|
client: &Client,
|
||||||
|
server: &str,
|
||||||
|
ip: &IpData,
|
||||||
|
ret: &mut Vec<String>,
|
||||||
|
) -> Result<(), ReqError> {
|
||||||
let result: String;
|
let result: String;
|
||||||
let mut data: Vec<IpData> = vec![];
|
let mut data: Vec<IpData> = vec![];
|
||||||
|
|
||||||
@ -30,9 +42,8 @@ async fn push_ip(ctx: &Context, ip: &IpData, ret: &mut Vec<String>) -> Result<()
|
|||||||
hostname: ip.hostname.to_string(),
|
hostname: ip.hostname.to_string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
let resp = ctx
|
let resp = client
|
||||||
.client
|
.post(format!("{server}/ips"))
|
||||||
.post(format!("{server}/ips", server = ctx.flags.server))
|
|
||||||
.json(&data)
|
.json(&data)
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
|
Loading…
Reference in New Issue
Block a user