mirror of
https://github.com/joohoi/acme-dns.git
synced 2024-12-22 21:13:54 +07:00
52 lines
960 B
Go
52 lines
960 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"net"
|
||
|
|
||
|
"github.com/satori/go.uuid"
|
||
|
)
|
||
|
|
||
|
// ACMETxt is the default structure for the user controlled record
|
||
|
type ACMETxt struct {
|
||
|
Username uuid.UUID
|
||
|
Password string
|
||
|
ACMETxtPost
|
||
|
LastActive int64
|
||
|
AllowFrom cidrslice
|
||
|
}
|
||
|
|
||
|
// ACMETxtPost holds the DNS part of the ACMETxt struct
|
||
|
type ACMETxtPost struct {
|
||
|
Subdomain string `json:"subdomain"`
|
||
|
Value string `json:"txt"`
|
||
|
}
|
||
|
|
||
|
// cidrslice is a list of allowed cidr ranges
|
||
|
type cidrslice []string
|
||
|
|
||
|
func (c *cidrslice) JSON() string {
|
||
|
ret, _ := json.Marshal(c.ValidEntries())
|
||
|
return string(ret)
|
||
|
}
|
||
|
|
||
|
func (c *cidrslice) ValidEntries() []string {
|
||
|
valid := []string{}
|
||
|
for _, v := range *c {
|
||
|
_, _, err := net.ParseCIDR(v)
|
||
|
if err == nil {
|
||
|
valid = append(valid, v)
|
||
|
}
|
||
|
}
|
||
|
return valid
|
||
|
}
|
||
|
|
||
|
func newACMETxt() ACMETxt {
|
||
|
var a = ACMETxt{}
|
||
|
password := generatePassword(40)
|
||
|
a.Username = uuid.NewV4()
|
||
|
a.Password = password
|
||
|
a.Subdomain = uuid.NewV4().String()
|
||
|
return a
|
||
|
}
|