more refactor

This commit is contained in:
Kevin Yue
2023-11-13 10:05:06 +08:00
parent 0b4829a610
commit bf2d327687
20 changed files with 965 additions and 64 deletions

View File

@@ -1,11 +1,8 @@
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")
@@ -55,7 +52,8 @@ async fn main() {
let url = Url::parse(&server).expect("Invalid server URL");
let host = url.host_str().expect("Invalid server URL");
let portal = Portal::new(host);
// let portal = Portal::new(host);
// let prelogin = portal.prelogin().await;
}
Some(("disconnect", _)) => {
println!("Disconnecting...");

View File

@@ -4,11 +4,14 @@ pub(crate) struct Portal<'a> {
address: &'a str,
}
struct SamlPrelogin {}
#[derive(Debug)]
pub(crate) struct SamlPrelogin {}
struct StandardPrelogin {}
#[derive(Debug)]
pub(crate) struct StandardPrelogin {}
enum Prelogin {
#[derive(Debug)]
pub(crate) enum Prelogin {
Saml(SamlPrelogin),
Standard(StandardPrelogin),
}
@@ -19,9 +22,10 @@ impl<'a> Portal<'a> {
}
// Preform the Portal prelogin
async fn prelogin(&self) -> Result<Prelogin> {
pub 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?;
let res_xml = reqwest::get(&prelogin_url).await?.text().await?;
println!("{}", res_xml);
Ok(Prelogin::Standard(StandardPrelogin {}))
@@ -38,9 +42,11 @@ mod tests {
assert_eq!(portal.address, "vpn.example.com");
}
#[test]
fn test_prelogin() {
let portal = Portal::new("vpn.example.com");
let prelogin = portal.prelogin();
#[tokio::test]
async fn test_prelogin() {
let portal = Portal::new("vpn.microstrategy.com");
let prelogin = portal.prelogin().await;
assert!(prelogin.is_ok());
}
}