diff --git a/Cargo.lock b/Cargo.lock index 32c6254..c1ad90f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -563,7 +563,7 @@ dependencies = [ "lazy_static", "maybe-uninit", "memoffset", - "scopeguard 1.1.0", + "scopeguard", ] [[package]] @@ -787,28 +787,6 @@ version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77f3309417938f28bf8228fcff79a4a37103981e3e186d2ccd19c74b38f4eb71" -[[package]] -name = "failure" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86" -dependencies = [ - "backtrace", - "failure_derive", -] - -[[package]] -name = "failure_derive" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" -dependencies = [ - "proc-macro2 1.0.38", - "quote 1.0.18", - "syn 1.0.94", - "synstructure", -] - [[package]] name = "fake-simd" version = "0.1.2" @@ -1110,8 +1088,8 @@ dependencies = [ [[package]] name = "golgi" -version = "0.1.1" -source = "git+https://git.coopcloud.tech/golgi-ssb/golgi#0aa616d92b005b38359aa34bf448f3f1f47e8e6a" +version = "0.1.4" +source = "git+https://git.coopcloud.tech/golgi-ssb/golgi#ca4c1114ddf328b818144c5a1af0187b1357e9be" dependencies = [ "async-std", "async-stream 0.3.3", @@ -1121,23 +1099,12 @@ dependencies = [ "kuska-handshake", "kuska-sodiumoxide", "kuska-ssb", + "log 0.4.17", "serde 1.0.137", "serde_json", "sha2", ] -[[package]] -name = "gpio-cdev" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04d50743080fbae298c55f0b28dd5ea4b513c53cddeddace6cbdd31db7dda981" -dependencies = [ - "bitflags 1.3.2", - "error-chain", - "libc", - "nix 0.11.1", -] - [[package]] name = "h2" version = "0.1.26" @@ -1458,7 +1425,7 @@ dependencies = [ "derive_more", "futures 0.3.21", "jsonrpc-core 18.0.0", - "jsonrpc-pubsub 18.0.0", + "jsonrpc-pubsub", "log 0.4.17", "serde 1.0.137", "serde_json", @@ -1506,20 +1473,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "jsonrpc-core-client" -version = "11.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c889ca27072f038496a62f38356e8f827acf194d7276030120265362b2974eab" -dependencies = [ - "failure", - "futures 0.1.31", - "jsonrpc-core 11.0.0", - "log 0.4.17", - "serde 1.0.137", - "serde_json", -] - [[package]] name = "jsonrpc-core-client" version = "18.0.0" @@ -1560,18 +1513,6 @@ dependencies = [ "unicase", ] -[[package]] -name = "jsonrpc-pubsub" -version = "11.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c233c4570183a45f7bde14cd7d23446d6c236de6df9442e53a60951adae9fd34" -dependencies = [ - "jsonrpc-core 11.0.0", - "log 0.4.17", - "parking_lot 0.7.1", - "serde 1.0.137", -] - [[package]] name = "jsonrpc-pubsub" version = "18.0.0" @@ -1622,20 +1563,6 @@ dependencies = [ "unicase", ] -[[package]] -name = "jsonrpc-test" -version = "11.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0aedad254cd8faba2bf8d1fe00c52fe9d9944f1a8c3f789916b68a61a3414c87" -dependencies = [ - "jsonrpc-core 11.0.0", - "jsonrpc-core-client 11.0.0", - "jsonrpc-pubsub 11.0.0", - "log 0.4.17", - "serde 1.0.137", - "serde_json", -] - [[package]] name = "jsonrpc-test" version = "18.0.0" @@ -1643,27 +1570,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be4347ecf335735719f555eff3f119e198049ddb22eec4d60dd7b4d63a3b10a6" dependencies = [ "jsonrpc-core 18.0.0", - "jsonrpc-core-client 18.0.0", - "jsonrpc-pubsub 18.0.0", + "jsonrpc-core-client", + "jsonrpc-pubsub", "log 0.4.17", "serde 1.0.137", "serde_json", ] -[[package]] -name = "jsonrpc-ws-server" -version = "11.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e72d8f524c7afd11d9c71614d1f814ee1c46377869933ce42d559d6973922f79" -dependencies = [ - "jsonrpc-core 11.0.0", - "jsonrpc-server-utils 11.0.0", - "log 0.4.17", - "parking_lot 0.7.1", - "slab 0.4.6", - "ws", -] - [[package]] name = "keccak" version = "0.1.0" @@ -1706,8 +1619,8 @@ dependencies = [ [[package]] name = "kuska-ssb" -version = "0.4.0" -source = "git+https://github.com/Kuska-ssb/ssb#fb7062de606e7c9cae8dd4df402a122db46c1b77" +version = "0.4.1" +source = "git+https://github.com/Kuska-ssb/ssb#6b0457a8ddd0e86a8f84cffac2b5cb835723822f" dependencies = [ "async-std", "async-stream 0.2.1", @@ -1800,23 +1713,13 @@ dependencies = [ "sysfs_gpio", ] -[[package]] -name = "lock_api" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" -dependencies = [ - "owning_ref", - "scopeguard 0.3.3", -] - [[package]] name = "lock_api" version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75" dependencies = [ - "scopeguard 1.1.0", + "scopeguard", ] [[package]] @@ -1826,7 +1729,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" dependencies = [ "autocfg 1.1.0", - "scopeguard 1.1.0", + "scopeguard", ] [[package]] @@ -2248,31 +2151,12 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" -[[package]] -name = "owning_ref" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ff55baddef9e4ad00f88b6c743a2a8062d4c6ade126c2a528644b8e444d52ce" -dependencies = [ - "stable_deref_trait", -] - [[package]] name = "parking" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" -[[package]] -name = "parking_lot" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337" -dependencies = [ - "lock_api 0.1.5", - "parking_lot_core 0.4.0", -] - [[package]] name = "parking_lot" version = "0.9.0" @@ -2295,19 +2179,6 @@ dependencies = [ "parking_lot_core 0.8.5", ] -[[package]] -name = "parking_lot_core" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" -dependencies = [ - "libc", - "rand 0.6.5", - "rustc_version 0.2.3", - "smallvec 0.6.14", - "winapi 0.3.9", -] - [[package]] name = "parking_lot_core" version = "0.6.2" @@ -2337,21 +2208,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "peach-buttons" -version = "0.1.3" -dependencies = [ - "crossbeam-channel", - "env_logger 0.6.2", - "gpio-cdev", - "jsonrpc-core 11.0.0", - "jsonrpc-pubsub 11.0.0", - "jsonrpc-test 11.0.0", - "jsonrpc-ws-server", - "log 0.4.17", - "snafu 0.4.4", -] - [[package]] name = "peach-config" version = "0.1.25" @@ -2385,7 +2241,7 @@ dependencies = [ "env_logger 0.9.0", "jsonrpc-core 18.0.0", "jsonrpc-http-server 18.0.0", - "jsonrpc-test 18.0.0", + "jsonrpc-test", "log 0.4.17", "peach-stats", "serde_json", @@ -2393,7 +2249,7 @@ dependencies = [ [[package]] name = "peach-lib" -version = "1.3.3" +version = "1.3.4" dependencies = [ "async-std", "chrono", @@ -2463,7 +2319,7 @@ dependencies = [ "env_logger 0.9.0", "jsonrpc-core 18.0.0", "jsonrpc-http-server 18.0.0", - "jsonrpc-test 18.0.0", + "jsonrpc-test", "linux-embedded-hal", "log 0.4.17", "nix 0.11.1", @@ -3007,12 +2863,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "332ffa32bf586782a3efaeb58f127980944bbc8c4d6913a86107ac2a5ab24b28" -[[package]] -name = "scopeguard" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" - [[package]] name = "scopeguard" version = "1.1.0" @@ -3228,17 +3078,6 @@ dependencies = [ "snafu-derive 0.2.3", ] -[[package]] -name = "snafu" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b028158eb06caa8345bee10cccfb25fa632beccf0ef5308832b4fd4b78a7db48" -dependencies = [ - "backtrace", - "doc-comment", - "snafu-derive 0.4.4", -] - [[package]] name = "snafu" version = "0.6.10" @@ -3260,17 +3099,6 @@ dependencies = [ "syn 0.15.44", ] -[[package]] -name = "snafu-derive" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf50aaef500c248a590e2696e8bf8c7620ca2235b9bb90a70363d82dd1abec6a" -dependencies = [ - "proc-macro2 0.4.30", - "quote 0.6.13", - "syn 0.15.44", -] - [[package]] name = "snafu-derive" version = "0.6.10" @@ -3313,12 +3141,6 @@ dependencies = [ "embedded-hal", ] -[[package]] -name = "stable_deref_trait" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" - [[package]] name = "string" version = "0.2.1" @@ -3380,18 +3202,6 @@ dependencies = [ "unicode-xid 0.2.3", ] -[[package]] -name = "synstructure" -version = "0.12.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" -dependencies = [ - "proc-macro2 1.0.38", - "quote 1.0.18", - "syn 1.0.94", - "unicode-xid 0.2.3", -] - [[package]] name = "sysfs_gpio" version = "0.5.4" diff --git a/Cargo.toml b/Cargo.toml index 25471e2..0317b43 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,5 @@ [workspace] - members = [ - "peach-buttons", "peach-oled", "peach-lib", "peach-config", @@ -13,3 +11,4 @@ members = [ "peach-jsonrpc-server", "peach-dyndns-updater" ] + diff --git a/peach-config/src/set_permissions.rs b/peach-config/src/set_permissions.rs index 355e24f..c50ffd0 100644 --- a/peach-config/src/set_permissions.rs +++ b/peach-config/src/set_permissions.rs @@ -1,17 +1,17 @@ use lazy_static::lazy_static; -use peach_lib::config_manager::get_config_value; +use peach_lib::config_manager; use crate::error::PeachConfigError; use crate::utils::cmd; lazy_static! { - pub static ref PEACH_CONFIGDIR: String = get_config_value("PEACH_CONFIGDIR") + pub static ref PEACH_CONFIGDIR: String = config_manager::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_WEBDIR: String = config_manager::get_config_value("PEACH_WEBDIR") + .expect("Failed to load config value for PEACH_WEBDIR"); + pub static ref PEACH_HOMEDIR: String = config_manager::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. diff --git a/peach-lib/Cargo.toml b/peach-lib/Cargo.toml index 028c61a..ee14e50 100644 --- a/peach-lib/Cargo.toml +++ b/peach-lib/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "peach-lib" -version = "1.3.3" +version = "1.3.4" authors = ["Andrew Reid "] edition = "2018" diff --git a/peach-lib/src/config_manager.rs b/peach-lib/src/config_manager.rs index 11ae424..49d6d38 100644 --- a/peach-lib/src/config_manager.rs +++ b/peach-lib/src/config_manager.rs @@ -60,6 +60,7 @@ pub fn get_peach_config_defaults() -> HashMap { ("ADMIN_PASSWORD_HASH", "47"), ("TEMPORARY_PASSWORD_HASH", ""), ("GO_SBOT_DATADIR", "/home/peach/.ssb-go"), + ("GO_SBOT_SERVICE", "go-sbot.service"), ("PEACH_CONFIGDIR", "/var/lib/peachcloud"), ("PEACH_HOMEDIR", "/home/peach"), ("PEACH_WEBDIR", "/usr/share/peach-web"), @@ -131,7 +132,10 @@ pub fn save_peach_config_to_disc( peach_config: HashMap, ) -> Result, PeachError> { // use a file lock to avoid race conditions while saving config - let mut lock = LockFile::open(&*LOCK_FILE_PATH)?; + let mut lock = LockFile::open(&*LOCK_FILE_PATH).map_err(|source| PeachError::Read { + source, + path: LOCK_FILE_PATH.to_string(), + })?; lock.lock()?; // first convert Hashmap to BTreeMap (so that keys are saved in deterministic alphabetical order) diff --git a/peach-lib/src/sbot.rs b/peach-lib/src/sbot.rs index 880479d..e2ddba7 100644 --- a/peach-lib/src/sbot.rs +++ b/peach-lib/src/sbot.rs @@ -2,7 +2,7 @@ use std::{fs, fs::File, io, io::Write, path::PathBuf, process::Command, str}; -use crate::config_manager::get_config_value; +use crate::config_manager; use serde::{Deserialize, Serialize}; use crate::error::PeachError; @@ -67,7 +67,7 @@ impl SbotStatus { // because non-privileged users are able to run systemctl show let info_output = Command::new("systemctl") .arg("show") - .arg("go-sbot.service") + .arg(config_manager::get_config_value("GO_SBOT_SERVICE")?) .arg("--no-page") .output()?; @@ -89,7 +89,7 @@ impl SbotStatus { // because non-privileged users are able to run systemctl status let status_output = Command::new("systemctl") .arg("status") - .arg("go-sbot.service") + .arg(config_manager::get_config_value("GO_SBOT_SERVICE")?) .output()?; let service_status = str::from_utf8(&status_output.stdout)?; @@ -128,7 +128,10 @@ impl SbotStatus { } // get path to blobstore - let blobstore_path = format!("{}/blobs/sha256", get_config_value("GO_SBOT_DATADIR")?); + let blobstore_path = format!( + "{}/blobs/sha256", + config_manager::get_config_value("GO_SBOT_DATADIR")? + ); // determine the size of the blobstore directory in bytes status.blobstore = dir_size(blobstore_path).ok(); @@ -199,9 +202,11 @@ impl Default for SbotConfig { impl SbotConfig { /// Read the go-sbot `config.toml` file from file and deserialize into `SbotConfig`. pub fn read() -> Result { - // 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"); + // determine path of user's go-sbot config.toml + let config_path = format!( + "{}/config.toml", + config_manager::get_config_value("GO_SBOT_DATADIR")? + ); let config_contents = fs::read_to_string(config_path)?; @@ -217,8 +222,11 @@ impl SbotConfig { // convert the provided `SbotConfig` instance to a string let config_string = toml::to_string(&config)?; - // determine path of user's home directory - let config_path = format!("{}/config.toml", get_config_value("GO_SBOT_DATADIR")?); + // determine path of user's go-sbot config.toml + let config_path = format!( + "{}/config.toml", + config_manager::get_config_value("GO_SBOT_DATADIR")? + ); // open config file for writing let mut file = File::create(config_path)?; diff --git a/peach-web/Cargo.toml b/peach-web/Cargo.toml index 11d345b..4e791fe 100644 --- a/peach-web/Cargo.toml +++ b/peach-web/Cargo.toml @@ -9,7 +9,6 @@ repository = "https://github.com/peachcloud/peach-web" readme = "README.md" license = "AGPL-3.0-only" publish = false - [package.metadata.deb] depends = "apache2-utils" extended-description = """\ @@ -27,11 +26,9 @@ assets = [ ["static/images/*", "/usr/share/peach-web/static/images/", "644"], ["README.md", "/usr/share/doc/peach-web/README", "644"], ] - [badges] travis-ci = { repository = "peachcloud/peach-web", branch = "master" } maintenance = { status = "actively-developed" } - [dependencies] async-std = "1.10" base64 = "0.13" diff --git a/peach-web/src/utils/sbot.rs b/peach-web/src/utils/sbot.rs index 5c9bc79..98ab413 100644 --- a/peach-web/src/utils/sbot.rs +++ b/peach-web/src/utils/sbot.rs @@ -3,7 +3,6 @@ use std::{ error::Error, fs, fs::File, - io, io::prelude::*, path::Path, process::{Command, Output}, @@ -16,6 +15,7 @@ use golgi::{ api::friends::RelationshipQuery, blobs, messages::SsbMessageValue, sbot::Keystore, Sbot, }; use log::debug; +use peach_lib::config_manager; use peach_lib::sbot::SbotConfig; use rouille::input::post::BufferedFile; use temporary::Directory; @@ -25,12 +25,13 @@ use crate::{error::PeachWebError, utils::sbot}; // SBOT HELPER FUNCTIONS /// Executes a systemctl command for the go-sbot.service process. -pub fn systemctl_sbot_cmd(cmd: &str) -> io::Result { - Command::new("sudo") +pub fn systemctl_sbot_cmd(cmd: &str) -> Result { + let output = Command::new("sudo") .arg("systemctl") .arg(cmd) - .arg("go-sbot.service") - .output() + .arg(config_manager::get_config_value("GO_SBOT_SERVICE")?) + .output()?; + Ok(output) } /// Executes a systemctl stop command followed by start command. @@ -68,15 +69,18 @@ pub async fn init_sbot_with_config( ) -> Result { debug!("Initialising an sbot client with configuration parameters"); // initialise sbot connection with ip:port and shscap from config file + let key_path = format!( + "{}/secret", + config_manager::get_config_value("GO_SBOT_DATADIR")? + ); let sbot_client = match sbot_config { // TODO: panics if we pass `Some(conf.shscap)` as second arg Some(conf) => { let ip_port = conf.lis.clone(); - Sbot::init(Keystore::GoSbot, Some(ip_port), None).await? + Sbot::init(Keystore::CustomGoSbot(key_path), Some(ip_port), None).await? } - None => Sbot::init(Keystore::GoSbot, None, None).await?, + None => Sbot::init(Keystore::CustomGoSbot(key_path), None, None).await?, }; - Ok(sbot_client) }