refactor: gigantic refactor
This commit is contained in:
1 parent
d1e2bde503
commit
0474f7bbb4
50 files changed
+232
-207
No files matched your search
@@ -0,0 +1,35 @@
|
||||
{
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
pyenv = pkgs.python3.withPackages (ps: with ps; [ nc-dnsapi ]);
|
||||
in
|
||||
{
|
||||
users.groups.dyndns = { };
|
||||
users.users.dyndns = {
|
||||
isSystemUser = true;
|
||||
group = "dyndns";
|
||||
description = "DynDNS service user";
|
||||
};
|
||||
|
||||
systemd.timers."dyndns" = {
|
||||
requires = [ "network-online.target" ];
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig = {
|
||||
OnBootSec = "5m";
|
||||
OnUnitActiveSec = "5m";
|
||||
Unit = "dyndns.service";
|
||||
};
|
||||
};
|
||||
|
||||
systemd.services."dyndns" = {
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
User = "dyndns";
|
||||
ExecStart = "${pyenv.interpreter} ${./dyndns.py}";
|
||||
EnvironmentFile = config.sops.secrets.dyndns.path;
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
from nc_dnsapi import Client
|
||||
import os, urllib3
|
||||
|
||||
CUSTOMER = os.environ["NC_CUSTOMER"]
|
||||
API_PASSWORD = os.environ["NC_API_PASSWORD"]
|
||||
API_KEY = os.environ["NC_API_KEY"]
|
||||
DOMAIN = os.environ["NC_DOMAIN"]
|
||||
|
||||
ip = urllib3.request("GET", "https://api.ipify.org").data.decode()
|
||||
|
||||
with Client(CUSTOMER, API_KEY, API_PASSWORD) as api:
|
||||
to_be_updated = []
|
||||
records = api.dns_records(DOMAIN)
|
||||
|
||||
for record in records:
|
||||
if record.type in ["A", "AAAA"] and record.destination != ip:
|
||||
record.destination = ip
|
||||
to_be_updated.append(record)
|
||||
|
||||
|
||||
if to_be_updated:
|
||||
api.update_dns_records(DOMAIN, to_be_updated)
|
||||
|
||||
zone = api.dns_zone(DOMAIN)
|
||||
if zone.ttl != '300':
|
||||
zone.ttl = '300'
|
||||
api.update_dns_zone(DOMAIN, zone)
|
||||
Reference in new issue
Block a user