Compare commits
4 Commits
3ad5b1ec0e
...
ci-codeql
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a1ec0ecdc | |||
| ad0932f4aa | |||
| fff36bf807 | |||
| 1c725993f5 |
23
.gitea/workflows/codeql.yaml
Normal file
23
.gitea/workflows/codeql.yaml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
name: CodeQL Analysis
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
codeql-analysis:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Initialize CodeQL
|
||||||
|
uses: github/codeql-action/init@v3
|
||||||
|
with:
|
||||||
|
languages: "go"
|
||||||
|
- name: Perform CodeQL Analysis
|
||||||
|
uses: github/codeql-action/analyze@v3
|
||||||
@@ -38,6 +38,7 @@ domains:
|
|||||||
- www
|
- www
|
||||||
check_interval: 0 0 0/6 * * * *
|
check_interval: 0 0 0/6 * * * *
|
||||||
mode: Scheduled
|
mode: Scheduled
|
||||||
|
log_level: info
|
||||||
```
|
```
|
||||||
|
|
||||||
The config file is expected to be in the same directory as the binary and called `config.yaml`. For the OCR image, the root directory is `/app`.
|
The config file is expected to be in the same directory as the binary and called `config.yaml`. For the OCR image, the root directory is `/app`.
|
||||||
|
|||||||
@@ -21,3 +21,4 @@ domains:
|
|||||||
- www
|
- www
|
||||||
check_interval: 0 0 0/6 * * * *
|
check_interval: 0 0 0/6 * * * *
|
||||||
mode: Scheduled
|
mode: Scheduled
|
||||||
|
log_level: info
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package realDynDns
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"realdnydns/pkg/config"
|
"realdnydns/pkg/config"
|
||||||
@@ -70,63 +71,82 @@ func (c *ChangeDetector) detectAndApplyChanges() (int, error) {
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var numberUpdated int
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
|
numberUpdatedChannel := make(chan int)
|
||||||
|
|
||||||
for _, domain := range c.domains {
|
for _, domain := range c.domains {
|
||||||
for _, subdomain := range domain.Subdomains {
|
for _, subdomain := range domain.Subdomains {
|
||||||
c.logger.Info("Checking record",
|
wg.Add(1)
|
||||||
slog.String("tld", domain.TLD),
|
|
||||||
slog.String("subdomain", subdomain),
|
go func(domain config.DomainConfig, subdomain string) {
|
||||||
)
|
defer wg.Done()
|
||||||
currentRecord, err := c.dnsProvider.GetRecord(domain.TLD, subdomain)
|
|
||||||
if err != nil {
|
c.logger.Info("Checking record",
|
||||||
c.logger.Error("Failed to retrieve record",
|
|
||||||
slog.String("error", err.Error()),
|
|
||||||
slog.String("tld", domain.TLD),
|
slog.String("tld", domain.TLD),
|
||||||
slog.String("subdomain", subdomain),
|
slog.String("subdomain", subdomain),
|
||||||
)
|
)
|
||||||
return numberUpdated, err
|
currentRecord, err := c.dnsProvider.GetRecord(domain.TLD, subdomain)
|
||||||
}
|
|
||||||
|
|
||||||
if currentRecord.IP != externalIp.String() {
|
|
||||||
c.logger.Info("Record has changed",
|
|
||||||
slog.String("tld", domain.TLD),
|
|
||||||
slog.String("subdomain", subdomain),
|
|
||||||
slog.String("current_ip", currentRecord.IP),
|
|
||||||
slog.String("external_ip", externalIp.String()),
|
|
||||||
)
|
|
||||||
|
|
||||||
err = c.notificationProvider.SendNotification(
|
|
||||||
fmt.Sprintf("Update %s.%s", subdomain, domain.TLD),
|
|
||||||
fmt.Sprintf("The IP of %s has changed from %s to %s", domain.TLD, currentRecord.IP, externalIp.String()),
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.logger.Warn("Failed to send notification",
|
c.logger.Error("Failed to retrieve record",
|
||||||
slog.String("error", err.Error()),
|
|
||||||
)
|
|
||||||
return numberUpdated, err
|
|
||||||
}
|
|
||||||
|
|
||||||
c.logger.Info("Updating record",
|
|
||||||
slog.String("tld", domain.TLD),
|
|
||||||
slog.String("subdomain", subdomain),
|
|
||||||
slog.String("current_ip", currentRecord.IP),
|
|
||||||
slog.String("external_ip", externalIp.String()),
|
|
||||||
)
|
|
||||||
_, err = c.dnsProvider.UpdateRecord(domain.TLD, subdomain, externalIp, currentRecord.TTL, currentRecord.Prio, currentRecord.Disabled)
|
|
||||||
if err != nil {
|
|
||||||
c.logger.Error("Failed to update record",
|
|
||||||
slog.String("error", err.Error()),
|
slog.String("error", err.Error()),
|
||||||
slog.String("tld", domain.TLD),
|
slog.String("tld", domain.TLD),
|
||||||
slog.String("subdomain", subdomain),
|
slog.String("subdomain", subdomain),
|
||||||
)
|
)
|
||||||
return numberUpdated, err
|
return
|
||||||
}
|
}
|
||||||
numberUpdated++
|
|
||||||
}
|
if currentRecord.IP != externalIp.String() {
|
||||||
|
c.logger.Info("Record has changed",
|
||||||
|
slog.String("tld", domain.TLD),
|
||||||
|
slog.String("subdomain", subdomain),
|
||||||
|
slog.String("current_ip", currentRecord.IP),
|
||||||
|
slog.String("external_ip", externalIp.String()),
|
||||||
|
)
|
||||||
|
|
||||||
|
err = c.notificationProvider.SendNotification(
|
||||||
|
fmt.Sprintf("Update %s.%s", subdomain, domain.TLD),
|
||||||
|
fmt.Sprintf("The IP of %s has changed from %s to %s", domain.TLD, currentRecord.IP, externalIp.String()),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
c.logger.Warn("Failed to send notification",
|
||||||
|
slog.String("error", err.Error()),
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.logger.Info("Updating record",
|
||||||
|
slog.String("tld", domain.TLD),
|
||||||
|
slog.String("subdomain", subdomain),
|
||||||
|
slog.String("current_ip", currentRecord.IP),
|
||||||
|
slog.String("external_ip", externalIp.String()),
|
||||||
|
)
|
||||||
|
_, err = c.dnsProvider.UpdateRecord(domain.TLD, subdomain, externalIp, currentRecord.TTL, currentRecord.Prio, currentRecord.Disabled)
|
||||||
|
if err != nil {
|
||||||
|
c.logger.Error("Failed to update record",
|
||||||
|
slog.String("error", err.Error()),
|
||||||
|
slog.String("tld", domain.TLD),
|
||||||
|
slog.String("subdomain", subdomain),
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
numberUpdatedChannel <- 1
|
||||||
|
}
|
||||||
|
}(domain, subdomain)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
wg.Wait()
|
||||||
|
close(numberUpdatedChannel)
|
||||||
|
}()
|
||||||
|
|
||||||
|
numberUpdated := 0
|
||||||
|
for v := range numberUpdatedChannel {
|
||||||
|
numberUpdated += v
|
||||||
|
}
|
||||||
|
|
||||||
c.logger.Info("Run completed", slog.Int("number_of_changes", numberUpdated))
|
c.logger.Info("Run completed", slog.Int("number_of_changes", numberUpdated))
|
||||||
return numberUpdated, nil
|
return numberUpdated, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user