fix(dyndns): finally make it work
This commit is contained in:
@@ -3,15 +3,18 @@
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
pyenv = pkgs.python3.withPackages (ps: with ps; [ nc-dnsapi ]);
|
||||
in
|
||||
{
|
||||
users.groups.dyndns = { };
|
||||
users.users.dyndns = {
|
||||
isSystemUser = true;
|
||||
group = "dyndns";
|
||||
packages = [ pkgs.python313Packages.nc-dnsapi ];
|
||||
};
|
||||
|
||||
systemd.timers."dyndns" = {
|
||||
requires = [ "network-online.target" ];
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig = {
|
||||
OnBootSec = "5m";
|
||||
@@ -22,11 +25,11 @@
|
||||
|
||||
systemd.services."dyndns" = {
|
||||
script = ''
|
||||
NC_CUSTOMER=${"$(cat " + config.age.secrets.nc_customer.path + ")"}
|
||||
NC_API_PASSWORD=${"$(cat " + config.age.secrets.nc_api_password.path + ")"}
|
||||
NC_API_KEY=${"$(cat " + config.age.secrets.nc_api_key.path + ")"}
|
||||
NC_DOMAIN=${"$(cat " + config.age.secrets.nc_domain.path + ")"}
|
||||
${pkgs.python313}/bin/python3 -c "${builtins.readFile ./dyndns.py}"
|
||||
NC_CUSTOMER=${"$(cat " + config.age.secrets.nc_customer.path + ")"} \
|
||||
NC_API_PASSWORD=${"$(cat " + config.age.secrets.nc_api_password.path + ")"} \
|
||||
NC_API_KEY=${"$(cat " + config.age.secrets.nc_api_key.path + ")"} \
|
||||
NC_DOMAIN=${"$(cat " + config.age.secrets.nc_domain.path + ")"} \
|
||||
${pyenv.interpreter} ${./dyndns.py}
|
||||
'';
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
|
||||
@@ -6,7 +6,7 @@ api_password = os.environ["NC_API_PASSWORD"]
|
||||
api_key = os.environ["NC_API_KEY"]
|
||||
domain = os.environ["NC_DOMAIN"]
|
||||
|
||||
ip = str(urllib3.request("GET", "https://api.ipify.org").data)
|
||||
ip = urllib3.request("GET", "https://api.ipify.org").data.decode("ascii")
|
||||
|
||||
with Client(customer, api_key, api_password) as api:
|
||||
to_be_updated = []
|
||||
@@ -21,5 +21,6 @@ with Client(customer, api_key, api_password) as api:
|
||||
api.update_dns_records(domain, to_be_updated)
|
||||
|
||||
zone = api.dns_zone(domain)
|
||||
zone.ttl = 300
|
||||
api.update_dns_zone(domain, zone)
|
||||
if zone.ttl != 300:
|
||||
zone.ttl = 300
|
||||
api.update_dns_zone(domain, zone)
|
||||
|
||||
Reference in New Issue
Block a user