SiloCityLabs / lochnas

Docker configuration for all-in-one nas setup
https://lochnas.com
GNU General Public License v3.0
50 stars 3 forks source link

Check if the domain points to this ip address #36

Closed ldrrp closed 2 years ago

ldrrp commented 2 years ago

Problem

If the domain is not pointing to this ip address, then we need to notify the user that the domain is not pointing to this ip address. This can cause domain-renew/domain-add to fail.

Solution

On startup we need to check for all required domains and if they are not valid notify user. We should be able to bring this into golang natively without any command calls.

See the following link for placement:

https://github.com/SiloCityLabs/docker-nas/blob/v3/server/models/app.go Start() function

You can see PortCheck as an example.

Previous code in bash:

# Check if domain points here
checkdomain () {
    wanip="$(dig +short myip.opendns.com @resolver1.opendns.com)"

    # Allows us to use root domain if blank
    if [[ $1 == "" ]]; then 
        dnsip="$(dig +short $GLOBAL_DOMAIN @resolver1.opendns.com)"
        if [[ ! $wanip == $dnsip ]]; then
            echo "$GLOBAL_DOMAIN ($dnsip) is not pointing to your ip $wanip"
            exit 1
        fi
    else
        dnsip="$(dig +short $1.$GLOBAL_DOMAIN @resolver1.opendns.com)"
        if [[ ! $wanip == $dnsip ]]; then
            echo "$1 ($dnsip) is not pointing to your ip $wanip"
            exit 1
        fi
    fi
}

https://jameshfisher.com/2017/08/03/golang-dns-lookup/

Configuration

- domain-check-notify: true

Notify may be "true", "false" or "email" etc. Parsed as string. True will use server default.

Steps to Reproduce the Problem

  1. ./server.bin
Bana0615 commented 2 years ago

Similar to port check, check if ngnix is enabled

ldrrp commented 2 years ago

Looks like we cant override the standard dns resolver so we will just have to use either a custom package or dig via command

ldrrp commented 2 years ago

https://github.com/Focinfi/go-dns-resolver ?