You've already forked ddns-updater
done
This commit is contained in:
@@ -18,6 +18,7 @@ const (
|
|||||||
envKeyOnChangeComment = "ON_CHANGE_COMMENT"
|
envKeyOnChangeComment = "ON_CHANGE_COMMENT"
|
||||||
envKeyCheckIntervalSeconds = "CHECK_INTERVAL_SECONDS"
|
envKeyCheckIntervalSeconds = "CHECK_INTERVAL_SECONDS"
|
||||||
envKeyNotifiers = "NOTIFIERS"
|
envKeyNotifiers = "NOTIFIERS"
|
||||||
|
envKeyIgnoredIpChange = "IGNORED_IP_CHANGE"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
@@ -28,6 +29,7 @@ type Config struct {
|
|||||||
OnChangeComment string
|
OnChangeComment string
|
||||||
Notifiers []string
|
Notifiers []string
|
||||||
CheckInterval time.Duration
|
CheckInterval time.Duration
|
||||||
|
IgnoredIpChange []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Config) Validate() error {
|
func (c Config) Validate() error {
|
||||||
@@ -61,5 +63,6 @@ func NewConfig() Config {
|
|||||||
OnChangeComment: os.Getenv(envKeyOnChangeComment),
|
OnChangeComment: os.Getenv(envKeyOnChangeComment),
|
||||||
Notifiers: parseCommaDelimited(os.Getenv(envKeyNotifiers)),
|
Notifiers: parseCommaDelimited(os.Getenv(envKeyNotifiers)),
|
||||||
CheckInterval: time.Duration(checkInterval) * time.Second,
|
CheckInterval: time.Duration(checkInterval) * time.Second,
|
||||||
|
IgnoredIpChange: parseCommaDelimited(os.Getenv(envKeyIgnoredIpChange)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package internal
|
package internal
|
||||||
|
|
||||||
import "strings"
|
import (
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
func parseCommaDelimited(data string) []string {
|
func parseCommaDelimited(data string) []string {
|
||||||
out := make([]string, 0, strings.Count(data, ",")+1)
|
out := make([]string, 0, strings.Count(data, ",")+1)
|
||||||
|
|||||||
26
internal/ignore_list.go
Normal file
26
internal/ignore_list.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
"regexp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func checkAddress(address, pattern string) bool {
|
||||||
|
pattern = "^" + pattern + "$"
|
||||||
|
re := regexp.MustCompile(pattern)
|
||||||
|
return re.MatchString(address)
|
||||||
|
}
|
||||||
|
|
||||||
|
func IgnoredIpChange(ip net.IP, ignored []string) bool {
|
||||||
|
if len(ignored) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, i := range ignored {
|
||||||
|
if checkAddress(ip.String(), i) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
75
internal/ignore_list_test.go
Normal file
75
internal/ignore_list_test.go
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
package internal
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func Test_checkAddress(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
address string
|
||||||
|
pattern string
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "empty",
|
||||||
|
args: args{
|
||||||
|
address: "192.168.0.1",
|
||||||
|
pattern: "",
|
||||||
|
},
|
||||||
|
want: false,
|
||||||
|
}, {
|
||||||
|
name: "true match 192.*",
|
||||||
|
args: args{
|
||||||
|
address: "192.168.0.1",
|
||||||
|
pattern: "192.*",
|
||||||
|
},
|
||||||
|
want: true,
|
||||||
|
}, {
|
||||||
|
name: "false match 193.*",
|
||||||
|
args: args{
|
||||||
|
address: "192.168.0.1",
|
||||||
|
pattern: "193.*",
|
||||||
|
},
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "true match 192.168.0.1",
|
||||||
|
args: args{
|
||||||
|
address: "192.168.0.1",
|
||||||
|
pattern: "192.168.0.1",
|
||||||
|
},
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "false not match 192.168.0.2",
|
||||||
|
args: args{
|
||||||
|
address: "192.168.0.1",
|
||||||
|
pattern: "192.168.0.2",
|
||||||
|
},
|
||||||
|
want: false,
|
||||||
|
}, {
|
||||||
|
name: "true match 192.168.0.*",
|
||||||
|
args: args{
|
||||||
|
address: "192.168.0.10",
|
||||||
|
pattern: "192.168.0.*",
|
||||||
|
},
|
||||||
|
want: true,
|
||||||
|
}, {
|
||||||
|
name: "false match 192.168.0.*",
|
||||||
|
args: args{
|
||||||
|
address: "192.168.1.10",
|
||||||
|
pattern: "192.168.0.*",
|
||||||
|
},
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := checkAddress(tt.args.address, tt.args.pattern); got != tt.want {
|
||||||
|
t.Errorf("checkAddress() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
6
main.go
6
main.go
@@ -64,6 +64,12 @@ func main() {
|
|||||||
}
|
}
|
||||||
log.Printf("Current public ip `%s` (resolver: %s)", currentPublicIP, resolverTag)
|
log.Printf("Current public ip `%s` (resolver: %s)", currentPublicIP, resolverTag)
|
||||||
|
|
||||||
|
// check if ip is not in ignore list
|
||||||
|
if internal.IgnoredIpChange(currentPublicIP, config.IgnoredIpChange) {
|
||||||
|
log.Printf("Ignored ip change `%s`, skipping.", currentPublicIP)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
dns, err := allDNSRecords(ctx, api, cloudflare.ZoneIdentifier(zoneID))
|
dns, err := allDNSRecords(ctx, api, cloudflare.ZoneIdentifier(zoneID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user