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