diff --git a/Cargo.lock b/Cargo.lock index 34bcd48..6622ccc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2432,7 +2432,7 @@ dependencies = [ [[package]] name = "peach-dyndns-updater" -version = "0.1.7" +version = "0.1.8" dependencies = [ "env_logger 0.6.2", "log 0.4.14", @@ -2541,7 +2541,7 @@ dependencies = [ [[package]] name = "peach-web" -version = "0.4.16" +version = "0.4.17" dependencies = [ "env_logger 0.8.4", "log 0.4.14", diff --git a/peach-dyndns-updater/Cargo.toml b/peach-dyndns-updater/Cargo.toml index 483c9fb..d60c720 100644 --- a/peach-dyndns-updater/Cargo.toml +++ b/peach-dyndns-updater/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "peach-dyndns-updater" -version = "0.1.7" +version = "0.1.8" authors = ["Max Fowler "] edition = "2018" description = "Sytemd timer which keeps a dynamic dns subdomain up to date with the latest device IP using nsupdate." diff --git a/peach-lib/Cargo.toml b/peach-lib/Cargo.toml index 11d696a..aa821d9 100644 --- a/peach-lib/Cargo.toml +++ b/peach-lib/Cargo.toml @@ -17,3 +17,4 @@ rust-crypto = "0.2.36" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" serde_yaml = "0.8" + diff --git a/peach-lib/src/config_manager.rs b/peach-lib/src/config_manager.rs index 7f48247..00fd104 100644 --- a/peach-lib/src/config_manager.rs +++ b/peach-lib/src/config_manager.rs @@ -17,6 +17,11 @@ pub const YAML_PATH: &str = "/var/lib/peachcloud/config.yml"; // lock file (used to avoid race conditions during config reading & writing) pub const LOCK_FILE_PATH: &str = "/var/lib/peachcloud/config.lock"; +// default values +pub const DEFAULT_DYN_SERVER_ADDRESS: &str = "http://dynserver.dyn.peachcloud.org"; +pub const DEFAULT_DYN_NAMESERVER: &str = "ns.peachcloud.org"; + + // we make use of Serde default values in order to make PeachCloud // robust and keep running even with a not fully complete config.yml // main type which represents all peachcloud configurations @@ -29,6 +34,8 @@ pub struct PeachConfig { #[serde(default)] pub dyn_dns_server_address: String, #[serde(default)] + pub dyn_use_custom_server: bool, + #[serde(default)] pub dyn_nameserver: String, #[serde(default)] pub dyn_tsig_key_path: String, @@ -72,8 +79,9 @@ pub fn load_peach_config() -> Result { peach_config = PeachConfig { external_domain: "".to_string(), dyn_domain: "".to_string(), - dyn_dns_server_address: "http://dynserver.dyn.peachcloud.org".to_string(), - dyn_nameserver: "ns.peachcloud.org".to_string(), + dyn_dns_server_address: DEFAULT_DYN_SERVER_ADDRESS.to_string(), + dyn_use_custom_server: false, + dyn_nameserver: DEFAULT_DYN_NAMESERVER.to_string(), dyn_tsig_key_path: "".to_string(), dyn_enabled: false, ssb_admin_ids: Vec::new(), @@ -127,7 +135,15 @@ pub fn get_peachcloud_domain() -> Result, PeachError> { pub fn get_dyndns_server_address() -> Result { let peach_config = load_peach_config()?; - Ok(peach_config.dyn_dns_server_address) + // if the user is using a custom dyn server then load the address from the config + if peach_config.dyn_use_custom_server { + Ok(peach_config.dyn_dns_server_address) + } + // otherwise hardcode the address + else { + Ok(DEFAULT_DYN_SERVER_ADDRESS.to_string()) + } + } pub fn set_dyndns_enabled_value(enabled_value: bool) -> Result { diff --git a/peach-lib/src/dyndns_client.rs b/peach-lib/src/dyndns_client.rs index 17379cd..1698ad0 100644 --- a/peach-lib/src/dyndns_client.rs +++ b/peach-lib/src/dyndns_client.rs @@ -12,6 +12,7 @@ use std::{ fs, fs::OpenOptions, + fs::File, io::Write, process::{Command, Stdio}, str::FromStr, @@ -64,6 +65,7 @@ pub fn register_domain(domain: &str) -> std::result::Result debug!("Creating HTTP transport for dyndns client."); let transport = HttpTransport::new().standalone()?; let http_server = get_dyndns_server_address()?; + info!("Using dyndns http server address: {:?}", http_server); debug!("Creating HTTP transport handle on {}.", &http_server); let transport_handle = transport.handle(&http_server)?; info!("Creating client for peach-dyndns service."); @@ -140,11 +142,10 @@ pub fn dyndns_update_ip() -> Result { .arg("-k") .arg(&peach_config.dyn_tsig_key_path) .arg("-v"); - let args: Vec<&OsStr> = nsupdate_command.get_args().collect(); - info!("nsupdate_args: {:?}", args); - let mut nsupdate_child = nsupdate_command - .stdin(Stdio::piped()) - .spawn()?; + // info!("nsupdate_args: {:?}", args); + // let mut nsupdate_child = nsupdate_command + // .stdin(Stdio::piped()) + // .spawn()?; // pass nsupdate commands via stdin let public_ip_address = get_public_ip_address()?; info!("found public ip address: {}", public_ip_address); @@ -161,15 +162,14 @@ pub fn dyndns_update_ip() -> Result { PUBLIC_IP_ADDRESS = public_ip_address, ); info!("ns_commands: {:?}", ns_commands); - let mut nsupdate_stdin = nsupdate_child.stdin.take().ok_or(PeachError::NsUpdate { - msg: "unable to capture stdin handle for `nsupdate` command".to_string(), - })?; - write!(nsupdate_stdin, "{}", ns_commands).map_err(|source| PeachError::Write { - source, - path: peach_config.dyn_tsig_key_path.to_string(), - })?; - let nsupdate_output = nsupdate_child.wait_with_output()?; - info!("nsupdate output: {:?}", nsupdate_output); + info!("creating nsupdate temp file"); + let temp_file_path = "/var/lib/peachcloud/nsupdate.sh"; + // write ns_commands to temp_file + fs::write(temp_file_path, ns_commands)?; + nsupdate_command.arg(temp_file_path); + let nsupdate_output = nsupdate_command.output()?; + let args: Vec<&OsStr> = nsupdate_command.get_args().collect(); + info!("nsupdate command: {:?}", args); // We only return a successful result if nsupdate was successful if nsupdate_output.status.success() { info!("nsupdate succeeded, returning ok"); diff --git a/peach-web/Cargo.toml b/peach-web/Cargo.toml index f514236..860508d 100644 --- a/peach-web/Cargo.toml +++ b/peach-web/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "peach-web" -version = "0.4.16" +version = "0.4.17" authors = ["Andrew Reid "] edition = "2018" description = "peach-web is a web application which provides a web interface for monitoring and interacting with the PeachCloud device. This allows administration of the single-board computer (ie. Raspberry Pi) running PeachCloud, as well as the ssb-server and related plugins." diff --git a/peach-web/README.md b/peach-web/README.md index 018ab8d..80f123f 100644 --- a/peach-web/README.md +++ b/peach-web/README.md @@ -97,6 +97,20 @@ Remove configuration files (not removed with `apt-get remove`): `peach-web` is built on the Rocket webserver and Tera templating engine. It presents a web interface for interacting with the device. HTML is rendered server-side. Request handlers call JSON-RPC microservices and serve HTML and assets. A JSON API is exposed for remote calls and dynamic client-side content updates (via plain JavaScript following unobstructive design principles). Each Tera template is passed a context object. In the case of Rust, this object is a `struct` and must implement `Serialize`. The fields of the context object are available in the context of the template to be rendered. +### Configuration + +Configuration variables are stored in /var/lib/peachcloud/config.yml. +Peach-web also updates this file when changes are made to configurations via +the web interface. peach-web has no database, so all configurations are stored in this file. + +#### Dynamic DNS Configuration + +Most users will want to use the default PeachCloud dynamic dns server. +If the config dyn_use_custom_server=false, then default values will be used. +If the config dyn_use_custom_server=true, then a value must also be set for dyn_dns_server_address (e.g. "http://peachdynserver.commoninternet.net"). +This value is the URL of the instance of peach-dyndns-server that requests will be sent to for domain registration. +Using a custom value can here can be useful for testing. + ### Licensing AGPL-3.0