Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de02b19861 | ||
|
|
99e9c130c0 |
No files matched your search
@@ -7,7 +7,9 @@
|
|||||||
|
|
||||||
let
|
let
|
||||||
# Declaratively read the external Python script into the Nix store at evaluation time
|
# Declaratively read the external Python script into the Nix store at evaluation time
|
||||||
ipMonitorScript = pkgs.writers.writePython3Bin "dynu-ip-monitor" { } (builtins.readFile ../scripts/monitor.py);
|
ipMonitorScript = pkgs.writers.writePython3Bin "dynu-ip-monitor" {
|
||||||
|
flakeIgnore = [ "E501" ];
|
||||||
|
} (builtins.readFile ../scripts/monitor.py);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# Define the keys to decrypt
|
# Define the keys to decrypt
|
||||||
|
|||||||
@@ -243,9 +243,9 @@
|
|||||||
"d /home/${config.homelab.operatorUser}/.local/state/homelab/gitops 0755 ${config.homelab.operatorUser} users -"
|
"d /home/${config.homelab.operatorUser}/.local/state/homelab/gitops 0755 ${config.homelab.operatorUser} users -"
|
||||||
"d /home/${config.homelab.operatorUser}/.local/state/homelab/docker 0755 ${config.homelab.operatorUser} users -"
|
"d /home/${config.homelab.operatorUser}/.local/state/homelab/docker 0755 ${config.homelab.operatorUser} users -"
|
||||||
"d /home/${config.homelab.operatorUser}/var/lib/homelab 0755 ${config.homelab.operatorUser} users -"
|
"d /home/${config.homelab.operatorUser}/var/lib/homelab 0755 ${config.homelab.operatorUser} users -"
|
||||||
# POSIX ACLs granting homelab-appctl traverse and access to operator sites & homepage config
|
# POSIX ACLs granting homelab-appctl and homelab-operators traverse & access (explicit mask m:: required on 0700 home dirs)
|
||||||
"a+ /home/${config.homelab.operatorUser} - - - - u:homelab-appctl:x"
|
"a+ /home/${config.homelab.operatorUser} - - - - u:homelab-appctl:x,g:homelab-operators:x,m::rx"
|
||||||
"a+ ${config.homelab.coreDir} - - - - u:homelab-appctl:x"
|
"a+ ${config.homelab.coreDir} - - - - u:homelab-appctl:x,g:homelab-operators:x,m::rx"
|
||||||
"A+ ${config.homelab.sitesDir} - - - - d:u:homelab-appctl:rwx,u:homelab-appctl:rwx"
|
"A+ ${config.homelab.sitesDir} - - - - d:u:homelab-appctl:rwx,u:homelab-appctl:rwx"
|
||||||
"A+ /home/${config.homelab.operatorUser}/var/lib/homelab - - - - d:u:homelab-appctl:rwx,u:homelab-appctl:rwx"
|
"A+ /home/${config.homelab.operatorUser}/var/lib/homelab - - - - d:u:homelab-appctl:rwx,u:homelab-appctl:rwx"
|
||||||
"A+ ${config.homelab.coreDir}/config/homepage - - - - d:u:homelab-appctl:rwx,u:homelab-appctl:rwx"
|
"A+ ${config.homelab.coreDir}/config/homepage - - - - d:u:homelab-appctl:rwx,u:homelab-appctl:rwx"
|
||||||
|
|||||||
@@ -78,7 +78,8 @@ def get_public_ip():
|
|||||||
for provider in PROVIDERS:
|
for provider in PROVIDERS:
|
||||||
try:
|
try:
|
||||||
req = urllib.request.Request(
|
req = urllib.request.Request(
|
||||||
provider, headers={"User-Agent": "Mozilla/5.0 (NixOS WAN Monitor)"}
|
provider,
|
||||||
|
headers={"User-Agent": "Mozilla/5.0 (NixOS WAN Monitor)"},
|
||||||
)
|
)
|
||||||
# Fetch with 5s timeout to avoid hanging the systemd service
|
# Fetch with 5s timeout to avoid hanging the systemd service
|
||||||
with urllib.request.urlopen(req, timeout=5) as response:
|
with urllib.request.urlopen(req, timeout=5) as response:
|
||||||
@@ -91,7 +92,8 @@ def get_public_ip():
|
|||||||
errors.append(f"{provider}: {e!s}")
|
errors.append(f"{provider}: {e!s}")
|
||||||
|
|
||||||
print(
|
print(
|
||||||
f"Error: All IP discovery providers failed. Details: {errors}", file=sys.stderr
|
f"Error: All IP discovery providers failed. Details: {errors}",
|
||||||
|
file=sys.stderr,
|
||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -128,7 +130,11 @@ def record_ip(ip, status, details=None):
|
|||||||
Appends a new event entry into the JSONLines history registry.
|
Appends a new event entry into the JSONLines history registry.
|
||||||
"""
|
"""
|
||||||
os.makedirs(os.path.dirname(HISTORY_FILE), exist_ok=True)
|
os.makedirs(os.path.dirname(HISTORY_FILE), exist_ok=True)
|
||||||
entry = {"timestamp": datetime.now(tz=UTC).isoformat(), "ip": ip, "status": status}
|
entry = {
|
||||||
|
"timestamp": datetime.now(tz=UTC).isoformat(),
|
||||||
|
"ip": ip,
|
||||||
|
"status": status,
|
||||||
|
}
|
||||||
if details:
|
if details:
|
||||||
entry["details"] = details
|
entry["details"] = details
|
||||||
try:
|
try:
|
||||||
@@ -156,7 +162,9 @@ def trigger_ddclient():
|
|||||||
if res.returncode == 0:
|
if res.returncode == 0:
|
||||||
return True, None
|
return True, None
|
||||||
else:
|
else:
|
||||||
err_msg = f"systemctl exited with {res.returncode}: {res.stderr.strip()}"
|
err_msg = (
|
||||||
|
f"systemctl exited with {res.returncode}: {res.stderr.strip()}"
|
||||||
|
)
|
||||||
return False, err_msg
|
return False, err_msg
|
||||||
except (OSError, subprocess.SubprocessError) as e:
|
except (OSError, subprocess.SubprocessError) as e:
|
||||||
return False, str(e)
|
return False, str(e)
|
||||||
|
|||||||
Reference in new issue
Block a user