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::utils::sleep_s;
|
||||
|
||||
use reqwest::Client;
|
||||
use reqwest::Error as ReqError;
|
||||
|
||||
pub async fn send_to_ipbl_api(ctx: &Context, ip: &IpEvent, ret: &mut Vec<String>) {
|
||||
ret.push(format!("host: {hostname}", hostname = ctx.hostname));
|
||||
pub async fn send_to_ipbl_ws(
|
||||
client: &Client,
|
||||
hostname: &str,
|
||||
server: &str,
|
||||
ip: &IpEvent,
|
||||
ret: &mut Vec<String>,
|
||||
) {
|
||||
ret.push(format!("host: {hostname}", hostname = hostname));
|
||||
loop {
|
||||
match push_ip(&ctx, &ip.ipdata, ret).await {
|
||||
match push_ip(&client, &server, &ip.ipdata, ret).await {
|
||||
Ok(_) => {
|
||||
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 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(),
|
||||
});
|
||||
|
||||
let resp = ctx
|
||||
.client
|
||||
.post(format!("{server}/ips", server = ctx.flags.server))
|
||||
let resp = client
|
||||
.post(format!("{server}/ips"))
|
||||
.json(&data)
|
||||
.send()
|
||||
.await?;
|
||||
|
Loading…
Reference in New Issue
Block a user