refactor: update the dependencies

This commit is contained in:
Kevin Yue
2023-09-03 21:26:31 +08:00
parent 9b9ac7fc8a
commit 0b4829a610
9 changed files with 441 additions and 61 deletions

View File

@@ -1,10 +1,14 @@
[package]
name = "gpclient"
version = "0.1.0"
version.workspace = true
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
gpcommon = { path = "../gpcommon" }
tokio = { version = "1.0", features = ["full"] }
anyhow.workspace = true
clap.workspace = true
reqwest.workspace = true
tokio.workspace = true
url.workspace = true

View File

@@ -1,5 +1,24 @@
use clap::{arg, Command, Parser};
use gpcommon::{Client, SOCKET_PATH};
use portal::Portal;
use tokio::{io::AsyncReadExt, net::UnixStream, sync::mpsc};
use url::Url;
mod portal;
fn cli() -> Command {
Command::new("gpclient")
.about("GlobalProtect-openconnect CLI client")
.subcommand_required(true)
.arg_required_else_help(true)
.subcommand(
Command::new("connect")
.about("Connect to GlobalProtect VPN")
.arg(arg!(<SERVER> "The GlobalProtect server"))
.arg_required_else_help(true),
)
.subcommand(Command::new("disconnect").about("Disconnect from GlobalProtect VPN"))
}
#[tokio::main]
async fn main() {
@@ -14,12 +33,33 @@ async fn main() {
// println!("http_port: {http_port}");
// println!("aes_key: {aes_key:?}");
let (output_tx, mut output_rx) = mpsc::channel::<String>(32);
let client = Client::default();
// let (output_tx, mut output_rx) = mpsc::channel::<String>(32);
// let client = Client::default();
tokio::select! {
_ = client.run() => {
println!("Client finished");
// tokio::select! {
// _ = client.run() => {
// println!("Client finished");
// }
// }
let matches = cli().get_matches();
match matches.subcommand() {
Some(("connect", sub_m)) => {
let server = sub_m.get_one::<String>("SERVER").expect("Missing server");
let server = if server.starts_with("https://") || server.starts_with("http://") {
server.to_string()
} else {
format!("https://{}", server)
};
let url = Url::parse(&server).expect("Invalid server URL");
let host = url.host_str().expect("Invalid server URL");
let portal = Portal::new(host);
}
Some(("disconnect", _)) => {
println!("Disconnecting...");
}
_ => unreachable!(),
}
}

46
gpclient/src/portal.rs Normal file
View File

@@ -0,0 +1,46 @@
use anyhow::Result;
pub(crate) struct Portal<'a> {
address: &'a str,
}
struct SamlPrelogin {}
struct StandardPrelogin {}
enum Prelogin {
Saml(SamlPrelogin),
Standard(StandardPrelogin),
}
impl<'a> Portal<'a> {
pub fn new(address: &'a str) -> Self {
Self { address }
}
// Preform the Portal prelogin
async fn prelogin(&self) -> Result<Prelogin> {
let prelogin_url = format!("https://{}/global-protect/prelogin.esp", self.address);
let res_xml = reqwest::get(prelogin_url).await?.text().await?;
println!("{}", res_xml);
Ok(Prelogin::Standard(StandardPrelogin {}))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_new() {
let portal = Portal::new("vpn.example.com");
assert_eq!(portal.address, "vpn.example.com");
}
#[test]
fn test_prelogin() {
let portal = Portal::new("vpn.example.com");
let prelogin = portal.prelogin();
}
}