diff --git a/dnapi-rs/Cargo.toml b/dnapi-rs/Cargo.toml index 9f08a15..c70fae4 100644 --- a/dnapi-rs/Cargo.toml +++ b/dnapi-rs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dnapi-rs" -version = "0.1.8" +version = "0.1.9" edition = "2021" description = "A rust client for the Defined Networking API" license = "AGPL-3.0-or-later" @@ -19,7 +19,7 @@ reqwest = { version = "0.11.16", features = ["blocking", "json"] } url = "2.3.1" base64 = "0.21.0" serde_json = "1.0.95" -trifid-pki = { version = "0.1.6", path = "../trifid-pki", features = ["serde_derive"] } +trifid-pki = { version = "0.1", path = "../trifid-pki", features = ["serde_derive"] } rand = "0.8.5" chrono = "0.4.24" openssl-sys = { version = "0.9.83", features = ["vendored"] } \ No newline at end of file diff --git a/tfclient/Cargo.toml b/tfclient/Cargo.toml index 1166c9b..a4222ea 100644 --- a/tfclient/Cargo.toml +++ b/tfclient/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tfclient" -version = "0.1.6" +version = "0.1.7" edition = "2021" description = "An open-source reimplementation of a Defined Networking-compatible client" license = "GPL-3.0-or-later" @@ -12,7 +12,7 @@ repository = "https://git.e3t.cc/~core/trifid" [dependencies] clap = { version = "4.1.10", features = ["derive"] } -trifid-pki = { version = "0.1.8", path = "../trifid-pki", features = ["serde_derive"] } +trifid-pki = { version = "0.1", path = "../trifid-pki", features = ["serde_derive"] } dirs = "5.0.0" log = "0.4.17" simple_logger = "4.1.0" @@ -28,7 +28,7 @@ base64 = "0.21.0" chrono = "0.4.24" ipnet = "2.7.1" base64-serde = "0.7.0" -dnapi-rs = { version = "0.1.8", path = "../dnapi-rs" } +dnapi-rs = { version = "0.1", path = "../dnapi-rs" } serde_yaml = "0.9.19" openssl-sys = { version = "0.9.83", features = ["vendored"] } diff --git a/tfclient/src/main.rs b/tfclient/src/main.rs index e8848e1..2096293 100644 --- a/tfclient/src/main.rs +++ b/tfclient/src/main.rs @@ -20,7 +20,6 @@ pub mod util; pub mod nebulaworker; pub mod daemon; pub mod config; -pub mod service; pub mod apiworker; pub mod socketworker; pub mod socketclient; @@ -74,37 +73,6 @@ enum Commands { /// Clear any cached data that tfclient may have added ClearCache {}, - /// Install the tfclient system service - Install { - #[clap(short, long, default_value = "tfclient")] - /// Optional service name used to run multiple tfclient instances. Specify the same name on all other cli sub-commands (start, uninstall, etc.) to refer to this installed instance - name: String, - #[clap(short, long)] - /// Server to use for API calls. - server: String - }, - - /// Uninstall the tfclient system service - Uninstall { - #[clap(short, long, default_value = "tfclient")] - /// Service name specified on install - name: String - }, - - /// Start the tfclient system service - Start { - #[clap(short, long, default_value = "tfclient")] - /// Service name specified on install - name: String - }, - - /// Stop the tfclient system service - Stop { - #[clap(short, long, default_value = "tfclient")] - /// Service name specified on start - name: String - }, - /// Run the tfclient daemon in the foreground Run { #[clap(short, long, default_value = "tfclient")] @@ -223,18 +191,6 @@ fn main() { } } } - Commands::Install { server, name } => { - cli_install(&name, &server); - } - Commands::Uninstall { name } => { - cli_uninstall(&name); - } - Commands::Start { name } => { - cli_start(&name); - } - Commands::Stop { name } => { - cli_stop(&name); - } Commands::Run { name, server } => { daemon::daemon_main(name, server); } diff --git a/tfclient/src/service/codegen/mod.rs b/tfclient/src/service/codegen/mod.rs deleted file mode 100644 index a570ad9..0000000 --- a/tfclient/src/service/codegen/mod.rs +++ /dev/null @@ -1,9 +0,0 @@ -pub mod systemd; - -use std::error::Error; -use std::path::PathBuf; - -pub trait ServiceFileGenerator { - fn create_service_files(bin_path: PathBuf, name: &str, server: &str) -> Result<(), Box>; - fn delete_service_files(name: &str) -> Result<(), Box>; -} \ No newline at end of file diff --git a/tfclient/src/service/codegen/systemd.rs b/tfclient/src/service/codegen/systemd.rs deleted file mode 100644 index b05db5d..0000000 --- a/tfclient/src/service/codegen/systemd.rs +++ /dev/null @@ -1,48 +0,0 @@ -use std::error::Error; -use std::path::PathBuf; -use log::debug; -use crate::service::codegen::ServiceFileGenerator; -use std::fmt::Write; -use std::fs; - -pub struct SystemDServiceFileGenerator {} -impl ServiceFileGenerator for SystemDServiceFileGenerator { - fn create_service_files(bin_path: PathBuf, name: &str, server: &str) -> Result<(), Box> { - debug!("Generating a unit file..."); - - let mut unit_file = String::new(); - writeln!(unit_file, "[Unit]")?; - writeln!(unit_file, "Description=A client for Defined Networking compatible overlay networks (instance {})", name)?; - writeln!(unit_file, "Wants=basic.target network-online.target")?; - writeln!(unit_file, "After=basic.target network.target network-online.target")?; - writeln!(unit_file)?; - writeln!(unit_file, "[Service]")?; - writeln!(unit_file, "SyslogIdentifier=tfclient-{}", name)?; - writeln!(unit_file, "ExecStart={} run --server {} --name {}", bin_path.as_path().display(), server, name)?; - writeln!(unit_file, "Restart=always")?; - writeln!(unit_file)?; - writeln!(unit_file, "[Install]")?; - writeln!(unit_file, "WantedBy=multi-user.target")?; - - fs::write(format!("/usr/lib/systemd/system/{}.service", SystemDServiceFileGenerator::get_service_file_name(name)), unit_file)?; - - debug!("Installed unit file"); - - Ok(()) - } - - fn delete_service_files(name: &str) -> Result<(), Box> { - debug!("Deleting unit file..."); - - fs::remove_file(format!("/usr/lib/systemd/system/{}.service", SystemDServiceFileGenerator::get_service_file_name(name)))?; - - debug!("Removed unit file"); - - Ok(()) - } -} -impl SystemDServiceFileGenerator { - pub fn get_service_file_name(name: &str) -> String { - format!("tfclient_i-{}", name) - } -} \ No newline at end of file diff --git a/tfclient/src/service/detect.rs b/tfclient/src/service/detect.rs deleted file mode 100644 index 42a76a4..0000000 --- a/tfclient/src/service/detect.rs +++ /dev/null @@ -1,29 +0,0 @@ -use std::path::Path; -use log::info; -use crate::service::macos::OSXServiceManager; -use crate::service::runit::RunitServiceManager; -use crate::service::ServiceManager; -use crate::service::systemd::SystemDServiceManager; -use crate::service::windows::WindowsServiceManager; - -pub fn detect_service() -> Option> { - if cfg!(windows) { - return Some(Box::new(WindowsServiceManager {})); - } - if cfg!(macos) { - return Some(Box::new(OSXServiceManager {})); - } - detect_unix_service_manager() -} - -pub fn detect_unix_service_manager() -> Option> { - if Path::new("/etc/runit/1").exists() { - info!("Detected Runit service supervision (confidence: 100%, /etc/runit/1 exists)"); - return Some(Box::new(RunitServiceManager {})) - } - if Path::new("/var/lib/systemd").exists() { - info!("Detected SystemD service supervision (confidence: 100%, /var/lib/systemd exists)"); - return Some(Box::new(SystemDServiceManager {})); - } - None -} \ No newline at end of file diff --git a/tfclient/src/service/entry.rs b/tfclient/src/service/entry.rs deleted file mode 100644 index beff268..0000000 --- a/tfclient/src/service/entry.rs +++ /dev/null @@ -1,82 +0,0 @@ -use std::env::current_exe; -use log::{error, info}; -use crate::service::detect::detect_service; -use crate::util::check_server_url; - -pub fn cli_start(name: &str) { - info!("Detecting service manager..."); - let service = detect_service(); - if let Some(sm) = service { - match sm.start(name) { - Ok(_) => (), - Err(e) => { - error!("Error starting service: {}", e); - std::process::exit(1); - } - } - } else { - error!("Unable to determine which service manager to use. Could not start."); - std::process::exit(1); - } -} - -pub fn cli_stop(name: &str) { - info!("Detecting service manager..."); - let service = detect_service(); - if let Some(sm) = service { - match sm.stop(name) { - Ok(_) => (), - Err(e) => { - error!("Error starting service: {}", e); - std::process::exit(1); - } - } - } else { - error!("Unable to determine which service manager to use. Could not stop."); - std::process::exit(1); - } -} - -pub fn cli_install(name: &str, server: &str) { - info!("Checking server url..."); - check_server_url(server); - - info!("Detecting service manager..."); - let service = detect_service(); - if let Some(sm) = service { - let current_file = match current_exe() { - Ok(e) => e, - Err(e) => { - error!("Unable to get current binary: {}", e); - std::process::exit(1); - } - }; - match sm.install(current_file, name, server) { - Ok(_) => (), - Err(e) => { - error!("Error creating service files: {}", e); - std::process::exit(1); - } - } - } else { - error!("Unable to determine which service manager to use. Could not install."); - std::process::exit(1); - } -} - -pub fn cli_uninstall(name: &str) { - info!("Detecting service manager..."); - let service = detect_service(); - if let Some(sm) = service { - match sm.uninstall(name) { - Ok(_) => (), - Err(e) => { - error!("Error removing service files: {}", e); - std::process::exit(1); - } - } - } else { - error!("Unable to determine which service manager to use. Could not install."); - std::process::exit(1); - } -} \ No newline at end of file diff --git a/tfclient/src/service/macos.rs b/tfclient/src/service/macos.rs deleted file mode 100644 index c1c7c8d..0000000 --- a/tfclient/src/service/macos.rs +++ /dev/null @@ -1,22 +0,0 @@ -use std::error::Error; -use std::path::PathBuf; -use crate::service::ServiceManager; - -pub struct OSXServiceManager {} -impl ServiceManager for OSXServiceManager { - fn install(&self, _bin_path: PathBuf, _name: &str, _server_url: &str) -> Result<(), Box> { - todo!() - } - - fn uninstall(&self, _name: &str) -> Result<(), Box> { - todo!() - } - - fn start(&self, _name: &str) -> Result<(), Box> { - todo!() - } - - fn stop(&self, _name: &str) -> Result<(), Box> { - todo!() - } -} \ No newline at end of file diff --git a/tfclient/src/service/mod.rs b/tfclient/src/service/mod.rs deleted file mode 100644 index e00c8fb..0000000 --- a/tfclient/src/service/mod.rs +++ /dev/null @@ -1,17 +0,0 @@ -use std::error::Error; -use std::path::PathBuf; - -pub mod codegen; -pub mod systemd; -pub mod detect; -pub mod entry; -pub mod windows; -pub mod macos; -pub mod runit; - -pub trait ServiceManager { - fn install(&self, bin_path: PathBuf, name: &str, server_url: &str) -> Result<(), Box>; - fn uninstall(&self, name: &str) -> Result<(), Box>; - fn start(&self, name: &str) -> Result<(), Box>; - fn stop(&self, name: &str) -> Result<(), Box>; -} \ No newline at end of file diff --git a/tfclient/src/service/runit.rs b/tfclient/src/service/runit.rs deleted file mode 100644 index db07e08..0000000 --- a/tfclient/src/service/runit.rs +++ /dev/null @@ -1,22 +0,0 @@ -use std::error::Error; -use std::path::PathBuf; -use crate::service::ServiceManager; - -pub struct RunitServiceManager {} -impl ServiceManager for RunitServiceManager { - fn install(&self, _bin_path: PathBuf, _name: &str, _server_url: &str) -> Result<(), Box> { - todo!() - } - - fn uninstall(&self, _name: &str) -> Result<(), Box> { - todo!() - } - - fn start(&self, _name: &str) -> Result<(), Box> { - todo!() - } - - fn stop(&self, _name: &str) -> Result<(), Box> { - todo!() - } -} \ No newline at end of file diff --git a/tfclient/src/service/systemd.rs b/tfclient/src/service/systemd.rs deleted file mode 100644 index 05d3cc3..0000000 --- a/tfclient/src/service/systemd.rs +++ /dev/null @@ -1,86 +0,0 @@ -use std::error::Error; -use std::path::PathBuf; -use std::process::Command; -use log::{error, info}; -use crate::service::codegen::ServiceFileGenerator; -use crate::service::codegen::systemd::SystemDServiceFileGenerator; -use crate::service::ServiceManager; - -pub struct SystemDServiceManager {} -impl ServiceManager for SystemDServiceManager { - fn install(&self, bin_path: PathBuf, name: &str, server_url: &str) -> Result<(), Box> { - info!("Installing for SystemD"); - - SystemDServiceFileGenerator::create_service_files(bin_path, name, server_url)?; - - info!("Enabling the SystemD service"); - - let out = Command::new("systemctl").args(["enable", &SystemDServiceFileGenerator::get_service_file_name(name)]).output()?; - if !out.status.success() { - error!("Error enabling the SystemD service (command exited with non-zero exit code)"); - error!("stdout:"); - error!("{}", String::from_utf8(out.stdout)?); - error!("stderr:"); - error!("{}", String::from_utf8(out.stderr)?); - return Err("Command exited with non-zero exit code".into()); - } - - info!("Installation successful"); - - Ok(()) - } - - fn uninstall(&self, name: &str) -> Result<(), Box> { - info!("Uninstalling SystemD service files"); - - info!("Disabling the SystemD service"); - - let out = Command::new("systemctl").args(["disable", &SystemDServiceFileGenerator::get_service_file_name(name)]).output()?; - if !out.status.success() { - error!("Error disabling the SystemD service (command exited with non-zero exit code)"); - error!("stdout:"); - error!("{}", String::from_utf8(out.stdout)?); - error!("stderr:"); - error!("{}", String::from_utf8(out.stderr)?); - return Err("Command exited with non-zero exit code".into()); - } - - info!("Removing the service files"); - - SystemDServiceFileGenerator::delete_service_files(name)?; - - Ok(()) - } - - fn start(&self, name: &str) -> Result<(), Box> { - info!("Starting the SystemD service"); - - let out = Command::new("systemctl").args(["start", &SystemDServiceFileGenerator::get_service_file_name(name)]).output()?; - if !out.status.success() { - error!("Error starting the SystemD service (command exited with non-zero exit code)"); - error!("stdout:"); - error!("{}", String::from_utf8(out.stdout)?); - error!("stderr:"); - error!("{}", String::from_utf8(out.stderr)?); - return Err("Command exited with non-zero exit code".into()); - } - - Ok(()) - } - - fn stop(&self, name: &str) -> Result<(), Box> { - info!("Stopping the SystemD service"); - - let out = Command::new("systemctl").args(["stop", &SystemDServiceFileGenerator::get_service_file_name(name)]).output()?; - if !out.status.success() { - error!("Error stopping the SystemD service (command exited with non-zero exit code)"); - error!("stdout:"); - error!("{}", String::from_utf8(out.stdout)?); - error!("stderr:"); - error!("{}", String::from_utf8(out.stderr)?); - return Err("Command exited with non-zero exit code".into()); - } - - Ok(()) - } -} \ No newline at end of file diff --git a/tfclient/src/service/windows.rs b/tfclient/src/service/windows.rs deleted file mode 100644 index 8006a06..0000000 --- a/tfclient/src/service/windows.rs +++ /dev/null @@ -1,22 +0,0 @@ -use std::error::Error; -use std::path::PathBuf; -use crate::service::ServiceManager; - -pub struct WindowsServiceManager {} -impl ServiceManager for WindowsServiceManager { - fn install(&self, _bin_path: PathBuf, _name: &str, _server_url: &str) -> Result<(), Box> { - todo!() - } - - fn uninstall(&self, _name: &str) -> Result<(), Box> { - todo!() - } - - fn start(&self, _name: &str) -> Result<(), Box> { - todo!() - } - - fn stop(&self, _name: &str) -> Result<(), Box> { - todo!() - } -} \ No newline at end of file diff --git a/trifid-api/Cargo.toml b/trifid-api/Cargo.toml index d63dc22..360b9fb 100644 --- a/trifid-api/Cargo.toml +++ b/trifid-api/Cargo.toml @@ -23,6 +23,6 @@ chrono = "0.4.23" aes-gcm = "0.10.1" hex = "0.4.3" rand = "0.8.5" -trifid-pki = { version = "0.1.3", path = "../trifid-pki" } +trifid-pki = { version = "0.1", path = "../trifid-pki" } sha2 = "0.10.6" ipnet = { version = "2.7.1", features = ["serde"] }