mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-05-20 07:26:58 -04:00
Support specify csd-wrapper
This commit is contained in:
51
crates/gpapi/src/gateway/hip.rs
Normal file
51
crates/gpapi/src/gateway/hip.rs
Normal file
@@ -0,0 +1,51 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use anyhow::bail;
|
||||
use reqwest::Client;
|
||||
|
||||
use crate::{gp_params::GpParams, utils::normalize_server};
|
||||
|
||||
async fn retrieve_config(gateway: &str, cookie: &str, gp_params: &GpParams) -> anyhow::Result<()> {
|
||||
let url = normalize_server(gateway)?;
|
||||
|
||||
let config_url = format!("{}/ssl-vpn/getconfig.esp", url);
|
||||
let client = Client::builder()
|
||||
.danger_accept_invalid_certs(gp_params.ignore_tls_errors())
|
||||
.user_agent(gp_params.user_agent())
|
||||
.build()?;
|
||||
|
||||
let mut params = serde_urlencoded::from_str::<HashMap<&str, &str>>(cookie)?;
|
||||
|
||||
println!("{:?}", params);
|
||||
|
||||
params.insert("client-type", "1");
|
||||
params.insert("protocol-version", "p1");
|
||||
params.insert("internal", "no");
|
||||
params.insert("ipv6-support", "yes");
|
||||
params.insert("clientos", gp_params.client_os());
|
||||
params.insert("hmac-algo", "sha1,md5,sha256");
|
||||
params.insert("enc-algo", "aes-128-cbc,aes-256-cbc");
|
||||
|
||||
if let Some(os_version) = gp_params.os_version() {
|
||||
params.insert("os-version", os_version);
|
||||
}
|
||||
if let Some(client_version) = gp_params.client_version() {
|
||||
params.insert("app-version", client_version);
|
||||
}
|
||||
|
||||
let res = client.post(&config_url).form(¶ms).send().await?;
|
||||
let status = res.status();
|
||||
|
||||
if status.is_client_error() || status.is_server_error() {
|
||||
bail!("Retrieve config error: {}", status)
|
||||
}
|
||||
|
||||
let res_xml = res.text().await?;
|
||||
println!("{}", res_xml);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn hip_report(gateway: &str, cookie: &str, gp_params: &GpParams) -> anyhow::Result<()> {
|
||||
retrieve_config(gateway, cookie, gp_params).await
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
mod login;
|
||||
mod parse_gateways;
|
||||
pub mod hip;
|
||||
|
||||
pub use login::*;
|
||||
pub(crate) use parse_gateways::*;
|
||||
|
@@ -83,6 +83,18 @@ impl GpParams {
|
||||
self.prefer_default_browser
|
||||
}
|
||||
|
||||
pub fn client_os(&self) -> &str {
|
||||
self.client_os.as_str()
|
||||
}
|
||||
|
||||
pub fn os_version(&self) -> Option<&str> {
|
||||
self.os_version.as_deref()
|
||||
}
|
||||
|
||||
pub fn client_version(&self) -> Option<&str> {
|
||||
self.client_version.as_deref()
|
||||
}
|
||||
|
||||
pub(crate) fn to_params(&self) -> HashMap<&str, &str> {
|
||||
let mut params: HashMap<&str, &str> = HashMap::new();
|
||||
let client_os = self.client_os.as_str();
|
||||
|
@@ -23,6 +23,11 @@ pub fn get_non_root_user() -> anyhow::Result<User> {
|
||||
Ok(user)
|
||||
}
|
||||
|
||||
pub fn get_current_user() -> anyhow::Result<User> {
|
||||
let current_user = whoami::username();
|
||||
get_user_by_name(¤t_user)
|
||||
}
|
||||
|
||||
fn get_real_user() -> anyhow::Result<User> {
|
||||
// Read the UID from SUDO_UID or PKEXEC_UID environment variable if available.
|
||||
let uid = match env::var("SUDO_UID") {
|
||||
|
@@ -32,6 +32,8 @@ pub struct ConnectArgs {
|
||||
cookie: String,
|
||||
vpnc_script: Option<String>,
|
||||
user_agent: Option<String>,
|
||||
csd_uid: u32,
|
||||
csd_wrapper: Option<String>,
|
||||
os: Option<ClientOs>,
|
||||
}
|
||||
|
||||
@@ -42,6 +44,8 @@ impl ConnectArgs {
|
||||
vpnc_script: None,
|
||||
user_agent: None,
|
||||
os: None,
|
||||
csd_uid: 0,
|
||||
csd_wrapper: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +64,14 @@ impl ConnectArgs {
|
||||
pub fn openconnect_os(&self) -> Option<String> {
|
||||
self.os.as_ref().map(|os| os.to_openconnect_os().to_string())
|
||||
}
|
||||
|
||||
pub fn csd_uid(&self) -> u32 {
|
||||
self.csd_uid
|
||||
}
|
||||
|
||||
pub fn csd_wrapper(&self) -> Option<String> {
|
||||
self.csd_wrapper.clone()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Type)]
|
||||
@@ -81,6 +93,16 @@ impl ConnectRequest {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_csd_uid(mut self, csd_uid: u32) -> Self {
|
||||
self.args.csd_uid = csd_uid;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_csd_wrapper<T: Into<Option<String>>>(mut self, csd_wrapper: T) -> Self {
|
||||
self.args.csd_wrapper = csd_wrapper.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_user_agent<T: Into<Option<String>>>(mut self, user_agent: T) -> Self {
|
||||
self.args.user_agent = user_agent.into();
|
||||
self
|
||||
|
Reference in New Issue
Block a user