You've already forked ddns-updater
Compare commits
4 Commits
ignore-ip-
...
upgrade
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
401884304e | ||
|
|
df74a0e159 | ||
|
|
316a40b662 | ||
|
|
17afc65f92 |
@@ -18,7 +18,6 @@ const (
|
||||
envKeyOnChangeComment = "ON_CHANGE_COMMENT"
|
||||
envKeyCheckIntervalSeconds = "CHECK_INTERVAL_SECONDS"
|
||||
envKeyNotifiers = "NOTIFIERS"
|
||||
envKeyIgnoredIpChange = "IGNORED_IP_CHANGE"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -29,7 +28,6 @@ type Config struct {
|
||||
OnChangeComment string
|
||||
Notifiers []string
|
||||
CheckInterval time.Duration
|
||||
IgnoredIpChange []string
|
||||
}
|
||||
|
||||
func (c Config) Validate() error {
|
||||
@@ -63,6 +61,5 @@ func NewConfig() Config {
|
||||
OnChangeComment: os.Getenv(envKeyOnChangeComment),
|
||||
Notifiers: parseCommaDelimited(os.Getenv(envKeyNotifiers)),
|
||||
CheckInterval: time.Duration(checkInterval) * time.Second,
|
||||
IgnoredIpChange: parseCommaDelimited(os.Getenv(envKeyIgnoredIpChange)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
import "strings"
|
||||
|
||||
func parseCommaDelimited(data string) []string {
|
||||
out := make([]string, 0, strings.Count(data, ",")+1)
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
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
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
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,12 +64,6 @@ func main() {
|
||||
}
|
||||
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))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user