You've already forked ddns-updater
Compare commits
5 Commits
ignore-ip-
...
v1.5.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13e2fa6f7b | ||
|
|
401884304e | ||
|
|
df74a0e159 | ||
|
|
316a40b662 | ||
|
|
17afc65f92 |
@@ -18,7 +18,6 @@ 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 {
|
||||||
@@ -29,7 +28,6 @@ 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 {
|
||||||
@@ -63,6 +61,5 @@ 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,8 +1,6 @@
|
|||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import "strings"
|
||||||
"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)
|
||||||
|
|||||||
@@ -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)
|
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