2016-11-11 21:48:00 +07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-11-28 04:21:46 +07:00
|
|
|
"database/sql"
|
|
|
|
"sync"
|
2018-08-10 20:51:32 +07:00
|
|
|
|
|
|
|
"github.com/google/uuid"
|
2016-11-11 21:48:00 +07:00
|
|
|
)
|
|
|
|
|
2017-11-14 05:42:30 +07:00
|
|
|
// Config is global configuration struct
|
|
|
|
var Config DNSConfig
|
2016-11-28 18:13:45 +07:00
|
|
|
|
|
|
|
// DB is used to access the database functions in acme-dns
|
|
|
|
var DB database
|
|
|
|
|
2016-11-23 23:07:38 +07:00
|
|
|
// DNSConfig holds the config structure
|
2016-11-17 00:15:36 +07:00
|
|
|
type DNSConfig struct {
|
2016-11-13 19:50:44 +07:00
|
|
|
General general
|
2016-11-17 22:52:55 +07:00
|
|
|
Database dbsettings
|
2016-11-17 00:15:36 +07:00
|
|
|
API httpapi
|
2016-11-13 19:50:44 +07:00
|
|
|
Logconfig logconfig
|
2016-11-11 21:48:00 +07:00
|
|
|
}
|
|
|
|
|
2016-11-13 19:50:44 +07:00
|
|
|
// Auth middleware
|
2016-11-23 23:07:38 +07:00
|
|
|
type authMiddleware struct{}
|
2016-11-13 19:50:44 +07:00
|
|
|
|
2016-11-11 21:48:00 +07:00
|
|
|
// Config file general section
|
|
|
|
type general struct {
|
2016-11-28 02:21:38 +07:00
|
|
|
Listen string
|
2016-11-29 03:46:24 +07:00
|
|
|
Proto string `toml:"protocol"`
|
2016-11-15 14:27:34 +07:00
|
|
|
Domain string
|
|
|
|
Nsname string
|
|
|
|
Nsadmin string
|
2016-11-16 19:56:49 +07:00
|
|
|
Debug bool
|
2016-11-15 14:27:34 +07:00
|
|
|
StaticRecords []string `toml:"records"`
|
2016-11-13 19:50:44 +07:00
|
|
|
}
|
|
|
|
|
2016-11-17 22:52:55 +07:00
|
|
|
type dbsettings struct {
|
|
|
|
Engine string
|
|
|
|
Connection string
|
|
|
|
}
|
|
|
|
|
2016-11-13 19:50:44 +07:00
|
|
|
// API config
|
|
|
|
type httpapi struct {
|
2018-03-15 04:35:39 +07:00
|
|
|
Domain string `toml:"api_domain"`
|
|
|
|
IP string
|
|
|
|
DisableRegistration bool `toml:"disable_registration"`
|
|
|
|
AutocertPort string `toml:"autocert_port"`
|
|
|
|
Port string `toml:"port"`
|
|
|
|
TLS string
|
|
|
|
TLSCertPrivkey string `toml:"tls_cert_privkey"`
|
|
|
|
TLSCertFullchain string `toml:"tls_cert_fullchain"`
|
2018-05-14 17:42:39 +07:00
|
|
|
ACMECacheDir string `toml:"acme_cache_dir"`
|
2018-03-15 04:35:39 +07:00
|
|
|
CorsOrigins []string
|
|
|
|
UseHeader bool `toml:"use_header"`
|
|
|
|
HeaderName string `toml:"header_name"`
|
2016-11-11 21:48:00 +07:00
|
|
|
}
|
2016-11-13 19:50:44 +07:00
|
|
|
|
|
|
|
// Logging config
|
|
|
|
type logconfig struct {
|
|
|
|
Level string `toml:"loglevel"`
|
|
|
|
Logtype string `toml:"logtype"`
|
|
|
|
File string `toml:"logfile"`
|
|
|
|
Format string `toml:"logformat"`
|
|
|
|
}
|
|
|
|
|
2016-11-28 04:21:46 +07:00
|
|
|
type acmedb struct {
|
|
|
|
sync.Mutex
|
|
|
|
DB *sql.DB
|
|
|
|
}
|
|
|
|
|
|
|
|
type database interface {
|
|
|
|
Init(string, string) error
|
2016-12-01 05:03:08 +07:00
|
|
|
Register(cidrslice) (ACMETxt, error)
|
2016-11-28 04:21:46 +07:00
|
|
|
GetByUsername(uuid.UUID) (ACMETxt, error)
|
2018-01-22 14:53:07 +07:00
|
|
|
GetTXTForDomain(string) ([]string, error)
|
2016-11-28 04:21:46 +07:00
|
|
|
Update(ACMETxt) error
|
|
|
|
GetBackend() *sql.DB
|
|
|
|
SetBackend(*sql.DB)
|
|
|
|
Close()
|
|
|
|
Lock()
|
|
|
|
Unlock()
|
|
|
|
}
|