Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dreamhost-ddns"
version = "0.2.0"
version = "0.2.1"
edition = "2021"

[dependencies]
Expand Down
Binary file modified binaries/linux-aarch64/dreamhost-ddns
Binary file not shown.
Binary file modified binaries/linux-rpi-armv7/dreamhost-ddns
Binary file not shown.
Binary file modified binaries/linux-x86_64/dreamhost-ddns
Binary file not shown.
Binary file modified binaries/windows/dreamhost-ddns.exe
Binary file not shown.
44 changes: 44 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,32 @@ impl DreamhostClient {
.ok_or_else(|| anyhow!("DreamHost error: DNS record '{}' not found", record_name))
}

fn list_records(&self) -> Result<Vec<Record>> {

let resp = self.call(&[
("cmd", "dns-list_records"),
])?;

let records: Vec<Record> = serde_json::from_value(resp["data"].clone())?;

Ok(records)
}

fn record_exists(
&self,
record_name: &str,
ip: &str,
) -> Result<bool> {

let records = self.list_records()?;

Ok(records.iter().any(|r|
r.record == record_name &&
r.record_type == "A" &&
r.value == ip
))
}

fn update_dns(&self, record: &str, old_ip: &str, new_ip: &str) -> Result<()> {

info!("Adding new DNS record {} -> {}", record, new_ip);
Expand All @@ -134,6 +160,23 @@ impl DreamhostClient {
info!("Waiting briefly for DNS propagation...");
std::thread::sleep(std::time::Duration::from_secs(3));

for attempt in 1..=5 {

if self.record_exists(record, new_ip)? {
info!("New DNS record verified");
break;
}

warn!("New record not visible yet (attempt {})", attempt);
std::thread::sleep(std::time::Duration::from_secs(2));

if attempt == 5 {
return Err(anyhow!(
"New DNS record never appeared; refusing to remove old record"
));
}
}

info!("Removing old DNS record {} -> {}", record, old_ip);

self.call(&[
Expand All @@ -145,6 +188,7 @@ impl DreamhostClient {

Ok(())
}

}

fn main() -> Result<()> {
Expand Down
Loading