mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-05-20 07:26:58 -04:00
more refactor
This commit is contained in:
@@ -7,8 +7,10 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
gpcommon = { path = "../gpcommon" }
|
||||
gpauth = { path = "../gpauth" }
|
||||
anyhow.workspace = true
|
||||
clap.workspace = true
|
||||
reqwest.workspace = true
|
||||
tokio.workspace = true
|
||||
url.workspace = true
|
||||
libc = "0.2"
|
||||
|
||||
@@ -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...");
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user