From b8f394b9018dcc6e6ba8fc9705a22250d0b43e68 Mon Sep 17 00:00:00 2001 From: notplants Date: Wed, 22 Dec 2021 09:59:20 -0500 Subject: [PATCH] Debugging dyndns --- .gitignore | 1 + peach-lib/src/config_manager.rs | 3 +++ peach-lib/src/dyndns_client.rs | 20 ++++++++++++++------ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 32758b3..41e4e65 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ target *peachdeploy.sh *vpsdeploy.sh +*bindeploy.sh diff --git a/peach-lib/src/config_manager.rs b/peach-lib/src/config_manager.rs index 3aab392..7f48247 100644 --- a/peach-lib/src/config_manager.rs +++ b/peach-lib/src/config_manager.rs @@ -29,6 +29,8 @@ pub struct PeachConfig { #[serde(default)] pub dyn_dns_server_address: String, #[serde(default)] + pub dyn_nameserver: String, + #[serde(default)] pub dyn_tsig_key_path: String, #[serde(default)] // default is false pub dyn_enabled: bool, @@ -71,6 +73,7 @@ pub fn load_peach_config() -> Result { 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_tsig_key_path: "".to_string(), dyn_enabled: false, ssb_admin_ids: Vec::new(), diff --git a/peach-lib/src/dyndns_client.rs b/peach-lib/src/dyndns_client.rs index 3538590..17379cd 100644 --- a/peach-lib/src/dyndns_client.rs +++ b/peach-lib/src/dyndns_client.rs @@ -16,6 +16,7 @@ use std::{ process::{Command, Stdio}, str::FromStr, }; +use std::ffi::OsStr; use chrono::prelude::*; use jsonrpc_client_core::{expand_params, jsonrpc_client}; @@ -113,7 +114,7 @@ fn get_public_ip_address() -> Result { /// Reads dyndns configurations from config.yml /// and then uses nsupdate to update the IP address for the configured domain pub fn dyndns_update_ip() -> Result { - info!("Running dyndns_update_ip"); + let peach_config = load_peach_config()?; info!( "Using config: @@ -121,21 +122,27 @@ pub fn dyndns_update_ip() -> Result { dyn_domain: {:?} dyn_dns_server_address: {:?} dyn_enabled: {:?} + dyn_nameserver: {:?} ", peach_config.dyn_tsig_key_path, peach_config.dyn_domain, peach_config.dyn_dns_server_address, peach_config.dyn_enabled, + peach_config.dyn_nameserver, ); if !peach_config.dyn_enabled { info!("dyndns is not enabled, not updating"); Ok(false) } else { // call nsupdate passing appropriate configs - let mut nsupdate_command = Command::new("/usr/bin/nsupdate") + let mut nsupdate_command = Command::new("/usr/bin/nsupdate"); + nsupdate_command .arg("-k") .arg(&peach_config.dyn_tsig_key_path) - .arg("-v") + .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()?; // pass nsupdate commands via stdin @@ -148,19 +155,20 @@ pub fn dyndns_update_ip() -> Result { update delete {DOMAIN} A update add {DOMAIN} 30 A {PUBLIC_IP_ADDRESS} send", - NAMESERVER = "ns.peachcloud.org", + NAMESERVER = peach_config.dyn_nameserver, ZONE = peach_config.dyn_domain, DOMAIN = peach_config.dyn_domain, PUBLIC_IP_ADDRESS = public_ip_address, ); - let mut nsupdate_stdin = nsupdate_command.stdin.take().ok_or(PeachError::NsUpdate { + 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_command.wait_with_output()?; + let nsupdate_output = nsupdate_child.wait_with_output()?; info!("nsupdate output: {:?}", nsupdate_output); // We only return a successful result if nsupdate was successful if nsupdate_output.status.success() {