mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-05-20 07:26:58 -04:00
Support connect gateway (#306)
This commit is contained in:
@@ -1,16 +1,24 @@
|
||||
use anyhow::bail;
|
||||
use log::info;
|
||||
use reqwest::Client;
|
||||
use roxmltree::Document;
|
||||
use urlencoding::encode;
|
||||
|
||||
use crate::{credential::Credential, gp_params::GpParams};
|
||||
use crate::{
|
||||
credential::Credential,
|
||||
gp_params::GpParams,
|
||||
utils::{normalize_server, remove_url_scheme},
|
||||
};
|
||||
|
||||
pub async fn gateway_login(
|
||||
gateway: &str,
|
||||
cred: &Credential,
|
||||
gp_params: &GpParams,
|
||||
) -> anyhow::Result<String> {
|
||||
let login_url = format!("https://{}/ssl-vpn/login.esp", gateway);
|
||||
let url = normalize_server(gateway)?;
|
||||
let gateway = remove_url_scheme(&url);
|
||||
|
||||
let login_url = format!("{}/ssl-vpn/login.esp", url);
|
||||
let client = Client::builder()
|
||||
.danger_accept_invalid_certs(gp_params.ignore_tls_errors())
|
||||
.user_agent(gp_params.user_agent())
|
||||
@@ -20,13 +28,18 @@ pub async fn gateway_login(
|
||||
let extra_params = gp_params.to_params();
|
||||
|
||||
params.extend(extra_params);
|
||||
params.insert("server", gateway);
|
||||
params.insert("server", &gateway);
|
||||
|
||||
info!("Gateway login, user_agent: {}", gp_params.user_agent());
|
||||
|
||||
let res = client.post(&login_url).form(¶ms).send().await?;
|
||||
let res_xml = res.error_for_status()?.text().await?;
|
||||
let status = res.status();
|
||||
|
||||
if status.is_client_error() || status.is_server_error() {
|
||||
bail!("Gateway login error: {}", status)
|
||||
}
|
||||
|
||||
let res_xml = res.text().await?;
|
||||
let doc = Document::parse(&res_xml)?;
|
||||
|
||||
build_gateway_token(&doc, gp_params.computer())
|
||||
|
@@ -31,6 +31,15 @@ impl Display for Gateway {
|
||||
}
|
||||
|
||||
impl Gateway {
|
||||
pub fn new(name: String, address: String) -> Self {
|
||||
Self {
|
||||
name,
|
||||
address,
|
||||
priority: 0,
|
||||
priority_rules: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &str {
|
||||
&self.name
|
||||
}
|
||||
|
Reference in New Issue
Block a user