merge latest changes from main
continuous-integration/drone/pr Build is failing
Details
continuous-integration/drone/pr Build is failing
Details
This commit is contained in:
commit
98497fa5ae
|
@ -1071,8 +1071,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad"
|
checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
|
"js-sys",
|
||||||
"libc",
|
"libc",
|
||||||
"wasi 0.10.2+wasi-snapshot-preview1",
|
"wasi 0.10.2+wasi-snapshot-preview1",
|
||||||
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -2042,6 +2044,9 @@ name = "nanorand"
|
||||||
version = "0.6.1"
|
version = "0.6.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "729eb334247daa1803e0a094d0a5c55711b85571179f5ec6e53eccfdf7008958"
|
checksum = "729eb334247daa1803e0a094d0a5c55711b85571179f5ec6e53eccfdf7008958"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom 0.2.6",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nb"
|
name = "nb"
|
||||||
|
@ -2349,7 +2354,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "peach-config"
|
name = "peach-config"
|
||||||
version = "0.1.23"
|
version = "0.1.25"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"env_logger 0.6.2",
|
"env_logger 0.6.2",
|
||||||
|
@ -2388,7 +2393,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "peach-lib"
|
name = "peach-lib"
|
||||||
version = "1.3.2"
|
version = "1.3.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-std",
|
"async-std",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "peach-config"
|
name = "peach-config"
|
||||||
version = "0.1.23"
|
version = "0.1.25"
|
||||||
authors = ["Andrew Reid <gnomad@cryptolab.net>", "Max Fowler <max@mfowler.info>"]
|
authors = ["Andrew Reid <gnomad@cryptolab.net>", "Max Fowler <max@mfowler.info>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Command line tool for installing, updating and configuring PeachCloud"
|
description = "Command line tool for installing, updating and configuring PeachCloud"
|
||||||
|
|
|
@ -1,23 +1,30 @@
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
|
use peach_lib::config_manager::get_config_value;
|
||||||
|
|
||||||
use crate::error::PeachConfigError;
|
use crate::error::PeachConfigError;
|
||||||
use crate::utils::cmd;
|
use crate::utils::cmd;
|
||||||
|
|
||||||
/// All configs are stored in this folder, and should be read/writeable by peach group
|
lazy_static! {
|
||||||
/// so they can be read and written by all PeachCloud services.
|
pub static ref PEACH_CONFIGDIR: String = get_config_value("PEACH_CONFIGDIR")
|
||||||
pub const CONFIGS_DIR: &str = "/var/lib/peachcloud";
|
.expect("Failed to load config value for PEACH_CONFIGDIR");
|
||||||
pub const PEACH_WEB_DIR: &str = "/usr/share/peach-web";
|
pub static ref PEACH_WEBDIR: String =
|
||||||
pub const PEACH_HOME_DIR: &str = "/home/peach";
|
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.
|
/// Utility function to set correct file permissions on the PeachCloud device.
|
||||||
/// Accidentally changing file permissions is a fairly common thing to happen,
|
/// 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.
|
/// so this is a useful CLI function for quickly correcting anything that may be out of order.
|
||||||
pub fn set_permissions() -> Result<(), PeachConfigError> {
|
pub fn set_permissions() -> Result<(), PeachConfigError> {
|
||||||
println!("[ UPDATING FILE PERMISSIONS ON PEACHCLOUD DEVICE ]");
|
println!("[ UPDATING FILE PERMISSIONS ON PEACHCLOUD DEVICE ]");
|
||||||
cmd(&["chmod", "-R", "u+rwX,g+rwX", CONFIGS_DIR])?;
|
cmd(&["chmod", "-R", "u+rwX,g+rwX", &PEACH_CONFIGDIR])?;
|
||||||
cmd(&["chown", "-R", "peach", CONFIGS_DIR])?;
|
cmd(&["chown", "-R", "peach:peach", &PEACH_CONFIGDIR])?;
|
||||||
cmd(&["chgrp", "-R", "peach", CONFIGS_DIR])?;
|
cmd(&["chmod", "-R", "u+rwX,g+rwX", &PEACH_WEBDIR])?;
|
||||||
cmd(&["chmod", "-R", "u+rwX,g+rwX", PEACH_WEB_DIR])?;
|
cmd(&["chown", "-R", "peach:peach", &PEACH_WEBDIR])?;
|
||||||
cmd(&["chown", "-R", "peach:peach", PEACH_WEB_DIR])?;
|
cmd(&["chmod", "-R", "u+rwX,g+rwX", &PEACH_HOMEDIR])?;
|
||||||
cmd(&["chown", "-R", "peach:peach", PEACH_HOME_DIR])?;
|
cmd(&["chown", "-R", "peach:peach", &PEACH_HOMEDIR])?;
|
||||||
println!("[ PERMISSIONS SUCCESSFULLY UPDATED ]");
|
println!("[ PERMISSIONS SUCCESSFULLY UPDATED ]");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "peach-lib"
|
name = "peach-lib"
|
||||||
version = "1.3.2"
|
version = "1.3.3"
|
||||||
authors = ["Andrew Reid <glyph@mycelial.technology>"]
|
authors = ["Andrew Reid <glyph@mycelial.technology>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ jsonrpc-client-core = "0.5"
|
||||||
jsonrpc-client-http = "0.5"
|
jsonrpc-client-http = "0.5"
|
||||||
jsonrpc-core = "8.0"
|
jsonrpc-core = "8.0"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
nanorand = "0.6"
|
nanorand = { version = "0.6", features = ["getrandom"] }
|
||||||
regex = "1"
|
regex = "1"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
|
|
@ -41,34 +41,35 @@ lazy_static! {
|
||||||
// Default values for PeachCloud configs which are used for any key which is not set
|
// 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.
|
// via an environment variable or in a saved configuration file.
|
||||||
pub fn get_peach_config_defaults() -> HashMap<String, String> {
|
pub fn get_peach_config_defaults() -> HashMap<String, String> {
|
||||||
let peach_config_defaults: HashMap<String, String> = HashMap::from([
|
let peach_config_defaults: HashMap<&str, &str> = HashMap::from([
|
||||||
("STANDALONE_MODE".to_string(), "true".to_string()),
|
("STANDALONE_MODE", "true"),
|
||||||
("DISABLE_AUTH".to_string(), "false".to_string()),
|
("DISABLE_AUTH", "false"),
|
||||||
("ADDR".to_string(), "127.0.0.1".to_string()),
|
("ADDR", "127.0.0.1"),
|
||||||
("PORT".to_string(), "8000".to_string()),
|
("PORT", "8000"),
|
||||||
("EXTERNAL_DOMAIN".to_string(), "".to_string()),
|
("EXTERNAL_DOMAIN", ""),
|
||||||
("DYN_DOMAIN".to_string(), "".to_string()),
|
("DYN_DOMAIN", ""),
|
||||||
(
|
(
|
||||||
"DYN_DNS_SERVER_ADDRESS".to_string(),
|
"DYN_DNS_SERVER_ADDRESS",
|
||||||
"http://dynserver.dyn.peachcloud.org".to_string(),
|
"http://dynserver.dyn.peachcloud.org",
|
||||||
),
|
|
||||||
("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_USE_CUSTOM_SERVER", "true"),
|
||||||
|
("DYN_TSIG_KEY_PATH", ""),
|
||||||
|
("DYN_NAMESERVER", "ns.peachcloud.org"),
|
||||||
|
("DYN_ENABLED", "false"),
|
||||||
|
("SSB_ADMIN_IDS", ""),
|
||||||
|
("ADMIN_PASSWORD_HASH", "47"),
|
||||||
|
("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"),
|
||||||
]);
|
]);
|
||||||
peach_config_defaults
|
// convert HashMap<&str, &str> to HashMap<String, String> and return
|
||||||
|
let pc_defaults: HashMap<String, String> = peach_config_defaults
|
||||||
|
.iter()
|
||||||
|
.map(|(key, val)| (key.to_string(), val.to_string()))
|
||||||
|
.collect();
|
||||||
|
pc_defaults
|
||||||
}
|
}
|
||||||
|
|
||||||
// primary interface for getting config values
|
// primary interface for getting config values
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use std::{fs, fs::File, io, io::Write, path::PathBuf, process::Command, str};
|
use std::{fs, fs::File, io, io::Write, path::PathBuf, process::Command, str};
|
||||||
|
|
||||||
|
use crate::config_manager::get_config_value;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::error::PeachError;
|
use crate::error::PeachError;
|
||||||
|
@ -126,11 +127,8 @@ impl SbotStatus {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// determine path of user's home directory
|
// get path to blobstore
|
||||||
let mut blobstore_path = dirs::home_dir().ok_or(PeachError::HomeDir)?;
|
let blobstore_path = format!("{}/blobs/sha256", get_config_value("GO_SBOT_DATADIR")?);
|
||||||
|
|
||||||
// append the blobstore path
|
|
||||||
blobstore_path.push(".ssb-go/blobs/sha256");
|
|
||||||
|
|
||||||
// determine the size of the blobstore directory in bytes
|
// determine the size of the blobstore directory in bytes
|
||||||
status.blobstore = dir_size(blobstore_path).ok();
|
status.blobstore = dir_size(blobstore_path).ok();
|
||||||
|
@ -220,8 +218,7 @@ impl SbotConfig {
|
||||||
let config_string = toml::to_string(&config)?;
|
let config_string = toml::to_string(&config)?;
|
||||||
|
|
||||||
// determine path of user's home directory
|
// determine path of user's home directory
|
||||||
let mut config_path = dirs::home_dir().ok_or(PeachError::HomeDir)?;
|
let config_path = format!("{}/config.toml", get_config_value("GO_SBOT_DATADIR")?);
|
||||||
config_path.push(".ssb-go/config.toml");
|
|
||||||
|
|
||||||
// open config file for writing
|
// open config file for writing
|
||||||
let mut file = File::create(config_path)?;
|
let mut file = File::create(config_path)?;
|
||||||
|
|
|
@ -1,53 +1,31 @@
|
||||||
//! Define the configuration parameters for the web application.
|
//! Define the configuration parameters for the web application.
|
||||||
//!
|
//!
|
||||||
//! Sets default values and updates them if the corresponding environment
|
//! These configs are loaded using peach-lib::config_manager which checks config keys from
|
||||||
//! variables have been set.
|
//! 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
|
pub struct ServerConfig {
|
||||||
const ENV_VARS: [&str; 4] = ["STANDALONE_MODE", "DISABLE_AUTH", "ADDR", "PORT"];
|
|
||||||
|
|
||||||
pub struct Config {
|
|
||||||
pub standalone_mode: bool,
|
pub standalone_mode: bool,
|
||||||
pub disable_auth: bool,
|
pub disable_auth: bool,
|
||||||
pub addr: String,
|
pub addr: String,
|
||||||
pub port: String,
|
pub port: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Config {
|
impl ServerConfig {
|
||||||
fn default() -> Self {
|
pub fn new() -> Result<ServerConfig, PeachWebError> {
|
||||||
Self {
|
|
||||||
standalone_mode: true,
|
|
||||||
disable_auth: false,
|
|
||||||
addr: "127.0.0.1".to_string(),
|
|
||||||
port: "8000".to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Config {
|
|
||||||
pub fn new() -> Config {
|
|
||||||
// define default config values
|
// define default config values
|
||||||
let mut config = Config::default();
|
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")?,
|
||||||
|
port: get_config_value("PORT")?,
|
||||||
|
};
|
||||||
|
|
||||||
// check for the environment variables in our config
|
Ok(config)
|
||||||
for key in ENV_VARS {
|
|
||||||
// if a variable (key) has been set, check the value
|
|
||||||
if let Ok(val) = env::var(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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,12 +29,13 @@ use lazy_static::lazy_static;
|
||||||
use log::info;
|
use log::info;
|
||||||
|
|
||||||
// crate-local dependencies
|
// crate-local dependencies
|
||||||
use config::Config;
|
use config::ServerConfig;
|
||||||
use utils::theme::Theme;
|
use utils::theme::Theme;
|
||||||
|
|
||||||
// load the application configuration and create the theme switcher
|
// load the application configuration and create the theme switcher
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref CONFIG: Config = Config::new();
|
static ref SERVER_CONFIG: ServerConfig =
|
||||||
|
ServerConfig::new().expect("Failed to load rouille configuration values on server startup");
|
||||||
static ref THEME: RwLock<Theme> = RwLock::new(Theme::Light);
|
static ref THEME: RwLock<Theme> = RwLock::new(Theme::Light);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ fn main() {
|
||||||
|
|
||||||
// set ip address / hostname and port for the webserver
|
// set ip address / hostname and port for the webserver
|
||||||
// defaults to "127.0.0.1:8000"
|
// defaults to "127.0.0.1:8000"
|
||||||
let addr_and_port = format!("{}:{}", CONFIG.addr, 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
|
// store the session data for each session and a hashmap that associates
|
||||||
// each session id with the data
|
// each session id with the data
|
||||||
|
@ -67,7 +68,7 @@ fn main() {
|
||||||
// with a name of "SID" and a duration of one hour (3600 seconds)
|
// with a name of "SID" and a duration of one hour (3600 seconds)
|
||||||
rouille::session::session(request, "SID", 3600, |session| {
|
rouille::session::session(request, "SID", 3600, |session| {
|
||||||
// if the "DISABLE_AUTH" env var is true, authenticate the 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 SERVER_CONFIG.disable_auth {
|
||||||
Some(SessionData {
|
Some(SessionData {
|
||||||
_login: "success".to_string(),
|
_login: "success".to_string(),
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use maud::{html, PreEscaped};
|
use maud::{html, PreEscaped};
|
||||||
|
|
||||||
use crate::{templates, utils::theme, CONFIG};
|
use crate::{templates, utils::theme, SERVER_CONFIG};
|
||||||
|
|
||||||
// ROUTE: /settings
|
// ROUTE: /settings
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ pub fn build_template() -> PreEscaped<String> {
|
||||||
(PreEscaped("<!-- BUTTONS -->"))
|
(PreEscaped("<!-- BUTTONS -->"))
|
||||||
div id="settingsButtons" {
|
div id="settingsButtons" {
|
||||||
// render the network settings button if we're not in standalone mode
|
// render the network settings button if we're not in standalone mode
|
||||||
@if !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="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" }
|
a id="scuttlebutt" class="button button-primary center" href="/settings/scuttlebutt" title="Scuttlebutt Settings" { "Scuttlebutt" }
|
||||||
|
|
Loading…
Reference in New Issue