You've already forked ddns-updater
FEAT: Refactor allowing multiple DNS Providers
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
55
internal/dns_providers/directadmin.go
Normal file
55
internal/dns_providers/directadmin.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package dns_providers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/levelzerotechnology/directadmin-go"
|
||||
"github.com/mkelcik/cloudflare-ddns-update/internal"
|
||||
)
|
||||
|
||||
const (
|
||||
DirectadminTag = "directadmin"
|
||||
)
|
||||
|
||||
type Directadmin struct {
|
||||
Client *directadmin.UserContext
|
||||
Context context.Context
|
||||
Config internal.Config
|
||||
}
|
||||
|
||||
func (d *Directadmin) UpdateRecord(hostname string, ip string, old_ip string) error {
|
||||
|
||||
result := GetDomainParts(hostname)
|
||||
|
||||
a := directadmin.DNSRecord{Name: result.Name, Ttl: 300, Type: "A", Value: old_ip}
|
||||
b := directadmin.DNSRecord{Name: result.Name, Ttl: 300, Type: "A", Value: ip}
|
||||
|
||||
err := d.Client.UpdateDNSRecord(result.Domain, a, b)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Directadmin) NewClient(server_url string, username string, key string) {
|
||||
api, err := directadmin.New(server_url, 5*time.Second, false, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
userCtx, err := api.LoginAsUser(username, key)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
d.Client = userCtx
|
||||
}
|
||||
|
||||
func NewDirectAdminProvider(ctx context.Context, config internal.Config) *Directadmin {
|
||||
c := &Directadmin{}
|
||||
c.Context = ctx
|
||||
c.Config = config
|
||||
c.NewClient(config.DirectadminUrl, config.DirectadminUsername, config.DirectadminKey)
|
||||
return c
|
||||
}
|
||||
Reference in New Issue
Block a user