documentation changes
This commit is contained in:
		| @@ -4,3 +4,7 @@ version = "0.1.0" | |||||||
| edition = "2021" | edition = "2021" | ||||||
|  |  | ||||||
| [dependencies] | [dependencies] | ||||||
|  | rustyline = "11" | ||||||
|  | color-eyre = "0.6" | ||||||
|  | tokio = { version = "1.0", default-features = false, features = ["macros"] } | ||||||
|  | tracing-subscriber = "0.3" | ||||||
|   | |||||||
| @@ -1,3 +1,6 @@ | |||||||
|  | // This example shows you how to add, edit and remove port forwading entries.
 | ||||||
|  | // Usage: cargo run --example port_forwards -- <Connect Box IP> <login code> <local IP>
 | ||||||
|  | 
 | ||||||
| use std::{env, net::Ipv4Addr}; | use std::{env, net::Ipv4Addr}; | ||||||
| 
 | 
 | ||||||
| use color_eyre::Result; | use color_eyre::Result; | ||||||
| @@ -10,16 +13,24 @@ use connectbox::{ | |||||||
| async fn main() -> Result<()> { | async fn main() -> Result<()> { | ||||||
|     tracing_subscriber::fmt::init(); |     tracing_subscriber::fmt::init(); | ||||||
|     color_eyre::install()?; |     color_eyre::install()?; | ||||||
|  | 
 | ||||||
|     let mut args = env::args().skip(1); |     let mut args = env::args().skip(1); | ||||||
|     let ip = args.next().expect("no ip specified"); |     let ip = args.next().expect("no ip specified"); | ||||||
|     let code = args.next().expect("no code specified"); |     let code = args.next().expect("no code specified"); | ||||||
|  |     let local_ip: Ipv4Addr = args | ||||||
|  |         .next() | ||||||
|  |         .expect("no local ip specified") | ||||||
|  |         .parse() | ||||||
|  |         .expect("local ip is not a valid ipv4 address"); | ||||||
| 
 | 
 | ||||||
|  |     // first, we create a new API client and log in to the router.
 | ||||||
|     let connect_box = ConnectBox::new(ip, code, true)?; |     let connect_box = ConnectBox::new(ip, code, true)?; | ||||||
|     connect_box.login().await?; |     connect_box.login().await?; | ||||||
| 
 | 
 | ||||||
|  |     // then, we remove all port forwarding entries for the local ip
 | ||||||
|     connect_box |     connect_box | ||||||
|         .edit_port_forwards(|v| { |         .edit_port_forwards(|v| { | ||||||
|             if v.local_ip == Ipv4Addr::new(192, 168, 0, 180) { |             if v.local_ip == local_ip { | ||||||
|                 PortForwardAction::Delete |                 PortForwardAction::Delete | ||||||
|             } else { |             } else { | ||||||
|                 PortForwardAction::Keep |                 PortForwardAction::Keep | ||||||
| @@ -27,9 +38,10 @@ async fn main() -> Result<()> { | |||||||
|         }) |         }) | ||||||
|         .await?; |         .await?; | ||||||
| 
 | 
 | ||||||
|  |     // then, we add a new port forward for the port 25565 (Minecraft server)
 | ||||||
|     let pf = PortForwardEntry { |     let pf = PortForwardEntry { | ||||||
|         id: 0, |         id: 0, | ||||||
|         local_ip: "192.168.0.180".parse().unwrap(), |         local_ip, | ||||||
|         start_port: 25565, |         start_port: 25565, | ||||||
|         end_port: 25565, |         end_port: 25565, | ||||||
|         start_port_in: 25565, |         start_port_in: 25565, | ||||||
| @@ -39,9 +51,11 @@ async fn main() -> Result<()> { | |||||||
|     }; |     }; | ||||||
|     connect_box.add_port_forward(&pf).await?; |     connect_box.add_port_forward(&pf).await?; | ||||||
| 
 | 
 | ||||||
|  |     // lastly, we get the new port forwarding table and print it out
 | ||||||
|     let portforwards = connect_box.port_forwards().await?; |     let portforwards = connect_box.port_forwards().await?; | ||||||
|     println!("{portforwards:#?}"); |     println!("{portforwards:#?}"); | ||||||
| 
 | 
 | ||||||
|  |     // and then we log out so that other users can log in to the web interface
 | ||||||
|     connect_box.logout().await?; |     connect_box.logout().await?; | ||||||
| 
 | 
 | ||||||
|     Ok(()) |     Ok(()) | ||||||
| @@ -1,4 +1,4 @@ | |||||||
| //! API client library for the Compal CH7465CE, which is a cable modem provided by various European ISPs under the name Connect Box. | //! API client library for the Compal CH7465LG, which is a cable modem provided by various European ISPs under the name Connect Box. | ||||||
|  |  | ||||||
| #![allow(clippy::missing_errors_doc)] | #![allow(clippy::missing_errors_doc)] | ||||||
| use std::{borrow::Cow, fmt::Display, sync::Arc}; | use std::{borrow::Cow, fmt::Display, sync::Arc}; | ||||||
| @@ -262,7 +262,7 @@ impl ConnectBox { | |||||||
|             ("end_port".into(), port.end_port.to_string().into()), |             ("end_port".into(), port.end_port.to_string().into()), | ||||||
|             ("start_portIn".into(), port.start_port_in.to_string().into()), |             ("start_portIn".into(), port.start_port_in.to_string().into()), | ||||||
|             ("end_portIn".into(), port.end_port_in.to_string().into()), |             ("end_portIn".into(), port.end_port_in.to_string().into()), | ||||||
|             ("protocol".into(), port.protocol.id().to_string().into()), |             ("protocol".into(), port.protocol.id_str().into()), | ||||||
|             ("enable".into(), u8::from(port.enable).to_string().into()), |             ("enable".into(), u8::from(port.enable).to_string().into()), | ||||||
|             ("delete".into(), "0".into()), |             ("delete".into(), "0".into()), | ||||||
|             ("idd".into(), "".into()), |             ("idd".into(), "".into()), | ||||||
|   | |||||||
| @@ -70,11 +70,11 @@ pub enum PortForwardProtocol { | |||||||
| } | } | ||||||
|  |  | ||||||
| impl PortForwardProtocol { | impl PortForwardProtocol { | ||||||
|     pub(crate) fn id(&self) -> u8 { |     pub(crate) fn id_str(&self) -> &str { | ||||||
|         match self { |         match self { | ||||||
|             PortForwardProtocol::Tcp => 1, |             PortForwardProtocol::Tcp => "1", | ||||||
|             PortForwardProtocol::Udp => 2, |             PortForwardProtocol::Udp => "2", | ||||||
|             PortForwardProtocol::Both => 3, |             PortForwardProtocol::Both => "3", | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user