feat: integrate common crate and add constants for user agent and lock files

This commit is contained in:
Kevin Yue committed 2025-11-12 23:35:43 +08:00
1 parent cad5ca3d68
commit 7048248268
26 files changed
+66 -54

No files matched your search

Generated
+5 -4
View File
@@ -165,6 +165,7 @@ version = "2.4.6"
dependencies = [
"anyhow",
"block2 0.6.2",
"common",
"gpapi",
"html-escape",
"log",
@@ -584,9 +585,6 @@ dependencies = [
[[package]]
name = "common"
version = "2.4.6"
dependencies = [
"is_executable",
]
[[package]]
name = "compile-time"
@@ -1602,6 +1600,7 @@ dependencies = [
"chacha20poly1305",
"clap",
"clap-verbosity-flag",
"common",
"dns-lookup",
"env_logger",
"gtk",
@@ -1637,6 +1636,7 @@ dependencies = [
"anyhow",
"auth",
"clap",
"common",
"compile-time",
"env_logger",
"gpapi",
@@ -1696,6 +1696,7 @@ dependencies = [
"anyhow",
"axum",
"clap",
"common",
"compile-time",
"env_logger",
"futures",
@@ -2986,7 +2987,7 @@ name = "openconnect"
version = "2.4.6"
dependencies = [
"cc",
"common",
"is_executable",
"log",
]
+1
View File
@@ -10,6 +10,7 @@ license.workspace = true
tauri-build = { version = "2", features = [], optional = true }
[dependencies]
common = { path = "../../crates/common" }
gpapi = { path = "../../crates/gpapi", features = ["clap"] }
auth = { path = "../../crates/auth", features = ["browser-auth"] }
+1 -1
View File
@@ -1,11 +1,11 @@
use auth::{auth_prelogin, BrowserAuthenticator};
use clap::Parser;
use common::constants::GP_USER_AGENT;
use gpapi::{
auth::{SamlAuthData, SamlAuthResult},
clap::{args::Os, handle_error, Args, InfoLevelVerbosity},
gp_params::{ClientOs, GpParams},
utils::{normalize_server, openssl},
GP_USER_AGENT,
};
use log::info;
use serde_json::json;
+1 -2
View File
@@ -2,7 +2,7 @@ use std::{cell::RefCell, fs, sync::Arc};
use anyhow::bail;
use clap::Args;
use common::vpn_utils::find_csd_wrapper;
use common::constants::GP_USER_AGENT;
use gpapi::{
auth::SamlAuthResult,
clap::{args::Os, ToVerboseArg},
@@ -16,7 +16,6 @@ use gpapi::{
users::{get_non_root_user, get_user_by_name},
},
utils::{request::RequestIdentityError, shutdown_signal},
GP_USER_AGENT,
};
use inquire::{Password, PasswordDisplayMode, Select, Text};
use log::{info, warn};
+1 -1
View File
@@ -1,11 +1,11 @@
use std::{collections::HashMap, env::temp_dir, fs, path::PathBuf};
use clap::Args;
use common::constants::GP_CALLBACK_PORT_FILENAME;
use directories::ProjectDirs;
use gpapi::{
process::service_launcher::ServiceLauncher,
utils::{endpoint::http_endpoint, env_utils, shutdown_signal},
GP_CALLBACK_PORT_FILENAME,
};
use log::info;
use tokio::io::AsyncWriteExt;
+1
View File
@@ -5,6 +5,7 @@ edition.workspace = true
license.workspace = true
[dependencies]
common = { path = "../../crates/common" }
gpapi = { path = "../../crates/gpapi", features = ["clap", "logger"] }
openconnect = { path = "../../crates/openconnect" }
clap.workspace = true
+1 -1
View File
@@ -3,13 +3,13 @@ use std::{collections::HashMap, io::Write};
use anyhow::bail;
use clap::Parser;
use common::constants::GP_SERVICE_LOCK_FILE;
use gpapi::clap::InfoLevelVerbosity;
use gpapi::logger;
use gpapi::{
process::gui_launcher::GuiLauncher,
service::{request::WsRequest, vpn_state::VpnState},
utils::{crypto::generate_key, env_utils, lock_file::LockFile, redact::Redaction, shutdown_signal},
GP_SERVICE_LOCK_FILE,
};
use log::{info, warn};
use tokio::sync::{mpsc, watch};
+1 -1
View File
@@ -17,11 +17,11 @@ use axum::{
http::StatusCode,
response::IntoResponse,
};
use common::constants::GP_GUI_BINARY;
use futures::{SinkExt, StreamExt};
use gpapi::{
service::{event::WsEvent, request::UpdateGuiRequest},
utils::checksum::verify_checksum,
GP_GUI_BINARY,
};
use log::{info, warn};
use tar::Archive;
+1
View File
@@ -8,6 +8,7 @@ edition.workspace = true
license.workspace = true
[dependencies]
common = { path = "../common" }
gpapi = { path = "../gpapi" }
# Shared dependencies
+2 -1
View File
@@ -1,6 +1,7 @@
use std::{env::temp_dir, fs, os::unix::fs::PermissionsExt};
use gpapi::{auth::SamlAuthData, GP_CALLBACK_PORT_FILENAME};
use common::constants::GP_CALLBACK_PORT_FILENAME;
use gpapi::auth::SamlAuthData;
use log::info;
use tokio::{
io::AsyncReadExt,
-3
View File
@@ -6,6 +6,3 @@ authors.workspace = true
homepage.workspace = true
edition.workspace = true
license.workspace = true
[dependencies]
is_executable.workspace = true
@@ -14,6 +14,9 @@ fn main() {
println!("cargo:rustc-env=GP_SERVICE_BINARY={}", gp_service_binary.display());
println!("cargo:rustc-env=GP_CLIENT_BINARY={}", gp_client_binary.display());
println!("cargo:rustc-env=GP_AUTH_BINARY={}", gp_auth_binary.display());
println!("cargo:rustc-env=GP_GUI_HELPER_BINARY={}", gp_gui_helper_binary.display());
println!(
"cargo:rustc-env=GP_GUI_HELPER_BINARY={}",
gp_gui_helper_binary.display()
);
println!("cargo:rustc-env=GP_GUI_BINARY={}", gp_gui_binary.display());
}
+27
View File
@@ -0,0 +1,27 @@
pub const GP_USER_AGENT: &str = "PAN GlobalProtect";
pub const GP_SERVICE_LOCK_FILE: &str = "/var/run/gpservice.lock";
pub const GP_CALLBACK_PORT_FILENAME: &str = "gpcallback.port";
// Release binaries are hardcoded paths
#[cfg(not(debug_assertions))]
pub const GP_CLIENT_BINARY: &str = "/usr/bin/gpclient";
#[cfg(not(debug_assertions))]
pub const GP_SERVICE_BINARY: &str = "/usr/bin/gpservice";
#[cfg(not(debug_assertions))]
pub const GP_GUI_BINARY: &str = "/usr/bin/gpgui";
#[cfg(not(debug_assertions))]
pub const GP_GUI_HELPER_BINARY: &str = "/usr/bin/gpgui-helper";
#[cfg(not(debug_assertions))]
pub const GP_AUTH_BINARY: &str = "/usr/bin/gpauth";
// Debug binaries are set in build.rs via environment variables
#[cfg(debug_assertions)]
pub const GP_CLIENT_BINARY: &str = env!("GP_CLIENT_BINARY");
#[cfg(debug_assertions)]
pub const GP_SERVICE_BINARY: &str = env!("GP_SERVICE_BINARY");
#[cfg(debug_assertions)]
pub const GP_GUI_BINARY: &str = env!("GP_GUI_BINARY");
#[cfg(debug_assertions)]
pub const GP_GUI_HELPER_BINARY: &str = env!("GP_GUI_HELPER_BINARY");
#[cfg(debug_assertions)]
pub const GP_AUTH_BINARY: &str = env!("GP_AUTH_BINARY");
+1 -1
View File
@@ -1 +1 @@
pub mod vpn_utils;
pub mod constants;
+1
View File
@@ -6,6 +6,7 @@ edition.workspace = true
license = "MIT"
[dependencies]
common = { path = "../common" }
anyhow.workspace = true
base64.workspace = true
dns-lookup.workspace = true
+2 -1
View File
@@ -1,11 +1,12 @@
use std::collections::HashMap;
use common::constants::GP_USER_AGENT;
use log::info;
use reqwest::Client;
use serde::{Deserialize, Serialize};
use specta::Type;
use crate::{utils::request::create_identity, GP_USER_AGENT};
use crate::utils::request::create_identity;
#[derive(Debug, Serialize, Deserialize, Clone, Type, Default)]
pub enum ClientOs {
-26
View File
@@ -16,29 +16,3 @@ pub mod clap;
#[cfg(debug_assertions)]
pub const GP_API_KEY: &[u8; 32] = &[0; 32];
pub const GP_USER_AGENT: &str = "PAN GlobalProtect";
pub const GP_SERVICE_LOCK_FILE: &str = "/var/run/gpservice.lock";
pub const GP_CALLBACK_PORT_FILENAME: &str = "gpcallback.port";
#[cfg(not(debug_assertions))]
pub const GP_CLIENT_BINARY: &str = "/usr/bin/gpclient";
#[cfg(not(debug_assertions))]
pub const GP_SERVICE_BINARY: &str = "/usr/bin/gpservice";
#[cfg(not(debug_assertions))]
pub const GP_GUI_BINARY: &str = "/usr/bin/gpgui";
#[cfg(not(debug_assertions))]
pub const GP_GUI_HELPER_BINARY: &str = "/usr/bin/gpgui-helper";
#[cfg(not(debug_assertions))]
pub(crate) const GP_AUTH_BINARY: &str = "/usr/bin/gpauth";
#[cfg(debug_assertions)]
pub const GP_CLIENT_BINARY: &str = env!("GP_CLIENT_BINARY");
#[cfg(debug_assertions)]
pub const GP_SERVICE_BINARY: &str = env!("GP_SERVICE_BINARY");
#[cfg(debug_assertions)]
pub const GP_GUI_BINARY: &str = env!("GP_GUI_BINARY");
#[cfg(debug_assertions)]
pub const GP_GUI_HELPER_BINARY: &str = env!("GP_GUI_HELPER_BINARY");
#[cfg(debug_assertions)]
pub(crate) const GP_AUTH_BINARY: &str = env!("GP_AUTH_BINARY");
+2 -1
View File
@@ -1,9 +1,10 @@
use std::process::Stdio;
use anyhow::bail;
use common::constants::GP_AUTH_BINARY;
use tokio::process::Command;
use crate::{auth::SamlAuthResult, credential::Credential, GP_AUTH_BINARY};
use crate::{auth::SamlAuthResult, credential::Credential};
use super::command_traits::CommandExt;
@@ -1,10 +1,11 @@
use std::{collections::HashMap, path::PathBuf, process::Stdio};
use anyhow::bail;
use common::constants::GP_GUI_HELPER_BINARY;
use log::info;
use tokio::{io::AsyncWriteExt, process::Command};
use crate::{process::command_traits::CommandExt, utils, GP_GUI_HELPER_BINARY};
use crate::{process::command_traits::CommandExt, utils};
pub struct GuiHelperLauncher<'a> {
program: PathBuf,
+2 -1
View File
@@ -5,10 +5,11 @@ use std::{
};
use anyhow::bail;
use common::constants::GP_GUI_BINARY;
use log::info;
use tokio::{io::AsyncWriteExt, process::Command};
use crate::{process::gui_helper_launcher::GuiHelperLauncher, utils::base64, GP_GUI_BINARY};
use crate::{process::gui_helper_launcher::GuiHelperLauncher, utils::base64};
use super::command_traits::CommandExt;
+3 -4
View File
@@ -4,10 +4,9 @@ use std::{
process::{ExitStatus, Stdio},
};
use common::constants::GP_SERVICE_BINARY;
use tokio::process::Command;
use crate::GP_SERVICE_BINARY;
use super::command_traits::CommandExt;
pub struct ServiceLauncher<'a> {
@@ -15,7 +14,7 @@ pub struct ServiceLauncher<'a> {
minimized: bool,
env_file: Option<String>,
log_file: Option<String>,
verbose: Option<&'a str>
verbose: Option<&'a str>,
}
impl Default for ServiceLauncher<'_> {
@@ -31,7 +30,7 @@ impl<'a> ServiceLauncher<'a> {
minimized: false,
env_file: None,
log_file: None,
verbose: None
verbose: None,
}
}
+2 -1
View File
@@ -1,5 +1,6 @@
use std::path::PathBuf;
use common::constants::GP_SERVICE_LOCK_FILE;
use thiserror::Error;
use tokio::fs;
@@ -94,7 +95,7 @@ impl LockInfo {
}
pub async fn gpservice_lock_info() -> Result<LockInfo, LockFileError> {
LockInfo::from_file(crate::GP_SERVICE_LOCK_FILE).await
LockInfo::from_file(GP_SERVICE_LOCK_FILE).await
}
#[cfg(test)]
+1 -1
View File
@@ -6,8 +6,8 @@ license.workspace = true
links = "openconnect"
[dependencies]
common = { path = "../common" }
log.workspace = true
is_executable.workspace = true
[build-dependencies]
cc = "1"
+2
View File
@@ -1,4 +1,6 @@
mod ffi;
mod vpn;
mod vpn_utils;
pub use vpn::*;
pub use vpn_utils::*;
+1 -1
View File
@@ -4,10 +4,10 @@ use std::{
sync::{Arc, RwLock},
};
use common::vpn_utils::{check_executable, find_vpnc_script};
use log::info;
use crate::ffi;
use crate::vpn_utils::{check_executable, find_csd_wrapper, find_vpnc_script};
type OnConnectedCallback = Arc<RwLock<Option<Box<dyn FnOnce() + 'static + Send + Sync>>>>;
@@ -48,7 +48,7 @@ pub fn find_csd_wrapper() -> Option<String> {
pub fn check_executable(file: &str) -> Result<(), io::Error> {
let path = Path::new(file);
if path.exists() && !path.is_executable() {
if !path.is_executable() {
return Err(io::Error::new(
io::ErrorKind::PermissionDenied,
format!("{} is not executable", file),