diff --git a/connectbox/examples/devices.rs b/connectbox/examples/devices.rs
index 2ac0343..90418f9 100644
--- a/connectbox/examples/devices.rs
+++ b/connectbox/examples/devices.rs
@@ -1,7 +1,10 @@
-use std::env;
+use std::{env, net::Ipv4Addr};
use color_eyre::Result;
-use connectbox::ConnectBox;
+use connectbox::{
+ models::{PortForwardEntry, PortForwardProtocol},
+ ConnectBox, PortForwardAction,
+};
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
@@ -14,8 +17,32 @@ async fn main() -> Result<()> {
let connect_box = ConnectBox::new(ip, code, true)?;
connect_box.login().await?;
- let devices = connect_box.get_devices().await?;
- println!("{devices:#?}");
+ connect_box
+ .edit_port_forwards(|v| {
+ if v.local_ip == Ipv4Addr::new(192, 168, 0, 180) {
+ PortForwardAction::Delete
+ } else {
+ PortForwardAction::Keep
+ }
+ })
+ .await?;
+
+ let pf = PortForwardEntry {
+ id: 0,
+ local_ip: "192.168.0.180".parse().unwrap(),
+ start_port: 25565,
+ end_port: 25565,
+ start_port_in: 25565,
+ end_port_in: 25565,
+ protocol: PortForwardProtocol::Both,
+ enable: true,
+ };
+ connect_box.add_port_forward(&pf).await?;
+
+ let portforwards = connect_box.port_forwards().await?;
+ println!("{portforwards:#?}");
+
+ connect_box.logout().await?;
Ok(())
}
diff --git a/connectbox/src/error.rs b/connectbox/src/error.rs
index e734eba..0ec5eee 100644
--- a/connectbox/src/error.rs
+++ b/connectbox/src/error.rs
@@ -15,6 +15,8 @@ pub enum Error {
AccessDenied,
#[error("an unexpected redirection has occurred: {0:?}")]
UnexpectedRedirect(String),
+ #[error("remote error: {0:?}")]
+ Remote(String),
#[error(transparent)]
URLParseError(#[from] url::ParseError),
diff --git a/connectbox/src/functions.rs b/connectbox/src/functions.rs
index 9d7444f..f8fc188 100644
--- a/connectbox/src/functions.rs
+++ b/connectbox/src/functions.rs
@@ -1,8 +1,10 @@
// Setters
pub const LOGIN: u32 = 15;
+pub const LOGOUT: u32 = 16;
+pub const EDIT_FORWARDS: u32 = 122;
// Getters
pub const LAN_TABLE: u32 = 123;
-pub const FORWARDS: u32 = 121;
\ No newline at end of file
+pub const FORWARDS: u32 = 121;
diff --git a/connectbox/src/lib.rs b/connectbox/src/lib.rs
index ebcd9d0..2a2ef21 100644
--- a/connectbox/src/lib.rs
+++ b/connectbox/src/lib.rs
@@ -1,12 +1,15 @@
//! API client library for the Compal CH7465CE, which is a cable modem provided by various European ISPs under the name Connect Box.
+#![allow(clippy::missing_errors_doc)]
use std::{borrow::Cow, fmt::Display, sync::Arc};
pub use error::Error;
+use models::PortForwardEntry;
use reqwest::{
cookie::{CookieStore, Jar},
+ header::HeaderValue,
redirect::Policy,
- Client, Url, header::HeaderValue,
+ Client, Url,
};
use serde::de::DeserializeOwned;
@@ -47,16 +50,16 @@ impl ConnectBox {
let setter_url = base_url.join("xml/setter.xml")?;
Ok(ConnectBox {
http,
+ code,
cookie_store,
base_url,
getter_url,
setter_url,
- code,
auto_reauth,
})
}
- fn cookie<'a>(&self, name: &str) -> Result