mirror of
https://github.com/house-of-vanity/khm.git
synced 2025-08-21 14:27:14 +00:00
Fix GUI feature declaration
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -2672,7 +2672,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "khm"
|
name = "khm"
|
||||||
version = "0.6.3"
|
version = "0.7.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"base64 0.21.7",
|
"base64 0.21.7",
|
||||||
|
@@ -1,5 +1,9 @@
|
|||||||
|
#[cfg(feature = "gui")]
|
||||||
mod state;
|
mod state;
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
mod ui;
|
mod ui;
|
||||||
|
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
pub use state::*;
|
pub use state::*;
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
pub use ui::*;
|
pub use ui::*;
|
||||||
|
@@ -12,6 +12,7 @@ pub struct SshKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Test connection to KHM server
|
/// Test connection to KHM server
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
pub async fn test_connection(
|
pub async fn test_connection(
|
||||||
host: String,
|
host: String,
|
||||||
flow: String,
|
flow: String,
|
||||||
@@ -52,6 +53,7 @@ pub async fn test_connection(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch all SSH keys including deprecated ones
|
/// Fetch all SSH keys including deprecated ones
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
pub async fn fetch_keys(
|
pub async fn fetch_keys(
|
||||||
host: String,
|
host: String,
|
||||||
flow: String,
|
flow: String,
|
||||||
@@ -95,6 +97,7 @@ pub async fn fetch_keys(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Deprecate a key for a specific server
|
/// Deprecate a key for a specific server
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
pub async fn deprecate_key(
|
pub async fn deprecate_key(
|
||||||
host: String,
|
host: String,
|
||||||
flow: String,
|
flow: String,
|
||||||
@@ -133,6 +136,7 @@ pub async fn deprecate_key(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Restore a key for a specific server
|
/// Restore a key for a specific server
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
pub async fn restore_key(
|
pub async fn restore_key(
|
||||||
host: String,
|
host: String,
|
||||||
flow: String,
|
flow: String,
|
||||||
@@ -171,6 +175,7 @@ pub async fn restore_key(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Delete a key permanently for a specific server
|
/// Delete a key permanently for a specific server
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
pub async fn delete_key(
|
pub async fn delete_key(
|
||||||
host: String,
|
host: String,
|
||||||
flow: String,
|
flow: String,
|
||||||
@@ -212,6 +217,7 @@ pub async fn delete_key(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Bulk deprecate multiple servers
|
/// Bulk deprecate multiple servers
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
pub async fn bulk_deprecate_servers(
|
pub async fn bulk_deprecate_servers(
|
||||||
host: String,
|
host: String,
|
||||||
flow: String,
|
flow: String,
|
||||||
@@ -244,6 +250,7 @@ pub async fn bulk_deprecate_servers(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Bulk restore multiple servers
|
/// Bulk restore multiple servers
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
pub async fn bulk_restore_servers(
|
pub async fn bulk_restore_servers(
|
||||||
host: String,
|
host: String,
|
||||||
flow: String,
|
flow: String,
|
||||||
@@ -276,6 +283,7 @@ pub async fn bulk_restore_servers(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Perform manual sync operation
|
/// Perform manual sync operation
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
pub async fn perform_manual_sync(settings: KhmSettings) -> Result<String, String> {
|
pub async fn perform_manual_sync(settings: KhmSettings) -> Result<String, String> {
|
||||||
match perform_sync(&settings).await {
|
match perform_sync(&settings).await {
|
||||||
Ok(keys_count) => Ok(format!(
|
Ok(keys_count) => Ok(format!(
|
||||||
@@ -288,6 +296,7 @@ pub async fn perform_manual_sync(settings: KhmSettings) -> Result<String, String
|
|||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
|
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
fn create_http_client() -> Result<Client, String> {
|
fn create_http_client() -> Result<Client, String> {
|
||||||
Client::builder()
|
Client::builder()
|
||||||
.timeout(std::time::Duration::from_secs(30))
|
.timeout(std::time::Duration::from_secs(30))
|
||||||
@@ -296,6 +305,7 @@ fn create_http_client() -> Result<Client, String> {
|
|||||||
.map_err(|e| format!("Failed to create HTTP client: {}", e))
|
.map_err(|e| format!("Failed to create HTTP client: {}", e))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
fn add_auth_if_needed(
|
fn add_auth_if_needed(
|
||||||
request: reqwest::RequestBuilder,
|
request: reqwest::RequestBuilder,
|
||||||
basic_auth: &str,
|
basic_auth: &str,
|
||||||
@@ -312,6 +322,7 @@ fn add_auth_if_needed(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
fn check_response_status(response: &reqwest::Response) -> Result<(), String> {
|
fn check_response_status(response: &reqwest::Response) -> Result<(), String> {
|
||||||
let status = response.status().as_u16();
|
let status = response.status().as_u16();
|
||||||
|
|
||||||
@@ -336,6 +347,7 @@ fn check_response_status(response: &reqwest::Response) -> Result<(), String> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
fn check_html_response(body: &str) -> Result<(), String> {
|
fn check_html_response(body: &str) -> Result<(), String> {
|
||||||
if body.trim_start().starts_with("<!DOCTYPE") || body.trim_start().starts_with("<html") {
|
if body.trim_start().starts_with("<!DOCTYPE") || body.trim_start().starts_with("<html") {
|
||||||
return Err("Server returned HTML page instead of JSON. This usually means authentication is required or the endpoint is incorrect.".to_string());
|
return Err("Server returned HTML page instead of JSON. This usually means authentication is required or the endpoint is incorrect.".to_string());
|
||||||
@@ -343,6 +355,7 @@ fn check_html_response(body: &str) -> Result<(), String> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
fn parse_api_response(body: &str, default_message: &str) -> Result<String, String> {
|
fn parse_api_response(body: &str, default_message: &str) -> Result<String, String> {
|
||||||
if let Ok(json_response) = serde_json::from_str::<serde_json::Value>(body) {
|
if let Ok(json_response) = serde_json::from_str::<serde_json::Value>(body) {
|
||||||
if let Some(message) = json_response.get("message").and_then(|v| v.as_str()) {
|
if let Some(message) = json_response.get("message").and_then(|v| v.as_str()) {
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
#[cfg(feature = "gui")]
|
||||||
mod client;
|
mod client;
|
||||||
|
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
pub use client::*;
|
pub use client::*;
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
#[cfg(feature = "gui")]
|
||||||
mod settings;
|
mod settings;
|
||||||
|
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
pub use settings::*;
|
pub use settings::*;
|
||||||
|
@@ -1,9 +1,15 @@
|
|||||||
|
#[cfg(feature = "gui")]
|
||||||
use dirs::home_dir;
|
use dirs::home_dir;
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
use log::{debug, error, info};
|
use log::{debug, error, info};
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct KhmSettings {
|
pub struct KhmSettings {
|
||||||
pub host: String,
|
pub host: String,
|
||||||
@@ -14,6 +20,7 @@ pub struct KhmSettings {
|
|||||||
pub auto_sync_interval_minutes: u32,
|
pub auto_sync_interval_minutes: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
impl Default for KhmSettings {
|
impl Default for KhmSettings {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
@@ -28,6 +35,7 @@ impl Default for KhmSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get default known_hosts file path based on OS
|
/// Get default known_hosts file path based on OS
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
fn get_default_known_hosts_path() -> String {
|
fn get_default_known_hosts_path() -> String {
|
||||||
if let Some(home) = home_dir() {
|
if let Some(home) = home_dir() {
|
||||||
let ssh_dir = home.join(".ssh");
|
let ssh_dir = home.join(".ssh");
|
||||||
@@ -39,6 +47,7 @@ fn get_default_known_hosts_path() -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get configuration file path
|
/// Get configuration file path
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
pub fn get_config_path() -> PathBuf {
|
pub fn get_config_path() -> PathBuf {
|
||||||
let mut path = home_dir().expect("Could not find home directory");
|
let mut path = home_dir().expect("Could not find home directory");
|
||||||
path.push(".khm");
|
path.push(".khm");
|
||||||
@@ -48,6 +57,7 @@ pub fn get_config_path() -> PathBuf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Load settings from configuration file
|
/// Load settings from configuration file
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
pub fn load_settings() -> KhmSettings {
|
pub fn load_settings() -> KhmSettings {
|
||||||
let path = get_config_path();
|
let path = get_config_path();
|
||||||
match fs::read_to_string(&path) {
|
match fs::read_to_string(&path) {
|
||||||
@@ -72,6 +82,7 @@ pub fn load_settings() -> KhmSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Save settings to configuration file
|
/// Save settings to configuration file
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
pub fn save_settings(settings: &KhmSettings) -> Result<(), std::io::Error> {
|
pub fn save_settings(settings: &KhmSettings) -> Result<(), std::io::Error> {
|
||||||
let path = get_config_path();
|
let path = get_config_path();
|
||||||
let json = serde_json::to_string_pretty(settings)?;
|
let json = serde_json::to_string_pretty(settings)?;
|
||||||
@@ -81,6 +92,7 @@ pub fn save_settings(settings: &KhmSettings) -> Result<(), std::io::Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Expand path with ~ substitution
|
/// Expand path with ~ substitution
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
pub fn expand_path(path: &str) -> String {
|
pub fn expand_path(path: &str) -> String {
|
||||||
if path.starts_with("~/") {
|
if path.starts_with("~/") {
|
||||||
if let Some(home) = home_dir() {
|
if let Some(home) = home_dir() {
|
||||||
@@ -91,6 +103,7 @@ pub fn expand_path(path: &str) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Perform sync operation using KHM client logic
|
/// Perform sync operation using KHM client logic
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
pub async fn perform_sync(settings: &KhmSettings) -> Result<usize, std::io::Error> {
|
pub async fn perform_sync(settings: &KhmSettings) -> Result<usize, std::io::Error> {
|
||||||
use crate::Args;
|
use crate::Args;
|
||||||
|
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
|
#[cfg(feature = "gui")]
|
||||||
use log::info;
|
use log::info;
|
||||||
|
|
||||||
// Modules
|
// Modules
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
mod admin;
|
mod admin;
|
||||||
mod api;
|
mod api;
|
||||||
mod common;
|
mod common;
|
||||||
|
Reference in New Issue
Block a user