Debugging dyndns

This commit is contained in:
notplants 2021-12-22 09:59:20 -05:00
parent 29cc40be48
commit b8f394b901
3 changed files with 18 additions and 6 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
target
*peachdeploy.sh
*vpsdeploy.sh
*bindeploy.sh

View File

@ -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<PeachConfig, PeachError> {
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(),

View File

@ -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<String, PeachError> {
/// 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<bool, PeachError> {
info!("Running dyndns_update_ip");
let peach_config = load_peach_config()?;
info!(
"Using config:
@ -121,21 +122,27 @@ pub fn dyndns_update_ip() -> Result<bool, PeachError> {
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<bool, PeachError> {
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() {