merge changes from main
continuous-integration/drone/pr Build is failing Details

This commit is contained in:
glyph 2022-06-16 11:10:32 +01:00
commit 11e94fa421
8 changed files with 198 additions and 382 deletions

509
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -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"
]

View File

@ -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.

View File

@ -1,6 +1,6 @@
[package]
name = "peach-lib"
version = "1.3.3"
version = "1.3.4"
authors = ["Andrew Reid <glyph@mycelial.technology>"]
edition = "2018"

View File

@ -60,6 +60,7 @@ pub fn get_peach_config_defaults() -> HashMap<String, String> {
("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<String, String>,
) -> Result<HashMap<String, String>, 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)

View File

@ -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<Self, PeachError> {
// 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)?;

View File

@ -30,7 +30,7 @@ pub fn build_template(request: &Request) -> PreEscaped<String> {
form id="sendPasswordReset" action="/auth/temporary" method="post" {
div id="buttonDiv" {
input class="button button-primary center" style="margin-top: 1rem;" type="submit" value="Send Temporary Password" title="Send temporary password to Scuttlebutt admin(s)";
a href="/auth/reset_password" class="button button-primary center" title="Set a new password using the temporary password" {
a href="/auth/reset" class="button button-primary center" title="Set a new password using the temporary password" {
"Set New Password"
}
}

View File

@ -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<Output> {
Command::new("sudo")
pub fn systemctl_sbot_cmd(cmd: &str) -> Result<Output, PeachWebError> {
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<Sbot, PeachWebError> {
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)
}