feat: helper script to create new records if they don't exist
This commit is contained in:
5 files changed
+198
-12
No files matched your search
@@ -13,7 +13,7 @@ It speaks the common dyndns2 protocol (HTTP Basic Auth, `myip`/`myipv6`, `good`/
|
||||
3. If the IP equals the last one it stored, it answers `nochg` right away. INWX is not contacted, so polling every minute is cheap.
|
||||
4. Otherwise it logs in to INWX, looks up the record by name and type, updates it, and only then stores the new IP. If INWX fails, the device gets `911` and retries on its next run.
|
||||
|
||||
The record (A and/or AAAA) has to exist at INWX already. The server picks A or AAAA depending on the IP family, and keeps the TTL you set there. The connection to INWX uses IPv4 only, so an IP-restricted INWX API account only needs the server's IPv4 address on its allow-list.
|
||||
The record (A and/or AAAA) has to exist at INWX; the helper script below creates it for new hosts. The server picks A or AAAA depending on the IP family, and keeps the TTL of the record. The connection to INWX uses IPv4 only, so an IP-restricted INWX API account only needs the server's IPv4 address on its allow-list.
|
||||
|
||||
## Requirements
|
||||
|
||||
@@ -74,12 +74,14 @@ With another proxy, stop the service (`supervisorctl stop snap-dyndns`), run `nc
|
||||
|
||||
### Adding a device
|
||||
|
||||
The helper creates a random token, stores only its SHA-256 in the config and prints the token once:
|
||||
The helper creates a random token, stores only its SHA-256 in the config, prints the token once, and makes sure the DNS record exists at INWX:
|
||||
|
||||
```
|
||||
python3 ~/snap-dyndns-server/snap_dyndns_host.py user1.example.com
|
||||
```
|
||||
|
||||
If the A record does not exist at INWX yet, it is created with the TTL 300 and a placeholder address, which the first update of the device replaces. An existing record is left alone. Use `-t A,AAAA` to handle both types, `--ttl` for another TTL of new records, and `--no-dns` to skip INWX completely. If INWX cannot be reached, nothing is changed in the config. The helper needs the INWX login from the config and is therefore best run on the server itself, as an IP-restricted INWX account refuses logins from elsewhere.
|
||||
|
||||
Give the printed token to the device, for the [client](https://src.mehl.mx/mxmehl/snap-dyndns-client) it is the `hostname:token` entry shown in the output. For an existing host it asks before replacing the token (`-y` skips the question), and the old token stops working immediately. Use `-c` for a config in another location and `-z example.co.uk` for a new host whose INWX zone is not the last two labels of its name. Comments and the rest of the config stay untouched. The config is read on every request, so no restart is needed.
|
||||
|
||||
The hostname is the Basic Auth user name, the token the password. Without the helper, generate a token and hash yourself with `python3 -c 'import secrets,hashlib;t=secrets.token_urlsafe(32);print(t, hashlib.sha256(t.encode()).hexdigest())'` and add a section `[hosts."user1.example.com"]` with `token_sha256 = "<hash>"`.
|
||||
@@ -133,7 +135,7 @@ user1.example.com
|
||||
## Known limits
|
||||
|
||||
- Explicit `myip`/`myipv6` values are only checked for syntax, private and reserved addresses are accepted there.
|
||||
- Missing records are not created, add them at INWX first.
|
||||
- The server itself never creates records, only the helper script does when adding a host.
|
||||
- If you change a record at INWX by hand, the server does not notice. Delete `state.json` or change the IP to resync.
|
||||
- Only one request updates at a time (a lock is held during the INWX call), which is plenty for a personal setup.
|
||||
- The built-in HTTP server is meant to sit behind a reverse proxy. Do not expose its port directly.
|
||||
@@ -144,7 +146,7 @@ user1.example.com
|
||||
uv run --python 3.14 python -m unittest -v
|
||||
```
|
||||
|
||||
The tests use a fake INWX server. An additional smoke test runs against the INWX OT&E test system and is skipped unless `INWX_OTE_USER`, `INWX_OTE_PASS` and `INWX_OTE_HOST` (an existing A record in that account) are set in the environment. It restores the record afterwards.
|
||||
The tests use a fake INWX server. An additional smoke test runs against the INWX OT&E test system and is skipped unless `INWX_OTE_USER`, `INWX_OTE_PASS` and `INWX_OTE_HOST` (an existing A record in that account) are set in the environment. It restores the record afterwards and removes the record it creates for the helper test.
|
||||
|
||||
## License
|
||||
|
||||
|
||||
Reference in new issue
Block a user