Skip to content

Commit

Permalink
Merge pull request #9 from mhum/log-timestamp
Browse files Browse the repository at this point in the history
Timestamp in logs
  • Loading branch information
mhum authored Mar 19, 2023
2 parents b444de8 + 82b9b5c commit 5f72d76
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ RUN curl -sSL https://github.com/tcltk/tcllib/archive/release.tar.gz | tar -xz -

RUN mkdir /logs
WORKDIR /root
RUN echo "$(crontab -l 2>&1; echo "*/5 * * * * /root/dns.tcl")" | crontab -
RUN echo "$(crontab -l 2>&1; echo "*/60 * * * * /root/dns.tcl")" | crontab -
CMD ["crond", "-f", "2>&1"]
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ $ export USERNAME=username API_KEY=api_key DOMAIN=domain.com SUBDOMAIN=subdomain

Ex: `docker run -d --name nfsn-dynamic-dns --env-file .env nfs-dynamic-dns`

### With Docker Compose
You can use the following config to run this with [docker compose](https://docs.docker.com/compose/).
```yaml
version: "3"

services:
nfs-dynamic-dns:
image: nfs-dynamic-dns
build: ./nfs-dynamic-dns
container_name: nfs-dynamic-dns
network_mode: host
environment:
- USERNAME=username
- API_KEY=api_key
- DOMAIN=domain.com
- SUBDOMAIN=subdomain
restart: unless-stopped
```
#### Development
To run the container locally (and let it run its cronjobs), use this command:
`docker run -it --rm --init nfs-dynamic-dns`
Expand Down
13 changes: 8 additions & 5 deletions dns.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ namespace eval ::nfs:: {
}

proc updateIPs {current_ip domain_ip} {
set now [clock seconds]
# When there's no existing record for a domain name, the
# listRRs API query returns the domain name of the name server.
if {[string first "nearlyfreespeech.net" $domain_ip] ne -1} {
puts "The domain IP doesn't appear to be set yet."
puts "[clock format $now -format {%y-%m-%d %H:%M:%S}]: The domain IP doesn't appear to be set yet."
} else {
puts "Current IP: $current_ip doesn't match Domain IP: $domain_ip"
puts "[clock format $now -format {%y-%m-%d %H:%M:%S}]: Current IP: $current_ip doesn't match Domain IP: $domain_ip"

# The case where the server returns 0.0.0.0 is probably
# vestigial, but I'm leaving it in just in case.
Expand All @@ -47,21 +48,23 @@ proc updateIPs {current_ip domain_ip} {

if {[::nfs::Utility::doIPsMatch]} {
set domain_ip [::nfs::Http::fetchDomainIP]
set now [clock seconds]

puts "IPs match now! Current IP: $current_ip Domain IP: $domain_ip"
puts "[clock format $now -format {%y-%m-%d %H:%M:%S}]: IPs match now! Current IP: $current_ip Domain IP: $domain_ip"
exit
} else {
puts "They still don't match. Current IP: $current_ip Domain IP: $domain_ip"
puts "[clock format $now -format {%y-%m-%d %H:%M:%S}]: They still don't match. Current IP: $current_ip Domain IP: $domain_ip"
exit
}
}

proc compareIPs {} {
set domain_ip [::nfs::Http::fetchDomainIP]
set current_ip [::nfs::Http::fetchCurrentIP]
set now [clock seconds]

if {[::nfs::Utility::doIPsMatch]} {
puts "IPs still match! Current IP: $current_ip Domain IP: $domain_ip"
puts "[clock format $now -format {%y-%m-%d %H:%M:%S}]: IPs still match! Current IP: $current_ip Domain IP: $domain_ip"
exit
} else {
updateIPs $current_ip $domain_ip
Expand Down
2 changes: 1 addition & 1 deletion packages/http.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ proc ::nfs::Http::getRequest {uri {body { }}} {
http::register https 443 [list ::tls::socket -tls1 1 -autoservername 1]

try {set token [http::geturl $url -headers $header -query $body]}

set resp_data [http::data $token]

::nfs::Utility::validateResponse $resp_data
Expand Down

0 comments on commit 5f72d76

Please sign in to comment.