mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-19 06:26:14 -05:00
feat: add VpnEnv struct and update WsEvent to include VPN environment details
This commit is contained in:
4 files changed
+37
-5
No files matched your search
@@ -1,11 +1,13 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use axum::extract::ws::Message;
|
use axum::extract::ws::Message;
|
||||||
|
use common::constants::GP_AUTH_BINARY;
|
||||||
use gpapi::{
|
use gpapi::{
|
||||||
service::{event::WsEvent, request::WsRequest, vpn_state::VpnState},
|
service::{event::WsEvent, request::WsRequest, vpn_env::VpnEnv, vpn_state::VpnState},
|
||||||
utils::{crypto::Crypto, lock_file::LockFile, redact::Redaction},
|
utils::{crypto::Crypto, lock_file::LockFile, redact::Redaction},
|
||||||
};
|
};
|
||||||
use log::{info, warn};
|
use log::{info, warn};
|
||||||
|
use openconnect::{find_csd_wrapper, find_vpnc_script};
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use tokio::{
|
use tokio::{
|
||||||
net::TcpListener,
|
net::TcpListener,
|
||||||
@@ -56,9 +58,15 @@ impl WsServerContext {
|
|||||||
let conn = Arc::new(WsConnection::new(Arc::clone(&self.crypto), tx));
|
let conn = Arc::new(WsConnection::new(Arc::clone(&self.crypto), tx));
|
||||||
|
|
||||||
// Send current VPN state to new client
|
// Send current VPN state to new client
|
||||||
info!("Sending current VPN state to new client");
|
info!("Sending current environment to new client");
|
||||||
let vpn_state = self.vpn_state_rx.borrow().clone();
|
let vpn_env = VpnEnv {
|
||||||
if let Err(err) = conn.send_event(&WsEvent::VpnState(vpn_state)).await {
|
vpn_state: self.vpn_state_rx.borrow().clone(),
|
||||||
|
vpnc_script: find_vpnc_script(),
|
||||||
|
csd_wrapper: find_csd_wrapper(),
|
||||||
|
auth_executable: GP_AUTH_BINARY.to_owned(),
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Err(err) = conn.send_event(&WsEvent::VpnEnv(vpn_env)).await {
|
||||||
warn!("Failed to send VPN state to new client: {}", err);
|
warn!("Failed to send VPN state to new client: {}", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::vpn_state::VpnState;
|
use crate::service::{vpn_env::VpnEnv, vpn_state::VpnState};
|
||||||
|
|
||||||
/// Events that can be emitted by the service
|
/// Events that can be emitted by the service
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub enum WsEvent {
|
pub enum WsEvent {
|
||||||
|
VpnEnv(VpnEnv),
|
||||||
VpnState(VpnState),
|
VpnState(VpnState),
|
||||||
ActiveGui,
|
ActiveGui,
|
||||||
ResumeConnection,
|
ResumeConnection,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
pub mod event;
|
pub mod event;
|
||||||
pub mod request;
|
pub mod request;
|
||||||
|
pub mod vpn_env;
|
||||||
pub mod vpn_state;
|
pub mod vpn_state;
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::service::vpn_state::VpnState;
|
||||||
|
|
||||||
|
/// Represents the VPN environment configuration.
|
||||||
|
/// When a client connects, the gpservice sends the current VPN environment
|
||||||
|
/// to the client so that it can configure itself accordingly.
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct VpnEnv {
|
||||||
|
/// The VPN connection state
|
||||||
|
pub vpn_state: VpnState,
|
||||||
|
|
||||||
|
/// The default VPN script path
|
||||||
|
pub vpnc_script: Option<String>,
|
||||||
|
|
||||||
|
/// The default CSD wrapper script path
|
||||||
|
pub csd_wrapper: Option<String>,
|
||||||
|
|
||||||
|
/// The gpauth executable path
|
||||||
|
/// Used by the client to launch gpauth for authentication
|
||||||
|
pub auth_executable: String,
|
||||||
|
}
|
||||||
Reference in new issue
Block a user