mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-18 22:16:18 -05:00
refactor: update session extension flow
This commit is contained in:
19 files changed
+927
-419
No files matched your search
@@ -1,5 +1,4 @@
|
||||
pub mod event;
|
||||
pub mod request;
|
||||
pub mod session;
|
||||
pub mod vpn_env;
|
||||
pub mod vpn_state;
|
||||
@@ -1,127 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use specta::Type;
|
||||
|
||||
use crate::gp_params::ClientOs;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Type)]
|
||||
pub struct SessionWarning {
|
||||
pub prior_secs: u32,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Type)]
|
||||
pub struct SessionRequestArgs {
|
||||
cookie: String,
|
||||
user_agent: Option<String>,
|
||||
os: Option<ClientOs>,
|
||||
os_version: Option<String>,
|
||||
client_version: Option<String>,
|
||||
certificate: Option<String>,
|
||||
sslkey: Option<String>,
|
||||
key_password: Option<String>,
|
||||
disable_ipv6: bool,
|
||||
}
|
||||
|
||||
impl SessionRequestArgs {
|
||||
pub fn new(cookie: String) -> Self {
|
||||
Self {
|
||||
cookie,
|
||||
user_agent: None,
|
||||
os: None,
|
||||
os_version: None,
|
||||
client_version: None,
|
||||
certificate: None,
|
||||
sslkey: None,
|
||||
key_password: None,
|
||||
disable_ipv6: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_user_agent<T: Into<Option<String>>>(mut self, user_agent: T) -> Self {
|
||||
self.user_agent = user_agent.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_os<T: Into<Option<ClientOs>>>(mut self, os: T) -> Self {
|
||||
self.os = os.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_os_version<T: Into<Option<String>>>(mut self, os_version: T) -> Self {
|
||||
self.os_version = os_version.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_client_version<T: Into<Option<String>>>(mut self, client_version: T) -> Self {
|
||||
self.client_version = client_version.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_certificate<T: Into<Option<String>>>(mut self, certificate: T) -> Self {
|
||||
self.certificate = certificate.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_sslkey<T: Into<Option<String>>>(mut self, sslkey: T) -> Self {
|
||||
self.sslkey = sslkey.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_key_password<T: Into<Option<String>>>(mut self, key_password: T) -> Self {
|
||||
self.key_password = key_password.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_disable_ipv6(mut self, disable_ipv6: bool) -> Self {
|
||||
self.disable_ipv6 = disable_ipv6;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn cookie(&self) -> &str {
|
||||
&self.cookie
|
||||
}
|
||||
|
||||
pub fn user_agent(&self) -> Option<String> {
|
||||
self.user_agent.clone()
|
||||
}
|
||||
|
||||
pub fn os(&self) -> Option<ClientOs> {
|
||||
self.os.clone()
|
||||
}
|
||||
|
||||
pub fn os_version(&self) -> Option<String> {
|
||||
self.os_version.clone()
|
||||
}
|
||||
|
||||
pub fn client_version(&self) -> Option<String> {
|
||||
self.client_version.clone()
|
||||
}
|
||||
|
||||
pub fn certificate(&self) -> Option<String> {
|
||||
self.certificate.clone()
|
||||
}
|
||||
|
||||
pub fn sslkey(&self) -> Option<String> {
|
||||
self.sslkey.clone()
|
||||
}
|
||||
|
||||
pub fn key_password(&self) -> Option<String> {
|
||||
self.key_password.clone()
|
||||
}
|
||||
|
||||
pub fn disable_ipv6(&self) -> bool {
|
||||
self.disable_ipv6
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize, Type)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SessionInfo {
|
||||
pub lifetime_secs: Option<u32>,
|
||||
pub user_expires: Option<u32>,
|
||||
pub expires_in_human: Option<String>,
|
||||
pub lifetime_warning: Option<SessionWarning>,
|
||||
pub inactivity_warning: Option<SessionWarning>,
|
||||
pub admin_logout_message: Option<String>,
|
||||
pub allow_extend_session: bool,
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use specta::Type;
|
||||
|
||||
use crate::gateway::Gateway;
|
||||
use crate::{gateway::Gateway, session::SessionInfo};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Type, Clone)]
|
||||
pub struct ConnectInfo {
|
||||
@@ -10,6 +10,30 @@ pub struct ConnectInfo {
|
||||
gateways: Vec<Gateway>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Type, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ConnectedInfo {
|
||||
info: Box<ConnectInfo>,
|
||||
session_info: Option<SessionInfo>,
|
||||
}
|
||||
|
||||
impl ConnectedInfo {
|
||||
pub fn new(info: ConnectInfo, session_info: Option<SessionInfo>) -> Self {
|
||||
Self {
|
||||
info: Box::new(info),
|
||||
session_info,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn info(&self) -> &ConnectInfo {
|
||||
&self.info
|
||||
}
|
||||
|
||||
pub fn session_info(&self) -> Option<&SessionInfo> {
|
||||
self.session_info.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl ConnectInfo {
|
||||
pub fn new(portal: String, gateway: Gateway, gateways: Vec<Gateway>) -> Self {
|
||||
Self {
|
||||
@@ -29,6 +53,31 @@ impl ConnectInfo {
|
||||
pub enum VpnState {
|
||||
Disconnected,
|
||||
Connecting(Box<ConnectInfo>),
|
||||
Connected(Box<ConnectInfo>),
|
||||
Connected(Box<ConnectedInfo>),
|
||||
Disconnecting,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn connected_state_serializes_session_info() {
|
||||
let gateway = Gateway::new("vpn".to_string(), "vpn.example.com".to_string());
|
||||
let connect_info = ConnectInfo::new("portal.example.com".to_string(), gateway.clone(), vec![gateway]);
|
||||
let session_info = SessionInfo {
|
||||
lifetime_secs: Some(43_200),
|
||||
allow_extend_session: true,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let value = serde_json::to_value(VpnState::Connected(Box::new(ConnectedInfo::new(
|
||||
connect_info,
|
||||
Some(session_info),
|
||||
))))
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(value["connected"]["sessionInfo"]["lifetimeSecs"], 43_200);
|
||||
assert_eq!(value["connected"]["sessionInfo"]["allowExtendSession"], true);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user