From b84e470a4250119ffd02c36839f2cf24137c5835 Mon Sep 17 00:00:00 2001 From: notplants Date: Wed, 11 May 2022 11:24:33 +0200 Subject: [PATCH 01/10] Remove unecessary .to_string --- peach-lib/src/config_manager.rs | 49 ++++++++++++++++----------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/peach-lib/src/config_manager.rs b/peach-lib/src/config_manager.rs index 5c9a849..840b11b 100644 --- a/peach-lib/src/config_manager.rs +++ b/peach-lib/src/config_manager.rs @@ -41,34 +41,33 @@ lazy_static! { // Default values for PeachCloud configs which are used for any key which is not set // via an environment variable or in a saved configuration file. pub fn get_peach_config_defaults() -> HashMap { - let peach_config_defaults: HashMap = HashMap::from([ - ("STANDALONE_MODE".to_string(), "true".to_string()), - ("DISABLE_AUTH".to_string(), "false".to_string()), - ("ADDR".to_string(), "127.0.0.1".to_string()), - ("PORT".to_string(), "8000".to_string()), - ("EXTERNAL_DOMAIN".to_string(), "".to_string()), - ("DYN_DOMAIN".to_string(), "".to_string()), + let peach_config_defaults: HashMap<&str, &str> = HashMap::from([ + ("STANDALONE_MODE", "true"), + ("DISABLE_AUTH", "false"), + ("ADDR", "127.0.0.1"), + ("PORT", "8000"), + ("EXTERNAL_DOMAIN", ""), + ("DYN_DOMAIN", ""), ( - "DYN_DNS_SERVER_ADDRESS".to_string(), - "http://dynserver.dyn.peachcloud.org".to_string(), - ), - ("DYN_USE_CUSTOM_SERVER".to_string(), "true".to_string()), - ("DYN_TSIG_KEY_PATH".to_string(), "".to_string()), - ( - "DYN_NAMESERVER".to_string(), - "ns.peachcloud.org".to_string(), - ), - ("DYN_ENABLED".to_string(), "false".to_string()), - ("SSB_ADMIN_IDS".to_string(), "".to_string()), - ("ADMIN_PASSWORD_HASH".to_string(), "146".to_string()), - ("TEMPORARY_PASSWORD_HASH".to_string(), "".to_string()), - ("GO_SBOT_DATADIR".to_string(), "".to_string()), - ( - "PEACH_CONFIGDIR".to_string(), - "/var/lib/peachcloud".to_string(), + "DYN_DNS_SERVER_ADDRESS", + "http://dynserver.dyn.peachcloud.org", ), + ("DYN_USE_CUSTOM_SERVER", "true"), + ("DYN_TSIG_KEY_PATH", ""), + ("DYN_NAMESERVER", "ns.peachcloud.org"), + ("DYN_ENABLED", "false"), + ("SSB_ADMIN_IDS", ""), + ("ADMIN_PASSWORD_HASH", "146"), + ("TEMPORARY_PASSWORD_HASH", ""), + ("GO_SBOT_DATADIR", ""), + ("PEACH_CONFIGDIR", "/var/lib/peachcloud"), ]); - peach_config_defaults + // convert HashMap<&str, &str> to HashMap and return + let pc_defaults: HashMap = peach_config_defaults + .iter() + .map(|(key, val)| (key.to_string(), val.to_string())) + .collect(); + pc_defaults } // primary interface for getting config values From f96c950aa6eba9631af08b69a45fc5ad304758bd Mon Sep 17 00:00:00 2001 From: notplants Date: Wed, 11 May 2022 17:06:12 +0200 Subject: [PATCH 02/10] Enable nanorand featureflag for cross-compilation on mac os --- Cargo.lock | 5 +++++ peach-lib/Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 989b105..40d86d4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1071,8 +1071,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad" dependencies = [ "cfg-if 1.0.0", + "js-sys", "libc", "wasi 0.10.2+wasi-snapshot-preview1", + "wasm-bindgen", ] [[package]] @@ -2063,6 +2065,9 @@ name = "nanorand" version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "729eb334247daa1803e0a094d0a5c55711b85571179f5ec6e53eccfdf7008958" +dependencies = [ + "getrandom 0.2.6", +] [[package]] name = "nb" diff --git a/peach-lib/Cargo.toml b/peach-lib/Cargo.toml index 82970a1..370db43 100644 --- a/peach-lib/Cargo.toml +++ b/peach-lib/Cargo.toml @@ -14,7 +14,7 @@ jsonrpc-client-core = "0.5" jsonrpc-client-http = "0.5" jsonrpc-core = "8.0" log = "0.4" -nanorand = "0.6" +nanorand = { version = "0.6", features = ["getrandom"] } regex = "1" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" From 288941e8a3c96bfcee858cffb71583a395909505 Mon Sep 17 00:00:00 2001 From: notplants Date: Thu, 12 May 2022 11:26:23 +0200 Subject: [PATCH 03/10] Change Rouille to use get_config_value --- Cargo.lock | 2 +- peach-config/Cargo.toml | 2 +- peach-lib/src/config_manager.rs | 2 +- peach-web/src/config.rs | 17 +++++++++-------- peach-web/src/main.rs | 8 ++++---- peach-web/src/routes/settings/menu.rs | 4 ++-- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 40d86d4..02a0593 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2386,7 +2386,7 @@ dependencies = [ [[package]] name = "peach-config" -version = "0.1.23" +version = "0.1.24" dependencies = [ "clap", "env_logger 0.6.2", diff --git a/peach-config/Cargo.toml b/peach-config/Cargo.toml index 679d4d9..d51afdb 100644 --- a/peach-config/Cargo.toml +++ b/peach-config/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "peach-config" -version = "0.1.23" +version = "0.1.24" authors = ["Andrew Reid ", "Max Fowler "] edition = "2018" description = "Command line tool for installing, updating and configuring PeachCloud" diff --git a/peach-lib/src/config_manager.rs b/peach-lib/src/config_manager.rs index 840b11b..a3213f6 100644 --- a/peach-lib/src/config_manager.rs +++ b/peach-lib/src/config_manager.rs @@ -57,7 +57,7 @@ pub fn get_peach_config_defaults() -> HashMap { ("DYN_NAMESERVER", "ns.peachcloud.org"), ("DYN_ENABLED", "false"), ("SSB_ADMIN_IDS", ""), - ("ADMIN_PASSWORD_HASH", "146"), + ("ADMIN_PASSWORD_HASH", "47"), ("TEMPORARY_PASSWORD_HASH", ""), ("GO_SBOT_DATADIR", ""), ("PEACH_CONFIGDIR", "/var/lib/peachcloud"), diff --git a/peach-web/src/config.rs b/peach-web/src/config.rs index b1c2e95..385404b 100644 --- a/peach-web/src/config.rs +++ b/peach-web/src/config.rs @@ -4,18 +4,19 @@ //! variables have been set. use std::env; +use peach_lib::config_manager::get_config_value; // environment variable keys to check for -const ENV_VARS: [&str; 4] = ["STANDALONE_MODE", "DISABLE_AUTH", "ADDR", "PORT"]; +const CONFIG_KEYS: [&str; 4] = ["STANDALONE_MODE", "DISABLE_AUTH", "ADDR", "PORT"]; -pub struct Config { +pub struct RouilleConfig { pub standalone_mode: bool, pub disable_auth: bool, pub addr: String, pub port: String, } -impl Default for Config { +impl Default for RouilleConfig { fn default() -> Self { Self { standalone_mode: true, @@ -26,15 +27,15 @@ impl Default for Config { } } -impl Config { - pub fn new() -> Config { +impl RouilleConfig { + pub fn new() -> RouilleConfig { // define default config values - let mut config = Config::default(); + let mut config = RouilleConfig::default(); // check for the environment variables in our config - for key in ENV_VARS { + for key in CONFIG_KEYS { // if a variable (key) has been set, check the value - if let Ok(val) = env::var(key) { + if let Ok(val) = get_config_value(key) { // if the value is of the correct type, update the config value match key { "STANDALONE_MODE" if val.as_str() == "true" => config.standalone_mode = true, diff --git a/peach-web/src/main.rs b/peach-web/src/main.rs index b43d669..ee2f1de 100644 --- a/peach-web/src/main.rs +++ b/peach-web/src/main.rs @@ -29,12 +29,12 @@ use lazy_static::lazy_static; use log::info; // crate-local dependencies -use config::Config; +use config::RouilleConfig; use utils::theme::Theme; // load the application configuration and create the theme switcher lazy_static! { - static ref CONFIG: Config = Config::new(); + static ref ROUILLE_CONFIG: RouilleConfig = RouilleConfig::new(); static ref THEME: RwLock = RwLock::new(Theme::Light); } @@ -51,7 +51,7 @@ fn main() { // set ip address / hostname and port for the webserver // defaults to "127.0.0.1:8000" - let addr_and_port = format!("{}:{}", CONFIG.addr, CONFIG.port); + let addr_and_port = format!("{}:{}", ROUILLE_CONFIG.addr, ROUILLE_CONFIG.port); // store the session data for each session and a hashmap that associates // each session id with the data @@ -67,7 +67,7 @@ fn main() { // with a name of "SID" and a duration of one hour (3600 seconds) rouille::session::session(request, "SID", 3600, |session| { // if the "DISABLE_AUTH" env var is true, authenticate the session - let mut session_data = if CONFIG.disable_auth { + let mut session_data = if ROUILLE_CONFIG.disable_auth { Some(SessionData { _login: "success".to_string(), }) diff --git a/peach-web/src/routes/settings/menu.rs b/peach-web/src/routes/settings/menu.rs index c49218d..6745263 100644 --- a/peach-web/src/routes/settings/menu.rs +++ b/peach-web/src/routes/settings/menu.rs @@ -1,6 +1,6 @@ use maud::{html, PreEscaped}; -use crate::{templates, utils::theme, CONFIG}; +use crate::{templates, utils::theme, ROUILLE_CONFIG}; // ROUTE: /settings @@ -12,7 +12,7 @@ pub fn build_template() -> PreEscaped { (PreEscaped("")) div id="settingsButtons" { // render the network settings button if we're not in standalone mode - @if !CONFIG.standalone_mode { + @if !ROUILLE_CONFIG.standalone_mode { a id="network" class="button button-primary center" href="/settings/network" title="Network Settings" { "Network" } } a id="scuttlebutt" class="button button-primary center" href="/settings/scuttlebutt" title="Scuttlebutt Settings" { "Scuttlebutt" } From e041e1c7f9f685ab2eded86f41584f0518e4ff3e Mon Sep 17 00:00:00 2001 From: notplants Date: Thu, 12 May 2022 11:55:59 +0200 Subject: [PATCH 04/10] Change defaults to only be defined in config_manager.rs --- peach-web/src/config.rs | 51 +++++++++++------------------------------ peach-web/src/main.rs | 3 ++- 2 files changed, 16 insertions(+), 38 deletions(-) diff --git a/peach-web/src/config.rs b/peach-web/src/config.rs index 385404b..bc851f5 100644 --- a/peach-web/src/config.rs +++ b/peach-web/src/config.rs @@ -1,14 +1,14 @@ //! Define the configuration parameters for the web application. //! -//! Sets default values and updates them if the corresponding environment -//! variables have been set. +//! These configs are loaded using peach-lib::config_manager which checks config keys from +//! three sources: +//! 1. from environmental variables +//! 2. from a configuration file +//! 3. from default values -use std::env; +use crate::error::PeachWebError; use peach_lib::config_manager::get_config_value; -// environment variable keys to check for -const CONFIG_KEYS: [&str; 4] = ["STANDALONE_MODE", "DISABLE_AUTH", "ADDR", "PORT"]; - pub struct RouilleConfig { pub standalone_mode: bool, pub disable_auth: bool, @@ -16,39 +16,16 @@ pub struct RouilleConfig { pub port: String, } -impl Default for RouilleConfig { - fn default() -> Self { - Self { - standalone_mode: true, - disable_auth: false, - addr: "127.0.0.1".to_string(), - port: "8000".to_string(), - } - } -} - impl RouilleConfig { - pub fn new() -> RouilleConfig { + pub fn new() -> Result { // define default config values - let mut config = RouilleConfig::default(); + let config = RouilleConfig { + standalone_mode: get_config_value("STANDALONE_MODE")?.as_str() == "true", + disable_auth: get_config_value("DISABLE_AUTH")?.as_str() == "true", + addr: get_config_value("ADDR")?, + port: get_config_value("PORT")?, + }; - // check for the environment variables in our config - for key in CONFIG_KEYS { - // if a variable (key) has been set, check the value - if let Ok(val) = get_config_value(key) { - // if the value is of the correct type, update the config value - match key { - "STANDALONE_MODE" if val.as_str() == "true" => config.standalone_mode = true, - "STANDALONE_MODE" if val.as_str() == "false" => config.standalone_mode = false, - "DISABLE_AUTH" if val.as_str() == "true" => config.disable_auth = true, - "DISABLE_AUTH" if val.as_str() == "false" => config.disable_auth = false, - "ADDR" => config.addr = val, - "PORT" => config.port = val, - _ => (), - } - } - } - - config + Ok(config) } } diff --git a/peach-web/src/main.rs b/peach-web/src/main.rs index ee2f1de..72de356 100644 --- a/peach-web/src/main.rs +++ b/peach-web/src/main.rs @@ -34,7 +34,8 @@ use utils::theme::Theme; // load the application configuration and create the theme switcher lazy_static! { - static ref ROUILLE_CONFIG: RouilleConfig = RouilleConfig::new(); + static ref ROUILLE_CONFIG: RouilleConfig = RouilleConfig::new() + .expect("Failed to load rouille configuration values on server startup"); static ref THEME: RwLock = RwLock::new(Theme::Light); } From 99fd3be4ad775570a12661769b93f298c8846e73 Mon Sep 17 00:00:00 2001 From: notplants Date: Thu, 12 May 2022 12:21:05 +0200 Subject: [PATCH 05/10] Change RouilleConfig to ServerConfig --- peach-web/src/config.rs | 8 ++++---- peach-web/src/main.rs | 8 ++++---- peach-web/src/routes/settings/menu.rs | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/peach-web/src/config.rs b/peach-web/src/config.rs index bc851f5..b4d7907 100644 --- a/peach-web/src/config.rs +++ b/peach-web/src/config.rs @@ -9,17 +9,17 @@ use crate::error::PeachWebError; use peach_lib::config_manager::get_config_value; -pub struct RouilleConfig { +pub struct ServerConfig { pub standalone_mode: bool, pub disable_auth: bool, pub addr: String, pub port: String, } -impl RouilleConfig { - pub fn new() -> Result { +impl ServerConfig { + pub fn new() -> Result { // define default config values - let config = RouilleConfig { + let config = ServerConfig { standalone_mode: get_config_value("STANDALONE_MODE")?.as_str() == "true", disable_auth: get_config_value("DISABLE_AUTH")?.as_str() == "true", addr: get_config_value("ADDR")?, diff --git a/peach-web/src/main.rs b/peach-web/src/main.rs index 72de356..b624615 100644 --- a/peach-web/src/main.rs +++ b/peach-web/src/main.rs @@ -29,12 +29,12 @@ use lazy_static::lazy_static; use log::info; // crate-local dependencies -use config::RouilleConfig; +use config::ServerConfig; use utils::theme::Theme; // load the application configuration and create the theme switcher lazy_static! { - static ref ROUILLE_CONFIG: RouilleConfig = RouilleConfig::new() + static ref SERVER_CONFIG: ServerConfig = ServerConfig::new() .expect("Failed to load rouille configuration values on server startup"); static ref THEME: RwLock = RwLock::new(Theme::Light); } @@ -52,7 +52,7 @@ fn main() { // set ip address / hostname and port for the webserver // defaults to "127.0.0.1:8000" - let addr_and_port = format!("{}:{}", ROUILLE_CONFIG.addr, ROUILLE_CONFIG.port); + let addr_and_port = format!("{}:{}", SERVER_CONFIG.addr, SERVER_CONFIG.port); // store the session data for each session and a hashmap that associates // each session id with the data @@ -68,7 +68,7 @@ fn main() { // with a name of "SID" and a duration of one hour (3600 seconds) rouille::session::session(request, "SID", 3600, |session| { // if the "DISABLE_AUTH" env var is true, authenticate the session - let mut session_data = if ROUILLE_CONFIG.disable_auth { + let mut session_data = if SERVER_CONFIG.disable_auth { Some(SessionData { _login: "success".to_string(), }) diff --git a/peach-web/src/routes/settings/menu.rs b/peach-web/src/routes/settings/menu.rs index 6745263..ad122b5 100644 --- a/peach-web/src/routes/settings/menu.rs +++ b/peach-web/src/routes/settings/menu.rs @@ -1,6 +1,6 @@ use maud::{html, PreEscaped}; -use crate::{templates, utils::theme, ROUILLE_CONFIG}; +use crate::{templates, utils::theme, SERVER_CONFIG}; // ROUTE: /settings @@ -12,7 +12,7 @@ pub fn build_template() -> PreEscaped { (PreEscaped("")) div id="settingsButtons" { // render the network settings button if we're not in standalone mode - @if !ROUILLE_CONFIG.standalone_mode { + @if !SERVER_CONFIG.standalone_mode { a id="network" class="button button-primary center" href="/settings/network" title="Network Settings" { "Network" } } a id="scuttlebutt" class="button button-primary center" href="/settings/scuttlebutt" title="Scuttlebutt Settings" { "Scuttlebutt" } From 5ea6a8670039909d879b6ac4a89bc0017820271b Mon Sep 17 00:00:00 2001 From: notplants Date: Thu, 12 May 2022 12:24:17 +0200 Subject: [PATCH 06/10] Fix clippy error --- Cargo.lock | 2 +- peach-web/src/main.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 02a0593..6585640 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1111,7 +1111,7 @@ dependencies = [ [[package]] name = "golgi" version = "0.1.1" -source = "git+https://git.coopcloud.tech/golgi-ssb/golgi#77dd75bcd4649b7487069a61e2a8069b49f60a1d" +source = "git+https://git.coopcloud.tech/golgi-ssb/golgi.git#77dd75bcd4649b7487069a61e2a8069b49f60a1d" dependencies = [ "async-std", "async-stream 0.3.3", diff --git a/peach-web/src/main.rs b/peach-web/src/main.rs index b624615..868496d 100644 --- a/peach-web/src/main.rs +++ b/peach-web/src/main.rs @@ -34,8 +34,8 @@ use utils::theme::Theme; // load the application configuration and create the theme switcher lazy_static! { - static ref SERVER_CONFIG: ServerConfig = ServerConfig::new() - .expect("Failed to load rouille configuration values on server startup"); + static ref SERVER_CONFIG: ServerConfig = + ServerConfig::new().expect("Failed to load rouille configuration values on server startup"); static ref THEME: RwLock = RwLock::new(Theme::Light); } From 8202d4af5f1d6fdb1f188af42b54c2813807f2ff Mon Sep 17 00:00:00 2001 From: notplants Date: Thu, 12 May 2022 12:47:33 +0200 Subject: [PATCH 07/10] Update peach-config to use configured paths --- Cargo.lock | 2 +- peach-config/src/set_permissions.rs | 26 +++++++++++++++----------- peach-lib/src/config_manager.rs | 2 +- peach-lib/src/sbot.rs | 11 ++++------- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6585640..02a0593 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1111,7 +1111,7 @@ dependencies = [ [[package]] name = "golgi" version = "0.1.1" -source = "git+https://git.coopcloud.tech/golgi-ssb/golgi.git#77dd75bcd4649b7487069a61e2a8069b49f60a1d" +source = "git+https://git.coopcloud.tech/golgi-ssb/golgi#77dd75bcd4649b7487069a61e2a8069b49f60a1d" dependencies = [ "async-std", "async-stream 0.3.3", diff --git a/peach-config/src/set_permissions.rs b/peach-config/src/set_permissions.rs index 45a6959..72ea4a0 100644 --- a/peach-config/src/set_permissions.rs +++ b/peach-config/src/set_permissions.rs @@ -1,23 +1,27 @@ +use lazy_static::lazy_static; + +use peach_lib::config_manager::get_config_value; + use crate::error::PeachConfigError; use crate::utils::cmd; -/// All configs are stored in this folder, and should be read/writeable by peach group -/// so they can be read and written by all PeachCloud services. -pub const CONFIGS_DIR: &str = "/var/lib/peachcloud"; -pub const PEACH_WEB_DIR: &str = "/usr/share/peach-web"; -pub const PEACH_HOME_DIR: &str = "/home/peach"; +lazy_static! { + pub static ref CONFIGS_DIR: String = get_config_value("PEACH_CONFIG_DIR").expect("Failed to load config value for PEACH_CONFIG_DIR"); + pub static ref PEACH_WEB_DIR: String = "/usr/share/peach-web".to_string(); + pub static ref PEACH_HOME_DIR: String = "/home/peach".to_string(); +} /// Utility function to set correct file permissions on the PeachCloud device. /// Accidentally changing file permissions is a fairly common thing to happen, /// so this is a useful CLI function for quickly correcting anything that may be out of order. pub fn set_permissions() -> Result<(), PeachConfigError> { println!("[ UPDATING FILE PERMISSIONS ON PEACHCLOUD DEVICE ]"); - cmd(&["chmod", "-R", "u+rwX,g+rwX", CONFIGS_DIR])?; - cmd(&["chown", "-R", "peach", CONFIGS_DIR])?; - cmd(&["chgrp", "-R", "peach", CONFIGS_DIR])?; - cmd(&["chmod", "-R", "u+rwX,g+rwX", PEACH_WEB_DIR])?; - cmd(&["chown", "-R", "peach:peach", PEACH_WEB_DIR])?; - cmd(&["chown", "-R", "peach:peach", PEACH_HOME_DIR])?; + cmd(&["chmod", "-R", "u+rwX,g+rwX", &CONFIGS_DIR])?; + cmd(&["chown", "-R", "peach:peach", &CONFIGS_DIR])?; + cmd(&["chmod", "-R", "u+rwX,g+rwX", &PEACH_WEB_DIR])?; + cmd(&["chown", "-R", "peach:peach", &PEACH_WEB_DIR])?; + cmd(&["chmod", "-R", "u+rwX,g+rwX", &PEACH_HOME_DIR])?; + cmd(&["chown", "-R", "peach:peach", &PEACH_HOME_DIR])?; println!("[ PERMISSIONS SUCCESSFULLY UPDATED ]"); Ok(()) } diff --git a/peach-lib/src/config_manager.rs b/peach-lib/src/config_manager.rs index a3213f6..3852dfc 100644 --- a/peach-lib/src/config_manager.rs +++ b/peach-lib/src/config_manager.rs @@ -59,7 +59,7 @@ pub fn get_peach_config_defaults() -> HashMap { ("SSB_ADMIN_IDS", ""), ("ADMIN_PASSWORD_HASH", "47"), ("TEMPORARY_PASSWORD_HASH", ""), - ("GO_SBOT_DATADIR", ""), + ("GO_SBOT_DATADIR", "/home/peach/.ssb-go"), ("PEACH_CONFIGDIR", "/var/lib/peachcloud"), ]); // convert HashMap<&str, &str> to HashMap and return diff --git a/peach-lib/src/sbot.rs b/peach-lib/src/sbot.rs index ee9434f..c76857d 100644 --- a/peach-lib/src/sbot.rs +++ b/peach-lib/src/sbot.rs @@ -3,6 +3,7 @@ use std::{fs, fs::File, io, io::Write, path::PathBuf, process::Command, str}; use serde::{Deserialize, Serialize}; +use crate::config_manager::get_config_value; use crate::error::PeachError; @@ -126,11 +127,8 @@ impl SbotStatus { } } - // determine path of user's home directory - let mut blobstore_path = dirs::home_dir().ok_or(PeachError::HomeDir)?; - - // append the blobstore path - blobstore_path.push(".ssb-go/blobs/sha256"); + // get path to blobstore + let blobstore_path = format!("{}/blobs/sha256", get_config_value("GO_SBOT_DATADIR")?); // determine the size of the blobstore directory in bytes status.blobstore = dir_size(blobstore_path).ok(); @@ -220,8 +218,7 @@ impl SbotConfig { let config_string = toml::to_string(&config)?; // determine path of user's home directory - let mut config_path = dirs::home_dir().ok_or(PeachError::HomeDir)?; - config_path.push(".ssb-go/config.toml"); + let config_path = format!("{}/config.toml", get_config_value("GO_SBOT_DATADIR")?); // open config file for writing let mut file = File::create(config_path)?; From 908d265de61ebf926da4fc6e7a4655a581755635 Mon Sep 17 00:00:00 2001 From: notplants Date: Thu, 12 May 2022 12:53:06 +0200 Subject: [PATCH 08/10] Bump version numbers --- Cargo.lock | 4 ++-- peach-config/Cargo.toml | 2 +- peach-config/src/set_permissions.rs | 18 +++++++++--------- peach-lib/Cargo.toml | 2 +- peach-lib/src/config_manager.rs | 2 ++ 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 02a0593..9224fae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2386,7 +2386,7 @@ dependencies = [ [[package]] name = "peach-config" -version = "0.1.24" +version = "0.1.25" dependencies = [ "clap", "env_logger 0.6.2", @@ -2425,7 +2425,7 @@ dependencies = [ [[package]] name = "peach-lib" -version = "1.3.2" +version = "1.3.3" dependencies = [ "async-std", "chrono", diff --git a/peach-config/Cargo.toml b/peach-config/Cargo.toml index d51afdb..e2f226f 100644 --- a/peach-config/Cargo.toml +++ b/peach-config/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "peach-config" -version = "0.1.24" +version = "0.1.25" authors = ["Andrew Reid ", "Max Fowler "] edition = "2018" description = "Command line tool for installing, updating and configuring PeachCloud" diff --git a/peach-config/src/set_permissions.rs b/peach-config/src/set_permissions.rs index 72ea4a0..26d07f8 100644 --- a/peach-config/src/set_permissions.rs +++ b/peach-config/src/set_permissions.rs @@ -6,9 +6,9 @@ use crate::error::PeachConfigError; use crate::utils::cmd; lazy_static! { - pub static ref CONFIGS_DIR: String = get_config_value("PEACH_CONFIG_DIR").expect("Failed to load config value for PEACH_CONFIG_DIR"); - pub static ref PEACH_WEB_DIR: String = "/usr/share/peach-web".to_string(); - pub static ref PEACH_HOME_DIR: String = "/home/peach".to_string(); + pub static ref PEACH_CONFIGDIR: String = get_config_value("PEACH_CONFIGDIR").expect("Failed to load config value for PEACH_CONFIGDIR"); + pub static ref PEACH_WEBDIR: String = get_config_value("PEACH_WEBDIR").expect("Failed to load config value for PEACH_WEBDIR"); + pub static ref PEACH_HOMEDIR: String = get_config_value("PEACH_HOMEDIR").expect("Failed to load config value for PEACH_HOMEDIR"); } /// Utility function to set correct file permissions on the PeachCloud device. @@ -16,12 +16,12 @@ lazy_static! { /// so this is a useful CLI function for quickly correcting anything that may be out of order. pub fn set_permissions() -> Result<(), PeachConfigError> { println!("[ UPDATING FILE PERMISSIONS ON PEACHCLOUD DEVICE ]"); - cmd(&["chmod", "-R", "u+rwX,g+rwX", &CONFIGS_DIR])?; - cmd(&["chown", "-R", "peach:peach", &CONFIGS_DIR])?; - cmd(&["chmod", "-R", "u+rwX,g+rwX", &PEACH_WEB_DIR])?; - cmd(&["chown", "-R", "peach:peach", &PEACH_WEB_DIR])?; - cmd(&["chmod", "-R", "u+rwX,g+rwX", &PEACH_HOME_DIR])?; - cmd(&["chown", "-R", "peach:peach", &PEACH_HOME_DIR])?; + cmd(&["chmod", "-R", "u+rwX,g+rwX", &PEACH_CONFIGDIR])?; + cmd(&["chown", "-R", "peach:peach", &PEACH_CONFIGDIR])?; + cmd(&["chmod", "-R", "u+rwX,g+rwX", &PEACH_WEBDIR])?; + cmd(&["chown", "-R", "peach:peach", &PEACH_WEBDIR])?; + cmd(&["chmod", "-R", "u+rwX,g+rwX", &PEACH_HOMEDIR])?; + cmd(&["chown", "-R", "peach:peach", &PEACH_HOMEDIR])?; println!("[ PERMISSIONS SUCCESSFULLY UPDATED ]"); Ok(()) } diff --git a/peach-lib/Cargo.toml b/peach-lib/Cargo.toml index 370db43..028c61a 100644 --- a/peach-lib/Cargo.toml +++ b/peach-lib/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "peach-lib" -version = "1.3.2" +version = "1.3.3" authors = ["Andrew Reid "] edition = "2018" diff --git a/peach-lib/src/config_manager.rs b/peach-lib/src/config_manager.rs index 3852dfc..11ae424 100644 --- a/peach-lib/src/config_manager.rs +++ b/peach-lib/src/config_manager.rs @@ -61,6 +61,8 @@ pub fn get_peach_config_defaults() -> HashMap { ("TEMPORARY_PASSWORD_HASH", ""), ("GO_SBOT_DATADIR", "/home/peach/.ssb-go"), ("PEACH_CONFIGDIR", "/var/lib/peachcloud"), + ("PEACH_HOMEDIR", "/home/peach"), + ("PEACH_WEBDIR", "/usr/share/peach-web"), ]); // convert HashMap<&str, &str> to HashMap and return let pc_defaults: HashMap = peach_config_defaults From 781af460ae3ddbc2565da4617b3e1ee256fc4e00 Mon Sep 17 00:00:00 2001 From: notplants Date: Thu, 12 May 2022 13:32:40 +0200 Subject: [PATCH 09/10] Fix clippy warning --- peach-config/src/set_permissions.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/peach-config/src/set_permissions.rs b/peach-config/src/set_permissions.rs index 26d07f8..355e24f 100644 --- a/peach-config/src/set_permissions.rs +++ b/peach-config/src/set_permissions.rs @@ -6,9 +6,12 @@ use crate::error::PeachConfigError; use crate::utils::cmd; lazy_static! { - pub static ref PEACH_CONFIGDIR: String = get_config_value("PEACH_CONFIGDIR").expect("Failed to load config value for PEACH_CONFIGDIR"); - pub static ref PEACH_WEBDIR: String = get_config_value("PEACH_WEBDIR").expect("Failed to load config value for PEACH_WEBDIR"); - pub static ref PEACH_HOMEDIR: String = get_config_value("PEACH_HOMEDIR").expect("Failed to load config value for PEACH_HOMEDIR"); + pub static ref PEACH_CONFIGDIR: String = get_config_value("PEACH_CONFIGDIR") + .expect("Failed to load config value for PEACH_CONFIGDIR"); + pub static ref PEACH_WEBDIR: String = + get_config_value("PEACH_WEBDIR").expect("Failed to load config value for PEACH_WEBDIR"); + pub static ref PEACH_HOMEDIR: String = + get_config_value("PEACH_HOMEDIR").expect("Failed to load config value for PEACH_HOMEDIR"); } /// Utility function to set correct file permissions on the PeachCloud device. From 8960df66357a60ebce902934550960ca10fb301e Mon Sep 17 00:00:00 2001 From: notplants Date: Thu, 12 May 2022 21:58:15 +0200 Subject: [PATCH 10/10] Fix cargo fmt --- peach-lib/src/sbot.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/peach-lib/src/sbot.rs b/peach-lib/src/sbot.rs index c76857d..880479d 100644 --- a/peach-lib/src/sbot.rs +++ b/peach-lib/src/sbot.rs @@ -2,8 +2,8 @@ use std::{fs, fs::File, io, io::Write, path::PathBuf, process::Command, str}; -use serde::{Deserialize, Serialize}; use crate::config_manager::get_config_value; +use serde::{Deserialize, Serialize}; use crate::error::PeachError;