mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-04-02 18:31:50 -04:00
Add the --hip option
This commit is contained in:
parent
cff2ff9dbe
commit
558485f5a9
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1486,6 +1486,7 @@ version = "2.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"clap",
|
"clap",
|
||||||
|
"common",
|
||||||
"compile-time",
|
"compile-time",
|
||||||
"directories",
|
"directories",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
|
@ -6,6 +6,7 @@ edition.workspace = true
|
|||||||
license.workspace = true
|
license.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
common = { path = "../../crates/common" }
|
||||||
gpapi = { path = "../../crates/gpapi", features = ["clap"] }
|
gpapi = { path = "../../crates/gpapi", features = ["clap"] }
|
||||||
openconnect = { path = "../../crates/openconnect" }
|
openconnect = { path = "../../crates/openconnect" }
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use std::{fs, sync::Arc};
|
use std::{fs, sync::Arc};
|
||||||
|
|
||||||
use clap::Args;
|
use clap::Args;
|
||||||
|
use common::vpn_utils::find_csd_wrapper;
|
||||||
use gpapi::{
|
use gpapi::{
|
||||||
clap::args::Os,
|
clap::args::Os,
|
||||||
credential::{Credential, PasswordCredential},
|
credential::{Credential, PasswordCredential},
|
||||||
@ -31,6 +32,12 @@ pub(crate) struct ConnectArgs {
|
|||||||
#[arg(long, short, help = "The VPNC script to use")]
|
#[arg(long, short, help = "The VPNC script to use")]
|
||||||
script: Option<String>,
|
script: Option<String>,
|
||||||
|
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
help = "Use the default CSD wrapper to generate the HIP report and send it to the server"
|
||||||
|
)]
|
||||||
|
hip: bool,
|
||||||
|
|
||||||
#[arg(long, help = "Same as the '--csd-user' option in the openconnect command")]
|
#[arg(long, help = "Same as the '--csd-user' option in the openconnect command")]
|
||||||
csd_user: Option<String>,
|
csd_user: Option<String>,
|
||||||
|
|
||||||
@ -112,16 +119,19 @@ impl<'a> ConnectHandler<'a> {
|
|||||||
let selected_gateway = match &self.args.gateway {
|
let selected_gateway = match &self.args.gateway {
|
||||||
Some(gateway) => portal_config
|
Some(gateway) => portal_config
|
||||||
.find_gateway(gateway)
|
.find_gateway(gateway)
|
||||||
.ok_or_else(|| anyhow::anyhow!("Cannot find gateway {}", gateway))?,
|
.ok_or_else(|| anyhow::anyhow!("Cannot find gateway specified: {}", gateway))?,
|
||||||
None => {
|
None => {
|
||||||
portal_config.sort_gateways(prelogin.region());
|
portal_config.sort_gateways(prelogin.region());
|
||||||
let gateways = portal_config.gateways();
|
let gateways = portal_config.gateways();
|
||||||
|
|
||||||
if gateways.len() > 1 {
|
if gateways.len() > 1 {
|
||||||
Select::new("Which gateway do you want to connect to?", gateways)
|
let gateway = Select::new("Which gateway do you want to connect to?", gateways)
|
||||||
.with_vim_mode(true)
|
.with_vim_mode(true)
|
||||||
.prompt()?
|
.prompt()?;
|
||||||
|
info!("Connecting to the selected gateway: {}", gateway);
|
||||||
|
gateway
|
||||||
} else {
|
} else {
|
||||||
|
info!("Connecting to the only available gateway: {}", gateways[0]);
|
||||||
gateways[0]
|
gateways[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -154,14 +164,21 @@ impl<'a> ConnectHandler<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn connect_gateway(&self, gateway: &str, cookie: &str) -> anyhow::Result<()> {
|
async fn connect_gateway(&self, gateway: &str, cookie: &str) -> anyhow::Result<()> {
|
||||||
let csd_uid = get_csd_uid(&self.args.csd_user)?;
|
|
||||||
let mtu = self.args.mtu.unwrap_or(0);
|
let mtu = self.args.mtu.unwrap_or(0);
|
||||||
|
let csd_uid = get_csd_uid(&self.args.csd_user)?;
|
||||||
|
let csd_wrapper = if self.args.csd_user.is_some() {
|
||||||
|
self.args.csd_wrapper.clone()
|
||||||
|
} else if self.args.hip {
|
||||||
|
find_csd_wrapper()
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
let vpn = Vpn::builder(gateway, cookie)
|
let vpn = Vpn::builder(gateway, cookie)
|
||||||
.script(self.args.script.clone())
|
.script(self.args.script.clone())
|
||||||
.user_agent(self.args.user_agent.clone())
|
.user_agent(self.args.user_agent.clone())
|
||||||
.csd_uid(csd_uid)
|
.csd_uid(csd_uid)
|
||||||
.csd_wrapper(self.args.csd_wrapper.clone())
|
.csd_wrapper(csd_wrapper)
|
||||||
.mtu(mtu)
|
.mtu(mtu)
|
||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user