Compare commits
No commits in common. "main" and "1.1.4" have entirely different histories.
7 changed files with 39 additions and 57 deletions
|
@ -63,7 +63,7 @@ jobs:
|
|||
name: Bundle .deb package
|
||||
run: |
|
||||
cargo deb
|
||||
DEBIAN_REF=$(cat Cargo.toml | grep -E "(^|\|)version =" | cut -f2- -d= | tr -d \" | tr -d " " | tr - \~)
|
||||
DEBIAN_REF=$(echo ${{ github.ref_name }} | tr - \~)
|
||||
echo "DEBIAN_REF=$DEBIAN_REF" >> dist/build.env
|
||||
DEBIAN_REV=-$(cat Cargo.toml | grep -E "(^|\|)revision =" | cut -f2- -d= | tr -d \" | tr -d " ")
|
||||
echo "DEBIAN_REV=$DEBIAN_REV" >> dist/build.env
|
||||
|
@ -137,7 +137,7 @@ jobs:
|
|||
run: rm release_blobs/build.env
|
||||
-
|
||||
name: Release New Version
|
||||
uses: actions/forgejo-release@v2
|
||||
uses: actions/forgejo-release@v1
|
||||
with:
|
||||
direction: upload
|
||||
url: https://forgejo.neshweb.net
|
||||
|
|
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -114,7 +114,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "cloudflare-dns-updater"
|
||||
version = "1.1.9"
|
||||
version = "1.1.4"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"confy",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
authors = ["Neshura"]
|
||||
name = "cloudflare-dns-updater"
|
||||
version = "1.1.9"
|
||||
version = "1.1.4"
|
||||
edition = "2021"
|
||||
description = "Application for automatically updating Cloudflare DNS records"
|
||||
license = "GPL-3.0-or-later"
|
||||
|
|
|
@ -10,7 +10,7 @@ Further the application must be located in the same network as the configured zo
|
|||
The actual configuration happens in three or more files located in `~/.config/cloudflare-dns-updater/`:
|
||||
`config.toml` contains general configuration parameters for the application
|
||||
`interfaces.toml` contains all IPv6 interfaces available/used by the zone config files.
|
||||
`.toml` files in `zones.d` contain settings for individual zones.
|
||||
`.toml` files in `zone.d` contain settings for individual zones.
|
||||
|
||||
Example:
|
||||
|
||||
|
@ -29,7 +29,7 @@ host_address = "::edcb:a098:7654:3210"
|
|||
example-interface = "::0123:4567:890a:bcde" # static part of the IP, the rest will be dynamically generated using the host
|
||||
```
|
||||
|
||||
*zones.d/example.org.toml*
|
||||
*zone.d/example.org.toml*
|
||||
```toml
|
||||
email = "owner@example.org" # Email of User owning the Zone
|
||||
zone = "example.org" # Zone Name
|
||||
|
|
|
@ -64,7 +64,7 @@ impl CloudflareZone {
|
|||
let entries = match response.json::<CloudflareApiResults>() {
|
||||
Ok(data) => data,
|
||||
Err(e) => {
|
||||
let err_msg = format!("Unable to parse API response: {e}");
|
||||
let err_msg = format!("Unable to parse API response. Error: {e}");
|
||||
match connected_to_journal() {
|
||||
true => error!("[ERROR] {err_msg}"),
|
||||
false => eprintln!("[ERROR] {err_msg}"),
|
||||
|
@ -75,7 +75,7 @@ impl CloudflareZone {
|
|||
|
||||
Ok(entries.result)
|
||||
} else {
|
||||
let err_msg = format!("Unable to fetch Cloudflare Zone Entries for {}: {}",self.name ,response.status());
|
||||
let err_msg = format!("Unable to fetch Cloudflare Zone Entries for {}. Error: {}",self.name ,response.status());
|
||||
match connected_to_journal() {
|
||||
true => error!("[ERROR] {err_msg}"),
|
||||
false => eprintln!("[ERROR] {err_msg}"),
|
||||
|
@ -84,7 +84,7 @@ impl CloudflareZone {
|
|||
}
|
||||
}
|
||||
Err(e) => {
|
||||
let err_msg = format!("Unable to access Cloudflare API: {e}");
|
||||
let err_msg = format!("Unable to access Cloudflare API. Error: {e}");
|
||||
match connected_to_journal() {
|
||||
true => error!("[ERROR] {err_msg}"),
|
||||
false => eprintln!("[ERROR] {err_msg}"),
|
||||
|
@ -107,7 +107,7 @@ impl CloudflareZone {
|
|||
self.validate_response(response)
|
||||
},
|
||||
Err(e) => {
|
||||
let err_msg = format!("Unable to access Cloudflare API: {e}");
|
||||
let err_msg = format!("Unable to access Cloudflare API. Error: {e}");
|
||||
match connected_to_journal() {
|
||||
true => error!("[ERROR] {err_msg}"),
|
||||
false => eprintln!("[ERROR] {err_msg}"),
|
||||
|
@ -133,7 +133,7 @@ impl CloudflareZone {
|
|||
self.validate_response(response)
|
||||
},
|
||||
Err(e) => {
|
||||
let err_msg = format!("Unable to access Cloudflare API: {e}");
|
||||
let err_msg = format!("Unable to access Cloudflare API. Error: {e}");
|
||||
match connected_to_journal() {
|
||||
true => error!("[ERROR] {err_msg}"),
|
||||
false => eprintln!("[ERROR] {err_msg}"),
|
||||
|
@ -174,7 +174,7 @@ impl CloudflareZone {
|
|||
self.validate_response(response)
|
||||
},
|
||||
Err(e) => {
|
||||
let err_msg = format!("Unable to access Cloudflare API: {e}");
|
||||
let err_msg = format!("Unable to access Cloudflare API. Error: {e}");
|
||||
match connected_to_journal() {
|
||||
true => error!("[ERROR] {err_msg}"),
|
||||
false => eprintln!("[ERROR] {err_msg}"),
|
||||
|
@ -200,7 +200,7 @@ impl CloudflareZone {
|
|||
self.validate_response(response)
|
||||
},
|
||||
Err(e) => {
|
||||
let err_msg = format!("Unable to access Cloudflare API: {e}");
|
||||
let err_msg = format!("Unable to access Cloudflare API. Error: {e}");
|
||||
match connected_to_journal() {
|
||||
true => error!("[ERROR] {err_msg}"),
|
||||
false => eprintln!("[ERROR] {err_msg}"),
|
||||
|
@ -270,7 +270,7 @@ impl CloudflareZone {
|
|||
match Url::parse(input) {
|
||||
Ok(url) => Ok(url),
|
||||
Err(e) => {
|
||||
let err_msg = format!("Unable to parse URL: {}", e);
|
||||
let err_msg = format!("Unable to parse URL. Error: {}", e);
|
||||
match connected_to_journal() {
|
||||
true => error!("[ERROR] {err_msg}"),
|
||||
false => eprintln!("[ERROR] {err_msg}"),
|
||||
|
@ -293,7 +293,7 @@ impl CloudflareZone {
|
|||
let data = match response.json::<CloudflareApiResult>() {
|
||||
Ok(data) => data,
|
||||
Err(e) => {
|
||||
let err_msg = format!("Unable to parse API response: {e}");
|
||||
let err_msg = format!("Unable to parse API response. Error: {e}");
|
||||
match connected_to_journal() {
|
||||
true => error!("[ERROR] {err_msg}"),
|
||||
false => eprintln!("[ERROR] {err_msg}"),
|
||||
|
@ -305,7 +305,7 @@ impl CloudflareZone {
|
|||
match data.success {
|
||||
true => Ok(()),
|
||||
false => {
|
||||
let err_msg = format!("Unexpected error while updating DNS record: {:?}", data);
|
||||
let err_msg = format!("Unexpected error while updating DNS record. Info: {:?}", data);
|
||||
match connected_to_journal() {
|
||||
true => error!("[ERROR] {err_msg}"),
|
||||
false => eprintln!("[ERROR] {err_msg}"),
|
||||
|
@ -314,7 +314,7 @@ impl CloudflareZone {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
let err_msg = format!("Unable to post/put Cloudflare DNS entry: {}", response.status());
|
||||
let err_msg = format!("Unable to post/put Cloudflare DNS entry. Error: {}", response.status());
|
||||
match connected_to_journal() {
|
||||
true => error!("[ERROR] {err_msg}"),
|
||||
false => eprintln!("[ERROR] {err_msg}"),
|
||||
|
|
|
@ -37,7 +37,7 @@ impl InterfaceConfig {
|
|||
let interface_address = match self.interfaces.get(interface_name) {
|
||||
Some(address) => *address,
|
||||
None => {
|
||||
let err_msg = format!("Malformed or missing IP in interfaces.toml for interface {}", interface_name);
|
||||
let err_msg = "Malformed IP in interfaces.toml";
|
||||
match connected_to_journal() {
|
||||
true => error!("[ERROR] {err_msg}"),
|
||||
false => eprintln!("[ERROR] {err_msg}"),
|
||||
|
|
60
src/main.rs
60
src/main.rs
|
@ -24,8 +24,8 @@ struct Addresses {
|
|||
impl Addresses {
|
||||
fn new() -> Result<Self, Box<dyn Error>> {
|
||||
let mut ret = Self {
|
||||
ipv4_uri: "http://ip4only.me/api/".to_owned(),
|
||||
ipv6_uri: "http://ip6only.me/api/".to_owned(),
|
||||
ipv4_uri: "https://am.i.mullvad.net/ip".to_owned(),
|
||||
ipv6_uri: "https://ipv6.am.i.mullvad.net/ip".to_owned(),
|
||||
ipv4: Ipv4Addr::new(0, 0, 0, 0),
|
||||
ipv6: Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)
|
||||
};
|
||||
|
@ -61,28 +61,19 @@ impl Addresses {
|
|||
match self.get_v4() {
|
||||
Ok(ip) => {
|
||||
if ip != self.ipv4 {
|
||||
if ip == Ipv4Addr::new(0,0,0,0) {
|
||||
let warn_msg = "'0.0.0.0' detected as new IPv4, skipping changes".to_owned();
|
||||
match connected_to_journal() {
|
||||
true => warn!("[WARN] {warn_msg}"),
|
||||
false => println!("[WARN] {warn_msg}"),
|
||||
}
|
||||
}
|
||||
else {
|
||||
let info_msg = format!("IPv4 changed from '{}' to '{}'", self.ipv4, ip);
|
||||
match connected_to_journal() {
|
||||
true => info!("[INFO] {info_msg}"),
|
||||
false => println!("[INFO] {info_msg}"),
|
||||
}
|
||||
self.ipv4 = ip;
|
||||
let info_msg = format!("IPv4 changed from '{}' to '{}'", self.ipv4, ip);
|
||||
match connected_to_journal() {
|
||||
true => info!("[INFO] {info_msg}"),
|
||||
false => println!("[INFO] {info_msg}"),
|
||||
}
|
||||
self.ipv4 = ip;
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
let error_msg = format!("Unable to fetch IPv4 from '{}': {}", self.ipv4_uri, e);
|
||||
let warn_msg = format!("Unable to fetch IPv4 from '{}'. Error: {}", self.ipv4_uri, e);
|
||||
match connected_to_journal() {
|
||||
true => error!("[ERROR] {error_msg}"),
|
||||
false => eprintln!("[ERROR] {error_msg}"),
|
||||
true => warn!("[WARN] {warn_msg}"),
|
||||
false => println!("[WARN] {warn_msg}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -90,28 +81,19 @@ impl Addresses {
|
|||
match self.get_v6() {
|
||||
Ok(ip) => {
|
||||
if ip != self.ipv6 {
|
||||
if ip == Ipv6Addr::new(0,0,0,0,0,0,0,0) {
|
||||
let warn_msg = "'::' detected as new IPv6, skipping changes".to_owned();
|
||||
match connected_to_journal() {
|
||||
true => warn!("[WARN] {warn_msg}"),
|
||||
false => println!("[WARN] {warn_msg}"),
|
||||
}
|
||||
}
|
||||
else {
|
||||
let info_msg = format!("IPv6 changed from '{}' to '{}'", self.ipv6, ip);
|
||||
match connected_to_journal() {
|
||||
true => info!("[INFO] {info_msg}"),
|
||||
false => println!("[INFO] {info_msg}"),
|
||||
}
|
||||
self.ipv6 = ip;
|
||||
let info_msg = format!("IPv6 changed from '{}' to '{}'", self.ipv6, ip);
|
||||
match connected_to_journal() {
|
||||
true => info!("[INFO] {info_msg}"),
|
||||
false => println!("[INFO] {info_msg}"),
|
||||
}
|
||||
self.ipv6 = ip;
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
let error_msg = format!("Unable to fetch IPv6 from '{}': {}", self.ipv6_uri, e);
|
||||
let warn_msg = format!("Unable to fetch IPv6 from '{}'. Error: {}", self.ipv6_uri, e);
|
||||
match connected_to_journal() {
|
||||
true => error!("[ERROR] {error_msg}"),
|
||||
false => eprintln!("[ERROR] {error_msg}"),
|
||||
true => warn!("[WARN] {warn_msg}"),
|
||||
false => println!("[WARN] {warn_msg}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +104,7 @@ impl Addresses {
|
|||
Ok(res) => {
|
||||
match res.status() {
|
||||
StatusCode::OK => {
|
||||
let ip_string = res.text().expect("Returned data should always contain text").trim_end().split(',').collect::<Vec<&str>>()[1].to_owned();
|
||||
let ip_string = res.text().expect("Returned data should always contain text").trim_end().to_owned();
|
||||
Ok(Ipv4Addr::from_str(ip_string.as_str()).expect("Returned IP should always be parseable"))
|
||||
},
|
||||
_ => {
|
||||
|
@ -145,7 +127,7 @@ impl Addresses {
|
|||
Ok(res) => {
|
||||
match res.status() {
|
||||
StatusCode::OK => {
|
||||
let ip_string: String = res.text().expect("Returned data should always contain text").trim_end().split(',').collect::<Vec<&str>>()[1].to_owned();
|
||||
let ip_string = res.text().expect("Returned data should always contain text").trim_end().to_owned();
|
||||
Ok(Ipv6Addr::from_str(ip_string.as_str()).expect("Returned IP should always be parseable"))
|
||||
},
|
||||
_ => {
|
||||
|
@ -656,7 +638,7 @@ fn main() {
|
|||
if cf_zone.update(entry, r#type, &cf_entry.id, ipv6, ipv4).is_ok() {
|
||||
let info_msg = format!("Updated {} DNS Record for entry '{}' in zone '{}'", r#type, entry.name, zone.name);
|
||||
match connected_to_journal() {
|
||||
true => info!("[INFO] {info_msg}"),
|
||||
true => warn!("[INFO] {info_msg}"),
|
||||
false => println!("[INFO] {info_msg}"),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue