Some changes

This commit is contained in:
dswd committed 2026-04-11 23:56:51 +02:00
1 parent aaa2167791
commit 302a7f57a4
2 files changed
+154 -124

No files matched your search

+3 -3
View File
@@ -97,13 +97,14 @@ class Updater:
def update_domain(self, domain: str, update_info: dict):
modes = update_info.get("modes", [Mode.IPv4])
update_required = False
resolved_addrs = {}
for mode in modes:
log.debug(f"Resolving {domain} ({mode})")
resolved = resolve(domain, mode)
resolved_addrs[mode] = resolved
log.debug(f"Resolved to {resolved}")
if resolved != self.addrs[mode]:
update_required = True
break
if not update_required:
return
log.info(f"Updating {domain}")
@@ -121,9 +122,8 @@ class Updater:
response = requests.request(method, url, params=params, headers=headers, timeout=10)
success = response.status_code == 200
response_text = response.text
print(response_text)
log.info(f"Updated {domain}")
self.add_to_history(domain, self.addrs, success, response_text)
self.add_to_history(domain, self.addrs if success else resolved_addrs, success, response_text)
def update_domains(self):
for domain, update_info in self.config["domains"].items():
+151 -121
View File
@@ -1,133 +1,163 @@
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>DynDns Updater</title>
<link rel="stylesheet" href="beer.min.css">
<script src="beer.min.js" defer></script>
<script src="alpine.min.js" defer></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>DynDns Updater</title>
<link rel="stylesheet" href="beer.min.css">
<script src="beer.min.js" defer></script>
<script src="alpine.min.js" defer></script>
</head>
<body>
<main x-data="data" class="responsive">
<h1>DynDns Updater</h1>
<main x-data="data" class="responsive">
<h1>DynDns Updater</h1>
<button class="small float-right" x-on:click="update">
<i>refresh</i>
<span>Update</span>
</button>
<table>
<tbody>
<tr>
<th>IPv4</td>
<td><span x-text="addrs.ipv4"></span></td>
</tr>
<tr>
<th>IPv6</td>
<td><span x-text="addrs.ipv6"></span></td>
</tr>
<tr>
<th>Last Update</td>
<td><span x-text="niceTime(lastUpdate)"></span></td>
</tr>
</tbody>
</table>
<template x-for="domain in domains">
<article>
<h6>
<template x-if="domain.success">
<i class="success-text">check_circle</i>
</template>
<template x-else>
<i class="error-text">error</i>
</template>
<span x-text="domain.name"></span>
</h6>
<table>
<tbody>
<tr>
<th>IPv4</td>
<td><span x-text="addrs.ipv4"></span></td>
</tr>
<tr>
<th>IPv6</td>
<td><span x-text="addrs.ipv6"></span></td>
</tr>
<tr>
<th>Last Update</td>
<td><span x-text="niceTime(lastUpdate)"></span></td>
</tr>
</tbody>
<tbody>
<tr>
<th>IPv4</td>
<td><span x-text="domain.addrs.ipv4"></span></td>
</tr>
<tr>
<th>IPv6</td>
<td><span x-text="domain.addrs.ipv6"></span></td>
</tr>
<tr>
<th>Last Update</td>
<td><span x-text="niceTime(domain.lastUpdate)"></span></td>
</tr>
</tbody>
</table>
<button class="small" x-on:click="update">Update</button>
<template x-for="domain in domains">
<article>
<h6>
<span x-text="domain.success ? '✅' : '❌'"></span>
<span x-text="domain.name"></span>
</h6>
<table>
<tbody>
<tr>
<th>IPv4</td>
<td><span x-text="domain.addrs.ipv4"></span></td>
</tr>
<tr>
<th>IPv6</td>
<td><span x-text="domain.addrs.ipv6"></span></td>
</tr>
<tr>
<th>Last Update</td>
<td><span x-text="niceTime(domain.lastUpdate)"></span></td>
</tr>
</tbody>
</table>
<details>
<summary>
<button class="small">
<span>History</span>
<i>expand_more</i>
</button>
</summary>
<ul class="list border">
<template x-for="update in domain.history">
<li>
<i>home</i>
<div class="max">
<h6 class="small" x-text="update.response_text"></h6>
<div>
<button class="chip">IPv4</button><span x-text="update.addrs.ipv4"></span>
<button class="chip">IPv6</button><span x-text="update.addrs.ipv6"></span>
</div>
</div>
<label><span x-text="niceTime(update.timestamp)"></span></label>
</li>
</template>
</ul>
</details>
</article>
</template>
</main>
<script>
document.addEventListener('alpine:init', () => {
Alpine.data('data', () => ({
addrs: { ipv4: null, ipv6: null },
lastUpdate: null,
domains: [],
niceTime(time) {
if (!time) return '';
const diff = new Date() - time;
if (diff < 1000) {
return 'just now';
} else if (diff < 60000) {
return `${Math.round(diff / 1000)} seconds ago`;
} else if (diff < 3600000) {
return `${Math.round(diff / 60000)} minutes ago`;
} else {
return time.toISOString();
}
},
async update() {
const res = await fetch('http://localhost:8080/state');
const data = await res.json();
this.addrs = data.addrs;
this.lastUpdate = new Date(data.timestamp * 1000);
this.domains = Object.entries(data.domains).map(([domain, history]) => ({
name: domain,
success: history[history.length - 1].success,
lastUpdate: new Date(history[history.length - 1].timestamp * 1000),
addrs: history[history.length - 1].addrs,
history: history.reverse().map(h => ({
timestamp: new Date(h.timestamp * 1000),
addrs: h.addrs,
success: h.success,
response_text: h.response_text
}))
}));
},
async init() {
await this.update();
window.setInterval(() => {
this.update();
}, 10000);
},
<details>
<summary>
<button class="small">
<i>history</i>
<span>History</span>
<i>expand_more</i>
</button>
</summary>
<ul class="list border no-space">
<template x-for="update in domain.history">
<li>
<template x-if="update.success">
<i class="success-text">check_circle</i>
</template>
<template x-else>
<i class="error-text">error</i>
</template>
<div class="max">
<template x-if="update.success">
<div>
<div>
<b>IPv4:</b> <span class="small-text" x-text="update.addrs.ipv4"></span>
</div>
<div>
<b>IPv6:</b> <span class="small-text" x-text="update.addrs.ipv6"></span>
</div>
</div>
</template>
<template x-else>
<p x-text="update.response_text"></p>
</template>
</div>
<label><span x-text="niceTime(update.timestamp)"></span></label>
</li>
</template>
</ul>
</details>
</article>
</template>
</main>
<script>
document.addEventListener('alpine:init', () => {
Alpine.data('data', () => ({
addrs: { ipv4: null, ipv6: null },
lastUpdate: null,
domains: [],
niceTime(time) {
if (!time) return '';
const diff = new Date() - time;
if (diff < 1000) {
return 'just now';
} else if (diff < 60000) {
return `${Math.round(diff / 1000)} seconds ago`;
} else if (diff < 3600000) {
return `${Math.round(diff / 60000)} minutes ago`;
} else {
return time.toISOString();
}
},
async update() {
const res = await fetch('http://localhost:8080/state');
const data = await res.json();
this.addrs = data.addrs;
this.lastUpdate = new Date(data.timestamp * 1000);
this.domains = Object.entries(data.domains).map(([domain, history]) => ({
name: domain,
success: history[history.length - 1].success,
lastUpdate: new Date(history[history.length - 1].timestamp * 1000),
addrs: history[history.length - 1].addrs,
history: history.reverse().map(h => ({
timestamp: new Date(h.timestamp * 1000),
addrs: h.addrs,
success: h.success,
response_text: h.response_text
}))
});
</script>
<style>
main {
overflow: auto;
}
</style>
}));
},
async init() {
await this.update();
window.setInterval(() => {
this.update();
}, 10000);
},
}))
});
</script>
<style>
main {
overflow: unset;
}
.float-right {
float: right;
}
.success-text {
color: #006e1c
}
</style>
</body>
</html>