mirror of
https://github.com/joohoi/acme-dns.git
synced 2025-07-22 21:58:25 +07:00

* chore: enable more linters and fix linter issues * ci: enable linter checks on all branches and disable recurring checks recurring linter checks don't make that much sense. The code & linter checks should not change on their own over night ;) * chore: update packages * Revert "chore: update packages" This reverts commit 30250bf28c4b39e9e5b3af012a4e28ab036bf9af. * chore: manually upgrade some packages
48 lines
1002 B
Go
48 lines
1002 B
Go
package acmedns
|
|
|
|
import (
|
|
"net"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// Check if IP belongs to an allowed net
|
|
func (a ACMETxt) AllowedFrom(ip string) bool {
|
|
remoteIP := net.ParseIP(ip)
|
|
// Range not limited
|
|
if len(a.AllowFrom.ValidEntries()) == 0 {
|
|
return true
|
|
}
|
|
for _, v := range a.AllowFrom.ValidEntries() {
|
|
_, vnet, _ := net.ParseCIDR(v)
|
|
if vnet.Contains(remoteIP) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// Go through list (most likely from headers) to check for the IP.
|
|
// Reason for this is that some setups use reverse proxy in front of acme-dns
|
|
func (a ACMETxt) AllowedFromList(ips []string) bool {
|
|
if len(ips) == 0 {
|
|
// If no IP provided, check if no whitelist present (everyone has access)
|
|
return a.AllowedFrom("")
|
|
}
|
|
for _, v := range ips {
|
|
if a.AllowedFrom(v) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func NewACMETxt() ACMETxt {
|
|
var a = ACMETxt{}
|
|
password := generatePassword(40)
|
|
a.Username = uuid.New()
|
|
a.Password = password
|
|
a.Subdomain = uuid.New().String()
|
|
return a
|
|
}
|