Add changepassword function to peach-config
This commit is contained in:
parent
1c26cb70fa
commit
3399a3c80f
|
@ -1,2 +1,4 @@
|
||||||
.idea
|
.idea
|
||||||
target
|
target
|
||||||
|
*peachdeploy.sh
|
||||||
|
*vpsdeploy.sh
|
||||||
|
|
|
@ -412,26 +412,6 @@ version = "0.4.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f92cfa0fd5690b3cf8c1ef2cabbd9b7ef22fa53cf5e1f92b05103f6d5d1cf6e7"
|
checksum = "f92cfa0fd5690b3cf8c1ef2cabbd9b7ef22fa53cf5e1f92b05103f6d5d1cf6e7"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "const_format"
|
|
||||||
version = "0.2.22"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "22bc6cd49b0ec407b680c3e380182b6ac63b73991cb7602de350352fc309b614"
|
|
||||||
dependencies = [
|
|
||||||
"const_format_proc_macros",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "const_format_proc_macros"
|
|
||||||
version = "0.2.22"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ef196d5d972878a48da7decb7686eded338b4858fbabeed513d63a7c98b2b82d"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2 1.0.33",
|
|
||||||
"quote 1.0.10",
|
|
||||||
"unicode-xid 0.2.2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "convert_case"
|
name = "convert_case"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
|
@ -1553,19 +1533,6 @@ dependencies = [
|
||||||
"serde_json",
|
"serde_json",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "jsonrpc-core"
|
|
||||||
version = "14.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a0747307121ffb9703afd93afbd0fb4f854c38fb873f2c8b90e0e902f27c7b62"
|
|
||||||
dependencies = [
|
|
||||||
"futures 0.1.31",
|
|
||||||
"log 0.4.14",
|
|
||||||
"serde 1.0.130",
|
|
||||||
"serde_derive",
|
|
||||||
"serde_json",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jsonrpc-core"
|
name = "jsonrpc-core"
|
||||||
version = "18.0.0"
|
version = "18.0.0"
|
||||||
|
@ -2448,13 +2415,15 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "peach-config"
|
name = "peach-config"
|
||||||
version = "0.1.12"
|
version = "0.1.14"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"env_logger 0.6.2",
|
"env_logger 0.6.2",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"log 0.4.14",
|
"log 0.4.14",
|
||||||
|
"peach-lib",
|
||||||
"regex",
|
"regex",
|
||||||
|
"rpassword",
|
||||||
"serde 1.0.130",
|
"serde 1.0.130",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"snafu 0.6.10",
|
"snafu 0.6.10",
|
||||||
|
@ -2559,26 +2528,6 @@ dependencies = [
|
||||||
"tinybmp",
|
"tinybmp",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "peach-probe"
|
|
||||||
version = "0.1.2"
|
|
||||||
dependencies = [
|
|
||||||
"clap",
|
|
||||||
"const_format",
|
|
||||||
"env_logger 0.6.2",
|
|
||||||
"jsonrpc-client-core",
|
|
||||||
"jsonrpc-client-http",
|
|
||||||
"jsonrpc-core 14.2.0",
|
|
||||||
"log 0.4.14",
|
|
||||||
"peach-lib",
|
|
||||||
"regex",
|
|
||||||
"serde 1.0.130",
|
|
||||||
"serde_derive",
|
|
||||||
"serde_json",
|
|
||||||
"snafu 0.4.4",
|
|
||||||
"structopt",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "peach-stats"
|
name = "peach-stats"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
|
@ -3273,6 +3222,16 @@ dependencies = [
|
||||||
"uncased",
|
"uncased",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rpassword"
|
||||||
|
version = "5.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ffc936cf8a7ea60c58f030fd36a612a48f440610214dc54bc36431f9ea0c3efb"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"winapi 0.3.9",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rust-crypto"
|
name = "rust-crypto"
|
||||||
version = "0.2.36"
|
version = "0.2.36"
|
||||||
|
|
|
@ -11,6 +11,5 @@ members = [
|
||||||
"peach-monitor",
|
"peach-monitor",
|
||||||
"peach-stats",
|
"peach-stats",
|
||||||
"peach-jsonrpc-server",
|
"peach-jsonrpc-server",
|
||||||
"peach-probe",
|
|
||||||
"peach-dyndns-updater"
|
"peach-dyndns-updater"
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "peach-config"
|
name = "peach-config"
|
||||||
version = "0.1.12"
|
version = "0.1.14"
|
||||||
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"
|
||||||
|
@ -35,3 +35,5 @@ structopt = "0.3.13"
|
||||||
clap = "2.33.3"
|
clap = "2.33.3"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
|
peach-lib = { path = "../peach-lib" }
|
||||||
|
rpassword = "5.0"
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
use crate::error::PeachConfigError;
|
||||||
|
use crate::ChangePasswordOpts;
|
||||||
|
use peach_lib::password_utils::set_new_password;
|
||||||
|
|
||||||
|
|
||||||
|
/// Utility function to set the admin password for peach-web from the command-line.
|
||||||
|
pub fn set_peach_web_password(opts: ChangePasswordOpts) -> Result<(), PeachConfigError> {
|
||||||
|
match opts.password {
|
||||||
|
// read password from CLI arg
|
||||||
|
Some(password) => {
|
||||||
|
set_new_password(&password)
|
||||||
|
.map_err(|err| PeachConfigError::ChangePasswordError { source: err })?;
|
||||||
|
println!(
|
||||||
|
"Your new password has been set for peach-web. You can login through the \
|
||||||
|
web interface with username admin."
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
// read password from tty
|
||||||
|
None => {
|
||||||
|
let pass1 = rpassword::read_password_from_tty(Some("New password: "))?;
|
||||||
|
let pass2 = rpassword::read_password_from_tty(Some("Confirm password: "))?;
|
||||||
|
if pass1 != pass2 {
|
||||||
|
Err(PeachConfigError::InvalidPassword)
|
||||||
|
} else {
|
||||||
|
set_new_password(&pass1)
|
||||||
|
.map_err(|err| PeachConfigError::ChangePasswordError { source: err })?;
|
||||||
|
println!(
|
||||||
|
"Your new password has been set for peach-web. You can login through the \
|
||||||
|
web interface with username admin."
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
#![allow(clippy::nonstandard_macro_braces)]
|
#![allow(clippy::nonstandard_macro_braces)]
|
||||||
|
use peach_lib::error::PeachError;
|
||||||
pub use snafu::ResultExt;
|
pub use snafu::ResultExt;
|
||||||
use snafu::Snafu;
|
use snafu::Snafu;
|
||||||
|
|
||||||
|
@ -30,6 +31,10 @@ pub enum PeachConfigError {
|
||||||
},
|
},
|
||||||
#[snafu(display("Error serializing json: {}", source))]
|
#[snafu(display("Error serializing json: {}", source))]
|
||||||
SerdeError { source: serde_json::Error },
|
SerdeError { source: serde_json::Error },
|
||||||
|
#[snafu(display("Error changing password: {}", source))]
|
||||||
|
ChangePasswordError { source: PeachError },
|
||||||
|
#[snafu(display("Entered passwords did not match. Please try again."))]
|
||||||
|
InvalidPassword,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<std::io::Error> for PeachConfigError {
|
impl From<std::io::Error> for PeachConfigError {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
mod change_password;
|
||||||
mod constants;
|
mod constants;
|
||||||
mod error;
|
mod error;
|
||||||
mod generate_manifest;
|
mod generate_manifest;
|
||||||
|
@ -12,6 +13,7 @@ use log::error;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
|
use crate::change_password::set_peach_web_password;
|
||||||
use crate::generate_manifest::generate_manifest;
|
use crate::generate_manifest::generate_manifest;
|
||||||
use crate::setup_peach::setup_peach;
|
use crate::setup_peach::setup_peach;
|
||||||
use crate::update::update;
|
use crate::update::update;
|
||||||
|
@ -44,6 +46,10 @@ enum PeachConfig {
|
||||||
/// Updates all PeachCloud microservices
|
/// Updates all PeachCloud microservices
|
||||||
#[structopt(name = "update")]
|
#[structopt(name = "update")]
|
||||||
Update(UpdateOpts),
|
Update(UpdateOpts),
|
||||||
|
|
||||||
|
/// Changes the password for the peach-web interface
|
||||||
|
#[structopt(name = "changepassword")]
|
||||||
|
ChangePassword(ChangePasswordOpts),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(StructOpt, Debug)]
|
#[derive(StructOpt, Debug)]
|
||||||
|
@ -76,6 +82,14 @@ pub struct UpdateOpts {
|
||||||
list: bool,
|
list: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(StructOpt, Debug)]
|
||||||
|
pub struct ChangePasswordOpts {
|
||||||
|
/// Optional argument to specify password as CLI argument
|
||||||
|
/// if not specified, this command asks for user input for the passwords
|
||||||
|
#[structopt(short, long)]
|
||||||
|
password: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
arg_enum! {
|
arg_enum! {
|
||||||
/// enum options for real-time clock choices
|
/// enum options for real-time clock choices
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -121,6 +135,15 @@ fn main() {
|
||||||
error!("peach-config encountered an error during update: {}", err)
|
error!("peach-config encountered an error during update: {}", err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
PeachConfig::ChangePassword(opts) => match set_peach_web_password(opts) {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(err) => {
|
||||||
|
error!(
|
||||||
|
"peach-config encountered an error during password update: {}",
|
||||||
|
err
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue